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 7648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7659 | 7659 |
7660 float new_offset = | 7660 float new_offset = |
7661 host_impl_->top_controls_manager()->ControlsTopOffset(); | 7661 host_impl_->top_controls_manager()->ControlsTopOffset(); |
7662 | 7662 |
7663 if (new_offset != old_offset) { | 7663 if (new_offset != old_offset) { |
7664 EXPECT_TRUE(did_request_redraw_); | 7664 EXPECT_TRUE(did_request_redraw_); |
7665 EXPECT_TRUE(did_request_commit_); | 7665 EXPECT_TRUE(did_request_commit_); |
7666 } | 7666 } |
7667 } | 7667 } |
7668 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); | 7668 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); |
| 7669 EXPECT_EQ(-top_controls_height_, |
| 7670 host_impl_->top_controls_manager()->ControlsTopOffset()); |
7669 } | 7671 } |
7670 | 7672 |
7671 TEST_F(LayerTreeHostImplWithTopControlsTest, | 7673 TEST_F(LayerTreeHostImplWithTopControlsTest, |
| 7674 TopControlsAnimationAfterMainThreadFlingStopped) { |
| 7675 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
| 7676 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 7677 host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
| 7678 false); |
| 7679 float initial_scroll_offset = 50; |
| 7680 scroll_layer->PushScrollOffsetFromMainThread( |
| 7681 gfx::ScrollOffset(0, initial_scroll_offset)); |
| 7682 DrawFrame(); |
| 7683 |
| 7684 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 7685 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); |
| 7686 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7687 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 7688 scroll_layer->CurrentScrollOffset().ToString()); |
| 7689 |
| 7690 // Scroll the top controls partially. |
| 7691 const float residue = 15; |
| 7692 float offset = top_controls_height_ - residue; |
| 7693 EXPECT_TRUE( |
| 7694 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset)).did_scroll); |
| 7695 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7696 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 7697 scroll_layer->CurrentScrollOffset().ToString()); |
| 7698 |
| 7699 did_request_redraw_ = false; |
| 7700 did_request_animate_ = false; |
| 7701 did_request_commit_ = false; |
| 7702 |
| 7703 // End the fling while the controls are still offset from the limit. |
| 7704 host_impl_->MainThreadHasStoppedFlinging(); |
| 7705 ASSERT_TRUE(host_impl_->top_controls_manager()->animation()); |
| 7706 EXPECT_TRUE(did_request_animate_); |
| 7707 EXPECT_TRUE(did_request_redraw_); |
| 7708 EXPECT_FALSE(did_request_commit_); |
| 7709 |
| 7710 // Animate the top controls to the limit. |
| 7711 base::TimeTicks animation_time = gfx::FrameTime::Now(); |
| 7712 while (did_request_animate_) { |
| 7713 did_request_redraw_ = false; |
| 7714 did_request_animate_ = false; |
| 7715 did_request_commit_ = false; |
| 7716 |
| 7717 float old_offset = host_impl_->top_controls_manager()->ControlsTopOffset(); |
| 7718 |
| 7719 animation_time += base::TimeDelta::FromMilliseconds(5); |
| 7720 host_impl_->Animate(animation_time); |
| 7721 |
| 7722 float new_offset = host_impl_->top_controls_manager()->ControlsTopOffset(); |
| 7723 |
| 7724 if (new_offset != old_offset) { |
| 7725 EXPECT_TRUE(did_request_redraw_); |
| 7726 EXPECT_TRUE(did_request_commit_); |
| 7727 } |
| 7728 } |
| 7729 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); |
| 7730 EXPECT_EQ(-top_controls_height_, |
| 7731 host_impl_->top_controls_manager()->ControlsTopOffset()); |
| 7732 } |
| 7733 |
| 7734 TEST_F(LayerTreeHostImplWithTopControlsTest, |
7672 TopControlsScrollDeltaInOverScroll) { | 7735 TopControlsScrollDeltaInOverScroll) { |
7673 // test varifies that the overscroll delta should not have accumulated in | 7736 // test varifies that the overscroll delta should not have accumulated in |
7674 // the top controls if we do a hide and show without releasing finger. | 7737 // the top controls if we do a hide and show without releasing finger. |
7675 | 7738 |
7676 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 7739 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
7677 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 7740 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
7678 host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, | 7741 host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, |
7679 false); | 7742 false); |
7680 DrawFrame(); | 7743 DrawFrame(); |
7681 | 7744 |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8388 // surface. | 8451 // surface. |
8389 EXPECT_EQ(0, num_lost_surfaces_); | 8452 EXPECT_EQ(0, num_lost_surfaces_); |
8390 host_impl_->DidLoseOutputSurface(); | 8453 host_impl_->DidLoseOutputSurface(); |
8391 EXPECT_EQ(1, num_lost_surfaces_); | 8454 EXPECT_EQ(1, num_lost_surfaces_); |
8392 host_impl_->DidLoseOutputSurface(); | 8455 host_impl_->DidLoseOutputSurface(); |
8393 EXPECT_LE(1, num_lost_surfaces_); | 8456 EXPECT_LE(1, num_lost_surfaces_); |
8394 } | 8457 } |
8395 | 8458 |
8396 } // namespace | 8459 } // namespace |
8397 } // namespace cc | 8460 } // namespace cc |
OLD | NEW |