diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-11-09 16:33:14 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-11-09 16:34:34 +0100 |
| commit | 485a628f0c58f89c7260c710bf3accf5bc2e8fff (patch) | |
| tree | f127f78eb45a3353edf071e69157d22878d3f00e | |
| parent | 63abe1308be087f0658186a303fe9e6843d2166a (diff) | |
| download | chawan-485a628f0c58f89c7260c710bf3accf5bc2e8fff.tar.gz | |
layout: adjust fixed positioning
In CSS, `position: fixed' either a) moves the box on scroll (with
`@media screen'), or b) repeats the box on every page (with
`@media print').
a) would completely mess up our document model, and even if it didn't,
the renderer couldn't handle a redraw on every single scroll.
b) sounds better, but still doesn't work because it's incompatible with
`@media screen' semantics. e.g. in a) I can read text despite any banner
on the bottom of the screen, because the box moves when I scroll, but
in b), the same box will obscure some text on every single page.
So instead, make the `position: fixed' containing box
width: max(:root.width, 100vw); height: max(:root.height, 100vh)).
This is completely non-standard, but at least both TOC-like fixed boxes
*and* banners are placed somewhere that makes some sense.
| -rw-r--r-- | src/layout/engine.nim | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 0ad0812d..63d2f9ae 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -3383,7 +3383,7 @@ proc layout*(root: StyledNode; attrsp: ptr WindowAttributes): BlockBox = ) let lctx = LayoutContext( attrsp: attrsp, - positioned: @[PositionedItem()], + positioned: @[PositionedItem(), PositionedItem()], myRootProperties: rootProperties(), imgText: newStyledText("[img]"), videoText: newStyledText("[video]"), @@ -3395,6 +3395,16 @@ proc layout*(root: StyledNode; attrsp: ptr WindowAttributes): BlockBox = let sizes = lctx.resolveBlockSizes(space, box.computed) # the bottom margin is unused. discard lctx.layoutRootBlock(box, offset(x = 0, y = 0), sizes) - let size = size(w = attrsp[].widthPx, h = attrsp[].heightPx) + var size = size(w = attrsp[].widthPx, h = attrsp[].heightPx) + # Last absolute layer. + lctx.popPositioned(box.state.overflow, size) + # Fixed containing block. + # The idea is to move fixed boxes to the real edges of the page, + # so that they do not overlap with other boxes *and* we don't have + # to move them on scroll. It's still not compatible with what desktop + # browsers do, but the alternative would completely break search (and + # slow down the renderer to a crawl.) + size.w = max(size.w, box.state.size.w) + size.h = max(size.h, box.state.size.h) lctx.popPositioned(box.state.overflow, size) return box |