changeset 1738:7974b38cc036

use background-color on <html>-element
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Mon, 11 Oct 2010 23:36:36 +0200
parents 31d490fe7e0a
children 7188140a1c0a
files src/html.cc src/styleengine.cc src/styleengine.hh
diffstat 3 files changed, 23 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/html.cc	Mon Oct 11 23:35:49 2010 +0200
+++ b/src/html.cc	Mon Oct 11 23:36:36 2010 +0200
@@ -1715,8 +1715,6 @@
    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 @@
       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 @@
                                            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 @@
 
    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);  
--- a/src/styleengine.cc	Mon Oct 11 23:35:49 2010 +0200
+++ b/src/styleengine.cc	Mon Oct 11 23:36:36 2010 +0200
@@ -80,6 +80,7 @@
 
    DoctreeNode *dn = doctree->push ();
    dn->element = element;
+   n->doctreeNode = dn;
 }
 
 void StyleEngine::startElement (const char *tagname) {
@@ -174,6 +175,17 @@
    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 @@
 /**
  * \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 @@
    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);
 
--- a/src/styleengine.hh	Mon Oct 11 23:35:49 2010 +0200
+++ b/src/styleengine.hh	Mon Oct 11 23:36:36 2010 +0200
@@ -25,6 +25,7 @@
          dw::core::style::Style *style;
          dw::core::style::Style *wordStyle;
          bool inheritBackgroundColor;
+         DoctreeNode *doctreeNode;
       };
 
       dw::core::Layout *layout;
@@ -39,7 +40,7 @@
                          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 @@
       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;