Skip to content

Truly independent web browser

LibWeb: Hand a subgrid what it takes of its parent grid as a value

Aliaksandr Kalenike1feabeb925d
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index 535cad91b79..c2d9f3baf2b 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -850,7 +850,7 @@ impl FcRunCacheAttempt {
/// an entry whose run built them; any other probe reads the result of any matching entry.
pub(super) fn probe(
box_: Node,
- parent_grid_is_present: bool,
+ runs_as_subgrid: bool,
builds_fragments: bool,
should_collect_devtools_layout_data: bool,
measurement_root_keeps_its_result: bool,
@@ -859,7 +859,7 @@ impl FcRunCacheAttempt {
) -> Result<Self, FcRunCacheHit> {
if !can_describe_run(
box_,
- parent_grid_is_present,
+ runs_as_subgrid,
should_collect_devtools_layout_data,
measurement_root_keeps_its_result,
callbacks,
@@ -967,7 +967,7 @@ impl FcRunCacheAttempt {
pub(super) fn can_describe_run(
box_: Node,
- parent_grid_is_present: bool,
+ runs_as_subgrid: bool,
should_collect_devtools_layout_data: bool,
measurement_root_keeps_its_result: bool,
callbacks: &LayoutPass<'_>,
@@ -986,10 +986,7 @@ pub(super) fn can_describe_run(
{
return false;
}
- if fc_type == formatting_context::FormattingContextType::Grid
- && parent_grid_is_present
- && grid_formatting_context::grid_template_declares_a_subgrid_axis(callbacks, box_)
- {
+ if runs_as_subgrid {
return false;
}
// Structural invariants behind this root-flag check, to re-verify if it is ever
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 5799ae44166..97cf0e1b519 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -1485,7 +1485,7 @@ pub(crate) fn formatting_context_type_created_by_box(facts: NodeFacts<'_>) -> Op
fn create_formatting_context_implementation<'pass>(
run: &FormattingContextRun<'pass>,
root_cells_in_own_frame: used_values::RootInputCells,
- parent_grid: Option<&grid_formatting_context::GridFormattingContext<'pass>>,
+ subgrid_parent: Option<&grid_formatting_context::SubgridParent<'pass>>,
fc_type: FormattingContextType,
previous_line_data: Option<std::sync::Arc<inline_content::InlineContent>>,
) -> FormattingContextImplementation<'pass> {
@@ -1497,7 +1497,7 @@ fn create_formatting_context_implementation<'pass>(
flex_formatting_context::FlexFormattingContext::new(run, root_cells_in_own_frame),
),
FormattingContextType::Grid => FormattingContextImplementation::Grid(
- grid_formatting_context::GridFormattingContext::new(run, root_cells_in_own_frame, parent_grid),
+ grid_formatting_context::GridFormattingContext::new(run, root_cells_in_own_frame, subgrid_parent),
),
FormattingContextType::Table => {
FormattingContextImplementation::Table(table_formatting_context::TableFormattingContext::new(
@@ -1996,7 +1996,7 @@ pub(super) fn run_formatting_context(
root_cells: used_values::RootInputCells,
box_: Node,
root_containing_block: Node,
- parent_grid: Option<&grid_formatting_context::GridFormattingContext>,
+ subgrid_parent: Option<&grid_formatting_context::SubgridParent>,
fc_type: FormattingContextType,
should_collect_devtools_layout_data: bool,
callbacks: LayoutPass<'_>,
@@ -2014,7 +2014,7 @@ pub(super) fn run_formatting_context(
root_cells,
box_,
root_containing_block,
- parent_grid,
+ subgrid_parent,
fc_type,
should_collect_devtools_layout_data,
callbacks,
@@ -2036,7 +2036,7 @@ pub(super) fn run_formatting_context(
let cache_probe = fc_run_cache::FcRunCacheProbe::new(fc_type, &input, root_cells);
let cache_attempt = match fc_run_cache::FcRunCacheAttempt::probe(
box_,
- parent_grid.is_some(),
+ subgrid_parent.is_some(),
builds_fragments,
should_collect_devtools_layout_data,
false,
@@ -2075,7 +2075,7 @@ pub(super) fn run_formatting_context(
root_cells,
box_,
root_containing_block,
- parent_grid,
+ subgrid_parent,
fc_type,
should_collect_devtools_layout_data,
callbacks,
@@ -2090,7 +2090,7 @@ pub(super) fn run_formatting_context(
root_cells,
box_,
root_containing_block,
- parent_grid,
+ subgrid_parent,
fc_type,
should_collect_devtools_layout_data,
callbacks,
@@ -2115,7 +2115,7 @@ pub(super) fn run_formatting_context(
other_root_cells,
box_,
root_containing_block,
- parent_grid,
+ subgrid_parent,
fc_type,
should_collect_devtools_layout_data,
callbacks,
@@ -2165,7 +2165,7 @@ fn execute_formatting_context_run(
root_cells: used_values::RootInputCells,
box_: Node,
root_containing_block: Node,
- parent_grid: Option<&grid_formatting_context::GridFormattingContext>,
+ subgrid_parent: Option<&grid_formatting_context::SubgridParent>,
fc_type: FormattingContextType,
should_collect_devtools_layout_data: bool,
callbacks: LayoutPass<'_>,
@@ -2209,7 +2209,7 @@ fn execute_formatting_context_run(
callbacks,
root_cells,
box_,
- parent_grid,
+ subgrid_parent,
fc_type,
should_collect_devtools_layout_data,
input,
@@ -2262,7 +2262,7 @@ fn lay_out_run_root_and_contents<'pass>(
callbacks: LayoutPass<'pass>,
root_cells: used_values::RootInputCells,
box_: Node,
- parent_grid: Option<&grid_formatting_context::GridFormattingContext<'pass>>,
+ subgrid_parent: Option<&grid_formatting_context::SubgridParent<'pass>>,
fc_type: FormattingContextType,
should_collect_devtools_layout_data: bool,
input: &LayoutInput,
@@ -2348,7 +2348,7 @@ fn lay_out_run_root_and_contents<'pass>(
let context_implementation = implementation.insert(create_formatting_context_implementation(
body_run,
own_root.get(),
- parent_grid,
+ subgrid_parent,
fc_type,
previous_line_data,
));
@@ -3073,12 +3073,15 @@ pub(crate) fn layout_inside_child_with_input_cells(
force_independent_context_run,
percentage_block_insets_of_containing_block_have_definite_basis,
);
+ let subgrid_parent = parent_grid
+ .filter(|_| fc_type == FormattingContextType::Grid)
+ .and_then(|grid| grid.subgrid_parent_of(child));
run_formatting_context(
run.fragments.is_some(),
child_input_cells,
child,
root_containing_block,
- parent_grid,
+ subgrid_parent.as_ref(),
fc_type,
run.should_collect_devtools_layout_data,
run.callbacks,
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index 30dc51e952f..ca4d6abc4b9 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -1431,6 +1431,14 @@ impl<'pass> ParentGridData<'pass> {
}
}
+/// What a subgrid takes from the grid it is an item of: that grid's lines and tracks as they are when the subgrid is
+/// laid out, and the block sizes measured for column subgrids in the run of the independent grid above both.
+#[derive(Clone)]
+pub(crate) struct SubgridParent<'pass> {
+ grid: ParentGridData<'pass>,
+ block_size_memo: SubgridBlockSizeMemo,
+}
+
/// Conservative superset of is_subgridded() for callers outside a live grid run
/// (the fc-run-cache probe): a declared subgrid axis counts regardless of the
/// parent-grid placement check only a run in progress can make.
@@ -1443,10 +1451,9 @@ impl<'pass> GridFormattingContext<'pass> {
pub(crate) fn new(
run: &FormattingContextRun<'pass>,
container_cells: used_values::RootInputCells,
- parent_grid: Option<&GridFormattingContext<'pass>>,
+ subgrid_parent: Option<&SubgridParent<'pass>>,
) -> Self {
let grid_container = run.box_;
- let parent_grid = parent_grid.filter(|_| grid_template_declares_a_subgrid_axis(&run.callbacks, grid_container));
let container_style = StyleValues::for_node(&run.callbacks, grid_container);
Self {
run: run.clone(),
@@ -1454,7 +1461,7 @@ impl<'pass> GridFormattingContext<'pass> {
container_constraints_for_cells: Cell::new(None),
derived_baselines_of_root_box: DerivedBaselines::default(),
container_style,
- parent_grid: parent_grid.map(|parent| ParentGridData::for_child_container(parent, grid_container)),
+ parent_grid: subgrid_parent.map(|parent| parent.grid.clone()),
available_space: None,
layout_input: None,
column_lines: Vec::new(),
@@ -1472,8 +1479,8 @@ impl<'pass> GridFormattingContext<'pass> {
subgridded_rows: false,
inherits_resolved_parent_columns: false,
subgrid_tracks_act_empty: false,
- subgrid_block_size_memo: parent_grid
- .map(|parent| std::cell::OnceCell::from(parent.subgrid_block_size_memo().clone()))
+ subgrid_block_size_memo: subgrid_parent
+ .map(|parent| std::cell::OnceCell::from(parent.block_size_memo.clone()))
.unwrap_or_default(),
automatic_content_block_size: CssPixels::default(),
row_alignment_container_size: CssPixels::default(),
@@ -1537,6 +1544,15 @@ impl<'pass> GridFormattingContext<'pass> {
self.subgrid_block_size_memo.get_or_init(SubgridBlockSizeMemo::default)
}
+ /// What `child`, an item of this grid laid out in a grid formatting context of its own, takes from this grid as
+ /// its parent grid, where it declares a subgrid axis.
+ pub(crate) fn subgrid_parent_of(&self, child: Node) -> Option<SubgridParent<'pass>> {
+ grid_template_declares_a_subgrid_axis(&self.run.callbacks, child).then(|| SubgridParent {
+ grid: ParentGridData::for_child_container(self, child),
+ block_size_memo: self.subgrid_block_size_memo().clone(),
+ })
+ }
+
#[inline]
#[track_caller]
fn collected_item(&self, item: GridItem) -> &CollectedGridItem<'pass> {
@@ -3541,7 +3557,8 @@ impl<'pass> GridFormattingContext<'pass> {
fragments: None,
fragmentainer: None,
};
- let mut context = GridFormattingContext::new(&scratch_run, scratch_root, Some(self));
+ let subgrid_parent = self.subgrid_parent_of(subgrid.box_);
+ let mut context = GridFormattingContext::new(&scratch_run, scratch_root, subgrid_parent.as_ref());
context.subgrid_tracks_act_empty = true;
measure(&mut context, &scratch_run)
},