diff options
author | bptato <nincsnevem662@gmail.com> | 2024-12-12 19:27:17 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-12-12 19:49:27 +0100 |
commit | 3be06da2cea7cfa60c1da7048392eba37ab18c39 (patch) | |
tree | 083ce543e5955455ee331067ce569ae29d58904e /src | |
parent | 3d7bbdf6707f93f497525e91921dbdc45a26212b (diff) | |
download | chawan-3be06da2cea7cfa60c1da7048392eba37ab18c39.tar.gz |
css: CSSComputedValue -> CSSValue
"Computed" was redundant; other types of values don't have a common type.
Diffstat (limited to 'src')
-rw-r--r-- | src/css/box.nim | 4 | ||||
-rw-r--r-- | src/css/cascade.nim | 10 | ||||
-rw-r--r-- | src/css/cssvalues.nim | 98 | ||||
-rw-r--r-- | src/css/layout.nim | 100 | ||||
-rw-r--r-- | src/css/render.nim | 2 | ||||
-rw-r--r-- | src/css/stylednode.nim | 4 |
6 files changed, 109 insertions, 109 deletions
diff --git a/src/css/box.nim b/src/css/box.nim index 3d35b2ab..3394d30d 100644 --- a/src/css/box.nim +++ b/src/css/box.nim @@ -59,7 +59,7 @@ type InlineFragment* = ref object state*: InlineFragmentState render*: BoxRenderState - computed*: CSSComputedValues + computed*: CSSValues node*: StyledNode splitType*: set[SplitType] case t*: InlineFragmentType @@ -86,7 +86,7 @@ type BlockBox* = ref object state*: BoxLayoutState render*: BoxRenderState - computed*: CSSComputedValues + computed*: CSSValues node*: StyledNode inline*: InlineFragment children*: seq[BlockBox] diff --git a/src/css/cascade.nim b/src/css/cascade.nim index 035573a0..2288466c 100644 --- a/src/css/cascade.nim +++ b/src/css/cascade.nim @@ -122,7 +122,7 @@ func calcPresHints(element: Element): seq[CSSComputedEntry] = result = @[] template set_cv(t, x, b: untyped) = const v = valueType(t) - result.add(makeEntry(t, CSSComputedValue(v: v, x: b))) + result.add(makeEntry(t, CSSValue(v: v, x: b))) template map_width = let s = parseDimensionValues(element.attr(satWidth)) if s.isSome: @@ -174,7 +174,7 @@ func calcPresHints(element: Element): seq[CSSComputedEntry] = if i <= 65534: set_cv cptChaRowspan, integer, int(i) template set_bgcolor_is_canvas = - var val = CSSComputedValueBit() + var val = CSSValueBit() val.bgcolorIsCanvas = true result.add(makeEntry(cptBgcolorIsCanvas, val)) template map_cellspacing = @@ -235,8 +235,8 @@ type CSSValueEntryMap = array[CSSOrigin, CSSValueEntryObj] func buildComputedValues(rules: CSSValueEntryMap; - presHints: openArray[CSSComputedEntry]; parent: CSSComputedValues): - CSSComputedValues = + presHints: openArray[CSSComputedEntry]; parent: CSSValues): + CSSValues = new(result) var inited = default(array[CSSPropertyType, bool]) var uaInited = default(array[CSSPropertyType, bool]) @@ -286,7 +286,7 @@ proc add(map: var CSSValueEntryObj; rules: seq[CSSRuleDef]) = map.normal.add(rule.normalVals) map.important.add(rule.importantVals) -proc applyDeclarations(styledNode: StyledNode; parent: CSSComputedValues; +proc applyDeclarations(styledNode: StyledNode; parent: CSSValues; map: RuleListMap; styling: bool) = var rules: CSSValueEntryMap var presHints: seq[CSSComputedEntry] = @[] diff --git a/src/css/cssvalues.nim b/src/css/cssvalues.nim index d7a25ff4..581c008a 100644 --- a/src/css/cssvalues.nim +++ b/src/css/cssvalues.nim @@ -340,7 +340,7 @@ type a*: CSSLength b*: CSSLength - CSSComputedValueBit* {.union.} = object + CSSValueBit* {.union.} = object dummy: uint8 bgcolorIsCanvas*: bool borderCollapse*: CSSBorderCollapse @@ -362,7 +362,7 @@ type whiteSpace*: CSSWhiteSpace wordBreak*: CSSWordBreak - CSSComputedValue* = ref object + CSSValue* = ref object case v*: CSSValueType of cvtColor: color*: CSSColor @@ -388,9 +388,9 @@ type image*: CSSContent else: discard - CSSComputedValues* = ref object - bits*: array[CSSPropertyType.low..cptFontStyle, CSSComputedValueBit] - objs*: array[cptColor..CSSPropertyType.high, CSSComputedValue] + CSSValues* = ref object + bits*: array[CSSPropertyType.low..cptFontStyle, CSSValueBit] + objs*: array[cptColor..CSSPropertyType.high, CSSValue] CSSOrigin* = enum coUserAgent @@ -401,7 +401,7 @@ type t*: CSSPropertyType global*: CSSGlobalType bit*: uint8 - obj*: CSSComputedValue + obj*: CSSValue const ValueTypes = [ cptNone: cvtNone, @@ -510,7 +510,7 @@ when defined(debug): result &= ' ' result &= $it.num - func `$`*(val: CSSComputedValue): string = + func `$`*(val: CSSValue): string = case val.v of cvtNone: return "none" of cvtColor: return $val.color @@ -526,7 +526,7 @@ when defined(debug): of cvtNumber: return $val.number else: assert false -macro `{}`*(vals: CSSComputedValues; s: static string): untyped = +macro `{}`*(vals: CSSValues; s: static string): untyped = let t = propertyType(s) let vs = ident($valueType(t)) if t.isBit: @@ -536,7 +536,7 @@ macro `{}`*(vals: CSSComputedValues; s: static string): untyped = return quote do: `vals`.objs[CSSPropertyType(`t`)].`vs` -macro `{}=`*(vals: CSSComputedValues; s: static string, val: typed) = +macro `{}=`*(vals: CSSValues; s: static string, val: typed) = let t = propertyType(s) let v = valueType(t) let vs = ident($v) @@ -545,7 +545,7 @@ macro `{}=`*(vals: CSSComputedValues; s: static string, val: typed) = `vals`.bits[CSSPropertyType(`t`)].dummy = uint8(`val`) else: return quote do: - `vals`.objs[CSSPropertyType(`t`)] = CSSComputedValue( + `vals`.objs[CSSPropertyType(`t`)] = CSSValue( v: CSSValueType(`v`), `vs`: `val` ) @@ -1151,11 +1151,11 @@ func cssNumber(cval: CSSComponentValue; positive: bool): Opt[float64] = return ok(tok.nvalue) return err() -proc makeEntry*(t: CSSPropertyType; obj: CSSComputedValue; global = cgtNone): +proc makeEntry*(t: CSSPropertyType; obj: CSSValue; global = cgtNone): CSSComputedEntry = return CSSComputedEntry(t: t, obj: obj, global: global) -proc makeEntry*(t: CSSPropertyType; bit: CSSComputedValueBit; global = cgtNone): +proc makeEntry*(t: CSSPropertyType; bit: CSSValueBit; global = cgtNone): CSSComputedEntry = return CSSComputedEntry(t: t, bit: bit.dummy, global: global) @@ -1173,7 +1173,7 @@ proc parseValue(cvals: openArray[CSSComponentValue]; inc i let v = valueType(t) template set_new(prop, val: untyped) = - entry.obj = CSSComputedValue(v: v, prop: val) + entry.obj = CSSValue(v: v, prop: val) template set_bit(prop, val: untyped) = entry.bit = uint8(val) case v @@ -1262,23 +1262,23 @@ func getInitialNumber(t: CSSPropertyType): float64 = return 1 return 0 -func calcInitial(t: CSSPropertyType): CSSComputedValue = +func calcInitial(t: CSSPropertyType): CSSValue = let v = valueType(t) case v - of cvtColor: return CSSComputedValue(v: v, color: getInitialColor(t)) - of cvtLength: return CSSComputedValue(v: v, length: getInitialLength(t)) - of cvtInteger: return CSSComputedValue(v: v, integer: getInitialInteger(t)) - of cvtQuotes: return CSSComputedValue(v: v, quotes: CSSQuotes(auto: true)) - of cvtNumber: return CSSComputedValue(v: v, number: getInitialNumber(t)) - else: return CSSComputedValue(v: v) - -func getInitialTable(): array[CSSPropertyType, CSSComputedValue] = + of cvtColor: return CSSValue(v: v, color: getInitialColor(t)) + of cvtLength: return CSSValue(v: v, length: getInitialLength(t)) + of cvtInteger: return CSSValue(v: v, integer: getInitialInteger(t)) + of cvtQuotes: return CSSValue(v: v, quotes: CSSQuotes(auto: true)) + of cvtNumber: return CSSValue(v: v, number: getInitialNumber(t)) + else: return CSSValue(v: v) + +func getInitialTable(): array[CSSPropertyType, CSSValue] = for t in CSSPropertyType: result[t] = calcInitial(t) let defaultTable = getInitialTable() -template getDefault*(t: CSSPropertyType): CSSComputedValue = +template getDefault*(t: CSSPropertyType): CSSValue = {.cast(noSideEffect).}: defaultTable[t] @@ -1290,12 +1290,12 @@ func lengthShorthand(cvals: openArray[CSSComponentValue]; for t in props: res.add(makeEntry(t, global)) return ok(res) - var lengths: seq[CSSComputedValue] = @[] + var lengths: seq[CSSValue] = @[] var i = 0 while i < cvals.len: cvals.skipWhitespace(i) let length = ?cssLength(cvals[i], hasAuto = hasAuto) - let val = CSSComputedValue(v: cvtLength, length: length) + let val = CSSValue(v: cvtLength, length: length) lengths.add(val) inc i case lengths.len @@ -1364,9 +1364,9 @@ proc parseComputedValues*(res: var seq[CSSComputedEntry]; name: string; if tok == cttWhitespace: continue if (let r = cssImage(tok); r.isSome): - bgimageval = CSSComputedValue(v: cvtImage, image: r.get) + bgimageval = CSSValue(v: cvtImage, image: r.get) elif (let r = cssColor(tok); r.isSome): - bgcolorval = CSSComputedValue(v: cvtColor, color: r.get) + bgcolorval = CSSValue(v: cvtColor, color: r.get) else: #TODO when we implement the other shorthands too #valid = false @@ -1375,8 +1375,8 @@ proc parseComputedValues*(res: var seq[CSSComputedEntry]; name: string; res.add(makeEntry(cptBackgroundColor, bgcolorval, global)) res.add(makeEntry(cptBackgroundImage, bgimageval, global)) of cstListStyle: - var positionVal = CSSComputedValueBit() - var typeVal = CSSComputedValueBit() + var positionVal = CSSValueBit() + var typeVal = CSSValueBit() var valid = true if global == cgtNone: for tok in cvals: @@ -1401,7 +1401,7 @@ proc parseComputedValues*(res: var seq[CSSComputedEntry]; name: string; return err() if (let r = cssNumber(cvals[i], positive = true); r.isSome): # flex-grow - let val = CSSComputedValue(v: cvtNumber, number: r.get) + let val = CSSValue(v: cvtNumber, number: r.get) res.add(makeEntry(cptFlexGrow, val)) inc i cvals.skipWhitespace(i) @@ -1410,22 +1410,22 @@ proc parseComputedValues*(res: var seq[CSSComputedEntry]; name: string; return err() if (let r = cssNumber(cvals[i], positive = true); r.isSome): # flex-shrink - let val = CSSComputedValue(v: cvtNumber, number: r.get) + let val = CSSValue(v: cvtNumber, number: r.get) res.add(makeEntry(cptFlexShrink, val)) inc i cvals.skipWhitespace(i) if res.len < 1: # flex-grow omitted, default to 1 - let val = CSSComputedValue(v: cvtNumber, number: 1) + let val = CSSValue(v: cvtNumber, number: 1) res.add(makeEntry(cptFlexGrow, val)) if res.len < 2: # flex-shrink omitted, default to 1 - let val = CSSComputedValue(v: cvtNumber, number: 1) + let val = CSSValue(v: cvtNumber, number: 1) res.add(makeEntry(cptFlexShrink, val)) if i < cvals.len: # flex-basis - let val = CSSComputedValue(v: cvtLength, length: ?cssLength(cvals[i])) + let val = CSSValue(v: cvtLength, length: ?cssLength(cvals[i])) res.add(makeEntry(cptFlexBasis, val)) else: # omitted, default to 0px - let val = CSSComputedValue( + let val = CSSValue( v: cvtLength, length: CSSLength(u: cuPx, num: 0) ) @@ -1442,14 +1442,14 @@ proc parseComputedValues*(res: var seq[CSSComputedEntry]; name: string; return err() if (let dir = parseIdent[CSSFlexDirection](cvals[i]); dir.isSome): # flex-direction - var val = CSSComputedValueBit() + var val = CSSValueBit() val.flexDirection = dir.get res.add(makeEntry(cptFlexDirection, val)) inc i cvals.skipWhitespace(i) if i < cvals.len: let wrap = ?parseIdent[CSSFlexWrap](cvals[i]) - var val = CSSComputedValueBit() + var val = CSSValueBit() val.flexWrap = wrap res.add(makeEntry(cptFlexWrap, val)) else: @@ -1464,26 +1464,26 @@ proc parseComputedValues*(name: string; value: seq[CSSComponentValue]): return res return @[] -proc copyFrom(a, b: CSSComputedValues; t: CSSPropertyType) = +proc copyFrom(a, b: CSSValues; t: CSSPropertyType) = if t.isBit: a.bits[t] = b.bits[t] else: a.objs[t] = b.objs[t] -proc setInitial(a: CSSComputedValues; t: CSSPropertyType) = +proc setInitial(a: CSSValues; t: CSSPropertyType) = if t.isBit: a.bits[t].dummy = 0 else: a.objs[t] = getDefault(t) -proc initialOrInheritFrom*(a, b: CSSComputedValues; t: CSSPropertyType) = +proc initialOrInheritFrom*(a, b: CSSValues; t: CSSPropertyType) = if t.inherited and b != nil: a.copyFrom(b, t) else: a.setInitial(t) -proc applyValue*(vals: CSSComputedValues; entry: CSSComputedEntry; - parent, previousOrigin: CSSComputedValues; +proc applyValue*(vals: CSSValues; entry: CSSComputedEntry; + parent, previousOrigin: CSSValues; inited: array[CSSPropertyType, bool]) = case entry.global of cgtInherit: @@ -1506,7 +1506,7 @@ proc applyValue*(vals: CSSComputedValues; entry: CSSComputedEntry; else: vals.objs[entry.t] = entry.obj -func inheritProperties*(parent: CSSComputedValues): CSSComputedValues = +func inheritProperties*(parent: CSSValues): CSSValues = new(result) for t in CSSPropertyType: if t.inherited: @@ -1514,20 +1514,20 @@ func inheritProperties*(parent: CSSComputedValues): CSSComputedValues = else: result.setInitial(t) -func copyProperties*(props: CSSComputedValues): CSSComputedValues = +func copyProperties*(props: CSSValues): CSSValues = new(result) result[] = props[] -func rootProperties*(): CSSComputedValues = +func rootProperties*(): CSSValues = new(result) for t in CSSPropertyType: result.setInitial(t) -# Separate CSSComputedValues of a table into those of the wrapper and the actual +# Separate CSSValues of a table into those of the wrapper and the actual # table. -func splitTable*(computed: CSSComputedValues): - tuple[outerComputed, innnerComputed: CSSComputedValues] = - var outerComputed, innerComputed: CSSComputedValues +func splitTable*(computed: CSSValues): + tuple[outerComputed, innnerComputed: CSSValues] = + var outerComputed, innerComputed: CSSValues new(outerComputed) new(innerComputed) const props = { diff --git a/src/css/layout.nim b/src/css/layout.nim index 8be6dc9a..c92f7cbc 100644 --- a/src/css/layout.nim +++ b/src/css/layout.nim @@ -41,7 +41,7 @@ type attrsp: ptr WindowAttributes cellSize: Size # size(w = attrsp.ppc, h = attrsp.ppl) positioned: seq[PositionedItem] - myRootProperties: CSSComputedValues + myRootProperties: CSSValues # placeholder text data imgText: StyledNode audioText: StyledNode @@ -268,7 +268,7 @@ type InlineContext = object state: BoxLayoutState - computed: CSSComputedValues + computed: CSSValues bctx: ptr BlockContext bfcOffset: Offset lbstate: LineBoxState @@ -296,11 +296,11 @@ type firstrw: int # first rune width of the current word prevrw: int # last processed rune's width -func whitespacepre(computed: CSSComputedValues): bool = +func whitespacepre(computed: CSSValues): bool = computed{"white-space"} in {WhitespacePre, WhitespacePreLine, WhitespacePreWrap} -func nowrap(computed: CSSComputedValues): bool = +func nowrap(computed: CSSValues): bool = computed{"white-space"} in {WhitespaceNowrap, WhitespacePre} func cellWidth(lctx: LayoutContext): int = @@ -645,7 +645,7 @@ proc finishLine(ictx: var InlineContext; state: var InlineState; wrap: bool; ictx.initLine() func shouldWrap(ictx: InlineContext; w: LayoutUnit; - pcomputed: CSSComputedValues): bool = + pcomputed: CSSValues): bool = if pcomputed != nil and pcomputed.nowrap: return false if ictx.space.w.t == scMaxContent: @@ -832,7 +832,7 @@ proc processWhitespace(ictx: var InlineContext; state: var InlineState; state.lastrw = state.prevrw func initInlineContext(bctx: var BlockContext; space: AvailableSpace; - bfcOffset: Offset; padding: RelativeRect; computed: CSSComputedValues): + bfcOffset: Offset; padding: RelativeRect; computed: CSSValues): InlineContext = return InlineContext( bctx: addr bctx, @@ -900,14 +900,14 @@ proc layoutText(ictx: var InlineContext; state: var InlineState; s: string) = ictx.layoutTextLoop(state, s) func spx(l: CSSLength; lctx: LayoutContext; p: SizeConstraint; - computed: CSSComputedValues; padding: LayoutUnit): LayoutUnit = + computed: CSSValues; padding: LayoutUnit): LayoutUnit = let u = l.px(lctx, p) if computed{"box-sizing"} == BoxSizingBorderBox: return max(u - padding, 0) return max(u, 0) proc resolveContentWidth(sizes: var ResolvedSizes; widthpx: LayoutUnit; - parentWidth: SizeConstraint; computed: CSSComputedValues; + parentWidth: SizeConstraint; computed: CSSValues; isauto = false) = if not sizes.space.w.isDefinite() or not parentWidth.isDefinite(): # width is indefinite, so no conflicts can be resolved here. @@ -935,7 +935,7 @@ proc resolveContentWidth(sizes: var ResolvedSizes; widthpx: LayoutUnit; sizes.margin[dtHorizontal].send = underflow div 2 proc resolveMargins(lctx: LayoutContext; availableWidth: SizeConstraint; - computed: CSSComputedValues): RelativeRect = + computed: CSSValues): RelativeRect = # Note: we use availableWidth for percentage resolution intentionally. return [ dtHorizontal: Span( @@ -949,7 +949,7 @@ proc resolveMargins(lctx: LayoutContext; availableWidth: SizeConstraint; ] proc resolvePadding(lctx: LayoutContext; availableWidth: SizeConstraint; - computed: CSSComputedValues): RelativeRect = + computed: CSSValues): RelativeRect = # Note: we use availableWidth for percentage resolution intentionally. return [ dtHorizontal: Span( @@ -963,7 +963,7 @@ proc resolvePadding(lctx: LayoutContext; availableWidth: SizeConstraint; ] func resolvePositioned(lctx: LayoutContext; size: Size; - computed: CSSComputedValues): RelativeRect = + computed: CSSValues): RelativeRect = # As per standard, vertical percentages refer to the *height*, not the width # (unlike with margin/padding) return [ @@ -983,7 +983,7 @@ const DefaultBounds = Bounds( ) func resolveBounds(lctx: LayoutContext; space: AvailableSpace; padding: Size; - computed: CSSComputedValues): Bounds = + computed: CSSValues): Bounds = var res = DefaultBounds block: let sc = space.w @@ -1010,7 +1010,7 @@ func resolveBounds(lctx: LayoutContext; space: AvailableSpace; padding: Size; const CvalSizeMap = [dtHorizontal: cptWidth, dtVertical: cptHeight] proc resolveAbsoluteWidth(sizes: var ResolvedSizes; size: Size; - positioned: RelativeRect; computed: CSSComputedValues; + positioned: RelativeRect; computed: CSSValues; lctx: LayoutContext) = if computed{"width"}.u == cuAuto: let u = max(size.w - positioned[dtHorizontal].sum(), 0) @@ -1026,7 +1026,7 @@ proc resolveAbsoluteWidth(sizes: var ResolvedSizes; size: Size; sizes.space.w = stretch(sizepx) proc resolveAbsoluteHeight(sizes: var ResolvedSizes; size: Size; - positioned: RelativeRect; computed: CSSComputedValues; + positioned: RelativeRect; computed: CSSValues; lctx: LayoutContext) = if computed{"height"}.u == cuAuto: let u = max(size.w - positioned[dtVertical].sum(), 0) @@ -1045,7 +1045,7 @@ proc resolveAbsoluteHeight(sizes: var ResolvedSizes; size: Size; # Calculate and resolve available width & height for absolutely positioned # boxes. proc resolveAbsoluteSizes(lctx: LayoutContext; size: Size; - positioned: var RelativeRect; computed: CSSComputedValues): ResolvedSizes = + positioned: var RelativeRect; computed: CSSValues): ResolvedSizes = positioned = lctx.resolvePositioned(size, computed) var sizes = ResolvedSizes( margin: lctx.resolveMargins(stretch(size.w), computed), @@ -1058,7 +1058,7 @@ proc resolveAbsoluteSizes(lctx: LayoutContext; size: Size; # Calculate and resolve available width & height for floating boxes. proc resolveFloatSizes(lctx: LayoutContext; space: AvailableSpace; - computed: CSSComputedValues): ResolvedSizes = + computed: CSSValues): ResolvedSizes = let padding = lctx.resolvePadding(space.w, computed) let paddingSum = padding.sum() var sizes = ResolvedSizes( @@ -1079,7 +1079,7 @@ proc resolveFloatSizes(lctx: LayoutContext; space: AvailableSpace; return sizes proc resolveFlexItemSizes(lctx: LayoutContext; space: AvailableSpace; - dim: DimensionType; computed: CSSComputedValues): ResolvedSizes = + dim: DimensionType; computed: CSSValues): ResolvedSizes = let padding = lctx.resolvePadding(space.w, computed) let paddingSum = padding.sum() var sizes = ResolvedSizes( @@ -1123,7 +1123,7 @@ proc resolveFlexItemSizes(lctx: LayoutContext; space: AvailableSpace; return sizes proc resolveBlockWidth(sizes: var ResolvedSizes; parentWidth: SizeConstraint; - inlinePadding: LayoutUnit; computed: CSSComputedValues; + inlinePadding: LayoutUnit; computed: CSSValues; lctx: LayoutContext) = let width = computed{"width"} var widthpx: LayoutUnit = 0 @@ -1152,7 +1152,7 @@ proc resolveBlockWidth(sizes: var ResolvedSizes; parentWidth: SizeConstraint; sizes.resolveContentWidth(sizes.minWidth, parentWidth, computed) proc resolveBlockHeight(sizes: var ResolvedSizes; parentHeight: SizeConstraint; - blockPadding: LayoutUnit; computed: CSSComputedValues; + blockPadding: LayoutUnit; computed: CSSValues; lctx: LayoutContext) = let height = computed{"height"} if height.canpx(parentHeight): @@ -1172,7 +1172,7 @@ proc resolveBlockHeight(sizes: var ResolvedSizes; parentHeight: SizeConstraint; sizes.space.h = stretch(sizes.minHeight) proc resolveBlockSizes(lctx: LayoutContext; space: AvailableSpace; - computed: CSSComputedValues): ResolvedSizes = + computed: CSSValues): ResolvedSizes = let padding = lctx.resolvePadding(space.w, computed) let paddingSum = padding.sum() var sizes = ResolvedSizes( @@ -2082,7 +2082,7 @@ proc calcUnspecifiedColIndices(tctx: var TableContext; W: var LayoutUnit; W -= col.width return avail -func needsRedistribution(tctx: TableContext; computed: CSSComputedValues): +func needsRedistribution(tctx: TableContext; computed: CSSValues): bool = case tctx.space.w.t of scMinContent, scMaxContent: @@ -2596,7 +2596,7 @@ proc layoutBlockChildBFC(state: var BlockState; bctx: var BlockContext; # Note: this does not include display types that cannot appear as block # children. -func establishesBFC(computed: CSSComputedValues): bool = +func establishesBFC(computed: CSSValues): bool = return computed{"float"} != FloatNone or computed{"display"} in {DisplayFlowRoot, DisplayTable, DisplayTableWrapper, DisplayFlex} or @@ -2782,7 +2782,7 @@ proc layoutBlock(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) = # 1st pass: build tree -proc newMarkerBox(computed: CSSComputedValues; listItemCounter: int): +proc newMarkerBox(computed: CSSValues; listItemCounter: int): InlineFragment = let computed = computed.inheritProperties() computed{"display"} = DisplayInline @@ -2824,7 +2824,7 @@ proc flushInlineGroup(ctx: var InnerBlockContext) = ctx.inline = nil # Don't build empty anonymous inline blocks between block boxes -func canBuildAnonInline(ctx: InnerBlockContext; computed: CSSComputedValues; +func canBuildAnonInline(ctx: InnerBlockContext; computed: CSSValues; str: string): bool = return ctx.inline != nil and ctx.inline.children.len > 0 or computed.whitespacepre or not str.onlyWhitespace() @@ -2834,20 +2834,20 @@ proc buildBlock(ctx: var InnerBlockContext) proc buildTable(ctx: var InnerBlockContext) proc buildFlex(ctx: var InnerBlockContext) proc buildInlineBoxes(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) + computed: CSSValues) proc buildTableRowGroup(parent: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues): BlockBox + computed: CSSValues): BlockBox proc buildTableRow(parent: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues): BlockBox + computed: CSSValues): BlockBox proc buildTableCell(parent: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues): BlockBox + computed: CSSValues): BlockBox proc buildTableCaption(parent: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues): BlockBox + computed: CSSValues): BlockBox proc newInnerBlockContext(styledNode: StyledNode; box: BlockBox; lctx: LayoutContext; parent: ptr InnerBlockContext): InnerBlockContext proc pushInline(ctx: var InnerBlockContext; fragment: InlineFragment) proc pushInlineBlock(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) + computed: CSSValues) func toTableWrapper(display: CSSDisplay): CSSDisplay = if display == DisplayTable: @@ -2855,7 +2855,7 @@ func toTableWrapper(display: CSSDisplay): CSSDisplay = assert display == DisplayInlineTable return DisplayInlineTableWrapper -proc createAnonTable(ctx: var InnerBlockContext; computed: CSSComputedValues): +proc createAnonTable(ctx: var InnerBlockContext; computed: CSSValues): BlockBox = let inline = ctx.inlineStack.len > 0 if not inline and ctx.anonTableWrapper == nil or @@ -2974,7 +2974,7 @@ proc reconstructInlineParents(ctx: var InnerBlockContext) = parent = child proc buildSomeBlock(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues): BlockBox = + computed: CSSValues): BlockBox = let box = BlockBox(computed: computed, node: styledNode) var childCtx = newInnerBlockContext(styledNode, box, ctx.lctx, addr ctx) case computed{"display"} @@ -2986,7 +2986,7 @@ proc buildSomeBlock(ctx: var InnerBlockContext; styledNode: StyledNode; # Note: these also pop proc pushBlock(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) = + computed: CSSValues) = if (computed{"position"} == PositionAbsolute or computed{"float"} != FloatNone) and (ctx.inline != nil or ctx.inlineStack.len > 0): @@ -3004,7 +3004,7 @@ proc pushInline(ctx: var InnerBlockContext; fragment: InlineFragment) = ctx.reconstructInlineParents() ctx.inlineStackFragments[^1].children.add(fragment) -proc pushInlineText(ctx: var InnerBlockContext; computed: CSSComputedValues; +proc pushInlineText(ctx: var InnerBlockContext; computed: CSSValues; parent, node: StyledNode) = ctx.pushInline(InlineFragment( t: iftText, @@ -3014,7 +3014,7 @@ proc pushInlineText(ctx: var InnerBlockContext; computed: CSSComputedValues; )) proc pushInlineBlock(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) = + computed: CSSValues) = ctx.pushInline(InlineFragment( t: iftBox, computed: computed.inheritProperties(), @@ -3023,7 +3023,7 @@ proc pushInlineBlock(ctx: var InnerBlockContext; styledNode: StyledNode; )) proc pushListItem(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) = + computed: CSSValues) = ctx.iflush() ctx.flush() inc ctx.listItemCounter @@ -3050,7 +3050,7 @@ proc pushListItem(ctx: var InnerBlockContext; styledNode: StyledNode; ctx.outer.children.add(content) proc pushTableRow(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) = + computed: CSSValues) = let child = ctx.buildTableRow(styledNode, computed) if ctx.inlineStack.len == 0: ctx.iflush() @@ -3066,7 +3066,7 @@ proc pushTableRow(ctx: var InnerBlockContext; styledNode: StyledNode; anonTableWrapper.children[0].children.add(child) proc pushTableRowGroup(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) = + computed: CSSValues) = let child = ctx.buildTableRowGroup(styledNode, computed) if ctx.inlineStack.len == 0: ctx.iflush() @@ -3083,7 +3083,7 @@ proc pushTableRowGroup(ctx: var InnerBlockContext; styledNode: StyledNode; anonTableWrapper.children[0].children.add(child) proc pushTableCell(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) = + computed: CSSValues) = let child = ctx.buildTableCell(styledNode, computed) if ctx.inlineStack.len == 0 and ctx.outer.computed{"display"} == DisplayTableRow: @@ -3095,7 +3095,7 @@ proc pushTableCell(ctx: var InnerBlockContext; styledNode: StyledNode; anonRow.children.add(child) proc pushTableCaption(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) = + computed: CSSValues) = ctx.iflush() ctx.flushInlineGroup() ctx.flushTableRow() @@ -3109,7 +3109,7 @@ proc pushTableCaption(ctx: var InnerBlockContext; styledNode: StyledNode; anonTableWrapper.children.add(child) proc buildFromElem(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) = + computed: CSSValues) = case computed{"display"} of DisplayBlock, DisplayFlowRoot, DisplayFlex, DisplayTable: ctx.pushBlock(styledNode, computed) @@ -3133,7 +3133,7 @@ proc buildFromElem(ctx: var InnerBlockContext; styledNode: StyledNode; of DisplayTableWrapper, DisplayInlineTableWrapper: assert false proc buildReplacement(ctx: var InnerBlockContext; child, parent: StyledNode; - computed: CSSComputedValues) = + computed: CSSValues) = case child.content.t of ContentNone: assert false # unreachable for `content' of ContentOpenQuote: @@ -3187,7 +3187,7 @@ proc buildReplacement(ctx: var InnerBlockContext; child, parent: StyledNode; )) proc buildInlineBoxes(ctx: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues) = + computed: CSSValues) = let parent = InlineFragment( t: iftParent, computed: computed, @@ -3298,7 +3298,7 @@ proc buildFlex(ctx: var InnerBlockContext) = ctx.outer.children.reverse() proc buildTableCell(parent: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues): BlockBox = + computed: CSSValues): BlockBox = let box = BlockBox(node: styledNode, computed: computed) var ctx = newInnerBlockContext(styledNode, box, parent.lctx, addr parent) ctx.buildInnerBlock() @@ -3306,7 +3306,7 @@ proc buildTableCell(parent: var InnerBlockContext; styledNode: StyledNode; return box proc buildTableRowChildWrappers(box: BlockBox) = - var wrapperVals: CSSComputedValues = nil + var wrapperVals: CSSValues = nil for child in box.children: if child.computed{"display"} != DisplayTableCell: wrapperVals = box.computed.inheritProperties() @@ -3328,7 +3328,7 @@ proc buildTableRowChildWrappers(box: BlockBox) = box.children = children proc buildTableRow(parent: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues): BlockBox = + computed: CSSValues): BlockBox = let box = BlockBox(node: styledNode, computed: computed) var ctx = newInnerBlockContext(styledNode, box, parent.lctx, addr parent) ctx.buildInnerBlock() @@ -3337,7 +3337,7 @@ proc buildTableRow(parent: var InnerBlockContext; styledNode: StyledNode; return box proc buildTableRowGroupChildWrappers(box: BlockBox) = - var wrapperVals: CSSComputedValues = nil + var wrapperVals: CSSValues = nil for child in box.children: if child.computed{"display"} != DisplayTableRow: wrapperVals = box.computed.inheritProperties() @@ -3363,7 +3363,7 @@ proc buildTableRowGroupChildWrappers(box: BlockBox) = box.children = children proc buildTableRowGroup(parent: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues): BlockBox = + computed: CSSValues): BlockBox = let box = BlockBox(node: styledNode, computed: computed) var ctx = newInnerBlockContext(styledNode, box, parent.lctx, addr parent) ctx.buildInnerBlock() @@ -3372,14 +3372,14 @@ proc buildTableRowGroup(parent: var InnerBlockContext; styledNode: StyledNode; return box proc buildTableCaption(parent: var InnerBlockContext; styledNode: StyledNode; - computed: CSSComputedValues): BlockBox = + computed: CSSValues): BlockBox = let box = BlockBox(node: styledNode, computed: computed) var ctx = newInnerBlockContext(styledNode, box, parent.lctx, addr parent) ctx.buildInnerBlock() ctx.flush() return box -proc buildTableChildWrappers(box: BlockBox; computed: CSSComputedValues) = +proc buildTableChildWrappers(box: BlockBox; computed: CSSValues) = let innerTable = BlockBox(computed: computed, node: box.node) let wrapperVals = box.computed.inheritProperties() wrapperVals{"display"} = DisplayTableRow diff --git a/src/css/render.nim b/src/css/render.nim index fb96ceb6..10045683 100644 --- a/src/css/render.nim +++ b/src/css/render.nim @@ -51,7 +51,7 @@ proc addFormat(line: var FlexibleLine; pos: int; format: Format; node: StyledNode = nil) = line.formats.add(FormatCell(format: format, node: node, pos: pos)) -func toFormat(computed: CSSComputedValues): Format = +func toFormat(computed: CSSValues): Format = if computed == nil: return Format() var flags: set[FormatFlag] = {} diff --git a/src/css/stylednode.nim b/src/css/stylednode.nim index 0402826e..5e060142 100644 --- a/src/css/stylednode.nim +++ b/src/css/stylednode.nim @@ -52,7 +52,7 @@ type of stText: discard of stElement: - computed*: CSSComputedValues + computed*: CSSValues children*: seq[StyledNode] # All elements our style depends on, for each dependency type d. depends*: DependencyInfo @@ -106,7 +106,7 @@ func newStyledElement*(element: Element): StyledNode = return StyledNode(t: stElement, node: element) func newStyledElement*(parent: StyledNode; pseudo: PseudoElem; - computed: CSSComputedValues): StyledNode = + computed: CSSValues): StyledNode = return StyledNode( t: stElement, computed: computed, |