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 2574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2585 | 2585 |
2586 gfx::ScrollOffset viewport_offset = | 2586 gfx::ScrollOffset viewport_offset = |
2587 host_impl_->active_tree()->TotalScrollOffset(); | 2587 host_impl_->active_tree()->TotalScrollOffset(); |
2588 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); | 2588 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); |
2589 | 2589 |
2590 // Hide the top controls by 25px. | 2590 // Hide the top controls by 25px. |
2591 gfx::Vector2dF scroll_delta(0.f, 25.f); | 2591 gfx::Vector2dF scroll_delta(0.f, 25.f); |
2592 EXPECT_EQ(InputHandler::ScrollStarted, | 2592 EXPECT_EQ(InputHandler::ScrollStarted, |
2593 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 2593 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
2594 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2594 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
| 2595 |
| 2596 // scrolling down at the max extents no longer hides the top controls |
| 2597 EXPECT_EQ(0.f, |
| 2598 settings_.top_controls_height - |
| 2599 host_impl_->active_tree()->total_top_controls_content_offset()); |
| 2600 |
| 2601 // forcefully hide the top controls by 25px |
| 2602 host_impl_->top_controls_manager()->ScrollBy(scroll_delta); |
2595 host_impl_->ScrollEnd(); | 2603 host_impl_->ScrollEnd(); |
2596 | 2604 |
2597 EXPECT_EQ(scroll_delta.y(), | 2605 EXPECT_EQ(scroll_delta.y(), |
2598 settings_.top_controls_height - | 2606 settings_.top_controls_height - |
2599 host_impl_->active_tree()->total_top_controls_content_offset()); | 2607 host_impl_->active_tree()->total_top_controls_content_offset()); |
2600 | 2608 |
2601 inner_scroll->ClampScrollToMaxScrollOffset(); | 2609 inner_scroll->ClampScrollToMaxScrollOffset(); |
2602 outer_scroll->ClampScrollToMaxScrollOffset(); | 2610 outer_scroll->ClampScrollToMaxScrollOffset(); |
2603 | 2611 |
2604 // We should still be fully scrolled. | 2612 // We should still be fully scrolled. |
(...skipping 4689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7294 host_impl_->top_controls_manager()->ControlsTopOffset(); | 7302 host_impl_->top_controls_manager()->ControlsTopOffset(); |
7295 | 7303 |
7296 if (new_offset != old_offset) { | 7304 if (new_offset != old_offset) { |
7297 EXPECT_TRUE(did_request_redraw_); | 7305 EXPECT_TRUE(did_request_redraw_); |
7298 EXPECT_TRUE(did_request_commit_); | 7306 EXPECT_TRUE(did_request_commit_); |
7299 } | 7307 } |
7300 } | 7308 } |
7301 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); | 7309 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); |
7302 } | 7310 } |
7303 | 7311 |
| 7312 TEST_F(LayerTreeHostImplWithTopControlsTest, |
| 7313 TopControlsScrollDeltaInOverScroll) { |
| 7314 // test varifies that the overscroll delta should not have accumulated in |
| 7315 // the top controls if we do a hide and show without releasing finger. |
| 7316 |
| 7317 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
| 7318 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 7319 host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
| 7320 false); |
| 7321 DrawFrame(); |
| 7322 |
| 7323 EXPECT_EQ(InputHandler::ScrollStarted, |
| 7324 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 7325 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7326 |
| 7327 float offset = 50; |
| 7328 EXPECT_TRUE( |
| 7329 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7330 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7331 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 7332 scroll_layer->TotalScrollOffset().ToString()); |
| 7333 |
| 7334 EXPECT_TRUE( |
| 7335 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7336 EXPECT_EQ(gfx::Vector2dF(0, offset).ToString(), |
| 7337 scroll_layer->TotalScrollOffset().ToString()); |
| 7338 |
| 7339 EXPECT_TRUE( |
| 7340 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7341 |
| 7342 // Should have fully scrolled |
| 7343 EXPECT_EQ(gfx::Vector2dF(0, scroll_layer->MaxScrollOffset().y()).ToString(), |
| 7344 scroll_layer->TotalScrollOffset().ToString()); |
| 7345 |
| 7346 float overscrollamount = 10; |
| 7347 |
| 7348 // Overscroll the content |
| 7349 EXPECT_FALSE( |
| 7350 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, overscrollamount)) |
| 7351 .did_scroll); |
| 7352 EXPECT_EQ(gfx::Vector2dF(0, 2 * offset).ToString(), |
| 7353 scroll_layer->TotalScrollOffset().ToString()); |
| 7354 EXPECT_EQ(gfx::Vector2dF(0, overscrollamount).ToString(), |
| 7355 host_impl_->accumulated_root_overscroll().ToString()); |
| 7356 |
| 7357 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -2 * offset)) |
| 7358 .did_scroll); |
| 7359 EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), |
| 7360 scroll_layer->TotalScrollOffset().ToString()); |
| 7361 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7362 |
| 7363 EXPECT_TRUE( |
| 7364 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -offset)).did_scroll); |
| 7365 EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), |
| 7366 scroll_layer->TotalScrollOffset().ToString()); |
| 7367 |
| 7368 // Top controls should be fully visible |
| 7369 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7370 |
| 7371 host_impl_->ScrollEnd(); |
| 7372 } |
| 7373 |
7304 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { | 7374 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { |
7305 public: | 7375 public: |
7306 void SetupVirtualViewportLayers(const gfx::Size& content_size, | 7376 void SetupVirtualViewportLayers(const gfx::Size& content_size, |
7307 const gfx::Size& outer_viewport, | 7377 const gfx::Size& outer_viewport, |
7308 const gfx::Size& inner_viewport) { | 7378 const gfx::Size& inner_viewport) { |
7309 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); | 7379 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
7310 const int kOuterViewportClipLayerId = 6; | 7380 const int kOuterViewportClipLayerId = 6; |
7311 const int kOuterViewportScrollLayerId = 7; | 7381 const int kOuterViewportScrollLayerId = 7; |
7312 const int kInnerViewportScrollLayerId = 2; | 7382 const int kInnerViewportScrollLayerId = 2; |
7313 const int kInnerViewportClipLayerId = 4; | 7383 const int kInnerViewportClipLayerId = 4; |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7634 // surface. | 7704 // surface. |
7635 EXPECT_EQ(0, num_lost_surfaces_); | 7705 EXPECT_EQ(0, num_lost_surfaces_); |
7636 host_impl_->DidLoseOutputSurface(); | 7706 host_impl_->DidLoseOutputSurface(); |
7637 EXPECT_EQ(1, num_lost_surfaces_); | 7707 EXPECT_EQ(1, num_lost_surfaces_); |
7638 host_impl_->DidLoseOutputSurface(); | 7708 host_impl_->DidLoseOutputSurface(); |
7639 EXPECT_LE(1, num_lost_surfaces_); | 7709 EXPECT_LE(1, num_lost_surfaces_); |
7640 } | 7710 } |
7641 | 7711 |
7642 } // namespace | 7712 } // namespace |
7643 } // namespace cc | 7713 } // namespace cc |
OLD | NEW |