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

📄 html.c

📁 嵌入式下基于MiniGUI的Web Browser
💻 C
📖 第 1 页 / 共 5 页
字号:
}/* * 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, int 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, int 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, int 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, int 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, int 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");   }   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);    /* HEAD to BODY section transition was done by Html_test_body_section() */    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);            style = a_Dw_style_new (&style_attrs, html->bw->main_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));        }        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 &&            html->linkblock->link_color == html->linkblock->visited_color) {            /* get a color that has a "safe distance" from text, link and bg */            html->linkblock->visited_color =                a_Color_vc(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){   html->InFlags &= ~IN_BODY;   Html_pop_tag(html, TagIdx);}/* * <P> * todo: what's the point between adding the parbreak before and *       after the push? * todo: <P> should be closed upon openning a 'block' element. */static void Html_tag_open_p(DilloHtml *html, char *tag, int 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, int tagsize){#ifdef USE_TABLES    DwWidget *table;    DwStyle style_attrs, *tstyle, *old_style;    const char *attrbuf;    int 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 = isdigit(attrbuf[0]) ? strtol (attrbuf, NULL, 10) : 1;    if ((attrbuf = Html_get_attr(html, tag, tagsize, "cellspacing")))        cellspacing = strtol (attrbuf, NULL, 10);    if ((attrbuf = Html_get_attr(html, tag, tagsize, "cellpadding")))        cellpadding = strtol (attrbuf, NULL, 10);    /* 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));    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")))        style_attrs.width = Html_parse_length (html, attrbuf);    if ((attrbuf = Html_get_attr(html, tag, tagsize, "align"))) {        if (strcasecmp (attrbuf, "left") == 0)            style_attrs.text_align = DW_STYLE_TEXT_ALIGN_LEFT;        else if (strcasecmp (attrbuf, "right") == 0)            style_attrs.text_align = DW_STYLE_TEXT_ALIGN_RIGHT;        else if (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);        }    }    tstyle = a_Dw_style_new (&style_attrs, html->bw->main_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);    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, int tagsize,                                     DwStyleTextAlignType text_align){#ifdef USE_TABLES    DwWidget *col_page;    int 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);        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);                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);            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, G_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, int tagsize){#if 0    Html_cleanup_tag(html, "td>");    Html_cleanup_tag(html, "th>");    Html_push_tag(html, tag, tagsize);#endif    Html_tag_open_table_cell (html, tag, tagsize, DW_STYLE_TEXT_ALIGN_LEFT);}/* * <TH> */static void Html_tag_open_th(DilloHtml *html, char *tag, int tagsize){#if 0    Html_cleanup_tag(html, "td>");    Html_cleanup_tag(html, "th>");    Html_push_tag(html, tag, tagsize);#endif    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, int tagsize){    const char *attrbuf;    DwStyle style_attrs, *style, *old_style;    guint32 bgcolor;#if 0    Html_cleanup_tag(html, "td>");    Html_cleanup_tag(html, "th>");    Html_cleanup_tag(html, "tr>");    Html_push_tag(html, tag, tagsize);#endif#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);                style =                    a_Dw_style_new (&style_attrs, html->bw->main_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);       

⌨️ 快捷键说明

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