about summary refs log tree commit diff stats
path: root/src/css/style.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-11-23 13:47:50 +0100
committerbptato <nincsnevem662@gmail.com>2021-11-23 13:56:53 +0100
commitfbac38a0b0ce15954f8ba441a7a1adfb67dd8a80 (patch)
tree27b1541b043f3d3a79de7818091d6e7d25c707f4 /src/css/style.nim
parent820d64f453829691013bc83be73ca36a1a5673bd (diff)
downloadchawan-fbac38a0b0ce15954f8ba441a7a1adfb67dd8a80.tar.gz
Allow matching root element, write last buffer display line instantly
Diffstat (limited to 'src/css/style.nim')
-rw-r--r--src/css/style.nim13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/css/style.nim b/src/css/style.nim
index 556fba67..7a453165 100644
--- a/src/css/style.nim
+++ b/src/css/style.nim
@@ -42,6 +42,7 @@ func pseudoSelectorMatches(elem: Element, sel: Selector): bool =
   of "first-child": return elem.parentNode.firstElementChild == elem
   of "last-child": return 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 =
@@ -79,7 +80,7 @@ func selectorMatches(elem: Element, sel: Selector): SelectResult =
       case sel.ct
       of DESCENDANT_COMBINATOR:
         var e = elem.parentElement
-        while e != nil and e != elem.ownerDocument.root and i >= 0:
+        while e != nil and i >= 0:
           let res = e.selectorsMatch(sel.csels[i])
 
           if res.pseudo != PSEUDO_NONE:
@@ -90,7 +91,7 @@ func selectorMatches(elem: Element, sel: Selector): SelectResult =
           e = e.parentElement
       of CHILD_COMBINATOR:
         var e = elem.parentElement
-        while e != nil and e != elem.ownerDocument.root and i >= 0:
+        while e != nil and i >= 0:
           let res = e.selectorsMatch(sel.csels[i])
 
           if res.pseudo != PSEUDO_NONE:
@@ -232,9 +233,8 @@ func calcRules(elem: Element, rules: ParsedStylesheet):
 proc applyRules*(document: Document, pss: ParsedStylesheet, reset: bool = false): ApplyResult =
   var stack: seq[Element]
 
-  stack.add(document.head)
-  stack.add(document.body)
   document.root.cssvalues.rootProperties()
+  stack.add(document.root)
 
   while stack.len > 0:
     let elem = stack.pop()
@@ -275,7 +275,7 @@ proc applyAuthorRules*(document: Document): ApplyResult =
 
   stack.setLen(0)
 
-  stack.add(document.body)
+  stack.add(document.root)
 
   if rules_head.len > 0:
     let parsed = newStringStream(rules_head).parseStylesheet()
@@ -352,4 +352,5 @@ proc applyStylesheets*(document: Document, uass: ParsedStylesheet, userss: Parse
     rule.e.applyProperty(rule.d, rule.p)
 
   for elem in elems:
-    elem.cssvalues.inheritProperties(elem.parentElement.cssvalues)
+    if elem.parentElement != nil:
+      elem.cssvalues.inheritProperties(elem.parentElement.cssvalues)