layout: Avoid ClipId, ExternalScrollId and ScrollTreeNodeId references (#39372)

Changes function signatures to accept `ClipId`, `ExternalScrollId` and
`ScrollTreeNodeId` instead of `&ClipId`, `&ExternalScrollId` and
`&ScrollTreeNodeId`. This avoids several `&` and `*`.

Testing: not needed, no behavior change.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Oriol Brufau 2025-09-19 01:34:49 +02:00 committed by GitHub
parent aeeb3cb488
commit 1473121fe5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 74 additions and 75 deletions

View file

@ -851,7 +851,7 @@ impl WebViewRenderer {
Some(&hit_test_result.pipeline_id)
{
let scroll_result = pipeline_details.scroll_tree.scroll_node_or_ancestor(
&hit_test_result.external_scroll_id,
hit_test_result.external_scroll_id,
scroll_location,
ScrollType::InputEvents,
);

View file

@ -69,8 +69,8 @@ impl StackingContextTreeClipStore {
pub(super) fn add_for_clip_path(
&mut self,
clip_path: ClipPath,
parent_scroll_node_id: &ScrollTreeNodeId,
parent_clip_chain_id: &ClipId,
parent_scroll_node_id: ScrollTreeNodeId,
parent_clip_chain_id: ClipId,
fragment_builder: BuilderForBoxFragment,
) -> Option<ClipId> {
let geometry_box = match clip_path {
@ -108,8 +108,8 @@ impl StackingContextTreeClipStore {
_ => fragment_builder.border_radius,
},
layout_rect,
*parent_scroll_node_id,
*parent_clip_chain_id,
parent_scroll_node_id,
parent_clip_chain_id,
))
}
}
@ -119,8 +119,8 @@ impl StackingContextTreeClipStore {
&mut self,
shape: BasicShape,
layout_box: LayoutRect,
parent_scroll_node_id: &ScrollTreeNodeId,
parent_clip_chain_id: &ClipId,
parent_scroll_node_id: ScrollTreeNodeId,
parent_clip_chain_id: ClipId,
) -> Option<ClipId> {
match shape {
BasicShape::Rect(rect) => {
@ -159,8 +159,8 @@ impl StackingContextTreeClipStore {
Some(self.add(
radii,
shape_rect,
*parent_scroll_node_id,
*parent_clip_chain_id,
parent_scroll_node_id,
parent_clip_chain_id,
))
},
BasicShape::Circle(circle) => {
@ -207,7 +207,7 @@ impl StackingContextTreeClipStore {
let start = center.add_size(&-radius);
let rect = LayoutRect::from_origin_and_size(start, radius * 2.);
normalize_radii(&layout_box, &mut radii);
Some(self.add(radii, rect, *parent_scroll_node_id, *parent_clip_chain_id))
Some(self.add(radii, rect, parent_scroll_node_id, parent_clip_chain_id))
},
BasicShape::Ellipse(ellipse) => {
let center = match ellipse.position {
@ -247,7 +247,7 @@ impl StackingContextTreeClipStore {
let start = center.add_size(&-size);
let rect = LayoutRect::from_origin_and_size(start, size * 2.);
normalize_radii(&rect, &mut radii);
Some(self.add(radii, rect, *parent_scroll_node_id, *parent_clip_chain_id))
Some(self.add(radii, rect, parent_scroll_node_id, parent_clip_chain_id))
},
_ => None,
}

View file

@ -103,7 +103,7 @@ impl<'a> HitTest<'a> {
.stacking_context_tree
.compositor_info
.scroll_tree
.cumulative_root_to_node_transform(&scroll_tree_node_id)?;
.cumulative_root_to_node_transform(scroll_tree_node_id)?;
let projected_point = transform.project_point2d(self.point_to_test)?;

View file

@ -238,7 +238,7 @@ impl DisplayListBuilder<'_> {
}
fn spatial_id(&self, id: ScrollTreeNodeId) -> SpatialId {
self.compositor_info.scroll_tree.webrender_id(&id)
self.compositor_info.scroll_tree.webrender_id(id)
}
fn clip_chain_id(&self, id: ClipId) -> ClipChainId {

View file

@ -204,7 +204,7 @@ impl StackingContextTree {
&mut self,
origin: LayoutPoint,
frame_origin_for_query: LayoutPoint,
parent_scroll_node_id: &ScrollTreeNodeId,
parent_scroll_node_id: ScrollTreeNodeId,
transform_style: wr::TransformStyle,
transform: LayoutTransform,
kind: wr::ReferenceFrameKind,
@ -223,7 +223,7 @@ impl StackingContextTree {
fn define_scroll_frame(
&mut self,
parent_scroll_node_id: &ScrollTreeNodeId,
parent_scroll_node_id: ScrollTreeNodeId,
external_id: wr::ExternalScrollId,
content_rect: LayoutRect,
clip_rect: LayoutRect,
@ -244,7 +244,7 @@ impl StackingContextTree {
fn define_sticky_frame(
&mut self,
parent_scroll_node_id: &ScrollTreeNodeId,
parent_scroll_node_id: ScrollTreeNodeId,
frame_rect: LayoutRect,
margins: SideOffsets2D<Option<f32>, LayoutPixel>,
vertical_offset_bounds: StickyOffsetBounds,
@ -1018,7 +1018,7 @@ impl BoxFragment {
let new_spatial_id = stacking_context_tree.push_reference_frame(
reference_frame_data.origin.to_webrender(),
frame_origin_for_query,
&containing_block.scroll_node_id,
containing_block.scroll_node_id,
self.style.get_box().transform_style.to_webrender(),
reference_frame_data.transform,
reference_frame_data.kind,
@ -1100,8 +1100,8 @@ impl BoxFragment {
.clip_store
.add_for_clip_path(
self.style.clone_clip_path(),
&containing_block.scroll_node_id,
&containing_block.clip_id,
containing_block.scroll_node_id,
containing_block.clip_id,
BuilderForBoxFragment::new(
self,
&containing_block.rect,
@ -1166,7 +1166,7 @@ impl BoxFragment {
if let Some(scroll_node_id) = self.build_sticky_frame_if_necessary(
stacking_context_tree,
&new_scroll_node_id,
new_scroll_node_id,
&containing_block.rect,
&new_scroll_frame_size,
) {
@ -1175,7 +1175,7 @@ impl BoxFragment {
if let Some(clip_id) = self.build_clip_frame_if_necessary(
stacking_context_tree,
&new_scroll_node_id,
new_scroll_node_id,
new_clip_id,
&containing_block.rect,
) {
@ -1184,8 +1184,8 @@ impl BoxFragment {
if let Some(clip_id) = stacking_context_tree.clip_store.add_for_clip_path(
self.style.clone_clip_path(),
&new_scroll_node_id,
&new_clip_id,
new_scroll_node_id,
new_clip_id,
BuilderForBoxFragment::new(
self,
&containing_block.rect,
@ -1243,7 +1243,7 @@ impl BoxFragment {
// they shouldn't scroll with the rest of the box content.
if let Some(overflow_frame_data) = self.build_overflow_frame_if_necessary(
stacking_context_tree,
&new_scroll_node_id,
new_scroll_node_id,
new_clip_id,
&containing_block.rect,
) {
@ -1371,7 +1371,7 @@ impl BoxFragment {
fn build_clip_frame_if_necessary(
&self,
stacking_context_tree: &mut StackingContextTree,
parent_scroll_node_id: &ScrollTreeNodeId,
parent_scroll_node_id: ScrollTreeNodeId,
parent_clip_id: ClipId,
containing_block_rect: &PhysicalRect<Au>,
) -> Option<ClipId> {
@ -1396,7 +1396,7 @@ impl BoxFragment {
Some(stacking_context_tree.clip_store.add(
BorderRadius::zero(),
clip_rect,
*parent_scroll_node_id,
parent_scroll_node_id,
parent_clip_id,
))
}
@ -1404,7 +1404,7 @@ impl BoxFragment {
fn build_overflow_frame_if_necessary(
&self,
stacking_context_tree: &mut StackingContextTree,
parent_scroll_node_id: &ScrollTreeNodeId,
parent_scroll_node_id: ScrollTreeNodeId,
parent_clip_id: ClipId,
containing_block_rect: &PhysicalRect<Au>,
) -> Option<OverflowFrameData> {
@ -1448,7 +1448,7 @@ impl BoxFragment {
let clip_id = stacking_context_tree.clip_store.add(
radii,
overflow_clip_rect,
*parent_scroll_node_id,
parent_scroll_node_id,
parent_clip_id,
);
@ -1466,7 +1466,7 @@ impl BoxFragment {
let clip_id = stacking_context_tree.clip_store.add(
BuilderForBoxFragment::new(self, containing_block_rect, false, false).border_radius,
scroll_frame_rect,
*parent_scroll_node_id,
parent_scroll_node_id,
parent_clip_id,
);
@ -1501,7 +1501,7 @@ impl BoxFragment {
fn build_sticky_frame_if_necessary(
&self,
stacking_context_tree: &mut StackingContextTree,
parent_scroll_node_id: &ScrollTreeNodeId,
parent_scroll_node_id: ScrollTreeNodeId,
containing_block_rect: &PhysicalRect<Au>,
scroll_frame_size: &Option<LayoutSize>,
) -> Option<ScrollTreeNodeId> {

View file

@ -66,7 +66,7 @@ fn root_transform_for_layout_node(
.borrow();
let scroll_tree_node_id = box_fragment.spatial_tree_node.borrow();
let scroll_tree_node_id = (*scroll_tree_node_id)?;
Some(scroll_tree.cumulative_node_to_root_transform(&scroll_tree_node_id))
Some(scroll_tree.cumulative_node_to_root_transform(scroll_tree_node_id))
}
pub(crate) fn process_box_area_request(

View file

@ -413,7 +413,7 @@ impl ScrollTreeNode {
for child_id in &self.children {
scroll_tree
.get_node(child_id)
.get_node(*child_id)
.invalidate_cached_transforms(scroll_tree, invalid);
}
}
@ -434,11 +434,11 @@ impl ScrollTree {
/// Add a scroll node to this ScrollTree returning the id of the new node.
pub fn add_scroll_tree_node(
&mut self,
parent: Option<&ScrollTreeNodeId>,
parent: Option<ScrollTreeNodeId>,
info: SpatialTreeNodeInfo,
) -> ScrollTreeNodeId {
self.nodes.push(ScrollTreeNode {
parent: parent.cloned(),
parent,
children: Vec::new(),
webrender_id: None,
info,
@ -465,24 +465,24 @@ impl ScrollTree {
}
/// Get a mutable reference to the node with the given index.
pub fn get_node_mut(&mut self, id: &ScrollTreeNodeId) -> &mut ScrollTreeNode {
pub fn get_node_mut(&mut self, id: ScrollTreeNodeId) -> &mut ScrollTreeNode {
&mut self.nodes[id.index]
}
/// Get an immutable reference to the node with the given index.
pub fn get_node(&self, id: &ScrollTreeNodeId) -> &ScrollTreeNode {
pub fn get_node(&self, id: ScrollTreeNodeId) -> &ScrollTreeNode {
&self.nodes[id.index]
}
/// Get the WebRender [`SpatialId`] for the given [`ScrollNodeId`]. This will
/// panic if [`ScrollTree::build_display_list`] has not been called yet.
pub fn webrender_id(&self, id: &ScrollTreeNodeId) -> SpatialId {
pub fn webrender_id(&self, id: ScrollTreeNodeId) -> SpatialId {
self.get_node(id).webrender_id()
}
pub fn scroll_node_or_ancestor_inner(
&mut self,
scroll_node_id: &ScrollTreeNodeId,
scroll_node_id: ScrollTreeNodeId,
scroll_location: ScrollLocation,
context: ScrollType,
) -> Option<(ExternalScrollId, LayoutVector2D)> {
@ -495,20 +495,19 @@ impl ScrollTree {
node.parent
};
parent.and_then(|parent| {
self.scroll_node_or_ancestor_inner(&parent, scroll_location, context)
})
parent
.and_then(|parent| self.scroll_node_or_ancestor_inner(parent, scroll_location, context))
}
fn node_with_external_scroll_node_id(
&self,
external_id: &ExternalScrollId,
external_id: ExternalScrollId,
) -> Option<ScrollTreeNodeId> {
self.nodes
.iter()
.enumerate()
.find_map(|(index, node)| match &node.info {
SpatialTreeNodeInfo::Scroll(info) if info.external_id == *external_id => {
SpatialTreeNodeInfo::Scroll(info) if info.external_id == external_id => {
Some(ScrollTreeNodeId { index })
},
_ => None,
@ -521,12 +520,12 @@ impl ScrollTree {
/// new offset if a scroll was performed, otherwise returns None.
pub fn scroll_node_or_ancestor(
&mut self,
external_id: &ExternalScrollId,
external_id: ExternalScrollId,
scroll_location: ScrollLocation,
context: ScrollType,
) -> Option<(ExternalScrollId, LayoutVector2D)> {
let scroll_node_id = self.node_with_external_scroll_node_id(external_id)?;
let result = self.scroll_node_or_ancestor_inner(&scroll_node_id, scroll_location, context);
let result = self.scroll_node_or_ancestor_inner(scroll_node_id, scroll_location, context);
if result.is_some() {
self.invalidate_cached_transforms();
}
@ -609,7 +608,7 @@ impl ScrollTree {
/// point in the root coordinate system.
pub fn cumulative_node_to_root_transform(
&self,
node_id: &ScrollTreeNodeId,
node_id: ScrollTreeNodeId,
) -> FastLayoutTransform {
let node = self.get_node(node_id);
if let Some(cached_transforms) = node.transformation_cache.get() {
@ -626,7 +625,7 @@ impl ScrollTree {
/// transform is uninvertible.
pub fn cumulative_root_to_node_transform(
&self,
node_id: &ScrollTreeNodeId,
node_id: ScrollTreeNodeId,
) -> Option<FastLayoutTransform> {
let node = self.get_node(node_id);
if let Some(cached_transforms) = node.transformation_cache.get() {
@ -644,7 +643,7 @@ impl ScrollTree {
node: &ScrollTreeNode,
) -> (ScrollTreeNodeTransformationCache, AncestorStickyInfo) {
let (parent_transforms, mut sticky_info) = match node.parent {
Some(parent_id) => self.cumulative_node_transform_inner(self.get_node(&parent_id)),
Some(parent_id) => self.cumulative_node_transform_inner(self.get_node(parent_id)),
None => (Default::default(), Default::default()),
};
@ -712,13 +711,13 @@ impl ScrollTree {
&self,
id: ScrollTreeNodeId,
) -> Option<ExternalScrollId> {
let mut maybe_node = Some(self.get_node(&id));
let mut maybe_node = Some(self.get_node(id));
while let Some(node) = maybe_node {
if let Some(external_scroll_id) = node.external_id() {
return Some(external_scroll_id);
}
maybe_node = node.parent.map(|id| self.get_node(&id));
maybe_node = node.parent.map(|id| self.get_node(id));
}
None
@ -752,12 +751,12 @@ impl ScrollTree {
fn debug_print_traversal(
&self,
print_tree: &mut PrintTree,
current_id: &ScrollTreeNodeId,
current_id: ScrollTreeNodeId,
adjacency_list: &[Vec<ScrollTreeNodeId>],
) {
for node_id in &adjacency_list[current_id.index] {
self.nodes[node_id.index].debug_print(print_tree, node_id.index);
self.debug_print_traversal(print_tree, node_id, adjacency_list);
self.debug_print_traversal(print_tree, *node_id, adjacency_list);
}
print_tree.end_level();
}
@ -775,7 +774,7 @@ impl ScrollTree {
let root_id = ScrollTreeNodeId { index: 0 };
self.nodes[root_id.index].debug_print(&mut print_tree, root_id.index);
self.debug_print_traversal(&mut print_tree, &root_id, &adj_list);
self.debug_print_traversal(&mut print_tree, root_id, &adj_list);
print_tree.end_level();
}
}
@ -842,7 +841,7 @@ impl CompositorDisplayListInfo {
}),
);
let root_scroll_node_id = scroll_tree.add_scroll_tree_node(
Some(&root_reference_frame_id),
Some(root_reference_frame_id),
SpatialTreeNodeInfo::Scroll(ScrollableNodeInfo {
external_id: ExternalScrollId(0, pipeline_id),
content_rect: LayoutRect::from_origin_and_size(LayoutPoint::zero(), content_size),

View file

@ -25,7 +25,7 @@ fn add_mock_scroll_node(tree: &mut ScrollTree) -> (ScrollTreeNodeId, ExternalScr
let external_id = ExternalScrollId(num_nodes as u64, pipeline_id);
let scroll_node_id = tree.add_scroll_tree_node(
parent.as_ref(),
parent,
SpatialTreeNodeInfo::Scroll(ScrollableNodeInfo {
external_id,
content_rect: Size2D::new(200.0, 200.0).into(),
@ -48,7 +48,7 @@ fn test_scroll_tree_simple_scroll() {
let (scrolled_id, offset) = scroll_tree
.scroll_node_or_ancestor(
&external_id,
external_id,
ScrollLocation::Delta(LayoutVector2D::new(20.0, 40.0)),
ScrollType::Script,
)
@ -56,11 +56,11 @@ fn test_scroll_tree_simple_scroll() {
let expected_offset = LayoutVector2D::new(20.0, 40.0);
assert_eq!(scrolled_id, external_id);
assert_eq!(offset, expected_offset);
assert_eq!(scroll_tree.get_node(&id).offset(), Some(expected_offset));
assert_eq!(scroll_tree.get_node(id).offset(), Some(expected_offset));
let (scrolled_id, offset) = scroll_tree
.scroll_node_or_ancestor(
&external_id,
external_id,
ScrollLocation::Delta(LayoutVector2D::new(-20.0, -40.0)),
ScrollType::Script,
)
@ -68,17 +68,17 @@ fn test_scroll_tree_simple_scroll() {
let expected_offset = LayoutVector2D::new(0.0, 0.0);
assert_eq!(scrolled_id, external_id);
assert_eq!(offset, expected_offset);
assert_eq!(scroll_tree.get_node(&id).offset(), Some(expected_offset));
assert_eq!(scroll_tree.get_node(id).offset(), Some(expected_offset));
// Scroll offsets must be positive.
let result = scroll_tree.scroll_node_or_ancestor(
&external_id,
external_id,
ScrollLocation::Delta(LayoutVector2D::new(-20.0, -40.0)),
ScrollType::Script,
);
assert!(result.is_none());
assert_eq!(
scroll_tree.get_node(&id).offset(),
scroll_tree.get_node(id).offset(),
Some(LayoutVector2D::new(0.0, 0.0))
);
}
@ -92,7 +92,7 @@ fn test_scroll_tree_simple_scroll_chaining() {
let unscrollable_external_id = ExternalScrollId(100 as u64, pipeline_id);
let unscrollable_child_id = scroll_tree.add_scroll_tree_node(
Some(&parent_id),
Some(parent_id),
SpatialTreeNodeInfo::Scroll(ScrollableNodeInfo {
external_id: unscrollable_external_id,
content_rect: Size2D::new(100.0, 100.0).into(),
@ -108,7 +108,7 @@ fn test_scroll_tree_simple_scroll_chaining() {
let (scrolled_id, offset) = scroll_tree
.scroll_node_or_ancestor(
&unscrollable_external_id,
unscrollable_external_id,
ScrollLocation::Delta(LayoutVector2D::new(20.0, 40.0)),
ScrollType::Script,
)
@ -117,13 +117,13 @@ fn test_scroll_tree_simple_scroll_chaining() {
assert_eq!(scrolled_id, parent_external_id);
assert_eq!(offset, expected_offset);
assert_eq!(
scroll_tree.get_node(&parent_id).offset(),
scroll_tree.get_node(parent_id).offset(),
Some(expected_offset)
);
let (scrolled_id, offset) = scroll_tree
.scroll_node_or_ancestor(
&unscrollable_external_id,
unscrollable_external_id,
ScrollLocation::Delta(LayoutVector2D::new(10.0, 15.0)),
ScrollType::Script,
)
@ -132,11 +132,11 @@ fn test_scroll_tree_simple_scroll_chaining() {
assert_eq!(scrolled_id, parent_external_id);
assert_eq!(offset, expected_offset);
assert_eq!(
scroll_tree.get_node(&parent_id).offset(),
scroll_tree.get_node(parent_id).offset(),
Some(expected_offset)
);
assert_eq!(
scroll_tree.get_node(&unscrollable_child_id).offset(),
scroll_tree.get_node(unscrollable_child_id).offset(),
Some(LayoutVector2D::zero())
);
}
@ -149,14 +149,14 @@ fn test_scroll_tree_chain_when_at_extent() {
let (child_id, child_external_id) = add_mock_scroll_node(&mut scroll_tree);
let (scrolled_id, offset) = scroll_tree
.scroll_node_or_ancestor(&child_external_id, ScrollLocation::End, ScrollType::Script)
.scroll_node_or_ancestor(child_external_id, ScrollLocation::End, ScrollType::Script)
.unwrap();
let expected_offset = LayoutVector2D::new(0.0, 100.0);
assert_eq!(scrolled_id, child_external_id);
assert_eq!(offset, expected_offset);
assert_eq!(
scroll_tree.get_node(&child_id).offset(),
scroll_tree.get_node(child_id).offset(),
Some(expected_offset)
);
@ -164,7 +164,7 @@ fn test_scroll_tree_chain_when_at_extent() {
// of its scroll area in the y axis.
let (scrolled_id, offset) = scroll_tree
.scroll_node_or_ancestor(
&child_external_id,
child_external_id,
ScrollLocation::Delta(LayoutVector2D::new(0.0, 10.0)),
ScrollType::Script,
)
@ -173,7 +173,7 @@ fn test_scroll_tree_chain_when_at_extent() {
assert_eq!(scrolled_id, parent_external_id);
assert_eq!(offset, expected_offset);
assert_eq!(
scroll_tree.get_node(&parent_id).offset(),
scroll_tree.get_node(parent_id).offset(),
Some(expected_offset)
);
}
@ -186,7 +186,7 @@ fn test_scroll_tree_chain_through_overflow_hidden() {
// reflect `overflow: hidden` ie not responsive to non-script scroll events.
let (parent_id, parent_external_id) = add_mock_scroll_node(&mut scroll_tree);
let (overflow_hidden_id, overflow_hidden_external_id) = add_mock_scroll_node(&mut scroll_tree);
let node = scroll_tree.get_node_mut(&overflow_hidden_id);
let node = scroll_tree.get_node_mut(overflow_hidden_id);
if let SpatialTreeNodeInfo::Scroll(ref mut scroll_node_info) = node.info {
scroll_node_info.scroll_sensitivity = AxesScrollSensitivity {
@ -197,7 +197,7 @@ fn test_scroll_tree_chain_through_overflow_hidden() {
let (scrolled_id, offset) = scroll_tree
.scroll_node_or_ancestor(
&overflow_hidden_external_id,
overflow_hidden_external_id,
ScrollLocation::Delta(LayoutVector2D::new(20.0, 40.0)),
ScrollType::InputEvents,
)
@ -206,11 +206,11 @@ fn test_scroll_tree_chain_through_overflow_hidden() {
assert_eq!(scrolled_id, parent_external_id);
assert_eq!(offset, expected_offset);
assert_eq!(
scroll_tree.get_node(&parent_id).offset(),
scroll_tree.get_node(parent_id).offset(),
Some(expected_offset)
);
assert_eq!(
scroll_tree.get_node(&overflow_hidden_id).offset(),
scroll_tree.get_node(overflow_hidden_id).offset(),
Some(LayoutVector2D::new(0.0, 0.0))
);
}