MCPcopy Create free account
hub / github.com/dillo-browser/dillo / match

Method match

src/css.cc:127–171  ·  view source on GitHub ↗

* \brief Return whether selector matches at a given node in the document tree. */

Source from the content-addressed store, hash-verified

125 * \brief Return whether selector matches at a given node in the document tree.
126 */
127bool CssSelector::match (Doctree *docTree, const DoctreeNode *node,
128 int i, Combinator comb, MatchCache *matchCache) {
129 int *matchCacheEntry;
130 assert (node);
131
132 if (i < 0)
133 return true;
134
135 struct CombinatorAndSelector *cs = selectorList.getRef (i);
136 CssSimpleSelector *sel = cs->selector;
137
138 switch (comb) {
139 case COMB_NONE:
140 break;
141 case COMB_CHILD:
142 node = docTree->parent (node);
143 break;
144 case COMB_ADJACENT_SIBLING:
145 node = docTree->sibling (node);
146 break;
147 case COMB_DESCENDANT:
148 node = docTree->parent (node);
149 matchCacheEntry = matchCache->getRef(matchCacheOffset + i);
150
151 for (const DoctreeNode *n = node;
152 n && n->num > *matchCacheEntry; n = docTree->parent (n))
153 if (sel->match (n) &&
154 match (docTree, n, i - 1, cs->combinator, matchCache))
155 return true;
156
157 if (node) // remember that it didn't match to avoid future tests
158 *matchCacheEntry = node->num;
159
160 return false;
161 break;
162 default:
163 return false; // \todo implement other combinators
164 }
165
166 if (!node || !sel->match (node))
167 return false;
168
169 // tail recursion should be optimized by the compiler
170 return match (docTree, node, i - 1, cs->combinator, matchCache);
171}
172
173void CssSelector::addSimpleSelector (Combinator c) {
174 struct CombinatorAndSelector *cs;

Callers 1

applyMethod · 0.45

Calls 6

dStrAsciiCasecmpFunction · 0.85
parentMethod · 0.80
siblingMethod · 0.80
getRefMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected