diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/html.cc | 25 | ||||
-rw-r--r-- | src/styleengine.cc | 21 | ||||
-rw-r--r-- | src/styleengine.hh | 4 |
3 files changed, 23 insertions, 27 deletions
diff --git a/src/html.cc b/src/html.cc index 9b53a082..e7ca7990 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1715,8 +1715,6 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) Textblock *textblock; int32_t color; int tag_index_a = a_Html_tag_index ("a"); - int tag_index_body = a_Html_tag_index ("body"); - int tag_index_html = a_Html_tag_index ("html"); style::Color *bgColor; if (!(html->InFlags & IN_BODY)) @@ -1732,22 +1730,6 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) BUG_MSG("unclosed HEAD element\n"); } - html->styleEngine->endElement(tag_index_body); - html->styleEngine->endElement(tag_index_html); - html->styleEngine->startElement(tag_index_html); - bgColor = html->styleEngine->style ()->backgroundColor; - html->styleEngine->startElement(tag_index_body); - - if ((attrbuf = Html_get_attr2(html, tag, tagsize, "id", - HTML_LeftTrim | HTML_RightTrim))) - html->styleEngine->setId(attrbuf); - if ((attrbuf = Html_get_attr2(html, tag, tagsize, "class", - HTML_LeftTrim | HTML_RightTrim))) - html->styleEngine->setClass(attrbuf); - if ((attrbuf = Html_get_attr2(html, tag, tagsize, "style", - HTML_LeftTrim | HTML_RightTrim))) - html->styleEngine->setStyle(attrbuf); - textblock = HT2TB(html); if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) { @@ -1764,6 +1746,8 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) 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); @@ -1772,10 +1756,7 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) html->dw->setStyle (html->styleEngine->style ()); - /* Set canvas color if not already set from Html_open_html(). - */ - if (!bgColor) - bgColor = html->styleEngine->style ()->backgroundColor; + bgColor = html->styleEngine->backgroundColor (); if (bgColor) HT2LT(html)->setBgColor(bgColor); diff --git a/src/styleengine.cc b/src/styleengine.cc index 9d3b8988..d655ee88 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -80,6 +80,7 @@ void StyleEngine::startElement (int element) { DoctreeNode *dn = doctree->push (); dn->element = element; + n->doctreeNode = dn; } void StyleEngine::startElement (const char *tagname) { @@ -174,6 +175,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. */ @@ -251,9 +263,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; @@ -687,10 +699,11 @@ Style * StyleEngine::style0 (int i) { nonCssProperties = stack->getRef (i)->nonCssProperties; // merge style information - cssContext->apply (&props, doctree, styleAttrProperties, nonCssProperties); + cssContext->apply (&props, doctree, stack->getRef(i)->doctreeNode, + styleAttrProperties, nonCssProperties); // apply style - apply (&attrs, &props); + apply (i, &attrs, &props); postprocessAttrs (&attrs); diff --git a/src/styleengine.hh b/src/styleengine.hh index a0fcdc08..bc421ca7 100644 --- a/src/styleengine.hh +++ b/src/styleengine.hh @@ -25,6 +25,7 @@ class StyleEngine { dw::core::style::Style *style; dw::core::style::Style *wordStyle; bool inheritBackgroundColor; + DoctreeNode *doctreeNode; }; dw::core::Layout *layout; @@ -39,7 +40,7 @@ class StyleEngine { CssPropertyValue 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, @@ -81,6 +82,7 @@ class StyleEngine { 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; |