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 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 float page_scale_factor = 1.f; | 894 float page_scale_factor = 1.f; |
895 | 895 |
896 // The impl-based pinch zoom should adjust the max scroll position. | 896 // The impl-based pinch zoom should adjust the max scroll position. |
897 { | 897 { |
898 host_impl_->active_tree()->SetPageScaleFactorAndLimits( | 898 host_impl_->active_tree()->SetPageScaleFactorAndLimits( |
899 page_scale_factor, min_page_scale, max_page_scale); | 899 page_scale_factor, min_page_scale, max_page_scale); |
900 host_impl_->active_tree()->SetPageScaleDelta(1.f); | 900 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
901 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 901 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
902 | 902 |
903 float page_scale_delta = 2.f; | 903 float page_scale_delta = 2.f; |
904 gfx::Vector2dF expected_container_size_delta( | |
905 container_layer->bounds().width(), container_layer->bounds().height()); | |
906 expected_container_size_delta.Scale((1.f - page_scale_delta) / | |
907 (page_scale_factor * page_scale_delta)); | |
908 | 904 |
909 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); | 905 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); |
910 host_impl_->PinchGestureBegin(); | 906 host_impl_->PinchGestureBegin(); |
911 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); | 907 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); |
912 // While the gesture is still active, the scroll layer should have a | |
913 // container size delta = container->bounds() * ((1.f - | |
914 // page_scale_delta)/()) | |
915 EXPECT_EQ(expected_container_size_delta, | |
916 scroll_layer->FixedContainerSizeDelta()); | |
917 host_impl_->PinchGestureEnd(); | 908 host_impl_->PinchGestureEnd(); |
918 host_impl_->ScrollEnd(); | 909 host_impl_->ScrollEnd(); |
919 EXPECT_FALSE(did_request_animate_); | 910 EXPECT_FALSE(did_request_animate_); |
920 EXPECT_TRUE(did_request_redraw_); | 911 EXPECT_TRUE(did_request_redraw_); |
921 EXPECT_TRUE(did_request_commit_); | 912 EXPECT_TRUE(did_request_commit_); |
922 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); | 913 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); |
923 | 914 |
924 scoped_ptr<ScrollAndScaleSet> scroll_info = | 915 scoped_ptr<ScrollAndScaleSet> scroll_info = |
925 host_impl_->ProcessScrollDeltas(); | 916 host_impl_->ProcessScrollDeltas(); |
926 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); | 917 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2237 // TODO(bokan): Convert these tests to create inner and outer viewports. | 2228 // TODO(bokan): Convert these tests to create inner and outer viewports. |
2238 class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { | 2229 class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { |
2239 public: | 2230 public: |
2240 LayerTreeHostImplTopControlsTest() | 2231 LayerTreeHostImplTopControlsTest() |
2241 // Make the clip size the same as the layer (content) size so the layer is | 2232 // Make the clip size the same as the layer (content) size so the layer is |
2242 // non-scrollable. | 2233 // non-scrollable. |
2243 : layer_size_(10, 10), | 2234 : layer_size_(10, 10), |
2244 clip_size_(layer_size_) { | 2235 clip_size_(layer_size_) { |
2245 settings_.calculate_top_controls_position = true; | 2236 settings_.calculate_top_controls_position = true; |
2246 settings_.top_controls_height = 50; | 2237 settings_.top_controls_height = 50; |
| 2238 settings_.use_pinch_virtual_viewport = true; |
2247 | 2239 |
2248 viewport_size_ = | 2240 viewport_size_ = |
2249 gfx::Size(clip_size_.width(), | 2241 gfx::Size(clip_size_.width(), |
2250 clip_size_.height() + settings_.top_controls_height); | 2242 clip_size_.height() + settings_.top_controls_height); |
2251 } | 2243 } |
2252 | 2244 |
2253 void SetupTopControlsAndScrollLayer() { | 2245 void SetupTopControlsAndScrollLayer() { |
2254 scoped_ptr<LayerImpl> root = | 2246 scoped_ptr<LayerImpl> root = |
2255 LayerImpl::Create(host_impl_->active_tree(), 1); | 2247 LayerImpl::Create(host_impl_->active_tree(), 1); |
2256 scoped_ptr<LayerImpl> root_clip = | 2248 scoped_ptr<LayerImpl> root_clip = |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2379 | 2371 |
2380 SetupTopControlsAndScrollLayer(); | 2372 SetupTopControlsAndScrollLayer(); |
2381 | 2373 |
2382 // After the root layer exists, it should be set normally. | 2374 // After the root layer exists, it should be set normally. |
2383 scroll_info = host_impl_->ProcessScrollDeltas(); | 2375 scroll_info = host_impl_->ProcessScrollDeltas(); |
2384 EXPECT_EQ(scroll_info->top_controls_delta, -20.f); | 2376 EXPECT_EQ(scroll_info->top_controls_delta, -20.f); |
2385 EXPECT_EQ(host_impl_->active_tree()->sent_top_controls_delta(), -20.f); | 2377 EXPECT_EQ(host_impl_->active_tree()->sent_top_controls_delta(), -20.f); |
2386 } | 2378 } |
2387 | 2379 |
2388 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { | 2380 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { |
2389 CreateHostImpl(settings_, CreateOutputSurface()); | 2381 SetupTopControlsAndScrollLayerWithVirtualViewport( |
2390 SetupTopControlsAndScrollLayer(); | 2382 gfx::Size(10, 10), gfx::Size(10, 10), gfx::Size(10, 10)); |
2391 DrawFrame(); | 2383 DrawFrame(); |
2392 | 2384 |
2393 EXPECT_EQ(InputHandler::ScrollStarted, | 2385 EXPECT_EQ(InputHandler::ScrollStarted, |
2394 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 2386 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
2395 | 2387 |
2396 // Make the test scroll delta a fractional amount, to verify that the | 2388 // Make the test scroll delta a fractional amount, to verify that the |
2397 // fixed container size delta is (1) non-zero, and (2) fractional, and | 2389 // fixed container size delta is (1) non-zero, and (2) fractional, and |
2398 // (3) matches the movement of the top controls. | 2390 // (3) matches the movement of the top controls. |
2399 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f); | 2391 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f); |
2400 host_impl_->top_controls_manager()->ScrollBegin(); | 2392 host_impl_->top_controls_manager()->ScrollBegin(); |
2401 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); | 2393 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
2402 host_impl_->top_controls_manager()->ScrollEnd(); | 2394 host_impl_->top_controls_manager()->ScrollEnd(); |
2403 | 2395 |
2404 LayerImpl* inner_viewport_scroll_layer = | 2396 LayerImpl* inner_viewport_scroll_layer = |
2405 host_impl_->active_tree()->InnerViewportScrollLayer(); | 2397 host_impl_->active_tree()->InnerViewportScrollLayer(); |
2406 DCHECK(inner_viewport_scroll_layer); | 2398 DCHECK(inner_viewport_scroll_layer); |
2407 host_impl_->ScrollEnd(); | 2399 host_impl_->ScrollEnd(); |
2408 EXPECT_EQ(top_controls_scroll_delta, | 2400 EXPECT_EQ(top_controls_scroll_delta, |
2409 inner_viewport_scroll_layer->FixedContainerSizeDelta()); | 2401 inner_viewport_scroll_layer->FixedContainerSizeDelta()); |
2410 } | 2402 } |
2411 | 2403 |
2412 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsWithPageScale) { | 2404 // Test that the fixed position container delta is appropriately adjusted |
2413 CreateHostImpl(settings_, CreateOutputSurface()); | 2405 // by the top controls showing/hiding and page scale doesn't affect it. |
2414 SetupTopControlsAndScrollLayer(); | 2406 TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) { |
| 2407 SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 2408 gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100)); |
2415 DrawFrame(); | 2409 DrawFrame(); |
2416 | 2410 |
| 2411 float page_scale = 1.5f; |
| 2412 float top_controls_height = settings_.top_controls_height; |
| 2413 LayerImpl* outer_viewport_scroll_layer = |
| 2414 host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 2415 |
| 2416 // Zoom in, since the fixed container is the outer viewport, the delta should |
| 2417 // not be scaled. |
| 2418 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f); |
| 2419 |
2417 EXPECT_EQ(InputHandler::ScrollStarted, | 2420 EXPECT_EQ(InputHandler::ScrollStarted, |
2418 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 2421 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
2419 | 2422 |
2420 float page_scale = 1.5f; | 2423 // Scroll down, the top controls hiding should expand the viewport size so |
2421 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f); | 2424 // the delta should be equal to the scroll distance. |
2422 | 2425 gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f); |
2423 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.f); | |
2424 gfx::Vector2dF expected_container_size_delta = | |
2425 ScaleVector2d(top_controls_scroll_delta, 1.f / page_scale); | |
2426 host_impl_->top_controls_manager()->ScrollBegin(); | 2426 host_impl_->top_controls_manager()->ScrollBegin(); |
2427 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); | 2427 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
2428 host_impl_->top_controls_manager()->ScrollEnd(); | 2428 EXPECT_EQ(top_controls_height - top_controls_scroll_delta.y(), |
2429 | 2429 host_impl_->top_controls_manager()->ContentTopOffset()); |
2430 LayerImpl* inner_viewport_scroll_layer = | 2430 EXPECT_VECTOR_EQ(top_controls_scroll_delta, |
2431 host_impl_->active_tree()->InnerViewportScrollLayer(); | 2431 outer_viewport_scroll_layer->FixedContainerSizeDelta()); |
2432 DCHECK(inner_viewport_scroll_layer); | |
2433 host_impl_->ScrollEnd(); | 2432 host_impl_->ScrollEnd(); |
2434 | 2433 |
2435 // Use a tolerance that requires the container size delta to be within 0.01 | 2434 // Scroll past the maximum extent. The delta shouldn't be greater than the |
2436 // pixels. | 2435 // top controls height. |
2437 double tolerance = 0.0001; | 2436 host_impl_->top_controls_manager()->ScrollBegin(); |
2438 EXPECT_LT( | 2437 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
2439 (expected_container_size_delta - | 2438 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
2440 inner_viewport_scroll_layer->FixedContainerSizeDelta()).LengthSquared(), | 2439 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); |
2441 tolerance); | 2440 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2441 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, top_controls_height), |
| 2442 outer_viewport_scroll_layer->FixedContainerSizeDelta()); |
| 2443 host_impl_->ScrollEnd(); |
| 2444 |
| 2445 // Scroll in the direction to make the top controls show. |
| 2446 host_impl_->top_controls_manager()->ScrollBegin(); |
| 2447 host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta); |
| 2448 EXPECT_EQ(top_controls_scroll_delta.y(), |
| 2449 host_impl_->top_controls_manager()->ContentTopOffset()); |
| 2450 EXPECT_VECTOR_EQ( |
| 2451 gfx::Vector2dF(0, top_controls_height - top_controls_scroll_delta.y()), |
| 2452 outer_viewport_scroll_layer->FixedContainerSizeDelta()); |
| 2453 host_impl_->top_controls_manager()->ScrollEnd(); |
2442 } | 2454 } |
2443 | 2455 |
2444 // Ensure setting the top controls position explicitly using the setters on the | 2456 // Ensure setting the top controls position explicitly using the setters on the |
2445 // TreeImpl correctly affects the top controls manager and viewport bounds. | 2457 // TreeImpl correctly affects the top controls manager and viewport bounds. |
2446 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { | 2458 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { |
2447 CreateHostImpl(settings_, CreateOutputSurface()); | 2459 CreateHostImpl(settings_, CreateOutputSurface()); |
2448 SetupTopControlsAndScrollLayer(); | 2460 SetupTopControlsAndScrollLayer(); |
2449 DrawFrame(); | 2461 DrawFrame(); |
2450 | 2462 |
2451 host_impl_->active_tree()->set_top_controls_delta(0.f); | 2463 host_impl_->active_tree()->set_top_controls_delta(0.f); |
(...skipping 5047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7499 // surface. | 7511 // surface. |
7500 EXPECT_EQ(0, num_lost_surfaces_); | 7512 EXPECT_EQ(0, num_lost_surfaces_); |
7501 host_impl_->DidLoseOutputSurface(); | 7513 host_impl_->DidLoseOutputSurface(); |
7502 EXPECT_EQ(1, num_lost_surfaces_); | 7514 EXPECT_EQ(1, num_lost_surfaces_); |
7503 host_impl_->DidLoseOutputSurface(); | 7515 host_impl_->DidLoseOutputSurface(); |
7504 EXPECT_LE(1, num_lost_surfaces_); | 7516 EXPECT_LE(1, num_lost_surfaces_); |
7505 } | 7517 } |
7506 | 7518 |
7507 } // namespace | 7519 } // namespace |
7508 } // namespace cc | 7520 } // namespace cc |
OLD | NEW |