Truly independent web browser
LibWeb: Keep an empty inline box between the text around it
sideshowbarker2b270e6518e8
diff --git a/Libraries/LibWeb/Rust/src/layout/line_builder.rs b/Libraries/LibWeb/Rust/src/layout/line_builder.rsindex dc95af42305..6739c8abaeb 100644--- a/Libraries/LibWeb/Rust/src/layout/line_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/line_builder.rs@@ -1665,16 +1665,23 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {// NB: An inline box after preserved white space that hangs at the end of the line comes after that white// space, even though the line's inline length doesn't count it.let hanging_whitespace_inline_size = self.hanging_whitespace_inline_size;+ let fragments_are_mirrored = self.context().atomic_items_are_right_to_left;let mut line = self.line_mut(line_index);let content_inline_length = line.inline_length;+ let indent = line.indent;let is_right_to_left = line.direction == direction::RTL;for strut in &mut line.inline_box_struts {- let offset = strut- .inline_offset- .min(content_inline_length + hanging_whitespace_inline_size);+ let line_end = content_inline_length + hanging_whitespace_inline_size;+ let offset = strut.inline_offset.min(line_end);+ // NB: A box between two fragments sits between them as they're laid out, which is in logical order+ // unless the fragments are mirrored, and moved by the line's indent as they are. A box at either+ // end of a right-to-left line is at that end in the line's own direction.+ let is_at_line_edge = offset <= indent || offset >= line_end;strut.inline_offset = marker_inline_offset- + if is_right_to_left {+ + if is_right_to_left && (fragments_are_mirrored || is_at_line_edge) {content_inline_length - offset+ } else if is_right_to_left {+ offset - indent} else {offset};diff --git a/Tests/LibWeb/Text/expected/css/empty-inline-box-position-in-right-to-left-line.txt b/Tests/LibWeb/Text/expected/css/empty-inline-box-position-in-right-to-left-line.txtnew file mode 100644index 00000000000..add3d84c5d7--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/empty-inline-box-position-in-right-to-left-line.txt@@ -0,0 +1,7 @@+collapsible-space-at-wrap: 80 span at (40, 5)+ltr-text-in-rtl-block: 60 span at (160, 5)+ltr-text-in-rtl-block-without-space: 60 span at (160, 5)+ltr-text-in-rtl-block-at-end: 60 span at (100, 5)+ltr-text-in-indented-rtl-block: 60 span at (140, 5)+ltr-text-in-indented-rtl-block-after-space: 60 span at (140, 5)+ltr-block: 60 span at (60, 5)diff --git a/Tests/LibWeb/Text/input/css/empty-inline-box-position-in-right-to-left-line.html b/Tests/LibWeb/Text/input/css/empty-inline-box-position-in-right-to-left-line.htmlnew file mode 100644index 00000000000..49240b7e363--- /dev/null+++ b/Tests/LibWeb/Text/input/css/empty-inline-box-position-in-right-to-left-line.html@@ -0,0 +1,25 @@+<!DOCTYPE html>+<style>+ @font-face { font-family: Ahem; src: url("../wpt-import/fonts/Ahem.ttf"); }+ body { margin: 0; font: 20px/20px Ahem; }+ .s { font-size: 50px; line-height: 60px; }+ .case { position: relative; }+</style>+<div class="case" id="collapsible-space-at-wrap" style="width: 60px">xx <span class="s"></span>yy</div>+<div class="case" id="ltr-text-in-rtl-block" style="direction: rtl; width: 200px">ab <span class="s"></span>cd</div>+<div class="case" id="ltr-text-in-rtl-block-without-space" style="direction: rtl; width: 200px">ab<span class="s"></span>cd</div>+<div class="case" id="ltr-text-in-rtl-block-at-end" style="direction: rtl; width: 200px">ab cd<span class="s"></span></div>+<div class="case" id="ltr-text-in-indented-rtl-block" style="direction: rtl; width: 200px; text-indent: 20px">ab<span class="s"></span>cd</div>+<div class="case" id="ltr-text-in-indented-rtl-block-after-space" style="direction: rtl; width: 200px; text-indent: 20px">ab <span class="s"></span>cd</div>+<div class="case" id="ltr-block" style="width: 200px">ab <span class="s"></span>cd</div>+<script src="../include.js"></script>+<script>+ promiseTest(async () => {+ await document.fonts.ready;+ for (const element of document.querySelectorAll(".case")) {+ const rect = element.getBoundingClientRect();+ const span = element.querySelector(".s").getBoundingClientRect();+ println(`${element.id}: ${rect.height} span at (${span.left - rect.left}, ${span.top - rect.top})`);+ }+ });+</script>