Truly independent web browser
LibWeb: Respect line clamping while breaking overflowing text
Andreas Kling7ebf7acc6454
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex a01bb92b2de..b131810f19e 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -1622,12 +1622,13 @@ impl<'context> InlineFormattingContext<'context> {});}- fn break_overflowing_text_item(- &self,- line_builder: &mut line_builder::LineBuilder<'_, '_>,+ fn break_overflowing_text_item<'builder>(+ &'builder self,+ line_builder: &mut line_builder::LineBuilder<'builder, 'context>,item: &mut inline_level_iterator::Item,item_index: usize,mut line_limit: Option<&mut FragmentainerLineLimit>,+ state_at_clamp_point: &mut Option<LineBuildingState<'builder, 'context>>,) -> bool {if line_builder.remaining_inline_size_for_overflow_break()@@ -1640,6 +1641,11 @@ impl<'context> InlineFormattingContext<'context> {let letter_spacing = style.letter_spacing().to_double() as f32;let word_spacing = style.word_spacing().to_double() as f32;loop {+ // NB: Splitting one text item can create several lines. Observe the clamp point before creating more,+ // preserving the first clamped line while laying out legacy scrollable overflow.+ if self.stops_at_line_clamp_point(line_builder, state_at_clamp_point) {+ return false;+ }if line_limit.as_deref_mut().is_some_and(|limit| limit.is_reached(self)) {return true;}@@ -2001,6 +2007,7 @@ impl<'context> InlineFormattingContext<'context> {&mut item,item_index,line_limit.as_mut(),+ &mut state_at_clamp_point,) {stopped_at_line_limit = true;break;diff --git a/Tests/LibWeb/Text/expected/css/line-clamp-overflow-wrap.txt b/Tests/LibWeb/Text/expected/css/line-clamp-overflow-wrap.txtnew file mode 100644index 00000000000..159994f3d3d--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/line-clamp-overflow-wrap.txt@@ -0,0 +1,26 @@+legacy, 1 lines, width 0: height 20+Clamped content remains scrollable: true+legacy, 1 lines, width 1: height 20+Clamped content remains scrollable: true+legacy, 1 lines, width 10: height 20+Clamped content remains scrollable: true+legacy, 1 lines, width 36: height 20+Clamped content remains scrollable: true+legacy, 2 lines, width 0: height 40+Clamped content remains scrollable: true+legacy, 2 lines, width 1: height 40+Clamped content remains scrollable: true+legacy, 2 lines, width 10: height 40+Clamped content remains scrollable: true+legacy, 2 lines, width 36: height 40+Clamped content remains scrollable: true+standard, 1 lines, width 0: height 20+standard, 1 lines, width 1: height 20+standard, 1 lines, width 10: height 20+standard, 1 lines, width 36: height 20+standard, 2 lines, width 0: height 40+standard, 2 lines, width 1: height 40+standard, 2 lines, width 10: height 40+standard, 2 lines, width 36: height 40+Flex row height: 20+Flex handle width: 0diff --git a/Tests/LibWeb/Text/input/css/line-clamp-overflow-wrap.html b/Tests/LibWeb/Text/input/css/line-clamp-overflow-wrap.htmlnew file mode 100644index 00000000000..69bead8fe59--- /dev/null+++ b/Tests/LibWeb/Text/input/css/line-clamp-overflow-wrap.html@@ -0,0 +1,32 @@+<!doctype html>+<script src="../include.js"></script>+<style>+ body { font: 20px/20px monospace; }+ .clamp { overflow: hidden; overflow-wrap: break-word; }+ .legacy { display: -webkit-box; -webkit-box-orient: vertical; }+ .row { display: flex; width: 180px; align-items: center; }+ .name { flex-shrink: 0; width: 180px; }+ .handle { min-width: 0; }+</style>+<div class="row"><div class="name">Name</div><div class="handle"><a><span class="clamp legacy" style="-webkit-line-clamp: 1">@abcdefghijklmnopqrstuvwx</span></a></div></div>+<script>+ test(() => {+ for (const mode of ["legacy", "standard"]) {+ for (const lines of [1, 2]) {+ for (const width of [0, 1, 10, 36]) {+ const element = document.createElement("div");+ element.className = `clamp ${mode}`;+ element.style.width = `${width}px`;+ element.style.setProperty(mode === "legacy" ? "-webkit-line-clamp" : "line-clamp", lines);+ element.textContent = "abcdefghijklmnopqrstuvwx";+ document.body.appendChild(element);+ println(`${mode}, ${lines} lines, width ${width}: height ${element.clientHeight}`);+ if (mode === "legacy")+ println(`Clamped content remains scrollable: ${element.scrollHeight > element.clientHeight}`);+ }+ }+ }+ println(`Flex row height: ${document.querySelector(".row").clientHeight}`);+ println(`Flex handle width: ${document.querySelector(".handle").clientWidth}`);+ });+</script>