⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html.c

📁 基于minigui的浏览器. 这是最新版本.
💻 C
📖 第 1 页 / 共 5 页
字号:
   if (event->button == 3 && image->url) {      a_Menu_popup_set_url(bw, image->url);      a_Menu_popup_clear_url2(bw->menu_popup.over_image);      gtk_menu_popup(GTK_MENU(bw->menu_popup.over_image), NULL, NULL,                     NULL, NULL, event->button, event->time);      return TRUE;   }   return FALSE;}/* * Popup the page menu ("button_press_event" callback of the viewport) */static int Html_page_menu(GtkWidget *viewport, GdkEventButton *event,                          BrowserWindow *bw){   gpointer bug_pix;   if (event->button == 3) {      /* set the working URL */      a_Menu_popup_set_url(bw, a_History_get_url(NAV_TOP(bw)));      /* set "View page Bugs" sensitivity */      bug_pix = gtk_object_get_data(GTK_OBJECT(bw->status_bug_meter), "bug");      gtk_widget_set_sensitive(bw->viewbugs_menuitem,                               GTK_WIDGET_VISIBLE(GTK_WIDGET(bug_pix)));      gtk_menu_popup(GTK_MENU(bw->menu_popup.over_page), NULL, NULL,                     NULL, NULL, event->button, event->time);      return TRUE;   } else      return FALSE;}/* * Connect all signals of a page or an image. */static void Html_connect_signals(DilloHtml *html, GtkObject *widget){   gtk_signal_connect (widget, "link_entered",                       GTK_SIGNAL_FUNC(Html_handle_status),                       (gpointer)html->linkblock);   gtk_signal_connect (widget, "link_pressed", GTK_SIGNAL_FUNC(Html_link_menu),                       (gpointer)html->linkblock);   gtk_signal_connect (widget, "link_clicked",                       GTK_SIGNAL_FUNC(Html_link_clicked),                       (gpointer)html->linkblock);}/* * Create a new link in the linkblock, set it as the url's parent * and return the index. */static gint Html_set_new_link(DilloHtml *html, DilloUrl **url){   gint nl;   nl = html->linkblock->num_links;   a_List_add(html->linkblock->links, nl, html->linkblock->num_links_max);   html->linkblock->links[nl] = (*url) ? *url : NULL;   return html->linkblock->num_links++;}/* * Check an integer value to be inside a range. * Return: 'n' if valid, 'def' if not. */static int Html_check_int(int n, int min, int max, int def){   return (n >= min && n <= max) ? n : def;}/* * Allocate and insert form information into the Html linkblock */static gint Html_form_new(DilloHtmlLB *html_lb,                          DilloHtmlMethod method,                          const DilloUrl *action,                          DilloHtmlEnc enc){   gint nf;   a_List_add(html_lb->forms, html_lb->num_forms, html_lb->num_forms_max);   nf = html_lb->num_forms;   html_lb->forms[nf].method = method;   html_lb->forms[nf].action = a_Url_dup(action);   html_lb->forms[nf].enc = enc;   html_lb->forms[nf].num_inputs = 0;   html_lb->forms[nf].num_inputs_max = 4;   html_lb->forms[nf].inputs = NULL;   html_lb->forms[nf].num_entry_fields = 0;   html_lb->forms[nf].num_submit_buttons = 0;   html_lb->num_forms++;   _MSG("Html_form_new: action=%s nform=%d\n", action, nf);   return nf;}/* * Change one toplevel attribute. var should be an identifier. val is * only evaluated once, so you can safely use a function call for it. */#define HTML_SET_TOP_ATTR(html, var, val) \   do { \      DwStyle style_attrs, *old_style; \       \      old_style = (html)->stack[(html)->stack_top].style; \      style_attrs = *old_style; \      style_attrs.var = (val); \      (html)->stack[(html)->stack_top].style = \         a_Dw_style_new (&style_attrs, (html)->bw->main_window->window); \      a_Dw_style_unref (old_style); \   } while (FALSE)/* * Set the font at the top of the stack. BImask specifies which * attributes in BI should be changed. */static void Html_set_top_font(DilloHtml *html, gchar *name, gint size,                              gint BI, gint BImask){   DwStyleFont font_attrs;   font_attrs = *html->stack[(html)->stack_top].style->font;   if ( name )      font_attrs.name = name;   if ( size )      font_attrs.size = size;   if ( BImask & 1 )      font_attrs.weight   = (BI & 1) ? 700 : 400;   if ( BImask & 2 )      font_attrs.style = (BI & 2) ?         (prefs.use_oblique ?          DW_STYLE_FONT_STYLE_OBLIQUE : DW_STYLE_FONT_STYLE_ITALIC) :         DW_STYLE_FONT_STYLE_NORMAL;   HTML_SET_TOP_ATTR (html, font, a_Dw_style_font_new (&font_attrs));}/* * Evaluates the ALIGN attribute (left|center|right|justify) and * sets the style at the top of the stack. */static void Html_tag_set_align_attr(DilloHtml *html, char *tag, gint tagsize){   const char *align, *charattr;   if ((align = Html_get_attr(html, tag, tagsize, "align"))) {      if (g_strcasecmp (align, "left") == 0)         HTML_SET_TOP_ATTR (html, text_align, DW_STYLE_TEXT_ALIGN_LEFT);      else if (g_strcasecmp (align, "right") == 0)         HTML_SET_TOP_ATTR (html, text_align, DW_STYLE_TEXT_ALIGN_RIGHT);      else if (g_strcasecmp (align, "center") == 0)         HTML_SET_TOP_ATTR (html, text_align, DW_STYLE_TEXT_ALIGN_CENTER);      else if (g_strcasecmp (align, "justify") == 0)         HTML_SET_TOP_ATTR (html, text_align, DW_STYLE_TEXT_ALIGN_JUSTIFY);      else if (g_strcasecmp (align, "char") == 0) {         /* todo: Actually not supported for <p> etc. */         HTML_SET_TOP_ATTR (html, text_align, DW_STYLE_TEXT_ALIGN_STRING);         if ((charattr = Html_get_attr(html, tag, tagsize, "char"))) {            if (charattr[0] == 0)               /* todo: ALIGN=" ", and even ALIGN="&32;" will reult in                * an empty string (don't know whether the latter is                * correct, has to be clarified with the specs), so                * that for empty strings, " " is assumed. */               HTML_SET_TOP_ATTR (html, text_align_char, ' ');            else               HTML_SET_TOP_ATTR (html, text_align_char, charattr[0]);         } else            /* todo: Examine LANG attr of <html>. */            HTML_SET_TOP_ATTR (html, text_align_char, '.');      }   }}/* * Evaluates the VALIGN attribute (top|bottom|middle|baseline) and * sets the style in style_attrs. Returns TRUE when set. */static gboolean Html_tag_set_valign_attr(DilloHtml *html, char *tag,                                         gint tagsize, DwStyle *style_attrs){   const char *attr;   if ((attr = Html_get_attr(html, tag, tagsize, "valign"))) {      if (g_strcasecmp (attr, "top") == 0)         style_attrs->valign = DW_STYLE_VALIGN_TOP;      else if (g_strcasecmp (attr, "bottom") == 0)         style_attrs->valign = DW_STYLE_VALIGN_BOTTOM;      else if (g_strcasecmp (attr, "baseline") == 0)         style_attrs->valign = DW_STYLE_VALIGN_BASELINE;      else         style_attrs->valign = DW_STYLE_VALIGN_MIDDLE;      return TRUE;   } else      return FALSE;}/* * Add a new DwPage into the current DwPage, for indentation. * left and right are the horizontal indentation amounts, space is the * vertical space around the block. */static void Html_add_indented_widget(DilloHtml *html, DwWidget *page,                                     int left, int right, int space){   DwStyle style_attrs, *style;   style_attrs = *html->stack[html->stack_top].style;   a_Dw_style_box_set_val(&style_attrs.margin, 0);   a_Dw_style_box_set_val(&style_attrs.border_width, 0);   a_Dw_style_box_set_val(&style_attrs.padding, 0);   /* Activate this for debugging */#if 0   a_Dw_style_box_set_val(&style_attrs.border_width, 1);   a_Dw_style_box_set_border_color      (&style_attrs,       a_Dw_style_shaded_color_new(style_attrs.color->color_val,                                   html->bw->main_window->window));   a_Dw_style_box_set_border_style(&style_attrs, DW_STYLE_BORDER_DASHED);#endif   style_attrs.margin.left = left;   style_attrs.margin.right = right;   style = a_Dw_style_new (&style_attrs, html->bw->main_window->window);   a_Dw_page_add_parbreak (DW_PAGE (html->dw), space, style);   a_Dw_page_add_widget (DW_PAGE (html->dw), page, style);   a_Dw_page_add_parbreak (DW_PAGE (html->dw), space, style);   html->stack[html->stack_top].page = html->dw = page;   html->stack[html->stack_top].hand_over_break = TRUE;   a_Dw_style_unref (style);   /* Handle it when the user clicks on a link */   Html_connect_signals(html, GTK_OBJECT(page));}/* * Create and add a new indented DwPage to the current DwPage */static void Html_add_indented(DilloHtml *html, int left, int right, int space){   DwWidget *page = a_Dw_page_new ();   Html_add_indented_widget (html, page, left, right, space);}/* * Given a font_size, this will return the correct 'level'. * (or the closest, if the exact level isn't found). */static gint Html_fontsize_to_level(gint fontsize){   gint i, level;   gdouble normalized_size = fontsize / prefs.font_factor,           approximation   = FontSizes[FontSizesNum-1] + 1;   for (i = level = 0; i < FontSizesNum; i++)      if (approximation >= fabs(normalized_size - FontSizes[i])) {         approximation = fabs(normalized_size - FontSizes[i]);         level = i;      } else {         break;      }   return level;}/* * Given a level of a font, this will return the correct 'size'. */static gint Html_level_to_fontsize(gint level){   level = MAX(0, level);   level = MIN(FontSizesNum - 1, level);   return rint(FontSizes[level]*prefs.font_factor);}/* * Miscelaneous initializations for a DwPage */static void Html_set_dwpage(DilloHtml *html){   DwWidget *widget;   DwPage *page;   DwStyle style_attrs;   DwStyleFont font;   g_return_if_fail (html->dw == NULL);   widget = a_Dw_page_new ();   page = DW_PAGE (widget);   html->dw = html->stack[0].page = widget;   /* Create a dummy font, attribute, and tag for the bottom of the stack. */   font.name = prefs.vw_fontname; /* Helvetica */   font.size = Html_level_to_fontsize(FontSizesBase);   font.weight = 400;   font.style = DW_STYLE_FONT_STYLE_NORMAL;   a_Dw_style_init_values (&style_attrs, html->bw->main_window->window);   style_attrs.font = a_Dw_style_font_new (&font);   style_attrs.color = a_Dw_style_color_new (prefs.text_color,                                             html->bw->main_window->window);   html->stack[0].style = a_Dw_style_new (&style_attrs,                                          html->bw->main_window->window);   html->stack[0].table_cell_style = NULL;   /* Handle it when the user clicks on a link */   Html_connect_signals(html, GTK_OBJECT(widget));   gtk_signal_connect_while_alive (      GTK_OBJECT(GTK_BIN(html->bw->docwin)->child), "button_press_event",      GTK_SIGNAL_FUNC(Html_page_menu), (gpointer)html->bw, GTK_OBJECT (page));   /* Connect the "bug meter" button-press to the linkblock */   gtk_signal_connect_while_alive(      GTK_OBJECT (html->bw->status_bug_meter), "clicked",      GTK_SIGNAL_FUNC (a_Commands_view_page_bugs_callback),      (gpointer)html->linkblock, GTK_OBJECT (page));   gtk_signal_connect_while_alive(      GTK_OBJECT (html->bw->status_bug_meter), "clicked1",      GTK_SIGNAL_FUNC (a_Commands_view_page_bugs_callback),      (gpointer)html->linkblock, GTK_OBJECT (page));   /* also connect with the "View page Bugs" menuitem */   gtk_signal_connect_while_alive(      GTK_OBJECT (html->bw->viewbugs_menuitem), "activate",      GTK_SIGNAL_FUNC (a_Commands_view_page_bugs_callback),      (gpointer)html->linkblock, GTK_OBJECT (page));   /* Destroy the linkblock when the DwPage is destroyed */   gtk_signal_connect_object(GTK_OBJECT(page), "destroy",                             GTK_SIGNAL_FUNC(Html_lb_free),                             (gpointer)html->linkblock);}/* * Create and initialize a new DilloHtml structure */static DilloHtml *Html_new(BrowserWindow *bw, const DilloUrl *url){   DilloHtml *html;   html = g_new(DilloHtml, 1);   html->Start_Buf = NULL;   html->Start_Ofs = 0;   html->CurrTagOfs = 0;   html->OldTagOfs = 0;   html->OldTagLine = 1;   html->DocType = DT_NONE;    /* assume Tag Soup 0.0!   :-) */   html->DocTypeVersion = 0.0f;   html->dw = NULL;   html->bw = bw;   html->linkblock = Html_lb_new(bw, url);   html->stack_max = 16;   html->stack_top = 0;   html->stack = g_new(DilloHtmlState, html->stack_max);   html->stack[0].tag_name = g_strdup("none");   html->stack[0].style = NULL;   html->stack[0].table_cell_style = NULL;   html->stack[0].parse_mode = DILLO_HTML_PARSE_MODE_INIT;   html->stack[0].table_mode = DILLO_HTML_TABLE_MODE_NONE;   html->stack[0].cell_text_align_set = FALSE;   html->stack[0].list_type = HTML_LIST_NONE; /* no <ul> or <ol> open */   html->stack[0].list_number = 0;   html->stack[0].tag_idx = -1;               /* MUST not be used */   html->stack[0].page = NULL;   html->stack[0].table = NULL;   html->stack[0].ref_list_item = NULL;   html->stack[0].current_bg_color = prefs.bg_color;   html->stack[0].hand_over_break = FALSE;   html->Stash = g_string_new("");   html->StashSpace = FALSE;   html->SPCBuf = NULL;   html->pre_column = 0;   html->PreFirstChar = FALSE;   html->PrevWasCR = FALSE;   html->PrevWasOpenTag = FALSE;   html->SPCPending = FALSE;   html->InVisitedLink = FALSE;   html->ReqTagClose = FALSE;   html->CloseOneTag = FALSE;   html->TagSoup = TRUE;   html->NameVal = NULL;   html->Num_HTML = html->Num_HEAD = html->Num_BODY = html->Num_TITLE = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -