| Index: cc/layers/layer_position_constraint_unittest.cc
|
| diff --git a/cc/layers/layer_position_constraint_unittest.cc b/cc/layers/layer_position_constraint_unittest.cc
|
| index 3557f7f5a1b98cf234cbbc3e4e816ff217f9d8a9..57e4c1de595b65c4dba6f7b0322d3b192830de10 100644
|
| --- a/cc/layers/layer_position_constraint_unittest.cc
|
| +++ b/cc/layers/layer_position_constraint_unittest.cc
|
| @@ -39,14 +39,13 @@
|
| 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 scroll_layer bounds are
|
| + // We are probably not testing what is intended if the root_layer bounds are
|
| // empty.
|
| - DCHECK(!scroll_layer->bounds().IsEmpty());
|
| + DCHECK(!root_layer->bounds().IsEmpty());
|
| LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
|
| root_layer, device_viewport_size, &dummy_render_surface_layer_list);
|
| inputs.device_scale_factor = device_scale_factor;
|
| @@ -67,7 +66,6 @@
|
| 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);
|
| @@ -76,8 +74,6 @@
|
|
|
| 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);
|
| @@ -89,9 +85,8 @@
|
| gfx::Transform IdentityMatrix;
|
| gfx::PointF anchor;
|
| gfx::PointF position;
|
| - gfx::Size bounds(200, 200);
|
| - gfx::Size clip_bounds(100, 100);
|
| - SetLayerPropertiesForTesting(scroll_layer.get(),
|
| + gfx::Size bounds(100, 100);
|
| + SetLayerPropertiesForTesting(root.get(),
|
| IdentityMatrix,
|
| IdentityMatrix,
|
| anchor,
|
| @@ -120,15 +115,16 @@
|
| bounds,
|
| false);
|
|
|
| - root->SetBounds(clip_bounds);
|
| - scroll_layer->SetScrollClipLayer(root->id());
|
| - child->SetScrollClipLayer(root->id());
|
| - grand_child->SetScrollClipLayer(root->id());
|
| + 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);
|
|
|
| grand_child->AddChild(great_grand_child.Pass());
|
| child->AddChild(grand_child.Pass());
|
| - scroll_layer->AddChild(child.Pass());
|
| - root->AddChild(scroll_layer.Pass());
|
| + root->AddChild(child.Pass());
|
|
|
| return root.Pass();
|
| }
|
| @@ -137,7 +133,6 @@
|
| FakeImplProxy proxy_;
|
| FakeLayerTreeHostImpl host_impl_;
|
| scoped_ptr<LayerImpl> root_;
|
| - LayerImpl* scroll_;
|
|
|
| LayerPositionConstraint fixed_to_top_left_;
|
| LayerPositionConstraint fixed_to_bottom_right_;
|
| @@ -147,7 +142,7 @@
|
| ScrollCompensationForFixedPositionLayerWithDirectContainer) {
|
| // This test checks for correct scroll compensation when the fixed-position
|
| // container is the direct parent of the fixed-position layer.
|
| - LayerImpl* child = scroll_->children()[0];
|
| + LayerImpl* child = root_->children()[0];
|
| LayerImpl* grand_child = child->children()[0];
|
|
|
| child->SetIsContainerForFixedPositionLayers(true);
|
| @@ -215,7 +210,7 @@
|
| // 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 = scroll_->children()[0];
|
| + LayerImpl* child = root_->children()[0];
|
| LayerImpl* grand_child = child->children()[0];
|
|
|
| // This scale will cause child and grand_child to be effectively 200 x 800
|
| @@ -287,7 +282,7 @@
|
| 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 = scroll_->children()[0];
|
| + LayerImpl* child = root_->children()[0];
|
| LayerImpl* grand_child = child->children()[0];
|
| LayerImpl* great_grand_child = grand_child->children()[0];
|
|
|
| @@ -367,7 +362,7 @@
|
| // 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 = scroll_->children()[0];
|
| + LayerImpl* child = root_->children()[0];
|
| LayerImpl* grand_child = child->children()[0];
|
| LayerImpl* great_grand_child = grand_child->children()[0];
|
|
|
| @@ -479,7 +474,7 @@
|
| // 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 = scroll_->children()[0];
|
| + LayerImpl* child = root_->children()[0];
|
| LayerImpl* grand_child = child->children()[0];
|
| LayerImpl* great_grand_child = grand_child->children()[0];
|
|
|
| @@ -590,7 +585,7 @@
|
| // 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 = scroll_->children()[0];
|
| + LayerImpl* child = root_->children()[0];
|
| LayerImpl* grand_child = child->children()[0];
|
| LayerImpl* great_grand_child = grand_child->children()[0];
|
|
|
| @@ -714,7 +709,7 @@
|
| // 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 = scroll_->children()[0];
|
| + LayerImpl* child = root_->children()[0];
|
| LayerImpl* grand_child = child->children()[0];
|
| LayerImpl* great_grand_child = grand_child->children()[0];
|
|
|
| @@ -901,7 +896,7 @@
|
| // 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 = scroll_->children()[0];
|
| + LayerImpl* child = root_->children()[0];
|
| LayerImpl* grand_child = child->children()[0];
|
|
|
| child->SetIsContainerForFixedPositionLayers(true);
|
| @@ -979,7 +974,7 @@
|
| // 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 = scroll_->children()[0];
|
| + LayerImpl* child = root_->children()[0];
|
| LayerImpl* grand_child = child->children()[0];
|
|
|
| child->SetIsContainerForFixedPositionLayers(true);
|
| @@ -1031,6 +1026,67 @@
|
| expected_grand_child_transform.MakeIdentity();
|
| // Apply size delta from the child(container) layer.
|
| expected_grand_child_transform.Translate(20.0, 20.0);
|
| +
|
| + 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,
|
| + 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());
|
| @@ -1046,7 +1102,7 @@
|
| // the scroll compensation, and the child fixed-position layer does not
|
| // need to compensate further.
|
|
|
| - LayerImpl* child = scroll_->children()[0];
|
| + LayerImpl* child = root_->children()[0];
|
| LayerImpl* grand_child = child->children()[0];
|
| LayerImpl* great_grand_child = grand_child->children()[0];
|
|
|
| @@ -1105,7 +1161,7 @@
|
| // position containers. In this situation, the child fixed-position element
|
| // would still have to compensate with respect to its container.
|
|
|
| - LayerImpl* container1 = scroll_->children()[0];
|
| + LayerImpl* container1 = root_->children()[0];
|
| LayerImpl* fixed_to_container1 = container1->children()[0];
|
| LayerImpl* container2 = fixed_to_container1->children()[0];
|
|
|
|
|