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