Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(842)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 646623003: Don't scale fixed container adjustment in pinch virtual viewport. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/layer_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 float page_scale_factor = 1.f; 907 float page_scale_factor = 1.f;
908 908
909 // The impl-based pinch zoom should adjust the max scroll position. 909 // The impl-based pinch zoom should adjust the max scroll position.
910 { 910 {
911 host_impl_->active_tree()->SetPageScaleFactorAndLimits( 911 host_impl_->active_tree()->SetPageScaleFactorAndLimits(
912 page_scale_factor, min_page_scale, max_page_scale); 912 page_scale_factor, min_page_scale, max_page_scale);
913 host_impl_->active_tree()->SetPageScaleDelta(1.f); 913 host_impl_->active_tree()->SetPageScaleDelta(1.f);
914 scroll_layer->SetScrollDelta(gfx::Vector2d()); 914 scroll_layer->SetScrollDelta(gfx::Vector2d());
915 915
916 float page_scale_delta = 2.f; 916 float page_scale_delta = 2.f;
917 gfx::Vector2dF expected_container_size_delta(
918 container_layer->bounds().width(), container_layer->bounds().height());
919 expected_container_size_delta.Scale((1.f - page_scale_delta) /
920 (page_scale_factor * page_scale_delta));
921 917
922 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); 918 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture);
923 host_impl_->PinchGestureBegin(); 919 host_impl_->PinchGestureBegin();
924 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); 920 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50));
925 // While the gesture is still active, the scroll layer should have a
926 // container size delta = container->bounds() * ((1.f -
927 // page_scale_delta)/())
928 EXPECT_EQ(expected_container_size_delta,
929 scroll_layer->FixedContainerSizeDelta());
930 host_impl_->PinchGestureEnd(); 921 host_impl_->PinchGestureEnd();
931 host_impl_->ScrollEnd(); 922 host_impl_->ScrollEnd();
932 EXPECT_FALSE(did_request_animate_); 923 EXPECT_FALSE(did_request_animate_);
933 EXPECT_TRUE(did_request_redraw_); 924 EXPECT_TRUE(did_request_redraw_);
934 EXPECT_TRUE(did_request_commit_); 925 EXPECT_TRUE(did_request_commit_);
935 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds()); 926 EXPECT_EQ(gfx::Size(50, 50), container_layer->bounds());
936 927
937 scoped_ptr<ScrollAndScaleSet> scroll_info = 928 scoped_ptr<ScrollAndScaleSet> scroll_info =
938 host_impl_->ProcessScrollDeltas(); 929 host_impl_->ProcessScrollDeltas();
939 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); 930 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta);
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after
2251 // TODO(bokan): Convert these tests to create inner and outer viewports. 2242 // TODO(bokan): Convert these tests to create inner and outer viewports.
2252 class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { 2243 class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest {
2253 public: 2244 public:
2254 LayerTreeHostImplTopControlsTest() 2245 LayerTreeHostImplTopControlsTest()
2255 // Make the clip size the same as the layer (content) size so the layer is 2246 // Make the clip size the same as the layer (content) size so the layer is
2256 // non-scrollable. 2247 // non-scrollable.
2257 : layer_size_(10, 10), 2248 : layer_size_(10, 10),
2258 clip_size_(layer_size_) { 2249 clip_size_(layer_size_) {
2259 settings_.calculate_top_controls_position = true; 2250 settings_.calculate_top_controls_position = true;
2260 settings_.top_controls_height = 50; 2251 settings_.top_controls_height = 50;
2252 settings_.use_pinch_virtual_viewport = true;
2261 2253
2262 viewport_size_ = 2254 viewport_size_ =
2263 gfx::Size(clip_size_.width(), 2255 gfx::Size(clip_size_.width(),
2264 clip_size_.height() + settings_.top_controls_height); 2256 clip_size_.height() + settings_.top_controls_height);
2265 } 2257 }
2266 2258
2267 void SetupTopControlsAndScrollLayer() { 2259 void SetupTopControlsAndScrollLayer() {
2268 scoped_ptr<LayerImpl> root = 2260 scoped_ptr<LayerImpl> root =
2269 LayerImpl::Create(host_impl_->active_tree(), 1); 2261 LayerImpl::Create(host_impl_->active_tree(), 1);
2270 scoped_ptr<LayerImpl> root_clip = 2262 scoped_ptr<LayerImpl> root_clip =
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 2385
2394 SetupTopControlsAndScrollLayer(); 2386 SetupTopControlsAndScrollLayer();
2395 2387
2396 // After the root layer exists, it should be set normally. 2388 // After the root layer exists, it should be set normally.
2397 scroll_info = host_impl_->ProcessScrollDeltas(); 2389 scroll_info = host_impl_->ProcessScrollDeltas();
2398 EXPECT_EQ(scroll_info->top_controls_delta, -20.f); 2390 EXPECT_EQ(scroll_info->top_controls_delta, -20.f);
2399 EXPECT_EQ(host_impl_->active_tree()->sent_top_controls_delta(), -20.f); 2391 EXPECT_EQ(host_impl_->active_tree()->sent_top_controls_delta(), -20.f);
2400 } 2392 }
2401 2393
2402 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { 2394 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) {
2403 CreateHostImpl(settings_, CreateOutputSurface()); 2395 SetupTopControlsAndScrollLayerWithVirtualViewport(
2404 SetupTopControlsAndScrollLayer(); 2396 gfx::Size(10, 10), gfx::Size(10, 10), gfx::Size(10, 10));
2405 DrawFrame(); 2397 DrawFrame();
2406 2398
2407 EXPECT_EQ(InputHandler::ScrollStarted, 2399 EXPECT_EQ(InputHandler::ScrollStarted,
2408 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2400 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2409 2401
2410 // Make the test scroll delta a fractional amount, to verify that the 2402 // Make the test scroll delta a fractional amount, to verify that the
2411 // fixed container size delta is (1) non-zero, and (2) fractional, and 2403 // fixed container size delta is (1) non-zero, and (2) fractional, and
2412 // (3) matches the movement of the top controls. 2404 // (3) matches the movement of the top controls.
2413 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f); 2405 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f);
2414 host_impl_->top_controls_manager()->ScrollBegin(); 2406 host_impl_->top_controls_manager()->ScrollBegin();
2415 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2407 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2416 host_impl_->top_controls_manager()->ScrollEnd(); 2408 host_impl_->top_controls_manager()->ScrollEnd();
2417 2409
2418 LayerImpl* inner_viewport_scroll_layer = 2410 LayerImpl* inner_viewport_scroll_layer =
2419 host_impl_->active_tree()->InnerViewportScrollLayer(); 2411 host_impl_->active_tree()->InnerViewportScrollLayer();
2420 DCHECK(inner_viewport_scroll_layer); 2412 DCHECK(inner_viewport_scroll_layer);
2421 host_impl_->ScrollEnd(); 2413 host_impl_->ScrollEnd();
2422 EXPECT_EQ(top_controls_scroll_delta, 2414 EXPECT_EQ(top_controls_scroll_delta,
2423 inner_viewport_scroll_layer->FixedContainerSizeDelta()); 2415 inner_viewport_scroll_layer->FixedContainerSizeDelta());
2424 } 2416 }
2425 2417
2426 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsWithPageScale) { 2418 // Test that the fixed position container delta is appropriately adjusted
2427 CreateHostImpl(settings_, CreateOutputSurface()); 2419 // by the top controls showing/hiding and page scale doesn't affect it.
2428 SetupTopControlsAndScrollLayer(); 2420 TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) {
2421 SetupTopControlsAndScrollLayerWithVirtualViewport(
2422 gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100));
2429 DrawFrame(); 2423 DrawFrame();
2430 2424
2425 float page_scale = 1.5f;
2426 float top_controls_height = settings_.top_controls_height;
2427 LayerImpl* outer_viewport_scroll_layer =
2428 host_impl_->active_tree()->OuterViewportScrollLayer();
2429
2430 // Zoom in, since the fixed container is the outer viewport, the delta should
2431 // not be scaled.
2432 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f);
2433
2431 EXPECT_EQ(InputHandler::ScrollStarted, 2434 EXPECT_EQ(InputHandler::ScrollStarted,
2432 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2435 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2433 2436
2434 float page_scale = 1.5f; 2437 // Scroll down, the top controls hiding should expand the viewport size so
2435 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f); 2438 // the delta should be equal to the scroll distance.
2436 2439 gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f);
2437 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.f);
2438 gfx::Vector2dF expected_container_size_delta =
2439 ScaleVector2d(top_controls_scroll_delta, 1.f / page_scale);
2440 host_impl_->top_controls_manager()->ScrollBegin(); 2440 host_impl_->top_controls_manager()->ScrollBegin();
2441 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2441 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2442 host_impl_->top_controls_manager()->ScrollEnd(); 2442 EXPECT_EQ(top_controls_height - top_controls_scroll_delta.y(),
2443 2443 host_impl_->top_controls_manager()->ContentTopOffset());
2444 LayerImpl* inner_viewport_scroll_layer = 2444 EXPECT_VECTOR_EQ(top_controls_scroll_delta,
2445 host_impl_->active_tree()->InnerViewportScrollLayer(); 2445 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2446 DCHECK(inner_viewport_scroll_layer);
2447 host_impl_->ScrollEnd(); 2446 host_impl_->ScrollEnd();
2448 2447
2449 // Use a tolerance that requires the container size delta to be within 0.01 2448 // Scroll past the maximum extent. The delta shouldn't be greater than the
2450 // pixels. 2449 // top controls height.
2451 double tolerance = 0.0001; 2450 host_impl_->top_controls_manager()->ScrollBegin();
2452 EXPECT_LT( 2451 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2453 (expected_container_size_delta - 2452 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2454 inner_viewport_scroll_layer->FixedContainerSizeDelta()).LengthSquared(), 2453 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2455 tolerance); 2454 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2455 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, top_controls_height),
2456 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2457 host_impl_->ScrollEnd();
2458
2459 // Scroll in the direction to make the top controls show.
2460 host_impl_->top_controls_manager()->ScrollBegin();
2461 host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta);
2462 EXPECT_EQ(top_controls_scroll_delta.y(),
2463 host_impl_->top_controls_manager()->ContentTopOffset());
2464 EXPECT_VECTOR_EQ(
2465 gfx::Vector2dF(0, top_controls_height - top_controls_scroll_delta.y()),
2466 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2467 host_impl_->top_controls_manager()->ScrollEnd();
2456 } 2468 }
2457 2469
2458 // Ensure setting the top controls position explicitly using the setters on the 2470 // Ensure setting the top controls position explicitly using the setters on the
2459 // TreeImpl correctly affects the top controls manager and viewport bounds. 2471 // TreeImpl correctly affects the top controls manager and viewport bounds.
2460 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { 2472 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) {
2461 CreateHostImpl(settings_, CreateOutputSurface()); 2473 CreateHostImpl(settings_, CreateOutputSurface());
2462 SetupTopControlsAndScrollLayer(); 2474 SetupTopControlsAndScrollLayer();
2463 DrawFrame(); 2475 DrawFrame();
2464 2476
2465 host_impl_->active_tree()->set_top_controls_delta(0.f); 2477 host_impl_->active_tree()->set_top_controls_delta(0.f);
(...skipping 5050 matching lines...) Expand 10 before | Expand all | Expand 10 after
7516 // surface. 7528 // surface.
7517 EXPECT_EQ(0, num_lost_surfaces_); 7529 EXPECT_EQ(0, num_lost_surfaces_);
7518 host_impl_->DidLoseOutputSurface(); 7530 host_impl_->DidLoseOutputSurface();
7519 EXPECT_EQ(1, num_lost_surfaces_); 7531 EXPECT_EQ(1, num_lost_surfaces_);
7520 host_impl_->DidLoseOutputSurface(); 7532 host_impl_->DidLoseOutputSurface();
7521 EXPECT_LE(1, num_lost_surfaces_); 7533 EXPECT_LE(1, num_lost_surfaces_);
7522 } 7534 }
7523 7535
7524 } // namespace 7536 } // namespace
7525 } // namespace cc 7537 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698