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

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

Issue 714003002: Allow changing top controls height (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some more fixes Created 6 years, 1 month 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 scrollbar_fade_start_ = start_fade; 153 scrollbar_fade_start_ = start_fade;
154 requested_scrollbar_animation_delay_ = delay; 154 requested_scrollbar_animation_delay_ = delay;
155 } 155 }
156 void DidActivateSyncTree() override {} 156 void DidActivateSyncTree() override {}
157 void DidManageTiles() override {} 157 void DidManageTiles() override {}
158 158
159 void set_reduce_memory_result(bool reduce_memory_result) { 159 void set_reduce_memory_result(bool reduce_memory_result) {
160 reduce_memory_result_ = reduce_memory_result; 160 reduce_memory_result_ = reduce_memory_result;
161 } 161 }
162 162
163 bool CreateHostImpl(const LayerTreeSettings& settings, 163 virtual bool CreateHostImpl(const LayerTreeSettings& settings,
164 scoped_ptr<OutputSurface> output_surface) { 164 scoped_ptr<OutputSurface> output_surface) {
165 host_impl_ = LayerTreeHostImpl::Create(settings, 165 host_impl_ = LayerTreeHostImpl::Create(settings,
166 this, 166 this,
167 &proxy_, 167 &proxy_,
168 &stats_instrumentation_, 168 &stats_instrumentation_,
169 shared_bitmap_manager_.get(), 169 shared_bitmap_manager_.get(),
170 gpu_memory_buffer_manager_.get(), 170 gpu_memory_buffer_manager_.get(),
171 0); 171 0);
172 bool init = host_impl_->InitializeRenderer(output_surface.Pass()); 172 bool init = host_impl_->InitializeRenderer(output_surface.Pass());
173 host_impl_->SetViewportSize(gfx::Size(10, 10)); 173 host_impl_->SetViewportSize(gfx::Size(10, 10));
174 return init; 174 return init;
(...skipping 2078 matching lines...) Expand 10 before | Expand all | Expand 10 after
2253 EXPECT_FALSE(did_request_commit_); 2253 EXPECT_FALSE(did_request_commit_);
2254 } 2254 }
2255 2255
2256 // TODO(bokan): Convert these tests to create inner and outer viewports. 2256 // TODO(bokan): Convert these tests to create inner and outer viewports.
2257 class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { 2257 class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest {
2258 public: 2258 public:
2259 LayerTreeHostImplTopControlsTest() 2259 LayerTreeHostImplTopControlsTest()
2260 // Make the clip size the same as the layer (content) size so the layer is 2260 // Make the clip size the same as the layer (content) size so the layer is
2261 // non-scrollable. 2261 // non-scrollable.
2262 : layer_size_(10, 10), 2262 : layer_size_(10, 10),
2263 clip_size_(layer_size_) { 2263 clip_size_(layer_size_),
2264 top_controls_height_(50) {
2264 settings_.calculate_top_controls_position = true; 2265 settings_.calculate_top_controls_position = true;
2265 settings_.top_controls_height = 50;
2266 settings_.use_pinch_virtual_viewport = true; 2266 settings_.use_pinch_virtual_viewport = true;
2267 2267
2268 viewport_size_ = 2268 viewport_size_ = gfx::Size(clip_size_.width(),
2269 gfx::Size(clip_size_.width(), 2269 clip_size_.height() + top_controls_height_);
2270 clip_size_.height() + settings_.top_controls_height); 2270 }
2271
2272 bool CreateHostImpl(const LayerTreeSettings& settings,
2273 scoped_ptr<OutputSurface> output_surface) override {
2274 bool init =
2275 LayerTreeHostImplTest::CreateHostImpl(settings, output_surface.Pass());
2276 if (init && settings.calculate_top_controls_position) {
2277 host_impl_->active_tree()->set_top_controls_height(top_controls_height_);
2278 host_impl_->active_tree()->set_top_controls_delta(top_controls_height_);
2279 host_impl_->top_controls_manager()->SetTopControlsHeight(
2280 top_controls_height_);
2281 }
2282 return init;
2271 } 2283 }
2272 2284
2273 void SetupTopControlsAndScrollLayer() { 2285 void SetupTopControlsAndScrollLayer() {
2274 scoped_ptr<LayerImpl> root = 2286 scoped_ptr<LayerImpl> root =
2275 LayerImpl::Create(host_impl_->active_tree(), 1); 2287 LayerImpl::Create(host_impl_->active_tree(), 1);
2276 scoped_ptr<LayerImpl> root_clip = 2288 scoped_ptr<LayerImpl> root_clip =
2277 LayerImpl::Create(host_impl_->active_tree(), 2); 2289 LayerImpl::Create(host_impl_->active_tree(), 2);
2278 root_clip->SetBounds(clip_size_); 2290 root_clip->SetBounds(clip_size_);
2279 root->SetScrollClipLayer(root_clip->id()); 2291 root->SetScrollClipLayer(root_clip->id());
2280 root->SetBounds(layer_size_); 2292 root->SetBounds(layer_size_);
2281 root->SetContentBounds(layer_size_); 2293 root->SetContentBounds(layer_size_);
2282 root->SetPosition(gfx::PointF()); 2294 root->SetPosition(gfx::PointF());
2283 root->SetDrawsContent(false); 2295 root->SetDrawsContent(false);
2284 root->SetIsContainerForFixedPositionLayers(true); 2296 root->SetIsContainerForFixedPositionLayers(true);
2285 int inner_viewport_scroll_layer_id = root->id(); 2297 int inner_viewport_scroll_layer_id = root->id();
2286 int page_scale_layer_id = root_clip->id(); 2298 int page_scale_layer_id = root_clip->id();
2287 root_clip->AddChild(root.Pass()); 2299 root_clip->AddChild(root.Pass());
2288 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); 2300 host_impl_->active_tree()->SetRootLayer(root_clip.Pass());
2289 host_impl_->active_tree()->SetViewportLayersFromIds( 2301 host_impl_->active_tree()->SetViewportLayersFromIds(
2290 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID); 2302 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID);
2291 // Set a viewport size that is large enough to contain both the top controls 2303 // Set a viewport size that is large enough to contain both the top controls
2292 // and some content. 2304 // and some content.
2293 host_impl_->SetViewportSize(viewport_size_); 2305 host_impl_->SetViewportSize(viewport_size_);
2294 host_impl_->SetTopControlsLayoutHeight( 2306 host_impl_->SetTopControlsShrinkBlinkSize(true);
2295 settings_.top_controls_height);
2296 2307
2297 host_impl_->CreatePendingTree(); 2308 host_impl_->CreatePendingTree();
2298 root = 2309 root =
2299 LayerImpl::Create(host_impl_->sync_tree(), 1); 2310 LayerImpl::Create(host_impl_->sync_tree(), 1);
2300 root_clip = 2311 root_clip =
2301 LayerImpl::Create(host_impl_->sync_tree(), 2); 2312 LayerImpl::Create(host_impl_->sync_tree(), 2);
2302 root_clip->SetBounds(clip_size_); 2313 root_clip->SetBounds(clip_size_);
2303 root->SetScrollClipLayer(root_clip->id()); 2314 root->SetScrollClipLayer(root_clip->id());
2304 root->SetBounds(layer_size_); 2315 root->SetBounds(layer_size_);
2305 root->SetContentBounds(layer_size_); 2316 root->SetContentBounds(layer_size_);
2306 root->SetPosition(gfx::PointF()); 2317 root->SetPosition(gfx::PointF());
2307 root->SetDrawsContent(false); 2318 root->SetDrawsContent(false);
2308 root->SetIsContainerForFixedPositionLayers(true); 2319 root->SetIsContainerForFixedPositionLayers(true);
2309 inner_viewport_scroll_layer_id = root->id(); 2320 inner_viewport_scroll_layer_id = root->id();
2310 page_scale_layer_id = root_clip->id(); 2321 page_scale_layer_id = root_clip->id();
2311 root_clip->AddChild(root.Pass()); 2322 root_clip->AddChild(root.Pass());
2312 host_impl_->sync_tree()->SetRootLayer(root_clip.Pass()); 2323 host_impl_->sync_tree()->SetRootLayer(root_clip.Pass());
2313 host_impl_->sync_tree()->SetViewportLayersFromIds( 2324 host_impl_->sync_tree()->SetViewportLayersFromIds(
2314 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID); 2325 page_scale_layer_id, inner_viewport_scroll_layer_id, Layer::INVALID_ID);
2315 // Set a viewport size that is large enough to contain both the top controls 2326 // Set a viewport size that is large enough to contain both the top controls
2316 // and some content. 2327 // and some content.
2317 host_impl_->SetViewportSize(viewport_size_); 2328 host_impl_->SetViewportSize(viewport_size_);
2318 host_impl_->sync_tree()->set_top_controls_layout_height( 2329 host_impl_->sync_tree()->set_top_controls_height(top_controls_height_);
2319 settings_.top_controls_height); 2330 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2320 } 2331 }
2321 2332
2322 void SetupTopControlsAndScrollLayerWithVirtualViewport( 2333 void SetupTopControlsAndScrollLayerWithVirtualViewport(
2323 const gfx::Size& inner_viewport_size, 2334 const gfx::Size& inner_viewport_size,
2324 const gfx::Size& outer_viewport_size, 2335 const gfx::Size& outer_viewport_size,
2325 const gfx::Size& scroll_layer_size) { 2336 const gfx::Size& scroll_layer_size) {
2326 CreateHostImpl(settings_, CreateOutputSurface()); 2337 CreateHostImpl(settings_, CreateOutputSurface());
2327 host_impl_->SetTopControlsLayoutHeight( 2338 host_impl_->SetTopControlsShrinkBlinkSize(true);
2328 settings_.top_controls_height);
2329 2339
2330 scoped_ptr<LayerImpl> root = 2340 scoped_ptr<LayerImpl> root =
2331 LayerImpl::Create(host_impl_->active_tree(), 1); 2341 LayerImpl::Create(host_impl_->active_tree(), 1);
2332 scoped_ptr<LayerImpl> root_clip = 2342 scoped_ptr<LayerImpl> root_clip =
2333 LayerImpl::Create(host_impl_->active_tree(), 2); 2343 LayerImpl::Create(host_impl_->active_tree(), 2);
2334 scoped_ptr<LayerImpl> page_scale = 2344 scoped_ptr<LayerImpl> page_scale =
2335 LayerImpl::Create(host_impl_->active_tree(), 3); 2345 LayerImpl::Create(host_impl_->active_tree(), 3);
2336 2346
2337 scoped_ptr<LayerImpl> outer_scroll = 2347 scoped_ptr<LayerImpl> outer_scroll =
2338 LayerImpl::Create(host_impl_->active_tree(), 4); 2348 LayerImpl::Create(host_impl_->active_tree(), 4);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 2382
2373 host_impl_->SetViewportSize(inner_viewport_size); 2383 host_impl_->SetViewportSize(inner_viewport_size);
2374 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2384 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2375 EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds()); 2385 EXPECT_EQ(inner_viewport_size, root_clip_ptr->bounds());
2376 } 2386 }
2377 2387
2378 protected: 2388 protected:
2379 gfx::Size layer_size_; 2389 gfx::Size layer_size_;
2380 gfx::Size clip_size_; 2390 gfx::Size clip_size_;
2381 gfx::Size viewport_size_; 2391 gfx::Size viewport_size_;
2392 float top_controls_height_;
2382 2393
2383 LayerTreeSettings settings_; 2394 LayerTreeSettings settings_;
2384 }; // class LayerTreeHostImplTopControlsTest 2395 }; // class LayerTreeHostImplTopControlsTest
2385 2396
2386 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { 2397 TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) {
2387 SetupTopControlsAndScrollLayerWithVirtualViewport( 2398 SetupTopControlsAndScrollLayerWithVirtualViewport(
2388 gfx::Size(10, 10), gfx::Size(10, 10), gfx::Size(10, 10)); 2399 gfx::Size(10, 10), gfx::Size(10, 10), gfx::Size(10, 10));
2389 DrawFrame(); 2400 DrawFrame();
2390 2401
2391 EXPECT_EQ(InputHandler::ScrollStarted, 2402 EXPECT_EQ(InputHandler::ScrollStarted,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
2483 } 2494 }
2484 2495
2485 // Test that the fixed position container delta is appropriately adjusted 2496 // Test that the fixed position container delta is appropriately adjusted
2486 // by the top controls showing/hiding and page scale doesn't affect it. 2497 // by the top controls showing/hiding and page scale doesn't affect it.
2487 TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) { 2498 TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) {
2488 SetupTopControlsAndScrollLayerWithVirtualViewport( 2499 SetupTopControlsAndScrollLayerWithVirtualViewport(
2489 gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100)); 2500 gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100));
2490 DrawFrame(); 2501 DrawFrame();
2491 2502
2492 float page_scale = 1.5f; 2503 float page_scale = 1.5f;
2493 float top_controls_height = settings_.top_controls_height;
2494 LayerImpl* outer_viewport_scroll_layer = 2504 LayerImpl* outer_viewport_scroll_layer =
2495 host_impl_->active_tree()->OuterViewportScrollLayer(); 2505 host_impl_->active_tree()->OuterViewportScrollLayer();
2496 2506
2497 // Zoom in, since the fixed container is the outer viewport, the delta should 2507 // Zoom in, since the fixed container is the outer viewport, the delta should
2498 // not be scaled. 2508 // not be scaled.
2499 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f); 2509 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, 1.f, 2.f);
2500 2510
2501 EXPECT_EQ(InputHandler::ScrollStarted, 2511 EXPECT_EQ(InputHandler::ScrollStarted,
2502 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2512 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2503 2513
2504 // Scroll down, the top controls hiding should expand the viewport size so 2514 // Scroll down, the top controls hiding should expand the viewport size so
2505 // the delta should be equal to the scroll distance. 2515 // the delta should be equal to the scroll distance.
2506 gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f); 2516 gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f);
2507 host_impl_->top_controls_manager()->ScrollBegin(); 2517 host_impl_->top_controls_manager()->ScrollBegin();
2508 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2518 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2509 EXPECT_EQ(top_controls_height - top_controls_scroll_delta.y(), 2519 EXPECT_EQ(top_controls_height_ - top_controls_scroll_delta.y(),
2510 host_impl_->top_controls_manager()->ContentTopOffset()); 2520 host_impl_->top_controls_manager()->ContentTopOffset());
2511 EXPECT_VECTOR_EQ(top_controls_scroll_delta, 2521 EXPECT_VECTOR_EQ(top_controls_scroll_delta,
2512 outer_viewport_scroll_layer->FixedContainerSizeDelta()); 2522 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2513 host_impl_->ScrollEnd(); 2523 host_impl_->ScrollEnd();
2514 2524
2515 // Scroll past the maximum extent. The delta shouldn't be greater than the 2525 // Scroll past the maximum extent. The delta shouldn't be greater than the
2516 // top controls height. 2526 // top controls height.
2517 host_impl_->top_controls_manager()->ScrollBegin(); 2527 host_impl_->top_controls_manager()->ScrollBegin();
2518 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2528 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2519 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2529 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2520 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2530 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2521 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2531 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2522 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, top_controls_height), 2532 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, top_controls_height_),
2523 outer_viewport_scroll_layer->FixedContainerSizeDelta()); 2533 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2524 host_impl_->ScrollEnd(); 2534 host_impl_->ScrollEnd();
2525 2535
2526 // Scroll in the direction to make the top controls show. 2536 // Scroll in the direction to make the top controls show.
2527 host_impl_->top_controls_manager()->ScrollBegin(); 2537 host_impl_->top_controls_manager()->ScrollBegin();
2528 host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta); 2538 host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta);
2529 EXPECT_EQ(top_controls_scroll_delta.y(), 2539 EXPECT_EQ(top_controls_scroll_delta.y(),
2530 host_impl_->top_controls_manager()->ContentTopOffset()); 2540 host_impl_->top_controls_manager()->ContentTopOffset());
2531 EXPECT_VECTOR_EQ( 2541 EXPECT_VECTOR_EQ(
2532 gfx::Vector2dF(0, top_controls_height - top_controls_scroll_delta.y()), 2542 gfx::Vector2dF(0, top_controls_height_ - top_controls_scroll_delta.y()),
2533 outer_viewport_scroll_layer->FixedContainerSizeDelta()); 2543 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2534 host_impl_->top_controls_manager()->ScrollEnd(); 2544 host_impl_->top_controls_manager()->ScrollEnd();
2535 } 2545 }
2536 2546
2537 // Ensure setting the top controls position explicitly using the setters on the 2547 // Ensure setting the top controls position explicitly using the setters on the
2538 // TreeImpl correctly affects the top controls manager and viewport bounds. 2548 // TreeImpl correctly affects the top controls manager and viewport bounds.
2539 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { 2549 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) {
2540 CreateHostImpl(settings_, CreateOutputSurface()); 2550 CreateHostImpl(settings_, CreateOutputSurface());
2541 SetupTopControlsAndScrollLayer(); 2551 SetupTopControlsAndScrollLayer();
2542 DrawFrame(); 2552 DrawFrame();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2594 // Test that changing the top controls layout height is correctly applied to 2604 // Test that changing the top controls layout height is correctly applied to
2595 // the inner viewport container bounds. That is, the top controls layout 2605 // the inner viewport container bounds. That is, the top controls layout
2596 // height is the amount that the inner viewport container was shrunk outside 2606 // height is the amount that the inner viewport container was shrunk outside
2597 // the compositor to accommodate the top controls. 2607 // the compositor to accommodate the top controls.
2598 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { 2608 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) {
2599 CreateHostImpl(settings_, CreateOutputSurface()); 2609 CreateHostImpl(settings_, CreateOutputSurface());
2600 SetupTopControlsAndScrollLayer(); 2610 SetupTopControlsAndScrollLayer();
2601 DrawFrame(); 2611 DrawFrame();
2602 2612
2603 host_impl_->sync_tree()->set_top_controls_content_offset(15.f); 2613 host_impl_->sync_tree()->set_top_controls_content_offset(15.f);
2604 host_impl_->sync_tree()->set_top_controls_layout_height(15.f); 2614 host_impl_->sync_tree()->set_top_controls_height(15.f);
2615 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2605 2616
2606 host_impl_->active_tree()->set_top_controls_content_offset(20.f); 2617 host_impl_->active_tree()->set_top_controls_content_offset(20.f);
2607 host_impl_->active_tree()->set_top_controls_delta(-20.f); 2618 host_impl_->active_tree()->set_top_controls_delta(-20.f);
2608 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); 2619 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f);
2609 2620
2610 host_impl_->DidChangeTopControlsPosition(); 2621 host_impl_->DidChangeTopControlsPosition();
2611 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2622 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2612 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2623 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2613 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2624 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2614 2625
(...skipping 22 matching lines...) Expand all
2637 } 2648 }
2638 2649
2639 // Test that showing/hiding the top controls when the viewport is fully scrolled 2650 // Test that showing/hiding the top controls when the viewport is fully scrolled
2640 // doesn't incorrectly change the viewport offset due to clamping from changing 2651 // doesn't incorrectly change the viewport offset due to clamping from changing
2641 // viewport bounds. 2652 // viewport bounds.
2642 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { 2653 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) {
2643 SetupTopControlsAndScrollLayerWithVirtualViewport( 2654 SetupTopControlsAndScrollLayerWithVirtualViewport(
2644 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2655 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2645 DrawFrame(); 2656 DrawFrame();
2646 2657
2647 EXPECT_EQ(settings_.top_controls_height, 2658 EXPECT_EQ(top_controls_height_,
2648 host_impl_->active_tree()->total_top_controls_content_offset()); 2659 host_impl_->active_tree()->total_top_controls_content_offset());
2649 2660
2650 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); 2661 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer();
2651 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); 2662 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer();
2652 2663
2653 // Scroll the viewports to max scroll offset. 2664 // Scroll the viewports to max scroll offset.
2654 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f)); 2665 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f));
2655 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f)); 2666 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f));
2656 2667
2657 gfx::ScrollOffset viewport_offset = 2668 gfx::ScrollOffset viewport_offset =
2658 host_impl_->active_tree()->TotalScrollOffset(); 2669 host_impl_->active_tree()->TotalScrollOffset();
2659 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); 2670 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset);
2660 2671
2661 // Hide the top controls by 25px. 2672 // Hide the top controls by 25px.
2662 gfx::Vector2dF scroll_delta(0.f, 25.f); 2673 gfx::Vector2dF scroll_delta(0.f, 25.f);
2663 EXPECT_EQ(InputHandler::ScrollStarted, 2674 EXPECT_EQ(InputHandler::ScrollStarted,
2664 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2675 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2665 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2676 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2666 2677
2667 // scrolling down at the max extents no longer hides the top controls 2678 // scrolling down at the max extents no longer hides the top controls
2668 EXPECT_EQ(0.f, 2679 EXPECT_EQ(0.f,
2669 settings_.top_controls_height - 2680 top_controls_height_ -
2670 host_impl_->active_tree()->total_top_controls_content_offset()); 2681 host_impl_->active_tree()->total_top_controls_content_offset());
2671 2682
2672 // forcefully hide the top controls by 25px 2683 // forcefully hide the top controls by 25px
2673 host_impl_->top_controls_manager()->ScrollBy(scroll_delta); 2684 host_impl_->top_controls_manager()->ScrollBy(scroll_delta);
2674 host_impl_->ScrollEnd(); 2685 host_impl_->ScrollEnd();
2675 2686
2676 EXPECT_EQ(scroll_delta.y(), 2687 EXPECT_EQ(scroll_delta.y(),
2677 settings_.top_controls_height - 2688 top_controls_height_ -
2678 host_impl_->active_tree()->total_top_controls_content_offset()); 2689 host_impl_->active_tree()->total_top_controls_content_offset());
2679 2690
2680 inner_scroll->ClampScrollToMaxScrollOffset(); 2691 inner_scroll->ClampScrollToMaxScrollOffset();
2681 outer_scroll->ClampScrollToMaxScrollOffset(); 2692 outer_scroll->ClampScrollToMaxScrollOffset();
2682 2693
2683 // We should still be fully scrolled. 2694 // We should still be fully scrolled.
2684 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), 2695 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(),
2685 host_impl_->active_tree()->TotalScrollOffset()); 2696 host_impl_->active_tree()->TotalScrollOffset());
2686 2697
2687 viewport_offset = host_impl_->active_tree()->TotalScrollOffset(); 2698 viewport_offset = host_impl_->active_tree()->TotalScrollOffset();
(...skipping 16 matching lines...) Expand all
2704 host_impl_->active_tree()->TotalScrollOffset()); 2715 host_impl_->active_tree()->TotalScrollOffset());
2705 } 2716 }
2706 2717
2707 // Test that the top controls coming in and out maintains the same aspect ratio 2718 // Test that the top controls coming in and out maintains the same aspect ratio
2708 // between the inner and outer viewports. 2719 // between the inner and outer viewports.
2709 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) { 2720 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) {
2710 SetupTopControlsAndScrollLayerWithVirtualViewport( 2721 SetupTopControlsAndScrollLayerWithVirtualViewport(
2711 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2722 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2712 DrawFrame(); 2723 DrawFrame();
2713 2724
2714 EXPECT_EQ(settings_.top_controls_height, 2725 EXPECT_EQ(top_controls_height_,
2715 host_impl_->active_tree()->total_top_controls_content_offset()); 2726 host_impl_->active_tree()->total_top_controls_content_offset());
2716 2727
2717 gfx::Vector2dF scroll_delta(0.f, 25.f); 2728 gfx::Vector2dF scroll_delta(0.f, 25.f);
2718 EXPECT_EQ(InputHandler::ScrollStarted, 2729 EXPECT_EQ(InputHandler::ScrollStarted,
2719 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2730 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2720 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2731 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2721 host_impl_->ScrollEnd(); 2732 host_impl_->ScrollEnd();
2722 2733
2723 EXPECT_EQ(scroll_delta.y(), 2734 EXPECT_EQ(scroll_delta.y(),
2724 settings_.top_controls_height - 2735 top_controls_height_ -
2725 host_impl_->active_tree()->total_top_controls_content_offset()); 2736 host_impl_->active_tree()->total_top_controls_content_offset());
2726 2737
2727 // Top controls were hidden by 25px so the inner viewport should have expanded 2738 // Top controls were hidden by 25px so the inner viewport should have expanded
2728 // by that much. 2739 // by that much.
2729 LayerImpl* outer_container = 2740 LayerImpl* outer_container =
2730 host_impl_->active_tree()->OuterViewportContainerLayer(); 2741 host_impl_->active_tree()->OuterViewportContainerLayer();
2731 LayerImpl* inner_container = 2742 LayerImpl* inner_container =
2732 host_impl_->active_tree()->InnerViewportContainerLayer(); 2743 host_impl_->active_tree()->InnerViewportContainerLayer();
2733 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->BoundsForScrolling()); 2744 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->BoundsForScrolling());
2734 2745
2735 // Outer viewport should match inner's aspect ratio. The bounds are ceiled. 2746 // Outer viewport should match inner's aspect ratio. The bounds are ceiled.
2736 float aspect_ratio = inner_container->BoundsForScrolling().width() / 2747 float aspect_ratio = inner_container->BoundsForScrolling().width() /
2737 inner_container->BoundsForScrolling().height(); 2748 inner_container->BoundsForScrolling().height();
2738 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio)); 2749 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio));
2739 EXPECT_EQ(expected, outer_container->BoundsForScrolling()); 2750 EXPECT_EQ(expected, outer_container->BoundsForScrolling());
2740 EXPECT_EQ(expected, 2751 EXPECT_EQ(expected,
2741 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling()); 2752 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling());
2742 } 2753 }
2743 2754
2744 // Test that scrolling the outer viewport affects the top controls. 2755 // Test that scrolling the outer viewport affects the top controls.
2745 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { 2756 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) {
2746 SetupTopControlsAndScrollLayerWithVirtualViewport( 2757 SetupTopControlsAndScrollLayerWithVirtualViewport(
2747 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2758 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2748 DrawFrame(); 2759 DrawFrame();
2749 2760
2750 EXPECT_EQ(settings_.top_controls_height, 2761 EXPECT_EQ(top_controls_height_,
2751 host_impl_->active_tree()->total_top_controls_content_offset()); 2762 host_impl_->active_tree()->total_top_controls_content_offset());
2752 2763
2753 // Send a gesture scroll that will scroll the outer viewport, make sure the 2764 // Send a gesture scroll that will scroll the outer viewport, make sure the
2754 // top controls get scrolled. 2765 // top controls get scrolled.
2755 gfx::Vector2dF scroll_delta(0.f, 15.f); 2766 gfx::Vector2dF scroll_delta(0.f, 15.f);
2756 EXPECT_EQ(InputHandler::ScrollStarted, 2767 EXPECT_EQ(InputHandler::ScrollStarted,
2757 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2768 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2758 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2769 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2759 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), 2770 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
2760 host_impl_->CurrentlyScrollingLayer()); 2771 host_impl_->CurrentlyScrollingLayer());
2761 host_impl_->ScrollEnd(); 2772 host_impl_->ScrollEnd();
2762 2773
2763 EXPECT_EQ(scroll_delta.y(), 2774 EXPECT_EQ(scroll_delta.y(),
2764 settings_.top_controls_height - 2775 top_controls_height_ -
2765 host_impl_->active_tree()->total_top_controls_content_offset()); 2776 host_impl_->active_tree()->total_top_controls_content_offset());
2766 2777
2767 scroll_delta = gfx::Vector2dF(0.f, 50.f); 2778 scroll_delta = gfx::Vector2dF(0.f, 50.f);
2768 EXPECT_EQ(InputHandler::ScrollStarted, 2779 EXPECT_EQ(InputHandler::ScrollStarted,
2769 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2780 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2770 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2781 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2771 2782
2772 EXPECT_EQ(0, host_impl_->active_tree()->total_top_controls_content_offset()); 2783 EXPECT_EQ(0, host_impl_->active_tree()->total_top_controls_content_offset());
2773 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), 2784 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
2774 host_impl_->CurrentlyScrollingLayer()); 2785 host_impl_->CurrentlyScrollingLayer());
2775 2786
2776 host_impl_->ScrollEnd(); 2787 host_impl_->ScrollEnd();
2777 2788
2778 // Position the viewports such that the inner viewport will be scrolled. 2789 // Position the viewports such that the inner viewport will be scrolled.
2779 gfx::Vector2dF inner_viewport_offset(0.f, 25.f); 2790 gfx::Vector2dF inner_viewport_offset(0.f, 25.f);
2780 host_impl_->OuterViewportScrollLayer()->SetScrollDelta(gfx::Vector2dF()); 2791 host_impl_->OuterViewportScrollLayer()->SetScrollDelta(gfx::Vector2dF());
2781 host_impl_->InnerViewportScrollLayer()->SetScrollDelta(inner_viewport_offset); 2792 host_impl_->InnerViewportScrollLayer()->SetScrollDelta(inner_viewport_offset);
2782 2793
2783 scroll_delta = gfx::Vector2dF(0.f, -65.f); 2794 scroll_delta = gfx::Vector2dF(0.f, -65.f);
2784 EXPECT_EQ(InputHandler::ScrollStarted, 2795 EXPECT_EQ(InputHandler::ScrollStarted,
2785 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2796 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2786 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2797 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2787 2798
2788 EXPECT_EQ(settings_.top_controls_height, 2799 EXPECT_EQ(top_controls_height_,
2789 host_impl_->active_tree()->total_top_controls_content_offset()); 2800 host_impl_->active_tree()->total_top_controls_content_offset());
2790 EXPECT_EQ(inner_viewport_offset.y() + 2801 EXPECT_EQ(
2791 (scroll_delta.y() + settings_.top_controls_height), 2802 inner_viewport_offset.y() + (scroll_delta.y() + top_controls_height_),
2792 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y()); 2803 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y());
2793 2804
2794 host_impl_->ScrollEnd(); 2805 host_impl_->ScrollEnd();
2795 } 2806 }
2796 2807
2797 TEST_F(LayerTreeHostImplTopControlsTest, 2808 TEST_F(LayerTreeHostImplTopControlsTest,
2798 ScrollNonScrollableRootWithTopControls) { 2809 ScrollNonScrollableRootWithTopControls) {
2799 CreateHostImpl(settings_, CreateOutputSurface()); 2810 CreateHostImpl(settings_, CreateOutputSurface());
2800 SetupTopControlsAndScrollLayer(); 2811 SetupTopControlsAndScrollLayer();
2801 DrawFrame(); 2812 DrawFrame();
2802 2813
(...skipping 4361 matching lines...) Expand 10 before | Expand all | Expand 10 after
7164 EXPECT_EQ(2, set_needs_redraw_count); 7175 EXPECT_EQ(2, set_needs_redraw_count);
7165 EXPECT_EQ(1, forward_to_main_count); 7176 EXPECT_EQ(1, forward_to_main_count);
7166 } 7177 }
7167 } 7178 }
7168 7179
7169 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { 7180 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest {
7170 public: 7181 public:
7171 void SetUp() override { 7182 void SetUp() override {
7172 LayerTreeSettings settings = DefaultSettings(); 7183 LayerTreeSettings settings = DefaultSettings();
7173 settings.calculate_top_controls_position = true; 7184 settings.calculate_top_controls_position = true;
7174 settings.top_controls_height = top_controls_height_;
7175 CreateHostImpl(settings, CreateOutputSurface()); 7185 CreateHostImpl(settings, CreateOutputSurface());
7186 host_impl_->active_tree()->set_top_controls_height(top_controls_height_);
7187 host_impl_->top_controls_manager()->SetTopControlsHeight(
7188 top_controls_height_);
7176 } 7189 }
7177 7190
7178 protected: 7191 protected:
7179 static const int top_controls_height_; 7192 static const int top_controls_height_;
7180 }; 7193 };
7181 7194
7182 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50; 7195 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50;
7183 7196
7184 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { 7197 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) {
7185 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 7198 SetupScrollAndContentsLayers(gfx::Size(100, 100))
7186 ->SetScrollOffset(gfx::ScrollOffset(0, 10)); 7199 ->SetScrollOffset(gfx::ScrollOffset(0, 10));
7187 host_impl_->Animate(base::TimeTicks()); 7200 host_impl_->Animate(base::TimeTicks());
7188 EXPECT_FALSE(did_request_redraw_); 7201 EXPECT_FALSE(did_request_redraw_);
7189 } 7202 }
7190 7203
7204 /*TEST_F(LayerTreeHostImplWithTopControlsTest, HeightChangeCausesInvalidate) {
7205 SetupScrollAndContentsLayers(gfx::Size(100, 100));
7206 EXPECT_FALSE(did_request_redraw_);
7207 host_impl_->SetTopControlsHeight(100);
7208 EXPECT_TRUE(did_request_redraw_);
7209 }*/
7210
7191 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { 7211 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) {
7192 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 7212 SetupScrollAndContentsLayers(gfx::Size(100, 100))
7193 ->SetScrollOffset(gfx::ScrollOffset(0, 10)); 7213 ->SetScrollOffset(gfx::ScrollOffset(0, 10));
7194 host_impl_->DidChangeTopControlsPosition(); 7214 host_impl_->DidChangeTopControlsPosition();
7195 EXPECT_TRUE(did_request_animate_); 7215 EXPECT_TRUE(did_request_animate_);
7196 EXPECT_TRUE(did_request_redraw_); 7216 EXPECT_TRUE(did_request_redraw_);
7197 } 7217 }
7198 7218
7199 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { 7219 TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) {
7200 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); 7220 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200));
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
7776 // surface. 7796 // surface.
7777 EXPECT_EQ(0, num_lost_surfaces_); 7797 EXPECT_EQ(0, num_lost_surfaces_);
7778 host_impl_->DidLoseOutputSurface(); 7798 host_impl_->DidLoseOutputSurface();
7779 EXPECT_EQ(1, num_lost_surfaces_); 7799 EXPECT_EQ(1, num_lost_surfaces_);
7780 host_impl_->DidLoseOutputSurface(); 7800 host_impl_->DidLoseOutputSurface();
7781 EXPECT_LE(1, num_lost_surfaces_); 7801 EXPECT_LE(1, num_lost_surfaces_);
7782 } 7802 }
7783 7803
7784 } // namespace 7804 } // namespace
7785 } // namespace cc 7805 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698