diff options
author | Steven Novaryo <65610990+stevennovaryo@users.noreply.github.com> | 2025-01-09 18:49:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-09 10:49:27 +0000 |
commit | 76fa456a9a6c6d9badc70cf31916b41119fba9f6 (patch) | |
tree | 945883c126d4399801239722a770485428c959f7 /components/layout_2020/taffy/layout.rs | |
parent | 040e29415b059869648098713fec534feae5ca5f (diff) | |
download | servo-76fa456a9a6c6d9badc70cf31916b41119fba9f6.tar.gz servo-76fa456a9a6c6d9badc70cf31916b41119fba9f6.zip |
layout: grid template getComputedStyle resolved value (#34885)
* Store taffy detailed info into fragment
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
* Fix info propagation and resolved grid track query
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
* Fix import
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
* Fix tracklist matching logic and type optimization
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
* Run fmt
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
* Update wpt expectations
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
* Optimizing info propagation and minor qol
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
* Run fmt
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
---------
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
Diffstat (limited to 'components/layout_2020/taffy/layout.rs')
-rw-r--r-- | components/layout_2020/taffy/layout.rs | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/components/layout_2020/taffy/layout.rs b/components/layout_2020/taffy/layout.rs index 44c66035ee7..e2b515042ee 100644 --- a/components/layout_2020/taffy/layout.rs +++ b/components/layout_2020/taffy/layout.rs @@ -12,14 +12,16 @@ use style::Zero; use taffy::style_helpers::{TaffyMaxContent, TaffyMinContent}; use taffy::{AvailableSpace, MaybeMath, RequestedAxis, RunMode}; -use super::{TaffyContainer, TaffyItemBox, TaffyItemBoxInner, TaffyStyloStyle}; +use super::{ + DetailedTaffyGridInfo, TaffyContainer, TaffyItemBox, TaffyItemBoxInner, TaffyStyloStyle, +}; use crate::cell::ArcRefCell; use crate::context::LayoutContext; use crate::formatting_contexts::{ Baselines, IndependentFormattingContext, IndependentFormattingContextContents, IndependentLayout, }; -use crate::fragment_tree::{BoxFragment, CollapsedBlockMargins, Fragment}; +use crate::fragment_tree::{BoxFragment, CollapsedBlockMargins, DetailedLayoutInfo, Fragment}; use crate::geom::{ LogicalSides, LogicalVec2, PhysicalPoint, PhysicalRect, PhysicalSides, PhysicalSize, Size, SizeConstraint, Sizes, @@ -64,6 +66,10 @@ struct TaffyContainerContext<'a> { positioning_context: &'a mut PositioningContext, content_box_size_override: &'a ContainingBlock<'a>, style: &'a ComputedValues, + detailed_layout_info: Option<DetailedLayoutInfo>, + + /// Temporary location for children detailed info, which will be moved into child fragments + child_detailed_layout_infos: Vec<Option<DetailedLayoutInfo>>, } struct ChildIter(std::ops::Range<usize>); @@ -264,6 +270,8 @@ impl taffy::LayoutPartialTree for TaffyContainerContext<'_> { }; child.child_fragments = layout.fragments; + self.child_detailed_layout_infos[usize::from(node_id)] = + layout.detailed_layout_info; let block_size = layout.content_block_size.to_f32_px(); @@ -314,6 +322,16 @@ impl taffy::LayoutGridContainer for TaffyContainerContext<'_> { let child = (*self.source_child_nodes[id]).borrow(); TaffyStyloStyle(AtomicRef::map(child, |c| &*c.style)) } + + fn set_detailed_grid_info( + &mut self, + _node_id: taffy::NodeId, + detailed_layout_info: taffy::DetailedGridInfo, + ) { + self.detailed_layout_info = Some(DetailedLayoutInfo::Grid(Box::new( + DetailedTaffyGridInfo::from_detailed_grid_layout(detailed_layout_info), + ))); + } } impl ComputeInlineContentSizes for TaffyContainer { @@ -355,6 +373,8 @@ impl ComputeInlineContentSizes for TaffyContainer { content_box_size_override: containing_block, style, source_child_nodes: &self.children, + detailed_layout_info: None, + child_detailed_layout_infos: vec![None; self.children.len()], }; let (max_content_output, min_content_output) = match style.clone_display().inside() { @@ -408,6 +428,8 @@ impl TaffyContainer { content_box_size_override, style: content_box_size_override.style, source_child_nodes: &self.children, + detailed_layout_info: None, + child_detailed_layout_infos: vec![None; self.children.len()], }; fn auto_or_to_option<T>(input: GenericLengthPercentageOrAuto<T>) -> Option<T> { @@ -456,11 +478,13 @@ impl TaffyContainer { }; // Convert `taffy::Layout` into Servo `Fragment`s + // with container_ctx.child_detailed_layout_infos will also moved to the corresponding `Fragment`s let fragments: Vec<Fragment> = self .children .iter() .map(|child| (**child).borrow_mut()) - .map(|mut child| { + .enumerate() + .map(|(child_id, mut child)| { fn rect_to_logical_sides<T>(rect: taffy::Rect<T>) -> LogicalSides<T> { LogicalSides { inline_start: rect.left, @@ -522,6 +546,9 @@ impl TaffyContainer { .map(Au::from_f32_px), ); + let child_detailed_layout_info: Option<DetailedLayoutInfo> = + std::mem::take(&mut container_ctx.child_detailed_layout_infos[child_id]); + match &mut child.taffy_level_box { TaffyItemBoxInner::InFlowBox(independent_box) => { let fragment = Fragment::Box( @@ -539,7 +566,8 @@ impl TaffyContainer { .with_baselines(Baselines { first: output.first_baselines.y.map(Au::from_f32_px), last: None, - }), + }) + .with_detailed_layout_info(child_detailed_layout_info), ); child @@ -604,6 +632,8 @@ impl TaffyContainer { // "true" is a safe default as it will prevent Servo from performing optimizations based // on the assumption that the node's size does not depend on block constraints. depends_on_block_constraints: true, + + detailed_layout_info: container_ctx.detailed_layout_info, } } } |