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

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

Issue 2382913003: Revert of Fix scroll chaining for non-descendants of root scroller. (Closed)
Patch Set: Created 4 years, 2 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 4137 matching lines...) Expand 10 before | Expand all | Expand 10 after
4148 EXPECT_EQ(0.f, outer_scroll->CurrentScrollOffset().y()); 4148 EXPECT_EQ(0.f, outer_scroll->CurrentScrollOffset().y());
4149 EXPECT_EQ(gfx::ScrollOffset(), outer_scroll->MaxScrollOffset()); 4149 EXPECT_EQ(gfx::ScrollOffset(), outer_scroll->MaxScrollOffset());
4150 4150
4151 host_impl_->ScrollEnd(EndState().get()); 4151 host_impl_->ScrollEnd(EndState().get());
4152 4152
4153 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 4153 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
4154 host_impl_ 4154 host_impl_
4155 ->ScrollBegin(BeginState(gfx::Point()).get(), 4155 ->ScrollBegin(BeginState(gfx::Point()).get(),
4156 InputHandler::TOUCHSCREEN) 4156 InputHandler::TOUCHSCREEN)
4157 .thread); 4157 .thread);
4158 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), outer_scroll); 4158 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll);
4159 4159
4160 host_impl_->ScrollBy( 4160 host_impl_->ScrollBy(
4161 UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -50.f)).get()); 4161 UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -50.f)).get());
4162 4162
4163 // The entire scroll delta should have been used to show the top controls. 4163 // The entire scroll delta should have been used to show the top controls.
4164 // The outer viewport should be resized to accomodate and scrolled to the 4164 // The outer viewport should be resized to accomodate and scrolled to the
4165 // bottom of the document to keep the viewport in place. 4165 // bottom of the document to keep the viewport in place.
4166 EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); 4166 EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio());
4167 EXPECT_EQ(50.f, outer_container->BoundsForScrolling().height()); 4167 EXPECT_EQ(50.f, outer_container->BoundsForScrolling().height());
4168 EXPECT_EQ(50.f, inner_container->BoundsForScrolling().height()); 4168 EXPECT_EQ(50.f, inner_container->BoundsForScrolling().height());
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
4604 // Send a gesture scroll that will scroll the outer viewport, make sure the 4604 // Send a gesture scroll that will scroll the outer viewport, make sure the
4605 // top controls get scrolled. 4605 // top controls get scrolled.
4606 gfx::Vector2dF scroll_delta(0.f, 15.f); 4606 gfx::Vector2dF scroll_delta(0.f, 15.f);
4607 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 4607 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
4608 host_impl_ 4608 host_impl_
4609 ->ScrollBegin(BeginState(gfx::Point()).get(), 4609 ->ScrollBegin(BeginState(gfx::Point()).get(),
4610 InputHandler::TOUCHSCREEN) 4610 InputHandler::TOUCHSCREEN)
4611 .thread); 4611 .thread);
4612 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 4612 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
4613 4613
4614 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), 4614 EXPECT_EQ(host_impl_->InnerViewportScrollLayer(),
4615 host_impl_->CurrentlyScrollingLayer()); 4615 host_impl_->CurrentlyScrollingLayer());
4616 host_impl_->ScrollEnd(EndState().get()); 4616 host_impl_->ScrollEnd(EndState().get());
4617 4617
4618 EXPECT_FLOAT_EQ(scroll_delta.y(), 4618 EXPECT_FLOAT_EQ(scroll_delta.y(),
4619 top_controls_height_ - 4619 top_controls_height_ -
4620 host_impl_->top_controls_manager()->ContentTopOffset()); 4620 host_impl_->top_controls_manager()->ContentTopOffset());
4621 4621
4622 scroll_delta = gfx::Vector2dF(0.f, 50.f); 4622 scroll_delta = gfx::Vector2dF(0.f, 50.f);
4623 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 4623 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
4624 host_impl_ 4624 host_impl_
4625 ->ScrollBegin(BeginState(gfx::Point()).get(), 4625 ->ScrollBegin(BeginState(gfx::Point()).get(),
4626 InputHandler::TOUCHSCREEN) 4626 InputHandler::TOUCHSCREEN)
4627 .thread); 4627 .thread);
4628 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 4628 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
4629 4629
4630 EXPECT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset()); 4630 EXPECT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset());
4631 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), 4631 EXPECT_EQ(host_impl_->InnerViewportScrollLayer(),
4632 host_impl_->CurrentlyScrollingLayer()); 4632 host_impl_->CurrentlyScrollingLayer());
4633 4633
4634 host_impl_->ScrollEnd(EndState().get()); 4634 host_impl_->ScrollEnd(EndState().get());
4635 4635
4636 // Position the viewports such that the inner viewport will be scrolled. 4636 // Position the viewports such that the inner viewport will be scrolled.
4637 gfx::Vector2dF inner_viewport_offset(0.f, 25.f); 4637 gfx::Vector2dF inner_viewport_offset(0.f, 25.f);
4638 SetScrollOffsetDelta(host_impl_->OuterViewportScrollLayer(), 4638 SetScrollOffsetDelta(host_impl_->OuterViewportScrollLayer(),
4639 gfx::Vector2dF()); 4639 gfx::Vector2dF());
4640 SetScrollOffsetDelta(host_impl_->InnerViewportScrollLayer(), 4640 SetScrollOffsetDelta(host_impl_->InnerViewportScrollLayer(),
4641 inner_viewport_offset); 4641 inner_viewport_offset);
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
5430 ASSERT_EQ(scroll_info->scrolls.size(), 1u); 5430 ASSERT_EQ(scroll_info->scrolls.size(), 1u);
5431 EXPECT_TRUE( 5431 EXPECT_TRUE(
5432 ScrollInfoContains(*scroll_info.get(), root_scroll_id, scroll_delta)); 5432 ScrollInfoContains(*scroll_info.get(), root_scroll_id, scroll_delta));
5433 } 5433 }
5434 } 5434 }
5435 5435
5436 TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { 5436 TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) {
5437 gfx::Size surface_size(10, 10); 5437 gfx::Size surface_size(10, 10);
5438 std::unique_ptr<LayerImpl> root_ptr = 5438 std::unique_ptr<LayerImpl> root_ptr =
5439 LayerImpl::Create(host_impl_->active_tree(), 1); 5439 LayerImpl::Create(host_impl_->active_tree(), 1);
5440 std::unique_ptr<LayerImpl> inner_clip = 5440 std::unique_ptr<LayerImpl> root_clip =
5441 LayerImpl::Create(host_impl_->active_tree(), 2); 5441 LayerImpl::Create(host_impl_->active_tree(), 2);
5442 std::unique_ptr<LayerImpl> inner_scroll = 5442 std::unique_ptr<LayerImpl> root_scroll =
5443 CreateScrollableLayer(3, surface_size, inner_clip.get()); 5443 CreateScrollableLayer(3, surface_size, root_clip.get());
5444 std::unique_ptr<LayerImpl> outer_clip = 5444 root_clip->test_properties()->force_render_surface = true;
5445 LayerImpl::Create(host_impl_->active_tree(), 7); 5445 root_scroll->test_properties()->is_container_for_fixed_position_layers = true;
5446 std::unique_ptr<LayerImpl> outer_scroll = 5446 root_clip->test_properties()->AddChild(std::move(root_scroll));
5447 CreateScrollableLayer(8, surface_size, outer_clip.get()); 5447 root_ptr->test_properties()->AddChild(std::move(root_clip));
5448 inner_clip->test_properties()->force_render_surface = true;
5449 inner_scroll->test_properties()->is_container_for_fixed_position_layers =
5450 true;
5451 outer_scroll->test_properties()->is_container_for_fixed_position_layers =
5452 true;
5453 outer_clip->test_properties()->AddChild(std::move(outer_scroll));
5454 inner_scroll->test_properties()->AddChild(std::move(outer_clip));
5455 inner_clip->test_properties()->AddChild(std::move(inner_scroll));
5456 root_ptr->test_properties()->AddChild(std::move(inner_clip));
5457 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); 5448 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr));
5458 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3, 5449 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3,
5459 8); 5450 Layer::INVALID_ID);
5460 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 5451 host_impl_->active_tree()->BuildPropertyTreesForTesting();
5461 host_impl_->active_tree()->DidBecomeActive(); 5452 host_impl_->active_tree()->DidBecomeActive();
5462 5453
5463 host_impl_->SetViewportSize(surface_size); 5454 host_impl_->SetViewportSize(surface_size);
5464 5455
5465 // Draw one frame and then immediately rebuild the layer tree to mimic a tree 5456 // Draw one frame and then immediately rebuild the layer tree to mimic a tree
5466 // synchronization. 5457 // synchronization.
5467 DrawFrame(); 5458 DrawFrame();
5468 5459
5469 host_impl_->active_tree()->DetachLayers(); 5460 host_impl_->active_tree()->DetachLayers();
5470 std::unique_ptr<LayerImpl> root_ptr2 = 5461 std::unique_ptr<LayerImpl> root_ptr2 =
5471 LayerImpl::Create(host_impl_->active_tree(), 4); 5462 LayerImpl::Create(host_impl_->active_tree(), 4);
5472 std::unique_ptr<LayerImpl> inner_clip2 = 5463 std::unique_ptr<LayerImpl> root_clip2 =
5473 LayerImpl::Create(host_impl_->active_tree(), 5); 5464 LayerImpl::Create(host_impl_->active_tree(), 5);
5474 std::unique_ptr<LayerImpl> inner_scroll2 = 5465 std::unique_ptr<LayerImpl> root_scroll2 =
5475 CreateScrollableLayer(6, surface_size, inner_clip2.get()); 5466 CreateScrollableLayer(6, surface_size, root_clip2.get());
5476 std::unique_ptr<LayerImpl> outer_clip2 = 5467 root_scroll2->test_properties()->is_container_for_fixed_position_layers =
5477 LayerImpl::Create(host_impl_->active_tree(), 9);
5478 std::unique_ptr<LayerImpl> outer_scroll2 =
5479 CreateScrollableLayer(10, surface_size, outer_clip2.get());
5480 inner_scroll2->test_properties()->is_container_for_fixed_position_layers =
5481 true; 5468 true;
5482 outer_scroll2->test_properties()->is_container_for_fixed_position_layers = 5469 root_clip2->test_properties()->AddChild(std::move(root_scroll2));
5483 true; 5470 root_clip2->test_properties()->force_render_surface = true;
5484 outer_clip2->test_properties()->AddChild(std::move(outer_scroll2)); 5471 root_ptr2->test_properties()->AddChild(std::move(root_clip2));
5485 inner_scroll2->test_properties()->AddChild(std::move(outer_clip2));
5486 inner_clip2->test_properties()->AddChild(std::move(inner_scroll2));
5487 inner_clip2->test_properties()->force_render_surface = true;
5488 root_ptr2->test_properties()->AddChild(std::move(inner_clip2));
5489 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr2)); 5472 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr2));
5490 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 5473 host_impl_->active_tree()->BuildPropertyTreesForTesting();
5491 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 6, 5474 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 6,
5492 10); 5475 Layer::INVALID_ID);
5493 host_impl_->active_tree()->DidBecomeActive(); 5476 host_impl_->active_tree()->DidBecomeActive();
5494 5477
5495 // Scrolling should still work even though we did not draw yet. 5478 // Scrolling should still work even though we did not draw yet.
5496 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 5479 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
5497 host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), 5480 host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(),
5498 InputHandler::WHEEL) 5481 InputHandler::WHEEL)
5499 .thread); 5482 .thread);
5500 } 5483 }
5501 5484
5502 TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { 5485 TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) {
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
6328 6311
6329 TEST_F(LayerTreeHostImplTest, OverscrollOnMainThread) { 6312 TEST_F(LayerTreeHostImplTest, OverscrollOnMainThread) {
6330 InputHandlerScrollResult scroll_result; 6313 InputHandlerScrollResult scroll_result;
6331 LayerTreeSettings settings = DefaultSettings(); 6314 LayerTreeSettings settings = DefaultSettings();
6332 CreateHostImpl(settings, CreateCompositorFrameSink()); 6315 CreateHostImpl(settings, CreateCompositorFrameSink());
6333 6316
6334 const gfx::Size content_size(50, 50); 6317 const gfx::Size content_size(50, 50);
6335 const gfx::Size viewport_size(50, 50); 6318 const gfx::Size viewport_size(50, 50);
6336 CreateBasicVirtualViewportLayers(viewport_size, content_size); 6319 CreateBasicVirtualViewportLayers(viewport_size, content_size);
6337 6320
6338 host_impl_->active_tree() 6321 LayerImpl* scroll_layer =
6339 ->InnerViewportScrollLayer() 6322 host_impl_->active_tree()->InnerViewportScrollLayer();
6340 ->set_main_thread_scrolling_reasons( 6323 scroll_layer->set_main_thread_scrolling_reasons(
6341 MainThreadScrollingReason::kThreadedScrollingDisabled); 6324 MainThreadScrollingReason::kThreadedScrollingDisabled);
6342 host_impl_->active_tree()
6343 ->OuterViewportScrollLayer()
6344 ->set_main_thread_scrolling_reasons(
6345 MainThreadScrollingReason::kThreadedScrollingDisabled);
6346
6347 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 6325 host_impl_->active_tree()->BuildPropertyTreesForTesting();
6348 6326
6349 DrawFrame(); 6327 DrawFrame();
6350 6328
6351 // Overscroll initiated outside layers will be handled by the main thread. 6329 // Overscroll initiated outside layers will be handled by the main thread.
6352 EXPECT_EQ(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( 6330 EXPECT_EQ(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint(
6353 gfx::PointF(0, 60))); 6331 gfx::PointF(0, 60)));
6354 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, 6332 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD,
6355 host_impl_ 6333 host_impl_
6356 ->ScrollBegin(BeginState(gfx::Point(0, 60)).get(), 6334 ->ScrollBegin(BeginState(gfx::Point(0, 60)).get(),
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
6491 host_impl_->ScrollBy( 6469 host_impl_->ScrollBy(
6492 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); 6470 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get());
6493 host_impl_->ScrollEnd(EndState().get()); 6471 host_impl_->ScrollEnd(EndState().get());
6494 6472
6495 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), 6473 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f),
6496 outer_scroll_layer->CurrentScrollOffset()); 6474 outer_scroll_layer->CurrentScrollOffset());
6497 EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f), 6475 EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f),
6498 scroll_layer->CurrentScrollOffset()); 6476 scroll_layer->CurrentScrollOffset());
6499 } 6477 }
6500 } 6478 }
6501 // Test that scrolls chain correctly when a child scroller on the page (e.g. a
6502 // scrolling div) is set as the outer viewport but scrolls start from a layer
6503 // that's not a descendant of the outer viewport. This happens in the
6504 // rootScroller proposal.
6505 TEST_F(LayerTreeHostImplTest, RootScrollerScrollNonDescendant) {
6506 const gfx::Size content_size(300, 300);
6507 const gfx::Size viewport_size(300, 300);
6508 6479
6509 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree();
6510
6511 LayerImpl* content_layer =
6512 CreateBasicVirtualViewportLayers(viewport_size, content_size);
6513 LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer();
6514
6515 LayerImpl* outer_scroll_layer = nullptr;
6516 LayerImpl* sibling_scroll_layer = nullptr;
6517
6518 // Initialization: Add a scrolling layer, simulating an ordinary DIV, to be
6519 // set as the outer viewport. Add a sibling scrolling layer that isn't a child
6520 // of the outer viewport scroll layer.
6521 {
6522 std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10);
6523 clip->SetBounds(content_size);
6524 clip->SetPosition(gfx::PointF(100, 100));
6525
6526 std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11);
6527 scroll->SetBounds(gfx::Size(1200, 1200));
6528 scroll->SetScrollClipLayer(clip->id());
6529 scroll->SetDrawsContent(true);
6530
6531 outer_scroll_layer = scroll.get();
6532
6533 clip->test_properties()->AddChild(std::move(scroll));
6534 content_layer->test_properties()->AddChild(std::move(clip));
6535
6536 // Create the non-descendant.
6537 std::unique_ptr<LayerImpl> clip2 = LayerImpl::Create(layer_tree_impl, 14);
6538 clip2->SetBounds(gfx::Size(600, 600));
6539 clip2->SetPosition(gfx::PointF());
6540
6541 std::unique_ptr<LayerImpl> scroll2 = LayerImpl::Create(layer_tree_impl, 15);
6542 scroll2->SetBounds(gfx::Size(1200, 1200));
6543 scroll2->SetScrollClipLayer(clip2->id());
6544 scroll2->SetDrawsContent(true);
6545
6546 sibling_scroll_layer = scroll2.get();
6547
6548 clip2->test_properties()->AddChild(std::move(scroll2));
6549 content_layer->test_properties()->AddChild(std::move(clip2));
6550
6551 layer_tree_impl->SetViewportLayersFromIds(
6552 Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(),
6553 inner_scroll_layer->id(), outer_scroll_layer->id());
6554 layer_tree_impl->BuildPropertyTreesForTesting();
6555
6556 ASSERT_EQ(outer_scroll_layer, layer_tree_impl->OuterViewportScrollLayer());
6557 }
6558
6559 // Scrolls should target the non-descendant scroller. Chaining should not
6560 // propagate to the outer viewport scroll layer.
6561 {
6562 // This should fully scroll the layer.
6563 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(),
6564 InputHandler::TOUCHSCREEN);
6565 host_impl_->ScrollBy(
6566 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(1000.f, 1000.f)).get());
6567 host_impl_->ScrollEnd(EndState().get());
6568
6569 EXPECT_VECTOR_EQ(gfx::Vector2dF(600.f, 600.f),
6570 sibling_scroll_layer->CurrentScrollOffset());
6571 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6572 outer_scroll_layer->CurrentScrollOffset());
6573
6574 // Scrolling now should chain up but, since the outer viewport is a sibling
6575 // rather than an ancestor, we shouldn't chain to it.
6576 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(),
6577 InputHandler::TOUCHSCREEN);
6578 host_impl_->ScrollBy(
6579 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(1000.f, 1000.f)).get());
6580 host_impl_->ScrollEnd(EndState().get());
6581
6582 EXPECT_VECTOR_EQ(gfx::Vector2dF(600.f, 600.f),
6583 sibling_scroll_layer->CurrentScrollOffset());
6584 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6585 outer_scroll_layer->CurrentScrollOffset());
6586 }
6587
6588 float min_page_scale = 1.f, max_page_scale = 4.f;
6589 float page_scale_factor = 1.f;
6590 host_impl_->active_tree()->PushPageScaleFromMainThread(
6591 page_scale_factor, min_page_scale, max_page_scale);
6592
6593 gfx::Vector2dF viewport_size_vec(viewport_size.width(),
6594 viewport_size.height());
6595
6596 // Reset the scroll offset.
6597 sibling_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset());
6598
6599 // Now pinch-zoom in. Anchoring should cause scrolling only on the inner
6600 // viewport layer.
6601 {
6602 // Pinch in to the middle of the screen. The inner viewport should scroll
6603 // to keep the gesture anchored but not the outer or the sibling scroller.
6604 page_scale_factor = 2.f;
6605 gfx::Point anchor(viewport_size.width() / 2, viewport_size.height() / 2);
6606 host_impl_->ScrollBegin(BeginState(anchor).get(),
6607 InputHandler::TOUCHSCREEN);
6608 host_impl_->PinchGestureBegin();
6609 host_impl_->PinchGestureUpdate(page_scale_factor, anchor);
6610 host_impl_->PinchGestureEnd();
6611
6612 EXPECT_VECTOR_EQ(gfx::Vector2dF(anchor.x() / 2, anchor.y() / 2),
6613 inner_scroll_layer->CurrentScrollOffset());
6614
6615 host_impl_->ScrollBy(UpdateState(anchor, viewport_size_vec).get());
6616
6617 EXPECT_VECTOR_EQ(ScaleVector2d(viewport_size_vec, 1.f / page_scale_factor),
6618 inner_scroll_layer->CurrentScrollOffset());
6619 // TODO(bokan): This doesn't yet work but we'll probably want to fix this
6620 // at some point.
6621 // EXPECT_VECTOR_EQ(
6622 // gfx::Vector2dF(),
6623 // outer_scroll_layer->CurrentScrollOffset());
6624 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6625 sibling_scroll_layer->CurrentScrollOffset());
6626
6627 host_impl_->ScrollEnd(EndState().get());
6628 }
6629
6630 // Reset the scroll offsets
6631 sibling_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset());
6632 inner_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset());
6633 outer_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset());
6634
6635 // Scrolls over the sibling while pinched in should scroll the sibling first,
6636 // but then chain up to the inner viewport so that the user can still pan
6637 // around. The outer viewport should be unaffected.
6638 {
6639 // This should fully scroll the sibling but, because we latch to the
6640 // scroller, it shouldn't chain up to the inner viewport yet.
6641 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(),
6642 InputHandler::TOUCHSCREEN);
6643 host_impl_->ScrollBy(
6644 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(2000.f, 2000.f)).get());
6645 host_impl_->ScrollEnd(EndState().get());
6646
6647 EXPECT_VECTOR_EQ(gfx::Vector2dF(600.f, 600.f),
6648 sibling_scroll_layer->CurrentScrollOffset());
6649 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6650 inner_scroll_layer->CurrentScrollOffset());
6651
6652 // Scrolling now should chain up to the inner viewport.
6653 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(),
6654 InputHandler::TOUCHSCREEN);
6655 host_impl_->ScrollBy(
6656 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(2000.f, 2000.f)).get());
6657 host_impl_->ScrollEnd(EndState().get());
6658
6659 EXPECT_VECTOR_EQ(ScaleVector2d(viewport_size_vec, 1 / page_scale_factor),
6660 inner_scroll_layer->CurrentScrollOffset());
6661 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6662 outer_scroll_layer->CurrentScrollOffset());
6663
6664 // No more scrolling should be possible.
6665 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(),
6666 InputHandler::TOUCHSCREEN);
6667 host_impl_->ScrollBy(
6668 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(2000.f, 2000.f)).get());
6669 host_impl_->ScrollEnd(EndState().get());
6670
6671 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6672 outer_scroll_layer->CurrentScrollOffset());
6673 }
6674 }
6675
6676 TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) { 6480 TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) {
6677 InputHandlerScrollResult scroll_result; 6481 InputHandlerScrollResult scroll_result;
6678 LayerTreeSettings settings = DefaultSettings(); 6482 LayerTreeSettings settings = DefaultSettings();
6679 CreateHostImpl(settings, CreateCompositorFrameSink()); 6483 CreateHostImpl(settings, CreateCompositorFrameSink());
6680 6484
6681 const gfx::Size content_size(50, 50); 6485 const gfx::Size content_size(50, 50);
6682 const gfx::Size viewport_size(50, 50); 6486 const gfx::Size viewport_size(50, 50);
6683 CreateBasicVirtualViewportLayers(viewport_size, content_size); 6487 CreateBasicVirtualViewportLayers(viewport_size, content_size);
6684 6488
6685 // By default, no main thread scrolling reasons should exist. 6489 // By default, no main thread scrolling reasons should exist.
(...skipping 1880 matching lines...) Expand 10 before | Expand all | Expand 10 after
8566 scroll_layer->test_properties()->AddChild(std::move(child_scroll)); 8370 scroll_layer->test_properties()->AddChild(std::move(child_scroll));
8567 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 8371 host_impl_->active_tree()->BuildPropertyTreesForTesting();
8568 8372
8569 DrawFrame(); 8373 DrawFrame();
8570 8374
8571 // We should not have scrolled |child_scroll| even though we technically "hit" 8375 // We should not have scrolled |child_scroll| even though we technically "hit"
8572 // it. The reason for this is that if the scrolling the scroll would not move 8376 // it. The reason for this is that if the scrolling the scroll would not move
8573 // any layer that is a drawn RSLL member, then we can ignore the hit. 8377 // any layer that is a drawn RSLL member, then we can ignore the hit.
8574 // 8378 //
8575 // Why SCROLL_STARTED? In this case, it's because we've bubbled out and 8379 // Why SCROLL_STARTED? In this case, it's because we've bubbled out and
8576 // started scrolling the viewport. 8380 // started scrolling the inner viewport.
8577 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 8381 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
8578 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), 8382 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(),
8579 InputHandler::WHEEL) 8383 InputHandler::WHEEL)
8580 .thread); 8384 .thread);
8581 8385
8582 EXPECT_EQ(117, host_impl_->CurrentlyScrollingLayer()->id()); 8386 EXPECT_EQ(2, host_impl_->CurrentlyScrollingLayer()->id());
8583 } 8387 }
8584 8388
8585 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) { 8389 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) {
8586 gfx::Size content_size(100, 100); 8390 gfx::Size content_size(100, 100);
8587 SetupScrollAndContentsLayers(content_size); 8391 SetupScrollAndContentsLayers(content_size);
8588 8392
8589 LayerImpl* root = host_impl_->active_tree()->LayerById(1); 8393 LayerImpl* root = host_impl_->active_tree()->LayerById(1);
8590 LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2); 8394 LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2);
8591 8395
8592 std::unique_ptr<LayerImpl> invisible_scroll_layer = 8396 std::unique_ptr<LayerImpl> invisible_scroll_layer =
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
9552 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); 9356 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset());
9553 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); 9357 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset());
9554 9358
9555 // Scrolling the viewport always sets the outer scroll layer as the 9359 // Scrolling the viewport always sets the outer scroll layer as the
9556 // currently scrolling layer. 9360 // currently scrolling layer.
9557 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9361 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9558 host_impl_ 9362 host_impl_
9559 ->ScrollBegin(BeginState(gfx::Point()).get(), 9363 ->ScrollBegin(BeginState(gfx::Point()).get(),
9560 InputHandler::TOUCHSCREEN) 9364 InputHandler::TOUCHSCREEN)
9561 .thread); 9365 .thread);
9562 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); 9366 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer());
9563 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9367 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9564 host_impl_->FlingScrollBegin().thread); 9368 host_impl_->FlingScrollBegin().thread);
9565 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); 9369 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer());
9566 9370
9567 gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f, 9371 gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f,
9568 inner_viewport.height() / 2.f); 9372 inner_viewport.height() / 2.f);
9569 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 9373 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
9570 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); 9374 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
9571 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); 9375 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer());
9572 9376
9573 host_impl_->ScrollEnd(EndState().get()); 9377 host_impl_->ScrollEnd(EndState().get());
9574 host_impl_->ClearCurrentlyScrollingLayerForTesting(); 9378 host_impl_->ClearCurrentlyScrollingLayerForTesting();
9575 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); 9379 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer());
9576 9380
9577 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); 9381 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset());
9578 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); 9382 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset());
9579 9383
9580 // Fling past the inner viewport boundry, make sure outer viewport scrolls. 9384 // Fling past the inner viewport boundry, make sure outer viewport scrolls.
9581 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9385 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9582 host_impl_ 9386 host_impl_
9583 ->ScrollBegin(BeginState(gfx::Point()).get(), 9387 ->ScrollBegin(BeginState(gfx::Point()).get(),
9584 InputHandler::TOUCHSCREEN) 9388 InputHandler::TOUCHSCREEN)
9585 .thread); 9389 .thread);
9586 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); 9390 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer());
9587 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9391 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9588 host_impl_->FlingScrollBegin().thread); 9392 host_impl_->FlingScrollBegin().thread);
9589 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); 9393 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer());
9590 9394
9591 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 9395 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
9592 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); 9396 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
9593 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); 9397 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer());
9594 9398
9595 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 9399 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
9596 outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); 9400 outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
9597 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); 9401 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer());
9598 9402
9599 host_impl_->ScrollEnd(EndState().get()); 9403 host_impl_->ScrollEnd(EndState().get());
9600 host_impl_->ClearCurrentlyScrollingLayerForTesting(); 9404 host_impl_->ClearCurrentlyScrollingLayerForTesting();
9601 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); 9405 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer());
9602 9406
9603 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); 9407 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset());
9604 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); 9408 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset());
9605 } 9409 }
9606 } 9410 }
9607 9411
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after
11355 ->test_properties() 11159 ->test_properties()
11356 ->children[0]; 11160 ->children[0];
11357 // The scroll done on the active tree is undone on the pending tree. 11161 // The scroll done on the active tree is undone on the pending tree.
11358 gfx::Transform translate; 11162 gfx::Transform translate;
11359 translate.Translate(0, accumulated_scroll); 11163 translate.Translate(0, accumulated_scroll);
11360 content_layer->test_properties()->transform = translate; 11164 content_layer->test_properties()->transform = translate;
11361 11165
11362 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); 11166 LayerTreeImpl* pending_tree = host_impl_->pending_tree();
11363 pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f); 11167 pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
11364 LayerImpl* last_scrolled_layer = pending_tree->LayerById( 11168 LayerImpl* last_scrolled_layer = pending_tree->LayerById(
11365 host_impl_->active_tree()->InnerViewportScrollLayer()->id()); 11169 host_impl_->active_tree()->LastScrolledLayerId());
11366 11170
11367 // When building property trees from impl side, the builder uses the scroll 11171 // When building property trees from impl side, the builder uses the scroll
11368 // offset of layer_impl to initialize the scroll offset in scroll tree: 11172 // offset of layer_impl to initialize the scroll offset in scroll tree:
11369 // scroll_tree.synced_scroll_offset.PushFromMainThread( 11173 // scroll_tree.synced_scroll_offset.PushFromMainThread(
11370 // layer->CurrentScrollOffset()). 11174 // layer->CurrentScrollOffset()).
11371 // However, layer_impl does not store scroll_offset, so it is using scroll 11175 // However, layer_impl does not store scroll_offset, so it is using scroll
11372 // tree's scroll offset to initialize itself. Usually this approach works 11176 // tree's scroll offset to initialize itself. Usually this approach works
11373 // because this is a simple assignment. However if scroll_offset's pending 11177 // because this is a simple assignment. However if scroll_offset's pending
11374 // delta is not zero, the delta would be counted twice. 11178 // delta is not zero, the delta would be counted twice.
11375 // This hacking here is to restore the damaged scroll offset. 11179 // This hacking here is to restore the damaged scroll offset.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
11419 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); 11223 EXPECT_TRUE(host_impl_->use_gpu_rasterization());
11420 11224
11421 // Re-initialize with a software output surface. 11225 // Re-initialize with a software output surface.
11422 compositor_frame_sink_ = FakeCompositorFrameSink::CreateSoftware(); 11226 compositor_frame_sink_ = FakeCompositorFrameSink::CreateSoftware();
11423 host_impl_->InitializeRenderer(compositor_frame_sink_.get()); 11227 host_impl_->InitializeRenderer(compositor_frame_sink_.get());
11424 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); 11228 EXPECT_FALSE(host_impl_->use_gpu_rasterization());
11425 } 11229 }
11426 11230
11427 } // namespace 11231 } // namespace
11428 } // namespace cc 11232 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698