aboutsummaryrefslogtreecommitdiffstats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-02-14 18:04:10 +0100
committerbptato <nincsnevem662@gmail.com>2025-02-14 18:04:10 +0100
commit99f85de667d18fb17b0357399e4005095b10a1b3 (patch)
treea19db43faf38ae3754379c8e834f6ce5f009f6ba /src/html
parent1ee2f67e1d7b2f8d164047a1250033de6aa7f3fb (diff)
downloadchawan-99f85de667d18fb17b0357399e4005095b10a1b3.tar.gz
dom: store pseudo-element computed values in a seq
A map isn't so bad with three pointers, but it won't be viable once we start adding more pseudo-elements.
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 28859e27..cdfb0e9a 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -284,7 +284,8 @@ type
attrs*: seq[AttrData] # sorted by int(qualifiedName)
cachedAttributes: NamedNodeMap
cachedStyle*: CSSStyleDeclaration
- computedMap*: array[peNone..peAfter, CSSValues]
+ computed*: CSSValues
+ computedMap*: seq[tuple[pseudo: PseudoElement; computed: CSSValues]]
AttrDummyElement = ref object of Element
@@ -3823,13 +3824,10 @@ proc delAttr(element: Element; i: int; keep = false) =
element.invalidate()
# Styles.
-template computed*(element: Element): CSSValues =
- element.computedMap[peNone]
-
proc invalidate*(element: Element) =
let valid = element.computed != nil
- for it in element.computedMap.mitems:
- it = nil
+ element.computed = nil
+ element.computedMap.setLen(0)
if element.document != nil:
element.document.invalid = true
if valid:
@@ -4032,6 +4030,14 @@ proc style*(element: Element): CSSStyleDeclaration {.jsfget.} =
element.cachedStyle = newCSSStyleDeclaration(element, "")
return element.cachedStyle
+proc getComputedStyle*(element: Element; pseudo: PseudoElement): CSSValues =
+ if pseudo == peNone:
+ return element.computed
+ for it in element.computedMap:
+ if it.pseudo == pseudo:
+ return it.computed
+ return nil
+
proc getComputedStyle0*(window: Window; element: Element;
pseudoElt: Option[string]): CSSStyleDeclaration =
let pseudo = case pseudoElt.get("")
@@ -4041,7 +4047,7 @@ proc getComputedStyle0*(window: Window; element: Element;
else: return newCSSStyleDeclaration(nil, "")
if window.settings.scripting == smApp:
window.maybeRestyle(element)
- return newCSSStyleDeclaration(element, $element.computedMap[pseudo],
+ return newCSSStyleDeclaration(element, $element.getComputedStyle(pseudo),
computed = true, readonly = true)
# In lite mode, we just parse the "style" attribute and hope for
# the best.