📄 html.c
字号:
if (html->Num_HTML == 1) { /* beware of pages with multiple HTML close tags... :-P */ html->InFlags &= ~IN_HTML; } Html_pop_tag(html, TagIdx);}/* * Handle open HEAD element */static void Html_tag_open_head(DilloHtml *html, char *tag, gint tagsize){ if (html->InFlags & IN_BODY) { MSG_HTML("HEAD element must go before the BODY section\n"); html->ReqTagClose = TRUE; return; } if (!(html->InFlags & IN_HEAD)) html->InFlags |= IN_HEAD; ++html->Num_HEAD; if (html->Num_HEAD > 1) { MSG_HTML("HEAD element was already open\n"); }}/* * Handle close HEAD element * Note: as a side effect of Html_test_section() this function is called * twice when the head element is closed implicitly. */static void Html_tag_close_head(DilloHtml *html, gint TagIdx){ if (html->InFlags & IN_HEAD) { if (html->Num_TITLE == 0) MSG_HTML("HEAD section lacks the TITLE element\n"); html->InFlags &= ~IN_HEAD; } Html_pop_tag(html, TagIdx);}/* * Handle open TITLE * calls stash init, where the title string will be stored */static void Html_tag_open_title(DilloHtml *html, char *tag, gint tagsize){ ++html->Num_TITLE; Html_stash_init(html);}/* * Handle close TITLE * set page-title in the browser window and in the history. */static void Html_tag_close_title(DilloHtml *html, gint TagIdx){ if (html->InFlags & IN_HEAD) { /* title is only valid inside HEAD */ a_Interface_set_page_title(html->linkblock->bw, html->Stash->str); a_History_set_title(NAV_TOP(html->linkblock->bw), html->Stash->str); } else { MSG_HTML("the TITLE element must be inside the HEAD section\n"); } Html_pop_tag(html, TagIdx);}/* * Handle open SCRIPT * initializes stash, where the embedded code will be stored. * MODE_VERBATIM is used because MODE_STASH catches entities. */static void Html_tag_open_script(DilloHtml *html, char *tag, gint tagsize){ Html_stash_init(html); html->stack[html->stack_top].parse_mode = DILLO_HTML_PARSE_MODE_VERBATIM;}/* * Handle close SCRIPT */static void Html_tag_close_script(DilloHtml *html, gint TagIdx){ /* eventually the stash will be sent to an interpreter for parsing */ Html_pop_tag(html, TagIdx);}/* * Handle open STYLE * store the contents to the stash where (in the future) the style * sheet interpreter can get it. */static void Html_tag_open_style(DilloHtml *html, char *tag, gint tagsize){ Html_stash_init(html); html->stack[html->stack_top].parse_mode = DILLO_HTML_PARSE_MODE_VERBATIM;}/* * Handle close STYLE */static void Html_tag_close_style(DilloHtml *html, gint TagIdx){ /* eventually the stash will be sent to an interpreter for parsing */ Html_pop_tag(html, TagIdx);}/* * <BODY> */static void Html_tag_open_body(DilloHtml *html, char *tag, gint tagsize){ const char *attrbuf; DwPage *page; DwStyle style_attrs, *style; gint32 color; if (!(html->InFlags & IN_BODY)) html->InFlags |= IN_BODY; ++html->Num_BODY; if (html->Num_BODY > 1) { MSG_HTML("BODY element was already open\n"); return; } if (html->InFlags & IN_HEAD) { /* if we're here, it's bad XHTML, no need to recover */ MSG_HTML("unclosed HEAD element\n"); } page = DW_PAGE (html->dw); if (!prefs.force_my_colors) { if ((attrbuf = Html_get_attr(html, tag, tagsize, "bgcolor"))) { color = Html_color_parse(html, attrbuf, prefs.bg_color); if ( (color == 0xffffff && !prefs.allow_white_bg) || prefs.force_my_colors ) color = prefs.bg_color; style_attrs = *html->dw->style; style_attrs.background_color = a_Dw_style_color_new (color, html->bw->main_window->window); style = a_Dw_style_new (&style_attrs, html->bw->main_window->window); a_Dw_widget_set_style (html->dw, style); a_Dw_style_unref (style); html->stack[html->stack_top].current_bg_color = color; } if ((attrbuf = Html_get_attr(html, tag, tagsize, "text"))) { color = Html_color_parse(html, attrbuf, prefs.text_color); HTML_SET_TOP_ATTR (html, color, a_Dw_style_color_new (color, html->bw->main_window->window)); } if ((attrbuf = Html_get_attr(html, tag, tagsize, "link"))) html->linkblock->link_color = Html_color_parse(html, attrbuf, prefs.link_color); if ((attrbuf = Html_get_attr(html, tag, tagsize, "vlink"))) html->linkblock->visited_color = Html_color_parse(html, attrbuf, prefs.visited_color); if (prefs.contrast_visited_color) { /* get a color that has a "safe distance" from text, link and bg */ html->linkblock->visited_color = a_Color_vc(html->linkblock->visited_color, html->stack[html->stack_top].style->color->color_val, html->linkblock->link_color, html->stack[html->stack_top].current_bg_color); } } html->stack[html->stack_top].parse_mode = DILLO_HTML_PARSE_MODE_BODY;}/* * BODY */static void Html_tag_close_body(DilloHtml *html, gint TagIdx){ if (html->Num_BODY == 1) { /* some tag soup pages use multiple BODY tags... */ html->InFlags &= ~IN_BODY; } Html_pop_tag(html, TagIdx);}/* * <P> * todo: what's the point between adding the parbreak before and * after the push? */static void Html_tag_open_p(DilloHtml *html, char *tag, gint tagsize){ a_Dw_page_add_parbreak(DW_PAGE (html->dw), 9, html->stack[(html)->stack_top].style); Html_tag_set_align_attr (html, tag, tagsize);}/* * <TABLE> */static void Html_tag_open_table(DilloHtml *html, char *tag, gint tagsize){#ifdef USE_TABLES DwWidget *table; DwStyle style_attrs, *tstyle, *old_style; const char *attrbuf; gint32 border = 0, cellspacing = 1, cellpadding = 2, bgcolor;#endif a_Dw_page_add_parbreak(DW_PAGE (html->dw), 0, html->stack[(html)->stack_top].style);#ifdef USE_TABLES if ((attrbuf = Html_get_attr(html, tag, tagsize, "border"))) border = *attrbuf ? Html_check_int(strtol(attrbuf,NULL,10), 0,100,1) : 1; if ((attrbuf = Html_get_attr(html, tag, tagsize, "cellspacing"))) cellspacing = Html_check_int(strtol(attrbuf, NULL, 10), 0, 100, 1); if ((attrbuf = Html_get_attr(html, tag, tagsize, "cellpadding"))) cellpadding = Html_check_int(strtol(attrbuf, NULL, 10), 0, 100, 2); /* The style for the table */ style_attrs = *html->stack[html->stack_top].style; /* When dillo was started with the --debug-rendering option, there * is always a border around the table. */ if (dillo_dbg_rendering) a_Dw_style_box_set_val (&style_attrs.border_width, MIN (border, 1)); else a_Dw_style_box_set_val (&style_attrs.border_width, border); a_Dw_style_box_set_border_color (&style_attrs, a_Dw_style_shaded_color_new ( html->stack[html->stack_top].current_bg_color, html->bw->main_window->window)); a_Dw_style_box_set_border_style (&style_attrs, DW_STYLE_BORDER_OUTSET); style_attrs.border_spacing = cellspacing; if ((attrbuf = Html_get_attr(html, tag, tagsize, "width"))) { int dw_len = Html_parse_length (html, attrbuf); int len = strtol(attrbuf, NULL, 10); if ((DW_STYLE_IS_PER_LENGTH(dw_len) && Html_check_int(len, 0, 100, -1) != -1) || (DW_STYLE_IS_ABS_LENGTH(dw_len) && Html_check_int(len, 0, 5000, -1) != -1) || (DW_STYLE_IS_REL_LENGTH(dw_len) && Html_check_int(len, 0, 100, -1) != -1)) { style_attrs.width = dw_len; } } if ((attrbuf = Html_get_attr(html, tag, tagsize, "align"))) { if (g_strcasecmp (attrbuf, "left") == 0) style_attrs.text_align = DW_STYLE_TEXT_ALIGN_LEFT; else if (g_strcasecmp (attrbuf, "right") == 0) style_attrs.text_align = DW_STYLE_TEXT_ALIGN_RIGHT; else if (g_strcasecmp (attrbuf, "center") == 0) style_attrs.text_align = DW_STYLE_TEXT_ALIGN_CENTER; } if (!prefs.force_my_colors && (attrbuf = Html_get_attr(html, tag, tagsize, "bgcolor"))) { bgcolor = Html_color_parse(html, attrbuf, -1); if (bgcolor != -1) { if (bgcolor == 0xffffff && !prefs.allow_white_bg) bgcolor = prefs.bg_color; html->stack[html->stack_top].current_bg_color = bgcolor; style_attrs.background_color = a_Dw_style_color_new (bgcolor, html->bw->main_window->window); } } tstyle = a_Dw_style_new (&style_attrs, html->bw->main_window->window); /* The style for the cells */ style_attrs = *html->stack[html->stack_top].style; /* When dillo was started with the --debug-rendering option, there * is always a border around the cells. */ if (dillo_dbg_rendering) a_Dw_style_box_set_val (&style_attrs.border_width, 1); else a_Dw_style_box_set_val (&style_attrs.border_width, border ? 1 : 0); a_Dw_style_box_set_val (&style_attrs.padding, cellpadding); a_Dw_style_box_set_border_color (&style_attrs, tstyle->border_color.top); a_Dw_style_box_set_border_style (&style_attrs, DW_STYLE_BORDER_INSET); old_style = html->stack[html->stack_top].table_cell_style; html->stack[html->stack_top].table_cell_style = a_Dw_style_new (&style_attrs, html->bw->main_window->window); if (old_style) a_Dw_style_unref (old_style); table = a_Dw_table_new (); a_Dw_page_add_widget (DW_PAGE (html->dw), table, tstyle); a_Dw_style_unref (tstyle); html->stack[html->stack_top].table_mode = DILLO_HTML_TABLE_MODE_TOP; html->stack[html->stack_top].cell_text_align_set = FALSE; html->stack[html->stack_top].table = table;#endif}/* * used by <TD> and <TH> */static void Html_tag_open_table_cell(DilloHtml *html, char *tag, gint tagsize, DwStyleTextAlignType text_align){#ifdef USE_TABLES DwWidget *col_page; gint colspan = 1, rowspan = 1; const char *attrbuf; DwStyle style_attrs, *style, *old_style; gint32 bgcolor; gboolean new_style; switch (html->stack[html->stack_top].table_mode) { case DILLO_HTML_TABLE_MODE_NONE: MSG_HTML("<td> or <th> outside <table>\n"); return; case DILLO_HTML_TABLE_MODE_TOP: MSG_HTML("<td> or <th> outside <tr>\n"); /* a_Dw_table_add_cell takes care that dillo does not crash. */ /* continues */ case DILLO_HTML_TABLE_MODE_TR: case DILLO_HTML_TABLE_MODE_TD: /* todo: check errors? */ if ((attrbuf = Html_get_attr(html, tag, tagsize, "colspan"))) colspan = Html_check_int(strtol(attrbuf, NULL, 10), 0, 1000, 1); if ((attrbuf = Html_get_attr(html, tag, tagsize, "rowspan"))) rowspan = Html_check_int(strtol(attrbuf, NULL, 10), 0, 1000, 1); /* text style */ old_style = html->stack[html->stack_top].style; style_attrs = *old_style; if (!html->stack[html->stack_top].cell_text_align_set) style_attrs.text_align = text_align; if (Html_get_attr(html, tag, tagsize, "nowrap")) style_attrs.white_space = DW_STYLE_WHITE_SPACE_NOWRAP; else style_attrs.white_space = DW_STYLE_WHITE_SPACE_NORMAL; html->stack[html->stack_top].style = a_Dw_style_new (&style_attrs, html->bw->main_window->window); a_Dw_style_unref (old_style); Html_tag_set_align_attr (html, tag, tagsize); /* cell style */ style_attrs = *html->stack[html->stack_top].table_cell_style; new_style = FALSE; if ((attrbuf = Html_get_attr(html, tag, tagsize, "width"))) { style_attrs.width = Html_parse_length (html, attrbuf); new_style = TRUE; } if (Html_tag_set_valign_attr (html, tag, tagsize, &style_attrs)) new_style = TRUE; if (!prefs.force_my_colors && (attrbuf = Html_get_attr(html, tag, tagsize, "bgcolor"))) { bgcolor = Html_color_parse(html, attrbuf, -1); if (bgcolor != -1) { if (bgcolor == 0xffffff && !prefs.allow_white_bg) bgcolor = prefs.bg_color; new_style = TRUE; style_attrs.background_color = a_Dw_style_color_new (bgcolor, html->bw->main_window->window); html->stack[html->stack_top].current_bg_color = bgcolor; } } if (html->stack[html->stack_top].style->text_align == DW_STYLE_TEXT_ALIGN_STRING) col_page = a_Dw_table_cell_new (a_Dw_table_get_cell_ref (DW_TABLE (html->stack[html->stack_top].table))); else col_page = a_Dw_page_new (); if (new_style) { style = a_Dw_style_new (&style_attrs, html->bw->main_window->window); a_Dw_widget_set_style (col_page, style); a_Dw_style_unref (style); } else a_Dw_widget_set_style (col_page, html->stack[html->stack_top].table_cell_style); a_Dw_table_add_cell (DW_TABLE (html->stack[html->stack_top].table), col_page, colspan, rowspan);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -