Skip to content

Truly independent web browser

LibWeb: Do not clamp lines of a multi-column container

Aliaksandr Kalenikba1c4eb874b6
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index 9c2351126f6..2ec1b199362 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -202,10 +202,11 @@ impl<'pass> BlockFormattingContext<'pass> {
// The -webkit-legacy value behaves identically to collapse, except that it only takes effect if the specified
// value of the display property is -webkit-box or -webkit-inline-box and the value of the -webkit-box-orient
// property is vertical.
- let is_line_clamp_container = computed_continue == continue_value::COLLAPSE
+ let is_line_clamp_container = (computed_continue == continue_value::COLLAPSE
|| (computed_continue == continue_value::_WEBKIT_LEGACY
&& style.display_before_box_type_transformation().is_webkit_box_inside()
- && style.webkit_box_orient() == webkit_box_orient::VERTICAL);
+ && style.webkit_box_orient() == webkit_box_orient::VERTICAL))
+ && !NodeFacts::new(&run.callbacks, run.box_).lays_out_in_columns();
// AD-HOC: Content after a -webkit-legacy clamp point stays scrollable overflow, matching other engines. Sites
// detect clamped text by comparing scrollHeight with clientHeight.
let clamped_content_is_scrollable_overflow =
diff --git a/Libraries/LibWeb/Rust/src/layout/node_facts.rs b/Libraries/LibWeb/Rust/src/layout/node_facts.rs
index 0cf385735fb..8d2ed9234ee 100644
--- a/Libraries/LibWeb/Rust/src/layout/node_facts.rs
+++ b/Libraries/LibWeb/Rust/src/layout/node_facts.rs
@@ -463,6 +463,17 @@ pub(crate) fn node_creates_block_formatting_context(
parent_is_flex_or_grid_container
}
+pub(crate) fn node_lays_out_in_columns(data: &NodeData, style: ComputedValuesView<'_>) -> bool {
+ style.establishes_multi_column_container()
+ && (has_flag(data, NodeFlag::Anonymous) || style.appearance() == crate::css::css_enums::appearance::NONE)
+ && !has_flag(data, NodeFlag::UsesButtonLayout)
+ && !has_flag(data, NodeFlag::IsHtmlInputElement)
+ && !matches!(
+ data.kind.get(),
+ NodeKind::RangeInputBox | NodeKind::TextAreaBox | NodeKind::TextInputBox | NodeKind::TableWrapper
+ )
+}
+
pub(crate) fn node_is_fieldset_content_wrapper(data: &NodeData, style: Option<ComputedValuesView<'_>>) -> bool {
has_flag(data, NodeFlag::Anonymous)
&& data.kind.get() == NodeKind::BlockContainer
@@ -1109,6 +1120,28 @@ impl<'pass> NodeFacts<'pass> {
Node::INVALID
}
+ pub(crate) fn lays_out_in_columns(&self) -> bool {
+ self.computed_values_view_if_styled()
+ .is_some_and(|view| node_lays_out_in_columns(self.data(), view))
+ && !self.has_fieldset_content_wrapper()
+ }
+
+ fn has_fieldset_content_wrapper(&self) -> bool {
+ let data = self.data();
+ if data.kind.get() != NodeKind::FieldSetBox {
+ return false;
+ }
+ let mut child = data.first_child.get();
+ while !child.is_invalid() {
+ let child_data = self.callbacks.node_data(child);
+ if node_is_fieldset_content_wrapper(child_data, self.callbacks.computed_values_view_if_styled(child)) {
+ return true;
+ }
+ child = child_data.next_sibling.get();
+ }
+ false
+ }
+
pub(crate) fn list_item_marker(&self) -> Node {
if !self.is_list_item_box() {
return Node::INVALID;
diff --git a/Tests/LibWeb/Text/expected/line-clamp-multicol-container.txt b/Tests/LibWeb/Text/expected/line-clamp-multicol-container.txt
new file mode 100644
index 00000000000..010dc9689e4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/line-clamp-multicol-container.txt
@@ -0,0 +1,5 @@
+standard: 40
+standard-columns: 80
+webkit: 40
+webkit-columns: 80
+webkit-column-width: 80
diff --git a/Tests/LibWeb/Text/input/line-clamp-multicol-container.html b/Tests/LibWeb/Text/input/line-clamp-multicol-container.html
new file mode 100644
index 00000000000..5541476dca9
--- /dev/null
+++ b/Tests/LibWeb/Text/input/line-clamp-multicol-container.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ @font-face {
+ font-family: Ahem;
+ src: url("../../Ref/data/fonts/Ahem.ttf");
+ }
+ body { margin: 0; font: 20px/20px Ahem; }
+ div { width: 300px; }
+ p { margin: 0; }
+ .standard { line-clamp: 2; }
+ .webkit { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
+</style>
+<div id="standard" class="standard"><p>a</p><p>b</p><p>c</p><p>d</p></div>
+<div id="standard-columns" class="standard" style="columns: 1"><p>a</p><p>b</p><p>c</p><p>d</p></div>
+<div id="webkit" class="webkit"><p>a</p><p>b</p><p>c</p><p>d</p></div>
+<div id="webkit-columns" class="webkit" style="columns: 1"><p>a</p><p>b</p><p>c</p><p>d</p></div>
+<div id="webkit-column-width" class="webkit" style="column-width: 1000px"><p>a</p><p>b</p><p>c</p><p>d</p></div>
+<script>
+ asyncTest(async done => {
+ await document.fonts.load("20px Ahem");
+ for (const id of ["standard", "standard-columns", "webkit", "webkit-columns", "webkit-column-width"])
+ println(`${id}: ${document.getElementById(id).getBoundingClientRect().height}`);
+ done();
+ });
+</script>