diff options
author | bptato <nincsnevem662@gmail.com> | 2024-04-27 17:17:48 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-04-27 17:17:48 +0200 |
commit | d8679af92bf88896a033238a1b0bea0648632b4c (patch) | |
tree | 90679172a6138b2081a9d6e6f62fe2d2670604fb | |
parent | dfc0b6c73f263876c10e56aee18e8ecabd1465c3 (diff) | |
download | chawan-d8679af92bf88896a033238a1b0bea0648632b4c.tar.gz |
layout: fix float size in table cells; remove redundant positioning
-rw-r--r-- | src/layout/engine.nim | 21 | ||||
-rwxr-xr-x | test/js/run_js_tests.sh | 2 | ||||
-rw-r--r-- | test/layout/float-height-in-table.expected | 3 | ||||
-rw-r--r-- | test/layout/float-height-in-table.html | 8 | ||||
-rwxr-xr-x | test/layout/run_layout_tests.sh | 2 |
5 files changed, 27 insertions, 9 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index e5093084..3c831afd 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -1427,7 +1427,7 @@ proc addInlineBlock(ictx: var InlineContext; state: var InlineState; bctx.layoutFlex(box, builder, sizes) else: assert false, $builder.computed{"display"} - bctx.positionFloats() + assert bctx.unpositionedFloats.len == 0 bctx.marginTodo.append(sizes.margin.bottom) let marginTop = box.offset.y let marginBottom = bctx.marginTodo.sum() @@ -1522,9 +1522,6 @@ proc layoutInline(ictx: var InlineContext; box: InlineBoxBuilder): ictx.currentLine.size.w += paddingRight let marginRight = box.computed{"margin-right"}.px(lctx, ictx.space.w) ictx.currentLine.size.w += marginRight - #TODO we verticalAlignLine here to know line height, but this is incredibly - # ugly. Maybe figure out some incremental line alignment scheme instead? - ictx.verticalAlignLine() if state.firstLine: fragment.startOffset = Offset( x: state.startOffsetTop.x, @@ -1665,10 +1662,14 @@ proc buildTableCell(lctx: LayoutState; builder: TableCellBoxBuilder; node: builder.node, margin: sizes.margin ) - var ctx = BlockContext(lctx: lctx) - ctx.layoutFlow(box, builder, sizes) + var bctx = BlockContext(lctx: lctx) + bctx.layoutFlow(box, builder, sizes) + assert bctx.unpositionedFloats.len == 0 # Table cells ignore margins. box.offset.y = 0 + # If the highest float edge is higher than the box itself, set that as + # the box height. + box.size.h = max(box.size.h, bctx.maxFloatHeight) return box # Sort growing cells, and filter out cells that have grown to their intended @@ -2035,6 +2036,7 @@ proc addTableCaption(ctx: TableContext; table: BlockBox) = ) var bctx = BlockContext(lctx: ctx.lctx) bctx.layoutFlow(box, builder, sizes) + assert bctx.unpositionedFloats.len == 0 let outerHeight = box.offset.y + box.size.h + bctx.marginTodo.sum() table.size.h += outerHeight table.size.w = max(table.size.w, box.size.w) @@ -2111,6 +2113,11 @@ proc layoutFlexChild(lctx: LayoutState; builder: BoxBuilder; margin: sizes.margin ) bctx.layout(box, builder, sizes) + assert bctx.unpositionedFloats.len == 0 + # If the highest float edge is higher than the box itself, set that as + # the box height. + if bctx.maxFloatHeight > box.offset.y + box.size.h: + box.size.h = bctx.maxFloatHeight - box.offset.y return box type @@ -2393,7 +2400,7 @@ proc layoutRootBlock(lctx: LayoutState; builder: BoxBuilder; BlockBox = var bctx = BlockContext(lctx: lctx) let box = bctx.layoutBlockChild(builder, space, offset, appendMargins = false) - bctx.positionFloats() + assert bctx.unpositionedFloats.len == 0 marginBottomOut = bctx.marginTodo.sum() # If the highest float edge is higher than the box itself, set that as # the box height. diff --git a/test/js/run_js_tests.sh b/test/js/run_js_tests.sh index a8cad435..8e1adeb3 100755 --- a/test/js/run_js_tests.sh +++ b/test/js/run_js_tests.sh @@ -1,6 +1,6 @@ #!/bin/sh if ! test "$CHA_TEST_BIN" -then test -f ../../../cha && CHA_TEST_BIN=../../../cha || CHA_TEST_BIN=cha +then test -f ../../cha && CHA_TEST_BIN=../../cha || CHA_TEST_BIN=cha fi failed=0 for h in *.html diff --git a/test/layout/float-height-in-table.expected b/test/layout/float-height-in-table.expected new file mode 100644 index 00000000..de4d7b4d --- /dev/null +++ b/test/layout/float-height-in-table.expected @@ -0,0 +1,3 @@ + first first first first first + second second second second second second second second second second second + second second second second second second second second second diff --git a/test/layout/float-height-in-table.html b/test/layout/float-height-in-table.html new file mode 100644 index 00000000..15d68abb --- /dev/null +++ b/test/layout/float-height-in-table.html @@ -0,0 +1,8 @@ +<!DOCTYPE html> +<table> +<tr> +<td><div style="float: right">first first first first first</div> +</td> +</tr> +<tr> +<td>second second second second second second second second second second second second second second second second second second second second diff --git a/test/layout/run_layout_tests.sh b/test/layout/run_layout_tests.sh index 03c9c818..6a6c7e4f 100755 --- a/test/layout/run_layout_tests.sh +++ b/test/layout/run_layout_tests.sh @@ -1,6 +1,6 @@ #!/bin/sh if test -z "$CHA_TEST_BIN" -then test -f ../../../cha && CHA_TEST_BIN=../../../cha || CHA_TEST_BIN=cha +then test -f ../../cha && CHA_TEST_BIN=../../cha || CHA_TEST_BIN=cha fi failed=0 for h in *.html |