diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-02-17 00:54:02 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-02-17 01:12:08 +0100 |
| commit | 6ec8abb19214835348bb96575455b0a65079741e (patch) | |
| tree | db7025ce171d1114d591aca12abb3d03c8d5d42a /src/render | |
| parent | 6604bd6dc1fd9ad110fc5ff1f01f3b8b4c787ed8 (diff) | |
| download | chawan-6ec8abb19214835348bb96575455b0a65079741e.tar.gz | |
layout: use html/body bgcolor as canvas bgcolor
This is required by the standard. (Without this, lots of websites have
incorrect background colors, because they set the body height to 100%
of the viewport.)
Diffstat (limited to 'src/render')
| -rw-r--r-- | src/render/renderdocument.nim | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim index 2a5ddccd..625984df 100644 --- a/src/render/renderdocument.nim +++ b/src/render/renderdocument.nim @@ -283,6 +283,8 @@ type RenderState = object # Position of the absolute positioning containing block: # https://drafts.csswg.org/css-position/#absolute-positioning-containing-block absolutePos: seq[Offset] + bgcolor: CellColor + root: bool proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState; box: BlockBox; offset: Offset; attrs: WindowAttributes) @@ -378,14 +380,19 @@ proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState; state.absolutePos.add(offset) stack.add((nil, Offset(x: -1, y: -1))) - if box.computed{"visibility"} == VISIBILITY_VISIBLE: + if box.computed{"-cha-bgcolor-is-canvas"} and + state.bgcolor == defaultColor: + #TODO bgimage if box.computed{"background-color"}.a != 0: #TODO color blending - let ix = toInt(offset.x) - let iy = toInt(offset.y) - let iex = toInt(offset.x + box.size.w) - let iey = toInt(offset.y + box.size.h) - let color = box.computed{"background-color"}.cellColor() - grid.paintBackground(color, ix, iy, iex, iey, box.node, attrs) + state.bgcolor = box.computed{"background-color"}.cellColor() + elif box.computed{"visibility"} == VISIBILITY_VISIBLE: + if box.computed{"background-color"}.a != 0: #TODO color blending + let ix = toInt(offset.x) + let iy = toInt(offset.y) + let iex = toInt(offset.x + box.size.w) + let iey = toInt(offset.y + box.size.h) + let color = box.computed{"background-color"}.cellColor() + grid.paintBackground(color, ix, iy, iex, iey, box.node, attrs) if box.computed{"background-image"}.t == CONTENT_IMAGE and box.computed{"background-image"}.s != "": # ugly hack for background-image display... TODO actually display images @@ -418,14 +425,16 @@ proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState; for i in countdown(box.nested.high, 0): stack.add((box.nested[i], offset)) -proc renderDocument*(styledRoot: StyledNode; attrs: WindowAttributes): - FlexibleGrid = - var grid: FlexibleGrid +proc renderDocument*(grid: var FlexibleGrid; bgcolor: var CellColor; + styledRoot: StyledNode; attrs: WindowAttributes) = + grid.setLen(0) var state = RenderState( - absolutePos: @[Offset(x: 0, y: 0)] + absolutePos: @[Offset(x: 0, y: 0)], + root: true, + bgcolor: bgcolor ) let rootBox = renderLayout(styledRoot, attrs) grid.renderBlockBox(state, rootBox, Offset(x: 0, y: 0), attrs) if grid.len == 0: grid.addLine() - return grid + bgcolor = state.bgcolor |