Bug 1604280 - Fix a bug in SpatialTree::get_world_transform_impl(). r=gw

The first branch (where the node is in the root coordinate system)
was not handling the TransformScroll::Unscrolled case, which should
use the scale/offset from the viewport transform rather than the
content transform.

Differential Revision: https://phabricator.services.mozilla.com/D196692
This commit is contained in:
Botond Ballo 2023-12-21 19:02:32 +00:00
Родитель 11ffdd4348
Коммит 8dd9084e61
1 изменённых файлов: 39 добавлений и 1 удалений

Просмотреть файл

@ -1077,7 +1077,10 @@ impl SpatialTree {
if index == self.root_reference_frame_index {
CoordinateSpaceMapping::Local
} else {
CoordinateSpaceMapping::ScaleOffset(child.content_transform)
match scroll {
TransformScroll::Scrolled => CoordinateSpaceMapping::ScaleOffset(child.content_transform),
TransformScroll::Unscrolled => CoordinateSpaceMapping::ScaleOffset(child.viewport_transform),
}
}
} else {
let system = &self.coord_systems[child.coordinate_system_id.0 as usize];
@ -2004,3 +2007,38 @@ fn test_find_scroll_root_2d_scale() {
assert_eq!(st.find_scroll_root(sub_scroll), sub_scroll);
}
#[test]
fn test_world_transforms() {
// Create a spatial tree with a scroll frame node with scroll offset (0, 200).
let mut cst = SceneSpatialTree::new();
let pid = PipelineInstanceId::new(0);
let scroll = cst.add_scroll_frame(
cst.root_reference_frame_index(),
ExternalScrollId(1, PipelineId::dummy()),
PipelineId::dummy(),
&LayoutRect::from_size(LayoutSize::new(400.0, 400.0)),
&LayoutSize::new(400.0, 800.0),
ScrollFrameKind::Explicit,
LayoutVector2D::new(0.0, 200.0),
APZScrollGeneration::default(),
HasScrollLinkedEffect::No,
SpatialNodeUid::external(SpatialTreeItemKey::new(0, 1), PipelineId::dummy(), pid));
let mut st = SpatialTree::new();
st.apply_updates(cst.end_frame_and_get_pending_updates());
st.update_tree(&SceneProperties::new());
// The node's world transform should reflect the scroll offset,
// e.g. here it should be (0, -200) to reflect that the content has been
// scrolled up by 200px.
assert_eq!(
st.get_world_transform(scroll).into_transform(),
LayoutToWorldTransform::translation(0.0, -200.0, 0.0));
// The node's world viewport transform only reflects enclosing scrolling
// or transforms. Here we don't have any, so it should be the identity.
assert_eq!(
st.get_world_viewport_transform(scroll).into_transform(),
LayoutToWorldTransform::identity());
}