about summary refs log tree commit diff stats
path: root/src/css
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-09 22:02:54 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-09 22:05:26 +0200
commit5e78cf0100e762593168bb94e2438d1cead53e45 (patch)
tree77bf6763efd550aa882d1a22f5a5ce0852478dd9 /src/css
parent2bc57a09aeccd70c27501e67cb5078e2dc7e7ad4 (diff)
downloadchawan-5e78cf0100e762593168bb94e2438d1cead53e45.tar.gz
cascade: fix style caching
the invalid flag must be toggled after styling
Diffstat (limited to 'src/css')
-rw-r--r--src/css/cascade.nim10
-rw-r--r--src/css/stylednode.nim4
2 files changed, 8 insertions, 6 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index 6f62b68d..4302b21c 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -498,19 +498,23 @@ proc applyRulesFrameInvalid(frame: CascadeFrame; ua, user: CSSStylesheet;
     assert child != nil
     if styledParent != nil:
       if child of Element:
-        styledChild = styledParent.newStyledElement(Element(child))
+        let element = Element(child)
+        styledChild = styledParent.newStyledElement(element)
         styledParent.children.add(styledChild)
         declmap = styledChild.calcRules(ua, user, author)
         applyStyle(styledParent, styledChild, declmap)
+        element.invalid = false
       elif child of Text:
         let text = Text(child)
         styledChild = styledParent.newStyledText(text)
         styledParent.children.add(styledChild)
     else:
       # Root element
-      styledChild = newStyledElement(Element(child))
+      let element = Element(child)
+      styledChild = newStyledElement(element)
       declmap = styledChild.calcRules(ua, user, author)
       applyStyle(styledParent, styledChild, declmap)
+      element.invalid = false
   return styledChild
 
 proc stackAppend(styledStack: var seq[CascadeFrame]; frame: CascadeFrame;
@@ -630,7 +634,7 @@ proc applyRules(document: Document; ua, user: CSSStylesheet;
       if styledChild.t == stElement and styledChild.node != nil:
         styledStack.appendChildren(frame, styledChild, declmap)
   for element in toReset:
-    element.invalid = true
+    element.invalid = false
     element.invalidDeps = {}
   return root
 
diff --git a/src/css/stylednode.nim b/src/css/stylednode.nim
index dc90856d..1b3a645b 100644
--- a/src/css/stylednode.nim
+++ b/src/css/stylednode.nim
@@ -107,9 +107,7 @@ func parentElement*(node: StyledNode): StyledNode {.inline.} =
   node.parent
 
 proc isValid*(styledNode: StyledNode; toReset: var seq[Element]): bool =
-  if styledNode.t == stText:
-    return true
-  if styledNode.t == stReplacement:
+  if styledNode.t in {stText, stReplacement}:
     return true
   if styledNode.node != nil:
     let element = Element(styledNode.node)