diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/css.cc | 8 | ||||
-rw-r--r-- | src/css.hh | 31 | ||||
-rw-r--r-- | src/form.cc | 7 | ||||
-rw-r--r-- | src/html.cc | 219 | ||||
-rw-r--r-- | src/html_common.hh | 7 | ||||
-rw-r--r-- | src/prefs.c | 1 | ||||
-rw-r--r-- | src/prefs.h | 1 | ||||
-rw-r--r-- | src/prefsparser.cc | 7 | ||||
-rw-r--r-- | src/styleengine.cc | 117 | ||||
-rw-r--r-- | src/styleengine.hh | 46 | ||||
-rw-r--r-- | src/table.cc | 168 | ||||
-rw-r--r-- | src/uicmd.cc | 4 | ||||
-rw-r--r-- | src/web.cc | 5 |
13 files changed, 333 insertions, 288 deletions
@@ -428,7 +428,7 @@ void CssStyleSheet::apply (CssPropertyList *props, } } - ruleList[numLists] = elementTable[docTree->top ()->element]; + ruleList[numLists] = elementTable[node->element]; if (ruleList[numLists]) numLists++; @@ -512,9 +512,8 @@ CssContext::~CssContext () { * This allows e.g. user styles to overwrite author styles. */ void CssContext::apply (CssPropertyList *props, Doctree *docTree, + DoctreeNode *node, CssPropertyList *tagStyle, CssPropertyList *nonCssHints) { - const DoctreeNode *node = docTree->top (); - if (sheet[CSS_PRIMARY_USER_AGENT]) sheet[CSS_PRIMARY_USER_AGENT]->apply (props, docTree, node); @@ -558,8 +557,7 @@ void CssContext::addRule (CssSelector *sel, CssPropertyList *props, */ void CssContext::buildUserAgentStyle () { const char *cssBuf = - "body {background-color: #e0e0a3; font-family: sans-serif; color: black;" - " margin: 5px}" + "body {margin: 5px}" "big {font-size: 1.17em}" "blockquote, dd {margin-left: 40px; margin-right: 40px}" "center {text-align: center}" @@ -304,25 +304,30 @@ class CssPropertyList : public lout::misc::SimpleVector <CssProperty> { refCount = 0; this->ownerOfStrings = ownerOfStrings; }; - inline CssPropertyList(const CssPropertyList &p) : + inline CssPropertyList(const CssPropertyList &p, bool deep = false) : lout::misc::SimpleVector <CssProperty> (p) { refCount = 0; - ownerOfStrings = false; + if (deep) { + for (int i = 0; i < size (); i++) { + CssProperty *p = getRef(i); + switch (p->type) { + case CSS_TYPE_STRING: + case CSS_TYPE_SYMBOL: + p->value.strVal = dStrdup (p->value.strVal); + break; + default: + break; + } + } + ownerOfStrings = true; + } else { + ownerOfStrings = false; + } }; ~CssPropertyList (); void set (CssPropertyName name, CssValueType type, CssPropertyValue value); - inline void set (CssPropertyName name, CssValueType type, char *value) { - CssPropertyValue v; - v.strVal = value; - set (name, type, v); - }; - inline void set (CssPropertyName name, CssValueType type, int value) { - CssPropertyValue v; - v.intVal = value; - set (name, type, v); - }; void apply (CssPropertyList *props); void print (); inline void ref () { refCount++; } @@ -488,7 +493,7 @@ class CssContext { void addRule (CssSelector *sel, CssPropertyList *props, CssPrimaryOrder order); void apply (CssPropertyList *props, - Doctree *docTree, + Doctree *docTree, DoctreeNode *node, CssPropertyList *tagStyle, CssPropertyList *nonCssHints); }; diff --git a/src/form.cc b/src/form.cc index 38afea8f..a74bcdd6 100644 --- a/src/form.cc +++ b/src/form.cc @@ -554,12 +554,9 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize) } if (prefs.show_tooltip && (attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) { - CssPropertyList props; - char *tooltip_str = dStrdup(attrbuf); - props.set (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, tooltip_str); - html->styleEngine->setNonCssHints (&props); - dFree(tooltip_str); + html->styleEngine->setNonCssHint (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, + attrbuf); } HT2TB(html)->addWidget (embed, html->styleEngine->backgroundStyle()); } diff --git a/src/html.cc b/src/html.cc index 278868a5..1f69e21e 100644 --- a/src/html.cc +++ b/src/html.cc @@ -304,9 +304,7 @@ static void Html_add_new_htmlimage(DilloHtml *html, * Evaluates the ALIGN attribute (left|center|right|justify) and * sets the style at the top of the stack. */ -void a_Html_tag_set_align_attr(DilloHtml *html, - CssPropertyList *props, - const char *tag, int tagsize) +void a_Html_tag_set_align_attr(DilloHtml *html, const char *tag, int tagsize) { const char *align; @@ -339,7 +337,8 @@ void a_Html_tag_set_align_attr(DilloHtml *html, style_attrs.textAlignChar = '.'; } #endif - props->set (CSS_PROPERTY_TEXT_ALIGN, CSS_TYPE_ENUM, textAlignType); + html->styleEngine->setNonCssHint(CSS_PROPERTY_TEXT_ALIGN, CSS_TYPE_ENUM, + textAlignType); } } @@ -347,8 +346,7 @@ void a_Html_tag_set_align_attr(DilloHtml *html, * Evaluates the VALIGN attribute (top|bottom|middle|baseline) and * sets the style in style_attrs. Returns true when set. */ -bool a_Html_tag_set_valign_attr(DilloHtml *html, const char *tag, - int tagsize, CssPropertyList *props) +bool a_Html_tag_set_valign_attr(DilloHtml *html, const char *tag, int tagsize) { const char *attr; VAlignType valign; @@ -363,7 +361,8 @@ bool a_Html_tag_set_valign_attr(DilloHtml *html, const char *tag, else valign = VALIGN_MIDDLE; - props->set (CSS_PROPERTY_VERTICAL_ALIGN, CSS_TYPE_ENUM, valign); + html->styleEngine->setNonCssHint (CSS_PROPERTY_VERTICAL_ALIGN, + CSS_TYPE_ENUM, valign); return true; } else return false; @@ -427,7 +426,6 @@ DilloHtml::DilloHtml(BrowserWindow *p_bw, const DilloUrl *url, stack = new misc::SimpleVector <DilloHtmlState> (16); stack->increase(); - stack->getRef(0)->table_cell_props = NULL; stack->getRef(0)->parse_mode = DILLO_HTML_PARSE_MODE_INIT; stack->getRef(0)->table_mode = DILLO_HTML_TABLE_MODE_NONE; stack->getRef(0)->cell_text_align_set = false; @@ -580,9 +578,6 @@ int DilloHtml::getCurTagLineNumber() */ void DilloHtml::freeParseData() { - for (int i = stack->size () - 1; i >= 0; i--) - if (stack->getRef (i)->table_cell_props) - stack->getRef (i)->table_cell_props->unref (); delete(stack); dStr_free(Stash, TRUE); @@ -1278,8 +1273,6 @@ static void Html_push_tag(DilloHtml *html, int tag_idx) * instead of copying all fields except for tag. --Jcid */ *html->stack->getRef(n_items) = *html->stack->getRef(n_items - 1); html->stack->getRef(n_items)->tag_idx = tag_idx; - if (S_TOP(html)->table_cell_props) - S_TOP(html)->table_cell_props->ref (); html->dw = S_TOP(html)->textblock; } @@ -1301,8 +1294,6 @@ static void Html_real_pop_tag(DilloHtml *html) bool hand_over_break; html->styleEngine->endElement (S_TOP(html)->tag_idx); - if (S_TOP(html)->table_cell_props) - S_TOP(html)->table_cell_props->unref (); hand_over_break = S_TOP(html)->hand_over_break; html->stack->setSize (html->stack->size() - 1); Html_eventually_pop_dw(html, hand_over_break); @@ -1722,9 +1713,9 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) { const char *attrbuf; Textblock *textblock; - CssPropertyList props; int32_t color; int tag_index_a = a_Html_tag_index ("a"); + style::Color *bgColor; if (!(html->InFlags & IN_BODY)) html->InFlags |= IN_BODY; @@ -1744,24 +1735,32 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) { color = a_Html_color_parse(html, attrbuf, -1); if (color != -1) - props.set (CSS_PROPERTY_BACKGROUND_COLOR, CSS_TYPE_COLOR, color); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BACKGROUND_COLOR, + CSS_TYPE_COLOR, color); } if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "text"))) { color = a_Html_color_parse(html, attrbuf, -1); if (color != -1) - props.set (CSS_PROPERTY_COLOR, CSS_TYPE_COLOR, color); + html->styleEngine->setNonCssHint (CSS_PROPERTY_COLOR, + CSS_TYPE_COLOR, color); } + html->styleEngine->restyle (); + if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "link"))) html->non_css_link_color = a_Html_color_parse(html, attrbuf, -1); if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "vlink"))) html->non_css_visited_color = a_Html_color_parse(html, attrbuf, -1); - html->styleEngine->setNonCssHints (&props); html->dw->setStyle (html->styleEngine->style ()); + bgColor = html->styleEngine->backgroundColor (); + + if (bgColor) + HT2LT(html)->setBgColor(bgColor); + /* Determine a color for visited links. * This color is computed once per page and used for immediate feedback * when clicking a link. @@ -1771,10 +1770,8 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) html->styleEngine->startElement (tag_index_a); html->styleEngine->setPseudoVisited (); if (html->non_css_visited_color != -1) { - CssPropertyList vprops; - vprops.set (CSS_PROPERTY_COLOR, CSS_TYPE_COLOR, - html->non_css_visited_color); - html->styleEngine->setNonCssHints (&vprops); + html->styleEngine->setNonCssHint (CSS_PROPERTY_COLOR, CSS_TYPE_COLOR, + html->non_css_visited_color); } html->visited_color = html->styleEngine->style ()->color->getColor (); html->styleEngine->endElement (tag_index_a); @@ -1788,6 +1785,7 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) html->styleEngine->backgroundStyle()->backgroundColor->getColor()); } + S_TOP(html)->parse_mode = DILLO_HTML_PARSE_MODE_BODY; } @@ -1811,9 +1809,8 @@ static void Html_tag_open_p(DilloHtml *html, const char *tag, int tagsize) { CssPropertyList props; - a_Html_tag_set_align_attr (html, &props, tag, tagsize); + a_Html_tag_set_align_attr (html, tag, tagsize); html->styleEngine->inheritBackgroundColor (); - html->styleEngine->setNonCssHints (&props); HT2TB(html)->addParbreak (9, html->styleEngine->wordStyle ()); } @@ -1849,8 +1846,8 @@ static void Html_tag_open_frame (DilloHtml *html, const char *tag, int tagsize) html->styleEngine->setPseudoLink (); } - props.set (PROPERTY_X_LINK, CSS_TYPE_INTEGER, Html_set_new_link(html,&url)); - html->styleEngine->setNonCssHints (&props); + html->styleEngine->setNonCssHint (PROPERTY_X_LINK, CSS_TYPE_INTEGER, + Html_set_new_link(html,&url)); textblock->addParbreak (5, html->styleEngine->wordStyle ()); @@ -1896,12 +1893,8 @@ static void Html_tag_open_frameset (DilloHtml *html, */ static void Html_tag_open_h(DilloHtml *html, const char *tag, int tagsize) { - CssPropertyList props; - - html->styleEngine->inheritBackgroundColor (); - a_Html_tag_set_align_attr (html, &props, tag, tagsize); - html->styleEngine->setNonCssHints (&props); + a_Html_tag_set_align_attr (html, tag, tagsize); HT2TB(html)->addParbreak (9, html->styleEngine->wordStyle ()); @@ -1926,7 +1919,6 @@ static void Html_tag_open_font(DilloHtml *html, const char *tag, int tagsize) const char *attrbuf; char *fontFamily = NULL; int32_t color; - CssPropertyList props; if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "color"))) { if (prefs.contrast_visited_color && html->InVisitedLink) { @@ -1936,15 +1928,16 @@ static void Html_tag_open_font(DilloHtml *html, const char *tag, int tagsize) color = a_Html_color_parse(html, attrbuf, -1); } if (color != -1) - props.set (CSS_PROPERTY_COLOR, CSS_TYPE_COLOR, color); + html->styleEngine->setNonCssHint (CSS_PROPERTY_COLOR, + CSS_TYPE_COLOR, color); } if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "face"))) { fontFamily = dStrdup(attrbuf); - props.set (CSS_PROPERTY_FONT_FAMILY, CSS_TYPE_SYMBOL, fontFamily); + html->styleEngine->setNonCssHint (CSS_PROPERTY_FONT_FAMILY, + CSS_TYPE_SYMBOL, fontFamily); } - html->styleEngine->setNonCssHints (&props); dFree(fontFamily); } @@ -1959,12 +1952,9 @@ static void Html_tag_open_abbr(DilloHtml *html, const char *tag, int tagsize) if (prefs.show_tooltip && (attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) { - CssPropertyList props; - char *tooltip_str = dStrdup(attrbuf); - props.set (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, tooltip_str); - html->styleEngine->setNonCssHints (&props); - dFree(tooltip_str); + html->styleEngine->setNonCssHint (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, + attrbuf); } } @@ -2008,13 +1998,11 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, CssLength l_h = CSS_CREATE_LENGTH(0.0, CSS_LENGTH_TYPE_AUTO); int space, border, w = 0, h = 0; bool load_now; - CssPropertyList props; - char *tooltip_str = NULL; if (prefs.show_tooltip && (attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) { - tooltip_str = dStrdup(attrbuf); - props.set (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, tooltip_str); + html->styleEngine->setNonCssHint(PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, + attrbuf); } alt_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "alt", NULL); if ((!alt_ptr || !*alt_ptr) && !prefs.load_images) { @@ -2053,9 +2041,11 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, MSG("a_Html_image_new: suspicious image size request %dx%d\n", w, h); } else { if (CSS_LENGTH_TYPE(l_w) != CSS_LENGTH_TYPE_AUTO) - props.set (CSS_PROPERTY_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, l_w); + html->styleEngine->setNonCssHint (CSS_PROPERTY_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, l_w); if (CSS_LENGTH_TYPE(l_h) != CSS_LENGTH_TYPE_AUTO) - props.set (CSS_PROPERTY_HEIGHT, CSS_TYPE_LENGTH_PERCENTAGE, l_h); + html->styleEngine->setNonCssHint (CSS_PROPERTY_HEIGHT, + CSS_TYPE_LENGTH_PERCENTAGE, l_h); } /* TODO: we should scale the image respecting its ratio. @@ -2070,10 +2060,10 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, space = strtol(attrbuf, NULL, 10); if (space > 0) { space = CSS_CREATE_LENGTH(space, CSS_LENGTH_TYPE_PX); - props.set (CSS_PROPERTY_MARGIN_LEFT, CSS_TYPE_LENGTH_PERCENTAGE, - space); - props.set (CSS_PROPERTY_MARGIN_RIGHT, CSS_TYPE_LENGTH_PERCENTAGE, - space); + html->styleEngine->setNonCssHint (CSS_PROPERTY_MARGIN_LEFT, + CSS_TYPE_LENGTH_PERCENTAGE, space); + html->styleEngine->setNonCssHint (CSS_PROPERTY_MARGIN_RIGHT, + CSS_TYPE_LENGTH_PERCENTAGE, space); } } @@ -2082,10 +2072,10 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, space = strtol(attrbuf, NULL, 10); if (space > 0) { space = CSS_CREATE_LENGTH(space, CSS_LENGTH_TYPE_PX); - props.set (CSS_PROPERTY_MARGIN_TOP, CSS_TYPE_LENGTH_PERCENTAGE, - space); - props.set (CSS_PROPERTY_MARGIN_BOTTOM, CSS_TYPE_LENGTH_PERCENTAGE, - space); + html->styleEngine->setNonCssHint (CSS_PROPERTY_MARGIN_TOP, + CSS_TYPE_LENGTH_PERCENTAGE, space); + html->styleEngine->setNonCssHint (CSS_PROPERTY_MARGIN_BOTTOM, + CSS_TYPE_LENGTH_PERCENTAGE, space); } } @@ -2094,31 +2084,30 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, border = strtol(attrbuf, NULL, 10); if (border >= 0) { border = CSS_CREATE_LENGTH(border, CSS_LENGTH_TYPE_PX); - props.set (CSS_PROPERTY_BORDER_TOP_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - border); - props.set (CSS_PROPERTY_BORDER_BOTTOM_WIDTH, - CSS_TYPE_LENGTH_PERCENTAGE, border); - props.set (CSS_PROPERTY_BORDER_LEFT_WIDTH, - CSS_TYPE_LENGTH_PERCENTAGE, border); - props.set (CSS_PROPERTY_BORDER_RIGHT_WIDTH, - CSS_TYPE_LENGTH_PERCENTAGE, border); - - props.set (CSS_PROPERTY_BORDER_TOP_STYLE, CSS_TYPE_ENUM, - BORDER_SOLID); - props.set (CSS_PROPERTY_BORDER_BOTTOM_STYLE, CSS_TYPE_ENUM, - BORDER_SOLID); - props.set (CSS_PROPERTY_BORDER_LEFT_STYLE, CSS_TYPE_ENUM, - BORDER_SOLID); - props.set (CSS_PROPERTY_BORDER_RIGHT_STYLE, CSS_TYPE_ENUM, - BORDER_SOLID); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_TOP_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, border); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_BOTTOM_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, border); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_LEFT_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, border); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_RIGHT_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, border); + + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_TOP_STYLE, + CSS_TYPE_ENUM, BORDER_SOLID); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_BOTTOM_STYLE, + CSS_TYPE_ENUM, BORDER_SOLID); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_LEFT_STYLE, + CSS_TYPE_ENUM, BORDER_SOLID); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_RIGHT_STYLE, + CSS_TYPE_ENUM, BORDER_SOLID); } } /* x_img is an index to a list of {url,image} pairs. * We know Html_add_new_htmlimage() will use size() as its next index */ - props.set (PROPERTY_X_IMG, CSS_TYPE_INTEGER, html->images->size()); - - html->styleEngine->setNonCssHints(&props); + html->styleEngine->setNonCssHint (PROPERTY_X_IMG, CSS_TYPE_INTEGER, + html->images->size()); /* Add a new image widget to this page */ Image = a_Image_new(alt_ptr, 0); @@ -2133,7 +2122,6 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, loading = Html_load_image(html->bw, url, html->page_url, Image); Html_add_new_htmlimage(html, &url, loading ? NULL : Image); - dFree(tooltip_str); dFree(width_ptr); dFree(height_ptr); dFree(alt_ptr); @@ -2373,7 +2361,6 @@ static void Html_tag_open_object(DilloHtml *html, const char *tag, int tagsize) { DilloUrl *url, *base_url = NULL; const char *attrbuf; - CssPropertyList props; if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "codebase"))) { base_url = a_Html_url_new(html, attrbuf, NULL, 0); @@ -2390,9 +2377,8 @@ static void Html_tag_open_object(DilloHtml *html, const char *tag, int tagsize) html->styleEngine->setPseudoLink (); } - props.set(PROPERTY_X_LINK, CSS_TYPE_INTEGER, - Html_set_new_link(html, &url)); - html->styleEngine->setNonCssHints (&props); + html->styleEngine->setNonCssHint(PROPERTY_X_LINK, CSS_TYPE_INTEGER, + Html_set_new_link(html, &url)); HT2TB(html)->addText("[OBJECT]", html->styleEngine->wordStyle ()); } @@ -2446,8 +2432,6 @@ static void Html_add_anchor(DilloHtml *html, const char *name) static void Html_tag_open_a(DilloHtml *html, const char *tag, int tagsize) { DilloUrl *url; - char *tooltip_str = NULL; - CssPropertyList props; const char *attrbuf; /* TODO: add support for MAP with A HREF */ @@ -2466,25 +2450,23 @@ static void Html_tag_open_a(DilloHtml *html, const char *tag, int tagsize) html->InVisitedLink = true; html->styleEngine->setPseudoVisited (); if (html->non_css_visited_color != -1) - props.set (CSS_PROPERTY_COLOR, CSS_TYPE_COLOR, - html->non_css_visited_color); + html->styleEngine->setNonCssHint(CSS_PROPERTY_COLOR, CSS_TYPE_COLOR, + html->non_css_visited_color); } else { html->styleEngine->setPseudoLink (); if (html->non_css_link_color != -1) - props.set (CSS_PROPERTY_COLOR, CSS_TYPE_COLOR, - html->non_css_link_color); + html->styleEngine->setNonCssHint(CSS_PROPERTY_COLOR, CSS_TYPE_COLOR, + html->non_css_link_color); } - props.set (PROPERTY_X_LINK, CSS_TYPE_INTEGER, - Html_set_new_link(html, &url)); + html->styleEngine->setNonCssHint (PROPERTY_X_LINK, CSS_TYPE_INTEGER, + Html_set_new_link(html, &url)); } if (prefs.show_tooltip && (attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) { - tooltip_str = dStrdup(attrbuf); - props.set (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, tooltip_str); + html->styleEngine->setNonCssHint (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, + attrbuf); } - html->styleEngine->setNonCssHints (&props); - dFree(tooltip_str); html->styleEngine->inheritBackgroundColor (); @@ -2562,7 +2544,6 @@ static void Html_tag_open_ul(DilloHtml *html, const char *tag, int tagsize) ListStyleType list_style_type; if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "type"))) { - CssPropertyList props; /* list_style_type explicitly defined */ if (dStrcasecmp(attrbuf, "disc") == 0) @@ -2575,8 +2556,8 @@ static void Html_tag_open_ul(DilloHtml *html, const char *tag, int tagsize) /* invalid value */ list_style_type = LIST_STYLE_TYPE_DISC; - props.set(CSS_PROPERTY_LIST_STYLE_TYPE, CSS_TYPE_ENUM, list_style_type); - html->styleEngine->setNonCssHints (&props); + html->styleEngine->setNonCssHint (CSS_PROPERTY_LIST_STYLE_TYPE, + CSS_TYPE_ENUM, list_style_type); } Html_add_textblock(html, 9); @@ -2620,7 +2601,6 @@ static void Html_tag_open_ol(DilloHtml *html, const char *tag, int tagsize) int n = 1; if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "type"))) { - CssPropertyList props; ListStyleType listStyleType = LIST_STYLE_TYPE_DECIMAL; if (*attrbuf == '1') @@ -2634,8 +2614,8 @@ static void Html_tag_open_ol(DilloHtml *html, const char *tag, int tagsize) else if (*attrbuf == 'I') listStyleType = LIST_STYLE_TYPE_UPPER_ROMAN; - props.set (CSS_PROPERTY_LIST_STYLE_TYPE, CSS_TYPE_ENUM, listStyleType); - html->styleEngine->setNonCssHints (&props); + html->styleEngine->setNonCssHint (CSS_PROPERTY_LIST_STYLE_TYPE, + CSS_TYPE_ENUM, listStyleType); } Html_add_textblock(html, 9); @@ -2713,29 +2693,33 @@ static void Html_tag_close_li(DilloHtml *html, int TagIdx) static void Html_tag_open_hr(DilloHtml *html, const char *tag, int tagsize) { Widget *hruler; - CssPropertyList props; char *width_ptr; const char *attrbuf; int32_t size = 0; width_ptr = a_Html_get_attr_wdef(html, tag, tagsize, "width", NULL); if (width_ptr) { - props.set (CSS_PROPERTY_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - a_Html_parse_length (html, width_ptr)); + html->styleEngine->setNonCssHint (CSS_PROPERTY_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, + a_Html_parse_length (html, width_ptr)); dFree(width_ptr); } if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "size"))) size = strtol(attrbuf, NULL, 10); - a_Html_tag_set_align_attr(html, &props, tag, tagsize); + a_Html_tag_set_align_attr(html, tag, tagsize); /* TODO: evaluate attribute */ if (a_Html_get_attr(html, tag, tagsize, "noshade")) { - props.set (CSS_PROPERTY_BORDER_TOP_STYLE, CSS_TYPE_ENUM, BORDER_SOLID); - props.set (CSS_PROPERTY_BORDER_BOTTOM_STYLE,CSS_TYPE_ENUM,BORDER_SOLID); - props.set (CSS_PROPERTY_BORDER_LEFT_STYLE, CSS_TYPE_ENUM, BORDER_SOLID); - props.set (CSS_PROPERTY_BORDER_RIGHT_STYLE, CSS_TYPE_ENUM, BORDER_SOLID); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_TOP_STYLE, + CSS_TYPE_ENUM, BORDER_SOLID); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_BOTTOM_STYLE, + CSS_TYPE_ENUM, BORDER_SOLID); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_LEFT_STYLE, + CSS_TYPE_ENUM, BORDER_SOLID); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_RIGHT_STYLE, + CSS_TYPE_ENUM, BORDER_SOLID); if (size <= 0) size = 1; @@ -2744,18 +2728,16 @@ static void Html_tag_open_hr(DilloHtml *html, const char *tag, int tagsize) if (size > 0) { CssLength size_top = CSS_CREATE_LENGTH ((size+1)/2, CSS_LENGTH_TYPE_PX); CssLength size_bottom = CSS_CREATE_LENGTH (size / 2, CSS_LENGTH_TYPE_PX); - props.set (CSS_PROPERTY_BORDER_TOP_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - size_top); - props.set (CSS_PROPERTY_BORDER_LEFT_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - size_top); - props.set (CSS_PROPERTY_BORDER_BOTTOM_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - size_bottom); - props.set (CSS_PROPERTY_BORDER_RIGHT_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - size_bottom); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_TOP_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, size_top); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_LEFT_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, size_top); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_BOTTOM_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, size_bottom); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_RIGHT_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, size_bottom); } - html->styleEngine->setNonCssHints (&props); - HT2TB(html)->addParbreak (5, html->styleEngine->wordStyle ()); hruler = new Ruler(); @@ -3094,10 +3076,7 @@ static void Html_tag_open_default(DilloHtml *html,const char *tag,int tagsize) */ static void Html_tag_open_div(DilloHtml *html, const char *tag, int tagsize) { - CssPropertyList props; - - a_Html_tag_set_align_attr (html, &props, tag, tagsize); - html->styleEngine->setNonCssHints (&props); + a_Html_tag_set_align_attr (html, tag, tagsize); Html_add_textblock(html, 0); } diff --git a/src/html_common.hh b/src/html_common.hh index 3cca82de..868d5d63 100644 --- a/src/html_common.hh +++ b/src/html_common.hh @@ -94,7 +94,6 @@ struct _DilloHtmlImage { }; struct _DilloHtmlState { - CssPropertyList *table_cell_props; DilloHtmlParseMode parse_mode; DilloHtmlTableMode table_mode; bool cell_text_align_set; @@ -242,11 +241,9 @@ int32_t a_Html_color_parse(DilloHtml *html, const char *subtag, int32_t default_color); dw::core::style::Length a_Html_parse_length (DilloHtml *html, const char *attr); -void a_Html_tag_set_align_attr(DilloHtml *html, CssPropertyList *props, - const char *tag, int tagsize); +void a_Html_tag_set_align_attr(DilloHtml *html, const char *tag, int tagsize); bool a_Html_tag_set_valign_attr(DilloHtml *html, - const char *tag, int tagsize, - CssPropertyList *props); + const char *tag, int tagsize); void a_Html_load_stylesheet(DilloHtml *html, DilloUrl *url); diff --git a/src/prefs.c b/src/prefs.c index 5514c01a..f968710a 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -36,6 +36,7 @@ DilloPrefs prefs; void a_Prefs_init(void) { prefs.allow_white_bg = TRUE; + prefs.bg_color = 0xdcd1ba; prefs.buffered_drawing = 1; prefs.contrast_visited_color = TRUE; prefs.enterpress_forces_submit = FALSE; diff --git a/src/prefs.h b/src/prefs.h index 684262ed..4009925c 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -46,6 +46,7 @@ struct _DilloPrefs { DilloUrl *start_page; DilloUrl *home; bool_t allow_white_bg; + int32_t bg_color; bool_t contrast_visited_color; bool_t show_tooltip; int panel_size; diff --git a/src/prefsparser.cc b/src/prefsparser.cc index 78cade0b..95f98c16 100644 --- a/src/prefsparser.cc +++ b/src/prefsparser.cc @@ -16,11 +16,13 @@ #include "prefs.h" #include "misc.h" #include "msg.h" +#include "colors.h" #include "prefsparser.hh" typedef enum { PREFS_BOOL, + PREFS_COLOR, PREFS_STRING, PREFS_URL, PREFS_INT32, @@ -43,10 +45,12 @@ int PrefsParser::parseOption(char *name, char *value) { const SymNode_t *node; uint_t i; + int st; /* Symbol array, sorted alphabetically */ const SymNode_t symbols[] = { { "allow_white_bg", &prefs.allow_white_bg, PREFS_BOOL }, + { "bg_color", &prefs.bg_color, PREFS_COLOR }, { "buffered_drawing", &prefs.buffered_drawing, PREFS_INT32 }, { "contrast_visited_color", &prefs.contrast_visited_color, PREFS_BOOL }, { "enterpress_forces_submit", &prefs.enterpress_forces_submit, @@ -122,6 +126,9 @@ int PrefsParser::parseOption(char *name, char *value) *(bool_t *)node->pref = (!dStrcasecmp(value, "yes") || !dStrcasecmp(value, "true")); break; + case PREFS_COLOR: + *(int32_t *)node->pref = a_Color_parse(value, *(int32_t*)node->pref,&st); + break; case PREFS_STRING: dFree(*(char **)node->pref); *(char **)node->pref = dStrdup(value); diff --git a/src/styleengine.cc b/src/styleengine.cc index e078542c..b5553973 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -50,7 +50,8 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) { n->style = Style::create (layout, &style_attrs); n->wordStyle = NULL; - n->styleAttribute = NULL; + n->styleAttrProperties = NULL; + n->nonCssProperties = NULL; n->inheritBackgroundColor = false; } @@ -67,17 +68,19 @@ StyleEngine::~StyleEngine () { */ void StyleEngine::startElement (int element) { if (stack->getRef (stack->size () - 1)->style == NULL) - style0 (); + style0 (stack->size () - 1); stack->increase (); Node *n = stack->getRef (stack->size () - 1); + n->styleAttrProperties = NULL; + n->nonCssProperties = NULL; n->style = NULL; n->wordStyle = NULL; - n->styleAttribute = NULL; n->inheritBackgroundColor = false; DoctreeNode *dn = doctree->push (); dn->element = element; + n->doctreeNode = dn; } void StyleEngine::startElement (const char *tagname) { @@ -121,20 +124,36 @@ void StyleEngine::setClass (const char *klass) { dn->klass = splitStr (klass, ' '); }; -void StyleEngine::setStyle (const char *style) { +void StyleEngine::setStyle (const char *styleAttr) { Node *n = stack->getRef (stack->size () - 1); - assert (n->styleAttribute == NULL); - n->styleAttribute = dStrdup (style); + assert (n->styleAttrProperties == NULL); + // parse style information from style="" attribute, if it exists + if (styleAttr && prefs.parse_embedded_css) + n->styleAttrProperties = + CssParser::parseDeclarationBlock (styleAttr, + strlen (styleAttr)); }; /** - * \brief set properties that were definded using (mostly deprecated) HTML - * attributes (e.g. bgColor). + * \brief Instruct StyleEngine to use the nonCssHints from parent element + * This is only used for tables where nonCssHints on the TABLE-element + * (e.g. border=1) also affect child elements like TD. */ -void StyleEngine::setNonCssHints (CssPropertyList *nonCssHints) { - if (stack->getRef (stack->size () - 1)->style) - stack->getRef (stack->size () - 1)->style->unref (); - style0 (nonCssHints); // evaluate now, so caller can free nonCssHints +void StyleEngine::inheritNonCssHints () { + Node *pn = stack->getRef (stack->size () - 2); + Node *n = stack->getRef (stack->size () - 1); + + if (pn->nonCssProperties) + n->nonCssProperties = new CssPropertyList (*pn->nonCssProperties, true); +} + +void StyleEngine::clearNonCssHints () { + Node *n = stack->getRef (stack->size () - 1); + + if (n->nonCssProperties) { + delete n->nonCssProperties; + n->nonCssProperties = NULL; + } } /** @@ -147,6 +166,17 @@ void StyleEngine::inheritBackgroundColor () { stack->getRef (stack->size () - 1)->inheritBackgroundColor = true; } +dw::core::style::Color *StyleEngine::backgroundColor () { + for (int i = 1; i < stack->size (); i++) { + Node *n = stack->getRef (i); + + if (n->style && n->style->backgroundColor) + return n->style->backgroundColor; + } + + return NULL; +} + /** * \brief set the CSS pseudo class :link. */ @@ -172,12 +202,14 @@ void StyleEngine::endElement (int element) { Node *n = stack->getRef (stack->size () - 1); + if (n->styleAttrProperties) + delete n->styleAttrProperties; + if (n->nonCssProperties) + delete n->nonCssProperties; if (n->style) n->style->unref (); if (n->wordStyle) n->wordStyle->unref (); - if (n->styleAttribute) - dFree ((void*) n->styleAttribute); doctree->pop (); stack->setSize (stack->size () - 1); @@ -227,9 +259,9 @@ void StyleEngine::postprocessAttrs (dw::core::style::StyleAttrs *attrs) { /** * \brief Make changes to StyleAttrs attrs according to CssPropertyList props. */ -void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) { +void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props) { FontAttrs fontAttrs = *attrs->font; - Font *parentFont = stack->get (stack->size () - 2).style->font; + Font *parentFont = stack->get (i - 1).style->font; char *c, *fontName; int lineHeight; @@ -641,52 +673,45 @@ Style * StyleEngine::backgroundStyle () { * HTML elements and the nonCssProperties that have been set. * This method is private. Call style() to get a current style object. */ -Style * StyleEngine::style0 (CssPropertyList *nonCssProperties) { - CssPropertyList props, *styleAttributeProps = NULL; - const char *styleAttribute = - stack->getRef (stack->size () - 1)->styleAttribute; +Style * StyleEngine::style0 (int i) { + CssPropertyList props, *styleAttrProperties, *nonCssProperties; // get previous style from the stack - StyleAttrs attrs = *stack->getRef (stack->size () - 2)->style; + StyleAttrs attrs = *stack->getRef (i - 1)->style; // Ensure that StyleEngine::style0() has not been called before for // this element. // Style computation is expensive so limit it as much as possible. // If this assertion is hit, you need to rearrange the code that is - // doing styleEngine calls to call setNonCssHints() before calling + // doing styleEngine calls to call setNonCssHint() before calling // style() or wordStyle() for each new element. - assert (stack->getRef (stack->size () - 1)->style == NULL); + assert (stack->getRef (i)->style == NULL); // reset values that are not inherited according to CSS attrs.resetValues (); preprocessAttrs (&attrs); - // parse style information from style="" attribute, if it exists - if (styleAttribute && prefs.parse_embedded_css) - styleAttributeProps = - CssParser::parseDeclarationBlock (styleAttribute, - strlen (styleAttribute)); + styleAttrProperties = stack->getRef (i)->styleAttrProperties; + nonCssProperties = stack->getRef (i)->nonCssProperties; // merge style information - cssContext->apply (&props, doctree, styleAttributeProps, nonCssProperties); + cssContext->apply (&props, doctree, stack->getRef(i)->doctreeNode, + styleAttrProperties, nonCssProperties); // apply style - apply (&attrs, &props); + apply (i, &attrs, &props); postprocessAttrs (&attrs); - stack->getRef (stack->size () - 1)->style = Style::create (layout, &attrs); + stack->getRef (i)->style = Style::create (layout, &attrs); - if (styleAttributeProps) - delete styleAttributeProps; - - return stack->getRef (stack->size () - 1)->style; + return stack->getRef (i)->style; } -Style * StyleEngine::wordStyle0 (CssPropertyList *nonCssProperties) { +Style * StyleEngine::wordStyle0 () { StyleAttrs attrs = *style (); attrs.resetValues (); - if (stack->getRef (stack->size () - 1)->inheritBackgroundColor) + if (stack->getRef (stack->size() - 1)->inheritBackgroundColor) attrs.backgroundColor = style ()->backgroundColor; attrs.valign = style ()->valign; @@ -695,6 +720,24 @@ Style * StyleEngine::wordStyle0 (CssPropertyList *nonCssProperties) { return stack->getRef (stack->size () - 1)->wordStyle; } +/** + * \brief Recompute all style information from scratch + * This is used to take into account CSS styles for the HTML-element. + * The CSS data is only completely available after parsing the HEAD-section + * and thereby after the HTML-element has been opened. + * Note that restyle() does not change any styles in the widget tree. + */ +void StyleEngine::restyle () { + for (int i = 1; i < stack->size (); i++) { + Node *n = stack->getRef (i); + if (n->style) { + n->style->unref (); + n->style = NULL; + } + style0 (i); + } +} + void StyleEngine::parse (DilloHtml *html, DilloUrl *url, const char *buf, int buflen, CssOrigin origin) { if (importDepth > 10) { // avoid looping with recursive @import directives diff --git a/src/styleengine.hh b/src/styleengine.hh index 5eafc7a6..8c119e26 100644 --- a/src/styleengine.hh +++ b/src/styleengine.hh @@ -19,12 +19,13 @@ class StyleEngine; */ class StyleEngine { private: - class Node { - public: - dw::core::style::Style *style; - dw::core::style::Style *wordStyle; - const char *styleAttribute; - bool inheritBackgroundColor; + struct Node { + CssPropertyList *styleAttrProperties; + CssPropertyList *nonCssProperties; + dw::core::style::Style *style; + dw::core::style::Style *wordStyle; + bool inheritBackgroundColor; + DoctreeNode *doctreeNode; }; dw::core::Layout *layout; @@ -33,11 +34,19 @@ class StyleEngine { Doctree *doctree; int importDepth; - dw::core::style::Style *style0 (CssPropertyList *nonCssHints = NULL); - dw::core::style::Style *wordStyle0 (CssPropertyList *nonCssHints = NULL); + dw::core::style::Style *style0 (int i); + dw::core::style::Style *wordStyle0 (); + inline void setNonCssHint(CssPropertyName name, CssValueType type, + CssPropertyValue value) { + Node *n = stack->getRef (stack->size () - 1); + + if (!n->nonCssProperties) + n->nonCssProperties = new CssPropertyList (true); + n->nonCssProperties->set(name, type, value); + } void preprocessAttrs (dw::core::style::StyleAttrs *attrs); void postprocessAttrs (dw::core::style::StyleAttrs *attrs); - void apply (dw::core::style::StyleAttrs *attrs, CssPropertyList *props); + void apply (int i, dw::core::style::StyleAttrs *attrs, CssPropertyList *props); bool computeValue (int *dest, CssLength value, dw::core::style::Font *font); bool computeValue (int *dest, CssLength value, @@ -62,16 +71,31 @@ class StyleEngine { void endElement (int tag); void setPseudoLink (); void setPseudoVisited (); - void setNonCssHints (CssPropertyList *nonCssHints); + inline void setNonCssHint(CssPropertyName name, CssValueType type, + int value) { + CssPropertyValue v; + v.intVal = value; + setNonCssHint (name, type, v); + } + inline void setNonCssHint(CssPropertyName name, CssValueType type, + const char *value) { + CssPropertyValue v; + v.strVal = dStrdup(value); + setNonCssHint (name, type, v); + } + void inheritNonCssHints (); + void clearNonCssHints (); + void restyle (); void inheritBackgroundColor (); /* \todo get rid of this somehow */ dw::core::style::Style *backgroundStyle (); + dw::core::style::Color *backgroundColor (); inline dw::core::style::Style *style () { dw::core::style::Style *s = stack->getRef (stack->size () - 1)->style; if (s) return s; else - return style0 (); + return style0 (stack->size () - 1); }; inline dw::core::style::Style *wordStyle () { diff --git a/src/table.cc b/src/table.cc index eb6a806a..751d18a4 100644 --- a/src/table.cc +++ b/src/table.cc @@ -38,7 +38,6 @@ static void Html_tag_open_table_cell(DilloHtml *html, void Html_tag_open_table(DilloHtml *html, const char *tag, int tagsize) { dw::core::Widget *table; - CssPropertyList props, *table_cell_props; const char *attrbuf; int32_t border = -1, cellspacing = -1, cellpadding = -1, bgcolor = -1; CssLength cssLength; @@ -52,93 +51,90 @@ void Html_tag_open_table(DilloHtml *html, const char *tag, int tagsize) if (border != -1) { cssLength = CSS_CREATE_LENGTH (border, CSS_LENGTH_TYPE_PX); - props.set (CSS_PROPERTY_BORDER_TOP_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - cssLength); - props.set (CSS_PROPERTY_BORDER_BOTTOM_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - cssLength); - props.set (CSS_PROPERTY_BORDER_LEFT_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - cssLength); - props.set (CSS_PROPERTY_BORDER_RIGHT_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - cssLength); - props.set (CSS_PROPERTY_BORDER_TOP_STYLE, CSS_TYPE_ENUM, - BORDER_OUTSET); - props.set (CSS_PROPERTY_BORDER_BOTTOM_STYLE, CSS_TYPE_ENUM, - BORDER_OUTSET); - props.set (CSS_PROPERTY_BORDER_LEFT_STYLE, CSS_TYPE_ENUM, - BORDER_OUTSET); - props.set (CSS_PROPERTY_BORDER_RIGHT_STYLE, CSS_TYPE_ENUM, - BORDER_OUTSET); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_TOP_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_BOTTOM_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_LEFT_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_RIGHT_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_TOP_STYLE, + CSS_TYPE_ENUM, BORDER_OUTSET); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_BOTTOM_STYLE, + CSS_TYPE_ENUM, BORDER_OUTSET); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_LEFT_STYLE, + CSS_TYPE_ENUM, BORDER_OUTSET); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_RIGHT_STYLE, + CSS_TYPE_ENUM, BORDER_OUTSET); } if (cellspacing != -1) { cssLength = CSS_CREATE_LENGTH (cellspacing, CSS_LENGTH_TYPE_PX); - props.set (CSS_PROPERTY_BORDER_SPACING, CSS_TYPE_LENGTH_PERCENTAGE, - cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_SPACING, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); } if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "width"))) - props.set (CSS_PROPERTY_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - a_Html_parse_length (html, attrbuf)); + html->styleEngine->setNonCssHint (CSS_PROPERTY_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, + a_Html_parse_length (html, attrbuf)); if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "align"))) { if (dStrcasecmp (attrbuf, "left") == 0) - props.set (CSS_PROPERTY_TEXT_ALIGN, CSS_TYPE_ENUM, TEXT_ALIGN_LEFT); + html->styleEngine->setNonCssHint (CSS_PROPERTY_TEXT_ALIGN, + CSS_TYPE_ENUM, TEXT_ALIGN_LEFT); else if (dStrcasecmp (attrbuf, "right") == 0) - props.set (CSS_PROPERTY_TEXT_ALIGN, CSS_TYPE_ENUM, TEXT_ALIGN_RIGHT); + html->styleEngine->setNonCssHint (CSS_PROPERTY_TEXT_ALIGN, + CSS_TYPE_ENUM, TEXT_ALIGN_RIGHT); else if (dStrcasecmp (attrbuf, "center") == 0) - props.set (CSS_PROPERTY_TEXT_ALIGN, CSS_TYPE_ENUM, TEXT_ALIGN_CENTER); + html->styleEngine->setNonCssHint (CSS_PROPERTY_TEXT_ALIGN, + CSS_TYPE_ENUM, TEXT_ALIGN_CENTER); } if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) { bgcolor = a_Html_color_parse(html, attrbuf, -1); if (bgcolor != -1) - props.set (CSS_PROPERTY_BACKGROUND_COLOR, CSS_TYPE_COLOR, bgcolor); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BACKGROUND_COLOR, + CSS_TYPE_COLOR, bgcolor); } - html->styleEngine->setNonCssHints (&props); - HT2TB(html)->addParbreak (0, html->styleEngine->wordStyle ()); /* The style for the cells */ - table_cell_props = new CssPropertyList (); + html->styleEngine->clearNonCssHints (); if (border > 0) { cssLength = CSS_CREATE_LENGTH (1, CSS_LENGTH_TYPE_PX); - table_cell_props->set (CSS_PROPERTY_BORDER_TOP_WIDTH, - CSS_TYPE_LENGTH_PERCENTAGE, cssLength); - table_cell_props->set (CSS_PROPERTY_BORDER_BOTTOM_WIDTH, - CSS_TYPE_LENGTH_PERCENTAGE, cssLength); - table_cell_props->set (CSS_PROPERTY_BORDER_LEFT_WIDTH, - CSS_TYPE_LENGTH_PERCENTAGE, cssLength); - table_cell_props->set (CSS_PROPERTY_BORDER_RIGHT_WIDTH, - CSS_TYPE_LENGTH_PERCENTAGE, cssLength); - table_cell_props->set (CSS_PROPERTY_BORDER_TOP_STYLE, - CSS_TYPE_ENUM, BORDER_INSET); - table_cell_props->set (CSS_PROPERTY_BORDER_BOTTOM_STYLE, - CSS_TYPE_ENUM, BORDER_INSET); - table_cell_props->set (CSS_PROPERTY_BORDER_LEFT_STYLE, - CSS_TYPE_ENUM, BORDER_INSET); - table_cell_props->set (CSS_PROPERTY_BORDER_RIGHT_STYLE, - CSS_TYPE_ENUM, BORDER_INSET); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_TOP_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_BOTTOM_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_LEFT_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_RIGHT_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_TOP_STYLE, + CSS_TYPE_ENUM, BORDER_INSET); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_BOTTOM_STYLE, + CSS_TYPE_ENUM, BORDER_INSET); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_LEFT_STYLE, + CSS_TYPE_ENUM, BORDER_INSET); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BORDER_RIGHT_STYLE, + CSS_TYPE_ENUM, BORDER_INSET); } if (cellpadding != -1) { cssLength = CSS_CREATE_LENGTH (cellpadding, CSS_LENGTH_TYPE_PX); - table_cell_props->set (CSS_PROPERTY_PADDING_TOP, - CSS_TYPE_LENGTH_PERCENTAGE, cssLength); - table_cell_props->set (CSS_PROPERTY_PADDING_BOTTOM, - CSS_TYPE_LENGTH_PERCENTAGE, cssLength); - table_cell_props->set (CSS_PROPERTY_PADDING_LEFT, - CSS_TYPE_LENGTH_PERCENTAGE, cssLength); - table_cell_props->set (CSS_PROPERTY_PADDING_RIGHT, - CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_PADDING_TOP, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_PADDING_BOTTOM, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_PADDING_LEFT, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); + html->styleEngine->setNonCssHint (CSS_PROPERTY_PADDING_RIGHT, + CSS_TYPE_LENGTH_PERCENTAGE, cssLength); } - if (S_TOP(html)->table_cell_props) - S_TOP(html)->table_cell_props->unref (); - - S_TOP(html)->table_cell_props = table_cell_props; - S_TOP(html)->table_cell_props->ref (); - table = new dw::Table(prefs.limit_text_width); HT2TB(html)->addWidget (table, html->styleEngine->style ()); @@ -155,7 +151,8 @@ void Html_tag_open_tr(DilloHtml *html, const char *tag, int tagsize) const char *attrbuf; int32_t bgcolor = -1; bool new_style = false; - CssPropertyList props, *table_cell_props; + + html->styleEngine->inheritNonCssHints (); switch (S_TOP(html)->table_mode) { case DILLO_HTML_TABLE_MODE_NONE: @@ -169,34 +166,26 @@ void Html_tag_open_tr(DilloHtml *html, const char *tag, int tagsize) if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) { bgcolor = a_Html_color_parse(html, attrbuf, -1); if (bgcolor != -1) - props.set (CSS_PROPERTY_BACKGROUND_COLOR, CSS_TYPE_COLOR, bgcolor); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BACKGROUND_COLOR, + CSS_TYPE_COLOR, bgcolor); } if (a_Html_get_attr (html, tag, tagsize, "align")) { S_TOP(html)->cell_text_align_set = TRUE; - a_Html_tag_set_align_attr (html, &props, tag, tagsize); + a_Html_tag_set_align_attr (html, tag, tagsize); } html->styleEngine->inheritBackgroundColor (); - html->styleEngine->setNonCssHints (&props); ((dw::Table*)S_TOP(html)->table)->addRow (html->styleEngine->style ()); - table_cell_props = new CssPropertyList (*S_TOP(html)->table_cell_props); if (bgcolor != -1) { - table_cell_props->set (CSS_PROPERTY_BACKGROUND_COLOR, - CSS_TYPE_COLOR, bgcolor); + html->styleEngine->setNonCssHint(CSS_PROPERTY_BACKGROUND_COLOR, + CSS_TYPE_COLOR, bgcolor); new_style = true; } - if (a_Html_tag_set_valign_attr (html, tag, tagsize, table_cell_props)) + if (a_Html_tag_set_valign_attr (html, tag, tagsize)) new_style = true; - if (new_style) { - S_TOP(html)->table_cell_props->unref (); - S_TOP(html)->table_cell_props = table_cell_props; - S_TOP(html)->table_cell_props->ref (); - } else { - delete table_cell_props; - } break; default: break; @@ -240,6 +229,8 @@ static void Html_tag_open_table_cell(DilloHtml *html, int32_t bgcolor; bool_t new_style; + html->styleEngine->inheritNonCssHints (); + switch (S_TOP(html)->table_mode) { case DILLO_HTML_TABLE_MODE_NONE: BUG_MSG("<td> or <th> outside <table>\n"); @@ -261,41 +252,36 @@ static void Html_tag_open_table_cell(DilloHtml *html, if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "rowspan"))) rowspan = MAX(1, strtol (attrbuf, NULL, 10)); - CssPropertyList *props; - // \todo any shorter way to do this? - if (S_TOP(html)->table_cell_props != NULL) - props = new CssPropertyList (*S_TOP(html)->table_cell_props); - else - props = new CssPropertyList (); - /* text style */ if (!S_TOP(html)->cell_text_align_set) { - props->set (CSS_PROPERTY_TEXT_ALIGN, CSS_TYPE_ENUM, text_align); + html->styleEngine->setNonCssHint (CSS_PROPERTY_TEXT_ALIGN, + CSS_TYPE_ENUM, text_align); } if (a_Html_get_attr(html, tag, tagsize, "nowrap")) - props->set(CSS_PROPERTY_WHITE_SPACE,CSS_TYPE_ENUM,WHITE_SPACE_NOWRAP); + html->styleEngine->setNonCssHint(CSS_PROPERTY_WHITE_SPACE, + CSS_TYPE_ENUM, WHITE_SPACE_NOWRAP); else - props->set(CSS_PROPERTY_WHITE_SPACE,CSS_TYPE_ENUM,WHITE_SPACE_NORMAL); + html->styleEngine->setNonCssHint(CSS_PROPERTY_WHITE_SPACE, + CSS_TYPE_ENUM, WHITE_SPACE_NORMAL); - a_Html_tag_set_align_attr (html, props, tag, tagsize); + a_Html_tag_set_align_attr (html, tag, tagsize); if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "width"))) { - props->set (CSS_PROPERTY_WIDTH, CSS_TYPE_LENGTH_PERCENTAGE, - a_Html_parse_length (html, attrbuf)); + html->styleEngine->setNonCssHint (CSS_PROPERTY_WIDTH, + CSS_TYPE_LENGTH_PERCENTAGE, + a_Html_parse_length (html, attrbuf)); } - if (a_Html_tag_set_valign_attr (html, tag, tagsize, props)) + if (a_Html_tag_set_valign_attr (html, tag, tagsize)) new_style = TRUE; if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) { bgcolor = a_Html_color_parse(html, attrbuf, -1); if (bgcolor != -1) - props->set (CSS_PROPERTY_BACKGROUND_COLOR, CSS_TYPE_COLOR,bgcolor); + html->styleEngine->setNonCssHint (CSS_PROPERTY_BACKGROUND_COLOR, + CSS_TYPE_COLOR, bgcolor); } - html->styleEngine->setNonCssHints (props); - delete props; - if (html->styleEngine->style ()->textAlign == TEXT_ALIGN_STRING) col_tb = new dw::TableCell ( diff --git a/src/uicmd.cc b/src/uicmd.cc index 93836735..001165d6 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -449,6 +449,8 @@ BrowserWindow *a_UIcmd_browser_window_new(int ww, int wh, // Now create the Dw render layout and viewport FltkPlatform *platform = new FltkPlatform (); Layout *layout = new Layout (platform); + style::Color *bgColor = style::Color::create (layout, prefs.bg_color); + layout->setBgColor (bgColor); FltkViewport *viewport = new FltkViewport (0, 0, 1, 1); if (prefs.buffered_drawing == 1) @@ -507,6 +509,8 @@ static BrowserWindow *UIcmd_tab_new(const void *vbw) // Now create the Dw render layout and viewport FltkPlatform *platform = new FltkPlatform (); Layout *layout = new Layout (platform); + style::Color *bgColor = style::Color::create (layout, prefs.bg_color); + layout->setBgColor (bgColor); FltkViewport *viewport = new FltkViewport (0, 0, 1, 1); @@ -61,10 +61,13 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web, if (Web->flags & WEB_RootUrl) { /* We have RootUrl! */ + style::Color *bgColor = style::Color::create (layout, prefs.bg_color); + Web->bgColor = bgColor->getColor (); + layout->setBgColor (bgColor); + /* Set a style for the widget */ StyleEngine styleEngine (layout); styleEngine.startElement ("body"); - Web->bgColor= styleEngine.backgroundStyle()->backgroundColor->getColor(); dw = (Widget*) a_Mime_set_viewer(Type, Web, Call, Data); if (dw == NULL) |