Truly independent web browser
LibWeb: Keep empty generated content’s end edges before text
sideshowbarker2ccd750a65cf
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rsindex e2f9cd5e676..f5879c4da20 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs@@ -912,9 +912,16 @@ impl<'pass> InlineContentPreparer<'pass> {fn exit_node_with_box_model_metrics(&mut self) {self.buffers.box_stack.pop().unwrap();- // NB: The walk looks one node ahead, so a box usually ends while its last item is the current node. An inline- // box as the current node has no item of its own, so nothing in the box comes with the next item.- let before_item = !self.current_node.is_invalid() && self.facts(self.current_node).is_fragmented_inline();+ // The walk looks one node ahead, so a box usually ends while its last item is the current node. An inline box+ // or an empty text node without a caret fragment has no item of its own. Its end edges precede the next item+ // rather than follow that item's content.+ let before_item = !self.current_node.is_invalid() && {+ let facts = self.facts(self.current_node);+ facts.is_fragmented_inline()+ || (facts.is_text_node()+ && !facts.produces_line_box_fragment_when_empty()+ && self.pass.text_content(self.current_node).text.is_empty())+ };let event = InlineBoxEvent::leaving_innermost_box(self.inline_box_event_position(), before_item);self.buffers.box_events.push(event);}diff --git a/Tests/LibWeb/Layout/expected/empty-pseudo-element-content.txt b/Tests/LibWeb/Layout/expected/empty-pseudo-element-content.txtindex c5633c3dbde..c7a74db6114 100644--- a/Tests/LibWeb/Layout/expected/empty-pseudo-element-content.txt+++ b/Tests/LibWeb/Layout/expected/empty-pseudo-element-content.txt@@ -2,7 +2,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 60 0+0+0] [BFC] children: not-inlineBlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 44 0+0+8] children: not-inlineBlockContainer <div.inline> at [8,8] [0+0+0 784 0+0+0] [0+0+0 20 0+0+0] children: inline- frag 0 from TextNode start: 0, length: 6, rect: [15,8 51.640625x20] baseline: 16+ frag 0 from TextNode start: 0, length: 6, rect: [22,8 51.640625x20] baseline: 16"inline"InlineNode <(anonymous)> at [8,8] [0+2+5 0 5+2+0] [0+2+5 0 5+2+0]GeneratedTextNode <(anonymous)> (not painted)diff --git a/Tests/LibWeb/Text/expected/css/empty-pseudo-inline-padding.txt b/Tests/LibWeb/Text/expected/css/empty-pseudo-inline-padding.txtnew file mode 100644index 00000000000..891ef87bf91--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/empty-pseudo-inline-padding.txt@@ -0,0 +1,6 @@+list text offset: 144+list text offset: 144+before: 40+after: 40+before edges: 50+before space: 40diff --git a/Tests/LibWeb/Text/input/css/empty-pseudo-inline-padding.html b/Tests/LibWeb/Text/input/css/empty-pseudo-inline-padding.htmlnew file mode 100644index 00000000000..0e365c75c63--- /dev/null+++ b/Tests/LibWeb/Text/input/css/empty-pseudo-inline-padding.html@@ -0,0 +1,30 @@+<!doctype html>+<style>+ html { font-size: 16px; }+ li::before { content: ""; padding-right: 9rem; }+ .before::before, .after::after { content: ""; padding-left: 10px; padding-right: 30px; }+ .edges::before { border-right: 4px solid; margin-right: 6px; }+ .space::before { content: " "; }+</style>+<ol><li>a</li><li>b</li></ol>+<script src="../include.js"></script>+<script>+ test(() => {+ for (const item of document.querySelectorAll("li")) {+ const range = document.createRange();+ range.selectNodeContents(item);+ println(`list text offset: ${range.getBoundingClientRect().left - item.getBoundingClientRect().left}`);+ }+ for (const className of ["before", "after", "before edges", "before space"]) {+ const block = document.createElement("div");+ const span = document.createElement("span");+ span.className = className;+ const text = document.createTextNode("x");+ block.append(span, text);+ document.body.append(block);+ const range = document.createRange();+ range.selectNodeContents(text);+ println(`${className}: ${range.getBoundingClientRect().left - block.getBoundingClientRect().left}`);+ }+ });+</script>