Skip to content

Truly independent web browser

LibWeb: Use transformed overflow for blocks inside inlines

sideshowbarkerf3aaffc79780
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
index cfdde0d1c18..6bac5edca5a 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
@@ -227,6 +227,10 @@ fn inline_box_unions(
let mut border_union = None;
for &piece_index in content.inline_boxes.piece_indices_of(link.fragment.node) {
let piece = &content.inline_box_pieces[piece_index as usize];
+ // An interrupting block's placeholder records inline geometry; the block supplies its own overflow.
+ if piece.is_geometry_only_placeholder && piece.fragment_count != 0 {
+ continue;
+ }
let border_rect = plane.piece_border_box_rect(piece);
if piece.is_geometry_only_placeholder {
let padding_rect = inflated_by(border_rect, padding_widths);
@@ -300,7 +304,13 @@ pub(crate) fn scrollable_overflow_of<'link>(
let plane = line_content.map(|content| PhysicalPlane::of(content, own.content_size));
if let (Some(content), Some(plane)) = (line_content, &plane) {
let origin = own.content_box.location();
- let line_rects = content.lines.iter().map(|line| plane.rect(line.rect));
+ // A block that interrupts inline layout contributes through its own transformed box. Its line record and
+ // inline fragments describe its untransformed position, not an additional CSS line box.
+ let line_rects = content
+ .lines
+ .iter()
+ .filter(|line| !line.has_block_level_box)
+ .map(|line| plane.rect(line.rect));
let elided_content_rects = content.elided_content_rects.iter().map(|&(_, rect)| plane.rect(rect));
let lines_after_clamp_point = content
.lines_after_clamp_point_rect
@@ -313,6 +323,9 @@ pub(crate) fn scrollable_overflow_of<'link>(
in_flow_and_floated_content_bounds.unite_vertically(line_rect);
}
for text_fragment in &content.fragments {
+ if content.lines[text_fragment.line_index as usize].has_block_level_box {
+ continue;
+ }
let mut fragment_rect = plane.fragment_rect(text_fragment).translated_by(origin);
if arena.node_is_in_focused_text_control(text_fragment.layout_node)
&& let Some(style_source_style) = arena.node_style_if_live(text_fragment.style_source)
diff --git a/Tests/LibWeb/Text/expected/transformed-block-in-inline-overflow.txt b/Tests/LibWeb/Text/expected/transformed-block-in-inline-overflow.txt
new file mode 100644
index 00000000000..48bf6678a1f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/transformed-block-in-inline-overflow.txt
@@ -0,0 +1,34 @@
+direct centered: 390x100
+direct positive: 510x100
+direct untransformed: 585x100
+direct far left: 410x100
+direct scale: 390x100
+direct vertical: 390x100
+inline centered: 390x100
+inline positive: 510x100
+inline untransformed: 585x100
+inline far left: 410x100
+inline scale: 390x100
+inline vertical: 390x100
+nested centered: 390x100
+nested positive: 510x100
+nested untransformed: 585x100
+nested far left: 410x100
+nested scale: 390x100
+nested vertical: 390x100
+decorated centered: 390x100
+decorated positive: 510x100
+decorated untransformed: 585x100
+decorated far left: 410x100
+decorated scale: 390x100
+decorated vertical: 390x100
+block-axis edges centered: 390x100
+block-axis edges positive: 510x100
+block-axis edges untransformed: 585x100
+block-axis edges far left: 410x100
+block-axis edges scale: 390x100
+block-axis edges vertical: 390x100
+before change: 390x100
+resized scroller: 390x100
+inline client rects unchanged: true
+restored scroller: 390x100
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline-002.txt
new file mode 100644
index 00000000000..f84ea429b20
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline-002.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass A relatively positioned block level box nested in an inline box contributes the same scrollable overflow in the inline direction as a block sibling
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline.txt
new file mode 100644
index 00000000000..014fe94648c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass A relatively positioned block level box nested in an inline box contributes the same scrollable overflow as a block sibling
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/transformed-block-in-inline-overflow.html b/Tests/LibWeb/Text/input/transformed-block-in-inline-overflow.html
new file mode 100644
index 00000000000..42ed2a1f42b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/transformed-block-in-inline-overflow.html
@@ -0,0 +1,85 @@
+<!doctype html>
+<script src="include.js"></script>
+<style>
+ body {
+ margin: 0;
+ }
+ .scroller {
+ width: 390px;
+ height: 100px;
+ overflow: auto;
+ font: 16px/20px monospace;
+ }
+ .content {
+ width: 350px;
+ padding: 0 20px;
+ }
+ .block {
+ width: 390px;
+ height: 40px;
+ margin-left: 50%;
+ transform: translateX(-50%);
+ }
+</style>
+<script>
+ promiseTest(async () => {
+ function add(wrapper, blockStyle = "", scrollerStyle = "", contentStyle = "") {
+ const scroller = document.createElement("div");
+ scroller.className = "scroller";
+ scroller.style.cssText = scrollerStyle;
+ const content = document.createElement("div");
+ content.className = "content";
+ content.style.cssText = contentStyle;
+ const block = document.createElement("div");
+ block.className = "block";
+ block.style.cssText = blockStyle;
+ content.innerHTML = wrapper;
+ (content.querySelector(".host") || content).append(block);
+ scroller.append(content);
+ document.body.append(scroller);
+ return { scroller, content, block };
+ }
+ function report(name, fixture) {
+ const { scroller } = fixture;
+ println(`${name}: ${scroller.scrollWidth}x${scroller.scrollHeight}`);
+ }
+ const wrappers = [
+ ["direct", ""],
+ ["inline", '<span class="host"></span>'],
+ ["nested", '<span><span class="host"></span></span>'],
+ ["decorated", '<span class="host" style="padding: 5px; border: 2px solid"></span>'],
+ ["block-axis edges", '<span class="host" style="padding-block: 5px; border-block: 2px solid"></span>'],
+ ];
+ for (const [name, wrapper] of wrappers) {
+ report(`${name} centered`, add(wrapper));
+ report(`${name} positive`, add(wrapper, "margin-left: 0; transform: translateX(100px)"));
+ report(`${name} untransformed`, add(wrapper, "transform: none"));
+ report(`${name} far left`, add(wrapper, "margin-left: 600px; transform: translateX(-600px)"));
+ report(`${name} scale`, add(wrapper, "margin-left: 0; transform: scale(.5); transform-origin: top left"));
+ report(
+ `${name} vertical`,
+ add(
+ wrapper,
+ "width: 40px; height: 100px; margin-left: 0; margin-top: 100px; transform: translateY(-100px)",
+ "writing-mode: vertical-lr",
+ "width: 390px; height: 100px; padding: 0"
+ )
+ );
+ }
+ const settle = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ const fixture = add('<span class="host"></span>');
+ document.body.prepend(fixture.scroller);
+ await settle();
+ const inline = fixture.content.querySelector("span");
+ const rects = () => JSON.stringify(Array.from(inline.getClientRects(), r => [r.x, r.y, r.width, r.height]));
+ const initialRects = rects();
+ report("before change", fixture);
+ fixture.scroller.style.width = "200px";
+ await settle();
+ report("resized scroller", fixture);
+ println(`inline client rects unchanged: ${rects() === initialRects}`);
+ fixture.scroller.style.width = "390px";
+ await settle();
+ report("restored scroller", fixture);
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline-002.html b/Tests/LibWeb/Text/input/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline-002.html
new file mode 100644
index 00000000000..04ac7f591c9
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline-002.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<meta name="assert" content="This ensures that a relatively positioned block level box nested in an inline box contributes the same scrollable overflow in the inline direction as it does as a block sibling.">
+<link rel="help" href="https://drafts.csswg.org/css-overflow-3/#scrollable" />
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<style>
+.container { width: 100px; height: 50px; font: 16px/18px monospace; }
+.shifted { width: 10px; height: 10px; position: relative; left: 20px; background-color: green; }
+</style>
+
+<div class="container" id="nested">text<span><div class="shifted"></div></span></div>
+<div class="container" id="sibling">text<div class="shifted"></div></div>
+
+<script>
+test(() => {
+ assert_equals(document.getElementById("nested").scrollWidth, document.getElementById("sibling").scrollWidth);
+}, "A relatively positioned block level box nested in an inline box contributes the same scrollable overflow in the inline direction as a block sibling");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline.html b/Tests/LibWeb/Text/input/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline.html
new file mode 100644
index 00000000000..11db0be6439
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-overflow/scrollable-overflow-relative-positioned-block-in-inline.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<meta name="assert" content="This ensures that a relatively positioned block level box nested in an inline box contributes the same scrollable overflow as it does as a block sibling.">
+<link rel="help" href="https://drafts.csswg.org/css-overflow-3/#scrollable" />
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<style>
+.container { width: 10px; height: 10px; }
+.shifted { width: 10px; height: 500px; position: relative; bottom: 300px; background-color: green; }
+</style>
+
+<div class="container" id="nested"><img style="width: 10px; height: 200px;"><span><div class="shifted"></div></span></div>
+<div class="container" id="sibling"><img style="width: 10px; height: 200px;"><div class="shifted"></div></div>
+
+<script>
+test(() => {
+ assert_equals(document.getElementById("nested").scrollHeight, document.getElementById("sibling").scrollHeight);
+}, "A relatively positioned block level box nested in an inline box contributes the same scrollable overflow as a block sibling");
+</script>