📄 html.c
字号:
/* 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 = strtol (attrbuf, NULL, 10); if ((attrbuf = Html_get_attr(html, tag, tagsize, "rowspan"))) rowspan = strtol (attrbuf, NULL, 10); /* 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); html->stack[html->stack_top].page = html->dw = col_page; /* Handle it when the user clicks on a link */ Html_connect_signals(html, GTK_OBJECT(col_page)); break; default: /* compiler happiness */ break; } html->stack[html->stack_top].table_mode = DILLO_HTML_TABLE_MODE_TD;#endif}/* * <TD> */static void Html_tag_open_td(DilloHtml *html, char *tag, gint tagsize){ Html_cleanup_tag(html, "td>"); Html_cleanup_tag(html, "th>"); Html_push_tag(html, tag, tagsize); Html_tag_open_table_cell (html, tag, tagsize, DW_STYLE_TEXT_ALIGN_LEFT);}/* * <TH> */static void Html_tag_open_th(DilloHtml *html, char *tag, gint tagsize){ Html_cleanup_tag(html, "td>"); Html_cleanup_tag(html, "th>"); Html_push_tag(html, tag, tagsize); Html_set_top_font(html, NULL, 0, 1, 1); Html_tag_open_table_cell (html, tag, tagsize, DW_STYLE_TEXT_ALIGN_CENTER);}/* * <TR> */static void Html_tag_open_tr(DilloHtml *html, char *tag, gint tagsize){ const char *attrbuf; DwStyle style_attrs, *style, *old_style; gint32 bgcolor; Html_cleanup_tag(html, "td>"); Html_cleanup_tag(html, "th>"); Html_cleanup_tag(html, "tr>"); Html_push_tag(html, tag, tagsize);#ifdef USE_TABLES switch (html->stack[html->stack_top].table_mode) { case DILLO_HTML_TABLE_MODE_NONE: _MSG("Invalid HTML syntax: <tr> outside <table>\n"); return; case DILLO_HTML_TABLE_MODE_TOP: case DILLO_HTML_TABLE_MODE_TR: case DILLO_HTML_TABLE_MODE_TD: style = NULL; 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; style_attrs = *html->stack[html->stack_top].style; style_attrs.background_color = a_Dw_style_color_new (bgcolor, html->bw->main_window->window); style = a_Dw_style_new (&style_attrs, html->bw->main_window->window); html->stack[html->stack_top].current_bg_color = bgcolor; } } a_Dw_table_add_row (DW_TABLE (html->stack[html->stack_top].table), style); if (style) a_Dw_style_unref (style); if (Html_get_attr (html, tag, tagsize, "align")) { html->stack[html->stack_top].cell_text_align_set = TRUE; Html_tag_set_align_attr (html, tag, tagsize); } style_attrs = *html->stack[html->stack_top].table_cell_style; if (Html_tag_set_valign_attr (html, tag, tagsize, &style_attrs)) { 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); a_Dw_style_unref (old_style); } else break; default: break; } html->stack[html->stack_top].table_mode = DILLO_HTML_TABLE_MODE_TR;#else a_Dw_page_add_parbreak(DW_PAGE (html->dw), 0, html->stack[(html)->stack_top].style);#endif}/* * <FRAME>, <IFRAME> * todo: This is just a temporary fix while real frame support * isn't finished. Imitates lynx/w3m's frames. */static void Html_tag_open_frame (DilloHtml *html, gchar *tag, gint tagsize){ const char *attrbuf; gchar *src, *buf; DilloUrl *url; DwPage *page; DwStyle style_attrs, *link_style; DwWidget *bullet; gint buf_size; page = DW_PAGE(html->dw); if ( !(attrbuf = Html_get_attr(html, tag, tagsize, "src")) ) return; if (!(url = Html_url_new(html, attrbuf, NULL, 0, 0, 0, 0))) return; src = g_strdup(attrbuf); style_attrs = *(html->stack[html->stack_top].style); if (a_Capi_get_buf(url, &buf, &buf_size)) /* visited frame */ style_attrs.color = a_Dw_style_color_new (html->linkblock->visited_color, html->bw->main_window->window); else /* unvisited frame */ style_attrs.color = a_Dw_style_color_new (html->linkblock->link_color, html->bw->main_window->window); style_attrs.text_decoration |= DW_STYLE_TEXT_DECORATION_UNDERLINE; style_attrs.x_link = Html_set_new_link(html, &url); link_style = a_Dw_style_new (&style_attrs, html->bw->main_window->window); a_Dw_page_add_parbreak(page, 5, html->stack[(html)->stack_top].style); /* The bullet will be assigned the current list style, which should * be "disc" by default, but may in very weird pages be different. * Anyway, there should be no harm. */ bullet = a_Dw_bullet_new(); a_Dw_page_add_widget(page, bullet, html->stack[html->stack_top].style); a_Dw_page_add_space(page, html->stack[html->stack_top].style); if (tolower(tag[1]) == 'i') { /* IFRAME usually comes with very long advertising/spying URLS, * to not break rendering we will force name="IFRAME" */ a_Dw_page_add_text(page, g_strdup("IFRAME"), link_style); } else { /* FRAME: * If 'name' tag is present use it, if not use 'src' value */ if ( !(attrbuf = Html_get_attr(html, tag, tagsize, "name")) ) { a_Dw_page_add_text(page, g_strdup(src), link_style); } else { a_Dw_page_add_text(page, g_strdup(attrbuf), link_style); } } a_Dw_page_add_parbreak(page, 5, html->stack[(html)->stack_top].style); a_Dw_style_unref(link_style); g_free(src);}/* * <FRAMESET> * todo: This is just a temporary fix while real frame support * isn't finished. Imitates lynx/w3m's frames. */static void Html_tag_open_frameset (DilloHtml *html, gchar *tag, gint tagsize){ Html_par_push_tag(html, tag, tagsize); a_Dw_page_add_text(DW_PAGE(html->dw), g_strdup("--FRAME--"), html->stack[html->stack_top].style); Html_add_indented(html, 40, 0, 5);}/* * <H1> | <H2> | <H3> | <H4> | <H5> | <H6> */static void Html_tag_open_h(DilloHtml *html, char *tag, gint tagsize){ Html_par_push_tag(html, tag, tagsize); /* todo: combining these two would be slightly faster */ Html_set_top_font(html, prefs.vw_fontname, Html_level_to_fontsize(FontSizesNum - (tag[2] - '0')), 1, 3); Html_tag_set_align_attr (html, tag, tagsize); /* First finalize unclosed H tags (we test if already named anyway) */ a_Menu_pagemarks_set_text(html->bw, html->Stash->str); a_Menu_pagemarks_add(html->bw, DW_PAGE (html->dw), html->stack[html->stack_top].style, (tag[2] - '0')); Html_stash_init(html); html->stack[html->stack_top].parse_mode = DILLO_HTML_PARSE_MODE_STASH_AND_BODY;}/* * Handle close: <H1> | <H2> | <H3> | <H4> | <H5> | <H6> */static void Html_tag_close_h(DilloHtml *html, char *tag, gint tagsize){ a_Menu_pagemarks_set_text(html->bw, html->Stash->str); Html_pop_tag(html, tag, tagsize); a_Dw_page_add_parbreak(DW_PAGE (html->dw), 9, html->stack[(html)->stack_top].style);}/* * <BIG> | <SMALL> */static void Html_tag_open_big_small(DilloHtml *html, char *tag, gint tagsize){ gint level; Html_push_tag(html, tag, tagsize); level = Html_fontsize_to_level(html->stack[html->stack_top].style->font->size) + ((g_strncasecmp(tag+1, "big", 3)) ? -1 : 1); Html_set_top_font(html, NULL, Html_level_to_fontsize(level), 0, 0);}/* * <BR> */static void Html_tag_open_br(DilloHtml *html, char *tag, gint tagsize){ a_Dw_page_add_linebreak(DW_PAGE (html->dw), html->stack[(html)->stack_top].style);}/* * <BUTTON> */static void Html_tag_open_button(DilloHtml *html, char *tag, gint tagsize){ /* * Buttons are rendered on one line, this is (at several levels) a * bit simpler. May be changed in the future. */ DwStyle style_attrs, *style; DwWidget *button, *page; DilloHtmlForm *form; DilloHtmlLB *html_lb; DilloHtmlInputType inp_type; gchar *name, *value, *type; /* Render the button */ Html_push_tag(html, tag, tagsize); 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); style = a_Dw_style_new (&style_attrs, html->bw->main_window->window); button = a_Dw_button_new (DW_USES_HINTS, TRUE); /* The new button is not set button-insensitive, since nested buttons * (if they a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -