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 <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 6500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6511 | 6511 |
6512 // And attempt to scroll past the end | 6512 // And attempt to scroll past the end |
6513 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | 6513 EXPECT_FALSE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
6514 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); | 6514 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); |
6515 EXPECT_EQ(gfx::Vector2dF().ToString(), | 6515 EXPECT_EQ(gfx::Vector2dF().ToString(), |
6516 scroll_layer->TotalScrollOffset().ToString()); | 6516 scroll_layer->TotalScrollOffset().ToString()); |
6517 | 6517 |
6518 host_impl_->ScrollEnd(); | 6518 host_impl_->ScrollEnd(); |
6519 } | 6519 } |
6520 | 6520 |
| 6521 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { |
| 6522 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
| 6523 host_impl_->SetViewportSize(gfx::Size(100, 200)); |
| 6524 DrawFrame(); |
| 6525 |
| 6526 EXPECT_EQ(InputHandler::ScrollStarted, |
| 6527 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 6528 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); |
| 6529 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6530 scroll_layer->TotalScrollOffset().ToString()); |
| 6531 |
| 6532 // Scroll the top controls partially. |
| 6533 const float residue = 35; |
| 6534 float offset = top_controls_height_ - residue; |
| 6535 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
| 6536 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->controls_top_offset()); |
| 6537 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6538 scroll_layer->TotalScrollOffset().ToString()); |
| 6539 |
| 6540 did_request_redraw_ = false; |
| 6541 did_request_animate_ = false; |
| 6542 did_request_commit_ = false; |
| 6543 |
| 6544 // End the scroll while the controls are still offset from their limit. |
| 6545 host_impl_->ScrollEnd(); |
| 6546 ASSERT_TRUE(host_impl_->top_controls_manager()->animation()); |
| 6547 EXPECT_TRUE(did_request_animate_); |
| 6548 EXPECT_TRUE(did_request_redraw_); |
| 6549 EXPECT_FALSE(did_request_commit_); |
| 6550 |
| 6551 // The top controls should properly animate until finished, despite the scroll |
| 6552 // offset being at the origin. |
| 6553 base::TimeTicks animation_time = gfx::FrameTime::Now(); |
| 6554 while (did_request_animate_) { |
| 6555 did_request_redraw_ = false; |
| 6556 did_request_animate_ = false; |
| 6557 did_request_commit_ = false; |
| 6558 |
| 6559 float old_offset = |
| 6560 host_impl_->top_controls_manager()->controls_top_offset(); |
| 6561 |
| 6562 animation_time += base::TimeDelta::FromMilliseconds(5); |
| 6563 host_impl_->Animate(animation_time); |
| 6564 EXPECT_EQ(gfx::Vector2dF().ToString(), |
| 6565 scroll_layer->TotalScrollOffset().ToString()); |
| 6566 |
| 6567 float new_offset = |
| 6568 host_impl_->top_controls_manager()->controls_top_offset(); |
| 6569 |
| 6570 // No commit is needed as the controls are animating the content offset, |
| 6571 // not the scroll offset. |
| 6572 EXPECT_FALSE(did_request_commit_); |
| 6573 |
| 6574 if (new_offset != old_offset) |
| 6575 EXPECT_TRUE(did_request_redraw_); |
| 6576 |
| 6577 if (new_offset != 0) { |
| 6578 EXPECT_TRUE(host_impl_->top_controls_manager()->animation()); |
| 6579 EXPECT_TRUE(did_request_animate_); |
| 6580 } |
| 6581 } |
| 6582 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); |
| 6583 } |
| 6584 |
| 6585 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { |
| 6586 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); |
| 6587 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
| 6588 float initial_scroll_offset = 50; |
| 6589 scroll_layer->SetScrollOffset(gfx::Vector2d(0, initial_scroll_offset)); |
| 6590 DrawFrame(); |
| 6591 |
| 6592 EXPECT_EQ(InputHandler::ScrollStarted, |
| 6593 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 6594 EXPECT_EQ(0, host_impl_->top_controls_manager()->controls_top_offset()); |
| 6595 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 6596 scroll_layer->TotalScrollOffset().ToString()); |
| 6597 |
| 6598 // Scroll the top controls partially. |
| 6599 const float residue = 15; |
| 6600 float offset = top_controls_height_ - residue; |
| 6601 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); |
| 6602 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->controls_top_offset()); |
| 6603 EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), |
| 6604 scroll_layer->TotalScrollOffset().ToString()); |
| 6605 |
| 6606 did_request_redraw_ = false; |
| 6607 did_request_animate_ = false; |
| 6608 did_request_commit_ = false; |
| 6609 |
| 6610 // End the scroll while the controls are still offset from the limit. |
| 6611 host_impl_->ScrollEnd(); |
| 6612 ASSERT_TRUE(host_impl_->top_controls_manager()->animation()); |
| 6613 EXPECT_TRUE(did_request_animate_); |
| 6614 EXPECT_TRUE(did_request_redraw_); |
| 6615 EXPECT_FALSE(did_request_commit_); |
| 6616 |
| 6617 // Animate the top controls to the limit. |
| 6618 base::TimeTicks animation_time = gfx::FrameTime::Now(); |
| 6619 while (did_request_animate_) { |
| 6620 did_request_redraw_ = false; |
| 6621 did_request_animate_ = false; |
| 6622 did_request_commit_ = false; |
| 6623 |
| 6624 float old_offset = |
| 6625 host_impl_->top_controls_manager()->controls_top_offset(); |
| 6626 |
| 6627 animation_time += base::TimeDelta::FromMilliseconds(5); |
| 6628 host_impl_->Animate(animation_time); |
| 6629 |
| 6630 float new_offset = |
| 6631 host_impl_->top_controls_manager()->controls_top_offset(); |
| 6632 |
| 6633 if (new_offset != old_offset) { |
| 6634 EXPECT_TRUE(did_request_redraw_); |
| 6635 EXPECT_TRUE(did_request_commit_); |
| 6636 } |
| 6637 } |
| 6638 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); |
| 6639 } |
| 6640 |
6521 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { | 6641 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { |
6522 public: | 6642 public: |
6523 void SetupVirtualViewportLayers(const gfx::Size& content_size, | 6643 void SetupVirtualViewportLayers(const gfx::Size& content_size, |
6524 const gfx::Size& outer_viewport, | 6644 const gfx::Size& outer_viewport, |
6525 const gfx::Size& inner_viewport) { | 6645 const gfx::Size& inner_viewport) { |
6526 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); | 6646 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
6527 const int kOuterViewportClipLayerId = 6; | 6647 const int kOuterViewportClipLayerId = 6; |
6528 const int kOuterViewportScrollLayerId = 7; | 6648 const int kOuterViewportScrollLayerId = 7; |
6529 const int kInnerViewportScrollLayerId = 2; | 6649 const int kInnerViewportScrollLayerId = 2; |
6530 const int kInnerViewportClipLayerId = 4; | 6650 const int kInnerViewportClipLayerId = 4; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6845 host_impl_->DidLoseOutputSurface(); | 6965 host_impl_->DidLoseOutputSurface(); |
6846 EXPECT_TRUE(host_impl_->IsContextLost()); | 6966 EXPECT_TRUE(host_impl_->IsContextLost()); |
6847 EXPECT_EQ(1, num_lost_surfaces_); | 6967 EXPECT_EQ(1, num_lost_surfaces_); |
6848 host_impl_->DidLoseOutputSurface(); | 6968 host_impl_->DidLoseOutputSurface(); |
6849 EXPECT_TRUE(host_impl_->IsContextLost()); | 6969 EXPECT_TRUE(host_impl_->IsContextLost()); |
6850 EXPECT_EQ(1, num_lost_surfaces_); | 6970 EXPECT_EQ(1, num_lost_surfaces_); |
6851 } | 6971 } |
6852 | 6972 |
6853 } // namespace | 6973 } // namespace |
6854 } // namespace cc | 6974 } // namespace cc |
OLD | NEW |