about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-29 23:21:36 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-29 23:22:04 +0100
commitf4b53af1261e6f9be16a315247ace80fcb816505 (patch)
tree4147107b5115e9d073dc8905fc9736e51adda8e3
parent6de9ada2e58d4bc341bb7f23db6db08d8b95d8e2 (diff)
downloadchawan-f4b53af1261e6f9be16a315247ace80fcb816505.tar.gz
css: fix shorthands not overriding all values
background & list-style did not override unspecified values
-rw-r--r--src/css/values.nim61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/css/values.nim b/src/css/values.nim
index e1282f57..41fe3f27 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -1392,45 +1392,48 @@ proc getComputedValues0(res: var seq[CSSComputedEntry], d: CSSDeclaration):
     res.add(?lengthShorthand(d, PropertyPaddingSpec))
   of SHORTHAND_BACKGROUND:
     let global = cssGlobal(d)
-    let bgcolorptype = PROPERTY_BACKGROUND_COLOR
-    let bgcolorval = CSSComputedValue(v: valueType(bgcolorptype))
-    let bgimageptype = PROPERTY_BACKGROUND_IMAGE
-    let bgimageval = CSSComputedValue(v: valueType(bgimageptype))
+    var bgcolorval = getDefault(PROPERTY_BACKGROUND_COLOR)
+    var bgimageval = getDefault(PROPERTY_BACKGROUND_IMAGE)
+    var valid = true
     if global == VALUE_NOGLOBAL:
       for tok in d.value:
         if tok == CSS_WHITESPACE_TOKEN:
           continue
-        let r = cssImage(tok)
-        if r.isOk:
-          bgimageval.image = r.get
-          res.add((bgimageptype, bgimageval, global))
+        if (let r = cssImage(tok); r.isOk):
+          bgimageval = CSSComputedValue(v: VALUE_IMAGE, image: r.get)
+        elif (let r = cssColor(tok); r.isOk):
+          bgcolorval = CSSComputedValue(v: VALUE_COLOR, color: r.get)
         else:
-          let r = cssColor(tok)
-          if r.isOk:
-            bgcolorval.color = r.get
-            res.add((bgcolorptype, bgcolorval, global))
-    else:
-      res.add((bgcolorptype, bgcolorval, global))
+          #TODO when we implement the other shorthands too
+          #valid = false
+          discard
+    if valid:
+      res.add((PROPERTY_BACKGROUND_COLOR, bgcolorval, global))
+      res.add((PROPERTY_BACKGROUND_IMAGE, bgimageval, global))
   of SHORTHAND_LIST_STYLE:
     let global = cssGlobal(d)
-    let positionptype = PROPERTY_LIST_STYLE_POSITION
-    let positionval = CSSComputedValue(v: valueType(positionptype))
-    let typeptype = PROPERTY_LIST_STYLE_TYPE
-    let typeval = CSSComputedValue(v: valueType(typeptype))
+    var positionval = getDefault(PROPERTY_LIST_STYLE_POSITION)
+    var typeval = getDefault(PROPERTY_LIST_STYLE_TYPE)
+    var valid = true
     if global == VALUE_NOGLOBAL:
       for tok in d.value:
-        let r = cssListStylePosition(tok)
-        if r.isOk:
-          positionval.liststyleposition = r.get
-          res.add((positionptype, positionval, global))
+        if (let r = cssListStylePosition(tok); r.isOk):
+          positionval = CSSComputedValue(
+            v: VALUE_LIST_STYLE_POSITION,
+            liststyleposition: r.get
+          )
+        elif (let r = cssListStyleType(tok); r.isOk):
+          positionval = CSSComputedValue(
+            v: VALUE_LIST_STYLE_TYPE,
+            liststyletype: r.get
+          )
         else:
-          let r = cssListStyleType(tok)
-          if r.isOk:
-            typeval.liststyletype = r.get
-            res.add((typeptype, typeval, global))
-          else:
-            #TODO list-style-image
-            discard
+          #TODO list-style-image
+          #valid = false
+          discard
+    if valid:
+      res.add((PROPERTY_LIST_STYLE_TYPE, positionval, global))
+      res.add((PROPERTY_LIST_STYLE_POSITION, typeval, global))
   return ok()
 
 proc getComputedValues(d: CSSDeclaration): seq[CSSComputedEntry] =