aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-01-06 16:31:10 +0100
committerbptato <nincsnevem662@gmail.com>2025-01-06 16:31:10 +0100
commite066acad98c510cfd9bd2593affcbb9673c93dca (patch)
treeb2c3da955eb887ca8fc1ad880968650e18f4e7c7
parent9ae109b366c7a933965ff506a7ce275a7abe71ed (diff)
downloadchawan-e066acad98c510cfd9bd2593affcbb9673c93dca.tar.gz
layout: wrap on inline floats that exceed the line's length
In this case, it seems we have to wrap. (It's still not quite there; replace flow-root with inline-box to see another interesting bug...)
-rw-r--r--src/css/layout.nim8
-rw-r--r--test/layout/inline-float-breaks-line.expected4
-rw-r--r--test/layout/inline-float-breaks-line.html21
3 files changed, 29 insertions, 4 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim
index 2cbf5190..6fea80e3 100644
--- a/src/css/layout.nim
+++ b/src/css/layout.nim
@@ -1414,9 +1414,6 @@ proc layoutInline(bctx: var BlockContext; box: BlockBox; sizes: ResolvedSizes) =
# rarely enough.
let floats = move(ictx.unpositionedFloats)
var space = sizes.space
- #TODO there is still a bug here: if the parent's size is
- # fit-content, then floats should trigger a re-layout in the
- # *parent*.
if space.w.t != scStretch:
space.w = stretch(ictx.state.size.w)
ictx = bctx.initInlineContext(space, bfcOffset, sizes.padding, box.computed)
@@ -1493,12 +1490,15 @@ proc addInlineFloat(ictx: var InlineContext; state: var InlineState;
box: BlockBox) =
let lctx = ictx.lctx
let sizes = lctx.resolveFloatSizes(ictx.space, box.computed)
- box.state = BoxLayoutState()
let offset = offset(
x = sizes.margin.left,
y = ictx.lbstate.offsety + sizes.margin.top
)
lctx.layoutRootBlock(box, offset, sizes)
+ if ictx.space.w.t == scStretch and
+ ictx.lbstate.size.w + box.state.size.w > ictx.space.w.u:
+ ictx.finishLine(state, wrap = true)
+ box.state.offset.y = ictx.lbstate.offsety + sizes.margin.top
ictx.lbstate.size.w += box.state.size.w
# Note that by now, the top y offset is always resolved.
ictx.unpositionedFloats.add(InlineUnpositionedFloat(
diff --git a/test/layout/inline-float-breaks-line.expected b/test/layout/inline-float-breaks-line.expected
new file mode 100644
index 00000000..c69cc18a
--- /dev/null
+++ b/test/layout/inline-float-breaks-line.expected
@@ -0,0 +1,4 @@
+test1 test4
+test2
+test3
+test2 test3test1 test4
diff --git a/test/layout/inline-float-breaks-line.html b/test/layout/inline-float-breaks-line.html
new file mode 100644
index 00000000..2bd74860
--- /dev/null
+++ b/test/layout/inline-float-breaks-line.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<div style="display: flow-root">
+test1
+<div style="float: left; width: 100%">
+test2
+</div>
+<div style="float: left">
+test3
+</div>
+test4
+</div>
+<div style="display: flow-root">
+test1
+<div style="float: left; width: 50%">
+test2
+</div>
+<div style="float: left">
+test3
+</div>
+test4
+</div>