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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 6371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6382 // Overscroll initiated inside layers will be handled by the main thread. | 6382 // Overscroll initiated inside layers will be handled by the main thread. |
6383 EXPECT_NE(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( | 6383 EXPECT_NE(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( |
6384 gfx::PointF(0, 0))); | 6384 gfx::PointF(0, 0))); |
6385 EXPECT_EQ( | 6385 EXPECT_EQ( |
6386 InputHandler::SCROLL_ON_MAIN_THREAD, | 6386 InputHandler::SCROLL_ON_MAIN_THREAD, |
6387 host_impl_ | 6387 host_impl_ |
6388 ->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), InputHandler::WHEEL) | 6388 ->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), InputHandler::WHEEL) |
6389 .thread); | 6389 .thread); |
6390 } | 6390 } |
6391 | 6391 |
| 6392 // Test that scrolls chain correctly when a child scroller on the page (e.g. a |
| 6393 // scrolling div) is set as the outer viewport. This happens in the |
| 6394 // rootScroller proposal. |
| 6395 TEST_F(LayerTreeHostImplTest, ScrollChainingWithReplacedOuterViewport) { |
| 6396 const gfx::Size content_size(200, 200); |
| 6397 const gfx::Size viewport_size(100, 100); |
| 6398 |
| 6399 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 6400 |
| 6401 LayerImpl* content_layer = |
| 6402 CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 6403 LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
| 6404 LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 6405 |
| 6406 LayerImpl* scroll_layer = nullptr; |
| 6407 LayerImpl* child_scroll_layer = nullptr; |
| 6408 |
| 6409 // Initialization: Add two nested scrolling layers, simulating a scrolling div |
| 6410 // with another scrolling div inside it. Set the outer "div" to be the outer |
| 6411 // viewport. |
| 6412 { |
| 6413 std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10); |
| 6414 clip->SetBounds(content_size); |
| 6415 clip->SetPosition(gfx::PointF()); |
| 6416 |
| 6417 std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11); |
| 6418 scroll->SetBounds(gfx::Size(400, 400)); |
| 6419 scroll->SetScrollClipLayer(clip->id()); |
| 6420 scroll->SetDrawsContent(true); |
| 6421 |
| 6422 std::unique_ptr<LayerImpl> clip2 = LayerImpl::Create(layer_tree_impl, 12); |
| 6423 clip2->SetBounds(gfx::Size(300, 300)); |
| 6424 clip2->SetPosition(gfx::PointF()); |
| 6425 clip2->SetDrawsContent(true); |
| 6426 |
| 6427 std::unique_ptr<LayerImpl> scroll2 = LayerImpl::Create(layer_tree_impl, 13); |
| 6428 scroll2->SetBounds(gfx::Size(500, 500)); |
| 6429 scroll2->SetScrollClipLayer(clip2->id()); |
| 6430 scroll2->SetDrawsContent(true); |
| 6431 |
| 6432 scroll_layer = scroll.get(); |
| 6433 child_scroll_layer = scroll2.get(); |
| 6434 |
| 6435 clip2->test_properties()->AddChild(std::move(scroll2)); |
| 6436 scroll->test_properties()->AddChild(std::move(clip2)); |
| 6437 |
| 6438 clip->test_properties()->AddChild(std::move(scroll)); |
| 6439 content_layer->test_properties()->AddChild(std::move(clip)); |
| 6440 layer_tree_impl->SetViewportLayersFromIds( |
| 6441 Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(), |
| 6442 inner_scroll_layer->id(), scroll_layer->id()); |
| 6443 layer_tree_impl->BuildPropertyTreesForTesting(); |
| 6444 } |
| 6445 |
| 6446 // Scroll should target the nested scrolling layer in the content and then |
| 6447 // chain to the parent scrolling layer which is now set as the outer |
| 6448 // viewport. The original outer viewport layer shouldn't get any scroll here. |
| 6449 { |
| 6450 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6451 InputHandler::TOUCHSCREEN); |
| 6452 host_impl_->ScrollBy( |
| 6453 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(200.f, 200.f)).get()); |
| 6454 host_impl_->ScrollEnd(EndState().get()); |
| 6455 |
| 6456 EXPECT_VECTOR_EQ(gfx::Vector2dF(200.f, 200.f), |
| 6457 child_scroll_layer->CurrentScrollOffset()); |
| 6458 |
| 6459 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6460 InputHandler::TOUCHSCREEN); |
| 6461 host_impl_->ScrollBy( |
| 6462 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(200.f, 200.f)).get()); |
| 6463 host_impl_->ScrollEnd(EndState().get()); |
| 6464 |
| 6465 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), |
| 6466 outer_scroll_layer->CurrentScrollOffset()); |
| 6467 |
| 6468 EXPECT_VECTOR_EQ(gfx::Vector2dF(200.f, 200.f), |
| 6469 scroll_layer->CurrentScrollOffset()); |
| 6470 } |
| 6471 |
| 6472 // Now that the nested scrolling layers are fully scrolled, further scrolls |
| 6473 // would normally chain up to the "outer viewport" but since we've set the |
| 6474 // scrolling content as the outer viewport, it should stop chaining there. |
| 6475 { |
| 6476 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6477 InputHandler::TOUCHSCREEN); |
| 6478 host_impl_->ScrollBy( |
| 6479 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 6480 host_impl_->ScrollEnd(EndState().get()); |
| 6481 |
| 6482 EXPECT_VECTOR_EQ(gfx::Vector2dF(), |
| 6483 outer_scroll_layer->CurrentScrollOffset()); |
| 6484 } |
| 6485 |
| 6486 // Zoom into the page by a 2X factor so that the inner viewport becomes |
| 6487 // scrollable. |
| 6488 float min_page_scale = 1.f, max_page_scale = 4.f; |
| 6489 float page_scale_factor = 2.f; |
| 6490 host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 6491 page_scale_factor, min_page_scale, max_page_scale); |
| 6492 host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 6493 |
| 6494 // Reset the parent scrolling layer (i.e. the current outer viewport) so that |
| 6495 // we can ensure viewport scrolling works correctly. |
| 6496 scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset(0, 0)); |
| 6497 |
| 6498 // Scrolling the content layer should now scroll the inner viewport first, |
| 6499 // and then chain up to the current outer viewport (i.e. the parent scroll |
| 6500 // layer). |
| 6501 { |
| 6502 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6503 InputHandler::TOUCHSCREEN); |
| 6504 host_impl_->ScrollBy( |
| 6505 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 6506 host_impl_->ScrollEnd(EndState().get()); |
| 6507 |
| 6508 EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f), |
| 6509 inner_scroll_layer->CurrentScrollOffset()); |
| 6510 |
| 6511 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 6512 InputHandler::TOUCHSCREEN); |
| 6513 host_impl_->ScrollBy( |
| 6514 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 6515 host_impl_->ScrollEnd(EndState().get()); |
| 6516 |
| 6517 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), |
| 6518 outer_scroll_layer->CurrentScrollOffset()); |
| 6519 EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f), |
| 6520 scroll_layer->CurrentScrollOffset()); |
| 6521 } |
| 6522 } |
| 6523 |
6392 TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) { | 6524 TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) { |
6393 InputHandlerScrollResult scroll_result; | 6525 InputHandlerScrollResult scroll_result; |
6394 LayerTreeSettings settings = DefaultSettings(); | 6526 LayerTreeSettings settings = DefaultSettings(); |
6395 CreateHostImpl(settings, CreateOutputSurface()); | 6527 CreateHostImpl(settings, CreateOutputSurface()); |
6396 | 6528 |
6397 const gfx::Size content_size(50, 50); | 6529 const gfx::Size content_size(50, 50); |
6398 const gfx::Size viewport_size(50, 50); | 6530 const gfx::Size viewport_size(50, 50); |
6399 CreateBasicVirtualViewportLayers(viewport_size, content_size); | 6531 CreateBasicVirtualViewportLayers(viewport_size, content_size); |
6400 | 6532 |
6401 // By default, no main thread scrolling reasons should exist. | 6533 // By default, no main thread scrolling reasons should exist. |
(...skipping 2626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9028 .did_scroll); | 9160 .did_scroll); |
9029 EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), | 9161 EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), |
9030 scroll_layer->CurrentScrollOffset().ToString()); | 9162 scroll_layer->CurrentScrollOffset().ToString()); |
9031 | 9163 |
9032 // Top controls should be fully visible | 9164 // Top controls should be fully visible |
9033 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); | 9165 EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); |
9034 | 9166 |
9035 host_impl_->ScrollEnd(EndState().get()); | 9167 host_impl_->ScrollEnd(EndState().get()); |
9036 } | 9168 } |
9037 | 9169 |
| 9170 // Tests that when we set a child scroller (e.g. a scrolling div) as the outer |
| 9171 // viewport, scrolling it controls the top controls. |
| 9172 TEST_F(LayerTreeHostImplTopControlsTest, |
| 9173 ReplacedOuterViewportScrollsTopControls) { |
| 9174 const gfx::Size scroll_content_size(400, 400); |
| 9175 const gfx::Size root_layer_size(200, 200); |
| 9176 const gfx::Size viewport_size(100, 100); |
| 9177 |
| 9178 SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 9179 viewport_size, viewport_size, root_layer_size); |
| 9180 |
| 9181 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9182 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 9183 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 9184 LayerImpl* scroll_layer = nullptr; |
| 9185 |
| 9186 // Initialization: Add a child scrolling layer to the outer scroll layer and |
| 9187 // set its scroll layer as the outer viewport. This simulates setting a |
| 9188 // scrolling element as the root scroller on the page. |
| 9189 { |
| 9190 std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10); |
| 9191 clip->SetBounds(root_layer_size); |
| 9192 clip->SetPosition(gfx::PointF()); |
| 9193 |
| 9194 std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11); |
| 9195 scroll->SetBounds(scroll_content_size); |
| 9196 scroll->SetScrollClipLayer(clip->id()); |
| 9197 scroll->SetDrawsContent(true); |
| 9198 |
| 9199 scroll_layer = scroll.get(); |
| 9200 |
| 9201 clip->test_properties()->AddChild(std::move(scroll)); |
| 9202 outer_scroll->test_properties()->AddChild(std::move(clip)); |
| 9203 layer_tree_impl->SetViewportLayersFromIds( |
| 9204 Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(), |
| 9205 inner_scroll->id(), scroll_layer->id()); |
| 9206 layer_tree_impl->BuildPropertyTreesForTesting(); |
| 9207 DrawFrame(); |
| 9208 } |
| 9209 |
| 9210 ASSERT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 9211 |
| 9212 // Scrolling should scroll the child content and the top controls. The |
| 9213 // original outer viewport should get no scroll. |
| 9214 { |
| 9215 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 9216 InputHandler::TOUCHSCREEN); |
| 9217 host_impl_->ScrollBy( |
| 9218 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); |
| 9219 host_impl_->ScrollEnd(EndState().get()); |
| 9220 |
| 9221 EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll->CurrentScrollOffset()); |
| 9222 EXPECT_VECTOR_EQ(gfx::Vector2dF(100.f, 50.f), |
| 9223 scroll_layer->CurrentScrollOffset()); |
| 9224 EXPECT_EQ(0.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); |
| 9225 } |
| 9226 } |
| 9227 |
9038 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { | 9228 class LayerTreeHostImplVirtualViewportTest : public LayerTreeHostImplTest { |
9039 public: | 9229 public: |
9040 void SetupVirtualViewportLayers(const gfx::Size& content_size, | 9230 void SetupVirtualViewportLayers(const gfx::Size& content_size, |
9041 const gfx::Size& outer_viewport, | 9231 const gfx::Size& outer_viewport, |
9042 const gfx::Size& inner_viewport) { | 9232 const gfx::Size& inner_viewport) { |
9043 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); | 9233 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
9044 const int kOuterViewportClipLayerId = 6; | 9234 const int kOuterViewportClipLayerId = 6; |
9045 const int kOuterViewportScrollLayerId = 7; | 9235 const int kOuterViewportScrollLayerId = 7; |
9046 const int kInnerViewportScrollLayerId = 2; | 9236 const int kInnerViewportScrollLayerId = 2; |
9047 const int kInnerViewportClipLayerId = 4; | 9237 const int kInnerViewportClipLayerId = 4; |
(...skipping 1900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10948 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); | 11138 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); |
10949 | 11139 |
10950 // Re-initialize with a software output surface. | 11140 // Re-initialize with a software output surface. |
10951 output_surface_ = FakeOutputSurface::CreateDelegatingSoftware(); | 11141 output_surface_ = FakeOutputSurface::CreateDelegatingSoftware(); |
10952 host_impl_->InitializeRenderer(output_surface_.get()); | 11142 host_impl_->InitializeRenderer(output_surface_.get()); |
10953 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); | 11143 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
10954 } | 11144 } |
10955 | 11145 |
10956 } // namespace | 11146 } // namespace |
10957 } // namespace cc | 11147 } // namespace cc |
OLD | NEW |