changeset 513:850c23b07f91

introduce CssPropertySet
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Wed, 29 Oct 2008 23:50:31 +0100
parents c82c5fd9b043
children dac3e759df92
files src/css.cc src/css.hh src/styleengine.cc src/styleengine.hh
diffstat 4 files changed, 40 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.cc	Wed Oct 29 19:34:46 2008 +0100
+++ b/src/css.cc	Wed Oct 29 23:50:31 2008 +0100
@@ -29,7 +29,7 @@
    getRef (size () - 1)->value = value;
 }
 
-void CssPropertyList::apply (CssPropertyList *props) {
+void CssPropertyList::apply (CssPropertySet *props) {
    for (int i = 0; i < size (); i++)
       props->set (getRef (i)->name, getRef (i)->value);
 }
@@ -44,12 +44,12 @@
    return tag < 0 || tag == docTree->top ()->tag;
 }
 
-void CssRule::apply (CssPropertyList *props, Doctree *docTree) {
+void CssRule::apply (CssPropertySet *props, Doctree *docTree) {
    if (selector->match (docTree))
       this->props->apply (props);
 }
 
-void CssStyleSheet::apply (CssPropertyList *props, Doctree *docTree) {
+void CssStyleSheet::apply (CssPropertySet *props, Doctree *docTree) {
    for (int i = 0; i < size (); i++)
       get (i)->apply (props, docTree);
 }
@@ -59,7 +59,7 @@
    sheet[order].set (sheet[order].size () - 1, rule);
 };
 
-void CssContext::apply (CssPropertyList *props, Doctree *docTree,
+void CssContext::apply (CssPropertySet *props, Doctree *docTree,
          CssPropertyList *tagStyle, CssPropertyList *nonCss) {
 
    sheet[CSS_PRIMARY_USER_AGENT].apply (props, docTree);
--- a/src/css.hh	Wed Oct 29 19:34:46 2008 +0100
+++ b/src/css.hh	Wed Oct 29 23:50:31 2008 +0100
@@ -113,13 +113,32 @@
       Value value;
 };
 
+class CssPropertySet {
+   private:
+      bool isSet[CssProperty::CSS_PROPERTY_LAST];
+      CssProperty::Value value[CssProperty::CSS_PROPERTY_LAST];
+
+   public:
+      inline void set (CssProperty::Name name, CssProperty::Value v) {
+         value[name] = v; 
+         isSet[name] = true;
+      }
+
+      inline CssProperty::Value *get (CssProperty::Name name) {
+         if (isSet[name])
+            return &value[name];
+         else
+            return NULL;
+      }
+};
+
 class CssPropertyList : public lout::misc::SimpleVector <CssProperty> {
    public:
       CssPropertyList() : lout::misc::SimpleVector <CssProperty> (1) {};
 
       static CssPropertyList *parse (const char *buf);
       void set (CssProperty::Name name, CssProperty::Value value);
-      void apply (CssPropertyList *props);
+      void apply (CssPropertySet *props);
 };
 
 /** \todo proper implementation */
@@ -152,13 +171,13 @@
       };
       ~CssRule ();
 
-      void apply (CssPropertyList *props, Doctree *docTree);
+      void apply (CssPropertySet *props, Doctree *docTree);
 };
 
 class CssStyleSheet : public lout::misc::SimpleVector <CssRule*> {
    public:
       CssStyleSheet() : lout::misc::SimpleVector <CssRule*> (1) {};
-      void apply (CssPropertyList *props, Doctree *docTree);
+      void apply (CssPropertySet *props, Doctree *docTree);
 };
 
 class CssContext {
@@ -176,7 +195,7 @@
 
    public:
       void addRule (CssRule *rule, PrimaryOrder order);
-      void apply (CssPropertyList *props,
+      void apply (CssPropertySet *props,
          Doctree *docTree,
          CssPropertyList *tagStyle, CssPropertyList *nonCss);
 };
--- a/src/styleengine.cc	Wed Oct 29 19:34:46 2008 +0100
+++ b/src/styleengine.cc	Wed Oct 29 23:50:31 2008 +0100
@@ -59,30 +59,32 @@
    stack->setSize (stack->size () - 1);
 }
 
-void StyleEngine::apply (StyleAttrs *attrs, CssPropertyList *props) {
+void StyleEngine::apply (StyleAttrs *attrs, CssPropertySet *props) {
    FontAttrs fontAttrs = *attrs->font;
 
-   for (int i = 0; i < props->size (); i++) {
-      CssProperty *p = props->getRef (i);
+   for (int i = 0; i < CssProperty::CSS_PROPERTY_LAST; i++) {
+      CssProperty::Value *v = props->get ((CssProperty::Name) i);
+      if (v == NULL)
+         continue;
       
-      switch (p->name) {
+      switch (i) {
          /* \todo missing cases */
          case CssProperty::CSS_PROPERTY_BACKGROUND_COLOR:
             attrs->backgroundColor =
-               Color::createSimple (layout, p->value.color);
+               Color::createSimple (layout, v->color);
             break; 
          case CssProperty::CSS_PROPERTY_BORDER_BOTTOM_COLOR:
             attrs->borderColor.bottom =
-              Color::createSimple (layout, p->value.color);
+              Color::createSimple (layout, v->color);
             break; 
          case CssProperty::CSS_PROPERTY_BORDER_BOTTOM_STYLE:
-            attrs->borderStyle.bottom = p->value.borderStyle;
+            attrs->borderStyle.bottom = v->borderStyle;
             break;
          case CssProperty::CSS_PROPERTY_FONT_FAMILY:
-            fontAttrs.name = p->value.name;
+            fontAttrs.name = v->name;
             break;
          case CssProperty::CSS_PROPERTY_FONT_SIZE:
-            fontAttrs.size = p->value.size;
+            fontAttrs.size = v->size;
             break;
 
          default:
@@ -94,7 +96,7 @@
 }
 
 Style * StyleEngine::style0 () {
-   CssPropertyList props;
+   CssPropertySet props;
    CssPropertyList *tagStyleProps = CssPropertyList::parse (
       stack->getRef (stack->size () - 1)->styleAttribute);
 
--- a/src/styleengine.hh	Wed Oct 29 19:34:46 2008 +0100
+++ b/src/styleengine.hh	Wed Oct 29 23:50:31 2008 +0100
@@ -19,7 +19,7 @@
       CssContext *cssContext;
 
       dw::core::style::Style *style0 ();
-      void apply (dw::core::style::StyleAttrs *attrs, CssPropertyList *props);
+      void apply (dw::core::style::StyleAttrs *attrs, CssPropertySet *props);
 
    public:
       StyleEngine (dw::core::Layout *layout);