| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 | 1048 |
| 1049 overflow->set_user_scrollable_horizontal(false); | 1049 overflow->set_user_scrollable_horizontal(false); |
| 1050 | 1050 |
| 1051 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 1051 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 1052 host_impl_->ScrollBegin(scroll_position, InputHandler::WHEEL)); | 1052 host_impl_->ScrollBegin(scroll_position, InputHandler::WHEEL)); |
| 1053 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->CurrentScrollOffset()); | 1053 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->CurrentScrollOffset()); |
| 1054 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 10), overflow->CurrentScrollOffset()); | 1054 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 10), overflow->CurrentScrollOffset()); |
| 1055 | 1055 |
| 1056 host_impl_->ScrollBy(scroll_position, scroll_delta); | 1056 host_impl_->ScrollBy(scroll_position, scroll_delta); |
| 1057 host_impl_->ScrollEnd(); | 1057 host_impl_->ScrollEnd(); |
| 1058 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 0), scroll_layer->CurrentScrollOffset()); | 1058 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), scroll_layer->CurrentScrollOffset()); |
| 1059 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); | 1059 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); |
| 1060 | 1060 |
| 1061 overflow->set_user_scrollable_vertical(false); | 1061 overflow->set_user_scrollable_vertical(false); |
| 1062 | 1062 |
| 1063 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 1063 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 1064 host_impl_->ScrollBegin(scroll_position, InputHandler::WHEEL)); | 1064 host_impl_->ScrollBegin(scroll_position, InputHandler::WHEEL)); |
| 1065 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 0), scroll_layer->CurrentScrollOffset()); | 1065 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), scroll_layer->CurrentScrollOffset()); |
| 1066 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); | 1066 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); |
| 1067 | 1067 |
| 1068 host_impl_->ScrollBy(scroll_position, scroll_delta); | 1068 host_impl_->ScrollBy(scroll_position, scroll_delta); |
| 1069 host_impl_->ScrollEnd(); | 1069 host_impl_->ScrollEnd(); |
| 1070 EXPECT_VECTOR_EQ(gfx::Vector2dF(20, 10), scroll_layer->CurrentScrollOffset()); | 1070 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 10), scroll_layer->CurrentScrollOffset()); |
| 1071 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); | 1071 EXPECT_VECTOR_EQ(gfx::Vector2dF(10, 20), overflow->CurrentScrollOffset()); |
| 1072 } | 1072 } |
| 1073 | 1073 |
| 1074 TEST_F(LayerTreeHostImplTest, AnimationSchedulingPendingTree) { | 1074 TEST_F(LayerTreeHostImplTest, AnimationSchedulingPendingTree) { |
| 1075 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 1075 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1076 | 1076 |
| 1077 host_impl_->CreatePendingTree(); | 1077 host_impl_->CreatePendingTree(); |
| 1078 host_impl_->pending_tree()->SetRootLayer( | 1078 host_impl_->pending_tree()->SetRootLayer( |
| 1079 LayerImpl::Create(host_impl_->pending_tree(), 1)); | 1079 LayerImpl::Create(host_impl_->pending_tree(), 1)); |
| 1080 LayerImpl* root = host_impl_->pending_tree()->root_layer(); | 1080 LayerImpl* root = host_impl_->pending_tree()->root_layer(); |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); | 1500 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); |
| 1501 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 1501 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 1502 host_impl_->QueueSwapPromiseForMainThreadScrollUpdate(swap_promise.Pass()); | 1502 host_impl_->QueueSwapPromiseForMainThreadScrollUpdate(swap_promise.Pass()); |
| 1503 host_impl_->ScrollEnd(); | 1503 host_impl_->ScrollEnd(); |
| 1504 | 1504 |
| 1505 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 1505 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
| 1506 EXPECT_EQ(1u, scroll_info->swap_promises.size()); | 1506 EXPECT_EQ(1u, scroll_info->swap_promises.size()); |
| 1507 EXPECT_EQ(latency_info.trace_id(), scroll_info->swap_promises[0]->TraceId()); | 1507 EXPECT_EQ(latency_info.trace_id(), scroll_info->swap_promises[0]->TraceId()); |
| 1508 } | 1508 } |
| 1509 | 1509 |
| 1510 // Test that scrolls targeting a layer with a non-null scroll_parent() bubble | 1510 // Test that scrolls targeting a layer with a non-null scroll_parent() don't |
| 1511 // up to the scroll_parent, rather than the stacking parent. | 1511 // bubble up. |
| 1512 TEST_F(LayerTreeHostImplTest, ScrollBubblesToScrollParent) { | 1512 TEST_F(LayerTreeHostImplTest, ScrollDoesntBubble) { |
| 1513 LayerImpl* viewport_scroll = | 1513 LayerImpl* viewport_scroll = |
| 1514 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 1514 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 1515 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 1515 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 1516 | 1516 |
| 1517 // Set up two scrolling children of the root, one of which is a scroll parent | 1517 // Set up two scrolling children of the root, one of which is a scroll parent |
| 1518 // to the other. Scrolls bubbling from the child should bubble to the parent, | 1518 // to the other. Scrolls shouldn't bubbling from the child. |
| 1519 // not the viewport. | |
| 1520 LayerImpl *parent; | 1519 LayerImpl *parent; |
| 1521 LayerImpl *child; | 1520 LayerImpl *child; |
| 1522 LayerImpl *child_clip; | 1521 LayerImpl *child_clip; |
| 1523 | 1522 |
| 1524 scoped_ptr<LayerImpl> scroll_parent_clip = | 1523 scoped_ptr<LayerImpl> scroll_parent_clip = |
| 1525 LayerImpl::Create(host_impl_->active_tree(), 6); | 1524 LayerImpl::Create(host_impl_->active_tree(), 6); |
| 1526 scoped_ptr<LayerImpl> scroll_parent = CreateScrollableLayer( | 1525 scoped_ptr<LayerImpl> scroll_parent = CreateScrollableLayer( |
| 1527 7, gfx::Size(10, 10), scroll_parent_clip.get()); | 1526 7, gfx::Size(10, 10), scroll_parent_clip.get()); |
| 1528 parent = scroll_parent.get(); | 1527 parent = scroll_parent.get(); |
| 1529 scroll_parent_clip->AddChild(scroll_parent.Pass()); | 1528 scroll_parent_clip->AddChild(scroll_parent.Pass()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1541 child_clip = scroll_child_clip.get(); | 1540 child_clip = scroll_child_clip.get(); |
| 1542 viewport_scroll->AddChild(scroll_child_clip.Pass()); | 1541 viewport_scroll->AddChild(scroll_child_clip.Pass()); |
| 1543 | 1542 |
| 1544 child_clip->SetScrollParent(parent); | 1543 child_clip->SetScrollParent(parent); |
| 1545 | 1544 |
| 1546 DrawFrame(); | 1545 DrawFrame(); |
| 1547 | 1546 |
| 1548 { | 1547 { |
| 1549 host_impl_->ScrollBegin(gfx::Point(21, 21), InputHandler::GESTURE); | 1548 host_impl_->ScrollBegin(gfx::Point(21, 21), InputHandler::GESTURE); |
| 1550 host_impl_->ScrollBy(gfx::Point(21, 21), gfx::Vector2d(5, 5)); | 1549 host_impl_->ScrollBy(gfx::Point(21, 21), gfx::Vector2d(5, 5)); |
| 1551 host_impl_->ScrollBy(gfx::Point(21, 21), gfx::Vector2d(2, 1)); | 1550 host_impl_->ScrollBy(gfx::Point(21, 21), gfx::Vector2d(100, 100)); |
| 1552 host_impl_->ScrollEnd(); | 1551 host_impl_->ScrollEnd(); |
| 1553 | 1552 |
| 1554 // The child should be fully scrolled by the first ScrollBy. | 1553 // The child should be fully scrolled by the first ScrollBy. |
| 1555 EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 5), child->CurrentScrollOffset()); | 1554 EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 5), child->CurrentScrollOffset()); |
| 1556 | 1555 |
| 1557 // The scroll_parent should receive the bubbled up second ScrollBy. | 1556 // The scroll_parent shouldn't receive the second ScrollBy. |
| 1558 EXPECT_VECTOR_EQ(gfx::Vector2dF(2, 1), parent->CurrentScrollOffset()); | 1557 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), parent->CurrentScrollOffset()); |
| 1559 | 1558 |
| 1560 // The viewport shouldn't have been scrolled at all. | 1559 // The viewport shouldn't have been scrolled at all. |
| 1561 EXPECT_VECTOR_EQ( | 1560 EXPECT_VECTOR_EQ( |
| 1562 gfx::Vector2dF(0, 0), | 1561 gfx::Vector2dF(0, 0), |
| 1563 host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); | 1562 host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 1564 EXPECT_VECTOR_EQ( | 1563 EXPECT_VECTOR_EQ( |
| 1565 gfx::Vector2dF(0, 0), | 1564 gfx::Vector2dF(0, 0), |
| 1566 host_impl_->OuterViewportScrollLayer()->CurrentScrollOffset()); | 1565 host_impl_->OuterViewportScrollLayer()->CurrentScrollOffset()); |
| 1567 } | 1566 } |
| 1568 | 1567 |
| 1569 { | 1568 { |
| 1570 host_impl_->ScrollBegin(gfx::Point(21, 21), InputHandler::GESTURE); | 1569 host_impl_->ScrollBegin(gfx::Point(21, 21), InputHandler::GESTURE); |
| 1571 host_impl_->ScrollBy(gfx::Point(21, 21), gfx::Vector2d(3, 4)); | 1570 host_impl_->ScrollBy(gfx::Point(21, 21), gfx::Vector2d(3, 4)); |
| 1572 host_impl_->ScrollBy(gfx::Point(21, 21), gfx::Vector2d(2, 1)); | 1571 host_impl_->ScrollBy(gfx::Point(21, 21), gfx::Vector2d(2, 1)); |
| 1572 host_impl_->ScrollBy(gfx::Point(21, 21), gfx::Vector2d(2, 1)); |
| 1573 host_impl_->ScrollBy(gfx::Point(21, 21), gfx::Vector2d(2, 1)); |
| 1573 host_impl_->ScrollEnd(); | 1574 host_impl_->ScrollEnd(); |
| 1574 | 1575 |
| 1575 // The first ScrollBy should scroll the parent to its extent. | 1576 // The ScrollBy's should scroll the parent to its extent. |
| 1576 EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 5), parent->CurrentScrollOffset()); | 1577 EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 5), parent->CurrentScrollOffset()); |
| 1577 | 1578 |
| 1578 // The viewport should now be next in bubbling order. | 1579 // The viewport shouldn't receive any scroll delta. |
| 1579 EXPECT_VECTOR_EQ( | 1580 EXPECT_VECTOR_EQ( |
| 1580 gfx::Vector2dF(2, 1), | 1581 gfx::Vector2dF(0, 0), |
| 1581 host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); | 1582 host_impl_->InnerViewportScrollLayer()->CurrentScrollOffset()); |
| 1582 EXPECT_VECTOR_EQ( | 1583 EXPECT_VECTOR_EQ( |
| 1583 gfx::Vector2dF(0, 0), | 1584 gfx::Vector2dF(0, 0), |
| 1584 host_impl_->OuterViewportScrollLayer()->CurrentScrollOffset()); | 1585 host_impl_->OuterViewportScrollLayer()->CurrentScrollOffset()); |
| 1585 } | 1586 } |
| 1586 } | 1587 } |
| 1587 | 1588 |
| 1588 | 1589 |
| 1589 TEST_F(LayerTreeHostImplTest, PinchGesture) { | 1590 TEST_F(LayerTreeHostImplTest, PinchGesture) { |
| 1590 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 1591 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| (...skipping 2072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3663 | 3664 |
| 3664 EXPECT_EQ(top_controls_height_, | 3665 EXPECT_EQ(top_controls_height_, |
| 3665 host_impl_->top_controls_manager()->ContentTopOffset()); | 3666 host_impl_->top_controls_manager()->ContentTopOffset()); |
| 3666 | 3667 |
| 3667 // Send a gesture scroll that will scroll the outer viewport, make sure the | 3668 // Send a gesture scroll that will scroll the outer viewport, make sure the |
| 3668 // top controls get scrolled. | 3669 // top controls get scrolled. |
| 3669 gfx::Vector2dF scroll_delta(0.f, 15.f); | 3670 gfx::Vector2dF scroll_delta(0.f, 15.f); |
| 3670 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 3671 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 3671 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); | 3672 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); |
| 3672 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 3673 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
| 3674 |
| 3673 EXPECT_EQ(host_impl_->InnerViewportScrollLayer(), | 3675 EXPECT_EQ(host_impl_->InnerViewportScrollLayer(), |
| 3674 host_impl_->CurrentlyScrollingLayer()); | 3676 host_impl_->CurrentlyScrollingLayer()); |
| 3675 host_impl_->ScrollEnd(); | 3677 host_impl_->ScrollEnd(); |
| 3676 | 3678 |
| 3677 EXPECT_FLOAT_EQ(scroll_delta.y(), | 3679 EXPECT_FLOAT_EQ(scroll_delta.y(), |
| 3678 top_controls_height_ - | 3680 top_controls_height_ - |
| 3679 host_impl_->top_controls_manager()->ContentTopOffset()); | 3681 host_impl_->top_controls_manager()->ContentTopOffset()); |
| 3680 | 3682 |
| 3681 scroll_delta = gfx::Vector2dF(0.f, 50.f); | 3683 scroll_delta = gfx::Vector2dF(0.f, 50.f); |
| 3682 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 3684 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4061 // The scroll range should not have changed. | 4063 // The scroll range should not have changed. |
| 4062 EXPECT_EQ(outer_scroll->MaxScrollOffset(), expected_max_scroll); | 4064 EXPECT_EQ(outer_scroll->MaxScrollOffset(), expected_max_scroll); |
| 4063 | 4065 |
| 4064 // The page scale delta remains constant because the impl thread did not | 4066 // The page scale delta remains constant because the impl thread did not |
| 4065 // scale. | 4067 // scale. |
| 4066 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); | 4068 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
| 4067 } | 4069 } |
| 4068 | 4070 |
| 4069 TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { | 4071 TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { |
| 4070 // Scroll a child layer beyond its maximum scroll range and make sure the | 4072 // Scroll a child layer beyond its maximum scroll range and make sure the |
| 4071 // parent layer is scrolled on the axis on which the child was unable to | 4073 // parent layer isn't scrolled. |
| 4072 // scroll. | |
| 4073 gfx::Size surface_size(10, 10); | 4074 gfx::Size surface_size(10, 10); |
| 4074 gfx::Size content_size(20, 20); | 4075 gfx::Size content_size(20, 20); |
| 4075 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 4076 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 4076 root->SetBounds(surface_size); | 4077 root->SetBounds(surface_size); |
| 4077 root->SetHasRenderSurface(true); | 4078 root->SetHasRenderSurface(true); |
| 4078 scoped_ptr<LayerImpl> grand_child = | 4079 scoped_ptr<LayerImpl> grand_child = |
| 4079 CreateScrollableLayer(3, content_size, root.get()); | 4080 CreateScrollableLayer(3, content_size, root.get()); |
| 4080 | 4081 |
| 4081 scoped_ptr<LayerImpl> child = | 4082 scoped_ptr<LayerImpl> child = |
| 4082 CreateScrollableLayer(2, content_size, root.get()); | 4083 CreateScrollableLayer(2, content_size, root.get()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4101 | 4102 |
| 4102 scoped_ptr<ScrollAndScaleSet> scroll_info = | 4103 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 4103 host_impl_->ProcessScrollDeltas(); | 4104 host_impl_->ProcessScrollDeltas(); |
| 4104 | 4105 |
| 4105 // The grand child should have scrolled up to its limit. | 4106 // The grand child should have scrolled up to its limit. |
| 4106 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; | 4107 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; |
| 4107 LayerImpl* grand_child = child->children()[0]; | 4108 LayerImpl* grand_child = child->children()[0]; |
| 4108 EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), | 4109 EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 4109 gfx::Vector2d(0, -5))); | 4110 gfx::Vector2d(0, -5))); |
| 4110 | 4111 |
| 4111 // The child should have only scrolled on the other axis. | 4112 // The child should not have scrolled. |
| 4112 EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child->id(), | 4113 ExpectNone(*scroll_info.get(), child->id()); |
| 4113 gfx::Vector2d(-3, 0))); | |
| 4114 } | 4114 } |
| 4115 } | 4115 } |
| 4116 | 4116 |
| 4117 TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { | 4117 TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { |
| 4118 // Scroll a child layer beyond its maximum scroll range and make sure the | 4118 // Scroll a child layer beyond its maximum scroll range and make sure the |
| 4119 // the scroll doesn't bubble up to the parent layer. | 4119 // the scroll doesn't bubble up to the parent layer. |
| 4120 gfx::Size surface_size(20, 20); | 4120 gfx::Size surface_size(20, 20); |
| 4121 gfx::Size viewport_size(10, 10); | 4121 gfx::Size viewport_size(10, 10); |
| 4122 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 4122 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 4123 root->SetHasRenderSurface(true); | 4123 root->SetHasRenderSurface(true); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4402 } | 4402 } |
| 4403 { | 4403 { |
| 4404 // Now reset and scroll the same amount horizontally. | 4404 // Now reset and scroll the same amount horizontally. |
| 4405 child_ptr->SetScrollDelta(gfx::Vector2dF()); | 4405 child_ptr->SetScrollDelta(gfx::Vector2dF()); |
| 4406 gfx::Vector2d gesture_scroll_delta(10, 0); | 4406 gfx::Vector2d gesture_scroll_delta(10, 0); |
| 4407 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 4407 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 4408 host_impl_->ScrollBegin(gfx::Point(1, 1), InputHandler::GESTURE)); | 4408 host_impl_->ScrollBegin(gfx::Point(1, 1), InputHandler::GESTURE)); |
| 4409 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 4409 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
| 4410 host_impl_->ScrollEnd(); | 4410 host_impl_->ScrollEnd(); |
| 4411 | 4411 |
| 4412 // The child layer should have scrolled down in its local coordinates an | 4412 // The child layer shouldn't have scrolled. |
| 4413 // amount proportional to the angle between it and the input scroll delta. | |
| 4414 gfx::Vector2d expected_scroll_delta( | 4413 gfx::Vector2d expected_scroll_delta( |
| 4415 0, -gesture_scroll_delta.x() * | 4414 0, -gesture_scroll_delta.x() * |
| 4416 std::sin(MathUtil::Deg2Rad(child_layer_angle))); | 4415 std::sin(MathUtil::Deg2Rad(child_layer_angle))); |
| 4417 scoped_ptr<ScrollAndScaleSet> scroll_info = | 4416 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 4418 host_impl_->ProcessScrollDeltas(); | 4417 host_impl_->ProcessScrollDeltas(); |
| 4419 EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child_layer_id, | 4418 EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child_layer_id, |
| 4420 expected_scroll_delta)); | 4419 expected_scroll_delta)); |
| 4421 | 4420 |
| 4422 // The root scroll layer should have scrolled more, since the input scroll | 4421 // The root scroll layer shouldn't have scrolled. |
| 4423 // delta was mostly orthogonal to the child layer's vertical scroll axis. | 4422 ExpectNone(*scroll_info.get(), scroll_layer->id()); |
| 4424 gfx::Vector2d expected_root_scroll_delta( | |
| 4425 gesture_scroll_delta.x() * | |
| 4426 std::pow(std::cos(MathUtil::Deg2Rad(child_layer_angle)), 2), | |
| 4427 0); | |
| 4428 EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), scroll_layer->id(), | |
| 4429 expected_root_scroll_delta)); | |
| 4430 } | 4423 } |
| 4431 } | 4424 } |
| 4432 | 4425 |
| 4433 TEST_F(LayerTreeHostImplTest, ScrollPerspectiveTransformedLayer) { | 4426 TEST_F(LayerTreeHostImplTest, ScrollPerspectiveTransformedLayer) { |
| 4434 // When scrolling an element with perspective, the distance scrolled | 4427 // When scrolling an element with perspective, the distance scrolled |
| 4435 // depends on the point at which the scroll begins. | 4428 // depends on the point at which the scroll begins. |
| 4436 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 4429 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 4437 int child_clip_layer_id = 6; | 4430 int child_clip_layer_id = 6; |
| 4438 int child_layer_id = 7; | 4431 int child_layer_id = 7; |
| 4439 | 4432 |
| (...skipping 2259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6699 | 6692 |
| 6700 scoped_ptr<ScrollAndScaleSet> scroll_info = | 6693 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 6701 host_impl_->ProcessScrollDeltas(); | 6694 host_impl_->ProcessScrollDeltas(); |
| 6702 | 6695 |
| 6703 // Only the child should have scrolled. | 6696 // Only the child should have scrolled. |
| 6704 ASSERT_EQ(1u, scroll_info->scrolls.size()); | 6697 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
| 6705 ExpectNone(*scroll_info.get(), root_id); | 6698 ExpectNone(*scroll_info.get(), root_id); |
| 6706 } | 6699 } |
| 6707 } | 6700 } |
| 6708 | 6701 |
| 6709 TEST_F(LayerTreeHostImplTest, TouchFlingShouldLockToFirstScrolledLayer) { | 6702 TEST_F(LayerTreeHostImplTest, TouchFlingShouldContinueScrollingCurrentLayer) { |
| 6710 // Scroll a child layer beyond its maximum scroll range and make sure the | 6703 // Scroll a child layer beyond its maximum scroll range and make sure the |
| 6711 // the scroll doesn't bubble up to the parent layer. | 6704 // the scroll doesn't bubble up to the parent layer. |
| 6712 gfx::Size surface_size(10, 10); | 6705 gfx::Size surface_size(10, 10); |
| 6713 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 6706 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 6714 root->SetHasRenderSurface(true); | 6707 root->SetHasRenderSurface(true); |
| 6715 scoped_ptr<LayerImpl> root_scrolling = | 6708 scoped_ptr<LayerImpl> root_scrolling = |
| 6716 CreateScrollableLayer(2, surface_size, root.get()); | 6709 CreateScrollableLayer(2, surface_size, root.get()); |
| 6717 | 6710 |
| 6718 scoped_ptr<LayerImpl> grand_child = | 6711 scoped_ptr<LayerImpl> grand_child = |
| 6719 CreateScrollableLayer(4, surface_size, root.get()); | 6712 CreateScrollableLayer(4, surface_size, root.get()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 6741 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); | 6734 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); |
| 6742 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); | 6735 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); |
| 6743 | 6736 |
| 6744 // The grand child should have scrolled up to its limit. | 6737 // The grand child should have scrolled up to its limit. |
| 6745 scroll_info = host_impl_->ProcessScrollDeltas(); | 6738 scroll_info = host_impl_->ProcessScrollDeltas(); |
| 6746 ASSERT_EQ(1u, scroll_info->scrolls.size()); | 6739 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
| 6747 EXPECT_TRUE( | 6740 EXPECT_TRUE( |
| 6748 ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); | 6741 ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); |
| 6749 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 6742 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 6750 | 6743 |
| 6751 // The child should have received the bubbled delta, but the locked | 6744 // The locked scrolling layer should remain set as the grand child. |
| 6752 // scrolling layer should remain set as the grand child. | 6745 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); |
| 6753 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); | |
| 6754 scroll_info = host_impl_->ProcessScrollDeltas(); | 6746 scroll_info = host_impl_->ProcessScrollDeltas(); |
| 6755 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 6747 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
| 6756 EXPECT_TRUE( | 6748 EXPECT_TRUE( |
| 6757 ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); | 6749 ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); |
| 6758 EXPECT_TRUE(ScrollInfoContains(*scroll_info, child->id(), scroll_delta)); | 6750 ExpectNone(*scroll_info, child->id()); |
| 6759 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 6751 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 6760 | 6752 |
| 6761 // The first |ScrollBy| after the fling should re-lock the scrolling | |
| 6762 // layer to the first layer that scrolled, which is the child. | |
| 6763 EXPECT_EQ(InputHandler::SCROLL_STARTED, host_impl_->FlingScrollBegin()); | 6753 EXPECT_EQ(InputHandler::SCROLL_STARTED, host_impl_->FlingScrollBegin()); |
| 6764 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); | 6754 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); |
| 6765 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); | 6755 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 6766 | 6756 |
| 6767 // The child should have scrolled up to its limit. | 6757 // The child should not have scrolled. |
| 6768 scroll_info = host_impl_->ProcessScrollDeltas(); | 6758 scroll_info = host_impl_->ProcessScrollDeltas(); |
| 6769 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 6759 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
| 6770 EXPECT_TRUE( | 6760 EXPECT_TRUE( |
| 6771 ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); | 6761 ScrollInfoContains(*scroll_info, grand_child->id(), scroll_delta)); |
| 6772 EXPECT_TRUE(ScrollInfoContains(*scroll_info, child->id(), | 6762 ExpectNone(*scroll_info, child->id()); |
| 6773 scroll_delta + scroll_delta)); | |
| 6774 | 6763 |
| 6775 // As the locked layer is at it's limit, no further scrolling can occur. | 6764 // As the locked layer is at it's limit, no further scrolling can occur. |
| 6776 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); | 6765 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); |
| 6777 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); | 6766 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 6778 host_impl_->ScrollEnd(); | 6767 host_impl_->ScrollEnd(); |
| 6779 } | 6768 } |
| 6780 } | 6769 } |
| 6781 | 6770 |
| 6782 TEST_F(LayerTreeHostImplTest, WheelFlingShouldBubble) { | 6771 TEST_F(LayerTreeHostImplTest, WheelFlingShouldntBubble) { |
| 6783 // When flinging via wheel, the root should eventually scroll (we should | 6772 // When flinging via wheel, we shouldn't bubble. |
| 6784 // bubble). | |
| 6785 gfx::Size surface_size(10, 10); | 6773 gfx::Size surface_size(10, 10); |
| 6786 gfx::Size content_size(20, 20); | 6774 gfx::Size content_size(20, 20); |
| 6787 scoped_ptr<LayerImpl> root_clip = | 6775 scoped_ptr<LayerImpl> root_clip = |
| 6788 LayerImpl::Create(host_impl_->active_tree(), 3); | 6776 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 6789 root_clip->SetHasRenderSurface(true); | 6777 root_clip->SetHasRenderSurface(true); |
| 6790 scoped_ptr<LayerImpl> root_scroll = | 6778 scoped_ptr<LayerImpl> root_scroll = |
| 6791 CreateScrollableLayer(1, content_size, root_clip.get()); | 6779 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 6792 int root_scroll_id = root_scroll->id(); | 6780 int root_scroll_id = root_scroll->id(); |
| 6793 scoped_ptr<LayerImpl> child = | 6781 scoped_ptr<LayerImpl> child = |
| 6794 CreateScrollableLayer(2, content_size, root_clip.get()); | 6782 CreateScrollableLayer(2, content_size, root_clip.get()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 6808 | 6796 |
| 6809 gfx::Vector2d scroll_delta(0, 100); | 6797 gfx::Vector2d scroll_delta(0, 100); |
| 6810 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 6798 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
| 6811 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 6799 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
| 6812 | 6800 |
| 6813 host_impl_->ScrollEnd(); | 6801 host_impl_->ScrollEnd(); |
| 6814 | 6802 |
| 6815 scoped_ptr<ScrollAndScaleSet> scroll_info = | 6803 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 6816 host_impl_->ProcessScrollDeltas(); | 6804 host_impl_->ProcessScrollDeltas(); |
| 6817 | 6805 |
| 6818 // The root should have scrolled. | 6806 // The root shouldn't have scrolled. |
| 6819 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 6807 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
| 6820 EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), root_scroll_id, | 6808 ExpectNone(*scroll_info.get(), root_scroll_id); |
| 6821 gfx::Vector2d(0, 10))); | |
| 6822 } | 6809 } |
| 6823 } | 6810 } |
| 6824 | 6811 |
| 6825 TEST_F(LayerTreeHostImplTest, ScrollUnknownNotOnAncestorChain) { | 6812 TEST_F(LayerTreeHostImplTest, ScrollUnknownNotOnAncestorChain) { |
| 6826 // If we ray cast a scroller that is not on the first layer's ancestor chain, | 6813 // If we ray cast a scroller that is not on the first layer's ancestor chain, |
| 6827 // we should return SCROLL_UNKNOWN. | 6814 // we should return SCROLL_UNKNOWN. |
| 6828 gfx::Size content_size(100, 100); | 6815 gfx::Size content_size(100, 100); |
| 6829 SetupScrollAndContentsLayers(content_size); | 6816 SetupScrollAndContentsLayers(content_size); |
| 6830 | 6817 |
| 6831 int scroll_layer_id = 2; | 6818 int scroll_layer_id = 2; |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7840 host_impl_->ScrollEnd(); | 7827 host_impl_->ScrollEnd(); |
| 7841 EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( | 7828 EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 7842 gfx::Point(), InputHandler::GESTURE)); | 7829 gfx::Point(), InputHandler::GESTURE)); |
| 7843 | 7830 |
| 7844 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); | 7831 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); |
| 7845 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); | 7832 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); |
| 7846 } | 7833 } |
| 7847 } | 7834 } |
| 7848 | 7835 |
| 7849 TEST_F(LayerTreeHostImplVirtualViewportTest, | 7836 TEST_F(LayerTreeHostImplVirtualViewportTest, |
| 7850 TouchFlingCanLockToViewportLayerAfterBubbling) { | 7837 TouchFlingDoesntSwitchScrollingLayer) { |
| 7851 gfx::Size content_size = gfx::Size(100, 160); | 7838 gfx::Size content_size = gfx::Size(100, 160); |
| 7852 gfx::Size outer_viewport = gfx::Size(50, 80); | 7839 gfx::Size outer_viewport = gfx::Size(50, 80); |
| 7853 gfx::Size inner_viewport = gfx::Size(25, 40); | 7840 gfx::Size inner_viewport = gfx::Size(25, 40); |
| 7854 | 7841 |
| 7855 SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); | 7842 SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); |
| 7856 | 7843 |
| 7857 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); | 7844 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 7858 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); | 7845 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 7859 | 7846 |
| 7860 scoped_ptr<LayerImpl> child = | 7847 scoped_ptr<LayerImpl> child = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 7873 EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), | 7860 EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), |
| 7874 InputHandler::GESTURE)); | 7861 InputHandler::GESTURE)); |
| 7875 | 7862 |
| 7876 // The child should have scrolled up to its limit. | 7863 // The child should have scrolled up to its limit. |
| 7877 scroll_info = host_impl_->ProcessScrollDeltas(); | 7864 scroll_info = host_impl_->ProcessScrollDeltas(); |
| 7878 ASSERT_EQ(1u, scroll_info->scrolls.size()); | 7865 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
| 7879 EXPECT_TRUE( | 7866 EXPECT_TRUE( |
| 7880 ScrollInfoContains(*scroll_info, child_scroll->id(), scroll_delta)); | 7867 ScrollInfoContains(*scroll_info, child_scroll->id(), scroll_delta)); |
| 7881 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); | 7868 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
| 7882 | 7869 |
| 7883 // The first |ScrollBy| after the fling should re-lock the scrolling | 7870 // The fling have no effect on the currently scrolling layer. |
| 7884 // layer to the first layer that scrolled, the inner viewport scroll layer. | |
| 7885 EXPECT_EQ(InputHandler::SCROLL_STARTED, host_impl_->FlingScrollBegin()); | 7871 EXPECT_EQ(InputHandler::SCROLL_STARTED, host_impl_->FlingScrollBegin()); |
| 7886 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); | 7872 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); |
| 7887 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); | 7873 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
| 7888 EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), | 7874 EXPECT_TRUE(host_impl_->IsCurrentlyScrollingLayerAt(gfx::Point(), |
| 7889 InputHandler::GESTURE)); | 7875 InputHandler::GESTURE)); |
| 7890 | 7876 |
| 7891 // The inner viewport should have scrolled up to its limit. | 7877 // The inner viewport shouldn't have scrolled. |
| 7892 scroll_info = host_impl_->ProcessScrollDeltas(); | 7878 scroll_info = host_impl_->ProcessScrollDeltas(); |
| 7893 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 7879 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
| 7894 EXPECT_TRUE( | 7880 EXPECT_TRUE( |
| 7895 ScrollInfoContains(*scroll_info, child_scroll->id(), scroll_delta)); | 7881 ScrollInfoContains(*scroll_info, child_scroll->id(), scroll_delta)); |
| 7896 EXPECT_TRUE( | 7882 ExpectNone(*scroll_info, inner_scroll->id()); |
| 7897 ScrollInfoContains(*scroll_info, inner_scroll->id(), scroll_delta)); | |
| 7898 | 7883 |
| 7899 // As the locked layer is at its limit, no further scrolling can occur. | 7884 // As the locked layer is at its limit, no further scrolling can occur. |
| 7900 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); | 7885 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); |
| 7901 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); | 7886 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); |
| 7902 host_impl_->ScrollEnd(); | 7887 host_impl_->ScrollEnd(); |
| 7903 EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( | 7888 EXPECT_FALSE(host_impl_->IsCurrentlyScrollingLayerAt( |
| 7904 gfx::Point(), InputHandler::GESTURE)); | 7889 gfx::Point(), InputHandler::GESTURE)); |
| 7905 } | 7890 } |
| 7906 } | 7891 } |
| 7907 | 7892 |
| 7908 TEST_F(LayerTreeHostImplVirtualViewportTest, | 7893 TEST_F(LayerTreeHostImplVirtualViewportTest, |
| 7909 ScrollBeginEventThatTargetsViewportLayerSkipsHitTest) { | 7894 ScrollBeginEventThatTargetsViewportLayerSkipsHitTest) { |
| 7910 gfx::Size content_size = gfx::Size(100, 160); | 7895 gfx::Size content_size = gfx::Size(100, 160); |
| 7911 gfx::Size outer_viewport = gfx::Size(50, 80); | 7896 gfx::Size outer_viewport = gfx::Size(50, 80); |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8561 // Hold an unowned pointer to the output surface to use for mock expectations. | 8546 // Hold an unowned pointer to the output surface to use for mock expectations. |
| 8562 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); | 8547 MockReclaimResourcesOutputSurface* mock_output_surface = output_surface.get(); |
| 8563 | 8548 |
| 8564 CreateHostImpl(DefaultSettings(), output_surface.Pass()); | 8549 CreateHostImpl(DefaultSettings(), output_surface.Pass()); |
| 8565 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); | 8550 EXPECT_CALL(*mock_output_surface, ForceReclaimResources()).Times(1); |
| 8566 host_impl_->BeginCommit(); | 8551 host_impl_->BeginCommit(); |
| 8567 } | 8552 } |
| 8568 | 8553 |
| 8569 } // namespace | 8554 } // namespace |
| 8570 } // namespace cc | 8555 } // namespace cc |
| OLD | NEW |