Truly independent web browser
LibWeb: Resolve SVG container lengths from the style engine in layout
Aliaksandr Kalenik031fd43caa59
diff --git a/Libraries/LibWeb/CSS/Length.cpp b/Libraries/LibWeb/CSS/Length.cppindex 3f7bc4078ba..80729983a1a 100644--- a/Libraries/LibWeb/CSS/Length.cpp+++ b/Libraries/LibWeb/CSS/Length.cpp@@ -153,27 +153,20 @@ double Length::container_relative_length_to_px_without_rounding(ResolutionContex}auto& subject = *context.subject_element;- auto* deferred_marks = context.deferred_container_query_marks();- if (!deferred_marks)- const_cast<DOM::Element&>(subject).set_style_depends_on_size_container_query();+ const_cast<DOM::Element&>(subject).set_style_depends_on_size_container_query();auto query_container = get_or_compute_query_container_for_axis(context, physical_axis);// A container unit asks about the container's box exactly as a size query does, so the// container has to know that a resize of it is a change for something under it.- if (query_container) {- if (deferred_marks)- (physical_axis == ContainerRelativeAxis::Width ? deferred_marks->width_query_container : deferred_marks->height_query_container) = query_container;- else- const_cast<DOM::Element&>(*query_container).set_is_size_query_container();- }+ if (query_container)+ const_cast<DOM::Element&>(*query_container).set_is_size_query_container();if (!query_container) {context.record_viewport_relative_length_resolution();auto viewport_length = physical_axis == ContainerRelativeAxis::Width ? context.viewport_rect.width() : context.viewport_rect.height();return viewport_length.to_double();}- // The container's box is read without making its layout node: a layout round asks this on the render owner,- // which must not allocate one.+ // The container's box is read from the committed layout, without making its layout node.auto const* arena = query_container->document().layout_node_arena_if_created();Layout::ForcedReadScope read { query_container->document() };CSSPixelSize container_size;@@ -181,12 +174,8 @@ double Length::container_relative_length_to_px_without_rounding(ResolutionContex// A running partial relayout pass reports layout as up to date, but a container// with no paintable yet still needs the post-layout evaluation, which routes the// follow-up pass to the full layout path that resolves the container's size.- if (!subject.document().layout_is_up_to_date() || subject.document().is_running_update_layout()) {- if (deferred_marks)- (physical_axis == ContainerRelativeAxis::Width ? deferred_marks->width_query_container_awaits_layout : deferred_marks->height_query_container_awaits_layout) = true;- else- const_cast<DOM::Document&>(subject.document()).set_needs_container_query_evaluation_after_layout(*query_container);- }+ if (!subject.document().layout_is_up_to_date() || subject.document().is_running_update_layout())+ const_cast<DOM::Document&>(subject.document()).set_needs_container_query_evaluation_after_layout(*query_container);return 0.0;}diff --git a/Libraries/LibWeb/CSS/Length.h b/Libraries/LibWeb/CSS/Length.hindex b7eaaf51cdf..ef98fc40b52 100644--- a/Libraries/LibWeb/CSS/Length.h+++ b/Libraries/LibWeb/CSS/Length.h@@ -58,15 +58,6 @@ public:LengthUnit unit() const { return m_unit; }Utf16FlyString unit_name() const { return CSS::to_string(m_unit); }- // What resolving container-relative lengths would mark on the DOM, kept for a caller that must not write there- // while it resolves them, as a layout pass must not.- struct DeferredContainerQueryMarks {- GC::Ptr<DOM::Element const> width_query_container;- GC::Ptr<DOM::Element const> height_query_container;- bool width_query_container_awaits_layout { false };- bool height_query_container_awaits_layout { false };- };-struct ResolutionContext {[[nodiscard]] static ResolutionContext for_document(DOM::Document const&);[[nodiscard]] static ResolutionContext for_element(DOM::AbstractElement const&);@@ -94,16 +85,6 @@ public:return m_did_resolve_viewport_relative_length;}- void defer_container_query_marks(DeferredContainerQueryMarks& marks) const- {- m_deferred_container_query_marks = &marks;- }-- [[nodiscard]] DeferredContainerQueryMarks* deferred_container_query_marks() const- {- return m_deferred_container_query_marks;- }-void record_viewport_relative_length_resolution() const{if (m_did_resolve_viewport_relative_length)@@ -153,7 +134,6 @@ public:void visit_edges(GC::Cell::Visitor&) const;mutable bool* m_did_resolve_viewport_relative_length { nullptr };- mutable DeferredContainerQueryMarks* m_deferred_container_query_marks { nullptr };};[[nodiscard]] CSSPixels to_px(ResolutionContext const&) const;diff --git a/Libraries/LibWeb/Layout/LayoutRustBridge.cpp b/Libraries/LibWeb/Layout/LayoutRustBridge.cppindex 76c2d7cc362..ca824df1011 100644--- a/Libraries/LibWeb/Layout/LayoutRustBridge.cpp+++ b/Libraries/LibWeb/Layout/LayoutRustBridge.cpp@@ -569,28 +569,6 @@ void register_layout_host(NodeArena& arena, DOM::Document& document)commit_messages.append(*read, messages[index]);// The pass that produced them reads back what they change before it ends.commit_messages.apply(*read); },- .container_length_bases = [](void* document_pointer, u32 style_node) -> RustFFI::FfiContainerLengthBases {- auto& document = *static_cast<DOM::Document*>(document_pointer);- auto element = document.style_computer().element_for_style_node(style_node);- VERIFY(element);- auto context = CSS::Length::ResolutionContext::for_element(DOM::AbstractElement { *element });- // Layout writes nothing on the DOM side: the marks these lengths make reach the document as commit- // messages, once the layout that resolved them is committed.- CSS::Length::DeferredContainerQueryMarks marks;- context.defer_container_query_marks(marks);- auto width = CSS::Length(100, CSS::LengthUnit::Cqw).to_px_without_rounding(context);- auto height = CSS::Length(100, CSS::LengthUnit::Cqh).to_px_without_rounding(context);- auto style_node_of = [](GC::Ptr<DOM::Element const> container) -> u32 {- return container ? container->style_node_id().value() : 0;- };- return {- .width = width,- .height = height,- .width_query_container = style_node_of(marks.width_query_container),- .height_query_container = style_node_of(marks.height_query_container),- .width_query_container_awaits_layout = marks.width_query_container_awaits_layout,- .height_query_container_awaits_layout = marks.height_query_container_awaits_layout,- }; },.take_built_scroll_containers = [](void* context, BegunRead const* read, RustFFI::FfiBuiltScrollContainer const* built, size_t count) {auto& document = *static_cast<DOM::Document*>(context);for (auto const& scroll_container : ReadonlySpan<RustFFI::FfiBuiltScrollContainer> { built, count })diff --git a/Libraries/LibWeb/Rust/src/css/style/container_queries.rs b/Libraries/LibWeb/Rust/src/css/style/container_queries.rsindex e4f5939000f..e7a0cb91af0 100644--- a/Libraries/LibWeb/Rust/src/css/style/container_queries.rs+++ b/Libraries/LibWeb/Rust/src/css/style/container_queries.rs@@ -69,21 +69,38 @@ impl ContainerVerdict {/// nearest flat-tree ancestor that accepts size queries on that axis as of the last layout commit,/// zero while that container has no box, and the viewport's size when there is no such container.#[derive(Clone, Copy)]-pub(super) struct ContainerUnitBasis {+pub(crate) struct ContainerUnitBasis {basis: f64,/// The container the basis is read from, or none for the viewport.container: Option<StyleNodeID>,container_has_no_box: bool,}+impl ContainerUnitBasis {+ /// The container the basis is read from, or none for the viewport.+ pub(crate) fn container(&self) -> Option<StyleNodeID> {+ self.container+ }++ /// Whether the container has no box as of the last layout commit, so its queries are evaluated again after the+ /// next layout gives it one.+ pub(crate) fn container_has_no_box(&self) -> bool {+ self.container_has_no_box+ }+}+/// The bases of both physical axes, width and height.#[derive(Clone, Copy)]-pub(super) struct ContainerUnitBases([ContainerUnitBasis; 2]);+pub(crate) struct ContainerUnitBases([ContainerUnitBasis; 2]);impl ContainerUnitBases {+ pub(crate) fn width_and_height(&self) -> [ContainerUnitBasis; 2] {+ self.0+ }+/// Resolve a context's container-relative lengths against these bases; one read from the/// viewport is a viewport dependency.- pub(super) fn apply_to(&self, length: &mut crate::css::style_compute::FfiLengthResolutionContext) {+ pub(crate) fn apply_to(&self, length: &mut crate::css::style_compute::FfiLengthResolutionContext) {let [width, height] = self.0;length.has_container_width_basis = true;length.has_container_height_basis = true;@@ -262,7 +279,7 @@ impl RetainedState {}/// The bases of both physical axes for a subject's container-relative lengths.- pub(super) fn container_unit_bases(+ pub(crate) fn container_unit_bases(&self,subject: StyleNodeID,subject_is_pseudo_element: bool,diff --git a/Libraries/LibWeb/Rust/src/css/style/mod.rs b/Libraries/LibWeb/Rust/src/css/style/mod.rsindex 7253892978c..336f04a3309 100644--- a/Libraries/LibWeb/Rust/src/css/style/mod.rs+++ b/Libraries/LibWeb/Rust/src/css/style/mod.rs@@ -75,6 +75,7 @@ mod column;pub mod compiler;mod computed;mod container_queries;+pub(crate) use container_queries::ContainerUnitBases;mod custom_property_cascade;mod custom_property_environments;#[cfg(test)]diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rsindex ae0084ca107..5136c488cd1 100644--- a/Libraries/LibWeb/Rust/src/layout/commit.rs+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs@@ -88,6 +88,14 @@ impl CommitNotifications {.filter_map(|message| StyleNodeID::from_raw(message.style_node))}+ /// Whether a length the committed layout resolved reads a size container that had no box, whose queries the host+ /// evaluates once a layout gives it one.+ pub(crate) fn awaits_container_query_evaluation(&self) -> bool {+ self.messages+ .iter()+ .any(|message| message.kind == FfiCommitMessageKind::ContainerQueryEvaluationNeededAfterLayout)+ }+/// Tells the host of the resets and messages of the commit, which it answers synchronously, while no mutable arena/// borrow is active.pub(crate) fn notify_host(diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex e01d71a570e..e6e1f569e4a 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -1220,7 +1220,7 @@ pub(crate) struct FlexLayoutData {pub(crate) lines: Vec<FlexLayoutLine>,}-/// The document-side answers every layout pass needs, registered once per arena. Each callback+/// The calls the layout stage makes into the document, registered once per arena. Each callback/// receives the registered `context`, the owning document, as its first argument. The fields are/// private: the callbacks are reached only through the methods below, which take the main thread/// token.@@ -1235,8 +1235,6 @@ pub struct FfiLayoutHostCallbacks {/// them.deliver_commit_messages:extern "C" fn(*mut c_void, &crate::render_state::BegunRead, *const commit::FfiCommitMessage, usize),- /// What a container-relative length on the element with the given identity resolves against.- container_length_bases: extern "C" fn(*mut c_void, u32) -> svg_formatting_context::FfiContainerLengthBases,/// The scroll containers a finished layout tree build gave a style, each with whether it is a/// scroll snap container.take_built_scroll_containers:@@ -1288,14 +1286,6 @@ impl FfiLayoutHostCallbacks {// The document registered the host with the arena and outlives this call.(self.take_built_scroll_containers)(self.context, read, built.as_ptr(), built.len());}-- /// The one question a layout pass may ask the document while it runs.- pub(crate) fn container_length_bases_query(- &self,- _: &crate::stage::MainThread,- ) -> layout_pass::ContainerLengthBasesQuery {- layout_pass::ContainerLengthBasesQuery::new(self.context, self.container_length_bases)- }}/// # Safety@@ -3456,11 +3446,10 @@ pub(crate) fn lay_out_boundary(.run(state)}-/// What every layout stage of a round reads besides the arena: the one question a pass may ask-/// the document, and the document's viewport and quirks mode as the round began.+/// What every layout stage of a round reads besides the arena: the document's viewport and quirks+/// mode as the round began.#[derive(Clone, Copy)]pub(crate) struct LayoutStageFacts {- pub(crate) container_length_bases: layout_pass::ContainerLengthBasesQuery,pub(crate) viewport_inline_size: CssPixels,pub(crate) viewport_block_size: CssPixels,pub(crate) document_in_quirks_mode: bool,@@ -3517,7 +3506,6 @@ impl LayoutStageJob {};let mut notifications = commit::commit_replacing(root, state.arena_mut(), &output.fragments);let super::run_state::HostFindings {- nodes_with_unresolved_container_lengths,messages,document_svg_root_natural_size,} = output.host_findings;@@ -3528,9 +3516,6 @@ impl LayoutStageJob {}notifications.prepend_layout_messages(messages);let arena = state.arena();- for node in nodes_with_unresolved_container_lengths {- arena.note_unresolved_container_lengths(node);- }arena.end_layout_pass();state.layout_scratch().end_layout_pass();arena.reset_layout_update_flags_in_subtree(root);@@ -3839,13 +3824,6 @@ mod baseline_tests {use crate::layout::node_data::{NodeConstructionFacts, NodeKind, StylePayloadsRef};use crate::layout::run_state::LayoutScratch;- unsafe extern "C" fn unused_container_bases(- _: *mut c_void,- _: u32,- ) -> svg_formatting_context::FfiContainerLengthBases {- unreachable!("baseline derivation does not resolve container lengths")- }-#[test]fn block_derivation_preserves_flex_last_baseline() {check_block_derivation(keyword::FLEX);@@ -3895,11 +3873,6 @@ mod baseline_tests {&arena,&scratch,LayoutStageFacts {- container_length_bases: layout_pass::ContainerLengthBasesQuery::new(- std::ptr::null_mut(),- unused_container_bases,- )- .sealed(),viewport_inline_size: CssPixels::from_integer(800),viewport_block_size: CssPixels::from_integer(600),document_in_quirks_mode: false,diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex afeea2dae19..81c2255e556 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -1225,8 +1225,6 @@ pub(crate) struct LayoutNodeArena {/// Every box must be recreated by the next layout tree build; set when the tree is torn down/// or a build finds a box it cannot place among rebuilt roots, cleared by the full pass.needs_full_layout_tree_update: Cell<bool>,- /// The nodes whose container-relative lengths a pass that could not ask the host resolved without their container.- unresolved_container_lengths: RefCell<Vec<NodeSlotId>>,partial_layout_count: Cell<u64>,full_layout_count: Cell<u64>,/// How many layouts were committed, full and partial.@@ -1350,7 +1348,6 @@ impl LayoutNodeArena {pending_rebuilt_subtree_roots: RefCell::new(Vec::new()),pending_layout_tree_update_escaped_rebuild_roots: Cell::new(false),needs_full_layout_tree_update: Cell::new(false),- unresolved_container_lengths: RefCell::new(Vec::new()),partial_layout_count: Cell::new(0),full_layout_count: Cell::new(0),layout_commit_count: 0,@@ -3212,26 +3209,6 @@ impl LayoutNodeArena {self.needs_full_layout_tree_update.get()}- /// Notes that a pass that could not ask the host resolved a container-relative length of `node` without its- /// container.- pub(crate) fn note_unresolved_container_lengths(&self, node: NodeSlotId) {- let mut nodes = self.unresolved_container_lengths.borrow_mut();- if nodes.last() != Some(&node) {- nodes.push(node);- }- }-- /// Marks the nodes whose container-relative lengths a pass resolved without their container since this was asked- /// last for a layout update, ancestors included, so that the next layout lays them out again rather than reusing- /// what the pass laid out. Answers whether there were any.- pub(crate) fn mark_unresolved_container_lengths_for_layout(&self) -> bool {- let nodes = self.unresolved_container_lengths.take();- for &node in &nodes {- self.set_needs_layout_update(node, true);- }- !nodes.is_empty()- }-pub(crate) fn set_needs_full_layout_tree_update(&self, value: bool) {self.needs_full_layout_tree_update.set(value);}diff --git a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs b/Libraries/LibWeb/Rust/src/layout/layout_pass.rsindex ae0ea8b37c8..3aa57da60ce 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_pass.rs@@ -7,53 +7,6 @@use super::node_facts::ReplacedContentFacts;use super::*;-/// The one question a layout pass still asks the document while it runs: what the container-relative-/// lengths on an element resolve against. The answer reads the committed size of the element's query-/// container, so it cannot be published ahead of the pass, and it writes nothing in the document: the-/// dependencies it finds reach the document as commit messages. A pass holds this and no other part-/// of the host. Every other host call takes the main thread token, which a-/// pass is not handed, so a pass has no way to make any other call into the document.-#[derive(Clone, Copy)]-pub(crate) struct ContainerLengthBasesQuery {- context: *mut c_void,- /// The query, or none for a pass that runs beside the host and cannot ask it.- query: Option<unsafe extern "C" fn(*mut c_void, u32) -> svg_formatting_context::FfiContainerLengthBases>,-}--// SAFETY: A layout job calls the query while the host waits for the job's answer, so the document the C++ side reads-// changes under neither of them.-unsafe impl Send for ContainerLengthBasesQuery {}--impl ContainerLengthBasesQuery {- /// Only the layout host makes one, for a caller holding the main thread token.- pub(super) fn new(- context: *mut c_void,- query: unsafe extern "C" fn(*mut c_void, u32) -> svg_formatting_context::FfiContainerLengthBases,- ) -> Self {- Self {- context,- query: Some(query),- }- }-- /// The query for a pass that runs beside the host, which answers nothing.- pub(crate) fn sealed(self) -> Self {- Self {- context: std::ptr::null_mut(),- query: None,- }- }-- /// What `cqw` and `cqh` are 100 of for `element`, where the pass can ask the host.- pub(crate) fn bases(- self,- element: crate::css::style::tree::StyleNodeID,- ) -> Option<svg_formatting_context::FfiContainerLengthBases> {- // SAFETY: The document registered the query with the arena and outlives the pass, which the host waits for.- self.query.map(|query| unsafe { query(self.context, element.raw()) })- }-}-/// Arena inputs borrowed while computing a layout result. The pass ends before commit takes a/// mutable arena borrow, so its text and style views cannot survive commit.///@@ -61,11 +14,13 @@ impl ContainerLengthBasesQuery {/// its layout input, its root's used values and its run state, or was derived onto the subtree/// before the pass, like ancestor facts. That is what lets partial relayout, the formatting context/// run cache and the intrinsic size caches reuse a subtree's layout without looking outside it.+///+/// A pass holds no part of the host. Every host call takes the main thread token, which a pass is+/// not handed, so a pass has no way to call into the document.#[derive(Clone, Copy)]pub(crate) struct LayoutPass<'arena> {arena: &'arena LayoutNodeArena,scratch: &'arena super::run_state::LayoutScratch,- pub(crate) container_length_bases: ContainerLengthBasesQuery,pub(crate) initial_containing_block_inline_size: CssPixels,pub(crate) initial_containing_block_block_size: CssPixels,pub(crate) document_in_quirks_mode: bool,@@ -85,7 +40,6 @@ impl<'arena> LayoutPass<'arena> {Self {arena,scratch,- container_length_bases: stage.container_length_bases,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,@@ -94,17 +48,13 @@ impl<'arena> LayoutPass<'arena> {}}- /// A pass whose only question to the document has no answer, over `arena` and `scratch`.+ /// A pass over `arena` and `scratch` with no viewport, in no-quirks mode.#[cfg(test)]pub(crate) fn for_test(arena: &'arena LayoutNodeArena, scratch: &'arena super::run_state::LayoutScratch) -> Self {Self::new(arena,scratch,super::formatting_context::LayoutStageFacts {- container_length_bases: ContainerLengthBasesQuery {- context: std::ptr::null_mut(),- query: None,- },viewport_inline_size: CssPixels::default(),viewport_block_size: CssPixels::default(),document_in_quirks_mode: false,diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rsindex 1513ac3bc2d..b3ad86f1639 100644--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs@@ -1159,21 +1159,4 @@ mod tests {assert_eq!(arena.take_partial_relayout_boundary_roots(), vec![child.slot]);free_node(&mut arena, &parent);}-- #[test]- fn a_length_resolved_without_its_container_marks_its_node_and_ancestors_for_layout_once() {- let mut arena = LayoutNodeArena::new();- let parent = allocate_box_with_a_dummy_shell(&mut arena);- let child = allocate_box_with_a_dummy_shell(&mut arena);- arena.insert_child(parent.slot, child.slot, NodeSlotId::INVALID);-- arena.note_unresolved_container_lengths(child.slot);- arena.note_unresolved_container_lengths(child.slot);-- assert!(arena.mark_unresolved_container_lengths_for_layout());- assert!(node_is_dirty(&arena, &child));- assert!(node_is_dirty(&arena, &parent));- assert!(!arena.mark_unresolved_container_lengths_for_layout());- free_node(&mut arena, &parent);- }}diff --git a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rsindex 59b2eef247b..01c6a90de3f 100644--- a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs@@ -278,10 +278,7 @@ fn host_findings_match(left: Option<&run_state::HostFindings>, right: Option<&rulet none = run_state::HostFindings::default();let left = left.unwrap_or(&none);let right = right.unwrap_or(&none);- same_elements_in_any_order(- &left.nodes_with_unresolved_container_lengths,- &right.nodes_with_unresolved_container_lengths,- ) && same_elements_in_any_order(&left.messages, &right.messages)+ same_elements_in_any_order(&left.messages, &right.messages)&& left.document_svg_root_natural_size == right.document_svg_root_natural_size}diff --git a/Libraries/LibWeb/Rust/src/layout/run_state.rs b/Libraries/LibWeb/Rust/src/layout/run_state.rsindex f132b37f0e7..8c82b75e1c9 100644--- a/Libraries/LibWeb/Rust/src/layout/run_state.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_state.rs@@ -29,54 +29,41 @@ pub(crate) struct LayoutScratch {discarded_runs_in_progress: Cell<u32>,}-/// What layout found out that the host hears of once the layout that found it is committed: the nodes whose SVG-/// lengths it resolved without the container they are relative to, what the container-relative lengths it resolved-/// depend on, and the natural size it negotiated for the box of an `<svg>` document element. A run hands them to its-/// parent with its result, so a discarded result tells the host nothing.+/// What layout found out that the host hears of once the layout that found it is committed: what the+/// container-relative lengths it resolved depend on, and the natural size it negotiated for the box of an `<svg>`+/// document element. A run hands them to its parent with its result, so a discarded result tells the host nothing.#[derive(Clone, Debug, Default, PartialEq)]pub(crate) struct HostFindings {- pub(crate) nodes_with_unresolved_container_lengths: Vec<NodeSlotId>,pub(crate) messages: Vec<super::commit::FfiCommitMessage>,pub(crate) document_svg_root_natural_size: Option<(NodeSlotId, crate::css::style::NaturalSize)>,}impl HostFindings {pub(crate) fn is_empty(&self) -> bool {- self.nodes_with_unresolved_container_lengths.is_empty()- && self.messages.is_empty()- && self.document_svg_root_natural_size.is_none()- }-- pub(crate) fn note_unresolved_container_lengths(&mut self, node: NodeSlotId) {- if !self.nodes_with_unresolved_container_lengths.contains(&node) {- self.nodes_with_unresolved_container_lengths.push(node);- }+ self.messages.is_empty() && self.document_svg_root_natural_size.is_none()}pub(crate) fn note_container_length_dependencies(&mut self,element: crate::css::style::tree::StyleNodeID,- bases: &super::svg_formatting_context::FfiContainerLengthBases,+ bases: &crate::css::style::ContainerUnitBases,) {use super::commit::{FfiCommitMessage, FfiCommitMessageKind};self.note_message(FfiCommitMessage::new(element.raw(),FfiCommitMessageKind::StyleDependsOnSizeContainerQuery,));- for (container, awaits_layout) in [- (bases.width_query_container, bases.width_query_container_awaits_layout),- (bases.height_query_container, bases.height_query_container_awaits_layout),- ] {- if container == 0 {+ for basis in bases.width_and_height() {+ let Some(container) = basis.container() else {continue;- }+ };self.note_message(FfiCommitMessage::new(- container,+ container.raw(),FfiCommitMessageKind::SizeQueryContainerResolvedAgainst,));- if awaits_layout {+ if basis.container_has_no_box() {self.note_message(FfiCommitMessage::new(- container,+ container.raw(),FfiCommitMessageKind::ContainerQueryEvaluationNeededAfterLayout,));}@@ -90,9 +77,6 @@ impl HostFindings {}pub(crate) fn receive(&mut self, other: HostFindings) {- for node in other.nodes_with_unresolved_container_lengths {- self.note_unresolved_container_lengths(node);- }for message in other.messages {self.note_message(message);}diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 6f8a49346d1..067a1592400 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -4295,13 +4295,6 @@ mod replaced_ratio_tests {use crate::layout::node_data::{NodeConstructionFacts, NodeKind, StylePayloadsRef};use crate::layout::run_state::LayoutScratch;- unsafe extern "C" fn unused_container_bases(- _: *mut c_void,- _: u32,- ) -> svg_formatting_context::FfiContainerLengthBases {- unreachable!("replaced ratio tests use absolute lengths")- }-fn size(width: Option<i64>,height: Option<i64>,@@ -4365,11 +4358,6 @@ mod replaced_ratio_tests {&arena,&scratch,LayoutStageFacts {- container_length_bases: layout_pass::ContainerLengthBasesQuery::new(- std::ptr::null_mut(),- unused_container_bases,- )- .sealed(),viewport_inline_size: CssPixels::from_integer(800),viewport_block_size: CssPixels::from_integer(600),document_in_quirks_mode: false,diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex 19d01206846..9d98d7cbf2c 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -166,22 +166,6 @@ pub struct FfiSvgLengthValue {pub unit: u8,}-/// The sizes a container-relative length on an element resolves against, as style answers them-/// for that element: per axis, the committed content box of its nearest size query container, or-/// the small viewport size. Style writes nothing while it answers: it says which containers the-/// lengths depend on, by style node or 0 for the viewport, and whether a container has no committed-/// box yet, so the document must evaluate its container queries after layout.-#[derive(Clone, Copy)]-#[repr(C)]-pub struct FfiContainerLengthBases {- pub width: f64,- pub height: f64,- pub width_query_container: u32,- pub height_query_container: u32,- pub width_query_container_awaits_layout: bool,- pub height_query_container_awaits_layout: bool,-}-pub const SVG_LENGTH_KIND_NONE: u8 = 0;pub const SVG_LENGTH_KIND_NUMBER: u8 = 1;pub const SVG_LENGTH_KIND_LENGTH: u8 = 2;@@ -2561,24 +2545,23 @@ fn length_resolution_context(let root_style = document_element_style(callbacks, node).unwrap_or(style);let viewport_width = callbacks.initial_containing_block_inline_size.to_double();let viewport_height = callbacks.initial_containing_block_block_size.to_double();- // A container unit resolves against the nearest size query container on its axis, or the small viewport size- // without one. Finding that container is style's business, so it is asked only for a length that needs it. A pass- // that cannot ask resolves it to zero, and leaves the node for the host to lay out again.- let container_bases = if crate::css::style_compute::length_unit_is_container_relative(unit) {+ // A container unit resolves against the committed content box of the nearest size query container on its axis, or+ // the viewport without one. Finding that container is style's business, so it is asked only for a length that+ // needs it, and the host hears which containers the lengths depend on once the layout is committed.+ let container_bases = crate::css::style_compute::length_unit_is_container_relative(unit).then(|| {let element = callbacks.arena().dom_node_style_node(node).expect("an SVG element's attribute length is resolved for the element's own box");- let bases = callbacks.container_length_bases.bases(element);- callbacks.scratch().note_host_findings(|findings| match &bases {- Some(bases) => findings.note_container_length_dependencies(element, bases),- None => findings.note_unresolved_container_lengths(node),- });+ let bases = callbacks+ .arena()+ .with_style_store(|engine| engine.container_unit_bases(element, false));+ callbacks+ .scratch()+ .note_host_findings(|findings| findings.note_container_length_dependencies(element, &bases));bases- } else {- None- };- crate::css::style_compute::FfiLengthResolutionContext {+ });+ let mut context = crate::css::style_compute::FfiLengthResolutionContext {viewport_width,viewport_height,font_metrics: font_metrics_for_length_resolution(style),@@ -2586,16 +2569,20 @@ fn length_resolution_context(// Only the out-flag below consumes these, and this resolution reports no dependency.font_metrics_depend_on_viewport_metrics: false,root_font_metrics_depend_on_viewport_metrics: false,- has_container_width_basis: container_bases.is_some(),- has_container_height_basis: container_bases.is_some(),- container_width_basis: container_bases.map_or(0.0, |bases| bases.width),- container_height_basis: container_bases.map_or(0.0, |bases| bases.height),+ has_container_width_basis: false,+ has_container_height_basis: false,+ container_width_basis: 0.0,+ container_height_basis: 0.0,container_width_basis_depends_on_viewport_metrics: false,container_height_basis_depends_on_viewport_metrics: false,subject_inline_axis_is_horizontal: style.writing_mode() == writing_mode::HORIZONTAL_TB,resolved_viewport_relative_length: std::ptr::null_mut(),zoom: 1.0,+ };+ if let Some(bases) = container_bases {+ bases.apply_to(&mut context);}+ context}/// The style of the document element, which a root-relative length resolves against.diff --git a/Libraries/LibWeb/Rust/src/layout/update_layout.rs b/Libraries/LibWeb/Rust/src/layout/update_layout.rsindex 1ae910f8457..c9af284d5ce 100644--- a/Libraries/LibWeb/Rust/src/layout/update_layout.rs+++ b/Libraries/LibWeb/Rust/src/layout/update_layout.rs@@ -498,7 +498,6 @@ pub(crate) struct LayoutRoundJob {/// Whether a size container waits for its queries to be evaluated after the next full layout, which only a round/// that may lay out partially reads.container_query_evaluation_is_pending: bool,- container_length_bases: super::layout_pass::ContainerLengthBasesQuery,}/// Which layout a round lays its tree out with.@@ -617,8 +616,7 @@ pub(crate) struct SealedRound {impl SealedRound {/// Runs the round over `state` in the frame's flight, where the frame's style left its layout to do, owing the host- /// `work` besides what the round owes it. The flight reaches nothing of the host, so a length only the host- /// resolves leaves the layout for the host to lay out again.+ /// `work` besides what the round owes it.pub(crate) fn run(self, state: &mut ArenaHandle, work: OwedHostWork) -> Option<FlownRound> {if state.arena()@@ -628,7 +626,6 @@ impl SealedRound {}let mut answer = self.job.run_owing(state, work);answer.prepare_committed_layout_for_rendering(state.arena());- state.arena().mark_unresolved_container_lengths_for_layout();Some(FlownRound {answer,rebuilds_tree: self.rebuilds_tree,@@ -650,17 +647,15 @@ impl FlownRound {}/// The layout round each tick of a clock lane runs once it has shown the samples of the document's animations: the-/// document's facts, and a container length query that answers nothing, sealed where the clock's plan was, at the end of-/// a rendering update that left the layout up to date.+/// document's facts, sealed where the clock's plan was, at the end of a rendering update that left the layout up to date.pub(crate) struct ClockRound {facts: FfiLayoutUpdateDocumentFacts,- container_length_bases: super::layout_pass::ContainerLengthBasesQuery,}impl ClockRound {/// Builds again what the clock frame marked and lays out what it moved, and pushes what the round owes the host to/// `owed`, answering it, or nothing where the round laid nothing out. A round declines a build that needs the host- /// and a length only the host resolves, after it owes the host what it ran.+ /// and a length whose container has no box yet, after it owes the host what it ran.pub(crate) fn run<'a>(&self,state: &mut ArenaHandle,@@ -675,7 +670,6 @@ impl ClockRound {build,layout: RoundLayout::PartialIfPlanned,container_query_evaluation_is_pending: false,- container_length_bases: self.container_length_bases,}.run(state);// A box the build gave an image has none until the host attaches it.@@ -686,13 +680,14 @@ impl ClockRound {Some("a build that needs the document's style")} else if answer.owed_images.iter().any(|image| image.is_shown(arena)) {Some("a box the build owes an image")+ } else if answer.awaits_container_query_evaluation() {+ // The host evaluates the queries of a container that had no box once a layout gave it one, and lays out+ // again what they decide.+ Some("a length whose container has no box yet")} else {None};owed.push(answer);- if state.arena().mark_unresolved_container_lengths_for_layout() {- return Err(ClockRoundDeclined("a length only the host resolves"));- }match declined {Some(reason) => Err(ClockRoundDeclined(reason)),None => Ok(owed.last()),@@ -770,7 +765,7 @@ impl ClockRound {}/// A clock round whose tree build or layout needs the host: a build that asks for another pass, reconciles list item-/// counters or owes the host image resources, or a length only the host resolves.+/// counters or owes the host image resources, or a length whose container has no box yet.pub(crate) struct ClockRoundDeclined(pub(crate) &'static str);/// Seals the round the ticks of a clock lane of `document_host`'s document run, where its layout is up to date in@@ -781,12 +776,7 @@ fn seal_clock_round(main_thread: &MainThread, document_host: &DocumentHost, readif !facts.document_is_active || !host_layout_is_up_to_date(document_host, read, &facts) {return None;}- Some(ClockRound {- facts,- container_length_bases: FfiLayoutHostCallbacks::of(main_thread)- .container_length_bases_query(main_thread)- .sealed(),- })+ Some(ClockRound { facts })}impl LayoutRoundJob {@@ -815,7 +805,6 @@ impl LayoutRoundJob {clamped_scroll_offsets: Vec::new(),};let stage = LayoutStageFacts {- container_length_bases: self.container_length_bases,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,@@ -947,6 +936,13 @@ impl LayoutRoundAnswer {.flat_map(CommitNotifications::resized_size_containers)}+ /// Whether a length the round's layout resolved reads a size container that had no box yet.+ pub(crate) fn awaits_container_query_evaluation(&self) -> bool {+ self.commits+ .iter()+ .any(CommitNotifications::awaits_container_query_evaluation)+ }+/// Prepares `arena` for rendering where the round committed a layout, as the host's commit of it asks, so that the/// host waits for no preparation of its own after the round.fn prepare_committed_layout_for_rendering(&mut self, arena: &LayoutNodeArena) {@@ -1012,7 +1008,6 @@ fn next_round(facts: FfiLayoutUpdateDocumentFacts,with_document_style: bool,) -> SealedRound {- let layout_host = FfiLayoutHostCallbacks::of(main_thread);let rebuilds_tree = facts.document_needs_layout_tree_build|| read_arena(document_host, read, (), |arena, ()| {arena.layout_root().is_invalid() || arena.needs_full_layout_tree_update()@@ -1031,7 +1026,6 @@ fn next_round(build,layout: RoundLayout::PartialIfPlanned,container_query_evaluation_is_pending: host.container_query_evaluation_is_pending(main_thread, read),- container_length_bases: layout_host.container_length_bases_query(main_thread),},rebuilds_tree,}@@ -1060,10 +1054,7 @@ fn sealed_first_round(if !facts.document_is_active || inputs.is_template_contents_document || !needs_round(&facts) {return None;}- let mut round = next_round(main_thread, document_host, read, &host, facts, false);- // The round runs beside the host, which it cannot ask.- round.job.container_length_bases = round.job.container_length_bases.sealed();- Some(round)+ Some(next_round(main_thread, document_host, read, &host, facts, false))}/// Seals the first round of a rendering update's layout of `document_host`'s document, which the frame the update lets@@ -1150,7 +1141,6 @@ fn update_layout(inputs: &FfiLayoutUpdateInputs,) {let host = layout_update_host(document_host);- let layout_host = FfiLayoutHostCallbacks::of(main_thread);assert!(document_host.host_tables().update_layout_running.get(),"the layout update runs between document_host_begin_update_layout and its end"@@ -1245,7 +1235,6 @@ fn update_layout(layout,container_query_evaluation_is_pending: layout == RoundLayout::PartialIfPlanned&& host.container_query_evaluation_is_pending(main_thread, read),- container_length_bases: layout_host.container_length_bases_query(main_thread),});};diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-svg-container-lengths.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-svg-container-lengths.txtnew file mode 100644index 00000000000..d7fad963c9c--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-tick-svg-container-lengths.txt@@ -0,0 +1,4 @@+lane as the task begins: ticking+lane after a tick: ticking+last frame presented by: clock+presented wrapper width: 150diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-svg-container-lengths.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-svg-container-lengths.htmlnew file mode 100644index 00000000000..25b5d081aab--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/clock-tick-svg-container-lengths.html@@ -0,0 +1,45 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script src="frame-in-flight.js"></script>+<style>+ @keyframes widen {+ from {+ width: 100px;+ }+ to {+ width: 200px;+ }+ }+ #wrapper.animated {+ animation: widen 10s linear;+ }+</style>+<div style="container-type: size; width: 300px; height: 100px">+ <div id="wrapper" style="width: 100px">+ <svg width="100%" height="100"><text x="50cqw" y="50">Label</text></svg>+ </div>+</div>+<script>+ // A tick of the render clock that resizes an SVG lays its text out again, and resolves the text's position in+ // container units against the container's committed box as the host does, so the lane goes on ticking.+ asyncTest(async done => {+ const result = await whileLaneAnimates(() => {+ wrapper.classList.add("animated");+ return wrapper.getAnimations()[0];+ }, (frameTime, animation, startTime) => {+ const before = internals.clockLaneState(document);+ internals.injectClockTick(startTime + 5000);+ return {+ before,+ after: internals.clockLaneState(document),+ presentedBy: internals.lastFramePresentedBy(document),+ presentedWidth: internals.presentedBorderBox(wrapper)?.width,+ };+ });+ println(`lane as the task begins: ${result.before}`);+ println(`lane after a tick: ${result.after}`);+ println(`last frame presented by: ${result.presentedBy}`);+ println(`presented wrapper width: ${result.presentedWidth}`);+ done();+ });+</script>