Skip to content

Truly independent web browser

LibWeb: Size the document element's svg at the layout entry

Aliaksandr Kalenika8d810e23dd0
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index 65c0aca6714..d476b75b578 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -297,7 +297,6 @@ fn sizing_directives_match_ignoring_unobserved(
treat_block_axis_percentage_insets_as_auto_beyond_root,
math_stretch_size_constraint,
root_is_measured_for_its_content_block_size,
- root_keeps_its_committed_geometry,
} = *a;
forced_content_block_size == b.forced_content_block_size
&& forced_min_border_box_block_size == b.forced_min_border_box_block_size
@@ -312,7 +311,6 @@ fn sizing_directives_match_ignoring_unobserved(
== b.treat_block_axis_percentage_insets_as_auto_beyond_root
&& math_stretch_size_constraint == b.math_stretch_size_constraint
&& root_is_measured_for_its_content_block_size == b.root_is_measured_for_its_content_block_size
- && root_keeps_its_committed_geometry == b.root_keeps_its_committed_geometry
&& match (
flex_self_block_size_resolution_space,
b.flex_self_block_size_resolution_space,
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index e4433898da4..9597bcebd8b 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -2207,13 +2207,6 @@ fn execute_formatting_context_run(
)
},
);
- if input.sizing.root_keeps_its_committed_geometry {
- assert_eq!(
- sizes_and_box_sides(root_cells_left_by_run),
- sizes_and_box_sides(root_cells),
- "the run of {box_:?} changed the committed geometry of its root"
- );
- }
if checks_root_input_cells_its_parent_owns {
let mut root_input_cells_the_run_must_leave = root_cells;
if fc_type.lays_out_inside_its_root_as_definite_in_both_axes() {
@@ -2774,7 +2767,6 @@ fn body_input_in_own_frame(
treat_block_axis_percentage_insets_as_auto_beyond_root: input
.sizing
.treat_block_axis_percentage_insets_as_auto_beyond_root,
- root_keeps_its_committed_geometry: input.sizing.root_keeps_its_committed_geometry,
..RootSizingDirectives::default()
};
std::mem::swap(
@@ -3720,6 +3712,13 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
root_cells.set_content_inline_size(viewport_inline_size);
root_cells.set_content_block_size(viewport_block_size);
root_cells.has_definite_block_size = true;
+ if root_for_layout != root {
+ svg_formatting_context::size_document_element_svg_from_its_width_and_height(
+ &callbacks,
+ root_for_layout,
+ &mut root_cells,
+ );
+ }
let input = LayoutInput::new(
AvailableSpace {
inline_size: AvailableSize::definite(viewport_inline_size),
@@ -3872,7 +3871,7 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
.expect("partial relayout root must have committed geometry");
let root_cells = committed_root.cells;
let fragments = run.fragments.expect("partial relayout must build fragments");
- let mut input = LayoutInput::new(
+ let input = LayoutInput::new(
AvailableSpace {
inline_size: AvailableSize::definite(root_cells.content_inline_size),
block_size: AvailableSize::definite(root_cells.content_block_size),
@@ -3882,7 +3881,6 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
ContainingBlockConstraints::default(),
ParticipationInParentFormattingContext::Root,
);
- input.sizing.root_keeps_its_committed_geometry = true;
let facts = NodeFacts::new(callbacks, root);
debug_assert!(facts.is_svg_svg_box());
@@ -3905,6 +3903,11 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
fragment_arrival,
..
} = root_outcome;
+ assert_eq!(
+ sizes_and_box_sides(root_box.cells),
+ sizes_and_box_sides(root_cells),
+ "the run of {root:?} changed the committed geometry of its root"
+ );
let root_geometry = fragment_tree::FragmentGeometry {
cells: root_box.cells,
line_data: root_box.line_data,
diff --git a/Libraries/LibWeb/Rust/src/layout/geometry.rs b/Libraries/LibWeb/Rust/src/layout/geometry.rs
index 9a5e226fe15..a764817d735 100644
--- a/Libraries/LibWeb/Rust/src/layout/geometry.rs
+++ b/Libraries/LibWeb/Rust/src/layout/geometry.rs
@@ -378,9 +378,6 @@ pub(crate) struct RootSizingDirectives {
// Input-only: MathML layout lays out an embellished operator with the size its core operator should stretch to
// cover.
pub(crate) math_stretch_size_constraint: Option<MathStretchSizeConstraint>,
- // Input-only: a partial relayout lays out the contents of its root inside the geometry the root committed, which
- // the run keeps as it is.
- pub(crate) root_keeps_its_committed_geometry: bool,
}
/// The size that MathML layout asks the core operator of an embellished operator to stretch to cover.
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index 49504bacf74..5082622439a 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -1952,23 +1952,6 @@ impl<'pass> SvgFormattingContext<'pass> {
let attributes = self.svg_attributes(self.run.box_);
self.commit_svg_element_facts(self.run.box_, facts, attributes);
- if facts.is_document_element
- && !facts.document_is_decoded_svg
- && !input.sizing.root_keeps_its_committed_geometry
- {
- // Overwrite the content width/height with the styled node width/height (from <svg width height ...>)
- //
- // NOTE: If a height had not been provided by the svg element, it was set to the height of the container
- let style = self.style(self.run.box_);
- if style.width().is_length() {
- cells.set_content_inline_size(style.width().to_px(CssPixels::default()));
- }
- if style.height().is_length() {
- cells.set_content_block_size(style.height().to_px(CssPixels::default()));
- }
- // FIXME: In SVG 2, length can also be a percentage. We'll need to support that.
- }
-
// NOTE: We consider all SVG root elements to have definite size in both axes.
// I'm not sure if this is good or bad, but our viewport transform logic depends on it.
cells.update_cells(|cells| {
@@ -2619,6 +2602,30 @@ pub(crate) fn svg_root_natural_size(
)
}
+/// Overwrites the content size of the document element's `<svg>`, which the layout entry sized as the viewport in
+/// `cells`, with its styled width and height (from <svg width height ...>) where they are lengths. A decoded SVG image
+/// keeps the size of the viewport it is drawn into.
+pub(crate) fn size_document_element_svg_from_its_width_and_height(
+ callbacks: &LayoutPass<'_>,
+ svg: Node,
+ cells: &mut used_values::RootInputCells,
+) {
+ if !node_facts::has_flag(callbacks.node_data(svg), NodeFlag::IsDocumentElement)
+ || callbacks.arena().document_is_decoded_svg()
+ {
+ return;
+ }
+ // NOTE: If a height had not been provided by the svg element, it was set to the height of the container
+ let style = StyleValues::for_node(callbacks, svg);
+ if style.width().is_length() {
+ cells.set_content_inline_size(style.width().to_px(CssPixels::default()));
+ }
+ if style.height().is_length() {
+ cells.set_content_block_size(style.height().to_px(CssPixels::default()));
+ }
+ // FIXME: In SVG 2, length can also be a percentage. We'll need to support that.
+}
+
/// The intrinsic aspect ratio must be calculated using the following algorithm. If the algorithm returns null, then
/// there is no intrinsic aspect ratio.
fn svg_root_natural_aspect_ratio(