void SetLayerPropertiesForTesting(LayerImpl* layer,
const gfx::Transform& transform,
- const gfx::Transform& sublayer_transform,
const gfx::PointF& anchor,
const gfx::PointF& position,
- gfx::Size bounds,
- bool preserves3d) {
+ const gfx::Size& bounds,
+ bool flatten_transform,
+ bool is_3d_sorted) {
layer->SetTransform(transform);
- layer->SetSublayerTransform(sublayer_transform);
layer->SetAnchorPoint(anchor);
layer->SetPosition(position);
layer->SetBounds(bounds);
- layer->SetPreserves3d(preserves3d);
+ layer->SetShouldFlattenTransform(flatten_transform);
+ layer->SetIs3dSorted(is_3d_sorted);
layer->SetContentBounds(bounds);
}
bool can_use_lcd_text) {
gfx::Transform identity_matrix;
std::vector<LayerImpl*> dummy_render_surface_layer_list;
+ LayerImpl* scroll_layer = root_layer->children()[0];
gfx::Size device_viewport_size =
gfx::Size(root_layer->bounds().width() * device_scale_factor,
root_layer->bounds().height() * device_scale_factor);
- // We are probably not testing what is intended if the root_layer bounds are
+ // We are probably not testing what is intended if the scroll_layer bounds are
// empty.
- DCHECK(!root_layer->bounds().IsEmpty());
+ DCHECK(!scroll_layer->bounds().IsEmpty());
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root_layer, device_viewport_size, &dummy_render_surface_layer_list);
inputs.device_scale_factor = device_scale_factor;
LayerPositionConstraintTest()
: host_impl_(&proxy_) {
root_ = CreateTreeForTest();
+ scroll_ = root_->children()[0];
fixed_to_top_left_.set_is_fixed_position(true);
fixed_to_bottom_right_.set_is_fixed_position(true);
fixed_to_bottom_right_.set_is_fixed_to_right_edge(true);
scoped_ptr<LayerImpl> CreateTreeForTest() {
scoped_ptr<LayerImpl> root =
+ LayerImpl::Create(host_impl_.active_tree(), 42);
+ scoped_ptr<LayerImpl> scroll_layer =
LayerImpl::Create(host_impl_.active_tree(), 1);
scoped_ptr<LayerImpl> child =
LayerImpl::Create(host_impl_.active_tree(), 2);
gfx::Transform IdentityMatrix;
gfx::PointF anchor;
gfx::PointF position;
- gfx::Size bounds(100, 100);
- SetLayerPropertiesForTesting(root.get(),
- IdentityMatrix,
+ gfx::Size bounds(200, 200);
+ gfx::Size clip_bounds(100, 100);
+ SetLayerPropertiesForTesting(scroll_layer.get(),
IdentityMatrix,
anchor,
position,
bounds,
+ true,
false);
SetLayerPropertiesForTesting(child.get(),
IdentityMatrix,
- IdentityMatrix,
anchor,
position,
bounds,
+ true,
false);
SetLayerPropertiesForTesting(grand_child.get(),
IdentityMatrix,
- IdentityMatrix,
anchor,
position,
bounds,
+ true,
false);
SetLayerPropertiesForTesting(great_grand_child.get(),
IdentityMatrix,
- IdentityMatrix,
anchor,
position,
bounds,
+ true,
false);
- root->SetMaxScrollOffset(gfx::Vector2d(100, 100));
- root->SetScrollable(true);
- child->SetMaxScrollOffset(gfx::Vector2d(100, 100));
- child->SetScrollable(true);
- grand_child->SetMaxScrollOffset(gfx::Vector2d(100, 100));
- grand_child->SetScrollable(true);
+ root->SetBounds(clip_bounds);
+ scroll_layer->SetScrollClipLayer(root->id());
+ child->SetScrollClipLayer(root->id());
+ grand_child->SetScrollClipLayer(root->id());
grand_child->AddChild(great_grand_child.Pass());
child->AddChild(grand_child.Pass());
- root->AddChild(child.Pass());
+ scroll_layer->AddChild(child.Pass());
+ root->AddChild(scroll_layer.Pass());
return root.Pass();
}
FakeImplProxy proxy_;
FakeLayerTreeHostImpl host_impl_;
scoped_ptr<LayerImpl> root_;
+ LayerImpl* scroll_;
LayerPositionConstraint fixed_to_top_left_;
LayerPositionConstraint fixed_to_bottom_right_;
};
+namespace {
+
+void SetFixedContainerSizeDelta(LayerImpl* scroll_layer,
+ const gfx::Vector2d& delta) {
+ DCHECK(scroll_layer);
+ DCHECK(scroll_layer->scrollable());
+
+ LayerImpl* container_layer = scroll_layer->scroll_clip_layer();
+ gfx::Size container_size(container_layer->bounds());
+ gfx::Size new_container_size(container_size.width() + delta.x(),
+ container_size.height() + delta.y());
+ container_layer->SetTemporaryImplBounds(new_container_size);
+}
+} // namespace
+
TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedPositionLayerWithDirectContainer) {
// This test checks for correct scroll compensation when the fixed-position
// container is the direct parent of the fixed-position layer.
- LayerImpl* child = root_->children()[0];
+ LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
child->SetIsContainerForFixedPositionLayers(true);
grand_child->draw_transform());
// Case 3: fixed-container size delta of 20, 20
- child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
+ SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
// Top-left fixed-position layer should not be affected by container size.
// Transforms are in general non-commutative; using something like a
// non-uniform scale helps to verify that translations and non-uniform scales
// are applied in the correct order.
- LayerImpl* child = root_->children()[0];
+ LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
// This scale will cause child and grand_child to be effectively 200 x 800
grand_child->draw_transform());
// Case 3: fixed-container size delta of 20, 20
- child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
+ SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
// Top-left fixed-position layer should not be affected by container size.
ScrollCompensationForFixedPositionLayerWithDistantContainer) {
// This test checks for correct scroll compensation when the fixed-position
// container is NOT the direct parent of the fixed-position layer.
- LayerImpl* child = root_->children()[0];
+ LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
great_grand_child->draw_transform());
// Case 3: fixed-container size delta of 20, 20
- child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
+ SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
// Top-left fixed-position layer should not be affected by container size.
// container is NOT the direct parent of the fixed-position layer, and the
// hierarchy has various transforms that have to be processed in the correct
// order.
- LayerImpl* child = root_->children()[0];
+ LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
great_grand_child->draw_transform());
// Case 3: fixed-container size delta of 20, 20
- child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
+ SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
// Top-left fixed-position layer should not be affected by container size.
// container is NOT the direct parent of the fixed-position layer, and the
// hierarchy has various transforms that have to be processed in the correct
// order.
- LayerImpl* child = root_->children()[0];
+ LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
great_grand_child->draw_transform());
// Case 3: fixed-container size delta of 20, 20
- child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
+ SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
// Top-left fixed-position layer should not be affected by container size.
// container contributes to a different render surface than the fixed-position
// layer. In this case, the surface draw transforms also have to be accounted
// for when checking the scroll delta.
- LayerImpl* child = root_->children()[0];
+ LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
great_grand_child->draw_transform());
// Case 3: fixed-container size delta of 20, 20
- child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
+ SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
// Top-left fixed-position layer should not be affected by container size.
// layer, with additional render surfaces in-between. This checks that the
// conversion to ancestor surfaces is accumulated properly in the final matrix
// transform.
- LayerImpl* child = root_->children()[0];
+ LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
LayerImpl::Create(host_impl_.active_tree(), 5);
SetLayerPropertiesForTesting(fixed_position_child.get(),
identity,
- identity,
gfx::PointF(),
gfx::PointF(),
gfx::Size(100, 100),
+ true,
false);
great_grand_child->AddChild(fixed_position_child.Pass());
}
// Case 3: fixed-container size delta of 20, 20
- child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
+ SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
// Top-left fixed-position layer should not be affected by container size.
// should be treated like a layer that contributes to a render target, and
// that render target is completely irrelevant; it should not affect the
// scroll compensation.
- LayerImpl* child = root_->children()[0];
+ LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
child->SetIsContainerForFixedPositionLayers(true);
grand_child->draw_transform());
// Case 3: fixed-container size delta of 20, 20
- child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
+ SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
// Top-left fixed-position layer should not be affected by container size.
// This test checks the scenario where a fixed-position layer also happens to
// be a container itself for a descendant fixed position layer. In particular,
// the layer should not accidentally be fixed to itself.
- LayerImpl* child = root_->children()[0];
+ LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
child->SetIsContainerForFixedPositionLayers(true);
grand_child->draw_transform());
// Case 3: fixed-container size delta of 20, 20
- child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
+ SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
// Top-left fixed-position layer should not be affected by container size.
}
TEST_F(LayerPositionConstraintTest,
- ScrollCompensationForFixedPositionLayerThatHasNoContainer) {
- // This test checks scroll compensation when a fixed-position layer does not
- // find any ancestor that is a "containerForFixedPositionLayers". In this
- // situation, the layer should be fixed to the root layer.
- LayerImpl* child = root_->children()[0];
- LayerImpl* grand_child = child->children()[0];
-
- gfx::Transform rotation_by_z;
- rotation_by_z.RotateAboutZAxis(90.0);
-
- root_->SetTransform(rotation_by_z);
- grand_child->SetPositionConstraint(fixed_to_top_left_);
-
- // Case 1: root scroll delta of 0, 0
- root_->SetScrollDelta(gfx::Vector2d(0, 0));
- ExecuteCalculateDrawProperties(root_.get());
-
- gfx::Transform identity_matrix;
-
- EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z, child->draw_transform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z,
- grand_child->draw_transform());
-
- // Case 2: root scroll delta of 10, 10
- root_->SetScrollDelta(gfx::Vector2d(10, 20));
- ExecuteCalculateDrawProperties(root_.get());
-
- gfx::Transform expected_child_transform;
- expected_child_transform.Translate(-10.0, -20.0);
- expected_child_transform.PreconcatTransform(rotation_by_z);
-
- EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
- child->draw_transform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z,
- grand_child->draw_transform());
-
- // Case 3: fixed-container size delta of 20, 20
- root_->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
- ExecuteCalculateDrawProperties(root_.get());
-
- // Top-left fixed-position layer should not be affected by container size.
- EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
- child->draw_transform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_by_z,
- grand_child->draw_transform());
-
- // Case 4: Bottom-right fixed-position layer.
- grand_child->SetPositionConstraint(fixed_to_bottom_right_);
- ExecuteCalculateDrawProperties(root_.get());
-
- gfx::Transform expected_grand_child_transform;
- expected_grand_child_transform.Translate(-20.0, 20.0);
- expected_grand_child_transform.PreconcatTransform(rotation_by_z);
-
- EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
- child->draw_transform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform,
- grand_child->draw_transform());
-}
-
-TEST_F(LayerPositionConstraintTest,
ScrollCompensationForFixedWithinFixedWithSameContainer) {
// This test checks scroll compensation for a fixed-position layer that is
// inside of another fixed-position layer and both share the same container.
// the scroll compensation, and the child fixed-position layer does not
// need to compensate further.
- LayerImpl* child = root_->children()[0];
+ LayerImpl* child = scroll_->children()[0];
LayerImpl* grand_child = child->children()[0];
LayerImpl* great_grand_child = grand_child->children()[0];
// Case 2: sizeDelta
child->SetScrollDelta(gfx::Vector2d(0, 0));
- child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20));
+ SetFixedContainerSizeDelta(child, gfx::Vector2d(20, 20));
ExecuteCalculateDrawProperties(root_.get());
expected_child_transform.MakeIdentity();
// position containers. In this situation, the child fixed-position element
// would still have to compensate with respect to its container.
- LayerImpl* container1 = root_->children()[0];
+ LayerImpl* container1 = scroll_->children()[0];
LayerImpl* fixed_to_container1 = container1->children()[0];
LayerImpl* container2 = fixed_to_container1->children()[0];
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_to_container2_transform,
fixed_to_container2->draw_transform());
}
-
} // namespace
} // namespace cc