summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/doctree.hh48
-rw-r--r--src/styleengine.cc61
-rw-r--r--src/styleengine.hh20
3 files changed, 72 insertions, 57 deletions
diff --git a/src/doctree.hh b/src/doctree.hh
index 30762e44..ef7faa7c 100644
--- a/src/doctree.hh
+++ b/src/doctree.hh
@@ -5,12 +5,20 @@
class DoctreeNode {
public:
+ DoctreeNode *parent;
int num; // unique ascending id
- int depth;
int element;
lout::misc::SimpleVector<char*> *klass;
const char *pseudo;
const char *id;
+
+ DoctreeNode () {
+ parent = NULL;
+ klass = NULL;
+ pseudo = NULL;
+ id = NULL;
+ element = 0;
+ };
};
/**
@@ -23,10 +31,42 @@ class DoctreeNode {
* be extended to a real tree.
*/
class Doctree {
+ private:
+ DoctreeNode *topNode;
+ int num;
+
public:
- virtual ~Doctree () {};
- virtual const DoctreeNode *top () = 0;
- virtual const DoctreeNode *parent (const DoctreeNode *node) = 0;
+ Doctree () {
+ topNode = NULL;
+ num = 0;
+ };
+ ~Doctree () { while (top ()) pop (); };
+ DoctreeNode *push () {
+ DoctreeNode *dn = new DoctreeNode ();
+ dn->parent = topNode;
+ dn->num = num++;
+ topNode = dn;
+ return dn;
+ };
+ void pop () {
+ DoctreeNode *dn = topNode;
+ if (dn) {
+ dFree ((void*) dn->id);
+ if (dn->klass) {
+ for (int i = 0; i < dn->klass->size (); i++)
+ dFree (dn->klass->get(i));
+ delete dn->klass;
+ }
+ topNode = dn->parent;
+ delete dn;
+ }
+ };
+ inline DoctreeNode *top () {
+ return topNode;
+ };
+ inline DoctreeNode *parent (const DoctreeNode *node) {
+ return node->parent;
+ };
};
#endif
diff --git a/src/styleengine.cc b/src/styleengine.cc
index cf61044b..ea5bc533 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -21,14 +21,14 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) {
StyleAttrs style_attrs;
FontAttrs font_attrs;
+ doctree = new Doctree ();
stack = new lout::misc::SimpleVector <Node> (1);
cssContext = new CssContext ();
this->layout = layout;
- num = 0;
importDepth = 0;
stack->increase ();
- Node *n = stack->getRef (stack->size () - 1);
+ Node *n = stack->getRef (stack->size () - 1);
/* Create a dummy font, attribute, and tag for the bottom of the stack. */
font_attrs.name = prefs.font_sans_serif;
@@ -46,21 +46,17 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) {
style_attrs.color = Color::create (layout, 0);
style_attrs.backgroundColor = Color::create (layout, 0xffffff);
- n->num = num++;
n->style = Style::create (layout, &style_attrs);
n->wordStyle = NULL;
- n->element = 0;
- n->id = NULL;
- n->klass = NULL;
- n->pseudo = NULL;
n->styleAttribute = NULL;
n->inheritBackgroundColor = false;
}
StyleEngine::~StyleEngine () {
- while (stack->size () > 0)
- endElement (stack->getRef (stack->size () - 1)->element);
+ while (doctree->top ())
+ endElement (doctree->top ()->element);
delete stack;
+ delete doctree;
delete cssContext;
}
@@ -72,17 +68,14 @@ void StyleEngine::startElement (int element) {
style0 ();
stack->increase ();
- Node *n = stack->getRef (stack->size () - 1);
- n->num = num++;
+ Node *n = stack->getRef (stack->size () - 1);
n->style = NULL;
n->wordStyle = NULL;
- n->depth = stack->size () - 1;
- n->element = element;
- n->id = NULL;
- n->klass = NULL;
- n->pseudo = NULL;
n->styleAttribute = NULL;
n->inheritBackgroundColor = false;
+
+ DoctreeNode *dn = doctree->push ();
+ dn->element = element;
}
void StyleEngine::startElement (const char *tagname) {
@@ -90,9 +83,9 @@ void StyleEngine::startElement (const char *tagname) {
}
void StyleEngine::setId (const char *id) {
- Node *n = stack->getRef (stack->size () - 1);
- assert (n->id == NULL);
- n->id = dStrdup (id);
+ DoctreeNode *dn = doctree->top ();
+ assert (dn->id == NULL);
+ dn->id = dStrdup (id);
};
/**
@@ -121,13 +114,13 @@ static lout::misc::SimpleVector<char *> *splitStr (const char *str, char sep) {
}
void StyleEngine::setClass (const char *klass) {
- Node *n = stack->getRef (stack->size () - 1);
- assert (n->klass == NULL);
- n->klass = splitStr (klass, ' ');
+ DoctreeNode *dn = doctree->top ();
+ assert (dn->klass == NULL);
+ dn->klass = splitStr (klass, ' ');
};
void StyleEngine::setStyle (const char *style) {
- Node *n = stack->getRef (stack->size () - 1);
+ Node *n = stack->getRef (stack->size () - 1);
assert (n->styleAttribute == NULL);
n->styleAttribute = dStrdup (style);
};
@@ -156,16 +149,16 @@ void StyleEngine::inheritBackgroundColor () {
* \brief set the CSS pseudo class :link.
*/
void StyleEngine::setPseudoLink () {
- Node *n = stack->getRef (stack->size () - 1);
- n->pseudo = "link";
+ DoctreeNode *dn = doctree->top ();
+ dn->pseudo = "link";
}
/**
* \brief set the CSS pseudo class :visited.
*/
void StyleEngine::setPseudoVisited () {
- Node *n = stack->getRef (stack->size () - 1);
- n->pseudo = "visited";
+ DoctreeNode *dn = doctree->top ();
+ dn->pseudo = "visited";
}
/**
@@ -173,24 +166,18 @@ void StyleEngine::setPseudoVisited () {
*/
void StyleEngine::endElement (int element) {
assert (stack->size () > 0);
- assert (element == stack->getRef (stack->size () - 1)->element);
+ assert (element == doctree->top ()->element);
- Node *n = stack->getRef (stack->size () - 1);
+ Node *n = stack->getRef (stack->size () - 1);
if (n->style)
n->style->unref ();
if (n->wordStyle)
n->wordStyle->unref ();
- if (n->id)
- dFree ((void*) n->id);
- 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);
+ doctree->pop ();
stack->setSize (stack->size () - 1);
}
@@ -621,7 +608,7 @@ Style * StyleEngine::style0 (CssPropertyList *nonCssProperties) {
strlen (styleAttribute));
// merge style information
- cssContext->apply (&props, this, styleAttributeProps, nonCssProperties);
+ cssContext->apply (&props, doctree, styleAttributeProps, nonCssProperties);
// apply style
apply (&attrs, &props);
diff --git a/src/styleengine.hh b/src/styleengine.hh
index 8b5dd1fd..66f28cee 100644
--- a/src/styleengine.hh
+++ b/src/styleengine.hh
@@ -17,9 +17,9 @@ class StyleEngine;
* HTML elements and their attributes via the startElement() / endElement()
* methods.
*/
-class StyleEngine : public Doctree {
+class StyleEngine {
private:
- class Node : public DoctreeNode {
+ class Node {
public:
dw::core::style::Style *style;
dw::core::style::Style *wordStyle;
@@ -30,7 +30,7 @@ class StyleEngine : public Doctree {
dw::core::Layout *layout;
lout::misc::SimpleVector <Node> *stack;
CssContext *cssContext;
- int num;
+ Doctree *doctree;
int importDepth;
dw::core::style::Style *style0 (CssPropertyList *nonCssHints = NULL);
@@ -49,24 +49,12 @@ class StyleEngine : public Doctree {
StyleEngine (dw::core::Layout *layout);
~StyleEngine ();
- /* Doctree interface */
- inline const DoctreeNode *top () {
- return stack->getRef (stack->size () - 1);
- };
-
- inline const DoctreeNode *parent (const DoctreeNode *n) {
- if (n->depth > 1)
- return stack->getRef (n->depth - 1);
- else
- return NULL;
- };
-
void parse (DilloHtml *html, DilloUrl *url, const char *buf, int buflen,
CssOrigin origin);
void startElement (int tag);
void startElement (const char *tagname);
void setId (const char *id);
- const char * getId () { return top ()->id; };
+ const char * getId () { return doctree->top ()->id; };
void setClass (const char *klass);
void setStyle (const char *style);
void endElement (int tag);