diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-01-28 19:36:15 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-01-28 19:36:15 +0100 |
| commit | 94f2ed4c705d59787c7004138a28decd0ac6257a (patch) | |
| tree | bebdc60db1e411aae47aa20aafb3f27f5470dba9 /src/css/cascade.nim | |
| parent | 59601e40572c58cbc4d4be0c300756cd863da339 (diff) | |
| download | chawan-94f2ed4c705d59787c7004138a28decd0ac6257a.tar.gz | |
cascade: fix variable inheritance
Diffstat (limited to 'src/css/cascade.nim')
| -rw-r--r-- | src/css/cascade.nim | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim index 57491938..09789eba 100644 --- a/src/css/cascade.nim +++ b/src/css/cascade.nim @@ -43,6 +43,7 @@ type ApplyValueContext = object vals: CSSValues + vars: CSSVariableMap parentComputed: CSSValues previousOrigin: CSSValues window: Window @@ -50,7 +51,7 @@ type varsSeen: HashSet[CAtom] # Forward declarations -proc applyValue(ctx: var ApplyValueContext; entry: CSSComputedEntry; +proc applyValue0(ctx: var ApplyValueContext; entry: CSSComputedEntry; initType: InitType; nextInitType: set[InitType]) proc applyStyle*(element: Element) @@ -98,28 +99,27 @@ proc calcRules(map: var RuleListMap; element: Element; for item in it: map[pseudo][origin].add(item.rule) -proc findVariable(computed: CSSValues; varName: CAtom): CSSVariable = - var vars = computed.vars - while vars != nil: - let cvar = vars.table.getOrDefault(varName) +proc findVariable(ctx: var ApplyValueContext; varName: CAtom): CSSVariable = + while ctx.vars != nil: + let cvar = ctx.vars.table.getOrDefault(varName) if cvar != nil: return cvar - vars = vars.parent + ctx.vars = ctx.vars.parent return nil proc applyVariable(ctx: var ApplyValueContext; t: CSSPropertyType; varName: CAtom; fallback: ref CSSComputedEntry; initType: InitType; nextInitType: set[InitType]) = let v = t.valueType - let cvar = ctx.vals.findVariable(varName) + let cvar = ctx.findVariable(varName) if cvar == nil: if fallback != nil: - ctx.applyValue(fallback[], initType, nextInitType) + ctx.applyValue0(fallback[], initType, nextInitType) return for (iv, entry) in cvar.resolved.mitems: if iv == v: entry.t = t # must override, same var can be used for different props - ctx.applyValue(entry, initType, nextInitType) + ctx.applyValue0(entry, initType, nextInitType) return var entries: seq[CSSComputedEntry] = @[] if entries.parseComputedValues($t, cvar.cvals, ctx.window.attrsp[], @@ -131,7 +131,7 @@ proc applyVariable(ctx: var ApplyValueContext; t: CSSPropertyType; else: ctx.varsSeen.clear() cvar.resolved.add((v, entries[0])) - ctx.applyValue(entries[0], initType, nextInitType) + ctx.applyValue0(entries[0], initType, nextInitType) proc applyGlobal(ctx: ApplyValueContext; t: CSSPropertyType; global: CSSGlobalType; initType: InitType) = @@ -148,7 +148,7 @@ proc applyGlobal(ctx: ApplyValueContext; t: CSSPropertyType; else: ctx.vals.initialOrInheritFrom(ctx.parentComputed, t) -proc applyValue(ctx: var ApplyValueContext; entry: CSSComputedEntry; +proc applyValue0(ctx: var ApplyValueContext; entry: CSSComputedEntry; initType: InitType; nextInitType: set[InitType]) = case entry.et of ceBit: ctx.vals.bits[entry.t].dummy = entry.bit @@ -162,6 +162,11 @@ proc applyValue(ctx: var ApplyValueContext; entry: CSSComputedEntry; return # maybe it applies, maybe it doesn't... ctx.initMap[entry.t] = ctx.initMap[entry.t] + nextInitType +proc applyValue(ctx: var ApplyValueContext; entry: CSSComputedEntry; + initType: InitType; nextInitType: set[InitType]) = + ctx.vars = ctx.vals.vars + ctx.applyValue0(entry, initType, nextInitType) + proc applyPresHints(ctx: var ApplyValueContext; element: Element) = template set_cv(t, x, b: untyped) = ctx.applyValue(makeEntry(t, CSSValueWord(x: b)), itUserAgent, {itUser}) |