aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-10-29 16:44:28 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-10-29 16:44:28 +0100
commitb8df95008c6a2e36aaac09f761e4c64a3520ac45 (patch)
treeb61ac3242a1170dc6ffdfe855d59e1369b22a929
parent5fb38f8dd5c9b2203fe6d4323f7b10d7385e582c (diff)
implement various apply() methods
-rw-r--r--src/css.cc41
-rw-r--r--src/css.hh32
-rw-r--r--src/doctree.hh6
-rw-r--r--src/styleengine.cc2
-rw-r--r--src/styleengine.hh27
5 files changed, 80 insertions, 28 deletions
diff --git a/src/css.cc b/src/css.cc
index 4cc9f59e..d01093b0 100644
--- a/src/css.cc
+++ b/src/css.cc
@@ -20,3 +20,44 @@ void CssProperty::apply (dw::core::style::StyleAttrs *styleAttrs) {
break;
}
}
+
+void CssPropertyList::apply (dw::core::style::StyleAttrs *styleAttrs) {
+ for (int i = 0; i < size (); i++)
+ get (i)->apply (styleAttrs);
+}
+
+bool CssSelector::match (Doctree *docTree) {
+ return tagIndex < 0 || tagIndex == docTree->top ()->tagIndex;
+}
+
+void CssRule::apply (dw::core::style::StyleAttrs *styleAttrs,
+ Doctree *docTree) {
+
+ if (selector->match (docTree))
+ props->apply (styleAttrs);
+}
+
+void CssStyleSheet::apply (dw::core::style::StyleAttrs *styleAttrs,
+ Doctree *docTree) {
+
+ for (int i = 0; i < size (); i++)
+ get (i)->apply (styleAttrs, docTree);
+}
+
+void CssContext::addRule (CssRule *rule, PrimaryOrder order) {
+ sheet[order].increase ();
+ sheet[order].set (sheet[order].size () - 1, rule);
+};
+
+void CssContext::apply (dw::core::style::StyleAttrs *styleAttrs,
+ Doctree *docTree,
+ CssPropertyList *tagStyle, CssPropertyList *nonCss) {
+
+ sheet[USER_AGENT].apply (styleAttrs, docTree);
+ if (nonCss)
+ nonCss->apply (styleAttrs);
+ for (int o = USER; o <= USER_IMPORTANT; o++)
+ sheet[o].apply (styleAttrs, docTree);
+ if (tagStyle)
+ nonCss->apply (styleAttrs);
+}
diff --git a/src/css.hh b/src/css.hh
index b59307ae..36067a3e 100644
--- a/src/css.hh
+++ b/src/css.hh
@@ -152,43 +152,33 @@ class CssRule {
};
~CssRule ();
- void apply (dw::core::style::StyleAttrs *styleAttr);
+ void apply (dw::core::style::StyleAttrs *styleAttrs, Doctree *docTree);
};
class CssStyleSheet : public lout::misc::SimpleVector <CssRule*> {
public:
CssStyleSheet() : lout::misc::SimpleVector <CssRule*> (1) {};
- void apply (dw::core::style::StyleAttrs *styleAttr);
+ void apply (dw::core::style::StyleAttrs *styleAttrs, Doctree *docTree);
};
-typedef enum {
- CSS_PRIMARY_USER_IMPORTANT,
- CSS_PRIMARY_AUTHOR_IMPORTANT,
- CSS_PRIMARY_AUTHOR,
- CSS_PRIMARY_USER,
- CSS_PRIMARY_USER_AGENT
-} CssPrimaryOrder;
-
class CssContext {
public:
typedef enum {
- USER_IMPORTANT,
- AUTHOR_IMPORTANT,
- AUTHOR,
+ USER_AGENT,
USER,
- USER_AGENT
+ AUTHOR,
+ AUTHOR_IMPORTANT,
+ USER_IMPORTANT
} PrimaryOrder;
private:
- CssStyleSheet sheet[USER_AGENT + 1];
+ CssStyleSheet sheet[USER_IMPORTANT + 1];
public:
- void addRule (CssRule *rule, PrimaryOrder order) {
- sheet[order].increase ();
- sheet[order].set (sheet[order].size () - 1, rule);
- };
-
- void apply (dw::core::style::StyleAttrs *styleAttr);
+ void addRule (CssRule *rule, PrimaryOrder order);
+ void apply (dw::core::style::StyleAttrs *styleAttrs,
+ Doctree *docTree,
+ CssPropertyList *tagStyle, CssPropertyList *nonCss);
};
#endif
diff --git a/src/doctree.hh b/src/doctree.hh
index 7d35135a..6f94a523 100644
--- a/src/doctree.hh
+++ b/src/doctree.hh
@@ -2,10 +2,8 @@
#define __DOCTREE_HH__
class DoctreeNode {
- private:
- int index;
-
public:
+ int depth;
int tagIndex;
const char *klass;
const char *id;
@@ -13,7 +11,7 @@ class DoctreeNode {
class Doctree {
public:
- virtual ~Doctree () = 0;
+ virtual ~Doctree () {};
virtual const DoctreeNode *top () = 0;
virtual const DoctreeNode *parent (const DoctreeNode *node) = 0;
};
diff --git a/src/styleengine.cc b/src/styleengine.cc
index a2ad556e..4147fb17 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -13,9 +13,11 @@
#include "styleengine.hh"
StyleEngine::StyleEngine () {
+ stack = new lout::misc::SimpleVector <Node> (1);
}
StyleEngine::~StyleEngine () {
+ delete stack;
}
void
diff --git a/src/styleengine.hh b/src/styleengine.hh
index af615a44..94792250 100644
--- a/src/styleengine.hh
+++ b/src/styleengine.hh
@@ -4,17 +4,38 @@
#include "dw/core.hh"
#include "doctree.hh"
-class StyleEngine {
+class StyleEngine : public Doctree {
private:
- dw::core::style::Style *currentStyle;
+ class Node : public DoctreeNode {
+ public:
+ dw::core::style::Style *style;
+
+
+ };
+
+ lout::misc::SimpleVector <Node> *stack;
public:
StyleEngine ();
~StyleEngine ();
+
+ /* Doctree interface */
+ const DoctreeNode *top () {
+ return stack->getRef (stack->size () - 1);
+ };
+ const DoctreeNode *parent (const DoctreeNode *n) {
+ if (n->depth > 0)
+ return stack->getRef (n->depth - 1);
+ else
+ return NULL;
+ };
void startElement (int tag, const char *id, const char *klass, const char *style);
void endElement (int tag);
- inline dw::core::style::Style *style () { return currentStyle; };
+
+ inline dw::core::style::Style *style () {
+ return stack->getRef (stack->size () - 1)->style;
+ };
};
#endif