Truly independent web browser
LibWeb: Keep a run root's record in the frame it lays out in
Aliaksandr Kalenik65a3117e08b1
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 0b6d09c2699..3cdc1843b92 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -163,7 +163,7 @@ pub(crate) fn run_fragmentainer(.containing_block_for_child_run(box_, &input.participation);execute_formatting_context_run(builds_fragments,- used_values::RootInputCells::capture(outer.records.used_values(box_)),+ used_values::RecordInFrame::new(outer.records.used_values(box_), outer.callbacks.frame).cells(),box_,root_containing_block,None,@@ -2199,11 +2199,15 @@ fn execute_formatting_context_run(let parent_owns_root_input_cells = parent_owns_root_input_cells(&callbacks, box_, &input);let checks_root_input_cells_its_parent_owns =parent_owns_root_input_cells && (cfg!(debug_assertions) || run_repeatability::verification_is_enabled());+ // NB: The root's record holds its metrics in the frame the root lays its contents out in, for its whole life. The+ // root's own box is sized in its parent's frame, through views of the record.+ let own_frame = frame_established_by(&callbacks, box_);let (outputs, root_cells_left_by_run) = RunRecords::with_root(callbacks,box_,root_containing_block,- root_cells,+ root_cells.in_frame(callbacks.frame, own_frame),+ own_frame,|records, callbacks| {let outputs = lay_out_run_root_and_contents(records,@@ -2312,7 +2316,7 @@ fn lay_out_run_root_and_contents<'pass>();let body_input = if changes_frame {- enter_own_frame(run, body_run, &input, body_input, parent_frame, own_frame)+ body_input_in_own_frame(run, body_run, &input, body_input, parent_frame, own_frame)} else {body_input};@@ -2426,7 +2430,7 @@ fn lay_out_run_root_and_contents<'pass>(// NB: Intrinsic size overrides use the box's own writing mode, before its sizes are projected into the// parent's frame.if changes_frame {- result = leave_own_frame(run, body_run, result, parent_frame, own_frame);+ result = result_in_parent_frame(run, body_run, result, parent_frame, own_frame);}if containment_facts.has_preferred_aspect_ratio() {@@ -2519,20 +2523,11 @@ fn lay_out_run_root_and_contents<'pass>(match &implementation {FormattingContextImplementation::Block(_) => {}FormattingContextImplementation::Table(_) => {- let box_ = run.box_;- in_own_frame(run, parent_frame, own_frame, || {- register_table_abspos_descendants(body_run, box_);- });- }- FormattingContextImplementation::Flex(context) => {- in_own_frame(run, parent_frame, own_frame, || context.parent_did_dimension());- }- FormattingContextImplementation::Grid(context) => {- in_own_frame(run, parent_frame, own_frame, || context.parent_did_dimension());- }- FormattingContextImplementation::Math(context) => {- in_own_frame(run, parent_frame, own_frame, || context.parent_did_dimension());+ register_table_abspos_descendants(body_run, run.box_);}+ FormattingContextImplementation::Flex(context) => context.parent_did_dimension(),+ FormattingContextImplementation::Grid(context) => context.parent_did_dimension(),+ FormattingContextImplementation::Math(context) => context.parent_did_dimension(),FormattingContextImplementation::Svg(_) | FormattingContextImplementation::ReplacedWithChildren => {}FormattingContextImplementation::InternalReplaced => {return run.outputs(@@ -2560,26 +2555,9 @@ pub(crate) fn frame_established_by(callbacks: &LayoutPass<'_>, node: Node) -> ge.map_or(callbacks.frame, |style| geometry::Frame::of(style.writing_mode()))}-/// Runs `body` with the run root's metrics read in the frame it lays out its contents in.-fn in_own_frame<R>(- run: &FormattingContextRun,- parent_frame: geometry::Frame,- own_frame: geometry::Frame,- body: impl FnOnce() -> R,-) -> R {- if parent_frame == own_frame {- return body();- }- let used = run.records.used_values(run.box_);- used.move_box_metrics_to_frame(parent_frame, own_frame);- let result = body();- used.move_box_metrics_to_frame(own_frame, parent_frame);- result-}--/// Moves the root of a run whose writing mode establishes a frame other than its parent's into its own frame, where-/// its contents are laid out, and returns the input for laying them out there.-fn enter_own_frame(+/// The input for laying out the contents of a run root whose writing mode establishes a frame other than its parent's,+/// in that frame.+fn body_input_in_own_frame(run: &FormattingContextRun,body_run: &FormattingContextRun,input: &LayoutInput,@@ -2588,8 +2566,7 @@ fn enter_own_frame(own_frame: geometry::Frame,) -> LayoutInput {let node = run.box_;- let used = run.records.used_values(node);- used.move_box_metrics_to_frame(parent_frame, own_frame);+ let used = body_run.root_record();if !parent_frame.is_orthogonal_to(own_frame) {// NB: Sizes keep their axes between frames that are not orthogonal, so the contents are laid out with the// input the root's sizing gave them, apart from the parent's block formatting context they leave.@@ -2620,13 +2597,13 @@ fn enter_own_frame(// In the sizing phase [...] the dimensions of the box and the containing block are mapped to the inline// size and block size and calculations are performed accordingly using the writing mode of the box// establishing the orthogonal flow.- if !used.has_definite_inline_size.get() {+ if !used.has_definite_inline_size() {// NB: A flex or grid container sizes its items in both axes before laying out their contents, even where it// leaves a size indefinite for the percentages of their contents.let inline_size = if input.participation == ParticipationInParentFormattingContext::Item&& NodeFacts::new(&run.callbacks, node).parent_is_flex_or_grid_container(){- used.content_inline_size.get()+ used.content_inline_size()} else {body_run.sizing()@@ -2643,9 +2620,8 @@ fn enter_own_frame(body_input}-/// Moves the root of a run back into its parent's frame once its contents are laid out in its own frame, and maps-/// what the layout found into the parent's frame.-fn leave_own_frame(+/// Maps what the layout of a run root's contents in its own frame found into its parent's frame.+fn result_in_parent_frame(run: &FormattingContextRun,body_run: &FormattingContextRun,mut result: ChildLayoutResult,@@ -2653,8 +2629,6 @@ fn leave_own_frame(own_frame: geometry::Frame,) -> ChildLayoutResult {let used = run.records.used_values(run.box_);- // NB: The root's lines are laid out along its own inline axis, so finish them while that is what the root- // record holds.used.finish_line_data(&body_run.callbacks);if parent_frame.is_orthogonal_to(own_frame) {// https://drafts.csswg.org/css-writing-modes-4/#orthogonal-shrink-to-fit@@ -2702,7 +2676,6 @@ fn leave_own_frame(Some(table_box.border_box_inline_size(table_box.uses_collapsing_borders_model()));}}- used.move_box_metrics_to_frame(own_frame, parent_frame);result}@@ -3821,21 +3794,28 @@ mod baseline_tests {},);let parent_cells = used_values::RootInputCells::capture(&UsedValues::default());- RunRecords::with_root(callbacks, parent, Node::INVALID, parent_cells, |records, callbacks| {- let child_used = records.register(child, UsedValues::default());- store_derived_baselines(- child_used,- DerivedBaselines {- first: Some(CssPixels::from_integer(10)),- last: Some(CssPixels::from_integer(30)),- inline_alignment: None,- },- );- let baselines = derive_baselines(records, &callbacks, parent);- assert_eq!(baselines.first, Some(CssPixels::from_integer(10)));- assert_eq!(baselines.last, Some(CssPixels::from_integer(30)));- assert_eq!(baselines.inline_alignment, Some(CssPixels::from_integer(10)));- });+ RunRecords::with_root(+ callbacks,+ parent,+ Node::INVALID,+ parent_cells,+ callbacks.frame,+ |records, callbacks| {+ let child_used = records.register(child, UsedValues::default());+ store_derived_baselines(+ child_used,+ DerivedBaselines {+ first: Some(CssPixels::from_integer(10)),+ last: Some(CssPixels::from_integer(30)),+ inline_alignment: None,+ },+ );+ let baselines = derive_baselines(records, &callbacks, parent);+ assert_eq!(baselines.first, Some(CssPixels::from_integer(10)));+ assert_eq!(baselines.last, Some(CssPixels::from_integer(30)));+ assert_eq!(baselines.inline_alignment, Some(CssPixels::from_integer(10)));+ },+ );arena.free_subtree(parent).destroy_shells_and_invoke_callbacks(&crate::stage::MainThread::for_test());diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rsindex 1b2b13cc620..24286fcc345 100644--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs@@ -3140,6 +3140,7 @@ impl<'pass> GridFormattingContext<'pass> {subgrid.box_,containing_block,scratch_root,+ self.run.callbacks.frame,|records, callbacks| {let scratch_run = FormattingContextRun {records,diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rsindex 173ad2dcc76..7466e385f86 100644--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs@@ -533,19 +533,21 @@ enum RunKeptBoxClaim {}impl<'arena> RunRecords<'arena> {- /// Runs `run` with the records of a run rooted at `root`, and the pass as that run sees it.+ /// Runs `run` with the records of a run rooted at `root`, and the pass as that run sees it. The root's record holds+ /// `root_cells`, which hold its metrics in `root_frame`, the frame it lays its contents out in.pub(crate) fn with_root<R>(callbacks: LayoutPass<'arena>,root: Node,root_containing_block: Node,root_cells: used_values::RootInputCells,+ root_frame: geometry::Frame,run: impl FnOnce(&Self, LayoutPass<'arena>) -> R,) -> R {Self::enter(callbacks,root,root_containing_block,- Some(root_cells),+ Some((root_cells, root_frame)),ContentSizing::Layout,run,)@@ -562,7 +564,7 @@ impl<'arena> RunRecords<'arena> {callbacks,root,root_containing_block,- Some(root_cells),+ Some((root_cells, callbacks.frame)),ContentSizing::RootContributions,run,)@@ -579,7 +581,7 @@ impl<'arena> RunRecords<'arena> {callbacks,root,root_containing_block,- Some(root_cells),+ Some((root_cells, callbacks.frame)),ContentSizing::RootContentInlineSizes,run,)@@ -598,7 +600,7 @@ impl<'arena> RunRecords<'arena> {callbacks: LayoutPass<'arena>,root: Node,root_containing_block: Node,- root_cells: Option<used_values::RootInputCells>,+ root_cells: Option<(used_values::RootInputCells, geometry::Frame)>,content_sizing: ContentSizing,run: impl FnOnce(&Self, LayoutPass<'arena>) -> R,) -> R {@@ -609,7 +611,7 @@ impl<'arena> RunRecords<'arena> {let scratch = callbacks.scratch();let records = Self {root,- root_used: root_cells.map(|cells| cells.materialize_record(callbacks.frame)),+ root_used: root_cells.map(|(cells, frame)| cells.materialize_record(frame)),scratch,nonce: scratch.begin_run(),stack_length_at_start: scratch.run_record_stack.length(),@@ -1187,7 +1189,7 @@ impl<'arena> RunRecords<'arena> {let geometry_of_record = |used: &UsedValues| {let line_data = used.finish_line_data(callbacks);fragment_tree::FragmentGeometry {- cells: used_values::RootInputCells::capture(used),+ cells: used_values::RecordInFrame::new(used, callbacks.frame).cells(),line_data,}};@@ -1353,6 +1355,7 @@ mod tests {root,NodeSlotId::INVALID,default_root_cells(),+ geometry::Frame::PHYSICAL,|parent, _| {let root_used: *const UsedValues = parent.used_values(root);let child_used: *const UsedValues = parent.register(child, UsedValues::default());@@ -1361,6 +1364,7 @@ mod tests {child,root,default_root_cells(),+ geometry::Frame::PHYSICAL,|nested, _| {let nested_used: *const UsedValues = nested.used_values(child);assert!(!std::ptr::eq(nested_used, child_used));@@ -1403,6 +1407,7 @@ mod tests {root,NodeSlotId::INVALID,default_root_cells(),+ geometry::Frame::PHYSICAL,|records, _| {let used = records.register(child, UsedValues::default());used.set_finished_line_data(lines);@@ -1415,6 +1420,7 @@ mod tests {root,NodeSlotId::INVALID,default_root_cells(),+ geometry::Frame::PHYSICAL,|records, _| std::ptr::from_ref(records.register(child, UsedValues::default())),);assert_eq!(first_record, second_record);@@ -1448,6 +1454,7 @@ mod tests {root,NodeSlotId::INVALID,default_root_cells(),+ geometry::Frame::PHYSICAL,|records, _| {records.register(child, UsedValues::default());},@@ -1466,6 +1473,7 @@ mod tests {root,NodeSlotId::INVALID,default_root_cells(),+ geometry::Frame::PHYSICAL,|records, _| {records.register(root, UsedValues::default());},@@ -1489,6 +1497,7 @@ mod tests {root,NodeSlotId::INVALID,default_root_cells(),+ geometry::Frame::PHYSICAL,|_, _| {parent.register(child, UsedValues::default());},@@ -1508,6 +1517,7 @@ mod tests {root,NodeSlotId::INVALID,default_root_cells(),+ geometry::Frame::PHYSICAL,|parent, _| {let root_used: *const UsedValues = parent.used_values(root);let child_used: *const UsedValues = parent.register(child, UsedValues::default());@@ -1517,6 +1527,7 @@ mod tests {child,root,default_root_cells(),+ geometry::Frame::PHYSICAL,|nested, _| {nested.register(root, UsedValues::default());panic!("abort the nested measurement");diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rsindex 42d4041656b..20df3da23b5 100644--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs@@ -97,13 +97,6 @@ impl<T: Copy> SealableCell<T> {pub(crate) fn seal(&self) {self.sealed.set(true);}-- /// Sets the value even where it is sealed, for moving a box's metrics between the frames of writing modes: that- /// changes how they read, not what they are.- #[inline]- pub(crate) fn set_ignoring_seal(&self, value: T) {- self.value.set(value);- }}#[derive(Clone, Default, PartialEq)]@@ -302,7 +295,7 @@ impl UsedValues {std::mem::take(data.as_mut()),callbacks.arena(),self.content_inline_size.get(),- callbacks.frame.writing_mode(),+ self.frame.get().writing_mode(),)),};*state = LineDataState::Finished(content.clone());@@ -317,39 +310,6 @@ impl UsedValues {}}- /// Moves the box's sizes, size constraints and box sides from frame `from` to frame `to`.- pub(crate) fn move_box_metrics_to_frame(&self, from: geometry::Frame, to: geometry::Frame) {- if from == to {- return;- }- self.frame.set(to);- let state = UsedValuesCellState::capture(self).in_frame(from, to);- macro_rules! move_sealable {- ($($field:ident),+) => {- $(self.$field.set_ignoring_seal(state.inputs.$field);)+- };- }- move_sealable!(- content_inline_size,- content_block_size,- margin_left,- margin_right,- margin_top,- margin_bottom,- border_left,- border_right,- border_top,- border_bottom,- padding_left,- padding_right,- padding_top,- padding_bottom- );- self.has_definite_inline_size.set(state.inputs.has_definite_inline_size);- self.has_definite_block_size.set(state.inputs.has_definite_block_size);- formatting_context::store_derived_baselines(self, state.baselines);- }-pub(crate) fn seal_own_metrics(&self) {self.content_inline_size.seal();self.content_block_size.seal();@@ -517,15 +477,6 @@ impl UsedValuesCellState {self.inputs.apply_to_record(used);formatting_context::store_derived_baselines(used, self.baselines);}-- /// The state, with the sizes, size constraints and box sides it holds in frame `from` read in frame `to` instead.- pub(crate) fn in_frame(mut self, from: geometry::Frame, to: geometry::Frame) -> Self {- self.inputs = self.inputs.in_frame(from, to);- if from.is_orthogonal_to(to) {- self.baselines = DerivedBaselines::default();- }- self- }}impl UsedValues {