Chromium Code Reviews| 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 2561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2572 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); | 2572 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 2573 | 2573 |
| 2574 // Scroll the viewports to max scroll offset. | 2574 // Scroll the viewports to max scroll offset. |
| 2575 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f)); | 2575 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f)); |
| 2576 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f)); | 2576 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f)); |
| 2577 | 2577 |
| 2578 gfx::ScrollOffset viewport_offset = | 2578 gfx::ScrollOffset viewport_offset = |
| 2579 host_impl_->active_tree()->TotalScrollOffset(); | 2579 host_impl_->active_tree()->TotalScrollOffset(); |
| 2580 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); | 2580 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); |
| 2581 | 2581 |
| 2582 // Hide the top controls by 25px. | 2582 // Try to Hide the top controls by 25px. |
| 2583 gfx::Vector2dF scroll_delta(0.f, 25.f); | 2583 gfx::Vector2dF scroll_delta(0.f, 25.f); |
| 2584 EXPECT_EQ(InputHandler::ScrollStarted, | 2584 EXPECT_EQ(InputHandler::ScrollStarted, |
| 2585 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 2585 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 2586 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2586 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
| 2587 host_impl_->ScrollEnd(); | 2587 host_impl_->ScrollEnd(); |
| 2588 | 2588 |
| 2589 EXPECT_EQ(scroll_delta.y(), | 2589 // top controls should not hide, since we reached max scrolloffset |
| 2590 EXPECT_EQ(0.f, | |
|
bokan
2014/11/06 16:14:57
This is fine, since scrolling down at the max exte
sujith
2014/11/07 05:06:40
Done.
| |
| 2590 settings_.top_controls_height - | 2591 settings_.top_controls_height - |
| 2591 host_impl_->active_tree()->total_top_controls_content_offset()); | 2592 host_impl_->active_tree()->total_top_controls_content_offset()); |
| 2592 | 2593 |
| 2593 inner_scroll->ClampScrollToMaxScrollOffset(); | 2594 inner_scroll->ClampScrollToMaxScrollOffset(); |
| 2594 outer_scroll->ClampScrollToMaxScrollOffset(); | 2595 outer_scroll->ClampScrollToMaxScrollOffset(); |
| 2595 | 2596 |
| 2596 // We should still be fully scrolled. | 2597 // We should still be fully scrolled. |
| 2597 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), | 2598 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), |
| 2598 host_impl_->active_tree()->TotalScrollOffset()); | 2599 host_impl_->active_tree()->TotalScrollOffset()); |
| 2599 | 2600 |
| 2600 viewport_offset = host_impl_->active_tree()->TotalScrollOffset(); | 2601 viewport_offset = host_impl_->active_tree()->TotalScrollOffset(); |
| 2601 | 2602 |
| 2602 // Bring the top controls down by 25px. | 2603 // Bring the top controls down by 25px. |
| 2603 scroll_delta = gfx::Vector2dF(0.f, -25.f); | 2604 scroll_delta = gfx::Vector2dF(0.f, -25.f); |
| 2604 EXPECT_EQ(InputHandler::ScrollStarted, | 2605 EXPECT_EQ(InputHandler::ScrollStarted, |
| 2605 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 2606 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 2606 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2607 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
| 2607 host_impl_->ScrollEnd(); | 2608 host_impl_->ScrollEnd(); |
| 2608 | 2609 |
| 2609 // The viewport offset shouldn't have changed. | 2610 // The viewport offset should have changed only by the negative offset. |
| 2610 EXPECT_EQ(viewport_offset, | 2611 EXPECT_EQ(viewport_offset + gfx::ScrollOffset(0.f, -25.f), |
|
sujith
2014/11/06 09:28:00
Since the +ve scroll will not reflect, if we scrol
bokan
2014/11/06 16:14:57
If you hide the top controls as mentioned in my co
sujith
2014/11/07 05:06:40
Done.
| |
| 2611 host_impl_->active_tree()->TotalScrollOffset()); | 2612 host_impl_->active_tree()->TotalScrollOffset()); |
| 2612 | 2613 |
| 2613 // Scroll the viewports to max scroll offset. | 2614 // Scroll the viewports to max scroll offset. |
| 2614 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f)); | 2615 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f)); |
| 2615 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f)); | 2616 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f)); |
| 2616 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), | 2617 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), |
| 2617 host_impl_->active_tree()->TotalScrollOffset()); | 2618 host_impl_->active_tree()->TotalScrollOffset()); |
| 2618 } | 2619 } |
| 2619 | 2620 |
| 2620 // Test that the top controls coming in and out maintains the same aspect ratio | 2621 // Test that the top controls coming in and out maintains the same aspect ratio |
| (...skipping 4570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7191 host_impl_->top_controls_manager()->ControlsTopOffset(); | 7192 host_impl_->top_controls_manager()->ControlsTopOffset(); |
| 7192 | 7193 |
| 7193 if (new_offset != old_offset) { | 7194 if (new_offset != old_offset) { |
| 7194 EXPECT_TRUE(did_request_redraw_); | 7195 EXPECT_TRUE(did_request_redraw_); |
| 7195 EXPECT_TRUE(did_request_commit_); | 7196 EXPECT_TRUE(did_request_commit_); |
| 7196 } | 7197 } |
| 7197 } | 7198 } |
| 7198 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); | 7199 EXPECT_FALSE(host_impl_->top_controls_manager()->animation()); |
| 7199 } | 7200 } |
| 7200 | 7201 |
| 7202 TEST_F(LayerTreeHostImplWithTopControlsTest, | |
| 7203 TopControlsScrollDeltaInOverScroll) { | |
| 7204 // test varifies that the overscroll delta should not have accumulated in | |
| 7205 // the top controls if we do a hide and show without releasing finger. | |
| 7206 | |
| 7207 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); | |
| 7208 host_impl_->SetViewportSize(gfx::Size(100, 100)); | |
| 7209 host_impl_->top_controls_manager()->UpdateTopControlsState( | |
| 7210 BOTH, SHOWN, false); | |
| 7211 DrawFrame(); | |
| 7212 | |
| 7213 EXPECT_EQ(InputHandler::ScrollStarted, | |
| 7214 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | |
| 7215 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | |
| 7216 | |
| 7217 float offset = 50; | |
| 7218 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | |
| 7219 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); | |
| 7220 EXPECT_EQ(gfx::Vector2dF().ToString(), | |
| 7221 scroll_layer->TotalScrollOffset().ToString()); | |
| 7222 | |
| 7223 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | |
| 7224 EXPECT_EQ(gfx::Vector2dF(0, offset).ToString(), | |
| 7225 scroll_layer->TotalScrollOffset().ToString()); | |
| 7226 | |
| 7227 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, offset))); | |
| 7228 | |
| 7229 // Should have fully scrolled | |
| 7230 EXPECT_EQ(gfx::Vector2dF(0, scroll_layer->MaxScrollOffset().y()).ToString(), | |
| 7231 scroll_layer->TotalScrollOffset().ToString()); | |
| 7232 | |
| 7233 float overscrollamount = 10; | |
| 7234 | |
| 7235 // Overscroll the content | |
| 7236 EXPECT_FALSE( | |
| 7237 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, overscrollamount))); | |
| 7238 EXPECT_EQ(gfx::Vector2dF(0, 2 * offset).ToString(), | |
| 7239 scroll_layer->TotalScrollOffset().ToString()); | |
| 7240 EXPECT_EQ(gfx::Vector2dF(0, overscrollamount).ToString(), | |
| 7241 host_impl_->accumulated_root_overscroll().ToString()); | |
| 7242 | |
| 7243 EXPECT_TRUE( | |
| 7244 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -2 * offset))); | |
| 7245 EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), | |
| 7246 scroll_layer->TotalScrollOffset().ToString()); | |
| 7247 EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); | |
| 7248 | |
| 7249 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -offset))); | |
| 7250 EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), | |
| 7251 scroll_layer->TotalScrollOffset().ToString()); | |
| 7252 | |
| 7253 // Top controls should be fully visible | |
| 7254 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | |
| 7255 | |
| 7256 host_impl_->ScrollEnd(); | |
| 7257 } | |
| 7258 | |
| 7201 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { | 7259 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { |
| 7202 public: | 7260 public: |
| 7203 void SetupVirtualViewportLayers(const gfx::Size& content_size, | 7261 void SetupVirtualViewportLayers(const gfx::Size& content_size, |
| 7204 const gfx::Size& outer_viewport, | 7262 const gfx::Size& outer_viewport, |
| 7205 const gfx::Size& inner_viewport) { | 7263 const gfx::Size& inner_viewport) { |
| 7206 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); | 7264 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 7207 const int kOuterViewportClipLayerId = 6; | 7265 const int kOuterViewportClipLayerId = 6; |
| 7208 const int kOuterViewportScrollLayerId = 7; | 7266 const int kOuterViewportScrollLayerId = 7; |
| 7209 const int kInnerViewportScrollLayerId = 2; | 7267 const int kInnerViewportScrollLayerId = 2; |
| 7210 const int kInnerViewportClipLayerId = 4; | 7268 const int kInnerViewportClipLayerId = 4; |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7516 // surface. | 7574 // surface. |
| 7517 EXPECT_EQ(0, num_lost_surfaces_); | 7575 EXPECT_EQ(0, num_lost_surfaces_); |
| 7518 host_impl_->DidLoseOutputSurface(); | 7576 host_impl_->DidLoseOutputSurface(); |
| 7519 EXPECT_EQ(1, num_lost_surfaces_); | 7577 EXPECT_EQ(1, num_lost_surfaces_); |
| 7520 host_impl_->DidLoseOutputSurface(); | 7578 host_impl_->DidLoseOutputSurface(); |
| 7521 EXPECT_LE(1, num_lost_surfaces_); | 7579 EXPECT_LE(1, num_lost_surfaces_); |
| 7522 } | 7580 } |
| 7523 | 7581 |
| 7524 } // namespace | 7582 } // namespace |
| 7525 } // namespace cc | 7583 } // namespace cc |
| OLD | NEW |