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

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

Issue 641873003: Made top controls work with virtual viewport pinch-to-zoom. (Chromium) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 2216 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 host_impl_->active_tree()->SetRootLayer(root.Pass()); 2227 host_impl_->active_tree()->SetRootLayer(root.Pass());
2228 DrawFrame(); 2228 DrawFrame();
2229 2229
2230 // Scroll event is ignored because layer is not scrollable. 2230 // Scroll event is ignored because layer is not scrollable.
2231 EXPECT_EQ(InputHandler::ScrollIgnored, 2231 EXPECT_EQ(InputHandler::ScrollIgnored,
2232 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); 2232 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel));
2233 EXPECT_FALSE(did_request_redraw_); 2233 EXPECT_FALSE(did_request_redraw_);
2234 EXPECT_FALSE(did_request_commit_); 2234 EXPECT_FALSE(did_request_commit_);
2235 } 2235 }
2236 2236
2237 // TODO(bokan): Convert these tests to create inner and outer viewports.
2237 class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { 2238 class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest {
2238 public: 2239 public:
2239 LayerTreeHostImplTopControlsTest() 2240 LayerTreeHostImplTopControlsTest()
2240 // Make the clip size the same as the layer (content) size so the layer is 2241 // Make the clip size the same as the layer (content) size so the layer is
2241 // non-scrollable. 2242 // non-scrollable.
2242 : layer_size_(10, 10), 2243 : layer_size_(10, 10),
2243 clip_size_(layer_size_) { 2244 clip_size_(layer_size_) {
2244 settings_.calculate_top_controls_position = true; 2245 settings_.calculate_top_controls_position = true;
2245 settings_.top_controls_height = 50; 2246 settings_.top_controls_height = 50;
2246 2247
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID); 2298 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID);
2298 // Set a viewport size that is large enough to contain both the top controls 2299 // Set a viewport size that is large enough to contain both the top controls
2299 // and some content. 2300 // and some content.
2300 host_impl_->SetViewportSize(viewport_size_); 2301 host_impl_->SetViewportSize(viewport_size_);
2301 host_impl_->sync_tree()->set_top_controls_layout_height( 2302 host_impl_->sync_tree()->set_top_controls_layout_height(
2302 settings_.top_controls_height); 2303 settings_.top_controls_height);
2303 root_clip_ptr = host_impl_->sync_tree()->root_layer(); 2304 root_clip_ptr = host_impl_->sync_tree()->root_layer();
2304 EXPECT_EQ(clip_size_, root_clip_ptr->bounds()); 2305 EXPECT_EQ(clip_size_, root_clip_ptr->bounds());
2305 } 2306 }
2306 2307
2308 void SetupTopControlsAndScrollLayerWithVirtualViewport(
2309 const gfx::Size& inner_viewport_size,
2310 const gfx::Size& outer_viewport_size,
2311 const gfx::Size& scroll_layer_size) {
2312 CreateHostImpl(settings_, CreateOutputSurface());
2313
2314 scoped_ptr<LayerImpl> root =
2315 LayerImpl::Create(host_impl_->active_tree(), 1);
2316 scoped_ptr<LayerImpl> root_clip =
2317 LayerImpl::Create(host_impl_->active_tree(), 2);
2318 scoped_ptr<LayerImpl> page_scale =
2319 LayerImpl::Create(host_impl_->active_tree(), 3);
2320
2321 scoped_ptr<LayerImpl> outer_scroll =
2322 LayerImpl::Create(host_impl_->active_tree(), 4);
2323 scoped_ptr<LayerImpl> outer_clip =
2324 LayerImpl::Create(host_impl_->active_tree(), 5);
2325
2326 root_clip->SetBounds(inner_viewport_size);
2327 root->SetScrollClipLayer(root_clip->id());
2328 root->SetBounds(outer_viewport_size);
2329 root->SetContentBounds(outer_viewport_size);
2330 root->SetPosition(gfx::PointF());
2331 root->SetDrawsContent(false);
2332 root->SetIsContainerForFixedPositionLayers(true);
2333
2334 outer_clip->SetBounds(outer_viewport_size);
2335 outer_scroll->SetScrollClipLayer(outer_clip->id());
2336 outer_scroll->SetBounds(scroll_layer_size);
2337 outer_scroll->SetContentBounds(scroll_layer_size);
2338 outer_scroll->SetPosition(gfx::PointF());
2339 outer_scroll->SetDrawsContent(false);
2340 outer_scroll->SetIsContainerForFixedPositionLayers(true);
2341
2342 int inner_viewport_scroll_layer_id = root->id();
2343 int outer_viewport_scroll_layer_id = outer_scroll->id();
2344 int page_scale_layer_id = page_scale->id();
2345
2346 outer_clip->AddChild(outer_scroll.Pass());
2347 root->AddChild(outer_clip.Pass());
2348 page_scale->AddChild(root.Pass());
2349 root_clip->AddChild(page_scale.Pass());
2350
2351 host_impl_->active_tree()->SetRootLayer(root_clip.Pass());
2352 host_impl_->active_tree()->SetViewportLayersFromIds(
2353 page_scale_layer_id,
2354 inner_viewport_scroll_layer_id,
2355 outer_viewport_scroll_layer_id);
2356
2357 host_impl_->SetViewportSize(inner_viewport_size);
2358 host_impl_->SetTopControlsLayoutHeight(
2359 settings_.top_controls_height);
2360 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2361 EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds());
2362 }
2363
2307 protected: 2364 protected:
2308 gfx::Size layer_size_; 2365 gfx::Size layer_size_;
2309 gfx::Size clip_size_; 2366 gfx::Size clip_size_;
2310 gfx::Size viewport_size_; 2367 gfx::Size viewport_size_;
2311 2368
2312 LayerTreeSettings settings_; 2369 LayerTreeSettings settings_;
2313 }; // class LayerTreeHostImplTopControlsTest 2370 }; // class LayerTreeHostImplTopControlsTest
2314 2371
2315 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { 2372 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) {
2316 SetupTopControlsAndScrollLayer(); 2373 SetupTopControlsAndScrollLayer();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 2515
2459 host_impl_->active_tree()->set_top_controls_delta(0.f); 2516 host_impl_->active_tree()->set_top_controls_delta(0.f);
2460 host_impl_->DidChangeTopControlsPosition(); 2517 host_impl_->DidChangeTopControlsPosition();
2461 2518
2462 EXPECT_EQ(15.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2519 EXPECT_EQ(15.f, host_impl_->top_controls_manager()->ContentTopOffset());
2463 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta()); 2520 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta());
2464 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height()-15.f), 2521 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height()-15.f),
2465 root_clip_ptr->bounds()); 2522 root_clip_ptr->bounds());
2466 } 2523 }
2467 2524
2525 // Test that showing/hiding the top controls when the viewport is fully scrolled
2526 // doesn't incorrectly change the viewport offset due to clamping from changing
2527 // viewport bounds.
2528 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) {
2529 SetupTopControlsAndScrollLayerWithVirtualViewport(
2530 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2531 DrawFrame();
2532
2533 EXPECT_EQ(settings_.top_controls_height,
2534 host_impl_->active_tree()->total_top_controls_content_offset());
2535
2536 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer();
2537 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer();
2538
2539 // Scroll the viewports to max scroll offset.
2540 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f));
2541 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f));
2542
2543 gfx::ScrollOffset viewport_offset =
2544 host_impl_->active_tree()->TotalScrollOffset();
2545 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset);
2546
2547 // Hide the top controls by 25px.
2548 gfx::Vector2dF scroll_delta(0.f, 25.f);
2549 EXPECT_EQ(InputHandler::ScrollStarted,
2550 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2551 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2552 host_impl_->ScrollEnd();
2553
2554 EXPECT_EQ(scroll_delta.y(),
2555 settings_.top_controls_height -
2556 host_impl_->active_tree()->total_top_controls_content_offset());
2557
2558 inner_scroll->ClampScrollToMaxScrollOffset();
2559 outer_scroll->ClampScrollToMaxScrollOffset();
2560
2561 // We should still be fully scrolled.
2562 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(),
2563 host_impl_->active_tree()->TotalScrollOffset());
2564
2565 viewport_offset = host_impl_->active_tree()->TotalScrollOffset();
2566
2567 // Bring the top controls down by 25px.
2568 scroll_delta = gfx::Vector2dF(0.f, -25.f);
2569 EXPECT_EQ(InputHandler::ScrollStarted,
2570 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2571 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2572 host_impl_->ScrollEnd();
2573
2574 // The viewport offset shouldn't have changed.
2575 EXPECT_EQ(viewport_offset,
2576 host_impl_->active_tree()->TotalScrollOffset());
2577
2578 // Scroll the viewports to max scroll offset.
2579 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f));
2580 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f));
2581 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(),
2582 host_impl_->active_tree()->TotalScrollOffset());
2583 }
2584
2585 // Test that the top controls coming in and out maintains the same aspect ratio
2586 // between the inner and outer viewports.
2587 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) {
2588 SetupTopControlsAndScrollLayerWithVirtualViewport(
2589 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2590 DrawFrame();
2591
2592 EXPECT_EQ(settings_.top_controls_height,
2593 host_impl_->active_tree()->total_top_controls_content_offset());
2594
2595 gfx::Vector2dF scroll_delta(0.f, 25.f);
2596 EXPECT_EQ(InputHandler::ScrollStarted,
2597 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2598 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2599 host_impl_->ScrollEnd();
2600
2601 EXPECT_EQ(scroll_delta.y(),
2602 settings_.top_controls_height -
2603 host_impl_->active_tree()->total_top_controls_content_offset());
2604
2605 // Top controls were hidden by 25px so the inner viewport should have expanded
2606 // by that much.
2607 LayerImpl* outer_container =
2608 host_impl_->active_tree()->OuterViewportContainerLayer();
2609 LayerImpl* inner_container =
2610 host_impl_->active_tree()->InnerViewportContainerLayer();
2611 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->bounds());
2612
2613 // Outer viewport should match inner's aspect ratio. The bounds are ceiled.
2614 float aspect_ratio = inner_container->bounds().width() /
2615 inner_container->bounds().height();
2616 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio));
2617 EXPECT_EQ(expected, outer_container->bounds());
2618 EXPECT_EQ(expected, host_impl_->InnerViewportScrollLayer()->bounds());
2619 }
2620
2621 // Test that scrolling the outer viewport affects the top controls.
2622 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) {
2623 SetupTopControlsAndScrollLayerWithVirtualViewport(
2624 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2625 DrawFrame();
2626
2627 EXPECT_EQ(settings_.top_controls_height,
2628 host_impl_->active_tree()->total_top_controls_content_offset());
2629
2630 // Send a gesture scroll that will scroll the outer viewport, make sure the
2631 // top controls get scrolled.
2632 gfx::Vector2dF scroll_delta(0.f, 15.f);
2633 EXPECT_EQ(InputHandler::ScrollStarted,
2634 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2635 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2636 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
2637 host_impl_->CurrentlyScrollingLayer());
2638 host_impl_->ScrollEnd();
2639
2640 EXPECT_EQ(scroll_delta.y(),
2641 settings_.top_controls_height -
2642 host_impl_->active_tree()->total_top_controls_content_offset());
2643
2644 scroll_delta = gfx::Vector2dF(0.f, 50.f);
2645 EXPECT_EQ(InputHandler::ScrollStarted,
2646 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2647 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2648
2649 EXPECT_EQ(0, host_impl_->active_tree()->total_top_controls_content_offset());
2650 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
2651 host_impl_->CurrentlyScrollingLayer());
2652
2653 host_impl_->ScrollEnd();
2654
2655 // Position the viewports such that the inner viewport will be scrolled.
2656 gfx::Vector2dF inner_viewport_offset(0.f, 25.f);
2657 host_impl_->OuterViewportScrollLayer()->SetScrollDelta(gfx::Vector2dF());
2658 host_impl_->InnerViewportScrollLayer()->SetScrollDelta(inner_viewport_offset);
2659
2660 scroll_delta = gfx::Vector2dF(0.f, -65.f);
2661 EXPECT_EQ(InputHandler::ScrollStarted,
2662 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2663 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2664
2665 EXPECT_EQ(settings_.top_controls_height,
2666 host_impl_->active_tree()->total_top_controls_content_offset());
2667 EXPECT_EQ(inner_viewport_offset.y() +
2668 (scroll_delta.y() + settings_.top_controls_height),
2669 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y());
2670
2671 host_impl_->ScrollEnd();
2672 }
2673
2468 TEST_F(LayerTreeHostImplTopControlsTest, 2674 TEST_F(LayerTreeHostImplTopControlsTest,
2469 ScrollNonScrollableRootWithTopControls) { 2675 ScrollNonScrollableRootWithTopControls) {
2470 SetupTopControlsAndScrollLayer(); 2676 SetupTopControlsAndScrollLayer();
2471 DrawFrame(); 2677 DrawFrame();
2472 2678
2473 EXPECT_EQ(InputHandler::ScrollStarted, 2679 EXPECT_EQ(InputHandler::ScrollStarted,
2474 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2680 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2475 2681
2476 host_impl_->top_controls_manager()->ScrollBegin(); 2682 host_impl_->top_controls_manager()->ScrollBegin();
2477 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); 2683 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f));
(...skipping 4789 matching lines...) Expand 10 before | Expand all | Expand 10 after
7267 // surface. 7473 // surface.
7268 EXPECT_EQ(0, num_lost_surfaces_); 7474 EXPECT_EQ(0, num_lost_surfaces_);
7269 host_impl_->DidLoseOutputSurface(); 7475 host_impl_->DidLoseOutputSurface();
7270 EXPECT_EQ(1, num_lost_surfaces_); 7476 EXPECT_EQ(1, num_lost_surfaces_);
7271 host_impl_->DidLoseOutputSurface(); 7477 host_impl_->DidLoseOutputSurface();
7272 EXPECT_LE(1, num_lost_surfaces_); 7478 EXPECT_LE(1, num_lost_surfaces_);
7273 } 7479 }
7274 7480
7275 } // namespace 7481 } // namespace
7276 } // namespace cc 7482 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698