changeset 505:a3b15690d2f4

apply to CssPropertyList instead of styleAttrs
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Wed, 29 Oct 2008 17:54:18 +0100
parents 5776ac0306cc
children 03de2284bfa6
files src/css.cc src/css.hh
diffstat 2 files changed, 29 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.cc	Wed Oct 29 16:45:20 2008 +0100
+++ b/src/css.cc	Wed Oct 29 17:54:18 2008 +0100
@@ -12,18 +12,22 @@
 #include <stdio.h>
 #include "css.hh"
 
-void CssProperty::apply (dw::core::style::StyleAttrs *styleAttrs) {
-   switch (name) {
-      
+void CssPropertyList::set (CssProperty::Name name, CssProperty::Value value) {
+   for (int i = 0; i < size (); i++) {
+      if (getRef (i)->name == name) {
+         getRef (i)->value = value;
+         return;
+      }
+   }
 
-      default:
-         break;
-   }
+   increase ();
+   getRef (size () - 1)->name = name;
+   getRef (size () - 1)->value = value;
 }
 
-void CssPropertyList::apply (dw::core::style::StyleAttrs *styleAttrs) {
+void CssPropertyList::apply (CssPropertyList *props) {
    for (int i = 0; i < size (); i++)
-      get (i)->apply (styleAttrs);
+      props->set (getRef (i)->name, getRef (i)->value);
 }
 
 /** \todo dummy only */
@@ -31,18 +35,15 @@
    return tagIndex < 0 || tagIndex == docTree->top ()->tagIndex;
 }
 
-void CssRule::apply (dw::core::style::StyleAttrs *styleAttrs,
-   Doctree *docTree) {
+void CssRule::apply (CssPropertyList *props, Doctree *docTree) {
 
    if (selector->match (docTree))
-      props->apply (styleAttrs);
+      this->props->apply (props);
 }
 
-void CssStyleSheet::apply (dw::core::style::StyleAttrs *styleAttrs,
-   Doctree *docTree) {
-
+void CssStyleSheet::apply (CssPropertyList *props, Doctree *docTree) {
    for (int i = 0; i < size (); i++)
-      get (i)->apply (styleAttrs, docTree);
+      get (i)->apply (props, docTree);
 }
 
 void CssContext::addRule (CssRule *rule, PrimaryOrder order) {
@@ -50,15 +51,14 @@
    sheet[order].set (sheet[order].size () - 1, rule);
 };
 
-void CssContext::apply (dw::core::style::StyleAttrs *styleAttrs,
-         Doctree *docTree,
+void CssContext::apply (CssPropertyList *props, Doctree *docTree,
          CssPropertyList *tagStyle, CssPropertyList *nonCss) {
 
-   sheet[USER_AGENT].apply (styleAttrs, docTree);
+   sheet[USER_AGENT].apply (props, docTree);
    if (nonCss)
-        nonCss->apply (styleAttrs);
+        nonCss->apply (props);
    for (int o = USER; o <= USER_IMPORTANT; o++)
-      sheet[o].apply (styleAttrs, docTree);
+      sheet[o].apply (props, docTree);
    if (tagStyle)
-        nonCss->apply (styleAttrs);
+        nonCss->apply (props);
 }
--- a/src/css.hh	Wed Oct 29 16:45:20 2008 +0100
+++ b/src/css.hh	Wed Oct 29 17:54:18 2008 +0100
@@ -111,17 +111,14 @@
 
       Name name;
       Value value;
-
-      CssProperty ();
-      ~CssProperty ();
-
-      void apply (dw::core::style::StyleAttrs *styleAttr);
 };
 
-class CssPropertyList : public lout::misc::SimpleVector <CssProperty*> {
+class CssPropertyList : public lout::misc::SimpleVector <CssProperty> {
    public:
-      CssPropertyList() : lout::misc::SimpleVector <CssProperty*> (1) {};
-      void apply (dw::core::style::StyleAttrs *styleAttr);
+      CssPropertyList() : lout::misc::SimpleVector <CssProperty> (1) {};
+
+      void set (CssProperty::Name name, CssProperty::Value value);
+      void apply (CssPropertyList *props);
 };
 
 /** \todo proper implementation */
@@ -152,13 +149,13 @@
       };
       ~CssRule ();
 
-      void apply (dw::core::style::StyleAttrs *styleAttrs, Doctree *docTree);
+      void apply (CssPropertyList *props, Doctree *docTree);
 };
 
 class CssStyleSheet : public lout::misc::SimpleVector <CssRule*> {
    public:
       CssStyleSheet() : lout::misc::SimpleVector <CssRule*> (1) {};
-      void apply (dw::core::style::StyleAttrs *styleAttrs, Doctree *docTree);
+      void apply (CssPropertyList *props, Doctree *docTree);
 };
 
 class CssContext {
@@ -176,7 +173,7 @@
 
    public:
       void addRule (CssRule *rule, PrimaryOrder order);
-      void apply (dw::core::style::StyleAttrs *styleAttrs,
+      void apply (CssPropertyList *props,
          Doctree *docTree,
          CssPropertyList *tagStyle, CssPropertyList *nonCss);
 };