aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-01-06 16:23:19 +0100
committerbptato <nincsnevem662@gmail.com>2025-01-06 16:23:19 +0100
commit9ae109b366c7a933965ff506a7ce275a7abe71ed (patch)
treec65be2b280066174fb8a106fbafe263f0c00d792
parent4ee4009cf6114db7c48972e7fb58a1397f024c09 (diff)
downloadchawan-9ae109b366c7a933965ff506a7ce275a7abe71ed.tar.gz
layout, render: establish absolute container with position: sticky
We do not support sticky scrolling, but this much should still work.
-rw-r--r--src/css/cssvalues.nim4
-rw-r--r--src/css/layout.nim18
-rw-r--r--src/css/render.nim10
-rw-r--r--test/layout/position-sticky-establishes-absolute-container.expected2
-rw-r--r--test/layout/position-sticky-establishes-absolute-container.html8
5 files changed, 23 insertions, 19 deletions
diff --git a/src/css/cssvalues.nim b/src/css/cssvalues.nim
index 350567ed..9126bafb 100644
--- a/src/css/cssvalues.nim
+++ b/src/css/cssvalues.nim
@@ -476,10 +476,6 @@ const InheritedProperties = {
cptVisibility, cptTextTransform
}
-const PositionStaticLike* = {
- PositionStatic, PositionSticky
-}
-
const OverflowScrollLike* = {OverflowScroll, OverflowAuto, OverflowOverlay}
const OverflowHiddenLike* = {OverflowHidden, OverflowClip}
diff --git a/src/css/layout.nim b/src/css/layout.nim
index fdf3a21a..2cbf5190 100644
--- a/src/css/layout.nim
+++ b/src/css/layout.nim
@@ -1385,7 +1385,7 @@ proc positionFloats(bctx: var BlockContext) =
bctx.unpositionedFloats.setLen(0)
proc layoutInline(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
- if box.computed{"position"} notin PositionStaticLike:
+ if box.computed{"position"} != PositionStatic:
bctx.lctx.pushPositioned()
let bfcOffset = if bctx.parentBps != nil:
bctx.parentBps.offset + box.state.offset
@@ -1440,7 +1440,7 @@ proc layoutInline(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
box.state.size += paddingSum
box.state.baseline = ictx.state.baseline
box.state.firstBaseline = ictx.state.firstBaseline
- if box.computed{"position"} notin PositionStaticLike:
+ if box.computed{"position"} != PositionStatic:
bctx.lctx.popPositioned(box.state.size)
# canClear signals if the box should clear in its inner (flow) layout.
@@ -1676,8 +1676,7 @@ proc layoutInline(ictx: var InlineContext; box: InlineBox) =
)
ictx.lbstate.size.w += padding.start
var state = InlineState(box: box)
- if stSplitStart in box.splitType and
- computed{"position"} notin PositionStaticLike:
+ if stSplitStart in box.splitType and computed{"position"} != PositionStatic:
lctx.pushPositioned()
case box.t
of ibtNewline:
@@ -1702,8 +1701,7 @@ proc layoutInline(ictx: var InlineContext; box: InlineBox) =
if not ictx.textFragmentSeen:
ictx.textFragmentSeen = true
ictx.lastTextFragment = box
- if stSplitEnd in box.splitType and
- computed{"position"} notin PositionStaticLike:
+ if stSplitEnd in box.splitType and computed{"position"} != PositionStatic:
# This is UB in CSS 2.1, I can't find a newer spec about it,
# and Gecko can't even layout it consistently (???)
#
@@ -2380,7 +2378,7 @@ proc flushMain(fctx: var FlexContext; mctx: var FlexMainContext;
proc layoutFlex(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
assert box.inline == nil
let lctx = bctx.lctx
- if box.computed{"position"} notin PositionStaticLike:
+ if box.computed{"position"} != PositionStatic:
lctx.pushPositioned()
let flexDir = box.computed{"flex-direction"}
let dim = if flexDir in FlexRow: dtHorizontal else: dtVertical
@@ -2445,7 +2443,7 @@ proc layoutFlex(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
box.applyIntr(sizes, fctx.intr)
for child in fctx.relativeChildren:
lctx.positionRelative(box, child)
- if box.computed{"position"} notin PositionStaticLike:
+ if box.computed{"position"} != PositionStatic:
lctx.popPositioned(box.state.size)
# Inner layout for boxes that establish a new block formatting context.
@@ -2741,7 +2739,7 @@ proc initReLayout(state: var BlockState; bctx: var BlockContext;
proc layoutBlock(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
let lctx = bctx.lctx
- if box.computed{"position"} notin PositionStaticLike:
+ if box.computed{"position"} != PositionStatic:
lctx.pushPositioned()
var state = BlockState(
offset: sizes.padding.topLeft,
@@ -2780,7 +2778,7 @@ proc layoutBlock(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
bctx.marginTarget = nil
# Reset parentBps to the previous node.
bctx.parentBps = state.prevParentBps
- if box.computed{"position"} notin PositionStaticLike:
+ if box.computed{"position"} != PositionStatic:
lctx.popPositioned(box.state.size)
# 1st pass: build tree
diff --git a/src/css/render.nim b/src/css/render.nim
index d0dabafa..6f3ac944 100644
--- a/src/css/render.nim
+++ b/src/css/render.nim
@@ -361,7 +361,7 @@ proc renderInlineBox(grid: var FlexibleGrid; state: var RenderState;
bgcolor0.rgb.cellColor())
let startOffset = offset + box.state.startOffset
box.render.offset = startOffset
- if position notin PositionStaticLike and stSplitStart in box.splitType:
+ if position != PositionStatic and stSplitStart in box.splitType:
state.absolutePos.add(startOffset)
if box.t == ibtParent:
for child in box.children:
@@ -404,7 +404,7 @@ proc renderInlineBox(grid: var FlexibleGrid; state: var RenderState;
height: atom.size.h.toInt,
bmp: atom.bmp
))
- if position notin PositionStaticLike and stSplitEnd in box.splitType:
+ if position != PositionStatic and stSplitEnd in box.splitType:
discard state.absolutePos.pop()
proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState;
@@ -412,7 +412,7 @@ proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState;
let position = box.computed{"position"}
#TODO handle negative z-index
let zindex = box.computed{"z-index"}
- if position notin PositionStaticLike and not pass2 and zindex >= 0:
+ if position != PositionStatic and not pass2 and zindex >= 0:
state.nstack.add(StackItem(
box: box,
offset: offset,
@@ -429,7 +429,7 @@ proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState;
offset.y = state.absolutePos[^1].y
offset += box.state.offset
box.render.offset = offset
- if position notin PositionStaticLike:
+ if position != PositionStatic:
state.absolutePos.add(offset)
let overflowX = box.computed{"overflow-x"}
let overflowY = box.computed{"overflow-y"}
@@ -482,7 +482,7 @@ proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState;
grid.renderBlockBox(state, child, offset)
if hasClipBox:
discard state.clipBoxes.pop()
- if position notin PositionStaticLike:
+ if position != PositionStatic:
discard state.absolutePos.pop()
proc renderDocument*(grid: var FlexibleGrid; bgcolor: var CellColor;
diff --git a/test/layout/position-sticky-establishes-absolute-container.expected b/test/layout/position-sticky-establishes-absolute-container.expected
new file mode 100644
index 00000000..33c1f19e
--- /dev/null
+++ b/test/layout/position-sticky-establishes-absolute-container.expected
@@ -0,0 +1,2 @@
+test
+absolute
diff --git a/test/layout/position-sticky-establishes-absolute-container.html b/test/layout/position-sticky-establishes-absolute-container.html
new file mode 100644
index 00000000..4725a883
--- /dev/null
+++ b/test/layout/position-sticky-establishes-absolute-container.html
@@ -0,0 +1,8 @@
+<div>
+test
+</div>
+<div style="position: sticky">
+<div style="position: absolute; top: 0">
+absolute
+</div>
+</div>