changeset 1734:90feb0de4310

add StyleEngine::restyle()
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Mon, 11 Oct 2010 21:50:13 +0200
parents f39cfc38ea10
children 9b95f6d31e13
files src/styleengine.cc src/styleengine.hh
diffstat 2 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/styleengine.cc	Mon Oct 11 21:35:53 2010 +0200
+++ b/src/styleengine.cc	Mon Oct 11 21:50:13 2010 +0200
@@ -68,7 +68,7 @@
  */
 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);
@@ -666,10 +666,10 @@
  * HTML elements and the nonCssProperties that have been set.
  * This method is private. Call style() to get a current style object.
  */
-Style * StyleEngine::style0 () {
+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.
@@ -677,14 +677,14 @@
    // If this assertion is hit, you need to rearrange the code that is
    // 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);
 
-   styleAttrProperties = stack->getRef(stack->size () - 1)->styleAttrProperties;
-   nonCssProperties = stack->getRef(stack->size () - 1)->nonCssProperties;
+   styleAttrProperties = stack->getRef (i)->styleAttrProperties;
+   nonCssProperties = stack->getRef (i)->nonCssProperties;
 
    // merge style information
    cssContext->apply (&props, doctree, styleAttrProperties, nonCssProperties);
@@ -694,16 +694,16 @@
 
    postprocessAttrs (&attrs);
 
-   stack->getRef (stack->size () - 1)->style = Style::create (layout, &attrs);
+   stack->getRef (i)->style = Style::create (layout, &attrs);
 
-   return stack->getRef (stack->size () - 1)->style;
+   return stack->getRef (i)->style;
 }
 
 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;
@@ -712,6 +712,17 @@
    return stack->getRef (stack->size () - 1)->wordStyle;
 }
 
+void StyleEngine::restyle () {
+   for (int i = 0; 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
--- a/src/styleengine.hh	Mon Oct 11 21:35:53 2010 +0200
+++ b/src/styleengine.hh	Mon Oct 11 21:50:13 2010 +0200
@@ -33,7 +33,7 @@
       Doctree *doctree;
       int importDepth;
 
-      dw::core::style::Style *style0 ();
+      dw::core::style::Style *style0 (int i);
       dw::core::style::Style *wordStyle0 ();
       void setNonCssHint(CssPropertyName name, CssValueType type,
                          CssPropertyValue value);
@@ -78,6 +78,7 @@
       }
       void inheritNonCssHints ();
       void clearNonCssHints ();
+      void restyle ();
       void inheritBackgroundColor (); /* \todo get rid of this somehow */
       dw::core::style::Style *backgroundStyle ();
 
@@ -86,7 +87,7 @@
          if (s)
             return s;
          else
-            return style0 ();
+            return style0 (stack->size () - 1);
       };
 
       inline dw::core::style::Style *wordStyle () {