Skip to content

Truly independent web browser

LibWeb: Let list marker runs ignore their list item's width

Aliaksandr Kalenik8999b156bcc7
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index d88c8c30991..73ce4b18c64 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -1264,16 +1264,35 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
// can reach its containing block's inline basis.
pub(crate) fn measurement_root_observes_percentage_inline_basis(&self, node: Node) -> bool {
let facts = self.facts(node);
+ if facts.is_list_item_marker_box() {
+ return self.list_item_marker_observes_percentage_inline_basis(node);
+ }
if facts.is_anonymous() || facts.is_replaced_box() || facts.has_auto_content_box_size() {
return true;
}
- let style = self.style(node);
+ Self::own_box_resolves_percentage_against_inline_basis(self.style(node))
+ }
+
+ fn own_box_resolves_percentage_against_inline_basis(style: StyleValues<'_>) -> bool {
style.width().contains_percentage()
|| style.min_width().contains_percentage()
|| style.max_width().contains_percentage()
|| Self::box_edges_contain_percentage(style)
}
+ fn list_item_marker_observes_percentage_inline_basis(&self, marker: Node) -> bool {
+ let style = self.style(marker);
+ if Self::own_box_resolves_percentage_against_inline_basis(style) {
+ return true;
+ }
+ let marker_content_may_read_its_containing_block_inline_size = style.text_indent().contains_percentage()
+ || self
+ .callbacks
+ .children(marker)
+ .any(|content| self.facts(content).is_replaced_box());
+ marker_content_may_read_its_containing_block_inline_size && self.is_anonymous_block_box_in_block_flow(marker)
+ }
+
fn box_edges_contain_percentage(style: StyleValues<'_>) -> bool {
style.padding_left().contains_percentage()
|| style.padding_right().contains_percentage()
diff --git a/Tests/LibWeb/Text/expected/layout-run-cache-list-marker-width-change.txt b/Tests/LibWeb/Text/expected/layout-run-cache-list-marker-width-change.txt
new file mode 100644
index 00000000000..218cb44a081
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/layout-run-cache-list-marker-width-change.txt
@@ -0,0 +1,10 @@
+PASS: decimal markers reuse their runs after a list width change (work)
+PASS: disc markers reuse their runs after a list width change (work)
+PASS: image markers reuse their runs after a list width change (work)
+PASS: RTL markers reuse their runs and move with the list's inline start (work + checks)
+PASS: inside markers reuse their runs after a list width change (work)
+PASS: markers of list items with block children reuse their runs after a list width change (work)
+PASS: markers of list items with a percentage text-indent and inline content reuse their runs after a list width change (work)
+PASS: markers whose percentage text-indent resolves against the list item re-run after a list width change (work + checks)
+PASS: a counter change re-runs the markers (work + checks)
+PASS: a list-style-type change re-runs the marker (work)
diff --git a/Tests/LibWeb/Text/input/layout-run-cache-list-marker-width-change.html b/Tests/LibWeb/Text/input/layout-run-cache-list-marker-width-change.html
new file mode 100644
index 00000000000..0b852fcd89b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/layout-run-cache-list-marker-width-change.html
@@ -0,0 +1,261 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<script src="layout-test.js"></script>
+<style>
+ body { margin: 0; font: 16px/20px serif; }
+ ol, ul { margin: 0; width: 400px; }
+ #image { list-style-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Crect width='12' height='8' fill='green'/%3E%3C/svg%3E"); }
+ #inside { list-style-position: inside; }
+ #indentedInline li, #indentedBlocks li { text-indent: 10%; }
+</style>
+<ol id="decimal"><li>one</li><li id="second">two</li></ol>
+<ul id="disc"><li>one</li></ul>
+<ul id="image"><li>one</li></ul>
+<ol id="rtl" dir="rtl"><li>one</li></ol>
+<ol id="inside"><li>one</li></ol>
+<ol id="blocks"><li><p>one</p></li></ol>
+<ol id="indentedInline"><li>one</li></ol>
+<ol id="indentedBlocks"><li><p>one</p></li></ol>
+<script>
+ function markerInlineOffsets(list) {
+ const markers = internals.dumpLayoutTree(list).matchAll(/ListItemMarkerBox <\(anonymous\)> at \[([\d.]+),/g);
+ return JSON.stringify([...markers].map(match => Number(match[1])));
+ }
+
+ function markerInlineSizes(list) {
+ const markers = internals.dumpLayoutTree(list).matchAll(/ListItemMarkerBox <\(anonymous\)> at \S+ \[\S+ ([\d.]+) /g);
+ return JSON.stringify([...markers].map(match => Number(match[1])));
+ }
+
+ function markerTexts(list) {
+ const texts = internals.dumpLayoutTree(list).matchAll(/from GeneratedTextNode .*\n\s+"(.*)"/g);
+ return JSON.stringify([...texts].map(match => match[1]));
+ }
+
+ layoutTest({
+ setup: async () => {
+ for (let frame = 0; frame < 100 && !/ImageBox <\(anonymous\)> at \S+ \[0\+0\+0 12 /.test(internals.dumpLayoutTree(image)); ++frame)
+ await new Promise(resolve => requestAnimationFrame(resolve));
+ },
+ steps: [
+ {
+ name: "decimal markers reuse their runs after a list width change",
+ mutate: () => {
+ decimal.style.width = "300px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=hit)
+ ListItemMarkerBox(anonymous)/block REUSE SUBTREE
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=hit)
+ ListItemMarkerBox(anonymous)/block REUSE SUBTREE
+ BlockContainer<UL>#disc REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#image REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#rtl REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#inside REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#blocks REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedInline REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedBlocks REUSE IN-FLOW SUBTREE
+ `,
+ },
+ {
+ name: "disc markers reuse their runs after a list width change",
+ mutate: () => {
+ disc.style.width = "300px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ BlockContainer<OL>#decimal REUSE IN-FLOW SUBTREE
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=hit)
+ ListItemMarkerBox(anonymous)/block REUSE SUBTREE
+ BlockContainer<UL>#image REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#rtl REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#inside REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#blocks REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedInline REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedBlocks REUSE IN-FLOW SUBTREE
+ `,
+ },
+ {
+ name: "image markers reuse their runs after a list width change",
+ mutate: () => {
+ image.style.width = "300px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ BlockContainer<OL>#decimal REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#disc REUSE IN-FLOW SUBTREE
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=hit)
+ ListItemMarkerBox(anonymous)/block REUSE SUBTREE
+ BlockContainer<OL>#rtl REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#inside REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#blocks REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedInline REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedBlocks REUSE IN-FLOW SUBTREE
+ `,
+ },
+ {
+ name: "RTL markers reuse their runs and move with the list's inline start",
+ mutate: () => {
+ rtl.style.width = "300px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ BlockContainer<OL>#decimal REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#disc REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#image REUSE IN-FLOW SUBTREE
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=hit)
+ ListItemMarkerBox(anonymous)/block REUSE SUBTREE
+ BlockContainer<OL>#inside REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#blocks REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedInline REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedBlocks REUSE IN-FLOW SUBTREE
+ `,
+ check: equal => {
+ equal(markerInlineOffsets(rtl), "[300]", "RTL marker inline offset");
+ },
+ },
+ {
+ name: "inside markers reuse their runs after a list width change",
+ mutate: () => {
+ inside.style.width = "300px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ BlockContainer<OL>#decimal REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#disc REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#image REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#rtl REUSE IN-FLOW SUBTREE
+ ListItemMarkerBox(anonymous)/block REUSE SUBTREE
+ BlockContainer<OL>#blocks REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedInline REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedBlocks REUSE IN-FLOW SUBTREE
+ `,
+ },
+ {
+ name: "markers of list items with block children reuse their runs after a list width change",
+ mutate: () => {
+ blocks.style.width = "300px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ BlockContainer<OL>#decimal REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#disc REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#image REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#rtl REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#inside REUSE IN-FLOW SUBTREE
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=hit)
+ ListItemMarkerBox(anonymous)/block REUSE SUBTREE
+ BlockContainer<OL>#indentedInline REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedBlocks REUSE IN-FLOW SUBTREE
+ `,
+ },
+ {
+ name: "markers of list items with a percentage text-indent and inline content reuse their runs after a list width change",
+ mutate: () => {
+ indentedInline.style.width = "300px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ BlockContainer<OL>#decimal REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#disc REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#image REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#rtl REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#inside REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#blocks REUSE IN-FLOW SUBTREE
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=hit)
+ ListItemMarkerBox(anonymous)/block REUSE SUBTREE
+ BlockContainer<OL>#indentedBlocks REUSE IN-FLOW SUBTREE
+ `,
+ },
+ {
+ name: "markers whose percentage text-indent resolves against the list item re-run after a list width change",
+ mutate: () => {
+ indentedBlocks.style.width = "300px";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ BlockContainer<OL>#decimal REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#disc REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#image REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#rtl REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#inside REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#blocks REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedInline REUSE IN-FLOW SUBTREE
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=miss) FROM ITEMS
+ ListItemMarkerBox(anonymous)/block RUN (cache=miss)
+ `,
+ check: equal => {
+ const [unindentedMarkerInlineSize] = JSON.parse(markerInlineSizes(blocks));
+ const textIndentOfThe300pxListItem = 30;
+ equal(
+ markerInlineSizes(indentedBlocks),
+ JSON.stringify([unindentedMarkerInlineSize + textIndentOfThe300pxListItem]),
+ "indented marker inline size"
+ );
+ },
+ },
+ {
+ name: "a counter change re-runs the markers",
+ mutate: () => {
+ second.value = 7;
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=miss) FROM ITEMS
+ ListItemMarkerBox(anonymous)/block RUN (cache=miss)
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=miss) FROM ITEMS
+ ListItemMarkerBox(anonymous)/block RUN (cache=miss)
+ BlockContainer<UL>#disc REUSE IN-FLOW SUBTREE
+ BlockContainer<UL>#image REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#rtl REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#inside REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#blocks REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedInline REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedBlocks REUSE IN-FLOW SUBTREE
+ `,
+ check: equal => {
+ equal(markerTexts(decimal), JSON.stringify(["1. ", "7. "]), "decimal marker texts");
+ },
+ },
+ {
+ name: "a list-style-type change re-runs the marker",
+ mutate: () => {
+ disc.style.listStyleType = "square";
+ },
+ expect: `
+ layout FULL
+ @viewport/block RUN (cache=bypass)
+ BlockContainer<HTML>/block RUN (cache=miss)
+ BlockContainer<OL>#decimal REUSE IN-FLOW SUBTREE
+ ListItemMarkerBox(anonymous) MEASURE max-content inline (cache=miss) FROM ITEMS
+ ListItemMarkerBox(anonymous)/block RUN (cache=miss)
+ BlockContainer<UL>#image REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#rtl REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#inside REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#blocks REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedInline REUSE IN-FLOW SUBTREE
+ BlockContainer<OL>#indentedBlocks REUSE IN-FLOW SUBTREE
+ `,
+ },
+ ],
+ });
+</script>