about summary refs log tree commit diff stats
path: root/src/css
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-11-21 22:01:21 +0100
committerbptato <nincsnevem662@gmail.com>2023-11-21 22:01:21 +0100
commitc6ca51309c050eafdb81fd33226d6ebde440bfa2 (patch)
treedd33b7ae2160dcdd68da1655312ca5ed1562f7d2 /src/css
parenta2be8910e51d647b6ec85a571cd8e68145c013f6 (diff)
downloadchawan-c6ca51309c050eafdb81fd33226d6ebde440bfa2.tar.gz
css/values: simplify getComputedValue
Diffstat (limited to 'src/css')
-rw-r--r--src/css/values.nim21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/css/values.nim b/src/css/values.nim
index 2a5b85eb..61813571 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -1209,20 +1209,19 @@ func getInitialTable(): array[CSSPropertyType, CSSComputedValue] =
 
 let defaultTable = getInitialTable()
 
-template getDefault(t: CSSPropertyType): CSSComputedValue = {.cast(noSideEffect).}:
-  defaultTable[t]
+template getDefault(t: CSSPropertyType): CSSComputedValue =
+  {.cast(noSideEffect).}:
+    defaultTable[t]
+
+type CSSComputedValueMaybeGlobal = (CSSComputedValue, CSSGlobalValueType)
 
 func getComputedValue(d: CSSDeclaration, ptype: CSSPropertyType,
-    vtype: CSSValueType):
-    Result[(CSSComputedValue, CSSGlobalValueType), string] =
+    vtype: CSSValueType): Result[CSSComputedValueMaybeGlobal, string] =
   let global = cssGlobal(d)
-  var val = CSSComputedValue(t: ptype, v: vtype)
-  let r = val.getValueFromDecl(d, vtype, ptype)
-  if r.isErr:
-    if global != VALUE_NOGLOBAL:
-      return ok((val, global))
-    else:
-      return err(r.error)
+  let val = CSSComputedValue(t: ptype, v: vtype)
+  if global != VALUE_NOGLOBAL:
+    return ok((val, global))
+  ?val.getValueFromDecl(d, vtype, ptype)
   return ok((val, global))
 
 func lengthShorthand(d: CSSDeclaration, props: array[4, CSSPropertyType]):