diff options
author | bptato <nincsnevem662@gmail.com> | 2024-07-03 17:21:14 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-07-03 17:21:14 +0200 |
commit | d0c43d69f5c64d01230c79458f473eb9ecd5a7e1 (patch) | |
tree | 6409d32007555c56d93d5f95b921bfcd977fefce /src/css | |
parent | 1eb05b007a71dbd6589e722d2aeefdf6747da022 (diff) | |
download | chawan-d0c43d69f5c64d01230c79458f473eb9ecd5a7e1.tar.gz |
css, html: fix CSS dependency invalidation
Diffstat (limited to 'src/css')
-rw-r--r-- | src/css/cascade.nim | 9 | ||||
-rw-r--r-- | src/css/stylednode.nim | 46 |
2 files changed, 19 insertions, 36 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim index bfb5b172..6f62b68d 100644 --- a/src/css/cascade.nim +++ b/src/css/cascade.nim @@ -332,7 +332,7 @@ proc applyDeclarations(styledNode: StyledNode; parent: CSSComputedValues; rules[coAuthor].add(rule[peNone]) if styledNode.node != nil: let element = Element(styledNode.node) - let style = element.style_cached + let style = element.cachedStyle if style != nil: for decl in style.decls: let vals = parseComputedValues(decl.name, decl.value) @@ -610,11 +610,12 @@ proc applyRules(document: Document; ua, user: CSSStylesheet; cachedChild: cachedTree )] var root: StyledNode + var toReset: seq[Element] = @[] while styledStack.len > 0: var frame = styledStack.pop() var declmap: RuleListMap let styledParent = frame.styledParent - let valid = frame.cachedChild != nil and frame.cachedChild.isValid() + let valid = frame.cachedChild != nil and frame.cachedChild.isValid(toReset) let styledChild = if valid: frame.applyRulesFrameValid() else: @@ -627,8 +628,10 @@ proc applyRules(document: Document; ua, user: CSSStylesheet; # Root element root = styledChild if styledChild.t == stElement and styledChild.node != nil: - styledChild.applyDependValues() styledStack.appendChildren(frame, styledChild, declmap) + for element in toReset: + element.invalid = true + element.invalidDeps = {} return root proc applyStylesheets*(document: Document; uass, userss: CSSStylesheet; diff --git a/src/css/stylednode.nim b/src/css/stylednode.nim index a5d2b44b..0fcdb6ad 100644 --- a/src/css/stylednode.nim +++ b/src/css/stylednode.nim @@ -1,4 +1,3 @@ -import chame/tags import css/cssvalues import css/selectorparser import html/dom @@ -87,15 +86,14 @@ iterator elementList_rev*(node: StyledNode): StyledNode {.inline.} = for i in countdown(node.children.high, 0): yield node.children[i] -func findElement*(root: StyledNode; elem: Element): StyledNode = - var stack: seq[StyledNode] +func findElement*(root: StyledNode; element: Element): StyledNode = + var stack: seq[StyledNode] = @[] for child in root.elementList_rev: if child.t == stElement and child.pseudo == peNone: stack.add(child) - let en = Node(elem) while stack.len > 0: let node = stack.pop() - if node.node == en: + if node.node == element: return node for child in node.elementList_rev: if child.t == stElement and child.pseudo == peNone: @@ -108,41 +106,23 @@ func isDomElement*(styledNode: StyledNode): bool {.inline.} = func parentElement*(node: StyledNode): StyledNode {.inline.} = node.parent -func checked(element: Element): bool = - if element.tagType == TAG_INPUT: - let input = HTMLInputElement(element) - result = input.checked - -func isValid*(styledNode: StyledNode): bool = +proc isValid*(styledNode: StyledNode; toReset: var seq[Element]): bool = if styledNode.t == stText: return true if styledNode.t == stReplacement: return true - if styledNode.node != nil and Element(styledNode.node).invalid: - return false + if styledNode.node != nil: + let element = Element(styledNode.node) + if element.invalid: + toReset.add(element) + return false for d in DependencyType: - for elem in styledNode.depends[d]: - case d - of dtHover: - if elem.prev[d] != elem.hover: - return false - of dtChecked: - if elem.prev[d] != elem.checked: - return false - of dtFocus: - let focus = elem.document.focus == elem - if elem.prev[d] != focus: - return false + for dep in styledNode.depends[d]: + if d in dep.invalidDeps: + toReset.add(dep) + return false return true -proc applyDependValues*(styledNode: StyledNode) = - let elem = Element(styledNode.node) - elem.prev[dtHover] = elem.hover - elem.prev[dtChecked] = elem.checked - let focus = elem.document.focus == elem - elem.prev[dtFocus] = focus - elem.invalid = false - proc addDependency*(styledNode: StyledNode; dep: Element; t: DependencyType) = if dep notin styledNode.depends[t]: styledNode.depends[t].add(dep) |