diff options
author | bptato <nincsnevem662@gmail.com> | 2022-01-23 11:24:17 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-01-23 11:26:06 +0100 |
commit | 806e38f140b377b308ed41622d795c21a497bd44 (patch) | |
tree | b068216741d260bebb6f1f9c2943f77bb3ccc1f0 /src/css/select.nim | |
parent | eeebe788fef445e6fb7f92596a47238205e33a10 (diff) | |
download | chawan-806e38f140b377b308ed41622d795c21a497bd44.tar.gz |
Support pseudo elems as pseudo classes
Diffstat (limited to 'src/css/select.nim')
-rw-r--r-- | src/css/select.nim | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/css/select.nim b/src/css/select.nim index ec285432..3a2e0e27 100644 --- a/src/css/select.nim +++ b/src/css/select.nim @@ -32,21 +32,24 @@ func attrSelectorMatches(elem: Element, sel: Selector): bool = of '*': return elem.attr(sel.attr).contains(sel.value) else: return false -func pseudoSelectorMatches(elem: Element, sel: Selector): bool = - case sel.pseudo - of "first-child": return elem.parentNode.firstElementChild == elem - of "last-child": return elem.parentNode.lastElementChild == elem - of "only-child": return elem.parentNode.firstElementChild == elem and elem.parentNode.lastElementChild == elem - of "hover": return elem.hover - of "root": return elem == elem.ownerDocument.root - else: return false - -func pseudoElemSelectorMatches(elem: Element, sel: Selector): SelectResult = - case sel.elem +func pseudoElemSelectorMatches(elem: Element, s: string): SelectResult = + case s of "before": return selectres(true, PSEUDO_BEFORE) of "after": return selectres(true, PSEUDO_AFTER) else: return selectres(false) +func pseudoElemSelectorMatches(elem: Element, sel: Selector): SelectResult = + return elem.pseudoElemSelectorMatches(sel.elem) + +func pseudoSelectorMatches(elem: Element, sel: Selector): SelectResult = + case sel.pseudo + of "first-child": return selectres(elem.parentNode.firstElementChild == elem) + of "last-child": return selectres(elem.parentNode.lastElementChild == elem) + of "only-child": return selectres(elem.parentNode.firstElementChild == elem and elem.parentNode.lastElementChild == elem) + of "hover": return selectres(elem.hover) + of "root": return selectres(elem == elem.ownerDocument.root) + else: return elem.pseudoElemSelectorMatches(sel.pseudo) + func selectorsMatch*(elem: Element, selectors: SelectorList): SelectResult func funcSelectorMatches(elem: Element, sel: Selector): SelectResult = @@ -133,7 +136,7 @@ func selectorMatches(elem: Element, sel: Selector): SelectResult = of ATTR_SELECTOR: return selectres(elem.attrSelectorMatches(sel)) of PSEUDO_SELECTOR: - return selectres(pseudoSelectorMatches(elem, sel)) + return pseudoSelectorMatches(elem, sel) of PSELEM_SELECTOR: return pseudoElemSelectorMatches(elem, sel) of UNIVERSAL_SELECTOR: |