aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/css.cc30
-rw-r--r--src/css.hh21
-rw-r--r--src/cssparser.cc8
3 files changed, 44 insertions, 15 deletions
diff --git a/src/css.cc b/src/css.cc
index 84eb36dc..030f3101 100644
--- a/src/css.cc
+++ b/src/css.cc
@@ -44,6 +44,15 @@ void CssPropertyList::print () {
getRef (i)->print ();
}
+CssSelector::CssSelector (int element, const char *klass,
+ const char *pseudo, const char *id) {
+ refCount = 0;
+ this->element = element;
+ this->klass = klass;
+ this->pseudo = pseudo;
+ this->id = id;
+};
+
/** \todo implement all selection option CSS offers */
bool CssSelector::match (Doctree *docTree) {
const DoctreeNode *n = docTree-> top ();
@@ -67,6 +76,18 @@ void CssSelector::print () {
element, klass, pseudo, id);
}
+CssRule::CssRule (CssSelector *selector, CssPropertyList *props) {
+ this->selector = selector;
+ this->selector->ref ();
+ this->props = props;
+ this->props->ref ();
+};
+
+CssRule::~CssRule () {
+ this->selector->unref ();
+ this->props->unref ();
+};
+
void CssRule::apply (CssPropertyList *props, Doctree *docTree) {
if (selector->match (docTree))
this->props->apply (props);
@@ -92,6 +113,11 @@ void CssStyleSheet::apply (CssPropertyList *props, Doctree *docTree) {
get (i)->apply (props, docTree);
}
+CssStyleSheet::~CssStyleSheet () {
+ for (int i = 0; i < size (); i++)
+ delete get (i);
+}
+
CssStyleSheet *CssContext::userAgentStyle;
CssStyleSheet *CssContext::userStyle;
CssStyleSheet *CssContext::userImportantStyle;
@@ -142,8 +168,8 @@ void CssContext::addRule (CssRule *rule, CssPrimaryOrder order) {
sheet[order]->addRule (rule);
- fprintf(stderr, "Adding Rule (%d)\n", order);
- rule->print ();
+// fprintf(stderr, "Adding Rule (%d)\n", order);
+// rule->print ();
}
void CssContext::buildUserAgentStyle () {
diff --git a/src/css.hh b/src/css.hh
index edc19c42..90dc2130 100644
--- a/src/css.hh
+++ b/src/css.hh
@@ -187,28 +187,25 @@ class CssPropertyList : public lout::misc::SimpleVector <CssProperty> {
};
void apply (CssPropertyList *props);
void print ();
-
inline void ref () { refCount++; }
inline void unref () { if(--refCount == 0) delete this; }
};
/** \todo proper implementation */
class CssSelector {
+ private:
+ int refCount;
+
public:
int element;
const char *klass, *pseudo, *id;
- public:
CssSelector (int element = -1, const char *klass = NULL,
- const char *pseudo = NULL, const char *id = NULL) {
- this->element = element;
- this->klass = klass;
- this->pseudo = pseudo;
- this->id = id;
- };
-
+ const char *pseudo = NULL, const char *id = NULL);
bool match (Doctree *dt);
void print ();
+ inline void ref () { refCount++; }
+ inline void unref () { if(--refCount == 0) delete this; }
};
class CssRule {
@@ -217,10 +214,7 @@ class CssRule {
CssPropertyList *props;
public:
- CssRule (CssSelector *selector, CssPropertyList *props) {
- this->selector = selector;
- this->props = props;
- };
+ CssRule (CssSelector *selector, CssPropertyList *props);
~CssRule ();
void apply (CssPropertyList *props, Doctree *docTree);
@@ -230,6 +224,7 @@ class CssRule {
class CssStyleSheet : lout::misc::SimpleVector <CssRule*> {
public:
CssStyleSheet() : lout::misc::SimpleVector <CssRule*> (1) {};
+ ~CssStyleSheet();
void addRule (CssRule *rule);
void addRule (CssSelector *selector, CssPropertyList *props);
void apply (CssPropertyList *props, Doctree *docTree);
diff --git a/src/cssparser.cc b/src/cssparser.cc
index 07ab3ac1..6bf7567e 100644
--- a/src/cssparser.cc
+++ b/src/cssparser.cc
@@ -893,6 +893,7 @@ static void Css_parse_ruleset (CssParser *parser)
}
if (selector) {
+ selector->ref ();
selector->id = selector->klass = selector->pseudo = NULL;
do {
@@ -962,7 +963,9 @@ static void Css_parse_ruleset (CssParser *parser)
DEBUG_MSG (DEBUG_PARSE_LEVEL, "end of %s\n", "selectors");
props = new CssPropertyList ();
+ props->ref ();
importantProps = new CssPropertyList ();
+ importantProps->ref ();
/* Read block. ('{' has already been read.) */
if (parser->ttype != CSS_TK_END) {
@@ -987,8 +990,13 @@ static void Css_parse_ruleset (CssParser *parser)
parser->context->addRule (new CssRule (s, props), CSS_PRIMARY_AUTHOR);
parser->context->addRule (new CssRule (s, importantProps), CSS_PRIMARY_AUTHOR_IMPORTANT);
}
+
+ s->unref ();
}
+ props->unref ();
+ importantProps->unref ();
+
delete list;
if (parser->ttype == CSS_TK_CHAR && parser->tval[0] == '}')