Skip to content

Truly independent web browser

LibWeb: Report a client rect for line breaks

Andreas Kling7eadc0e07bb6
diff --git a/Libraries/LibWeb/Rust/src/painting/client_rects.rs b/Libraries/LibWeb/Rust/src/painting/client_rects.rs
index 69d8ad06078..7c023eed4ed 100644
--- a/Libraries/LibWeb/Rust/src/painting/client_rects.rs
+++ b/Libraries/LibWeb/Rust/src/painting/client_rects.rs
@@ -93,6 +93,20 @@ pub(crate) fn for_each_client_rect(
rect,
));
};
+ // INTEROP: A line break has no box fragments of its own, but browsers report a zero-width rect where it ends its
+ // line.
+ if arena.node_kind_if_live(layout_node) == Some(NodeKind::BreakNode) {
+ if let Some((line_root, rect)) = line_break_rect(arena, layout_node) {
+ push_rect(transform_rect_to_viewport_or_identity(
+ rect_to_viewport_transform,
+ arena,
+ line_root,
+ rect,
+ ));
+ }
+ return;
+ }
+
let row_is_populated = arena.paintable_row_is_populated(layout_node);
// FIXME: 2. If the element has an associated SVG layout box return a DOMRectList object containing a single
@@ -131,6 +145,50 @@ pub(crate) fn for_each_client_rect(
}
}
+/// The line root whose line the forced line break ends, and the zero-width rect of the break at the inline end of
+/// that line's content, or at the inline start of the line where it is empty.
+fn line_break_rect(arena: &impl PaintRead, break_node: NodeSlotId) -> Option<(NodeSlotId, CssPixelRect)> {
+ let mut ancestor = arena.node(break_node)?.parent();
+ while let Some(row) = arena.node(ancestor) {
+ if arena.paintable_row_is_populated(ancestor) {
+ let side = arena.committed_side_data(ancestor);
+ if let Some(line) = side.lines().iter().find(|line| line.forced_break_node == break_node) {
+ let style = arena.node_style_if_live(ancestor)?;
+ let root_position =
+ paintable_geometry::LineRootPositions::new(arena, ancestor).of_fragment(line.box_fragment);
+ let line_rect = CssPixelRect::from(line.rect).translated_by(root_position);
+ let inline_axis_is_horizontal =
+ style.writing_mode() == crate::css::css_enums::writing_mode::HORIZONTAL_TB;
+ let at_high_side = (line.fragment_count == 0) == style.inline_axis_is_reverse();
+ let zero = CssPixels::default();
+ let rect = match (inline_axis_is_horizontal, at_high_side) {
+ (true, false) => CssPixelRect {
+ width: zero,
+ ..line_rect
+ },
+ (true, true) => CssPixelRect {
+ x: line_rect.x + line_rect.width,
+ width: zero,
+ ..line_rect
+ },
+ (false, false) => CssPixelRect {
+ height: zero,
+ ..line_rect
+ },
+ (false, true) => CssPixelRect {
+ y: line_rect.y + line_rect.height,
+ height: zero,
+ ..line_rect
+ },
+ };
+ return Some((ancestor, rect));
+ }
+ }
+ ancestor = row.parent();
+ }
+ None
+}
+
// https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect
pub(crate) fn bounding_client_rect(
arena: &impl PaintRead,
diff --git a/Tests/LibWeb/Text/expected/get-bounding-client-rect-display-none.txt b/Tests/LibWeb/Text/expected/get-bounding-client-rect-display-none.txt
index 9b4d5d8aa4b..f038b91c381 100644
--- a/Tests/LibWeb/Text/expected/get-bounding-client-rect-display-none.txt
+++ b/Tests/LibWeb/Text/expected/get-bounding-client-rect-display-none.txt
@@ -1,2 +1,2 @@
{"x":0,"y":0,"width":0,"height":0,"top":0,"right":0,"bottom":0,"left":0}
-{"x":0,"y":0,"width":0,"height":0,"top":0,"right":0,"bottom":0,"left":0}
+{"x":8,"y":8,"width":0,"height":16,"top":8,"right":8,"bottom":24,"left":8}
diff --git a/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt b/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt
index 194a11b6d1f..25033af6074 100644
--- a/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt
+++ b/Tests/LibWeb/Text/expected/intrinsic-inline-content-sizing.txt
@@ -57,9 +57,9 @@ preserved spaces, fit-content: [220,30]
only spaces, min-content: [60,30]
only spaces, max-content: [60,30]
only spaces, fit-content: [60,30]
-forced breaks, min-content: [60,120]
-forced breaks, max-content: [60,120]
-forced breaks, fit-content: [60,120]
+forced breaks, min-content: [60,120,40,60,0,30]
+forced breaks, max-content: [60,120,40,60,0,30]
+forced breaks, fit-content: [60,120,40,60,0,30]
inline boundaries, min-content: [40,90,20,5,20,20,0,35,40,20]
inline boundaries, max-content: [140,30,20,5,40,20,60,5,40,20]
inline boundaries, fit-content: [140,30,20,5,40,20,60,5,40,20]
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-htb-ltr.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-htb-ltr.txt
index f3267b4cc9a..d80ee72bcec 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-htb-ltr.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-htb-ltr.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Position of the BR element
\ No newline at end of file
+1 Pass
+Pass Position of the BR element
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-htb-rtl.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-htb-rtl.txt
index f3267b4cc9a..d80ee72bcec 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-htb-rtl.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-htb-rtl.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Position of the BR element
\ No newline at end of file
+1 Pass
+Pass Position of the BR element
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vlr-ltr.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vlr-ltr.txt
index f3267b4cc9a..d80ee72bcec 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vlr-ltr.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vlr-ltr.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Position of the BR element
\ No newline at end of file
+1 Pass
+Pass Position of the BR element
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vlr-rtl.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vlr-rtl.txt
index f3267b4cc9a..d80ee72bcec 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vlr-rtl.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vlr-rtl.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Position of the BR element
\ No newline at end of file
+1 Pass
+Pass Position of the BR element
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vrl-ltr.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vrl-ltr.txt
index f3267b4cc9a..d80ee72bcec 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vrl-ltr.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vrl-ltr.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Position of the BR element
\ No newline at end of file
+1 Pass
+Pass Position of the BR element
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vrl-rtl.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vrl-rtl.txt
index f3267b4cc9a..d80ee72bcec 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vrl-rtl.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/getClientRects-br-vrl-rtl.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Position of the BR element
\ No newline at end of file
+1 Pass
+Pass Position of the BR element
\ No newline at end of file