Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 2495123002: Make all scrollable layers visible to hit testing. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8550 matching lines...) Expand 10 before | Expand all | Expand 10 after
8561 8561
8562 DrawFrame(); 8562 DrawFrame();
8563 8563
8564 InputHandler::ScrollStatus status = host_impl_->ScrollBegin( 8564 InputHandler::ScrollStatus status = host_impl_->ScrollBegin(
8565 BeginState(gfx::Point()).get(), InputHandler::WHEEL); 8565 BeginState(gfx::Point()).get(), InputHandler::WHEEL);
8566 EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread); 8566 EXPECT_EQ(InputHandler::SCROLL_UNKNOWN, status.thread);
8567 EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest, 8567 EXPECT_EQ(MainThreadScrollingReason::kFailedHitTest,
8568 status.main_thread_scrolling_reasons); 8568 status.main_thread_scrolling_reasons);
8569 } 8569 }
8570 8570
8571 TEST_F(LayerTreeHostImplTest, NotScrollInvisibleScroller) { 8571 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScroller) {
8572 gfx::Size content_size(100, 100); 8572 gfx::Size content_size(100, 100);
8573 SetupScrollAndContentsLayers(content_size); 8573 SetupScrollAndContentsLayers(content_size);
8574 8574
8575 LayerImpl* root = host_impl_->active_tree()->LayerById(1); 8575 LayerImpl* root = host_impl_->active_tree()->LayerById(1);
8576 8576
8577 int scroll_layer_id = 2; 8577 int scroll_layer_id = 2;
8578 LayerImpl* scroll_layer = 8578 LayerImpl* scroll_layer =
8579 host_impl_->active_tree()->LayerById(scroll_layer_id); 8579 host_impl_->active_tree()->LayerById(scroll_layer_id);
8580 8580
8581 int child_scroll_layer_id = 7; 8581 int child_scroll_layer_id = 7;
8582 std::unique_ptr<LayerImpl> child_scroll = 8582 std::unique_ptr<LayerImpl> child_scroll =
8583 CreateScrollableLayer(child_scroll_layer_id, content_size, root); 8583 CreateScrollableLayer(child_scroll_layer_id, content_size, root);
8584 child_scroll->SetDrawsContent(false); 8584 child_scroll->SetDrawsContent(false);
8585 8585
8586 scroll_layer->test_properties()->AddChild(std::move(child_scroll)); 8586 scroll_layer->test_properties()->AddChild(std::move(child_scroll));
8587 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 8587 host_impl_->active_tree()->BuildPropertyTreesForTesting();
8588 8588
8589 DrawFrame(); 8589 DrawFrame();
8590 8590
8591 // We should not have scrolled |child_scroll| even though we technically "hit" 8591 // We should have scrolled |child_scroll| even though it does not move
8592 // it. The reason for this is that if the scrolling the scroll would not move 8592 // any layer that is a drawn RSLL member.
8593 // any layer that is a drawn RSLL member, then we can ignore the hit.
8594 //
8595 // Why SCROLL_STARTED? In this case, it's because we've bubbled out and
8596 // started scrolling the viewport.
8597 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 8593 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
8598 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), 8594 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(),
8599 InputHandler::WHEEL) 8595 InputHandler::WHEEL)
8600 .thread);
8601
8602 EXPECT_EQ(117, host_impl_->CurrentlyScrollingLayer()->id());
8603 }
8604
8605 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) {
8606 gfx::Size content_size(100, 100);
8607 SetupScrollAndContentsLayers(content_size);
8608
8609 LayerImpl* root = host_impl_->active_tree()->LayerById(1);
8610 LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2);
8611
8612 std::unique_ptr<LayerImpl> invisible_scroll_layer =
8613 CreateScrollableLayer(7, content_size, root);
8614 invisible_scroll_layer->SetDrawsContent(false);
8615
8616 std::unique_ptr<LayerImpl> child_layer =
8617 LayerImpl::Create(host_impl_->active_tree(), 8);
8618 child_layer->SetDrawsContent(false);
8619
8620 std::unique_ptr<LayerImpl> grand_child_layer =
8621 LayerImpl::Create(host_impl_->active_tree(), 9);
8622 grand_child_layer->SetDrawsContent(true);
8623 grand_child_layer->SetBounds(content_size);
8624 // Move the grand child so it's not hit by our test point.
8625 grand_child_layer->SetPosition(gfx::PointF(10.f, 10.f));
8626
8627 child_layer->test_properties()->AddChild(std::move(grand_child_layer));
8628 invisible_scroll_layer->test_properties()->AddChild(std::move(child_layer));
8629 root_scroll_layer->test_properties()->AddChild(
8630 std::move(invisible_scroll_layer));
8631 host_impl_->active_tree()->BuildPropertyTreesForTesting();
8632
8633 DrawFrame();
8634
8635 // We should have scrolled |invisible_scroll_layer| as it was hit and it has
8636 // a descendant which is a drawn RSLL member.
8637 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
8638 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(),
8639 InputHandler::WHEEL)
8640 .thread);
8641
8642 EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id());
8643 }
8644
8645 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleScrollChild) {
8646 // This test case is very similar to the one above with one key difference:
8647 // the invisible scroller has a scroll child that is indeed draw contents.
8648 // If we attempt to initiate a gesture scroll off of the visible scroll child
8649 // we should still start the scroll child.
8650 gfx::Size content_size(100, 100);
8651 SetupScrollAndContentsLayers(content_size);
8652
8653 LayerImpl* root = host_impl_->active_tree()->LayerById(1);
8654
8655 int scroll_layer_id = 2;
8656 LayerImpl* scroll_layer =
8657 host_impl_->active_tree()->LayerById(scroll_layer_id);
8658
8659 int scroll_child_id = 6;
8660 std::unique_ptr<LayerImpl> scroll_child =
8661 LayerImpl::Create(host_impl_->active_tree(), scroll_child_id);
8662 scroll_child->SetDrawsContent(true);
8663 scroll_child->SetBounds(content_size);
8664 // Move the scroll child so it's not hit by our test point.
8665 scroll_child->SetPosition(gfx::PointF(10.f, 10.f));
8666
8667 int invisible_scroll_layer_id = 7;
8668 std::unique_ptr<LayerImpl> invisible_scroll =
8669 CreateScrollableLayer(invisible_scroll_layer_id, content_size, root);
8670 invisible_scroll->SetDrawsContent(false);
8671
8672 int container_id = 8;
8673 std::unique_ptr<LayerImpl> container =
8674 LayerImpl::Create(host_impl_->active_tree(), container_id);
8675
8676 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
8677 new std::set<LayerImpl*>);
8678 scroll_children->insert(scroll_child.get());
8679 invisible_scroll->test_properties()->scroll_children.reset(
8680 scroll_children.release());
8681
8682 scroll_child->test_properties()->scroll_parent = invisible_scroll.get();
8683
8684 container->test_properties()->AddChild(std::move(invisible_scroll));
8685 container->test_properties()->AddChild(std::move(scroll_child));
8686
8687 scroll_layer->test_properties()->AddChild(std::move(container));
8688 host_impl_->active_tree()->BuildPropertyTreesForTesting();
8689
8690 DrawFrame();
8691
8692 // We should have scrolled |child_scroll| even though it is invisible.
8693 // The reason for this is that if the scrolling the scroll would move a layer
8694 // that is a drawn RSLL member, then we should accept this hit.
8695 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
8696 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(),
8697 InputHandler::WHEEL)
8698 .thread); 8596 .thread);
8699 8597
8700 EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id()); 8598 EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id());
8701 } 8599 }
8702 8600
8703 // Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed 8601 // Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed
8704 // in CompositorFrameMetadata. 8602 // in CompositorFrameMetadata.
8705 TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) { 8603 TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) {
8706 std::unique_ptr<SolidColorLayerImpl> root = 8604 std::unique_ptr<SolidColorLayerImpl> root =
8707 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); 8605 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
(...skipping 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after
11630 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); 11528 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar());
11631 host_impl_->MouseMoveAt(gfx::Point(10, 150)); 11529 host_impl_->MouseMoveAt(gfx::Point(10, 150));
11632 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); 11530 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar());
11633 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); 11531 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar());
11634 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); 11532 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar());
11635 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); 11533 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar());
11636 } 11534 }
11637 11535
11638 } // namespace 11536 } // namespace
11639 } // namespace cc 11537 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698