changeset 1732:3e3630a58627

store style attribute as CssPropertyList instead of a string
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Mon, 11 Oct 2010 18:23:33 +0200
parents 92b899247f72
children f39cfc38ea10
files src/styleengine.cc src/styleengine.hh
diffstat 2 files changed, 21 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/styleengine.cc	Mon Oct 11 18:08:31 2010 +0200
+++ b/src/styleengine.cc	Mon Oct 11 18:23:33 2010 +0200
@@ -50,7 +50,8 @@
 
    n->style = Style::create (layout, &style_attrs);
    n->wordStyle = NULL;
-   n->styleAttribute = NULL;
+   n->styleAttrProperties = NULL;
+   n->nonCssProperties = NULL;
    n->inheritBackgroundColor = false;
 }
 
@@ -71,9 +72,10 @@
 
    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 ();
@@ -121,10 +123,14 @@
    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));
 };
 
 /**
@@ -172,12 +178,14 @@
 
    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);
@@ -638,9 +646,7 @@
  * 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;
+   CssPropertyList props, *styleAttrProperties;
    // get previous style from the stack
    StyleAttrs attrs = *stack->getRef (stack->size () - 2)->style;
 
@@ -656,14 +662,10 @@
    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(stack->size () - 1)->styleAttrProperties;
 
    // merge style information
-   cssContext->apply (&props, doctree, styleAttributeProps, nonCssProperties);
+   cssContext->apply (&props, doctree, styleAttrProperties, nonCssProperties);
 
    // apply style
    apply (&attrs, &props);
@@ -672,9 +674,6 @@
 
    stack->getRef (stack->size () - 1)->style = Style::create (layout, &attrs);
 
-   if (styleAttributeProps)
-      delete styleAttributeProps;
-
    return stack->getRef (stack->size () - 1)->style;
 }
 
--- a/src/styleengine.hh	Mon Oct 11 18:08:31 2010 +0200
+++ b/src/styleengine.hh	Mon Oct 11 18:23:33 2010 +0200
@@ -20,9 +20,10 @@
 class StyleEngine {
    private:
       struct Node {
+         CssPropertyList *styleAttrProperties;
+         CssPropertyList *nonCssProperties;
          dw::core::style::Style *style;
          dw::core::style::Style *wordStyle;
-         const char *styleAttribute;
          bool inheritBackgroundColor;
       };
 
@@ -62,6 +63,7 @@
       void setPseudoLink ();
       void setPseudoVisited ();
       void setNonCssHints (CssPropertyList *nonCssHints);
+      void setNonCssHint(CssPropertyName name, CssPropertyValue value);
       void inheritBackgroundColor (); /* \todo get rid of this somehow */
       dw::core::style::Style *backgroundStyle ();