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

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: Replace more EXPECT_EQ with EXPECT_FLOAT_EQ for windows bots 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 2443 matching lines...) Expand 10 before | Expand all | Expand 10 after
2454 viewport_size_ = gfx::Size(clip_size_.width(), 2454 viewport_size_ = gfx::Size(clip_size_.width(),
2455 clip_size_.height() + top_controls_height_); 2455 clip_size_.height() + top_controls_height_);
2456 } 2456 }
2457 2457
2458 bool CreateHostImpl(const LayerTreeSettings& settings, 2458 bool CreateHostImpl(const LayerTreeSettings& settings,
2459 scoped_ptr<OutputSurface> output_surface) override { 2459 scoped_ptr<OutputSurface> output_surface) override {
2460 bool init = 2460 bool init =
2461 LayerTreeHostImplTest::CreateHostImpl(settings, output_surface.Pass()); 2461 LayerTreeHostImplTest::CreateHostImpl(settings, output_surface.Pass());
2462 if (init && settings.calculate_top_controls_position) { 2462 if (init && settings.calculate_top_controls_position) {
2463 host_impl_->active_tree()->set_top_controls_height(top_controls_height_); 2463 host_impl_->active_tree()->set_top_controls_height(top_controls_height_);
2464 host_impl_->active_tree()->set_top_controls_delta(top_controls_height_); 2464 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f);
2465 host_impl_->top_controls_manager()->SetTopControlsHeight(
2466 top_controls_height_);
2467 host_impl_->DidChangeTopControlsPosition();
2468 } 2465 }
2469 return init; 2466 return init;
2470 } 2467 }
2471 2468
2472 void SetupTopControlsAndScrollLayer() { 2469 void SetupTopControlsAndScrollLayer() {
2473 scoped_ptr<LayerImpl> root = 2470 scoped_ptr<LayerImpl> root =
2474 LayerImpl::Create(host_impl_->active_tree(), 1); 2471 LayerImpl::Create(host_impl_->active_tree(), 1);
2475 scoped_ptr<LayerImpl> root_clip = 2472 scoped_ptr<LayerImpl> root_clip =
2476 LayerImpl::Create(host_impl_->active_tree(), 2); 2473 LayerImpl::Create(host_impl_->active_tree(), 2);
2477 root_clip->SetBounds(clip_size_); 2474 root_clip->SetBounds(clip_size_);
(...skipping 13 matching lines...) Expand all
2491 Layer::INVALID_ID, page_scale_layer_id, inner_viewport_scroll_layer_id, 2488 Layer::INVALID_ID, page_scale_layer_id, inner_viewport_scroll_layer_id,
2492 Layer::INVALID_ID); 2489 Layer::INVALID_ID);
2493 // Set a viewport size that is large enough to contain both the top controls 2490 // Set a viewport size that is large enough to contain both the top controls
2494 // and some content. 2491 // and some content.
2495 host_impl_->SetViewportSize(viewport_size_); 2492 host_impl_->SetViewportSize(viewport_size_);
2496 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); 2493 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2497 2494
2498 host_impl_->DidChangeTopControlsPosition(); 2495 host_impl_->DidChangeTopControlsPosition();
2499 2496
2500 host_impl_->CreatePendingTree(); 2497 host_impl_->CreatePendingTree();
2498 host_impl_->sync_tree()->set_top_controls_height(top_controls_height_);
2501 root = 2499 root =
2502 LayerImpl::Create(host_impl_->sync_tree(), 1); 2500 LayerImpl::Create(host_impl_->sync_tree(), 1);
2503 root_clip = 2501 root_clip =
2504 LayerImpl::Create(host_impl_->sync_tree(), 2); 2502 LayerImpl::Create(host_impl_->sync_tree(), 2);
2505 root_clip->SetBounds(clip_size_); 2503 root_clip->SetBounds(clip_size_);
2506 root->SetScrollClipLayer(root_clip->id()); 2504 root->SetScrollClipLayer(root_clip->id());
2507 root->SetBounds(layer_size_); 2505 root->SetBounds(layer_size_);
2508 root->SetContentBounds(layer_size_); 2506 root->SetContentBounds(layer_size_);
2509 root->SetPosition(gfx::PointF()); 2507 root->SetPosition(gfx::PointF());
2510 root->SetDrawsContent(false); 2508 root->SetDrawsContent(false);
(...skipping 11 matching lines...) Expand all
2522 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); 2520 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2523 host_impl_->DidChangeTopControlsPosition(); 2521 host_impl_->DidChangeTopControlsPosition();
2524 } 2522 }
2525 2523
2526 void SetupTopControlsAndScrollLayerWithVirtualViewport( 2524 void SetupTopControlsAndScrollLayerWithVirtualViewport(
2527 const gfx::Size& inner_viewport_size, 2525 const gfx::Size& inner_viewport_size,
2528 const gfx::Size& outer_viewport_size, 2526 const gfx::Size& outer_viewport_size,
2529 const gfx::Size& scroll_layer_size) { 2527 const gfx::Size& scroll_layer_size) {
2530 CreateHostImpl(settings_, CreateOutputSurface()); 2528 CreateHostImpl(settings_, CreateOutputSurface());
2531 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); 2529 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2530 host_impl_->sync_tree()->set_top_controls_height(top_controls_height_);
2532 host_impl_->DidChangeTopControlsPosition(); 2531 host_impl_->DidChangeTopControlsPosition();
2533 2532
2534 scoped_ptr<LayerImpl> root = 2533 scoped_ptr<LayerImpl> root =
2535 LayerImpl::Create(host_impl_->active_tree(), 1); 2534 LayerImpl::Create(host_impl_->active_tree(), 1);
2536 scoped_ptr<LayerImpl> root_clip = 2535 scoped_ptr<LayerImpl> root_clip =
2537 LayerImpl::Create(host_impl_->active_tree(), 2); 2536 LayerImpl::Create(host_impl_->active_tree(), 2);
2538 scoped_ptr<LayerImpl> page_scale = 2537 scoped_ptr<LayerImpl> page_scale =
2539 LayerImpl::Create(host_impl_->active_tree(), 3); 2538 LayerImpl::Create(host_impl_->active_tree(), 3);
2540 2539
2541 scoped_ptr<LayerImpl> outer_scroll = 2540 scoped_ptr<LayerImpl> outer_scroll =
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2600 // (3) matches the movement of the top controls. 2599 // (3) matches the movement of the top controls.
2601 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f); 2600 gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f);
2602 host_impl_->top_controls_manager()->ScrollBegin(); 2601 host_impl_->top_controls_manager()->ScrollBegin();
2603 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2602 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2604 host_impl_->top_controls_manager()->ScrollEnd(); 2603 host_impl_->top_controls_manager()->ScrollEnd();
2605 2604
2606 LayerImpl* inner_viewport_scroll_layer = 2605 LayerImpl* inner_viewport_scroll_layer =
2607 host_impl_->active_tree()->InnerViewportScrollLayer(); 2606 host_impl_->active_tree()->InnerViewportScrollLayer();
2608 DCHECK(inner_viewport_scroll_layer); 2607 DCHECK(inner_viewport_scroll_layer);
2609 host_impl_->ScrollEnd(); 2608 host_impl_->ScrollEnd();
2610 EXPECT_EQ(top_controls_scroll_delta, 2609 EXPECT_FLOAT_EQ(top_controls_scroll_delta.y(),
2611 inner_viewport_scroll_layer->FixedContainerSizeDelta()); 2610 inner_viewport_scroll_layer->FixedContainerSizeDelta().y());
2612 } 2611 }
2613 2612
2614 // In this test, the outer viewport is initially unscrollable. We test that a 2613 // In this test, the outer viewport is initially unscrollable. We test that a
2615 // scroll initiated on the inner viewport, causing the top controls to show and 2614 // scroll initiated on the inner viewport, causing the top controls to show and
2616 // thus making the outer viewport scrollable, still scrolls the outer viewport. 2615 // thus making the outer viewport scrollable, still scrolls the outer viewport.
2617 TEST_F(LayerTreeHostImplTopControlsTest, 2616 TEST_F(LayerTreeHostImplTopControlsTest,
2618 TopControlsOuterViewportBecomesScrollable) { 2617 TopControlsOuterViewportBecomesScrollable) {
2619 SetupTopControlsAndScrollLayerWithVirtualViewport( 2618 SetupTopControlsAndScrollLayerWithVirtualViewport(
2620 gfx::Size(10, 50), gfx::Size(10, 50), gfx::Size(10, 100)); 2619 gfx::Size(10, 50), gfx::Size(10, 50), gfx::Size(10, 100));
2621 DrawFrame(); 2620 DrawFrame();
(...skipping 10 matching lines...) Expand all
2632 // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer. 2631 // Need SetDrawsContent so ScrollBegin's hit test finds an actual layer.
2633 outer_scroll->SetDrawsContent(true); 2632 outer_scroll->SetDrawsContent(true);
2634 host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 1.f, 2.f); 2633 host_impl_->active_tree()->PushPageScaleFromMainThread(2.f, 1.f, 2.f);
2635 2634
2636 EXPECT_EQ(InputHandler::ScrollStarted, 2635 EXPECT_EQ(InputHandler::ScrollStarted,
2637 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2636 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2638 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 50.f)); 2637 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 50.f));
2639 2638
2640 // The entire scroll delta should have been used to hide the top controls. 2639 // The entire scroll delta should have been used to hide the top controls.
2641 // The viewport layers should be resized back to their full sizes. 2640 // The viewport layers should be resized back to their full sizes.
2642 EXPECT_EQ(0.f, 2641 EXPECT_EQ(0.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
2643 host_impl_->active_tree()->total_top_controls_content_offset());
2644 EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y()); 2642 EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y());
2645 EXPECT_EQ(100.f, inner_container->BoundsForScrolling().height()); 2643 EXPECT_EQ(100.f, inner_container->BoundsForScrolling().height());
2646 EXPECT_EQ(100.f, outer_container->BoundsForScrolling().height()); 2644 EXPECT_EQ(100.f, outer_container->BoundsForScrolling().height());
2647 2645
2648 // The inner viewport should be scrollable by 50px * page_scale. 2646 // The inner viewport should be scrollable by 50px * page_scale.
2649 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 100.f)); 2647 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, 100.f));
2650 EXPECT_EQ(50.f, inner_scroll->CurrentScrollOffset().y()); 2648 EXPECT_EQ(50.f, inner_scroll->CurrentScrollOffset().y());
2651 EXPECT_EQ(0.f, outer_scroll->CurrentScrollOffset().y()); 2649 EXPECT_EQ(0.f, outer_scroll->CurrentScrollOffset().y());
2652 EXPECT_EQ(gfx::ScrollOffset(), outer_scroll->MaxScrollOffset()); 2650 EXPECT_EQ(gfx::ScrollOffset(), outer_scroll->MaxScrollOffset());
2653 2651
2654 host_impl_->ScrollEnd(); 2652 host_impl_->ScrollEnd();
2655 2653
2656 EXPECT_EQ(InputHandler::ScrollStarted, 2654 EXPECT_EQ(InputHandler::ScrollStarted,
2657 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2655 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2658 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); 2656 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll);
2659 2657
2660 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -50.f)); 2658 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -50.f));
2661 2659
2662 // The entire scroll delta should have been used to show the top controls. 2660 // The entire scroll delta should have been used to show the top controls.
2663 // The outer viewport should be resized to accomodate and scrolled to the 2661 // The outer viewport should be resized to accomodate and scrolled to the
2664 // bottom of the document to keep the viewport in place. 2662 // bottom of the document to keep the viewport in place.
2665 EXPECT_EQ(50.f, 2663 EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
2666 host_impl_->active_tree()->total_top_controls_content_offset());
2667 EXPECT_EQ(50.f, outer_container->BoundsForScrolling().height()); 2664 EXPECT_EQ(50.f, outer_container->BoundsForScrolling().height());
2668 EXPECT_EQ(50.f, inner_container->BoundsForScrolling().height()); 2665 EXPECT_EQ(50.f, inner_container->BoundsForScrolling().height());
2669 EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y()); 2666 EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y());
2670 EXPECT_EQ(25.f, inner_scroll->CurrentScrollOffset().y()); 2667 EXPECT_EQ(25.f, inner_scroll->CurrentScrollOffset().y());
2671 2668
2672 // Now when we continue scrolling, make sure the outer viewport gets scrolled 2669 // Now when we continue scrolling, make sure the outer viewport gets scrolled
2673 // since it wasn't scrollable when the scroll began. 2670 // since it wasn't scrollable when the scroll began.
2674 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -20.f)); 2671 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0.f, -20.f));
2675 EXPECT_EQ(15.f, outer_scroll->CurrentScrollOffset().y()); 2672 EXPECT_EQ(15.f, outer_scroll->CurrentScrollOffset().y());
2676 EXPECT_EQ(25.f, inner_scroll->CurrentScrollOffset().y()); 2673 EXPECT_EQ(25.f, inner_scroll->CurrentScrollOffset().y());
(...skipping 25 matching lines...) Expand all
2702 host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, 2.f); 2699 host_impl_->active_tree()->PushPageScaleFromMainThread(page_scale, 1.f, 2.f);
2703 2700
2704 EXPECT_EQ(InputHandler::ScrollStarted, 2701 EXPECT_EQ(InputHandler::ScrollStarted,
2705 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2702 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2706 2703
2707 // Scroll down, the top controls hiding should expand the viewport size so 2704 // Scroll down, the top controls hiding should expand the viewport size so
2708 // the delta should be equal to the scroll distance. 2705 // the delta should be equal to the scroll distance.
2709 gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f); 2706 gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f);
2710 host_impl_->top_controls_manager()->ScrollBegin(); 2707 host_impl_->top_controls_manager()->ScrollBegin();
2711 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2708 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2712 EXPECT_EQ(top_controls_height_ - top_controls_scroll_delta.y(), 2709 EXPECT_FLOAT_EQ(top_controls_height_ - top_controls_scroll_delta.y(),
2713 host_impl_->top_controls_manager()->ContentTopOffset()); 2710 host_impl_->top_controls_manager()->ContentTopOffset());
2714 EXPECT_VECTOR_EQ(top_controls_scroll_delta, 2711 EXPECT_VECTOR_EQ(top_controls_scroll_delta,
2715 outer_viewport_scroll_layer->FixedContainerSizeDelta()); 2712 outer_viewport_scroll_layer->FixedContainerSizeDelta());
2716 host_impl_->ScrollEnd(); 2713 host_impl_->ScrollEnd();
2717 2714
2718 // Scroll past the maximum extent. The delta shouldn't be greater than the 2715 // Scroll past the maximum extent. The delta shouldn't be greater than the
2719 // top controls height. 2716 // top controls height.
2720 host_impl_->top_controls_manager()->ScrollBegin(); 2717 host_impl_->top_controls_manager()->ScrollBegin();
2721 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2718 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2722 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2719 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
2723 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); 2720 host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta);
(...skipping 16 matching lines...) Expand all
2740 // Test that if a scrollable sublayer doesn't consume the scroll, 2737 // Test that if a scrollable sublayer doesn't consume the scroll,
2741 // top controls should hide when scrolling down. 2738 // top controls should hide when scrolling down.
2742 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollableSublayer) { 2739 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollableSublayer) {
2743 gfx::Size sub_content_size(100, 400); 2740 gfx::Size sub_content_size(100, 400);
2744 gfx::Size sub_content_layer_size(100, 300); 2741 gfx::Size sub_content_layer_size(100, 300);
2745 SetupTopControlsAndScrollLayerWithVirtualViewport( 2742 SetupTopControlsAndScrollLayerWithVirtualViewport(
2746 gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100)); 2743 gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100));
2747 DrawFrame(); 2744 DrawFrame();
2748 2745
2749 // Show top controls 2746 // Show top controls
2750 EXPECT_EQ(top_controls_height_, 2747 EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
2751 host_impl_->active_tree()->total_top_controls_content_offset());
2752 2748
2753 LayerImpl* outer_viewport_scroll_layer = 2749 LayerImpl* outer_viewport_scroll_layer =
2754 host_impl_->active_tree()->OuterViewportScrollLayer(); 2750 host_impl_->active_tree()->OuterViewportScrollLayer();
2755 int id = outer_viewport_scroll_layer->id(); 2751 int id = outer_viewport_scroll_layer->id();
2756 2752
2757 scoped_ptr<LayerImpl> child = 2753 scoped_ptr<LayerImpl> child =
2758 LayerImpl::Create(host_impl_->active_tree(), id + 2); 2754 LayerImpl::Create(host_impl_->active_tree(), id + 2);
2759 scoped_ptr<LayerImpl> child_clip = 2755 scoped_ptr<LayerImpl> child_clip =
2760 LayerImpl::Create(host_impl_->active_tree(), id + 3); 2756 LayerImpl::Create(host_impl_->active_tree(), id + 3);
2761 2757
(...skipping 13 matching lines...) Expand all
2775 // Scroll 25px to hide top controls 2771 // Scroll 25px to hide top controls
2776 gfx::Vector2dF scroll_delta(0.f, 25.f); 2772 gfx::Vector2dF scroll_delta(0.f, 25.f);
2777 EXPECT_EQ(InputHandler::ScrollStarted, 2773 EXPECT_EQ(InputHandler::ScrollStarted,
2778 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2774 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2779 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2775 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2780 host_impl_->ScrollEnd(); 2776 host_impl_->ScrollEnd();
2781 2777
2782 // Top controls should be hidden 2778 // Top controls should be hidden
2783 EXPECT_EQ(scroll_delta.y(), 2779 EXPECT_EQ(scroll_delta.y(),
2784 top_controls_height_ - 2780 top_controls_height_ -
2785 host_impl_->active_tree()->total_top_controls_content_offset()); 2781 host_impl_->top_controls_manager()->ContentTopOffset());
2786 } 2782 }
2787 2783
2788 // Ensure setting the top controls position explicitly using the setters on the 2784 // Ensure setting the top controls position explicitly using the setters on the
2789 // TreeImpl correctly affects the top controls manager and viewport bounds. 2785 // TreeImpl correctly affects the top controls manager and viewport bounds.
2790 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { 2786 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) {
2791 CreateHostImpl(settings_, CreateOutputSurface()); 2787 CreateHostImpl(settings_, CreateOutputSurface());
2792 SetupTopControlsAndScrollLayer(); 2788 SetupTopControlsAndScrollLayer();
2793 DrawFrame(); 2789 DrawFrame();
2794 2790
2795 host_impl_->active_tree()->set_top_controls_delta(0.f); 2791 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f);
2796 host_impl_->active_tree()->set_top_controls_content_offset(30.f); 2792 host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread(
2797 EXPECT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2793 30.f / top_controls_height_);
2798 EXPECT_EQ(-20.f, host_impl_->top_controls_manager()->ControlsTopOffset()); 2794 host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive();
2795 EXPECT_FLOAT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset());
2796 EXPECT_FLOAT_EQ(-20.f,
2797 host_impl_->top_controls_manager()->ControlsTopOffset());
2799 2798
2800 host_impl_->active_tree()->set_top_controls_delta(-30.f); 2799 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f);
2801 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2800 EXPECT_FLOAT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2802 EXPECT_EQ(-50.f, host_impl_->top_controls_manager()->ControlsTopOffset()); 2801 EXPECT_FLOAT_EQ(-50.f,
2802 host_impl_->top_controls_manager()->ControlsTopOffset());
2803 2803
2804 host_impl_->DidChangeTopControlsPosition(); 2804 host_impl_->DidChangeTopControlsPosition();
2805 2805
2806 // Now that top controls have moved, expect the clip to resize. 2806 // Now that top controls have moved, expect the clip to resize.
2807 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2807 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2808 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2808 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2809 } 2809 }
2810 2810
2811 // Test that the top_controls delta and sent delta are appropriately 2811 // Test that the top_controls delta and sent delta are appropriately
2812 // applied on sync tree activation. The total top controls offset shouldn't 2812 // applied on sync tree activation. The total top controls offset shouldn't
2813 // change after the activation. 2813 // change after the activation.
2814 TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { 2814 TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) {
2815 CreateHostImpl(settings_, CreateOutputSurface()); 2815 CreateHostImpl(settings_, CreateOutputSurface());
2816 SetupTopControlsAndScrollLayer(); 2816 SetupTopControlsAndScrollLayer();
2817 DrawFrame(); 2817 DrawFrame();
2818 2818
2819 host_impl_->sync_tree()->set_top_controls_content_offset(15.f); 2819 host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread(
2820 2820 20.f / top_controls_height_);
2821 host_impl_->active_tree()->set_top_controls_content_offset(20.f); 2821 host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive();
2822 host_impl_->active_tree()->set_top_controls_delta(-20.f); 2822 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(
2823 host_impl_->active_tree()->set_sent_top_controls_delta(-5.f); 2823 15.f / top_controls_height_);
2824 host_impl_->active_tree()
2825 ->top_controls_shown_ratio()
2826 ->PullDeltaForMainThread();
2827 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f);
2828 host_impl_->sync_tree()->PushTopControlsFromMainThread(15.f /
2829 top_controls_height_);
2824 2830
2825 host_impl_->DidChangeTopControlsPosition(); 2831 host_impl_->DidChangeTopControlsPosition();
2826 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2832 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2827 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2833 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2828 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2834 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2829 EXPECT_EQ(0.f,
2830 host_impl_->active_tree()->total_top_controls_content_offset());
2831 2835
2832 host_impl_->ActivateSyncTree(); 2836 host_impl_->ActivateSyncTree();
2833 2837
2834 root_clip_ptr = host_impl_->active_tree()->root_layer(); 2838 root_clip_ptr = host_impl_->active_tree()->root_layer();
2835 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2839 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2836 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2840 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2837 2841
2838 EXPECT_EQ(0.f, host_impl_->active_tree()->sent_top_controls_delta()); 2842 EXPECT_FLOAT_EQ(
2839 EXPECT_EQ(-15.f, host_impl_->active_tree()->top_controls_delta()); 2843 -15.f, host_impl_->active_tree()->top_controls_shown_ratio()->Delta() *
2840 EXPECT_EQ(15.f, host_impl_->active_tree()->top_controls_content_offset()); 2844 top_controls_height_);
2841 EXPECT_EQ(0.f, 2845 EXPECT_FLOAT_EQ(
2842 host_impl_->active_tree()->total_top_controls_content_offset()); 2846 15.f,
2847 host_impl_->active_tree()->top_controls_shown_ratio()->ActiveBase() *
2848 top_controls_height_);
2843 } 2849 }
2844 2850
2845 // Test that changing the top controls layout height is correctly applied to 2851 // Test that changing the top controls layout height is correctly applied to
2846 // the inner viewport container bounds. That is, the top controls layout 2852 // the inner viewport container bounds. That is, the top controls layout
2847 // height is the amount that the inner viewport container was shrunk outside 2853 // height is the amount that the inner viewport container was shrunk outside
2848 // the compositor to accommodate the top controls. 2854 // the compositor to accommodate the top controls.
2849 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { 2855 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) {
2850 CreateHostImpl(settings_, CreateOutputSurface()); 2856 CreateHostImpl(settings_, CreateOutputSurface());
2851 SetupTopControlsAndScrollLayer(); 2857 SetupTopControlsAndScrollLayer();
2852 DrawFrame(); 2858 DrawFrame();
2853 2859
2854 host_impl_->sync_tree()->set_top_controls_content_offset(50.f); 2860 host_impl_->sync_tree()->PushTopControlsFromMainThread(1.f);
2855 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); 2861 host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true);
2856 2862
2857 host_impl_->active_tree()->set_top_controls_content_offset(50.f); 2863 host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread(
2858 host_impl_->active_tree()->set_top_controls_delta(-50.f); 2864 1.f);
2865 host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive();
2866 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f);
2859 2867
2860 host_impl_->DidChangeTopControlsPosition(); 2868 host_impl_->DidChangeTopControlsPosition();
2861 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer(); 2869 LayerImpl* root_clip_ptr = host_impl_->active_tree()->root_layer();
2862 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2870 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2863 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2871 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2864 2872
2865 host_impl_->sync_tree()->root_layer()->SetBounds( 2873 host_impl_->sync_tree()->root_layer()->SetBounds(
2866 gfx::Size(root_clip_ptr->bounds().width(), 2874 gfx::Size(root_clip_ptr->bounds().width(),
2867 root_clip_ptr->bounds().height() - 50.f)); 2875 root_clip_ptr->bounds().height() - 50.f));
2868 2876
2869 host_impl_->ActivateSyncTree(); 2877 host_impl_->ActivateSyncTree();
2870 2878
2871 root_clip_ptr = host_impl_->active_tree()->root_layer(); 2879 root_clip_ptr = host_impl_->active_tree()->root_layer();
2872 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2880 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset());
2873 2881
2874 // The total bounds should remain unchanged since the bounds delta should 2882 // The total bounds should remain unchanged since the bounds delta should
2875 // account for the difference between the layout height and the current 2883 // account for the difference between the layout height and the current
2876 // top controls offset. 2884 // top controls offset.
2877 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds()); 2885 EXPECT_EQ(viewport_size_, root_clip_ptr->bounds());
2878 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 50.f), root_clip_ptr->bounds_delta()); 2886 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 50.f), root_clip_ptr->bounds_delta());
2879 2887
2880 host_impl_->active_tree()->set_top_controls_delta(0.f); 2888 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f);
2881 host_impl_->DidChangeTopControlsPosition(); 2889 host_impl_->DidChangeTopControlsPosition();
2882 2890
2891 EXPECT_EQ(1.f, host_impl_->top_controls_manager()->TopControlsShownRatio());
2892 EXPECT_EQ(50.f, host_impl_->top_controls_manager()->TopControlsHeight());
2883 EXPECT_EQ(50.f, host_impl_->top_controls_manager()->ContentTopOffset()); 2893 EXPECT_EQ(50.f, host_impl_->top_controls_manager()->ContentTopOffset());
2884 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta()); 2894 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), root_clip_ptr->bounds_delta());
2885 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height() - 50.f), 2895 EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height() - 50.f),
2886 root_clip_ptr->bounds()); 2896 root_clip_ptr->bounds());
2887 } 2897 }
2888 2898
2889 // Test that showing/hiding the top controls when the viewport is fully scrolled 2899 // Test that showing/hiding the top controls when the viewport is fully scrolled
2890 // doesn't incorrectly change the viewport offset due to clamping from changing 2900 // doesn't incorrectly change the viewport offset due to clamping from changing
2891 // viewport bounds. 2901 // viewport bounds.
2892 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { 2902 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) {
2893 SetupTopControlsAndScrollLayerWithVirtualViewport( 2903 SetupTopControlsAndScrollLayerWithVirtualViewport(
2894 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2904 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2895 DrawFrame(); 2905 DrawFrame();
2896 2906
2897 EXPECT_EQ(top_controls_height_, 2907 EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
2898 host_impl_->active_tree()->total_top_controls_content_offset());
2899 2908
2900 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); 2909 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer();
2901 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); 2910 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer();
2902 2911
2903 // Scroll the viewports to max scroll offset. 2912 // Scroll the viewports to max scroll offset.
2904 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f)); 2913 outer_scroll->SetScrollDelta(gfx::Vector2dF(0, 200.f));
2905 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f)); 2914 inner_scroll->SetScrollDelta(gfx::Vector2dF(100, 100.f));
2906 2915
2907 gfx::ScrollOffset viewport_offset = 2916 gfx::ScrollOffset viewport_offset =
2908 host_impl_->active_tree()->TotalScrollOffset(); 2917 host_impl_->active_tree()->TotalScrollOffset();
2909 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); 2918 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset);
2910 2919
2911 // Hide the top controls by 25px. 2920 // Hide the top controls by 25px.
2912 gfx::Vector2dF scroll_delta(0.f, 25.f); 2921 gfx::Vector2dF scroll_delta(0.f, 25.f);
2913 EXPECT_EQ(InputHandler::ScrollStarted, 2922 EXPECT_EQ(InputHandler::ScrollStarted,
2914 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2923 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2915 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2924 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2916 2925
2917 // scrolling down at the max extents no longer hides the top controls 2926 // scrolling down at the max extents no longer hides the top controls
2918 EXPECT_EQ(0.f, 2927 EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
2919 top_controls_height_ -
2920 host_impl_->active_tree()->total_top_controls_content_offset());
2921 2928
2922 // forcefully hide the top controls by 25px 2929 // forcefully hide the top controls by 25px
2923 host_impl_->top_controls_manager()->ScrollBy(scroll_delta); 2930 host_impl_->top_controls_manager()->ScrollBy(scroll_delta);
2924 host_impl_->ScrollEnd(); 2931 host_impl_->ScrollEnd();
2925 2932
2926 EXPECT_EQ(scroll_delta.y(), 2933 EXPECT_FLOAT_EQ(scroll_delta.y(),
2927 top_controls_height_ - 2934 top_controls_height_ -
2928 host_impl_->active_tree()->total_top_controls_content_offset()); 2935 host_impl_->top_controls_manager()->ContentTopOffset());
2929 2936
2930 inner_scroll->ClampScrollToMaxScrollOffset(); 2937 inner_scroll->ClampScrollToMaxScrollOffset();
2931 outer_scroll->ClampScrollToMaxScrollOffset(); 2938 outer_scroll->ClampScrollToMaxScrollOffset();
2932 2939
2933 // We should still be fully scrolled. 2940 // We should still be fully scrolled.
2934 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), 2941 EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(),
2935 host_impl_->active_tree()->TotalScrollOffset()); 2942 host_impl_->active_tree()->TotalScrollOffset());
2936 2943
2937 viewport_offset = host_impl_->active_tree()->TotalScrollOffset(); 2944 viewport_offset = host_impl_->active_tree()->TotalScrollOffset();
2938 2945
(...skipping 15 matching lines...) Expand all
2954 host_impl_->active_tree()->TotalScrollOffset()); 2961 host_impl_->active_tree()->TotalScrollOffset());
2955 } 2962 }
2956 2963
2957 // Test that the top controls coming in and out maintains the same aspect ratio 2964 // Test that the top controls coming in and out maintains the same aspect ratio
2958 // between the inner and outer viewports. 2965 // between the inner and outer viewports.
2959 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) { 2966 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) {
2960 SetupTopControlsAndScrollLayerWithVirtualViewport( 2967 SetupTopControlsAndScrollLayerWithVirtualViewport(
2961 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 2968 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2962 DrawFrame(); 2969 DrawFrame();
2963 2970
2964 EXPECT_EQ(top_controls_height_, 2971 EXPECT_FLOAT_EQ(top_controls_height_,
2965 host_impl_->active_tree()->total_top_controls_content_offset()); 2972 host_impl_->top_controls_manager()->ContentTopOffset());
2966 2973
2967 gfx::Vector2dF scroll_delta(0.f, 25.f); 2974 gfx::Vector2dF scroll_delta(0.f, 25.f);
2968 EXPECT_EQ(InputHandler::ScrollStarted, 2975 EXPECT_EQ(InputHandler::ScrollStarted,
2969 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2976 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2970 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2977 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2971 host_impl_->ScrollEnd(); 2978 host_impl_->ScrollEnd();
2972 2979
2973 EXPECT_EQ(scroll_delta.y(), 2980 EXPECT_FLOAT_EQ(scroll_delta.y(),
2974 top_controls_height_ - 2981 top_controls_height_ -
2975 host_impl_->active_tree()->total_top_controls_content_offset()); 2982 host_impl_->top_controls_manager()->ContentTopOffset());
2976 2983
2977 // Top controls were hidden by 25px so the inner viewport should have expanded 2984 // Top controls were hidden by 25px so the inner viewport should have expanded
2978 // by that much. 2985 // by that much.
2979 LayerImpl* outer_container = 2986 LayerImpl* outer_container =
2980 host_impl_->active_tree()->OuterViewportContainerLayer(); 2987 host_impl_->active_tree()->OuterViewportContainerLayer();
2981 LayerImpl* inner_container = 2988 LayerImpl* inner_container =
2982 host_impl_->active_tree()->InnerViewportContainerLayer(); 2989 host_impl_->active_tree()->InnerViewportContainerLayer();
2983 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->BoundsForScrolling()); 2990 EXPECT_EQ(gfx::Size(100, 100+25), inner_container->BoundsForScrolling());
2984 2991
2985 // Outer viewport should match inner's aspect ratio. The bounds are ceiled. 2992 // Outer viewport should match inner's aspect ratio. The bounds are ceiled.
2986 float aspect_ratio = inner_container->BoundsForScrolling().width() / 2993 float aspect_ratio = inner_container->BoundsForScrolling().width() /
2987 inner_container->BoundsForScrolling().height(); 2994 inner_container->BoundsForScrolling().height();
2988 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio)); 2995 gfx::Size expected = gfx::ToCeiledSize(gfx::SizeF(200, 200 / aspect_ratio));
2989 EXPECT_EQ(expected, outer_container->BoundsForScrolling()); 2996 EXPECT_EQ(expected, outer_container->BoundsForScrolling());
2990 EXPECT_EQ(expected, 2997 EXPECT_EQ(expected,
2991 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling()); 2998 host_impl_->InnerViewportScrollLayer()->BoundsForScrolling());
2992 } 2999 }
2993 3000
2994 // Test that scrolling the outer viewport affects the top controls. 3001 // Test that scrolling the outer viewport affects the top controls.
2995 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { 3002 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) {
2996 SetupTopControlsAndScrollLayerWithVirtualViewport( 3003 SetupTopControlsAndScrollLayerWithVirtualViewport(
2997 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); 3004 gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400));
2998 DrawFrame(); 3005 DrawFrame();
2999 3006
3000 EXPECT_EQ(top_controls_height_, 3007 EXPECT_EQ(top_controls_height_,
3001 host_impl_->active_tree()->total_top_controls_content_offset()); 3008 host_impl_->top_controls_manager()->ContentTopOffset());
3002 3009
3003 // Send a gesture scroll that will scroll the outer viewport, make sure the 3010 // Send a gesture scroll that will scroll the outer viewport, make sure the
3004 // top controls get scrolled. 3011 // top controls get scrolled.
3005 gfx::Vector2dF scroll_delta(0.f, 15.f); 3012 gfx::Vector2dF scroll_delta(0.f, 15.f);
3006 EXPECT_EQ(InputHandler::ScrollStarted, 3013 EXPECT_EQ(InputHandler::ScrollStarted,
3007 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 3014 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
3008 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 3015 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
3009 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), 3016 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
3010 host_impl_->CurrentlyScrollingLayer()); 3017 host_impl_->CurrentlyScrollingLayer());
3011 host_impl_->ScrollEnd(); 3018 host_impl_->ScrollEnd();
3012 3019
3013 EXPECT_EQ(scroll_delta.y(), 3020 EXPECT_FLOAT_EQ(scroll_delta.y(),
3014 top_controls_height_ - 3021 top_controls_height_ -
3015 host_impl_->active_tree()->total_top_controls_content_offset()); 3022 host_impl_->top_controls_manager()->ContentTopOffset());
3016 3023
3017 scroll_delta = gfx::Vector2dF(0.f, 50.f); 3024 scroll_delta = gfx::Vector2dF(0.f, 50.f);
3018 EXPECT_EQ(InputHandler::ScrollStarted, 3025 EXPECT_EQ(InputHandler::ScrollStarted,
3019 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 3026 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
3020 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 3027 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
3021 3028
3022 EXPECT_EQ(0, host_impl_->active_tree()->total_top_controls_content_offset()); 3029 EXPECT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset());
3023 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), 3030 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
3024 host_impl_->CurrentlyScrollingLayer()); 3031 host_impl_->CurrentlyScrollingLayer());
3025 3032
3026 host_impl_->ScrollEnd(); 3033 host_impl_->ScrollEnd();
3027 3034
3028 // Position the viewports such that the inner viewport will be scrolled. 3035 // Position the viewports such that the inner viewport will be scrolled.
3029 gfx::Vector2dF inner_viewport_offset(0.f, 25.f); 3036 gfx::Vector2dF inner_viewport_offset(0.f, 25.f);
3030 host_impl_->OuterViewportScrollLayer()->SetScrollDelta(gfx::Vector2dF()); 3037 host_impl_->OuterViewportScrollLayer()->SetScrollDelta(gfx::Vector2dF());
3031 host_impl_->InnerViewportScrollLayer()->SetScrollDelta(inner_viewport_offset); 3038 host_impl_->InnerViewportScrollLayer()->SetScrollDelta(inner_viewport_offset);
3032 3039
3033 scroll_delta = gfx::Vector2dF(0.f, -65.f); 3040 scroll_delta = gfx::Vector2dF(0.f, -65.f);
3034 EXPECT_EQ(InputHandler::ScrollStarted, 3041 EXPECT_EQ(InputHandler::ScrollStarted,
3035 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 3042 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
3036 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 3043 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
3037 3044
3038 EXPECT_EQ(top_controls_height_, 3045 EXPECT_EQ(top_controls_height_,
3039 host_impl_->active_tree()->total_top_controls_content_offset()); 3046 host_impl_->top_controls_manager()->ContentTopOffset());
3040 EXPECT_EQ( 3047 EXPECT_FLOAT_EQ(
3041 inner_viewport_offset.y() + (scroll_delta.y() + top_controls_height_), 3048 inner_viewport_offset.y() + (scroll_delta.y() + top_controls_height_),
3042 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y()); 3049 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y());
3043 3050
3044 host_impl_->ScrollEnd(); 3051 host_impl_->ScrollEnd();
3045 } 3052 }
3046 3053
3047 TEST_F(LayerTreeHostImplTopControlsTest, 3054 TEST_F(LayerTreeHostImplTopControlsTest,
3048 ScrollNonScrollableRootWithTopControls) { 3055 ScrollNonScrollableRootWithTopControls) {
3049 CreateHostImpl(settings_, CreateOutputSurface()); 3056 CreateHostImpl(settings_, CreateOutputSurface());
3050 SetupTopControlsAndScrollLayer(); 3057 SetupTopControlsAndScrollLayer();
(...skipping 12 matching lines...) Expand all
3063 3070
3064 host_impl_->ScrollEnd(); 3071 host_impl_->ScrollEnd();
3065 3072
3066 EXPECT_EQ(InputHandler::ScrollStarted, 3073 EXPECT_EQ(InputHandler::ScrollStarted,
3067 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 3074 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
3068 3075
3069 float scroll_increment_y = -25.f; 3076 float scroll_increment_y = -25.f;
3070 host_impl_->top_controls_manager()->ScrollBegin(); 3077 host_impl_->top_controls_manager()->ScrollBegin();
3071 host_impl_->top_controls_manager()->ScrollBy( 3078 host_impl_->top_controls_manager()->ScrollBy(
3072 gfx::Vector2dF(0.f, scroll_increment_y)); 3079 gfx::Vector2dF(0.f, scroll_increment_y));
3073 EXPECT_EQ(-scroll_increment_y, 3080 EXPECT_FLOAT_EQ(-scroll_increment_y,
3074 host_impl_->top_controls_manager()->ContentTopOffset()); 3081 host_impl_->top_controls_manager()->ContentTopOffset());
3075 // Now that top controls have moved, expect the clip to resize. 3082 // Now that top controls have moved, expect the clip to resize.
3076 EXPECT_EQ(gfx::Size(viewport_size_.width(), 3083 EXPECT_EQ(gfx::Size(viewport_size_.width(),
3077 viewport_size_.height() + scroll_increment_y), 3084 viewport_size_.height() + scroll_increment_y),
3078 root_clip_ptr->bounds()); 3085 root_clip_ptr->bounds());
3079 3086
3080 host_impl_->top_controls_manager()->ScrollBy( 3087 host_impl_->top_controls_manager()->ScrollBy(
3081 gfx::Vector2dF(0.f, scroll_increment_y)); 3088 gfx::Vector2dF(0.f, scroll_increment_y));
3082 host_impl_->top_controls_manager()->ScrollEnd(); 3089 host_impl_->top_controls_manager()->ScrollEnd();
3083 EXPECT_EQ(-2 * scroll_increment_y, 3090 EXPECT_FLOAT_EQ(-2 * scroll_increment_y,
3084 host_impl_->top_controls_manager()->ContentTopOffset()); 3091 host_impl_->top_controls_manager()->ContentTopOffset());
3085 // Now that top controls have moved, expect the clip to resize. 3092 // Now that top controls have moved, expect the clip to resize.
3086 EXPECT_EQ(clip_size_, root_clip_ptr->bounds()); 3093 EXPECT_EQ(clip_size_, root_clip_ptr->bounds());
3087 3094
3088 host_impl_->ScrollEnd(); 3095 host_impl_->ScrollEnd();
3089 3096
3090 // Verify the layer is once-again non-scrollable. 3097 // Verify the layer is once-again non-scrollable.
3091 EXPECT_EQ( 3098 EXPECT_EQ(
3092 gfx::ScrollOffset(), 3099 gfx::ScrollOffset(),
3093 host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset()); 3100 host_impl_->active_tree()->InnerViewportScrollLayer()->MaxScrollOffset());
3094 3101
(...skipping 4337 matching lines...) Expand 10 before | Expand all | Expand 10 after
7432 } 7439 }
7433 } 7440 }
7434 7441
7435 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { 7442 class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest {
7436 public: 7443 public:
7437 void SetUp() override { 7444 void SetUp() override {
7438 LayerTreeSettings settings = DefaultSettings(); 7445 LayerTreeSettings settings = DefaultSettings();
7439 settings.calculate_top_controls_position = true; 7446 settings.calculate_top_controls_position = true;
7440 CreateHostImpl(settings, CreateOutputSurface()); 7447 CreateHostImpl(settings, CreateOutputSurface());
7441 host_impl_->active_tree()->set_top_controls_height(top_controls_height_); 7448 host_impl_->active_tree()->set_top_controls_height(top_controls_height_);
7442 host_impl_->active_tree()->set_top_controls_delta(top_controls_height_); 7449 host_impl_->sync_tree()->set_top_controls_height(top_controls_height_);
7443 host_impl_->top_controls_manager()->SetTopControlsHeight( 7450 host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f);
7444 top_controls_height_);
7445 } 7451 }
7446 7452
7447 protected: 7453 protected:
7448 static const int top_controls_height_; 7454 static const int top_controls_height_;
7449 }; 7455 };
7450 7456
7451 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50; 7457 const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50;
7452 7458
7453 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { 7459 TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) {
7454 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 7460 SetupScrollAndContentsLayers(gfx::Size(100, 100))
7455 ->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 10)); 7461 ->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 10));
7456 host_impl_->Animate(base::TimeTicks()); 7462 host_impl_->Animate(base::TimeTicks());
7457 EXPECT_FALSE(did_request_redraw_); 7463 EXPECT_FALSE(did_request_redraw_);
7458 } 7464 }
7459 7465
7460 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsHeightIsCommitted) { 7466 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsHeightIsCommitted) {
7461 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 7467 SetupScrollAndContentsLayers(gfx::Size(100, 100));
7462 EXPECT_FALSE(did_request_redraw_); 7468 EXPECT_FALSE(did_request_redraw_);
7463 host_impl_->CreatePendingTree(); 7469 host_impl_->CreatePendingTree();
7464 host_impl_->sync_tree()->set_top_controls_height(100); 7470 host_impl_->sync_tree()->set_top_controls_height(100);
7465 host_impl_->ActivateSyncTree(); 7471 host_impl_->ActivateSyncTree();
7466 EXPECT_EQ(100, host_impl_->top_controls_manager()->top_controls_height()); 7472 EXPECT_EQ(100, host_impl_->top_controls_manager()->TopControlsHeight());
7467 } 7473 }
7468 7474
7469 TEST_F(LayerTreeHostImplWithTopControlsTest, 7475 TEST_F(LayerTreeHostImplWithTopControlsTest,
7470 TopControlsStayFullyVisibleOnHeightChange) { 7476 TopControlsStayFullyVisibleOnHeightChange) {
7471 SetupScrollAndContentsLayers(gfx::Size(100, 100)); 7477 SetupScrollAndContentsLayers(gfx::Size(100, 100));
7472 EXPECT_EQ(0.f, host_impl_->ControlsTopOffset()); 7478 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset());
7473 7479
7474 host_impl_->CreatePendingTree(); 7480 host_impl_->CreatePendingTree();
7475 host_impl_->sync_tree()->set_top_controls_height(0); 7481 host_impl_->sync_tree()->set_top_controls_height(0);
7476 host_impl_->ActivateSyncTree(); 7482 host_impl_->ActivateSyncTree();
7477 EXPECT_EQ(0.f, host_impl_->ControlsTopOffset()); 7483 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset());
7478 7484
7479 host_impl_->CreatePendingTree(); 7485 host_impl_->CreatePendingTree();
7480 host_impl_->sync_tree()->set_top_controls_height(50); 7486 host_impl_->sync_tree()->set_top_controls_height(50);
7481 host_impl_->ActivateSyncTree(); 7487 host_impl_->ActivateSyncTree();
7482 EXPECT_EQ(0.f, host_impl_->ControlsTopOffset()); 7488 EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset());
7483 } 7489 }
7484 7490
7485 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { 7491 TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) {
7486 SetupScrollAndContentsLayers(gfx::Size(100, 100)) 7492 SetupScrollAndContentsLayers(gfx::Size(100, 100))
7487 ->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 10)); 7493 ->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 10));
7488 host_impl_->DidChangeTopControlsPosition(); 7494 host_impl_->DidChangeTopControlsPosition();
7489 EXPECT_TRUE(did_request_animate_); 7495 EXPECT_TRUE(did_request_animate_);
7490 EXPECT_TRUE(did_request_redraw_); 7496 EXPECT_TRUE(did_request_redraw_);
7491 } 7497 }
7492 7498
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
8209 // surface. 8215 // surface.
8210 EXPECT_EQ(0, num_lost_surfaces_); 8216 EXPECT_EQ(0, num_lost_surfaces_);
8211 host_impl_->DidLoseOutputSurface(); 8217 host_impl_->DidLoseOutputSurface();
8212 EXPECT_EQ(1, num_lost_surfaces_); 8218 EXPECT_EQ(1, num_lost_surfaces_);
8213 host_impl_->DidLoseOutputSurface(); 8219 host_impl_->DidLoseOutputSurface();
8214 EXPECT_LE(1, num_lost_surfaces_); 8220 EXPECT_LE(1, num_lost_surfaces_);
8215 } 8221 }
8216 8222
8217 } // namespace 8223 } // namespace
8218 } // namespace cc 8224 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698