From c6ca51309c050eafdb81fd33226d6ebde440bfa2 Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 21 Nov 2023 22:01:21 +0100 Subject: css/values: simplify getComputedValue --- src/css/values.nim | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/css') 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]): -- cgit