| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 void SetMaxSwapsPendingOnImplThread(int max) override {} | 117 void SetMaxSwapsPendingOnImplThread(int max) override {} |
| 118 void DidSwapBuffersOnImplThread() override {} | 118 void DidSwapBuffersOnImplThread() override {} |
| 119 void DidSwapBuffersCompleteOnImplThread() override {} | 119 void DidSwapBuffersCompleteOnImplThread() override {} |
| 120 void OnCanDrawStateChanged(bool can_draw) override { | 120 void OnCanDrawStateChanged(bool can_draw) override { |
| 121 on_can_draw_state_changed_called_ = true; | 121 on_can_draw_state_changed_called_ = true; |
| 122 } | 122 } |
| 123 void NotifyReadyToActivate() override { | 123 void NotifyReadyToActivate() override { |
| 124 did_notify_ready_to_activate_ = true; | 124 did_notify_ready_to_activate_ = true; |
| 125 host_impl_->ActivateSyncTree(); | 125 host_impl_->ActivateSyncTree(); |
| 126 } | 126 } |
| 127 void NotifyReadyToDraw() override {} |
| 127 void SetNeedsRedrawOnImplThread() override { did_request_redraw_ = true; } | 128 void SetNeedsRedrawOnImplThread() override { did_request_redraw_ = true; } |
| 128 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) override { | 129 void SetNeedsRedrawRectOnImplThread(const gfx::Rect& damage_rect) override { |
| 129 did_request_redraw_ = true; | 130 did_request_redraw_ = true; |
| 130 } | 131 } |
| 131 void SetNeedsAnimateOnImplThread() override { did_request_animate_ = true; } | 132 void SetNeedsAnimateOnImplThread() override { did_request_animate_ = true; } |
| 132 void SetNeedsManageTilesOnImplThread() override { | 133 void SetNeedsManageTilesOnImplThread() override { |
| 133 did_request_manage_tiles_ = true; | 134 did_request_manage_tiles_ = true; |
| 134 } | 135 } |
| 135 void DidInitializeVisibleTileOnImplThread() override { | 136 void DidInitializeVisibleTileOnImplThread() override { |
| 136 did_upload_visible_tile_ = true; | 137 did_upload_visible_tile_ = true; |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 TEST_F(LayerTreeHostImplTest, ScrollByReturnsCorrectValue) { | 766 TEST_F(LayerTreeHostImplTest, ScrollByReturnsCorrectValue) { |
| 766 SetupScrollAndContentsLayers(gfx::Size(200, 200)); | 767 SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
| 767 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 768 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 768 | 769 |
| 769 DrawFrame(); | 770 DrawFrame(); |
| 770 | 771 |
| 771 EXPECT_EQ(InputHandler::ScrollStarted, | 772 EXPECT_EQ(InputHandler::ScrollStarted, |
| 772 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 773 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 773 | 774 |
| 774 // Trying to scroll to the left/top will not succeed. | 775 // Trying to scroll to the left/top will not succeed. |
| 775 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); | 776 EXPECT_FALSE( |
| 776 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10))); | 777 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0)).did_scroll); |
| 777 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, -10))); | 778 EXPECT_FALSE( |
| 779 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10)).did_scroll); |
| 780 EXPECT_FALSE( |
| 781 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, -10)).did_scroll); |
| 778 | 782 |
| 779 // Scrolling to the right/bottom will succeed. | 783 // Scrolling to the right/bottom will succeed. |
| 780 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, 0))); | 784 EXPECT_TRUE( |
| 781 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10))); | 785 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, 0)).did_scroll); |
| 782 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, 10))); | 786 EXPECT_TRUE( |
| 787 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)).did_scroll); |
| 788 EXPECT_TRUE( |
| 789 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, 10)).did_scroll); |
| 783 | 790 |
| 784 // Scrolling to left/top will now succeed. | 791 // Scrolling to left/top will now succeed. |
| 785 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); | 792 EXPECT_TRUE( |
| 786 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10))); | 793 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0)).did_scroll); |
| 787 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, -10))); | 794 EXPECT_TRUE( |
| 795 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10)).did_scroll); |
| 796 EXPECT_TRUE( |
| 797 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, -10)).did_scroll); |
| 788 | 798 |
| 789 // Scrolling diagonally against an edge will succeed. | 799 // Scrolling diagonally against an edge will succeed. |
| 790 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, -10))); | 800 EXPECT_TRUE( |
| 791 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0))); | 801 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, -10)).did_scroll); |
| 792 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 10))); | 802 EXPECT_TRUE( |
| 803 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 0)).did_scroll); |
| 804 EXPECT_TRUE( |
| 805 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-10, 10)).did_scroll); |
| 793 | 806 |
| 794 // Trying to scroll more than the available space will also succeed. | 807 // Trying to scroll more than the available space will also succeed. |
| 795 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(5000, 5000))); | 808 EXPECT_TRUE( |
| 809 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(5000, 5000)).did_scroll); |
| 796 } | 810 } |
| 797 | 811 |
| 798 TEST_F(LayerTreeHostImplTest, ScrollVerticallyByPageReturnsCorrectValue) { | 812 TEST_F(LayerTreeHostImplTest, ScrollVerticallyByPageReturnsCorrectValue) { |
| 799 SetupScrollAndContentsLayers(gfx::Size(200, 2000)); | 813 SetupScrollAndContentsLayers(gfx::Size(200, 2000)); |
| 800 host_impl_->SetViewportSize(gfx::Size(100, 1000)); | 814 host_impl_->SetViewportSize(gfx::Size(100, 1000)); |
| 801 | 815 |
| 802 DrawFrame(); | 816 DrawFrame(); |
| 803 | 817 |
| 804 EXPECT_EQ(InputHandler::ScrollStarted, | 818 EXPECT_EQ(InputHandler::ScrollStarted, |
| 805 host_impl_->ScrollBegin(gfx::Point(), | 819 host_impl_->ScrollBegin(gfx::Point(), |
| (...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2567 | 2581 |
| 2568 gfx::ScrollOffset viewport_offset = | 2582 gfx::ScrollOffset viewport_offset = |
| 2569 host_impl_->active_tree()->TotalScrollOffset(); | 2583 host_impl_->active_tree()->TotalScrollOffset(); |
| 2570 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); | 2584 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); |
| 2571 | 2585 |
| 2572 // Hide the top controls by 25px. | 2586 // Hide the top controls by 25px. |
| 2573 gfx::Vector2dF scroll_delta(0.f, 25.f); | 2587 gfx::Vector2dF scroll_delta(0.f, 25.f); |
| 2574 EXPECT_EQ(InputHandler::ScrollStarted, | 2588 EXPECT_EQ(InputHandler::ScrollStarted, |
| 2575 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 2589 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 2576 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2590 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
| 2591 |
| 2592 // scrolling down at the max extents no longer hides the top controls |
| 2593 EXPECT_EQ(0.f, |
| 2594 settings_.top_controls_height - |
| 2595 host_impl_->active_tree()->total_top_controls_content_offset()); |
| 2596 |
| 2597 // forcefully hide the top controls by 25px |
| 2598 host_impl_->top_controls_manager()->ScrollBy(scroll_delta); |
| 2577 host_impl_->ScrollEnd(); | 2599 host_impl_->ScrollEnd(); |
| 2578 | 2600 |
| 2579 EXPECT_EQ(scroll_delta.y(), | 2601 EXPECT_EQ(scroll_delta.y(), |
| 2580 settings_.top_controls_height - | 2602 settings_.top_controls_height - |
| 2581 host_impl_->active_tree()->total_top_controls_content_offset()); | 2603 host_impl_->active_tree()->total_top_controls_content_offset()); |
| 2582 | 2604 |
| 2583 inner_scroll->ClampScrollToMaxScrollOffset(); | 2605 inner_scroll->ClampScrollToMaxScrollOffset(); |
| 2584 outer_scroll->ClampScrollToMaxScrollOffset(); | 2606 outer_scroll->ClampScrollToMaxScrollOffset(); |
| 2585 | 2607 |
| 2586 // We should still be fully scrolled. | 2608 // We should still be fully scrolled. |
| (...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3698 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); | 3720 EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame)); |
| 3699 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 3721 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 3700 host_impl_->DidDrawAllLayers(frame); | 3722 host_impl_->DidDrawAllLayers(frame); |
| 3701 EXPECT_FALSE(frame.has_no_damage); | 3723 EXPECT_FALSE(frame.has_no_damage); |
| 3702 CheckLayerScrollDelta(scroll_layer, ScrollOffsetToVector2dF(scroll_offset)); | 3724 CheckLayerScrollDelta(scroll_layer, ScrollOffsetToVector2dF(scroll_offset)); |
| 3703 | 3725 |
| 3704 host_impl_->SetRootLayerScrollOffsetDelegate(NULL); | 3726 host_impl_->SetRootLayerScrollOffsetDelegate(NULL); |
| 3705 } | 3727 } |
| 3706 | 3728 |
| 3707 TEST_F(LayerTreeHostImplTest, OverscrollRoot) { | 3729 TEST_F(LayerTreeHostImplTest, OverscrollRoot) { |
| 3730 InputHandlerScrollResult scroll_result; |
| 3708 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 3731 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 3709 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 3732 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 3710 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 3733 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
| 3711 DrawFrame(); | 3734 DrawFrame(); |
| 3712 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3735 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
| 3713 | 3736 |
| 3714 // In-bounds scrolling does not affect overscroll. | 3737 // In-bounds scrolling does not affect overscroll. |
| 3715 EXPECT_EQ(InputHandler::ScrollStarted, | 3738 EXPECT_EQ(InputHandler::ScrollStarted, |
| 3716 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 3739 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
| 3717 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 3740 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 3741 EXPECT_TRUE(scroll_result.did_scroll); |
| 3742 EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 3743 EXPECT_EQ(gfx::Vector2dF(), scroll_result.unused_scroll_delta); |
| 3718 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3744 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
| 3719 | 3745 |
| 3720 // Overscroll events are reflected immediately. | 3746 // Overscroll events are reflected immediately. |
| 3721 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 50)); | 3747 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 50)); |
| 3748 EXPECT_TRUE(scroll_result.did_scroll); |
| 3749 EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 3750 EXPECT_EQ(gfx::Vector2dF(0, 10), scroll_result.unused_scroll_delta); |
| 3722 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); | 3751 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); |
| 3752 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3753 host_impl_->accumulated_root_overscroll()); |
| 3723 | 3754 |
| 3724 // In-bounds scrolling resets accumulated overscroll for the scrolled axes. | 3755 // In-bounds scrolling resets accumulated overscroll for the scrolled axes. |
| 3725 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -50)); | 3756 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -50)); |
| 3757 EXPECT_TRUE(scroll_result.did_scroll); |
| 3758 EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 3759 EXPECT_EQ(gfx::Vector2dF(), scroll_result.unused_scroll_delta); |
| 3726 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); | 3760 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); |
| 3727 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10)); | 3761 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3762 host_impl_->accumulated_root_overscroll()); |
| 3763 |
| 3764 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10)); |
| 3765 EXPECT_FALSE(scroll_result.did_scroll); |
| 3766 EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 3767 EXPECT_EQ(gfx::Vector2dF(0, -10), scroll_result.unused_scroll_delta); |
| 3728 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3768 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
| 3729 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, 0)); | 3769 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3770 host_impl_->accumulated_root_overscroll()); |
| 3771 |
| 3772 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, 0)); |
| 3773 EXPECT_TRUE(scroll_result.did_scroll); |
| 3774 EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 3775 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_result.unused_scroll_delta); |
| 3730 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3776 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
| 3731 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-15, 0)); | 3777 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3778 host_impl_->accumulated_root_overscroll()); |
| 3779 |
| 3780 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-15, 0)); |
| 3781 EXPECT_TRUE(scroll_result.did_scroll); |
| 3782 EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 3783 EXPECT_EQ(gfx::Vector2dF(-5, 0), scroll_result.unused_scroll_delta); |
| 3732 EXPECT_EQ(gfx::Vector2dF(-5, -10), host_impl_->accumulated_root_overscroll()); | 3784 EXPECT_EQ(gfx::Vector2dF(-5, -10), host_impl_->accumulated_root_overscroll()); |
| 3733 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 60)); | 3785 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3786 host_impl_->accumulated_root_overscroll()); |
| 3787 |
| 3788 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 60)); |
| 3789 EXPECT_TRUE(scroll_result.did_scroll); |
| 3790 EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 3791 EXPECT_EQ(gfx::Vector2dF(0, 10), scroll_result.unused_scroll_delta); |
| 3734 EXPECT_EQ(gfx::Vector2dF(-5, 10), host_impl_->accumulated_root_overscroll()); | 3792 EXPECT_EQ(gfx::Vector2dF(-5, 10), host_impl_->accumulated_root_overscroll()); |
| 3735 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, -60)); | 3793 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3794 host_impl_->accumulated_root_overscroll()); |
| 3795 |
| 3796 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, -60)); |
| 3797 EXPECT_TRUE(scroll_result.did_scroll); |
| 3798 EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 3799 EXPECT_EQ(gfx::Vector2dF(0, -10), scroll_result.unused_scroll_delta); |
| 3736 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3800 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
| 3801 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3802 host_impl_->accumulated_root_overscroll()); |
| 3737 | 3803 |
| 3738 // Overscroll accumulates within the scope of ScrollBegin/ScrollEnd as long | 3804 // Overscroll accumulates within the scope of ScrollBegin/ScrollEnd as long |
| 3739 // as no scroll occurs. | 3805 // as no scroll occurs. |
| 3740 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 3806 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
| 3807 EXPECT_FALSE(scroll_result.did_scroll); |
| 3808 EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 3809 EXPECT_EQ(gfx::Vector2dF(0, -20), scroll_result.unused_scroll_delta); |
| 3741 EXPECT_EQ(gfx::Vector2dF(0, -30), host_impl_->accumulated_root_overscroll()); | 3810 EXPECT_EQ(gfx::Vector2dF(0, -30), host_impl_->accumulated_root_overscroll()); |
| 3742 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 3811 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3812 host_impl_->accumulated_root_overscroll()); |
| 3813 |
| 3814 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
| 3815 EXPECT_FALSE(scroll_result.did_scroll); |
| 3816 EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 3817 EXPECT_EQ(gfx::Vector2dF(0, -20), scroll_result.unused_scroll_delta); |
| 3743 EXPECT_EQ(gfx::Vector2dF(0, -50), host_impl_->accumulated_root_overscroll()); | 3818 EXPECT_EQ(gfx::Vector2dF(0, -50), host_impl_->accumulated_root_overscroll()); |
| 3819 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3820 host_impl_->accumulated_root_overscroll()); |
| 3821 |
| 3744 // Overscroll resets on valid scroll. | 3822 // Overscroll resets on valid scroll. |
| 3745 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 3823 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 3824 EXPECT_TRUE(scroll_result.did_scroll); |
| 3825 EXPECT_FALSE(scroll_result.did_overscroll_root); |
| 3826 EXPECT_EQ(gfx::Vector2dF(0, 0), scroll_result.unused_scroll_delta); |
| 3746 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); | 3827 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); |
| 3747 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 3828 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3829 host_impl_->accumulated_root_overscroll()); |
| 3830 |
| 3831 scroll_result = host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
| 3832 EXPECT_TRUE(scroll_result.did_scroll); |
| 3833 EXPECT_TRUE(scroll_result.did_overscroll_root); |
| 3834 EXPECT_EQ(gfx::Vector2dF(0, -10), scroll_result.unused_scroll_delta); |
| 3748 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3835 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
| 3836 EXPECT_EQ(scroll_result.accumulated_root_overscroll, |
| 3837 host_impl_->accumulated_root_overscroll()); |
| 3838 |
| 3749 host_impl_->ScrollEnd(); | 3839 host_impl_->ScrollEnd(); |
| 3750 } | 3840 } |
| 3751 | 3841 |
| 3752 | 3842 |
| 3753 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { | 3843 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { |
| 3754 // Scroll child layers beyond their maximum scroll range and make sure root | 3844 // Scroll child layers beyond their maximum scroll range and make sure root |
| 3755 // overscroll does not accumulate. | 3845 // overscroll does not accumulate. |
| 3756 gfx::Size surface_size(10, 10); | 3846 gfx::Size surface_size(10, 10); |
| 3757 scoped_ptr<LayerImpl> root_clip = | 3847 scoped_ptr<LayerImpl> root_clip = |
| 3758 LayerImpl::Create(host_impl_->active_tree(), 4); | 3848 LayerImpl::Create(host_impl_->active_tree(), 4); |
| (...skipping 2215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5974 LayerImpl::Create(host_impl_->pending_tree(), 2); | 6064 LayerImpl::Create(host_impl_->pending_tree(), 2); |
| 5975 LayerImpl* scrolling_layer = scoped_scrolling_layer.get(); | 6065 LayerImpl* scrolling_layer = scoped_scrolling_layer.get(); |
| 5976 root->AddChild(scoped_scrolling_layer.Pass()); | 6066 root->AddChild(scoped_scrolling_layer.Pass()); |
| 5977 | 6067 |
| 5978 gfx::Size content_layer_bounds(100000, 100); | 6068 gfx::Size content_layer_bounds(100000, 100); |
| 5979 gfx::Size pile_tile_size(3000, 3000); | 6069 gfx::Size pile_tile_size(3000, 3000); |
| 5980 scoped_refptr<FakePicturePileImpl> pile(FakePicturePileImpl::CreateFilledPile( | 6070 scoped_refptr<FakePicturePileImpl> pile(FakePicturePileImpl::CreateFilledPile( |
| 5981 pile_tile_size, content_layer_bounds)); | 6071 pile_tile_size, content_layer_bounds)); |
| 5982 | 6072 |
| 5983 scoped_ptr<FakePictureLayerImpl> scoped_content_layer = | 6073 scoped_ptr<FakePictureLayerImpl> scoped_content_layer = |
| 5984 FakePictureLayerImpl::CreateWithPile(host_impl_->pending_tree(), 3, pile); | 6074 FakePictureLayerImpl::CreateWithRasterSource(host_impl_->pending_tree(), |
| 6075 3, pile); |
| 5985 LayerImpl* content_layer = scoped_content_layer.get(); | 6076 LayerImpl* content_layer = scoped_content_layer.get(); |
| 5986 scrolling_layer->AddChild(scoped_content_layer.Pass()); | 6077 scrolling_layer->AddChild(scoped_content_layer.Pass()); |
| 5987 content_layer->SetBounds(content_layer_bounds); | 6078 content_layer->SetBounds(content_layer_bounds); |
| 5988 content_layer->SetDrawsContent(true); | 6079 content_layer->SetDrawsContent(true); |
| 5989 | 6080 |
| 5990 root->SetBounds(root_size); | 6081 root->SetBounds(root_size); |
| 5991 | 6082 |
| 5992 gfx::ScrollOffset scroll_offset(100000, 0); | 6083 gfx::ScrollOffset scroll_offset(100000, 0); |
| 5993 scrolling_layer->SetScrollClipLayer(root->id()); | 6084 scrolling_layer->SetScrollClipLayer(root->id()); |
| 5994 scrolling_layer->SetScrollOffset(scroll_offset); | 6085 scrolling_layer->SetScrollOffset(scroll_offset); |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6520 DrawFrame(); | 6611 DrawFrame(); |
| 6521 { | 6612 { |
| 6522 scoped_ptr<ScrollAndScaleSet> scroll_info; | 6613 scoped_ptr<ScrollAndScaleSet> scroll_info; |
| 6523 LayerImpl* child = | 6614 LayerImpl* child = |
| 6524 host_impl_->active_tree()->root_layer()->children()[0]->children()[0]; | 6615 host_impl_->active_tree()->root_layer()->children()[0]->children()[0]; |
| 6525 LayerImpl* grand_child = child->children()[0]; | 6616 LayerImpl* grand_child = child->children()[0]; |
| 6526 | 6617 |
| 6527 gfx::Vector2d scroll_delta(0, -2); | 6618 gfx::Vector2d scroll_delta(0, -2); |
| 6528 EXPECT_EQ(InputHandler::ScrollStarted, | 6619 EXPECT_EQ(InputHandler::ScrollStarted, |
| 6529 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 6620 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 6530 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta)); | 6621 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); |
| 6531 | 6622 |
| 6532 // The grand child should have scrolled up to its limit. | 6623 // The grand child should have scrolled up to its limit. |
| 6533 scroll_info = host_impl_->ProcessScrollDeltas(); | 6624 scroll_info = host_impl_->ProcessScrollDeltas(); |
| 6534 ASSERT_EQ(1u, scroll_info->scrolls.size()); | 6625 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
| 6535 ExpectContains(*scroll_info, grand_child->id(), scroll_delta); | 6626 ExpectContains(*scroll_info, grand_child->id(), scroll_delta); |
| 6536 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 6627 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 6537 | 6628 |
| 6538 // The child should have received the bubbled delta, but the locked | 6629 // The child should have received the bubbled delta, but the locked |
| 6539 // scrolling layer should remain set as the grand child. | 6630 // scrolling layer should remain set as the grand child. |
| 6540 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta)); | 6631 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); |
| 6541 scroll_info = host_impl_->ProcessScrollDeltas(); | 6632 scroll_info = host_impl_->ProcessScrollDeltas(); |
| 6542 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 6633 ASSERT_EQ(2u, scroll_info->scrolls.size()); |
| 6543 ExpectContains(*scroll_info, grand_child->id(), scroll_delta); | 6634 ExpectContains(*scroll_info, grand_child->id(), scroll_delta); |
| 6544 ExpectContains(*scroll_info, child->id(), scroll_delta); | 6635 ExpectContains(*scroll_info, child->id(), scroll_delta); |
| 6545 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 6636 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); |
| 6546 | 6637 |
| 6547 // The first |ScrollBy| after the fling should re-lock the scrolling | 6638 // The first |ScrollBy| after the fling should re-lock the scrolling |
| 6548 // layer to the first layer that scrolled, which is the child. | 6639 // layer to the first layer that scrolled, which is the child. |
| 6549 EXPECT_EQ(InputHandler::ScrollStarted, host_impl_->FlingScrollBegin()); | 6640 EXPECT_EQ(InputHandler::ScrollStarted, host_impl_->FlingScrollBegin()); |
| 6550 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta)); | 6641 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); |
| 6551 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); | 6642 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); |
| 6552 | 6643 |
| 6553 // The child should have scrolled up to its limit. | 6644 // The child should have scrolled up to its limit. |
| 6554 scroll_info = host_impl_->ProcessScrollDeltas(); | 6645 scroll_info = host_impl_->ProcessScrollDeltas(); |
| 6555 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 6646 ASSERT_EQ(2u, scroll_info->scrolls.size()); |
| 6556 ExpectContains(*scroll_info, grand_child->id(), scroll_delta); | 6647 ExpectContains(*scroll_info, grand_child->id(), scroll_delta); |
| 6557 ExpectContains(*scroll_info, child->id(), scroll_delta + scroll_delta); | 6648 ExpectContains(*scroll_info, child->id(), scroll_delta + scroll_delta); |
| 6558 | 6649 |
| 6559 // As the locked layer is at it's limit, no further scrolling can occur. | 6650 // As the locked layer is at it's limit, no further scrolling can occur. |
| 6560 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), scroll_delta)); | 6651 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), scroll_delta).did_scroll); |
| 6561 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); | 6652 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); |
| 6562 host_impl_->ScrollEnd(); | 6653 host_impl_->ScrollEnd(); |
| 6563 } | 6654 } |
| 6564 } | 6655 } |
| 6565 | 6656 |
| 6566 TEST_F(LayerTreeHostImplTest, WheelFlingShouldBubble) { | 6657 TEST_F(LayerTreeHostImplTest, WheelFlingShouldBubble) { |
| 6567 // When flinging via wheel, the root should eventually scroll (we should | 6658 // When flinging via wheel, the root should eventually scroll (we should |
| 6568 // bubble). | 6659 // bubble). |
| 6569 gfx::Size surface_size(10, 10); | 6660 gfx::Size surface_size(10, 10); |
| 6570 gfx::Size content_size(20, 20); | 6661 gfx::Size content_size(20, 20); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6948 new SimpleSwapPromiseMonitor(NULL, | 7039 new SimpleSwapPromiseMonitor(NULL, |
| 6949 host_impl_.get(), | 7040 host_impl_.get(), |
| 6950 &set_needs_commit_count, | 7041 &set_needs_commit_count, |
| 6951 &set_needs_redraw_count, | 7042 &set_needs_redraw_count, |
| 6952 &forward_to_main_count)); | 7043 &forward_to_main_count)); |
| 6953 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 7044 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 6954 | 7045 |
| 6955 // Scrolling normally should not trigger any forwarding. | 7046 // Scrolling normally should not trigger any forwarding. |
| 6956 EXPECT_EQ(InputHandler::ScrollStarted, | 7047 EXPECT_EQ(InputHandler::ScrollStarted, |
| 6957 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 7048 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 6958 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10))); | 7049 EXPECT_TRUE( |
| 7050 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)).did_scroll); |
| 6959 host_impl_->ScrollEnd(); | 7051 host_impl_->ScrollEnd(); |
| 6960 | 7052 |
| 6961 EXPECT_EQ(0, set_needs_commit_count); | 7053 EXPECT_EQ(0, set_needs_commit_count); |
| 6962 EXPECT_EQ(1, set_needs_redraw_count); | 7054 EXPECT_EQ(1, set_needs_redraw_count); |
| 6963 EXPECT_EQ(0, forward_to_main_count); | 7055 EXPECT_EQ(0, forward_to_main_count); |
| 6964 | 7056 |
| 6965 // Scrolling with a scroll handler should defer the swap to the main | 7057 // Scrolling with a scroll handler should defer the swap to the main |
| 6966 // thread. | 7058 // thread. |
| 6967 scroll_layer->SetHaveScrollEventHandlers(true); | 7059 scroll_layer->SetHaveScrollEventHandlers(true); |
| 6968 EXPECT_EQ(InputHandler::ScrollStarted, | 7060 EXPECT_EQ(InputHandler::ScrollStarted, |
| 6969 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 7061 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 6970 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10))); | 7062 EXPECT_TRUE( |
| 7063 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)).did_scroll); |
| 6971 host_impl_->ScrollEnd(); | 7064 host_impl_->ScrollEnd(); |
| 6972 | 7065 |
| 6973 EXPECT_EQ(0, set_needs_commit_count); | 7066 EXPECT_EQ(0, set_needs_commit_count); |
| 6974 EXPECT_EQ(2, set_needs_redraw_count); | 7067 EXPECT_EQ(2, set_needs_redraw_count); |
| 6975 EXPECT_EQ(1, forward_to_main_count); | 7068 EXPECT_EQ(1, forward_to_main_count); |
| 6976 } | 7069 } |
| 6977 } | 7070 } |
| 6978 | 7071 |
| 6979 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { | 7072 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { |
| 6980 public: | 7073 public: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7015 | 7108 |
| 7016 EXPECT_EQ(InputHandler::ScrollStarted, | 7109 EXPECT_EQ(InputHandler::ScrollStarted, |
| 7017 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 7110 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 7018 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7111 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7019 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7112 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 7020 scroll_layer->TotalScrollOffset().ToString()); | 7113 scroll_layer->TotalScrollOffset().ToString()); |
| 7021 | 7114 |
| 7022 // Scroll just the top controls and verify that the scroll succeeds. | 7115 // Scroll just the top controls and verify that the scroll succeeds. |
| 7023 const float residue = 10; | 7116 const float residue = 10; |
| 7024 float offset = top_controls_height_ - residue; | 7117 float offset = top_controls_height_ - residue; |
| 7025 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 7118 EXPECT_TRUE( |
| 7119 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7026 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7120 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7027 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7121 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 7028 scroll_layer->TotalScrollOffset().ToString()); | 7122 scroll_layer->TotalScrollOffset().ToString()); |
| 7029 | 7123 |
| 7030 // Scroll across the boundary | 7124 // Scroll across the boundary |
| 7031 const float content_scroll = 20; | 7125 const float content_scroll = 20; |
| 7032 offset = residue + content_scroll; | 7126 offset = residue + content_scroll; |
| 7033 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 7127 EXPECT_TRUE( |
| 7128 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7034 EXPECT_EQ(-top_controls_height_, | 7129 EXPECT_EQ(-top_controls_height_, |
| 7035 host_impl_->top_controls_manager()->ControlsTopOffset()); | 7130 host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7036 EXPECT_EQ(gfx::Vector2dF(0, content_scroll).ToString(), | 7131 EXPECT_EQ(gfx::Vector2dF(0, content_scroll).ToString(), |
| 7037 scroll_layer->TotalScrollOffset().ToString()); | 7132 scroll_layer->TotalScrollOffset().ToString()); |
| 7038 | 7133 |
| 7039 // Now scroll back to the top of the content | 7134 // Now scroll back to the top of the content |
| 7040 offset = -content_scroll; | 7135 offset = -content_scroll; |
| 7041 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 7136 EXPECT_TRUE( |
| 7137 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7042 EXPECT_EQ(-top_controls_height_, | 7138 EXPECT_EQ(-top_controls_height_, |
| 7043 host_impl_->top_controls_manager()->ControlsTopOffset()); | 7139 host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7044 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7140 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 7045 scroll_layer->TotalScrollOffset().ToString()); | 7141 scroll_layer->TotalScrollOffset().ToString()); |
| 7046 | 7142 |
| 7047 // And scroll the top controls completely into view | 7143 // And scroll the top controls completely into view |
| 7048 offset = -top_controls_height_; | 7144 offset = -top_controls_height_; |
| 7049 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 7145 EXPECT_TRUE( |
| 7146 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7050 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7147 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7051 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7148 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 7052 scroll_layer->TotalScrollOffset().ToString()); | 7149 scroll_layer->TotalScrollOffset().ToString()); |
| 7053 | 7150 |
| 7054 // And attempt to scroll past the end | 7151 // And attempt to scroll past the end |
| 7055 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 7152 EXPECT_FALSE( |
| 7153 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7056 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7154 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7057 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7155 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 7058 scroll_layer->TotalScrollOffset().ToString()); | 7156 scroll_layer->TotalScrollOffset().ToString()); |
| 7059 | 7157 |
| 7060 host_impl_->ScrollEnd(); | 7158 host_impl_->ScrollEnd(); |
| 7061 } | 7159 } |
| 7062 | 7160 |
| 7063 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { | 7161 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { |
| 7064 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 7162 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
| 7065 host_impl_->SetViewportSize(gfx::Size(100, 200)); | 7163 host_impl_->SetViewportSize(gfx::Size(100, 200)); |
| 7066 host_impl_->top_controls_manager()->UpdateTopControlsState( | 7164 host_impl_->top_controls_manager()->UpdateTopControlsState( |
| 7067 BOTH, SHOWN, false); | 7165 BOTH, SHOWN, false); |
| 7068 DrawFrame(); | 7166 DrawFrame(); |
| 7069 | 7167 |
| 7070 EXPECT_EQ(InputHandler::ScrollStarted, | 7168 EXPECT_EQ(InputHandler::ScrollStarted, |
| 7071 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 7169 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 7072 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7170 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7073 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7171 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 7074 scroll_layer->TotalScrollOffset().ToString()); | 7172 scroll_layer->TotalScrollOffset().ToString()); |
| 7075 | 7173 |
| 7076 // Scroll the top controls partially. | 7174 // Scroll the top controls partially. |
| 7077 const float residue = 35; | 7175 const float residue = 35; |
| 7078 float offset = top_controls_height_ - residue; | 7176 float offset = top_controls_height_ - residue; |
| 7079 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 7177 EXPECT_TRUE( |
| 7178 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7080 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7179 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7081 EXPECT_EQ(gfx::Vector2dF().ToString(), | 7180 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 7082 scroll_layer->TotalScrollOffset().ToString()); | 7181 scroll_layer->TotalScrollOffset().ToString()); |
| 7083 | 7182 |
| 7084 did_request_redraw_ = false; | 7183 did_request_redraw_ = false; |
| 7085 did_request_animate_ = false; | 7184 did_request_animate_ = false; |
| 7086 did_request_commit_ = false; | 7185 did_request_commit_ = false; |
| 7087 | 7186 |
| 7088 // End the scroll while the controls are still offset from their limit. | 7187 // End the scroll while the controls are still offset from their limit. |
| 7089 host_impl_->ScrollEnd(); | 7188 host_impl_->ScrollEnd(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7137 | 7236 |
| 7138 EXPECT_EQ(InputHandler::ScrollStarted, | 7237 EXPECT_EQ(InputHandler::ScrollStarted, |
| 7139 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 7238 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 7140 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7239 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7141 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), | 7240 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 7142 scroll_layer->TotalScrollOffset().ToString()); | 7241 scroll_layer->TotalScrollOffset().ToString()); |
| 7143 | 7242 |
| 7144 // Scroll the top controls partially. | 7243 // Scroll the top controls partially. |
| 7145 const float residue = 15; | 7244 const float residue = 15; |
| 7146 float offset = top_controls_height_ - residue; | 7245 float offset = top_controls_height_ - residue; |
| 7147 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 7246 EXPECT_TRUE( |
| 7247 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7148 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); | 7248 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7149 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), | 7249 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 7150 scroll_layer->TotalScrollOffset().ToString()); | 7250 scroll_layer->TotalScrollOffset().ToString()); |
| 7151 | 7251 |
| 7152 did_request_redraw_ = false; | 7252 did_request_redraw_ = false; |
| 7153 did_request_animate_ = false; | 7253 did_request_animate_ = false; |
| 7154 did_request_commit_ = false; | 7254 did_request_commit_ = false; |
| 7155 | 7255 |
| 7156 // End the scroll while the controls are still offset from the limit. | 7256 // End the scroll while the controls are still offset from the limit. |
| 7157 host_impl_->ScrollEnd(); | 7257 host_impl_->ScrollEnd(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 7177 host_impl_->top_controls_manager()->ControlsTopOffset(); | 7277 host_impl_->top_controls_manager()->ControlsTopOffset(); |
| 7178 | 7278 |
| 7179 if (new_offset != old_offset) { | 7279 if (new_offset != old_offset) { |
| 7180 EXPECT_TRUE(did_request_redraw_); | 7280 EXPECT_TRUE(did_request_redraw_); |
| 7181 EXPECT_TRUE(did_request_commit_); | 7281 EXPECT_TRUE(did_request_commit_); |
| 7182 } | 7282 } |
| 7183 } | 7283 } |
| 7184 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); | 7284 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); |
| 7185 } | 7285 } |
| 7186 | 7286 |
| 7287 TEST_F(LayerTreeHostImplWithTopControlsTest, |
| 7288 TopControlsScrollDeltaInOverScroll) { |
| 7289 // test varifies that the overscroll delta should not have accumulated in |
| 7290 // the top controls if we do a hide and show without releasing finger. |
| 7291 |
| 7292 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
| 7293 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 7294 host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
| 7295 false); |
| 7296 DrawFrame(); |
| 7297 |
| 7298 EXPECT_EQ(InputHandler::ScrollStarted, |
| 7299 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 7300 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7301 |
| 7302 float offset = 50; |
| 7303 EXPECT_TRUE( |
| 7304 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7305 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7306 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 7307 scroll_layer->TotalScrollOffset().ToString()); |
| 7308 |
| 7309 EXPECT_TRUE( |
| 7310 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7311 EXPECT_EQ(gfx::Vector2dF(0, offset).ToString(), |
| 7312 scroll_layer->TotalScrollOffset().ToString()); |
| 7313 |
| 7314 EXPECT_TRUE( |
| 7315 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7316 |
| 7317 // Should have fully scrolled |
| 7318 EXPECT_EQ(gfx::Vector2dF(0, scroll_layer->MaxScrollOffset().y()).ToString(), |
| 7319 scroll_layer->TotalScrollOffset().ToString()); |
| 7320 |
| 7321 float overscrollamount = 10; |
| 7322 |
| 7323 // Overscroll the content |
| 7324 EXPECT_FALSE( |
| 7325 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, overscrollamount)) |
| 7326 .did_scroll); |
| 7327 EXPECT_EQ(gfx::Vector2dF(0, 2 * offset).ToString(), |
| 7328 scroll_layer->TotalScrollOffset().ToString()); |
| 7329 EXPECT_EQ(gfx::Vector2dF(0, overscrollamount).ToString(), |
| 7330 host_impl_->accumulated_root_overscroll().ToString()); |
| 7331 |
| 7332 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -2 * offset)) |
| 7333 .did_scroll); |
| 7334 EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), |
| 7335 scroll_layer->TotalScrollOffset().ToString()); |
| 7336 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7337 |
| 7338 EXPECT_TRUE( |
| 7339 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -offset)).did_scroll); |
| 7340 EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), |
| 7341 scroll_layer->TotalScrollOffset().ToString()); |
| 7342 |
| 7343 // Top controls should be fully visible |
| 7344 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7345 |
| 7346 host_impl_->ScrollEnd(); |
| 7347 } |
| 7348 |
| 7187 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { | 7349 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { |
| 7188 public: | 7350 public: |
| 7189 void SetupVirtualViewportLayers(const gfx::Size& content_size, | 7351 void SetupVirtualViewportLayers(const gfx::Size& content_size, |
| 7190 const gfx::Size& outer_viewport, | 7352 const gfx::Size& outer_viewport, |
| 7191 const gfx::Size& inner_viewport) { | 7353 const gfx::Size& inner_viewport) { |
| 7192 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); | 7354 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 7193 const int kOuterViewportClipLayerId = 6; | 7355 const int kOuterViewportClipLayerId = 6; |
| 7194 const int kOuterViewportScrollLayerId = 7; | 7356 const int kOuterViewportScrollLayerId = 7; |
| 7195 const int kInnerViewportScrollLayerId = 2; | 7357 const int kInnerViewportScrollLayerId = 2; |
| 7196 const int kInnerViewportClipLayerId = 4; | 7358 const int kInnerViewportClipLayerId = 4; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7391 | 7553 |
| 7392 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) { | 7554 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) { |
| 7393 host_impl_->CreatePendingTree(); | 7555 host_impl_->CreatePendingTree(); |
| 7394 host_impl_->pending_tree()->SetRootLayer( | 7556 host_impl_->pending_tree()->SetRootLayer( |
| 7395 PictureLayerImpl::Create(host_impl_->pending_tree(), 10)); | 7557 PictureLayerImpl::Create(host_impl_->pending_tree(), 10)); |
| 7396 | 7558 |
| 7397 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); | 7559 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
| 7398 LayerImpl* pending_layer = pending_tree->root_layer(); | 7560 LayerImpl* pending_layer = pending_tree->root_layer(); |
| 7399 | 7561 |
| 7400 std::vector<PictureLayerImpl::Pair> layer_pairs; | 7562 std::vector<PictureLayerImpl::Pair> layer_pairs; |
| 7401 host_impl_->GetPictureLayerImplPairs(&layer_pairs); | 7563 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); |
| 7402 EXPECT_EQ(1u, layer_pairs.size()); | 7564 EXPECT_EQ(1u, layer_pairs.size()); |
| 7403 EXPECT_EQ(pending_layer, layer_pairs[0].pending); | 7565 EXPECT_EQ(pending_layer, layer_pairs[0].pending); |
| 7404 EXPECT_EQ(nullptr, layer_pairs[0].active); | 7566 EXPECT_EQ(nullptr, layer_pairs[0].active); |
| 7405 | 7567 |
| 7406 host_impl_->ActivateSyncTree(); | 7568 host_impl_->ActivateSyncTree(); |
| 7407 | 7569 |
| 7408 LayerTreeImpl* active_tree = host_impl_->active_tree(); | 7570 LayerTreeImpl* active_tree = host_impl_->active_tree(); |
| 7409 LayerImpl* active_layer = active_tree->root_layer(); | 7571 LayerImpl* active_layer = active_tree->root_layer(); |
| 7410 EXPECT_NE(active_tree, pending_tree); | 7572 EXPECT_NE(active_tree, pending_tree); |
| 7411 EXPECT_NE(active_layer, pending_layer); | 7573 EXPECT_NE(active_layer, pending_layer); |
| 7412 EXPECT_NE(nullptr, active_tree); | 7574 EXPECT_NE(nullptr, active_tree); |
| 7413 EXPECT_NE(nullptr, active_layer); | 7575 EXPECT_NE(nullptr, active_layer); |
| 7414 | 7576 |
| 7415 host_impl_->CreatePendingTree(); | 7577 host_impl_->CreatePendingTree(); |
| 7416 | 7578 |
| 7417 layer_pairs.clear(); | 7579 layer_pairs.clear(); |
| 7418 host_impl_->GetPictureLayerImplPairs(&layer_pairs); | 7580 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); |
| 7419 EXPECT_EQ(1u, layer_pairs.size()); | 7581 EXPECT_EQ(1u, layer_pairs.size()); |
| 7420 EXPECT_EQ(active_layer, layer_pairs[0].active); | 7582 EXPECT_EQ(active_layer, layer_pairs[0].active); |
| 7421 EXPECT_EQ(pending_layer, layer_pairs[0].pending); | 7583 EXPECT_EQ(pending_layer, layer_pairs[0].pending); |
| 7422 | 7584 |
| 7423 // Activate, the active layer has no twin now. | 7585 // Activate, the active layer has no twin now. |
| 7424 host_impl_->ActivateSyncTree(); | 7586 host_impl_->ActivateSyncTree(); |
| 7425 | 7587 |
| 7426 layer_pairs.clear(); | 7588 layer_pairs.clear(); |
| 7427 host_impl_->GetPictureLayerImplPairs(&layer_pairs); | 7589 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); |
| 7428 EXPECT_EQ(1u, layer_pairs.size()); | 7590 EXPECT_EQ(1u, layer_pairs.size()); |
| 7429 EXPECT_EQ(active_layer, layer_pairs[0].active); | 7591 EXPECT_EQ(active_layer, layer_pairs[0].active); |
| 7430 EXPECT_EQ(nullptr, layer_pairs[0].pending); | 7592 EXPECT_EQ(nullptr, layer_pairs[0].pending); |
| 7431 | 7593 |
| 7432 // Create another layer in the pending tree that's not in the active tree. We | 7594 // Create another layer in the pending tree that's not in the active tree. We |
| 7433 // should get two pairs. | 7595 // should get two pairs. |
| 7434 host_impl_->CreatePendingTree(); | 7596 host_impl_->CreatePendingTree(); |
| 7435 host_impl_->pending_tree()->root_layer()->AddChild( | 7597 host_impl_->pending_tree()->root_layer()->AddChild( |
| 7436 PictureLayerImpl::Create(host_impl_->pending_tree(), 11)); | 7598 PictureLayerImpl::Create(host_impl_->pending_tree(), 11)); |
| 7437 | 7599 |
| 7438 LayerImpl* new_pending_layer = pending_tree->root_layer()->children()[0]; | 7600 LayerImpl* new_pending_layer = pending_tree->root_layer()->children()[0]; |
| 7439 | 7601 |
| 7440 layer_pairs.clear(); | 7602 layer_pairs.clear(); |
| 7441 host_impl_->GetPictureLayerImplPairs(&layer_pairs); | 7603 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); |
| 7442 EXPECT_EQ(2u, layer_pairs.size()); | 7604 EXPECT_EQ(2u, layer_pairs.size()); |
| 7443 | 7605 |
| 7444 // The pair ordering is flaky, so make it consistent. | 7606 // The pair ordering is flaky, so make it consistent. |
| 7445 if (layer_pairs[0].active != active_layer) | 7607 if (layer_pairs[0].active != active_layer) |
| 7446 std::swap(layer_pairs[0], layer_pairs[1]); | 7608 std::swap(layer_pairs[0], layer_pairs[1]); |
| 7447 | 7609 |
| 7448 EXPECT_EQ(active_layer, layer_pairs[0].active); | 7610 EXPECT_EQ(active_layer, layer_pairs[0].active); |
| 7449 EXPECT_EQ(pending_layer, layer_pairs[0].pending); | 7611 EXPECT_EQ(pending_layer, layer_pairs[0].pending); |
| 7450 EXPECT_EQ(new_pending_layer, layer_pairs[1].pending); | 7612 EXPECT_EQ(new_pending_layer, layer_pairs[1].pending); |
| 7451 EXPECT_EQ(nullptr, layer_pairs[1].active); | 7613 EXPECT_EQ(nullptr, layer_pairs[1].active); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7517 // surface. | 7679 // surface. |
| 7518 EXPECT_EQ(0, num_lost_surfaces_); | 7680 EXPECT_EQ(0, num_lost_surfaces_); |
| 7519 host_impl_->DidLoseOutputSurface(); | 7681 host_impl_->DidLoseOutputSurface(); |
| 7520 EXPECT_EQ(1, num_lost_surfaces_); | 7682 EXPECT_EQ(1, num_lost_surfaces_); |
| 7521 host_impl_->DidLoseOutputSurface(); | 7683 host_impl_->DidLoseOutputSurface(); |
| 7522 EXPECT_LE(1, num_lost_surfaces_); | 7684 EXPECT_LE(1, num_lost_surfaces_); |
| 7523 } | 7685 } |
| 7524 | 7686 |
| 7525 } // namespace | 7687 } // namespace |
| 7526 } // namespace cc | 7688 } // namespace cc |
| OLD | NEW |