Skip to content

Truly independent web browser

LibWeb: Remove the dummy formatting context

Aliaksandr Kalenik318525042e92
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index ec5fc2e6892..7f1a56810e0 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -968,10 +968,7 @@ pub(super) fn can_describe_run(
let input = &key.input;
if should_collect_devtools_layout_data
|| (input.participation == ParticipationInParentFormattingContext::Root && !measurement_root_keeps_its_result)
- || matches!(
- fc_type,
- formatting_context::FormattingContextType::InternalReplaced | formatting_context::FormattingContextType::InternalDummy
- )
+ || fc_type == formatting_context::FormattingContextType::InternalReplaced
// The direct normal-layout path for an empty atomic block only sizes and snapshots its root.
// Replaying a stored output costs more than rebuilding it and retains an entry needlessly.
|| (fc_type == formatting_context::FormattingContextType::Block
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 8145ed76149..0c56fb73866 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -952,7 +952,6 @@ pub enum FormattingContextType {
Math,
ReplacedWithChildren,
InternalReplaced,
- InternalDummy,
}
impl FormattingContextType {
@@ -1298,7 +1297,6 @@ enum FormattingContextImplementation<'pass> {
Math(Box<math_formatting_context::MathFormattingContext<'pass>>),
ReplacedWithChildren,
InternalReplaced,
- InternalDummy,
}
pub(crate) fn formatting_context_type_created_by_node_data(
@@ -1361,30 +1359,13 @@ pub(crate) fn formatting_context_type_created_by_node_data(
}
return Some(FormattingContextType::Math);
}
- if node_facts::node_creates_block_formatting_context(
+ node_facts::node_creates_block_formatting_context(
data,
style,
parent_is_flex_or_grid_container,
parent_writing_mode,
- ) {
- return Some(FormattingContextType::Block);
- }
- if node_facts::has_flag(data, NodeFlag::ChildrenAreInline)
- || display.is_some_and(|display| {
- display.is_table_column()
- || display.is_table_column_group()
- || display.is_table_row()
- || display.is_table_row_group()
- || display.is_table_header_group()
- || display.is_table_footer_group()
- })
- {
- return None;
- }
- if !display.is_some_and(|display| display.is_flow_inside()) {
- return Some(FormattingContextType::InternalDummy);
- }
- None
+ )
+ .then_some(FormattingContextType::Block)
}
pub(crate) fn formatting_context_type_created_by_box(facts: NodeFacts<'_>) -> Option<FormattingContextType> {
@@ -1429,7 +1410,6 @@ fn create_formatting_context_implementation<'pass>(
}
FormattingContextType::ReplacedWithChildren => FormattingContextImplementation::ReplacedWithChildren,
FormattingContextType::InternalReplaced => FormattingContextImplementation::InternalReplaced,
- FormattingContextType::InternalDummy => FormattingContextImplementation::InternalDummy,
}
}
@@ -2237,8 +2217,7 @@ fn execute_formatting_context_run(
FormattingContextImplementation::ReplacedWithChildren => {
replaced_with_children_formatting_context::layout_replaced_with_children(body_run, body_input)
}
- FormattingContextImplementation::InternalReplaced
- | FormattingContextImplementation::InternalDummy => ChildLayoutResult::default(),
+ FormattingContextImplementation::InternalReplaced => ChildLayoutResult::default(),
};
implementation = Some(context_implementation);
result
@@ -2374,8 +2353,7 @@ fn execute_formatting_context_run(
}
FormattingContextImplementation::Svg(_) | FormattingContextImplementation::ReplacedWithChildren => {
}
- FormattingContextImplementation::InternalReplaced
- | FormattingContextImplementation::InternalDummy => {
+ FormattingContextImplementation::InternalReplaced => {
return run.outputs(
result,
take_run_fragments(),
@@ -3094,15 +3072,11 @@ pub(super) fn independent_formatting_context_type(box_: Node, callbacks: &Layout
if let Some(fc_type) = formatting_context_type_created_by_box(facts) {
return fc_type;
}
- if facts.is_block_container() {
- return FormattingContextType::Block;
- }
-
- // HACK: Instead of crashing in scenarios that assume the formatting context can be created, create a dummy formatting context that does nothing.
- eprintln!(
- "FIXME: An independent formatting context was requested from a Box that does not have a formatting context type. A dummy formatting context will be created instead."
+ assert!(
+ facts.is_block_container(),
+ "a box that creates no formatting context must be a block container to be laid out in one"
);
- FormattingContextType::InternalDummy
+ FormattingContextType::Block
}
pub(crate) fn resolve_block_axis_percentage_inset_basis_is_definite(
diff --git a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs
index b07d2e799b5..e982a517cbb 100644
--- a/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs
+++ b/Libraries/LibWeb/Rust/src/layout/intrinsic_sizing.rs
@@ -665,8 +665,7 @@ pub(super) fn content_sizes_of_replaced_content(
}
let size = match formatting_context::independent_formatting_context_type(node, &callbacks) {
formatting_context::FormattingContextType::Svg
- | formatting_context::FormattingContextType::InternalReplaced
- | formatting_context::FormattingContextType::InternalDummy => CssPixels::default(),
+ | formatting_context::FormattingContextType::InternalReplaced => CssPixels::default(),
formatting_context::FormattingContextType::ReplacedWithChildren => scope.root().content_inline_size.get(),
_ => return None,
};
diff --git a/Libraries/LibWeb/Rust/src/layout/node_facts.rs b/Libraries/LibWeb/Rust/src/layout/node_facts.rs
index 893776bee0c..d7facdc6888 100644
--- a/Libraries/LibWeb/Rust/src/layout/node_facts.rs
+++ b/Libraries/LibWeb/Rust/src/layout/node_facts.rs
@@ -456,6 +456,7 @@ pub(crate) fn node_creates_block_formatting_context(
if display.is_table_inside() || display.is_flex_inside() || display.is_grid_inside() {
return false;
}
+ let inside_is_laid_out_as_flow = display.is_flow_inside() || display.is_ruby_inside();
if (style.is_floating() && !has_flag(data, NodeFlag::IsFlexItem))
|| style.own_style_establishes_block_formatting_context()
{
@@ -465,7 +466,7 @@ pub(crate) fn node_creates_block_formatting_context(
// If a box has a different 'writing-mode' value than its parent box (i.e. nearest ancestor without
// 'display: contents'):
// - If the box is a block container, then it establishes an independent block formatting context.
- if display.is_flow_inside()
+ if inside_is_laid_out_as_flow
&& !display.is_inline_outside()
&& parent_writing_mode().is_some_and(|writing_mode| writing_mode != style.writing_mode())
{
@@ -475,7 +476,7 @@ pub(crate) fn node_creates_block_formatting_context(
// inline establishes an independent formatting context: the boxes inside it belong to a context it establishes
// rather than to the one its line is part of.
if display.is_inline_outside()
- && display.is_flow_inside()
+ && inside_is_laid_out_as_flow
&& node_forms_containing_block_for_children(data, Some(style))
{
return true;
diff --git a/Libraries/LibWeb/Rust/src/layout/trace.rs b/Libraries/LibWeb/Rust/src/layout/trace.rs
index af491d4c760..4f64fe2b812 100644
--- a/Libraries/LibWeb/Rust/src/layout/trace.rs
+++ b/Libraries/LibWeb/Rust/src/layout/trace.rs
@@ -196,7 +196,6 @@ impl LayoutTrace {
FormattingContextType::Math => "math",
FormattingContextType::ReplacedWithChildren => "replaced-with-children",
FormattingContextType::InternalReplaced => "internal-replaced",
- FormattingContextType::InternalDummy => "internal-dummy",
};
format!("/{context} {}", action())
})
diff --git a/Tests/LibWeb/Text/expected/ruby-display-boxes-lay-out-like-flow-boxes.txt b/Tests/LibWeb/Text/expected/ruby-display-boxes-lay-out-like-flow-boxes.txt
new file mode 100644
index 00000000000..8365560cc27
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/ruby-display-boxes-lay-out-like-flow-boxes.txt
@@ -0,0 +1,6 @@
+block-ruby: 300x40 at 0,0, child 50x20 at 0,0, same as its flow twin
+vertical-block-ruby: 70x100 at 0,0, child 50x20 at 20,0, same as its flow twin
+inline-ruby-legend-with-block-child: 50x20 at 0,0, child 50x20 at 0,0, same as its flow twin
+inline-ruby-legend-with-text: 40.1875x20 at 0,0, same as its flow twin
+ruby-text-legend: 300x40 at 0,0, child 50x20 at 0,0, same as its flow twin
+inline-ruby-input: 242x22 at 0,0, same as its flow twin
diff --git a/Tests/LibWeb/Text/expected/width-queries-of-remaining-horizontal-boxes-skip-layout.txt b/Tests/LibWeb/Text/expected/width-queries-of-remaining-horizontal-boxes-skip-layout.txt
index b666583814c..97b0dbb1bc1 100644
--- a/Tests/LibWeb/Text/expected/width-queries-of-remaining-horizontal-boxes-skip-layout.txt
+++ b/Tests/LibWeb/Text/expected/width-queries-of-remaining-horizontal-boxes-skip-layout.txt
@@ -9,4 +9,4 @@ grid-limited-to-min-content-in-fixed-width-box: 1 inline misses answered from gr
grid-limited-to-max-content-in-fixed-width-box: 1 inline misses answered from grid tracks, 0 runs under them, width 150
svg-without-natural-size: 1 inline misses answered from replaced content, 0 runs under them, width 200
contained-with-ratio: 0 inline misses answered from nothing, 0 runs under them, width 50
-block-ruby: 1 inline misses answered from replaced content, 0 runs under them, width 0
+block-ruby: 1 inline misses answered from children, 0 runs under them, width 50
diff --git a/Tests/LibWeb/Text/input/ruby-display-boxes-lay-out-like-flow-boxes.html b/Tests/LibWeb/Text/input/ruby-display-boxes-lay-out-like-flow-boxes.html
new file mode 100644
index 00000000000..59e88f7e75a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/ruby-display-boxes-lay-out-like-flow-boxes.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ body { margin: 0; font: 20px/20px SerenitySans; }
+ .case { width: 300px; height: 120px; }
+ .block { width: 50px; height: 20px; }
+ .vertical { writing-mode: vertical-rl; height: 100px; }
+ legend, input { margin: 0; padding: 0; }
+</style>
+<div class="case"><div id="block-ruby" style="display: block ruby"><div class="block"></div>text</div></div>
+<div class="case"><div id="block-ruby-flow-twin" style="display: block"><div class="block"></div>text</div></div>
+<div class="case"><div id="vertical-block-ruby" class="vertical" style="display: block ruby"><div class="block"></div>text</div></div>
+<div class="case"><div id="vertical-block-ruby-flow-twin" class="vertical" style="display: block"><div class="block"></div>text</div></div>
+<div class="case"><legend id="inline-ruby-legend-with-block-child" style="display: ruby"><div class="block"></div></legend></div>
+<div class="case"><legend id="inline-ruby-legend-with-block-child-flow-twin" style="display: inline"><div class="block"></div></legend></div>
+<div class="case"><legend id="inline-ruby-legend-with-text" style="display: ruby">text</legend></div>
+<div class="case"><legend id="inline-ruby-legend-with-text-flow-twin" style="display: inline">text</legend></div>
+<div class="case"><legend id="ruby-text-legend" style="display: ruby-text"><div class="block"></div>text</legend></div>
+<div class="case"><legend id="ruby-text-legend-flow-twin" style="display: block"><div class="block"></div>text</legend></div>
+<div class="case"><input id="inline-ruby-input" style="display: ruby" value="text"></div>
+<div class="case"><input id="inline-ruby-input-flow-twin" style="display: inline" value="text"></div>
+<script>
+ test(() => {
+ const geometry = id => {
+ const box = document.getElementById(id);
+ const boxRect = box.getBoundingClientRect();
+ const caseRect = box.parentElement.getBoundingClientRect();
+ const parts = [`${boxRect.width}x${boxRect.height} at ${boxRect.left - caseRect.left},${boxRect.top - caseRect.top}`];
+ const child = box.querySelector(".block");
+ if (child) {
+ const childRect = child.getBoundingClientRect();
+ parts.push(`child ${childRect.width}x${childRect.height} at ${childRect.left - boxRect.left},${childRect.top - boxRect.top}`);
+ }
+ return parts.join(", ");
+ };
+ for (const id of [
+ "block-ruby",
+ "vertical-block-ruby",
+ "inline-ruby-legend-with-block-child",
+ "inline-ruby-legend-with-text",
+ "ruby-text-legend",
+ "inline-ruby-input",
+ ]) {
+ const ruby = geometry(id);
+ const flow = geometry(`${id}-flow-twin`);
+ println(`${id}: ${ruby}${ruby === flow ? ", same as its flow twin" : `, flow twin: ${flow}`}`);
+ }
+ });
+</script>