about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-07-29 19:08:19 +0200
committerbptato <nincsnevem662@gmail.com>2022-07-29 19:08:19 +0200
commitd207bf1d5ec19bfaac8f65e600cab05ddd35f74e (patch)
tree32485c9ac044622ba4e435d65e92aaf98b171876 /src
parent70c54e2a05426b2ba9d155440fa06c19fabd4c52 (diff)
downloadchawan-d207bf1d5ec19bfaac8f65e600cab05ddd35f74e.tar.gz
StyledNode: avoid duplicate dependencies
Diffstat (limited to 'src')
-rw-r--r--src/css/select.nim4
-rw-r--r--src/css/stylednode.nim4
2 files changed, 6 insertions, 2 deletions
diff --git a/src/css/select.nim b/src/css/select.nim
index f1140d1e..f47df9af 100644
--- a/src/css/select.nim
+++ b/src/css/select.nim
@@ -29,7 +29,7 @@ func pseudoSelectorMatches[T: Element|StyledNode](elem: T, sel: Selector, felem:
   of PSEUDO_LAST_CHILD: return elem.parentNode.lastElementChild == elem
   of PSEUDO_ONLY_CHILD: return elem.parentNode.firstElementChild == elem and elem.parentNode.lastElementChild == elem
   of PSEUDO_HOVER:
-    when selem is StyledNode: felem.depends.nodes[DEPEND_HOVER].add(selem)
+    when selem is StyledNode: felem.addDependency(selem, DEPEND_HOVER)
     return elem.hover
   of PSEUDO_ROOT: return elem == elem.document.html
   of PSEUDO_NTH_CHILD:
@@ -41,7 +41,7 @@ func pseudoSelectorMatches[T: Element|StyledNode](elem: T, sel: Selector, felem:
       inc i
     return false
   of PSEUDO_CHECKED:
-    when selem is StyledNode: felem.depends.nodes[DEPEND_CHECKED].add(selem)
+    when selem is StyledNode: felem.addDependency(selem, DEPEND_CHECKED)
     if elem.tagType == TAG_INPUT:
       return HTMLInputElement(elem).checked
     elif elem.tagType == TAG_OPTION:
diff --git a/src/css/stylednode.nim b/src/css/stylednode.nim
index 8586bee4..f575d99a 100644
--- a/src/css/stylednode.nim
+++ b/src/css/stylednode.nim
@@ -101,6 +101,10 @@ proc applyDependValues*(styledNode: StyledNode) =
   styledNode.depends.prev[DEPEND_CHECKED] = elem.checked
   elem.invalid = false
 
+proc addDependency*(styledNode, dep: StyledNode, t: DependencyType) =
+  if dep notin styledNode.depends.nodes[t]:
+    styledNode.depends.nodes[t].add(dep)
+
 func newStyledElement*(parent: StyledNode, element: Element, computed: CSSComputedValues, reg: sink DependencyInfo): StyledNode =
   result = StyledNode(t: STYLED_ELEMENT, computed: computed, node: element, parent: parent)
   result.depends = reg