OLD | NEW |
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 2525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2536 host_impl_->top_controls_manager()->ScrollBegin(); | 2536 host_impl_->top_controls_manager()->ScrollBegin(); |
2537 host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta); | 2537 host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta); |
2538 EXPECT_EQ(top_controls_scroll_delta.y(), | 2538 EXPECT_EQ(top_controls_scroll_delta.y(), |
2539 host_impl_->top_controls_manager()->ContentTopOffset()); | 2539 host_impl_->top_controls_manager()->ContentTopOffset()); |
2540 EXPECT_VECTOR_EQ( | 2540 EXPECT_VECTOR_EQ( |
2541 gfx::Vector2dF(0, top_controls_height_ - top_controls_scroll_delta.y()), | 2541 gfx::Vector2dF(0, top_controls_height_ - top_controls_scroll_delta.y()), |
2542 outer_viewport_scroll_layer->FixedContainerSizeDelta()); | 2542 outer_viewport_scroll_layer->FixedContainerSizeDelta()); |
2543 host_impl_->top_controls_manager()->ScrollEnd(); | 2543 host_impl_->top_controls_manager()->ScrollEnd(); |
2544 } | 2544 } |
2545 | 2545 |
| 2546 // Test that if a scrollable sublayer doesn't consume the scroll, |
| 2547 // top controls should hide when scrolling down. |
| 2548 TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollableSublayer) { |
| 2549 gfx::Size sub_content_size(100, 400); |
| 2550 gfx::Size sub_content_layer_size(100, 300); |
| 2551 SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 2552 gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100)); |
| 2553 DrawFrame(); |
| 2554 |
| 2555 // Show top controls |
| 2556 EXPECT_EQ(top_controls_height_, |
| 2557 host_impl_->active_tree()->total_top_controls_content_offset()); |
| 2558 |
| 2559 LayerImpl* outer_viewport_scroll_layer = |
| 2560 host_impl_->active_tree()->OuterViewportScrollLayer(); |
| 2561 int id = outer_viewport_scroll_layer->id(); |
| 2562 |
| 2563 scoped_ptr<LayerImpl> child = |
| 2564 LayerImpl::Create(host_impl_->active_tree(), id + 2); |
| 2565 scoped_ptr<LayerImpl> child_clip = |
| 2566 LayerImpl::Create(host_impl_->active_tree(), id + 3); |
| 2567 |
| 2568 child_clip->SetBounds(sub_content_layer_size); |
| 2569 child->SetScrollClipLayer(child_clip->id()); |
| 2570 child->SetBounds(sub_content_size); |
| 2571 child->SetContentBounds(sub_content_size); |
| 2572 child->SetPosition(gfx::PointF()); |
| 2573 child->SetDrawsContent(true); |
| 2574 child->SetIsContainerForFixedPositionLayers(true); |
| 2575 |
| 2576 // scroll child to limit |
| 2577 child->SetScrollDelta(gfx::Vector2dF(0, 100.f)); |
| 2578 child_clip->AddChild(child.Pass()); |
| 2579 outer_viewport_scroll_layer->AddChild(child_clip.Pass()); |
| 2580 |
| 2581 // Scroll 25px to hide top controls |
| 2582 gfx::Vector2dF scroll_delta(0.f, 25.f); |
| 2583 EXPECT_EQ(InputHandler::ScrollStarted, |
| 2584 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
| 2585 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
| 2586 host_impl_->ScrollEnd(); |
| 2587 |
| 2588 // Top controls should be hidden |
| 2589 EXPECT_EQ(scroll_delta.y(), |
| 2590 top_controls_height_ - |
| 2591 host_impl_->active_tree()->total_top_controls_content_offset()); |
| 2592 } |
| 2593 |
2546 // Ensure setting the top controls position explicitly using the setters on the | 2594 // Ensure setting the top controls position explicitly using the setters on the |
2547 // TreeImpl correctly affects the top controls manager and viewport bounds. | 2595 // TreeImpl correctly affects the top controls manager and viewport bounds. |
2548 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { | 2596 TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { |
2549 CreateHostImpl(settings_, CreateOutputSurface()); | 2597 CreateHostImpl(settings_, CreateOutputSurface()); |
2550 SetupTopControlsAndScrollLayer(); | 2598 SetupTopControlsAndScrollLayer(); |
2551 DrawFrame(); | 2599 DrawFrame(); |
2552 | 2600 |
2553 host_impl_->active_tree()->set_top_controls_delta(0.f); | 2601 host_impl_->active_tree()->set_top_controls_delta(0.f); |
2554 host_impl_->active_tree()->set_top_controls_content_offset(30.f); | 2602 host_impl_->active_tree()->set_top_controls_content_offset(30.f); |
2555 EXPECT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); | 2603 EXPECT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); |
(...skipping 5205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7761 host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(250)); | 7809 host_impl_->Animate(start_time + base::TimeDelta::FromMilliseconds(250)); |
7762 host_impl_->UpdateAnimationState(true); | 7810 host_impl_->UpdateAnimationState(true); |
7763 | 7811 |
7764 EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), | 7812 EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), |
7765 scrolling_layer->TotalScrollOffset()); | 7813 scrolling_layer->TotalScrollOffset()); |
7766 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); | 7814 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
7767 } | 7815 } |
7768 | 7816 |
7769 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) { | 7817 TEST_F(LayerTreeHostImplTest, GetPictureLayerImplPairs) { |
7770 host_impl_->CreatePendingTree(); | 7818 host_impl_->CreatePendingTree(); |
7771 host_impl_->pending_tree()->SetRootLayer( | 7819 |
7772 PictureLayerImpl::Create(host_impl_->pending_tree(), 10, false)); | 7820 scoped_ptr<PictureLayerImpl> layer = |
| 7821 PictureLayerImpl::Create(host_impl_->pending_tree(), 10, false); |
| 7822 layer->SetBounds(gfx::Size(10, 10)); |
| 7823 |
| 7824 scoped_refptr<RasterSource> pile(FakePicturePileImpl::CreateEmptyPile( |
| 7825 gfx::Size(10, 10), gfx::Size(10, 10))); |
| 7826 Region empty_invalidation; |
| 7827 const PictureLayerTilingSet* null_tiling_set = nullptr; |
| 7828 layer->UpdateRasterSource(pile, &empty_invalidation, null_tiling_set); |
| 7829 |
| 7830 host_impl_->pending_tree()->SetRootLayer(layer.Pass()); |
7773 | 7831 |
7774 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); | 7832 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
7775 LayerImpl* pending_layer = pending_tree->root_layer(); | 7833 LayerImpl* pending_layer = pending_tree->root_layer(); |
7776 | 7834 |
7777 std::vector<PictureLayerImpl::Pair> layer_pairs; | 7835 std::vector<PictureLayerImpl::Pair> layer_pairs; |
7778 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); | 7836 host_impl_->GetPictureLayerImplPairs(&layer_pairs, true); |
7779 EXPECT_EQ(1u, layer_pairs.size()); | 7837 EXPECT_EQ(1u, layer_pairs.size()); |
7780 EXPECT_EQ(pending_layer, layer_pairs[0].pending); | 7838 EXPECT_EQ(pending_layer, layer_pairs[0].pending); |
7781 EXPECT_EQ(nullptr, layer_pairs[0].active); | 7839 EXPECT_EQ(nullptr, layer_pairs[0].active); |
7782 | 7840 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7830 | 7888 |
7831 TEST_F(LayerTreeHostImplTest, DidBecomeActive) { | 7889 TEST_F(LayerTreeHostImplTest, DidBecomeActive) { |
7832 host_impl_->CreatePendingTree(); | 7890 host_impl_->CreatePendingTree(); |
7833 host_impl_->ActivateSyncTree(); | 7891 host_impl_->ActivateSyncTree(); |
7834 host_impl_->CreatePendingTree(); | 7892 host_impl_->CreatePendingTree(); |
7835 | 7893 |
7836 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); | 7894 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
7837 | 7895 |
7838 scoped_ptr<FakePictureLayerImpl> pending_layer = | 7896 scoped_ptr<FakePictureLayerImpl> pending_layer = |
7839 FakePictureLayerImpl::Create(pending_tree, 10); | 7897 FakePictureLayerImpl::Create(pending_tree, 10); |
7840 pending_layer->DoPostCommitInitializationIfNeeded(); | |
7841 FakePictureLayerImpl* raw_pending_layer = pending_layer.get(); | 7898 FakePictureLayerImpl* raw_pending_layer = pending_layer.get(); |
7842 pending_tree->SetRootLayer(pending_layer.Pass()); | 7899 pending_tree->SetRootLayer(pending_layer.Pass()); |
7843 ASSERT_EQ(raw_pending_layer, pending_tree->root_layer()); | 7900 ASSERT_EQ(raw_pending_layer, pending_tree->root_layer()); |
7844 | 7901 |
7845 EXPECT_EQ(0u, raw_pending_layer->did_become_active_call_count()); | 7902 EXPECT_EQ(0u, raw_pending_layer->did_become_active_call_count()); |
7846 pending_tree->DidBecomeActive(); | 7903 pending_tree->DidBecomeActive(); |
7847 EXPECT_EQ(1u, raw_pending_layer->did_become_active_call_count()); | 7904 EXPECT_EQ(1u, raw_pending_layer->did_become_active_call_count()); |
7848 | 7905 |
7849 scoped_ptr<FakePictureLayerImpl> mask_layer = | 7906 scoped_ptr<FakePictureLayerImpl> mask_layer = |
7850 FakePictureLayerImpl::Create(pending_tree, 11); | 7907 FakePictureLayerImpl::Create(pending_tree, 11); |
7851 mask_layer->DoPostCommitInitializationIfNeeded(); | |
7852 FakePictureLayerImpl* raw_mask_layer = mask_layer.get(); | 7908 FakePictureLayerImpl* raw_mask_layer = mask_layer.get(); |
7853 raw_pending_layer->SetMaskLayer(mask_layer.Pass()); | 7909 raw_pending_layer->SetMaskLayer(mask_layer.Pass()); |
7854 ASSERT_EQ(raw_mask_layer, raw_pending_layer->mask_layer()); | 7910 ASSERT_EQ(raw_mask_layer, raw_pending_layer->mask_layer()); |
7855 | 7911 |
7856 EXPECT_EQ(1u, raw_pending_layer->did_become_active_call_count()); | 7912 EXPECT_EQ(1u, raw_pending_layer->did_become_active_call_count()); |
7857 EXPECT_EQ(0u, raw_mask_layer->did_become_active_call_count()); | 7913 EXPECT_EQ(0u, raw_mask_layer->did_become_active_call_count()); |
7858 pending_tree->DidBecomeActive(); | 7914 pending_tree->DidBecomeActive(); |
7859 EXPECT_EQ(2u, raw_pending_layer->did_become_active_call_count()); | 7915 EXPECT_EQ(2u, raw_pending_layer->did_become_active_call_count()); |
7860 EXPECT_EQ(1u, raw_mask_layer->did_become_active_call_count()); | 7916 EXPECT_EQ(1u, raw_mask_layer->did_become_active_call_count()); |
7861 | 7917 |
7862 scoped_ptr<FakePictureLayerImpl> replica_layer = | 7918 scoped_ptr<FakePictureLayerImpl> replica_layer = |
7863 FakePictureLayerImpl::Create(pending_tree, 12); | 7919 FakePictureLayerImpl::Create(pending_tree, 12); |
7864 scoped_ptr<FakePictureLayerImpl> replica_mask_layer = | 7920 scoped_ptr<FakePictureLayerImpl> replica_mask_layer = |
7865 FakePictureLayerImpl::Create(pending_tree, 13); | 7921 FakePictureLayerImpl::Create(pending_tree, 13); |
7866 replica_mask_layer->DoPostCommitInitializationIfNeeded(); | |
7867 FakePictureLayerImpl* raw_replica_mask_layer = replica_mask_layer.get(); | 7922 FakePictureLayerImpl* raw_replica_mask_layer = replica_mask_layer.get(); |
7868 replica_layer->SetMaskLayer(replica_mask_layer.Pass()); | 7923 replica_layer->SetMaskLayer(replica_mask_layer.Pass()); |
7869 raw_pending_layer->SetReplicaLayer(replica_layer.Pass()); | 7924 raw_pending_layer->SetReplicaLayer(replica_layer.Pass()); |
7870 ASSERT_EQ(raw_replica_mask_layer, | 7925 ASSERT_EQ(raw_replica_mask_layer, |
7871 raw_pending_layer->replica_layer()->mask_layer()); | 7926 raw_pending_layer->replica_layer()->mask_layer()); |
7872 | 7927 |
7873 EXPECT_EQ(2u, raw_pending_layer->did_become_active_call_count()); | 7928 EXPECT_EQ(2u, raw_pending_layer->did_become_active_call_count()); |
7874 EXPECT_EQ(1u, raw_mask_layer->did_become_active_call_count()); | 7929 EXPECT_EQ(1u, raw_mask_layer->did_become_active_call_count()); |
7875 EXPECT_EQ(0u, raw_replica_mask_layer->did_become_active_call_count()); | 7930 EXPECT_EQ(0u, raw_replica_mask_layer->did_become_active_call_count()); |
7876 pending_tree->DidBecomeActive(); | 7931 pending_tree->DidBecomeActive(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7929 // surface. | 7984 // surface. |
7930 EXPECT_EQ(0, num_lost_surfaces_); | 7985 EXPECT_EQ(0, num_lost_surfaces_); |
7931 host_impl_->DidLoseOutputSurface(); | 7986 host_impl_->DidLoseOutputSurface(); |
7932 EXPECT_EQ(1, num_lost_surfaces_); | 7987 EXPECT_EQ(1, num_lost_surfaces_); |
7933 host_impl_->DidLoseOutputSurface(); | 7988 host_impl_->DidLoseOutputSurface(); |
7934 EXPECT_LE(1, num_lost_surfaces_); | 7989 EXPECT_LE(1, num_lost_surfaces_); |
7935 } | 7990 } |
7936 | 7991 |
7937 } // namespace | 7992 } // namespace |
7938 } // namespace cc | 7993 } // namespace cc |
OLD | NEW |