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

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

Issue 901813002: Normalize top controls offset to (0, 1), Chromium-side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 2284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2295 viewport_size_ = gfx::Size(clip_size_.width(), 2295 viewport_size_ = gfx::Size(clip_size_.width(),
2296 clip_size_.height() + top_controls_height_); 2296 clip_size_.height() + top_controls_height_);
2297 } 2297 }
2298 2298
2299 bool CreateHostImpl(const LayerTreeSettings& settings, 2299 bool CreateHostImpl(const LayerTreeSettings& settings,
2300 scoped_ptr<OutputSurface> output_surface) override { 2300 scoped_ptr<OutputSurface> output_surface) override {
2301 bool init = 2301 bool init =
2302 LayerTreeHostImplTest::CreateHostImpl(settings, output_surface.Pass()); 2302 LayerTreeHostImplTest::CreateHostImpl(settings, output_surface.Pass());
2303 if (init && settings.calculate_top_controls_position) { 2303 if (init && settings.calculate_top_controls_position) {
2304 host_impl_->active_tree()->set_top_controls_height(top_controls_height_); 2304 host_impl_->active_tree()->set_top_controls_height(top_controls_height_);
2305 host_impl_->active_tree()->set_top_controls_delta(top_controls_height_); 2305 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f);
2306 host_impl_->top_controls_manager()->SetTopControlsHeight(
2307 top_controls_height_);
2308 host_impl_->DidChangeTopControlsPosition();
2309 } 2306 }
2310 return init; 2307 return init;
2311 } 2308 }
2312 2309
2313 void SetupTopControlsAndScrollLayer() { 2310 void SetupTopControlsAndScrollLayer() {
2314 scoped_ptr<LayerImpl> root = 2311 scoped_ptr<LayerImpl> root =
2315 LayerImpl::Create(host_impl_->active_tree(), 1); 2312 LayerImpl::Create(host_impl_->active_tree(), 1);
2316 scoped_ptr<LayerImpl> root_clip = 2313 scoped_ptr<LayerImpl> root_clip =
2317 LayerImpl::Create(host_impl_->active_tree(), 2); 2314 LayerImpl::Create(host_impl_->active_tree(), 2);
2318 root_clip->SetBounds(clip_size_); 2315 root_clip->SetBounds(clip_size_);
(...skipping 13 matching lines...) Expand all
2332 Layer::INVALID_ID, page_scale_layer_id, inner_viewport_scroll_layer_id, 2329 Layer::INVALID_ID, page_scale_layer_id, inner_viewport_scroll_layer_id,
2333 Layer::INVALID_ID); 2330 Layer::INVALID_ID);
2334 // Set a viewport size that is large enough to contain both the top controls 2331 // Set a viewport size that is large enough to contain both the top controls
2335 // and some content. 2332 // and some content.
2336 host_impl_->SetViewportSize(viewport_size_); 2333 host_impl_->SetViewportSize(viewport_size_);
2337 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); 2334 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2338 2335
2339 host_impl_->DidChangeTopControlsPosition(); 2336 host_impl_->DidChangeTopControlsPosition();
2340 2337
2341 host_impl_->CreatePendingTree(); 2338 host_impl_->CreatePendingTree();
2339 host_impl_->sync_tree()->set_top_controls_height(top_controls_height_);
2342 root = 2340 root =
2343 LayerImpl::Create(host_impl_->sync_tree(), 1); 2341 LayerImpl::Create(host_impl_->sync_tree(), 1);
2344 root_clip = 2342 root_clip =
2345 LayerImpl::Create(host_impl_->sync_tree(), 2); 2343 LayerImpl::Create(host_impl_->sync_tree(), 2);
2346 root_clip->SetBounds(clip_size_); 2344 root_clip->SetBounds(clip_size_);
2347 root->SetScrollClipLayer(root_clip->id()); 2345 root->SetScrollClipLayer(root_clip->id());
2348 root->SetBounds(layer_size_); 2346 root->SetBounds(layer_size_);
2349 root->SetContentBounds(layer_size_); 2347 root->SetContentBounds(layer_size_);
2350 root->SetPosition(gfx::PointF()); 2348 root->SetPosition(gfx::PointF());
2351 root->SetDrawsContent(false); 2349 root->SetDrawsContent(false);
(...skipping 11 matching lines...) Expand all
2363 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); 2361 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2364 host_impl_->DidChangeTopControlsPosition(); 2362 host_impl_->DidChangeTopControlsPosition();
2365 } 2363 }
2366 2364
2367 void SetupTopControlsAndScrollLayerWithVirtualViewport( 2365 void SetupTopControlsAndScrollLayerWithVirtualViewport(
2368 const gfx::Size& inner_viewport_size, 2366 const gfx::Size& inner_viewport_size,
2369 const gfx::Size& outer_viewport_size, 2367 const gfx::Size& outer_viewport_size,
2370 const gfx::Size& scroll_layer_size) { 2368 const gfx::Size& scroll_layer_size) {
2371 CreateHostImpl(settings_, CreateOutputSurface()); 2369 CreateHostImpl(settings_, CreateOutputSurface());
2372 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); 2370 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2371 host_impl_->sync_tree()->set_top_controls_height(top_controls_height_);
2373 host_impl_->DidChangeTopControlsPosition(); 2372 host_impl_->DidChangeTopControlsPosition();
2374 2373
2375 scoped_ptr<LayerImpl> root = 2374 scoped_ptr<LayerImpl> root =
2376 LayerImpl::Create(host_impl_->active_tree(), 1); 2375 LayerImpl::Create(host_impl_->active_tree(), 1);
2377 scoped_ptr<LayerImpl> root_clip = 2376 scoped_ptr<LayerImpl> root_clip =
2378 LayerImpl::Create(host_impl_->active_tree(), 2); 2377 LayerImpl::Create(host_impl_->active_tree(), 2);
2379 scoped_ptr<LayerImpl> page_scale = 2378 scoped_ptr<LayerImpl> page_scale =
2380 LayerImpl::Create(host_impl_->active_tree(), 3); 2379 LayerImpl::Create(host_impl_->active_tree(), 3);
2381 2380
2382 scoped_ptr<LayerImpl> outer_scroll = 2381 scoped_ptr<LayerImpl> outer_scroll =
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer. 2472 // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer.
2474 outer_scroll->SetDrawsContent(true); 2473 outer_scroll->SetDrawsContent(true);
2475 host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 1.f, 2.f); 2474 host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 1.f, 2.f);
2476 2475
2477 EXPECT_EQ(InputHandler::ScrollStarted, 2476 EXPECT_EQ(InputHandler::ScrollStarted,
2478 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2477 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2479 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 50.f)); 2478 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 50.f));
2480 2479
2481 // The entire scroll delta should have been used to hide the top controls. 2480 // The entire scroll delta should have been used to hide the top controls.
2482 // The viewport layers should be resized back to their full sizes. 2481 // The viewport layers should be resized back to their full sizes.
2483 EXPECT_EQ(0.f, 2482 EXPECT_EQ(0.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
2484 host_impl_->active_tree()->total_top_controls_content_offset());
2485 EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y()); 2483 EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y());
2486 EXPECT_EQ(100.f, inner_container->BoundsForScrolling().height()); 2484 EXPECT_EQ(100.f, inner_container->BoundsForScrolling().height());
2487 EXPECT_EQ(100.f, outer_container->BoundsForScrolling().height()); 2485 EXPECT_EQ(100.f, outer_container->BoundsForScrolling().height());
2488 2486
2489 // The inner viewport should be scrollable by 50px * page_scale. 2487 // The inner viewport should be scrollable by 50px * page_scale.
2490 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 100.f)); 2488 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 100.f));
2491 EXPECT_EQ(50.f, inner_scroll->CurrentScrollOffset().y()); 2489 EXPECT_EQ(50.f, inner_scroll->CurrentScrollOffset().y());
2492 EXPECT_EQ(0.f, outer_scroll->CurrentScrollOffset().y()); 2490 EXPECT_EQ(0.f, outer_scroll->CurrentScrollOffset().y());
2493 EXPECT_EQ(gfx::ScrollOffset(), outer_scroll->MaxScrollOffset()); 2491 EXPECT_EQ(gfx::ScrollOffset(), outer_scroll->MaxScrollOffset());
2494 2492
2495 host_impl_->ScrollEnd(); 2493 host_impl_->ScrollEnd();
2496 2494
2497 EXPECT_EQ(InputHandler::ScrollStarted, 2495 EXPECT_EQ(InputHandler::ScrollStarted,
2498 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2496 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2499 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); 2497 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll);
2500 2498
2501 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -50.f)); 2499 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -50.f));
2502 2500
2503 // The entire scroll delta should have been used to show the top controls. 2501 // The entire scroll delta should have been used to show the top controls.
2504 // The outer viewport should be resized to accomodate and scrolled to the 2502 // The outer viewport should be resized to accomodate and scrolled to the
2505 // bottom of the document to keep the viewport in place. 2503 // bottom of the document to keep the viewport in place.
2506 EXPECT_EQ(50.f, 2504 EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
2507 host_impl_->active_tree()->total_top_controls_content_offset());
2508 EXPECT_EQ(50.f, outer_container->BoundsForScrolling().height()); 2505 EXPECT_EQ(50.f, outer_container->BoundsForScrolling().height());
2509 EXPECT_EQ(50.f, inner_container->BoundsForScrolling().height()); 2506 EXPECT_EQ(50.f, inner_container->BoundsForScrolling().height());
2510 EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y()); 2507 EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y());
2511 EXPECT_EQ(25.f, inner_scroll->CurrentScrollOffset().y()); 2508 EXPECT_EQ(25.f, inner_scroll->CurrentScrollOffset().y());
2512 2509
2513 // Now when we continue scrolling, make sure the outer viewport gets scrolled 2510 // Now when we continue scrolling, make sure the outer viewport gets scrolled
2514 // since it wasn't scrollable when the scroll began. 2511 // since it wasn't scrollable when the scroll began.
2515 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -20.f)); 2512 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -20.f));
2516 EXPECT_EQ(15.f, outer_scroll->CurrentScrollOffset().y()); 2513 EXPECT_EQ(15.f, outer_scroll->CurrentScrollOffset().y());
2517 EXPECT_EQ(25.f, inner_scroll->CurrentScrollOffset().y()); 2514 EXPECT_EQ(25.f, inner_scroll->CurrentScrollOffset().y());
(...skipping 25 matching lines...) Expand all
2543 host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, 2.f); 2540 host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, 2.f);
2544 2541
2545 EXPECT_EQ(InputHandler::ScrollStarted, 2542 EXPECT_EQ(InputHandler::ScrollStarted,
2546 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2543 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2547 2544
2548 // Scroll down, the top controls hiding should expand the viewport size so 2545 // Scroll down, the top controls hiding should expand the viewport size so
2549 // the delta should be equal to the scroll distance. 2546 // the delta should be equal to the scroll distance.
2550 gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f); 2547 gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f);
2551 host_impl_->top_controls_manager()->ScrollBegin(); 2548 host_impl_->top_controls_manager()->ScrollBegin();
2552 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2549 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2553 EXPECT_EQ(top_controls_height_ - top_controls_scroll_delta.y(), 2550 EXPECT_FLOAT_EQ(top_controls_height_ - top_controls_scroll_delta.y(),
2554 host_impl_->top_controls_manager()->ContentTopOffset()); 2551 host_impl_->top_controls_manager()->ContentTopOffset());
2555 EXPECT_VECTOR_EQ(top_controls_scroll_delta, 2552 EXPECT_VECTOR_EQ(top_controls_scroll_delta,
2556 outer_viewport_scroll_layer->FixedContainerSizeDelta()); 2553 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2557 host_impl_->ScrollEnd(); 2554 host_impl_->ScrollEnd();
2558 2555
2559 // Scroll past the maximum extent. The delta shouldn't be greater than the 2556 // Scroll past the maximum extent. The delta shouldn't be greater than the
2560 // top controls height. 2557 // top controls height.
2561 host_impl_->top_controls_manager()->ScrollBegin(); 2558 host_impl_->top_controls_manager()->ScrollBegin();
2562 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2559 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2563 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2560 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2564 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2561 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
(...skipping 16 matching lines...) Expand all
2581 // Test that if a scrollable sublayer doesn't consume the scroll, 2578 // Test that if a scrollable sublayer doesn't consume the scroll,
2582 // top controls should hide when scrolling down. 2579 // top controls should hide when scrolling down.
2583 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollableSublayer) { 2580 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollableSublayer) {
2584 gfx::Size sub_content_size(100, 400); 2581 gfx::Size sub_content_size(100, 400);
2585 gfx::Size sub_content_layer_size(100, 300); 2582 gfx::Size sub_content_layer_size(100, 300);
2586 SetupTopControlsAndScrollLayerWithVirtualViewport( 2583 SetupTopControlsAndScrollLayerWithVirtualViewport(
2587 gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100)); 2584 gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100));
2588 DrawFrame(); 2585 DrawFrame();
2589 2586
2590 // Show top controls 2587 // Show top controls
2591 EXPECT_EQ(top_controls_height_, 2588 EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
2592 host_impl_->active_tree()->total_top_controls_content_offset());
2593 2589
2594 LayerImpl* outer_viewport_scroll_layer = 2590 LayerImpl* outer_viewport_scroll_layer =
2595 host_impl_->active_tree()->OuterViewportScrollLayer(); 2591 host_impl_->active_tree()->OuterViewportScrollLayer();
2596 int id = outer_viewport_scroll_layer->id(); 2592 int id = outer_viewport_scroll_layer->id();
2597 2593
2598 scoped_ptr<LayerImpl> child = 2594 scoped_ptr<LayerImpl> child =
2599 LayerImpl::Create(host_impl_->active_tree(), id + 2); 2595 LayerImpl::Create(host_impl_->active_tree(), id + 2);
2600 scoped_ptr<LayerImpl> child_clip = 2596 scoped_ptr<LayerImpl> child_clip =
2601 LayerImpl::Create(host_impl_->active_tree(), id + 3); 2597 LayerImpl::Create(host_impl_->active_tree(), id + 3);
2602 2598
(...skipping 13 matching lines...) Expand all
2616 // Scroll 25px to hide top controls 2612 // Scroll 25px to hide top controls
2617 gfx::Vector2dF scroll_delta(0.f, 25.f); 2613 gfx::Vector2dF scroll_delta(0.f, 25.f);
2618 EXPECT_EQ(InputHandler::ScrollStarted, 2614 EXPECT_EQ(InputHandler::ScrollStarted,
2619 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2615 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2620 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2616 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2621 host_impl_->ScrollEnd(); 2617 host_impl_->ScrollEnd();
2622 2618
2623 // Top controls should be hidden 2619 // Top controls should be hidden
2624 EXPECT_EQ(scroll_delta.y(), 2620 EXPECT_EQ(scroll_delta.y(),
2625 top_controls_height_ - 2621 top_controls_height_ -
2626 host_impl_->active_tree()->total_top_controls_content_offset()); 2622 host_impl_->top_controls_manager()->ContentTopOffset());
2627 } 2623 }
2628 2624
2629 // Ensure setting the top controls position explicitly using the setters on the 2625 // Ensure setting the top controls position explicitly using the setters on the
2630 // TreeImpl correctly affects the top controls manager and viewport bounds. 2626 // TreeImpl correctly affects the top controls manager and viewport bounds.
2631 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { 2627 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) {
2632 CreateHostImpl(settings_, CreateOutputSurface()); 2628 CreateHostImpl(settings_, CreateOutputSurface());
2633 SetupTopControlsAndScrollLayer(); 2629 SetupTopControlsAndScrollLayer();
2634 DrawFrame(); 2630 DrawFrame();
2635 2631
2636 host_impl_->active_tree()->set_top_controls_delta(0.f); 2632 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f);
2637 host_impl_->active_tree()->set_top_controls_content_offset(30.f); 2633 host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread(
2638 EXPECT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2634 30.f / top_controls_height_);
2639 EXPECT_EQ(-20.f, host_impl_->top_controls_manager()->ControlsTopOffset()); 2635 host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive();
2636 EXPECT_FLOAT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset());
2637 EXPECT_FLOAT_EQ(-20.f,
2638 host_impl_->top_controls_manager()->ControlsTopOffset());
2640 2639
2641 host_impl_->active_tree()->set_top_controls_delta(-30.f); 2640 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f);
2642 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2641 EXPECT_FLOAT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2643 EXPECT_EQ(-50.f, host_impl_->top_controls_manager()->ControlsTopOffset()); 2642 EXPECT_FLOAT_EQ(-50.f,
2643 host_impl_->top_controls_manager()->ControlsTopOffset());
2644 2644
2645 host_impl_->DidChangeTopControlsPosition(); 2645 host_impl_->DidChangeTopControlsPosition();
2646 2646
2647 // Now that top controls have moved, expect the clip to resize. 2647 // Now that top controls have moved, expect the clip to resize.
2648 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2648 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2649 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2649 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2650 } 2650 }
2651 2651
2652 // Test that the top_controls delta and sent delta are appropriately 2652 // Test that the top_controls delta and sent delta are appropriately
2653 // applied on sync tree activation. The total top controls offset shouldn't 2653 // applied on sync tree activation. The total top controls offset shouldn't
2654 // change after the activation. 2654 // change after the activation.
2655 TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { 2655 TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) {
2656 CreateHostImpl(settings_, CreateOutputSurface()); 2656 CreateHostImpl(settings_, CreateOutputSurface());
2657 SetupTopControlsAndScrollLayer(); 2657 SetupTopControlsAndScrollLayer();
2658 DrawFrame(); 2658 DrawFrame();
2659 2659
2660 host_impl_->sync_tree()->set_top_controls_content_offset(15.f); 2660 host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread(
2661 2661 20.f / top_controls_height_);
2662 host_impl_->active_tree()->set_top_controls_content_offset(20.f); 2662 host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive();
2663 host_impl_->active_tree()->set_top_controls_delta(-20.f); 2663 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(
2664 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); 2664 15.f / top_controls_height_);
2665 host_impl_->active_tree()
2666 ->top_controls_shown_ratio()
2667 ->PullDeltaForMainThread();
2668 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f);
2669 host_impl_->sync_tree()->PushTopControlsFromMainThread(15.f /
2670 top_controls_height_);
2665 2671
2666 host_impl_->DidChangeTopControlsPosition(); 2672 host_impl_->DidChangeTopControlsPosition();
2667 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2673 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2668 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2674 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2669 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2675 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2670 EXPECT_EQ(0.f,
2671 host_impl_->active_tree()->total_top_controls_content_offset());
2672 2676
2673 host_impl_->ActivateSyncTree(); 2677 host_impl_->ActivateSyncTree();
2674 2678
2675 root_clip_ptr = host_impl_->active_tree()->root_layer(); 2679 root_clip_ptr = host_impl_->active_tree()->root_layer();
2676 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2680 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2677 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2681 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2678 2682
2679 EXPECT_EQ(0.f, host_impl_->active_tree()->sent_top_controls_delta()); 2683 EXPECT_FLOAT_EQ(
2680 EXPECT_EQ(-15.f, host_impl_->active_tree()->top_controls_delta()); 2684 -15.f, host_impl_->active_tree()->top_controls_shown_ratio()->Delta() *
2681 EXPECT_EQ(15.f, host_impl_->active_tree()->top_controls_content_offset()); 2685 top_controls_height_);
2682 EXPECT_EQ(0.f, 2686 EXPECT_FLOAT_EQ(
2683 host_impl_->active_tree()->total_top_controls_content_offset()); 2687 15.f,
2688 host_impl_->active_tree()->top_controls_shown_ratio()->ActiveBase() *
2689 top_controls_height_);
2684 } 2690 }
2685 2691
2686 // Test that changing the top controls layout height is correctly applied to 2692 // Test that changing the top controls layout height is correctly applied to
2687 // the inner viewport container bounds. That is, the top controls layout 2693 // the inner viewport container bounds. That is, the top controls layout
2688 // height is the amount that the inner viewport container was shrunk outside 2694 // height is the amount that the inner viewport container was shrunk outside
2689 // the compositor to accommodate the top controls. 2695 // the compositor to accommodate the top controls.
2690 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { 2696 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) {
2691 CreateHostImpl(settings_, CreateOutputSurface()); 2697 CreateHostImpl(settings_, CreateOutputSurface());
2692 SetupTopControlsAndScrollLayer(); 2698 SetupTopControlsAndScrollLayer();
2693 DrawFrame(); 2699 DrawFrame();
2694 2700
2695 host_impl_->sync_tree()->set_top_controls_content_offset(50.f); 2701 host_impl_->sync_tree()->PushTopControlsFromMainThread(1.f);
2696 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); 2702 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2697 2703
2698 host_impl_->active_tree()->set_top_controls_content_offset(50.f); 2704 host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread(
2699 host_impl_->active_tree()->set_top_controls_delta(-50.f); 2705 1.f);
2706 host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive();
2707 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f);
2700 2708
2701 host_impl_->DidChangeTopControlsPosition(); 2709 host_impl_->DidChangeTopControlsPosition();
2702 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2710 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2703 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2711 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2704 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2712 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2705 2713
2706 host_impl_->sync_tree()->root_layer()->SetBounds( 2714 host_impl_->sync_tree()->root_layer()->SetBounds(
2707 gfx::Size(root_clip_ptr->bounds().width(), 2715 gfx::Size(root_clip_ptr->bounds().width(),
2708 root_clip_ptr->bounds().height() - 50.f)); 2716 root_clip_ptr->bounds().height() - 50.f));
2709 2717
2710 host_impl_->ActivateSyncTree(); 2718 host_impl_->ActivateSyncTree();
2711 2719
2712 root_clip_ptr = host_impl_->active_tree()->root_layer(); 2720 root_clip_ptr = host_impl_->active_tree()->root_layer();
2713 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2721 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2714 2722
2715 // The total bounds should remain unchanged since the bounds delta should 2723 // The total bounds should remain unchanged since the bounds delta should
2716 // account for the difference between the layout height and the current 2724 // account for the difference between the layout height and the current
2717 // top controls offset. 2725 // top controls offset.
2718 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2726 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2719 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 50.f), root_clip_ptr->bounds_delta()); 2727 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 50.f), root_clip_ptr->bounds_delta());
2720 2728
2721 host_impl_->active_tree()->set_top_controls_delta(0.f); 2729 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f);
2722 host_impl_->DidChangeTopControlsPosition(); 2730 host_impl_->DidChangeTopControlsPosition();
2723 2731
2732 EXPECT_EQ(1.f, host_impl_->top_controls_manager()->TopControlsShownRatio());
2733 EXPECT_EQ(50.f, host_impl_->top_controls_manager()->TopControlsHeight());
2724 EXPECT_EQ(50.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2734 EXPECT_EQ(50.f, host_impl_->top_controls_manager()->ContentTopOffset());
2725 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta()); 2735 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta());
2726 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height() - 50.f), 2736 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height() - 50.f),
2727 root_clip_ptr->bounds()); 2737 root_clip_ptr->bounds());
2728 } 2738 }
2729 2739
2730 // Test that showing/hiding the top controls when the viewport is fully scrolled 2740 // Test that showing/hiding the top controls when the viewport is fully scrolled
2731 // doesn't incorrectly change the viewport offset due to clamping from changing 2741 // doesn't incorrectly change the viewport offset due to clamping from changing
2732 // viewport bounds. 2742 // viewport bounds.
2733 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { 2743 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) {
2734 SetupTopControlsAndScrollLayerWithVirtualViewport( 2744 SetupTopControlsAndScrollLayerWithVirtualViewport(
2735 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2745 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2736 DrawFrame(); 2746 DrawFrame();
2737 2747
2738 EXPECT_EQ(top_controls_height_, 2748 EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
2739 host_impl_->active_tree()->total_top_controls_content_offset());
2740 2749
2741 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); 2750 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer();
2742 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); 2751 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer();
2743 2752
2744 // Scroll the viewports to max scroll offset. 2753 // Scroll the viewports to max scroll offset.
2745 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f)); 2754 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f));
2746 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f)); 2755 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f));
2747 2756
2748 gfx::ScrollOffset viewport_offset = 2757 gfx::ScrollOffset viewport_offset =
2749 host_impl_->active_tree()->TotalScrollOffset(); 2758 host_impl_->active_tree()->TotalScrollOffset();
2750 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); 2759 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset);
2751 2760
2752 // Hide the top controls by 25px. 2761 // Hide the top controls by 25px.
2753 gfx::Vector2dF scroll_delta(0.f, 25.f); 2762 gfx::Vector2dF scroll_delta(0.f, 25.f);
2754 EXPECT_EQ(InputHandler::ScrollStarted, 2763 EXPECT_EQ(InputHandler::ScrollStarted,
2755 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2764 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2756 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2765 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2757 2766
2758 // scrolling down at the max extents no longer hides the top controls 2767 // scrolling down at the max extents no longer hides the top controls
2759 EXPECT_EQ(0.f, 2768 EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
2760 top_controls_height_ -
2761 host_impl_->active_tree()->total_top_controls_content_offset());
2762 2769
2763 // forcefully hide the top controls by 25px 2770 // forcefully hide the top controls by 25px
2764 host_impl_->top_controls_manager()->ScrollBy(scroll_delta); 2771 host_impl_->top_controls_manager()->ScrollBy(scroll_delta);
2765 host_impl_->ScrollEnd(); 2772 host_impl_->ScrollEnd();
2766 2773
2767 EXPECT_EQ(scroll_delta.y(), 2774 EXPECT_EQ(scroll_delta.y(),
2768 top_controls_height_ - 2775 top_controls_height_ -
2769 host_impl_->active_tree()->total_top_controls_content_offset()); 2776 host_impl_->top_controls_manager()->ContentTopOffset());
2770 2777
2771 inner_scroll->ClampScrollToMaxScrollOffset(); 2778 inner_scroll->ClampScrollToMaxScrollOffset();
2772 outer_scroll->ClampScrollToMaxScrollOffset(); 2779 outer_scroll->ClampScrollToMaxScrollOffset();
2773 2780
2774 // We should still be fully scrolled. 2781 // We should still be fully scrolled.
2775 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), 2782 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(),
2776 host_impl_->active_tree()->TotalScrollOffset()); 2783 host_impl_->active_tree()->TotalScrollOffset());
2777 2784
2778 viewport_offset = host_impl_->active_tree()->TotalScrollOffset(); 2785 viewport_offset = host_impl_->active_tree()->TotalScrollOffset();
2779 2786
(...skipping 16 matching lines...) Expand all
2796 } 2803 }
2797 2804
2798 // Test that the top controls coming in and out maintains the same aspect ratio 2805 // Test that the top controls coming in and out maintains the same aspect ratio
2799 // between the inner and outer viewports. 2806 // between the inner and outer viewports.
2800 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) { 2807 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) {
2801 SetupTopControlsAndScrollLayerWithVirtualViewport( 2808 SetupTopControlsAndScrollLayerWithVirtualViewport(
2802 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2809 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2803 DrawFrame(); 2810 DrawFrame();
2804 2811
2805 EXPECT_EQ(top_controls_height_, 2812 EXPECT_EQ(top_controls_height_,
2806 host_impl_->active_tree()->total_top_controls_content_offset()); 2813 host_impl_->top_controls_manager()->ContentTopOffset());
2807 2814
2808 gfx::Vector2dF scroll_delta(0.f, 25.f); 2815 gfx::Vector2dF scroll_delta(0.f, 25.f);
2809 EXPECT_EQ(InputHandler::ScrollStarted, 2816 EXPECT_EQ(InputHandler::ScrollStarted,
2810 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2817 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2811 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2818 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2812 host_impl_->ScrollEnd(); 2819 host_impl_->ScrollEnd();
2813 2820
2814 EXPECT_EQ(scroll_delta.y(), 2821 EXPECT_EQ(scroll_delta.y(),
2815 top_controls_height_ - 2822 top_controls_height_ -
2816 host_impl_->active_tree()->total_top_controls_content_offset()); 2823 host_impl_->top_controls_manager()->ContentTopOffset());
2817 2824
2818 // Top controls were hidden by 25px so the inner viewport should have expanded 2825 // Top controls were hidden by 25px so the inner viewport should have expanded
2819 // by that much. 2826 // by that much.
2820 LayerImpl* outer_container = 2827 LayerImpl* outer_container =
2821 host_impl_->active_tree()->OuterViewportContainerLayer(); 2828 host_impl_->active_tree()->OuterViewportContainerLayer();
2822 LayerImpl* inner_container = 2829 LayerImpl* inner_container =
2823 host_impl_->active_tree()->InnerViewportContainerLayer(); 2830 host_impl_->active_tree()->InnerViewportContainerLayer();
2824 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->BoundsForScrolling()); 2831 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->BoundsForScrolling());
2825 2832
2826 // Outer viewport should match inner's aspect ratio. The bounds are ceiled. 2833 // Outer viewport should match inner's aspect ratio. The bounds are ceiled.
2827 float aspect_ratio = inner_container->BoundsForScrolling().width() / 2834 float aspect_ratio = inner_container->BoundsForScrolling().width() /
2828 inner_container->BoundsForScrolling().height(); 2835 inner_container->BoundsForScrolling().height();
2829 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio)); 2836 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio));
2830 EXPECT_EQ(expected, outer_container->BoundsForScrolling()); 2837 EXPECT_EQ(expected, outer_container->BoundsForScrolling());
2831 EXPECT_EQ(expected, 2838 EXPECT_EQ(expected,
2832 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling()); 2839 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling());
2833 } 2840 }
2834 2841
2835 // Test that scrolling the outer viewport affects the top controls. 2842 // Test that scrolling the outer viewport affects the top controls.
2836 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { 2843 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) {
2837 SetupTopControlsAndScrollLayerWithVirtualViewport( 2844 SetupTopControlsAndScrollLayerWithVirtualViewport(
2838 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2845 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2839 DrawFrame(); 2846 DrawFrame();
2840 2847
2841 EXPECT_EQ(top_controls_height_, 2848 EXPECT_EQ(top_controls_height_,
2842 host_impl_->active_tree()->total_top_controls_content_offset()); 2849 host_impl_->top_controls_manager()->ContentTopOffset());
2843 2850
2844 // Send a gesture scroll that will scroll the outer viewport, make sure the 2851 // Send a gesture scroll that will scroll the outer viewport, make sure the
2845 // top controls get scrolled. 2852 // top controls get scrolled.
2846 gfx::Vector2dF scroll_delta(0.f, 15.f); 2853 gfx::Vector2dF scroll_delta(0.f, 15.f);
2847 EXPECT_EQ(InputHandler::ScrollStarted, 2854 EXPECT_EQ(InputHandler::ScrollStarted,
2848 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2855 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2849 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2856 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2850 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), 2857 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
2851 host_impl_->CurrentlyScrollingLayer()); 2858 host_impl_->CurrentlyScrollingLayer());
2852 host_impl_->ScrollEnd(); 2859 host_impl_->ScrollEnd();
2853 2860
2854 EXPECT_EQ(scroll_delta.y(), 2861 EXPECT_EQ(scroll_delta.y(),
2855 top_controls_height_ - 2862 top_controls_height_ -
2856 host_impl_->active_tree()->total_top_controls_content_offset()); 2863 host_impl_->top_controls_manager()->ContentTopOffset());
2857 2864
2858 scroll_delta = gfx::Vector2dF(0.f, 50.f); 2865 scroll_delta = gfx::Vector2dF(0.f, 50.f);
2859 EXPECT_EQ(InputHandler::ScrollStarted, 2866 EXPECT_EQ(InputHandler::ScrollStarted,
2860 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2867 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2861 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2868 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2862 2869
2863 EXPECT_EQ(0, host_impl_->active_tree()->total_top_controls_content_offset()); 2870 EXPECT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset());
2864 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), 2871 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
2865 host_impl_->CurrentlyScrollingLayer()); 2872 host_impl_->CurrentlyScrollingLayer());
2866 2873
2867 host_impl_->ScrollEnd(); 2874 host_impl_->ScrollEnd();
2868 2875
2869 // Position the viewports such that the inner viewport will be scrolled. 2876 // Position the viewports such that the inner viewport will be scrolled.
2870 gfx::Vector2dF inner_viewport_offset(0.f, 25.f); 2877 gfx::Vector2dF inner_viewport_offset(0.f, 25.f);
2871 host_impl_->OuterViewportScrollLayer()->SetScrollDelta(gfx::Vector2dF()); 2878 host_impl_->OuterViewportScrollLayer()->SetScrollDelta(gfx::Vector2dF());
2872 host_impl_->InnerViewportScrollLayer()->SetScrollDelta(inner_viewport_offset); 2879 host_impl_->InnerViewportScrollLayer()->SetScrollDelta(inner_viewport_offset);
2873 2880
2874 scroll_delta = gfx::Vector2dF(0.f, -65.f); 2881 scroll_delta = gfx::Vector2dF(0.f, -65.f);
2875 EXPECT_EQ(InputHandler::ScrollStarted, 2882 EXPECT_EQ(InputHandler::ScrollStarted,
2876 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2883 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2877 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2884 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2878 2885
2879 EXPECT_EQ(top_controls_height_, 2886 EXPECT_EQ(top_controls_height_,
2880 host_impl_->active_tree()->total_top_controls_content_offset()); 2887 host_impl_->top_controls_manager()->ContentTopOffset());
2881 EXPECT_EQ( 2888 EXPECT_EQ(
2882 inner_viewport_offset.y() + (scroll_delta.y() + top_controls_height_), 2889 inner_viewport_offset.y() + (scroll_delta.y() + top_controls_height_),
2883 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y()); 2890 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y());
2884 2891
2885 host_impl_->ScrollEnd(); 2892 host_impl_->ScrollEnd();
2886 } 2893 }
2887 2894
2888 TEST_F(LayerTreeHostImplTopControlsTest, 2895 TEST_F(LayerTreeHostImplTopControlsTest,
2889 ScrollNonScrollableRootWithTopControls) { 2896 ScrollNonScrollableRootWithTopControls) {
2890 CreateHostImpl(settings_, CreateOutputSurface()); 2897 CreateHostImpl(settings_, CreateOutputSurface());
(...skipping 4385 matching lines...) Expand 10 before | Expand all | Expand 10 after
7276 } 7283 }
7277 } 7284 }
7278 7285
7279 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { 7286 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest {
7280 public: 7287 public:
7281 void SetUp() override { 7288 void SetUp() override {
7282 LayerTreeSettings settings = DefaultSettings(); 7289 LayerTreeSettings settings = DefaultSettings();
7283 settings.calculate_top_controls_position = true; 7290 settings.calculate_top_controls_position = true;
7284 CreateHostImpl(settings, CreateOutputSurface()); 7291 CreateHostImpl(settings, CreateOutputSurface());
7285 host_impl_->active_tree()->set_top_controls_height(top_controls_height_); 7292 host_impl_->active_tree()->set_top_controls_height(top_controls_height_);
7286 host_impl_->active_tree()->set_top_controls_delta(top_controls_height_); 7293 host_impl_->sync_tree()->set_top_controls_height(top_controls_height_);
7287 host_impl_->top_controls_manager()->SetTopControlsHeight( 7294 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f);
7288 top_controls_height_);
7289 } 7295 }
7290 7296
7291 protected: 7297 protected:
7292 static const int top_controls_height_; 7298 static const int top_controls_height_;
7293 }; 7299 };
7294 7300
7295 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50; 7301 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50;
7296 7302
7297 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { 7303 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) {
7298 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 7304 SetupScrollAndContentsLayers(gfx::Size(100, 100))
7299 ->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 10)); 7305 ->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 10));
7300 host_impl_->Animate(base::TimeTicks()); 7306 host_impl_->Animate(base::TimeTicks());
7301 EXPECT_FALSE(did_request_redraw_); 7307 EXPECT_FALSE(did_request_redraw_);
7302 } 7308 }
7303 7309
7304 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsHeightIsCommitted) { 7310 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsHeightIsCommitted) {
7305 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 7311 SetupScrollAndContentsLayers(gfx::Size(100, 100));
7306 EXPECT_FALSE(did_request_redraw_); 7312 EXPECT_FALSE(did_request_redraw_);
7307 host_impl_->CreatePendingTree(); 7313 host_impl_->CreatePendingTree();
7308 host_impl_->sync_tree()->set_top_controls_height(100); 7314 host_impl_->sync_tree()->set_top_controls_height(100);
7309 host_impl_->ActivateSyncTree(); 7315 host_impl_->ActivateSyncTree();
7310 EXPECT_EQ(100, host_impl_->top_controls_manager()->top_controls_height()); 7316 EXPECT_EQ(100, host_impl_->top_controls_manager()->TopControlsHeight());
7311 } 7317 }
7312 7318
7313 TEST_F(LayerTreeHostImplWithTopControlsTest, 7319 TEST_F(LayerTreeHostImplWithTopControlsTest,
7314 TopControlsStayFullyVisibleOnHeightChange) { 7320 TopControlsStayFullyVisibleOnHeightChange) {
7315 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 7321 SetupScrollAndContentsLayers(gfx::Size(100, 100));
7316 EXPECT_EQ(0.f, host_impl_->ControlsTopOffset()); 7322 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset());
7317 7323
7318 host_impl_->CreatePendingTree(); 7324 host_impl_->CreatePendingTree();
7319 host_impl_->sync_tree()->set_top_controls_height(0); 7325 host_impl_->sync_tree()->set_top_controls_height(0);
7320 host_impl_->ActivateSyncTree(); 7326 host_impl_->ActivateSyncTree();
7321 EXPECT_EQ(0.f, host_impl_->ControlsTopOffset()); 7327 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset());
7322 7328
7323 host_impl_->CreatePendingTree(); 7329 host_impl_->CreatePendingTree();
7324 host_impl_->sync_tree()->set_top_controls_height(50); 7330 host_impl_->sync_tree()->set_top_controls_height(50);
7325 host_impl_->ActivateSyncTree(); 7331 host_impl_->ActivateSyncTree();
7326 EXPECT_EQ(0.f, host_impl_->ControlsTopOffset()); 7332 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset());
7327 } 7333 }
7328 7334
7329 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { 7335 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) {
7330 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 7336 SetupScrollAndContentsLayers(gfx::Size(100, 100))
7331 ->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 10)); 7337 ->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 10));
7332 host_impl_->DidChangeTopControlsPosition(); 7338 host_impl_->DidChangeTopControlsPosition();
7333 EXPECT_TRUE(did_request_animate_); 7339 EXPECT_TRUE(did_request_animate_);
7334 EXPECT_TRUE(did_request_redraw_); 7340 EXPECT_TRUE(did_request_redraw_);
7335 } 7341 }
7336 7342
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
8053 // surface. 8059 // surface.
8054 EXPECT_EQ(0, num_lost_surfaces_); 8060 EXPECT_EQ(0, num_lost_surfaces_);
8055 host_impl_->DidLoseOutputSurface(); 8061 host_impl_->DidLoseOutputSurface();
8056 EXPECT_EQ(1, num_lost_surfaces_); 8062 EXPECT_EQ(1, num_lost_surfaces_);
8057 host_impl_->DidLoseOutputSurface(); 8063 host_impl_->DidLoseOutputSurface();
8058 EXPECT_LE(1, num_lost_surfaces_); 8064 EXPECT_LE(1, num_lost_surfaces_);
8059 } 8065 }
8060 8066
8061 } // namespace 8067 } // namespace
8062 } // namespace cc 8068 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698