| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 8642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8653 | 8653 |
| 8654 DrawFrame(); | 8654 DrawFrame(); |
| 8655 | 8655 |
| 8656 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( | 8656 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( |
| 8657 BeginState(gfx::Point()).get(), InputHandler::WHEEL); | 8657 BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
| 8658 EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); | 8658 EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); |
| 8659 EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, | 8659 EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, |
| 8660 status.main_thread_scrolling_reasons); | 8660 status.main_thread_scrolling_reasons); |
| 8661 } | 8661 } |
| 8662 | 8662 |
| 8663 TEST_F(LayerTreeHostImplTest, NotScrollInvisibleScroller) { | 8663 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScroller) { |
| 8664 gfx::Size content_size(100, 100); | 8664 gfx::Size content_size(100, 100); |
| 8665 SetupScrollAndContentsLayers(content_size); | 8665 SetupScrollAndContentsLayers(content_size); |
| 8666 | 8666 |
| 8667 LayerImpl* root = host_impl_->active_tree()->LayerById(1); | 8667 LayerImpl* root = host_impl_->active_tree()->LayerById(1); |
| 8668 | 8668 |
| 8669 int scroll_layer_id = 2; | 8669 int scroll_layer_id = 2; |
| 8670 LayerImpl* scroll_layer = | 8670 LayerImpl* scroll_layer = |
| 8671 host_impl_->active_tree()->LayerById(scroll_layer_id); | 8671 host_impl_->active_tree()->LayerById(scroll_layer_id); |
| 8672 | 8672 |
| 8673 int child_scroll_layer_id = 7; | 8673 int child_scroll_layer_id = 7; |
| 8674 std::unique_ptr<LayerImpl> child_scroll = | 8674 std::unique_ptr<LayerImpl> child_scroll = |
| 8675 CreateScrollableLayer(child_scroll_layer_id, content_size, root); | 8675 CreateScrollableLayer(child_scroll_layer_id, content_size, root); |
| 8676 child_scroll->SetDrawsContent(false); | 8676 child_scroll->SetDrawsContent(false); |
| 8677 | 8677 |
| 8678 scroll_layer->test_properties()->AddChild(std::move(child_scroll)); | 8678 scroll_layer->test_properties()->AddChild(std::move(child_scroll)); |
| 8679 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 8679 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 8680 | 8680 |
| 8681 DrawFrame(); | 8681 DrawFrame(); |
| 8682 | 8682 |
| 8683 // We should not have scrolled |child_scroll| even though we technically "hit" | 8683 // We should have scrolled |child_scroll| even though it does not move |
| 8684 // it. The reason for this is that if the scrolling the scroll would not move | 8684 // any layer that is a drawn RSLL member. |
| 8685 // any layer that is a drawn RSLL member, then we can ignore the hit. | |
| 8686 // | |
| 8687 // Why SCROLL_STARTED? In this case, it's because we've bubbled out and | |
| 8688 // started scrolling the viewport. | |
| 8689 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 8685 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 8690 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | 8686 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8691 InputHandler::WHEEL) | 8687 InputHandler::WHEEL) |
| 8692 .thread); | |
| 8693 | |
| 8694 EXPECT_EQ(117, host_impl_->CurrentlyScrollingLayer()->id()); | |
| 8695 } | |
| 8696 | |
| 8697 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) { | |
| 8698 gfx::Size content_size(100, 100); | |
| 8699 SetupScrollAndContentsLayers(content_size); | |
| 8700 | |
| 8701 LayerImpl* root = host_impl_->active_tree()->LayerById(1); | |
| 8702 LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2); | |
| 8703 | |
| 8704 std::unique_ptr<LayerImpl> invisible_scroll_layer = | |
| 8705 CreateScrollableLayer(7, content_size, root); | |
| 8706 invisible_scroll_layer->SetDrawsContent(false); | |
| 8707 | |
| 8708 std::unique_ptr<LayerImpl> child_layer = | |
| 8709 LayerImpl::Create(host_impl_->active_tree(), 8); | |
| 8710 child_layer->SetDrawsContent(false); | |
| 8711 | |
| 8712 std::unique_ptr<LayerImpl> grand_child_layer = | |
| 8713 LayerImpl::Create(host_impl_->active_tree(), 9); | |
| 8714 grand_child_layer->SetDrawsContent(true); | |
| 8715 grand_child_layer->SetBounds(content_size); | |
| 8716 // Move the grand child so it's not hit by our test point. | |
| 8717 grand_child_layer->SetPosition(gfx::PointF(10.f, 10.f)); | |
| 8718 | |
| 8719 child_layer->test_properties()->AddChild(std::move(grand_child_layer)); | |
| 8720 invisible_scroll_layer->test_properties()->AddChild(std::move(child_layer)); | |
| 8721 root_scroll_layer->test_properties()->AddChild( | |
| 8722 std::move(invisible_scroll_layer)); | |
| 8723 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | |
| 8724 | |
| 8725 DrawFrame(); | |
| 8726 | |
| 8727 // We should have scrolled |invisible_scroll_layer| as it was hit and it has | |
| 8728 // a descendant which is a drawn RSLL member. | |
| 8729 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | |
| 8730 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | |
| 8731 InputHandler::WHEEL) | |
| 8732 .thread); | |
| 8733 | |
| 8734 EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id()); | |
| 8735 } | |
| 8736 | |
| 8737 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleScrollChild) { | |
| 8738 // This test case is very similar to the one above with one key difference: | |
| 8739 // the invisible scroller has a scroll child that is indeed draw contents. | |
| 8740 // If we attempt to initiate a gesture scroll off of the visible scroll child | |
| 8741 // we should still start the scroll child. | |
| 8742 gfx::Size content_size(100, 100); | |
| 8743 SetupScrollAndContentsLayers(content_size); | |
| 8744 | |
| 8745 LayerImpl* root = host_impl_->active_tree()->LayerById(1); | |
| 8746 | |
| 8747 int scroll_layer_id = 2; | |
| 8748 LayerImpl* scroll_layer = | |
| 8749 host_impl_->active_tree()->LayerById(scroll_layer_id); | |
| 8750 | |
| 8751 int scroll_child_id = 6; | |
| 8752 std::unique_ptr<LayerImpl> scroll_child = | |
| 8753 LayerImpl::Create(host_impl_->active_tree(), scroll_child_id); | |
| 8754 scroll_child->SetDrawsContent(true); | |
| 8755 scroll_child->SetBounds(content_size); | |
| 8756 // Move the scroll child so it's not hit by our test point. | |
| 8757 scroll_child->SetPosition(gfx::PointF(10.f, 10.f)); | |
| 8758 | |
| 8759 int invisible_scroll_layer_id = 7; | |
| 8760 std::unique_ptr<LayerImpl> invisible_scroll = | |
| 8761 CreateScrollableLayer(invisible_scroll_layer_id, content_size, root); | |
| 8762 invisible_scroll->SetDrawsContent(false); | |
| 8763 | |
| 8764 int container_id = 8; | |
| 8765 std::unique_ptr<LayerImpl> container = | |
| 8766 LayerImpl::Create(host_impl_->active_tree(), container_id); | |
| 8767 | |
| 8768 std::unique_ptr<std::set<LayerImpl*>> scroll_children( | |
| 8769 new std::set<LayerImpl*>); | |
| 8770 scroll_children->insert(scroll_child.get()); | |
| 8771 invisible_scroll->test_properties()->scroll_children.reset( | |
| 8772 scroll_children.release()); | |
| 8773 | |
| 8774 scroll_child->test_properties()->scroll_parent = invisible_scroll.get(); | |
| 8775 | |
| 8776 container->test_properties()->AddChild(std::move(invisible_scroll)); | |
| 8777 container->test_properties()->AddChild(std::move(scroll_child)); | |
| 8778 | |
| 8779 scroll_layer->test_properties()->AddChild(std::move(container)); | |
| 8780 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | |
| 8781 | |
| 8782 DrawFrame(); | |
| 8783 | |
| 8784 // We should have scrolled |child_scroll| even though it is invisible. | |
| 8785 // The reason for this is that if the scrolling the scroll would move a layer | |
| 8786 // that is a drawn RSLL member, then we should accept this hit. | |
| 8787 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | |
| 8788 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | |
| 8789 InputHandler::WHEEL) | |
| 8790 .thread); | 8688 .thread); |
| 8791 | 8689 |
| 8792 EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id()); | 8690 EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id()); |
| 8793 } | 8691 } |
| 8794 | 8692 |
| 8795 // Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed | 8693 // Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed |
| 8796 // in CompositorFrameMetadata. | 8694 // in CompositorFrameMetadata. |
| 8797 TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) { | 8695 TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) { |
| 8798 std::unique_ptr<SolidColorLayerImpl> root = | 8696 std::unique_ptr<SolidColorLayerImpl> root = |
| 8799 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | 8697 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
| (...skipping 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11722 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); | 11620 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); |
| 11723 host_impl_->MouseMoveAt(gfx::Point(10, 150)); | 11621 host_impl_->MouseMoveAt(gfx::Point(10, 150)); |
| 11724 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); | 11622 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); |
| 11725 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); | 11623 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); |
| 11726 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); | 11624 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); |
| 11727 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); | 11625 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); |
| 11728 } | 11626 } |
| 11729 | 11627 |
| 11730 } // namespace | 11628 } // namespace |
| 11731 } // namespace cc | 11629 } // namespace cc |
| OLD | NEW |