summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/styleengine.cc64
-rw-r--r--src/styleengine.hh2
2 files changed, 28 insertions, 38 deletions
diff --git a/src/styleengine.cc b/src/styleengine.cc
index fe2d7b7d..a482f088 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -31,8 +31,8 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) {
this->layout = layout;
importDepth = 0;
- stack->increase ();
- Node *n = stack->getRef (stack->size () - 1);
+ stackPush ();
+ Node *n = stack->getLastRef ();
/* Create a dummy font, attribute, and tag for the bottom of the stack. */
font_attrs.name = prefs.font_sans_serif;
@@ -52,20 +52,31 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) {
style_attrs.backgroundColor = Color::create (layout, 0xffffff);
n->style = Style::create (layout, &style_attrs);
- n->wordStyle = NULL;
- n->backgroundStyle = NULL;
- n->styleAttrProperties = NULL;
- n->styleAttrPropertiesImportant = NULL;
- n->nonCssProperties = NULL;
- n->inheritBackgroundColor = false;
}
StyleEngine::~StyleEngine () {
while (doctree->top ())
endElement (doctree->top ()->element);
- assert (stack->size () == 1); // dummy node on the bottom of the stack
+ stackPop (); // dummy node on the bottom of the stack
+ assert (stack->size () == 0);
+
+ delete stack;
+ delete doctree;
+ delete cssContext;
+}
+
+void StyleEngine::stackPush () {
+ static const Node emptyNode = {
+ NULL, NULL, NULL, NULL, NULL, NULL, false, NULL
+ };
+
+ stack->setSize (stack->size () + 1, emptyNode);
+}
+
+void StyleEngine::stackPop () {
Node *n = stack->getRef (stack->size () - 1);
+
delete n->styleAttrProperties;
delete n->styleAttrPropertiesImportant;
delete n->nonCssProperties;
@@ -75,30 +86,19 @@ StyleEngine::~StyleEngine () {
n->wordStyle->unref ();
if (n->backgroundStyle)
n->backgroundStyle->unref ();
-
- delete stack;
- delete doctree;
- delete cssContext;
+ stack->setSize (stack->size () - 1);
}
/**
* \brief tell the styleEngine that a new html element has started.
*/
void StyleEngine::startElement (int element) {
- if (stack->getRef (stack->size () - 1)->style == NULL)
- style0 (stack->size () - 1);
-
- stack->increase ();
- Node *n = stack->getRef (stack->size () - 1);
- n->styleAttrProperties = NULL;
- n->styleAttrPropertiesImportant = NULL;
- n->nonCssProperties = NULL;
- n->style = NULL;
- n->wordStyle = NULL;
- n->backgroundStyle = NULL;
- n->inheritBackgroundColor = false;
+ style (); // ensure that style of current node is computed
+ stackPush ();
+ Node *n = stack->getLastRef ();
DoctreeNode *dn = doctree->push ();
+
dn->element = element;
n->doctreeNode = dn;
}
@@ -225,20 +225,8 @@ void StyleEngine::setPseudoVisited () {
void StyleEngine::endElement (int element) {
assert (element == doctree->top ()->element);
- Node *n = stack->getRef (stack->size () - 1);
-
- delete n->styleAttrProperties;
- delete n->styleAttrPropertiesImportant;
- delete n->nonCssProperties;
- if (n->style)
- n->style->unref ();
- if (n->wordStyle)
- n->wordStyle->unref ();
- if (n->backgroundStyle)
- n->backgroundStyle->unref ();
-
+ stackPop ();
doctree->pop ();
- stack->setSize (stack->size () - 1);
}
void StyleEngine::preprocessAttrs (dw::core::style::StyleAttrs *attrs) {
diff --git a/src/styleengine.hh b/src/styleengine.hh
index 7cca1475..237008a6 100644
--- a/src/styleengine.hh
+++ b/src/styleengine.hh
@@ -36,6 +36,8 @@ class StyleEngine {
Doctree *doctree;
int importDepth;
+ void stackPush ();
+ void stackPop ();
void buildUserAgentStyle ();
void buildUserStyle ();
dw::core::style::Style *style0 (int i);