aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/html.cc29
-rw-r--r--src/styleengine.cc45
-rw-r--r--src/styleengine.hh8
3 files changed, 51 insertions, 31 deletions
diff --git a/src/html.cc b/src/html.cc
index 29bbfcf8..4ebd97ad 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -2451,11 +2451,11 @@ static void Html_tag_open_a(DilloHtml *html, const char *tag, int tagsize)
if (a_Capi_get_flags(url) & CAPI_IsCached) {
html->InVisitedLink = true;
- html->styleEngine->setPseudoClass ("visited");
+ html->styleEngine->setPseudo ("visited");
if (html->visited_color != -1)
props.set (CssProperty::CSS_PROPERTY_COLOR, html->visited_color);
} else {
- html->styleEngine->setPseudoClass ("link");
+ html->styleEngine->setPseudo ("link");
if (html->link_color != -1)
props.set (CssProperty::CSS_PROPERTY_COLOR, html->link_color);
}
@@ -3399,7 +3399,6 @@ static void Html_process_tag(DilloHtml *html, char *tag, int tagsize)
{
int ci, ni; /* current and new tag indexes */
const char *attrbuf;
- char *id = NULL, *klass = NULL, *style = NULL;
char *start = tag + 1; /* discard the '<' */
int IsCloseTag = (*start == '/');
@@ -3437,6 +3436,7 @@ static void Html_process_tag(DilloHtml *html, char *tag, int tagsize)
/* Push the tag into the stack */
Html_push_tag(html, ni);
+ html->styleEngine->startElement (ni);
/* Now parse attributes that can appear on any tag */
if (tagsize >= 8 && /* length of "<t id=i>" */
@@ -3449,13 +3449,14 @@ static void Html_process_tag(DilloHtml *html, char *tag, int tagsize)
* So we don't do it and hope for better specs in the future ...
*/
if (attrbuf)
- id = strdup (attrbuf);
- Html_check_name_val(html, id, "id");
+ html->styleEngine->setId (attrbuf);
+
+ Html_check_name_val(html, attrbuf, "id");
/* We compare the "id" value with the url-decoded "name" value */
- if (!html->NameVal || strcmp(html->NameVal, id)) {
+ if (!html->NameVal || strcmp(html->NameVal, attrbuf)) {
if (html->NameVal)
BUG_MSG("'id' and 'name' attribute of <a> tag differ\n");
- Html_add_anchor(html, id);
+ Html_add_anchor(html, attrbuf);
}
}
@@ -3469,26 +3470,16 @@ static void Html_process_tag(DilloHtml *html, char *tag, int tagsize)
attrbuf = Html_get_attr2(html, tag, tagsize, "class",
HTML_LeftTrim | HTML_RightTrim);
if (attrbuf)
- klass = strdup (attrbuf);
+ html->styleEngine->setClass (attrbuf);
}
if (tagsize >= 11) { /* length of "<t style=i>" */
attrbuf = Html_get_attr2(html, tag, tagsize, "style",
HTML_LeftTrim | HTML_RightTrim);
if (attrbuf)
- style = strdup (attrbuf);
+ html->styleEngine->setStyle (attrbuf);
}
-
- html->styleEngine->startElement (ni, id, klass, style);
-
- if (id)
- free (id);
- if (klass)
- free (klass);
- if (style)
- free (style);
-
/* Call the open function for this tag */
Tags[ni].open (html, tag, tagsize);
if (html->stop_parser)
diff --git a/src/styleengine.cc b/src/styleengine.cc
index b1661a9e..fdda9d38 100644
--- a/src/styleengine.cc
+++ b/src/styleengine.cc
@@ -11,6 +11,7 @@
#include <stdio.h>
#include <math.h>
+#include "../dlib/dlib.h"
#include "styleengine.hh"
using namespace dw::core::style;
@@ -47,9 +48,8 @@ StyleEngine::~StyleEngine () {
/**
* \brief tell the styleEngine that a new html element has started.
*/
-void StyleEngine::startElement (int element, const char *id, const char *klass,
- const char *style) {
-// fprintf(stderr, "===> START %d %s %s %s\n", element, id, klass, style);
+void StyleEngine::startElement (int element) {
+// fprintf(stderr, "===> START %d\n", element);
if (stack->getRef (stack->size () - 1)->style == NULL)
style0 ();
@@ -59,12 +59,30 @@ void StyleEngine::startElement (int element, const char *id, const char *klass,
n->style = NULL;
n->depth = stack->size ();
n->element = element;
- n->id = id;
- n->klass = klass;
+ n->id = NULL;
+ n->klass = NULL;
n->pseudo = NULL;
- n->styleAttribute = style;
+ n->styleAttribute = NULL;
}
+void StyleEngine::setId (const char *id) {
+ Node *n = stack->getRef (stack->size () - 1);
+ assert (n->id == NULL);
+ n->id = dStrdup (id);
+};
+
+void StyleEngine::setClass (const char *klass) {
+ Node *n = stack->getRef (stack->size () - 1);
+ assert (n->klass == NULL);
+ n->klass = dStrdup (klass);
+};
+
+void StyleEngine::setStyle (const char *style) {
+ Node *n = stack->getRef (stack->size () - 1);
+ assert (n->styleAttribute == NULL);
+ n->styleAttribute = dStrdup (style);
+};
+
/**
* \brief set properties that were definded using (mostly deprecated) HTML
* attributes (e.g. bgColor).
@@ -78,8 +96,10 @@ void StyleEngine::setNonCssHints (CssPropertyList *nonCssHints) {
/**
* \brief set the CSS pseudo class (e.g. "link", "visited").
*/
-void StyleEngine::setPseudoClass (const char *pseudo) {
- stack->getRef (stack->size () - 1)->pseudo = pseudo;
+void StyleEngine::setPseudo (const char *pseudo) {
+ Node *n = stack->getRef (stack->size () - 1);
+ assert (n->pseudo == NULL);
+ n->pseudo = dStrdup (pseudo);
}
/**
@@ -91,9 +111,16 @@ void StyleEngine::endElement (int element) {
assert (element == stack->getRef (stack->size () - 1)->element);
Node *n = stack->getRef (stack->size () - 1);
+
if (n->style)
n->style->unref ();
-
+ if (n->id)
+ dFree ((void*) n->id);
+ if (n->klass)
+ dFree ((void*) n->klass);
+ if (n->styleAttribute)
+ dFree ((void*) n->styleAttribute);
+
stack->setSize (stack->size () - 1);
}
diff --git a/src/styleengine.hh b/src/styleengine.hh
index 7f41705e..60b044b8 100644
--- a/src/styleengine.hh
+++ b/src/styleengine.hh
@@ -37,11 +37,13 @@ class StyleEngine : public Doctree {
return NULL;
};
- void startElement (int tag, const char *id = NULL, const char *klass = NULL,
- const char *style = NULL);
+ void startElement (int tag);
+ void setId (const char *id);
+ void setClass (const char *klass);
+ void setStyle (const char *style);
void endElement (int tag);
+ void setPseudo (const char *pseudo);
void setNonCssHints (CssPropertyList *nonCssHints);
- void setPseudoClass (const char *pseudoClass);
inline dw::core::style::Style *style () {
dw::core::style::Style *s = stack->getRef (stack->size () - 1)->style;