diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2008-12-01 21:56:23 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2008-12-01 21:56:23 +0100 |
commit | 74a8390c5ffbcf41bf1361d4e13ec2d85a021d33 (patch) | |
tree | 8ad1a12093ca10517c6b1753db958f1b3ecadc61 /src/css.cc | |
parent | 122167b63adafda62d57bd9581065d2889e1dabb (diff) |
streamline CssSelector a bit
Diffstat (limited to 'src/css.cc')
-rw-r--r-- | src/css.cc | 50 |
1 files changed, 24 insertions, 26 deletions
@@ -48,9 +48,9 @@ void CssPropertyList::print () { CssSelector::CssSelector (int element, const char *klass, const char *pseudo, const char *id) { refCount = 0; - combinator = NULL; - simpleSelector = new lout::misc::SimpleVector <CssSimpleSelector> (1); - simpleSelector->increase (); + selectorList = new lout::misc::SimpleVector + <struct CombinatorAndSelector> (1); + selectorList->increase (); top ()->element = element; top ()->klass = klass; top ()->pseudo = pseudo; @@ -62,18 +62,16 @@ bool CssSelector::match (Doctree *docTree) { Combinator comb; const DoctreeNode *node = docTree->top (); - assert (simpleSelector->size () > 0); - assert ((combinator == NULL && simpleSelector->size () == 1) || - combinator->size () == simpleSelector->size () - 1); + assert (selectorList->size () > 0); sel = top (); if (! sel->match (node)) return false; - for (int i = simpleSelector->size () - 2; i >= 0; i--) { - sel = simpleSelector->getRef (i); - comb = combinator->get (i); + for (int i = selectorList->size () - 2; i >= 0; i--) { + sel = &selectorList->getRef (i)->selector; + comb = selectorList->getRef (i + 1)->combinator; node = docTree->parent (node); if (node == NULL) @@ -102,12 +100,9 @@ bool CssSelector::match (Doctree *docTree) { void CssSelector::addSimpleSelector (Combinator c, int element, const char *klass, const char *pseudo, const char *id) { - simpleSelector->increase (); - if (combinator == NULL) - combinator = new lout::misc::SimpleVector <Combinator> (1); - combinator->increase (); + selectorList->increase (); - *combinator->getRef (combinator->size () - 1) = c; + selectorList->getRef (selectorList->size () - 1)->combinator = c; top ()->element = element; top ()->klass = klass; top ()->pseudo = pseudo; @@ -116,18 +111,21 @@ void CssSelector::addSimpleSelector (Combinator c, int element, } void CssSelector::print () { - for (int i = 0; i < simpleSelector->size () - 1; i++) { - simpleSelector->getRef (i)->print (); - switch (combinator->get (i)) { - case CHILD: - fprintf (stderr, ">"); - break; - case DESCENDENT: - fprintf (stderr, " "); - break; - default: - fprintf (stderr, "?"); - break; + for (int i = 0; i < selectorList->size () - 1; i++) { + selectorList->getRef (i)->selector.print (); + + if (i < selectorList->size () - 2) { + switch (selectorList->getRef (i)->combinator) { + case CHILD: + fprintf (stderr, ">"); + break; + case DESCENDENT: + fprintf (stderr, " "); + break; + default: + fprintf (stderr, "?"); + break; + } } } |