changeset 1214:e9729d5a1416

support multiple classes per doctree node
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Sat, 11 Jul 2009 10:54:22 +0200
parents d805df86cc98
children 47e96b92122c
files src/css.cc src/doctree.hh src/styleengine.cc
diffstat 3 files changed, 38 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.cc	Tue Jul 07 17:27:59 2009 -0400
+++ b/src/css.cc	Sat Jul 11 10:54:22 2009 +0200
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include "../dlib/dlib.h"
 #include "misc.h"
+#include "msg.h"
 #include "html_common.hh"
 #include "css.hh"
 #include "cssparser.hh"
@@ -206,14 +207,24 @@
 bool CssSimpleSelector::match (const DoctreeNode *n) {
    if (element != ELEMENT_ANY && element != n->element)
       return false;
-   if (klass != NULL &&
-      (n->klass == NULL || dStrcasecmp (klass, n->klass) != 0))
-      return false;
    if (pseudo != NULL &&
       (n->pseudo == NULL || dStrcasecmp (pseudo, n->pseudo) != 0))
       return false;
    if (id != NULL && (n->id == NULL || dStrcasecmp (id, n->id) != 0))
       return false;
+   if (klass != NULL) {
+      bool found = false;
+      if (n->klass != NULL) {
+         for (int i = 0; i < n->klass->size (); i++) {
+            if (dStrcasecmp (klass, n->klass->get(i)) == 0) {
+               found = true;
+               break;
+            }
+         }
+      }
+      if (! found)
+         return false;
+   }
 
    return true;
 }
@@ -356,8 +367,8 @@
  */ 
 void CssStyleSheet::apply (CssPropertyList *props,
                            Doctree *docTree, const DoctreeNode *node) {
-   RuleList *ruleList[4];
-   int numLists = 0, index[4] = {0, 0, 0, 0};
+   RuleList *ruleList[32];
+   int numLists = 0, index[32] = {0};
 
    if (node->id) {
       lout::object::ConstString idString (node->id);
@@ -368,11 +379,18 @@
    }
 
    if (node->klass) {
-      lout::object::ConstString classString (node->klass);
+      for (int i = 0; i < node->klass->size (); i++) {
+         if (i >= 16) {
+            MSG_WARN("Maximum number of classes per node exceeded.\n");
+            break;
+         }
 
-      ruleList[numLists] = classTable->get (&classString);
-      if (ruleList[numLists])
-         numLists++;
+         lout::object::ConstString classString (node->klass->get (i));
+
+         ruleList[numLists] = classTable->get (&classString);
+         if (ruleList[numLists])
+            numLists++;
+      }
    }
 
    ruleList[numLists] = elementTable[docTree->top ()->element];
--- a/src/doctree.hh	Tue Jul 07 17:27:59 2009 -0400
+++ b/src/doctree.hh	Sat Jul 11 10:54:22 2009 +0200
@@ -1,12 +1,14 @@
 #ifndef __DOCTREE_HH__
 #define __DOCTREE_HH__
 
+#include "lout/misc.hh"
+
 class DoctreeNode {
    public:
       int num; // unique ascending id
       int depth;
       int element;
-      const char *klass;
+      lout::misc::SimpleVector<char*> *klass;
       const char *pseudo;
       const char *id;
 };
--- a/src/styleengine.cc	Tue Jul 07 17:27:59 2009 -0400
+++ b/src/styleengine.cc	Sat Jul 11 10:54:22 2009 +0200
@@ -100,7 +100,9 @@
 void StyleEngine::setClass (const char *klass) {
    Node *n =  stack->getRef (stack->size () - 1);
    assert (n->klass == NULL);
-   n->klass = dStrdup (klass);
+   n->klass = new lout::misc::SimpleVector<char*>(1);
+   n->klass->increase ();
+   n->klass->set (0, dStrdup (klass));
 };
 
 void StyleEngine::setStyle (const char *style) {
@@ -161,8 +163,11 @@
       n->wordStyle->unref ();
    if (n->id)
       dFree ((void*) n->id);
-   if (n->klass)
-      dFree ((void*) n->klass);
+   if (n->klass) {
+      for (int i = 0; i < n->klass->size (); i++)
+         dFree (n->klass->get(i));
+      delete n->klass;
+   }
    if (n->styleAttribute)
       dFree ((void*) n->styleAttribute);