Skip to content

Truly independent web browser

LibWeb: Measure table wrappers and aspect-ratio minimums normally

Aliaksandr Kalenikb5fd945b74d1
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 48e818f0231..809c4ea0b2c 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -1765,15 +1765,14 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
IntrinsicSizeCacheKind::MaxContentBlock,
);
}
- let measurement = formatting_context::MeasurementState::create(self.callbacks);
- let root = measurement.create_used_values(node, constraints);
+ let root = used_values::create_used_values(&self.callbacks, node, constraints);
root.set_content_inline_size(other_axis_size);
root.set_content_block_size(transferred_size);
root.has_definite_block_size.set(true);
- let result = measurement.run_with_layout_mode(
+ let result = formatting_context::lay_out_measurement_root_for_its_result(
+ self.callbacks,
node,
- &root,
- LayoutMode::Normal,
+ used_values::RootInputCells::capture(&root),
LayoutInput::new(
AvailableSpace {
inline_size: AvailableSize::definite(other_axis_size),
@@ -3171,15 +3170,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
}
fn block_size_is_measured_with_normal_layout(&self, node: Node) -> bool {
- let facts = self.facts(node);
- !facts.document_in_quirks_mode()
- && !facts.is_table_wrapper()
- && matches!(
- formatting_context::independent_formatting_context_type(node, &self.callbacks),
- formatting_context::FormattingContextType::Block
- | formatting_context::FormattingContextType::Flex
- | formatting_context::FormattingContextType::Grid
- )
+ !self.facts(node).document_in_quirks_mode()
}
fn measure_block_size_with_normal_layout(
@@ -3641,21 +3632,27 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
// table-wrapper can't have borders or paddings but it might have margin taken from table-root.
let available_block_size = containing_block_block_size - margin_top - margin_bottom;
- let measurement = formatting_context::MeasurementState::create(self.callbacks);
- let wrapper_used = measurement.create_used_values(wrapper, table_wrapper_constraints);
- let wrapper_outputs = measurement.run_with_layout_mode(
+ let wrapper_inner_space = self
+ .used(wrapper)
+ .available_inner_space_or_constraints_from(available_space);
+ let wrapper_used = used_values::create_used_values(&self.callbacks, wrapper, table_wrapper_constraints);
+ if let AvailableSize::Definite(inline_size) = wrapper_inner_space.inline_size {
+ wrapper_used.set_content_inline_size(inline_size);
+ }
+ if let AvailableSize::Definite(block_size) = wrapper_inner_space.block_size {
+ wrapper_used.set_content_block_size(block_size);
+ } else {
+ wrapper_used.has_definite_block_size.set(false);
+ }
+ let wrapper_outputs = formatting_context::lay_out_measurement_root_for_its_result(
+ self.callbacks,
wrapper,
- &wrapper_used,
- LayoutMode::IntrinsicSizing,
- LayoutInput {
- available_space: self
- .used(wrapper)
- .available_inner_space_or_constraints_from(available_space),
- containing_block_constraints: table_wrapper_constraints,
- content_box_position_in_bfc_root: None,
- sizing: RootSizingDirectives::default(),
- participation: ParticipationInParentFormattingContext::Root,
- },
+ used_values::RootInputCells::capture(&wrapper_used),
+ LayoutInput::new(
+ wrapper_inner_space,
+ table_wrapper_constraints,
+ ParticipationInParentFormattingContext::Root,
+ ),
);
let table_used_block_size = wrapper_outputs
diff --git a/Tests/LibWeb/Text/expected/auto-width-tables-measured-as-grid-and-column-flex-items.txt b/Tests/LibWeb/Text/expected/auto-width-tables-measured-as-grid-and-column-flex-items.txt
new file mode 100644
index 00000000000..9542f829f46
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/auto-width-tables-measured-as-grid-and-column-flex-items.txt
@@ -0,0 +1,3 @@
+column-flex: container height 160, table 300x150, next sibling at 150
+grid: container height 160, table 300x150, next sibling at 150
+grid-with-max-width-table: container height 110, table 200x100, next sibling at 100
diff --git a/Tests/LibWeb/Text/expected/layout-run-cache-aspect-ratio-minimum-reads-cached-result.txt b/Tests/LibWeb/Text/expected/layout-run-cache-aspect-ratio-minimum-reads-cached-result.txt
new file mode 100644
index 00000000000..2e4a500e2f4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/layout-run-cache-aspect-ratio-minimum-reads-cached-result.txt
@@ -0,0 +1 @@
+PASS: laying out the row again reads the aspect-ratio minimum of its item from the cache (work + checks)
diff --git a/Tests/LibWeb/Text/expected/table-with-caption-measured-as-grid-and-flex-item.txt b/Tests/LibWeb/Text/expected/table-with-caption-measured-as-grid-and-flex-item.txt
new file mode 100644
index 00000000000..8b61bd36d6a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/table-with-caption-measured-as-grid-and-flex-item.txt
@@ -0,0 +1,3 @@
+gridItem: caption 300x20, cell 300x180
+columnItem: caption 300x20, cell 300x20
+rowItem: caption 60x60, cell 60x140
diff --git a/Tests/LibWeb/Text/input/auto-width-tables-measured-as-grid-and-column-flex-items.html b/Tests/LibWeb/Text/input/auto-width-tables-measured-as-grid-and-column-flex-items.html
new file mode 100644
index 00000000000..ee574660dd1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/auto-width-tables-measured-as-grid-and-column-flex-items.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body { margin: 0; }
+ table { border-spacing: 0; }
+ td { padding: 0; }
+ img { width: 100%; display: block; }
+ .after { height: 10px; }
+</style>
+<div id="column-flex" style="display: flex; flex-direction: column; width: 300px"><table><tr><td><img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='50'/%3E"></td></tr></table><div class="after"></div></div>
+<div id="grid" style="display: grid; width: 300px"><table><tr><td><img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='50'/%3E"></td></tr></table><div class="after"></div></div>
+<div id="grid-with-max-width-table" style="display: grid; grid-template-columns: 300px"><table style="max-width: 200px"><tr><td><img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='50'/%3E"></td></tr></table><div class="after"></div></div>
+<script>
+ asyncTest(async done => {
+ await Promise.all([...document.images].map(image => image.decode()));
+ for (const id of ["column-flex", "grid", "grid-with-max-width-table"]) {
+ const container = document.getElementById(id);
+ const containerRect = container.getBoundingClientRect();
+ const table = container.querySelector("table").getBoundingClientRect();
+ const after = container.querySelector(".after").getBoundingClientRect();
+ println(`${id}: container height ${containerRect.height}, table ${table.width}x${table.height}, next sibling at ${after.top - containerRect.top}`);
+ }
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/layout-run-cache-aspect-ratio-minimum-reads-cached-result.html b/Tests/LibWeb/Text/input/layout-run-cache-aspect-ratio-minimum-reads-cached-result.html
new file mode 100644
index 00000000000..eaa7ebefbcc
--- /dev/null
+++ b/Tests/LibWeb/Text/input/layout-run-cache-aspect-ratio-minimum-reads-cached-result.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<script src="layout-test.js"></script>
+<style>
+ body { margin: 0; font: 20px/20px SerenitySans; }
+ #row { display: flex; width: 300px; }
+ #ratio { width: 100px; aspect-ratio: 1; }
+ #tall { height: 150px; }
+</style>
+<div id="row"><div id="ratio"><div id="tall"></div></div><span id="sibling">text</span></div>
+<script>
+ layoutTest({
+ steps: [
+ {
+ name: "laying out the row again reads the aspect-ratio minimum of its item from the cache",
+ mutate: () => {
+ sibling.firstChild.data = "other text";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ Box<DIV>#row/flex RUN (cache=miss)
+ BlockContainer<SPAN>#sibling MEASURE max-content inline (cache=miss) FROM ITEMS
+ BlockContainer<SPAN>#sibling MEASURE min-content inline (cache=hit)
+ BlockContainer<DIV>#ratio/block READ RESULT
+ BlockContainer<SPAN>#sibling/block RUN (cache=miss)
+ BlockContainer<DIV>#ratio/block REUSE SUBTREE
+ BlockContainer<SPAN>#sibling/block REPLAY FRAGMENTS
+ `,
+ check: equal => {
+ equal(ratio.getBoundingClientRect().height, 150, "aspect-ratio item height");
+ },
+ },
+ ],
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/table-measurement-reuse-work.html b/Tests/LibWeb/Text/input/table-measurement-reuse-work.html
index e03438a7a4a..1946890a8e5 100644
--- a/Tests/LibWeb/Text/input/table-measurement-reuse-work.html
+++ b/Tests/LibWeb/Text/input/table-measurement-reuse-work.html
@@ -35,22 +35,20 @@
Box<DIV>#item MEASURE max-content block (cache=miss)
Box<DIV>#item/flex RUN (cache=miss)
TableWrapper(anonymous) MEASURE max-content block (cache=miss)
- TableWrapper(anonymous)/block (intrinsic) RUN (cache=bypass)
- Box<TABLE>#table/table (intrinsic) RUN (cache=miss)
- BlockContainer<TD>#cell/block (intrinsic) RUN (cache=miss)
- BlockContainer<TD>/block (intrinsic) READ RESULT
+ TableWrapper(anonymous)/block RUN (cache=miss)
+ Box<TABLE>#table/table RUN (cache=miss)
+ BlockContainer<TD>#cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
+ BlockContainer<DIV> REUSE IN-FLOW SUBTREE
+ BlockContainer<TD>/block READ RESULT AHEAD OF INTRINSIC BLOCK PADDING
+ BlockContainer<TD>#cell/block RUN (cache=miss)
+ BlockContainer<DIV> REUSE IN-FLOW SUBTREE
+ BlockContainer<TD>/block REUSE SUBTREE
+ BlockContainer<SPAN>.control/block RUN (cache=miss)
TableWrapper(anonymous) MEASURE max-content block (cache=hit)
TableWrapper(anonymous) MEASURE max-content block (cache=hit)
TableWrapper(anonymous) MEASURE max-content block (cache=hit)
TableWrapper(anonymous)/block RUN (cache=miss)
- Box<TABLE>#table/table RUN (cache=miss)
- BlockContainer<TD>#cell/block RUN AHEAD OF INTRINSIC BLOCK PADDING
- BlockContainer<DIV> REUSE IN-FLOW SUBTREE
- BlockContainer<TD>/block READ RESULT AHEAD OF INTRINSIC BLOCK PADDING
- BlockContainer<TD>#cell/block RUN (cache=miss)
- BlockContainer<DIV> REUSE IN-FLOW SUBTREE
- BlockContainer<TD>/block REUSE SUBTREE
- BlockContainer<SPAN>.control/block RUN (cache=miss)
+ Box<TABLE>#table/table REPLAY FRAGMENTS
Box<DIV>#item/flex RUN (cache=miss)
TableWrapper(anonymous) MEASURE max-content block (cache=hit)
TableWrapper(anonymous) MEASURE max-content block (cache=hit)
diff --git a/Tests/LibWeb/Text/input/table-with-caption-measured-as-grid-and-flex-item.html b/Tests/LibWeb/Text/input/table-with-caption-measured-as-grid-and-flex-item.html
new file mode 100644
index 00000000000..0402f4844d6
--- /dev/null
+++ b/Tests/LibWeb/Text/input/table-with-caption-measured-as-grid-and-flex-item.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ @font-face {
+ font-family: Ahem;
+ src: url("../../Ref/data/fonts/Ahem.ttf");
+ }
+ body { margin: 0; font: 20px/20px Ahem; }
+ .grid { display: grid; width: 300px; height: 200px; }
+ .column { display: flex; flex-direction: column; width: 300px; height: 200px; }
+ .row { display: flex; width: 300px; height: 200px; }
+ table { border-spacing: 0; }
+ td { padding: 0; }
+</style>
+<div class="grid"><table id="gridItem"><caption>aaa bbb ccc</caption><tr><td>x</td></tr></table></div>
+<div class="column"><table id="columnItem"><caption>aaa bbb ccc</caption><tr><td>x</td></tr></table></div>
+<div class="row"><table id="rowItem"><caption>aaa bbb ccc</caption><tr><td>x</td></tr></table></div>
+<script>
+ asyncTest(async done => {
+ await document.fonts.load("20px Ahem");
+ for (const id of ["gridItem", "columnItem", "rowItem"]) {
+ const table = document.getElementById(id);
+ const caption = table.querySelector("caption").getBoundingClientRect();
+ const cell = table.querySelector("td").getBoundingClientRect();
+ println(`${id}: caption ${caption.width}x${caption.height}, cell ${cell.width}x${cell.height}`);
+ }
+ done();
+ });
+</script>