Skip to content

Truly independent web browser

LibWeb: Apply the line-height quirk in limited-quirks mode too

sideshowbarker14b318a92553
diff --git a/Libraries/LibWeb/Layout/UpdateLayout.cpp b/Libraries/LibWeb/Layout/UpdateLayout.cpp
index 1b56284106f..85d73eef5f0 100644
--- a/Libraries/LibWeb/Layout/UpdateLayout.cpp
+++ b/Libraries/LibWeb/Layout/UpdateLayout.cpp
@@ -49,6 +49,7 @@ Layout::RustFFI::FfiLayoutUpdateHostCallbacks Document::layout_update_host_callb
.top_layer_work_pending = !document.m_elements_with_pending_top_layer_membership_change.is_empty(),
.should_collect_devtools_layout_data = document.page().client().has_active_devtools_client(),
.document_in_quirks_mode = document.in_quirks_mode(),
+ .document_in_limited_quirks_mode = document.in_limited_quirks_mode(),
.viewport_inline_size_raw = viewport_rect.width().raw_value(),
.viewport_block_size_raw = viewport_rect.height().raw_value(),
.document_style_node = document.style_node_id().value(),
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 34ffe6c85a7..fa4e9e74635 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -3794,6 +3794,7 @@ pub(crate) struct LayoutStageFacts {
pub(crate) viewport_inline_size: CssPixels,
pub(crate) viewport_block_size: CssPixels,
pub(crate) document_in_quirks_mode: bool,
+ pub(crate) document_in_limited_quirks_mode: bool,
}
/// What a layout stage computes from: the arena and the layout stage's scratch, borrowed for the
@@ -4233,6 +4234,7 @@ mod baseline_tests {
viewport_inline_size: CssPixels::from_integer(800),
viewport_block_size: CssPixels::from_integer(600),
document_in_quirks_mode: false,
+ document_in_limited_quirks_mode: false,
},
);
RunState::with_root(pass, parent, Node::INVALID, None, |_, pass| {
diff --git a/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rs b/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rs
index 6d8342f4eea..8d1e917e3cc 100644
--- a/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/in_flow_block_cache.rs
@@ -33,6 +33,7 @@ pub(super) struct InFlowBlockKey {
pub(super) treat_block_axis_percentage_insets_as_auto_beyond_root: bool,
pub(super) initial_containing_block_size: (CssPixels, CssPixels),
pub(super) document_in_quirks_mode: bool,
+ pub(super) document_in_limited_quirks_mode: bool,
}
impl InFlowBlockKey {
@@ -58,6 +59,7 @@ impl InFlowBlockKey {
run.pass.initial_containing_block_block_size,
),
document_in_quirks_mode: run.pass.document_in_quirks_mode,
+ document_in_limited_quirks_mode: run.pass.document_in_limited_quirks_mode,
}
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 72aceadeee2..da2e85dcfef 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -2690,7 +2690,8 @@ impl<'context> InlineFormattingContext<'context> {
let mut stopped_at_line_limit = false;
let mut needs_float_fitting = !float_fit_trial;
// https://quirks.spec.whatwg.org/#the-line-height-calculation-quirk
- let takes_struts_of_inline_boxes_without_text = !self.facts(self.containing_block).document_in_quirks_mode();
+ let takes_struts_of_inline_boxes_without_text =
+ !self.facts(self.containing_block).document_in_line_height_quirks_mode();
loop {
if float_fit_trial && line_builder.float_refit().is_some() {
break;
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index 2acf26410f0..9cedbebcdf9 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -2144,7 +2144,7 @@ impl<'context> RunItemResolver<'_, 'context> {
// unless it has a border or padding at its start or end.
let none = CssPixels::default();
if in_flow_item_count_at_start == self.in_flow_item_count
- && (!self.context().facts(node).document_in_quirks_mode()
+ && (!self.context().facts(node).document_in_line_height_quirks_mode()
|| sides.border_left != none
|| sides.border_right != none
|| sides.padding_left != none
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs b/Libraries/LibWeb/Rust/src/layout/layout_pass.rs
index 7997ad83253..462f8dd0ae9 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_pass.rs
@@ -27,6 +27,7 @@ pub(crate) struct LayoutPass<'arena> {
pub(crate) initial_containing_block_inline_size: CssPixels,
pub(crate) initial_containing_block_block_size: CssPixels,
pub(crate) document_in_quirks_mode: bool,
+ pub(crate) document_in_limited_quirks_mode: bool,
/// The frame of the formatting context the pass is laying out, in which style reads see sizes and box sides.
pub(crate) frame: super::geometry::Frame,
/// The root of the run this pass view was handed to and that root's containing block, where containing block
@@ -131,6 +132,7 @@ impl<'arena> LayoutPass<'arena> {
initial_containing_block_inline_size: stage.viewport_inline_size,
initial_containing_block_block_size: stage.viewport_block_size,
document_in_quirks_mode: stage.document_in_quirks_mode,
+ document_in_limited_quirks_mode: stage.document_in_limited_quirks_mode,
frame: super::geometry::Frame::PHYSICAL,
innermost_run: (NodeSlotId::INVALID, NodeSlotId::INVALID),
host_findings: host_findings_outside_runs,
@@ -191,6 +193,7 @@ impl<'arena> LayoutPass<'arena> {
viewport_inline_size: CssPixels::default(),
viewport_block_size: CssPixels::default(),
document_in_quirks_mode: false,
+ document_in_limited_quirks_mode: false,
},
)
}
diff --git a/Libraries/LibWeb/Rust/src/layout/node_facts.rs b/Libraries/LibWeb/Rust/src/layout/node_facts.rs
index d51d92f96b8..9260d7523dd 100644
--- a/Libraries/LibWeb/Rust/src/layout/node_facts.rs
+++ b/Libraries/LibWeb/Rust/src/layout/node_facts.rs
@@ -1629,6 +1629,13 @@ impl<'pass> NodeFacts<'pass> {
self.pass.document_in_quirks_mode
}
+ // https://quirks.spec.whatwg.org/#the-line-height-calculation-quirk
+ // In quirks mode and limited-quirks mode, an inline box that matches the following conditions, must, for the
+ // purpose of line height calculation, act as if the box had a line-height of zero.
+ pub(crate) fn document_in_line_height_quirks_mode(&self) -> bool {
+ self.pass.document_in_quirks_mode || self.pass.document_in_limited_quirks_mode
+ }
+
pub(crate) fn is_in_user_agent_shadow_tree(&self) -> bool {
has_flag(self.data(), NodeFlag::IsInUserAgentShadowTree)
}
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index f1e829bea94..8b5a36494ed 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -4728,6 +4728,7 @@ mod replaced_ratio_tests {
viewport_inline_size: CssPixels::from_integer(800),
viewport_block_size: CssPixels::from_integer(600),
document_in_quirks_mode: false,
+ document_in_limited_quirks_mode: false,
},
);
let result = RunState::with_root(pass, node, Node::INVALID, None, |state, pass| {
diff --git a/Libraries/LibWeb/Rust/src/layout/update_layout.rs b/Libraries/LibWeb/Rust/src/layout/update_layout.rs
index db7e920f112..ccecc72e8e7 100644
--- a/Libraries/LibWeb/Rust/src/layout/update_layout.rs
+++ b/Libraries/LibWeb/Rust/src/layout/update_layout.rs
@@ -127,6 +127,7 @@ pub struct FfiLayoutUpdateDocumentFacts {
pub top_layer_work_pending: bool,
pub should_collect_devtools_layout_data: bool,
pub document_in_quirks_mode: bool,
+ pub document_in_limited_quirks_mode: bool,
pub viewport_inline_size_raw: i32,
pub viewport_block_size_raw: i32,
/// The document's style node, which a layout tree build walks from.
@@ -766,6 +767,7 @@ impl LayoutRoundJob {
viewport_inline_size: crate::layout::CssPixels::from_raw(facts.viewport_inline_size_raw),
viewport_block_size: crate::layout::CssPixels::from_raw(facts.viewport_block_size_raw),
document_in_quirks_mode: facts.document_in_quirks_mode,
+ document_in_limited_quirks_mode: facts.document_in_limited_quirks_mode,
};
// The round cannot call the host, which hears of the boxes nodes gain and lose once it is over.
state.arena_mut().queue_box_presence();
@@ -1282,6 +1284,7 @@ mod tests {
top_layer_work_pending: false,
should_collect_devtools_layout_data: false,
document_in_quirks_mode: false,
+ document_in_limited_quirks_mode: false,
viewport_inline_size_raw: 0,
viewport_block_size_raw: 0,
document_style_node: 0,
diff --git a/Tests/LibWeb/Text/expected/css/line-height-quirk-strut-of-block-container-limited-quirks.txt b/Tests/LibWeb/Text/expected/css/line-height-quirk-strut-of-block-container-limited-quirks.txt
new file mode 100644
index 00000000000..deddb5f2021
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/line-height-quirk-strut-of-block-container-limited-quirks.txt
@@ -0,0 +1,26 @@
+CSS1Compat
+text: 20
+inline-block: 20
+image: 20
+text-then-inline-block: 20
+text-in-span: 20
+text-in-nested-span: 20
+inline-block-then-text-in-span: 20
+inline-block-in-tall-span: 60
+inline-block-in-padded-span: 60
+br: 20
+br-then-text: 40
+inline-block-then-br: 40
+text-in-span-then-br: 40
+br-in-span: 20
+collapsed-spaces: 20
+space-between-inline-blocks: 20
+space-at-wrap: 40
+preserved-space-at-wrap: 40
+nbsp: 20
+zero-width-space: 20
+list-item: 20
+empty-span-then-text: 20
+padded-empty-span: 20
+bordered-empty-span: 60
+menu-title: 15 (span at 3)
diff --git a/Tests/LibWeb/Text/input/css/line-height-quirk-strut-of-block-container-limited-quirks.html b/Tests/LibWeb/Text/input/css/line-height-quirk-strut-of-block-container-limited-quirks.html
new file mode 100644
index 00000000000..3e6dd3f4431
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/line-height-quirk-strut-of-block-container-limited-quirks.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<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; }
+ .t { font-size: 10px; line-height: 10px; }
+ .ib { display: inline-block; width: 10px; height: 10px; }
+ .case { position: relative; }
+</style>
+<div class="case" id="text">x</div>
+<div class="case" id="inline-block"><span class="ib"></span></div>
+<div class="case" id="image"><img style="width: 10px; height: 10px" src="data:image/svg+xml,<svg xmlns=%27http://www.w3.org/2000/svg%27 width=%2710%27 height=%2710%27/>"></div>
+<div class="case" id="text-then-inline-block">x<span class="ib"></span></div>
+<div class="case" id="text-in-span"><span class="t">x</span></div>
+<div class="case" id="text-in-nested-span"><span class="t"><b>x</b></span></div>
+<div class="case" id="inline-block-then-text-in-span"><span class="ib"></span><span class="t">x</span></div>
+<div class="case" id="inline-block-in-tall-span"><span class="s"><span class="ib"></span></span></div>
+<div class="case" id="inline-block-in-padded-span"><span class="s" style="padding-left: 1px"><span class="ib"></span></span></div>
+<div class="case" id="br"><br></div>
+<div class="case" id="br-then-text"><br>x</div>
+<div class="case" id="inline-block-then-br"><span class="ib"></span><br>x</div>
+<div class="case" id="text-in-span-then-br"><span class="t">x</span><br>y</div>
+<div class="case" id="br-in-span"><span class="t"><br></span></div>
+<div class="case" id="collapsed-spaces"> <span class="ib"></span> </div>
+<div class="case" id="space-between-inline-blocks"><span class="ib"></span> <span class="ib"></span></div>
+<div class="case" id="space-at-wrap" style="width: 15px"><span class="ib"></span> <span class="ib"></span></div>
+<div class="case" id="preserved-space-at-wrap" style="white-space: pre-wrap; width: 15px"><span class="ib"></span> <span class="ib"></span></div>
+<div class="case" id="nbsp"><span class="ib"></span>&nbsp;</div>
+<div class="case" id="zero-width-space">&#x200b;<span class="ib"></span></div>
+<div class="case" id="list-item" style="display: list-item; list-style: none"><span class="ib"></span></div>
+<div class="case" id="empty-span-then-text"><span class="s"></span>x</div>
+<div class="case" id="padded-empty-span" style="font-size: 10px"><span class="s" style="padding-top: 1px"></span><span class="ib"></span></div>
+<div class="case" id="bordered-empty-span"><span class="s" style="border-left: 1px solid"></span><span class="ib"></span></div>
+<div class="case" id="menu-title" style="font: 16px/normal serif; height: 15px"><span style="font: 12px/16px Ahem; padding: 0 9px">Ladybird</span></div>
+<script src="../include.js"></script>
+<script>
+ promiseTest(async () => {
+ await document.fonts.ready;
+ println(document.compatMode);
+ for (const element of document.querySelectorAll(".case")) {
+ const rect = element.getBoundingClientRect();
+ const span = element.querySelector("span");
+ println(`${element.id}: ${rect.height}${element.id === "menu-title" ? ` (span at ${span.getBoundingClientRect().top - rect.top})` : ""}`);
+ }
+ });
+</script>