about summary refs log tree commit diff stats
path: root/src/css
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-01-01 03:17:55 +0100
committerbptato <nincsnevem662@gmail.com>2023-01-01 03:18:25 +0100
commit004966d06322c942fd641bef2579c67e40737435 (patch)
tree974b65f86fa957a2458751546aa18fcc19c7d4a7 /src/css
parentb1e13dc24349d0ec4b504ac358f7a505926b6416 (diff)
downloadchawan-004966d06322c942fd641bef2579c67e40737435.tar.gz
cascade: document a bit
Diffstat (limited to 'src/css')
-rw-r--r--src/css/cascade.nim9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index 07ff5e9a..7822bca2 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -246,7 +246,8 @@ proc applyRules(document: Document, ua, user: CSSStylesheet, cachedTree: StyledN
       continue
 
     var styledChild: StyledNode
-    if cachedChild != nil and cachedChild.isValid():
+    let valid = cachedChild != nil and cachedChild.isValid()
+    if valid:
       if cachedChild.t == STYLED_ELEMENT:
         if cachedChild.pseudo == PSEUDO_NONE:
           # We can't just copy cachedChild.children from the previous pass, as
@@ -266,6 +267,10 @@ proc applyRules(document: Document, ua, user: CSSStylesheet, cachedTree: StyledN
       else:
         styledParent.children.add(styledChild)
     else:
+      # From here on, computed values of this node's children are invalid
+      # (because of inheritance).
+      # That said, we could do this way more efficiently... TODO.
+      # (For example, we could replace the parent's computed values in-place.)
       cachedChild = nil
       if pseudo != PSEUDO_NONE:
         let (ua, user, authordecls) = styledParent.calcRules(ua, user, author)
@@ -364,7 +369,7 @@ proc applyRules(document: Document, ua, user: CSSStylesheet, cachedTree: StyledN
           styledStack.add((styledParent, nil, ps, nil))
 
       let elem = Element(styledChild.node)
-      if cachedChild != nil and result != styledChild:
+      if valid and result != styledChild:
         styledChild.sheets = cachedChild.sheets
       else:
         if result == styledChild: