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

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

Issue 2365793002: Fix scroll chaining for non-descendants of root scroller. (Closed)
Patch Set: Rebase and remove hack 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(), inner_scroll); 4158 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), outer_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_->InnerViewportScrollLayer(), 4614 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
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_->InnerViewportScrollLayer(), 4631 EXPECT_EQ(host_impl_->OuterViewportScrollLayer(),
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> root_clip = 5440 std::unique_ptr<LayerImpl> inner_clip =
5441 LayerImpl::Create(host_impl_->active_tree(), 2); 5441 LayerImpl::Create(host_impl_->active_tree(), 2);
5442 std::unique_ptr<LayerImpl> root_scroll = 5442 std::unique_ptr<LayerImpl> inner_scroll =
5443 CreateScrollableLayer(3, surface_size, root_clip.get()); 5443 CreateScrollableLayer(3, surface_size, inner_clip.get());
5444 root_clip->test_properties()->force_render_surface = true; 5444 std::unique_ptr<LayerImpl> outer_clip =
5445 root_scroll->test_properties()->is_container_for_fixed_position_layers = true; 5445 LayerImpl::Create(host_impl_->active_tree(), 7);
5446 root_clip->test_properties()->AddChild(std::move(root_scroll)); 5446 std::unique_ptr<LayerImpl> outer_scroll =
5447 root_ptr->test_properties()->AddChild(std::move(root_clip)); 5447 CreateScrollableLayer(8, surface_size, outer_clip.get());
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));
5448 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); 5457 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr));
5449 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3, 5458 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3,
5450 Layer::INVALID_ID); 5459 8);
5451 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 5460 host_impl_->active_tree()->BuildPropertyTreesForTesting();
5452 host_impl_->active_tree()->DidBecomeActive(); 5461 host_impl_->active_tree()->DidBecomeActive();
5453 5462
5454 host_impl_->SetViewportSize(surface_size); 5463 host_impl_->SetViewportSize(surface_size);
5455 5464
5456 // Draw one frame and then immediately rebuild the layer tree to mimic a tree 5465 // Draw one frame and then immediately rebuild the layer tree to mimic a tree
5457 // synchronization. 5466 // synchronization.
5458 DrawFrame(); 5467 DrawFrame();
5459 5468
5460 host_impl_->active_tree()->DetachLayers(); 5469 host_impl_->active_tree()->DetachLayers();
5461 std::unique_ptr<LayerImpl> root_ptr2 = 5470 std::unique_ptr<LayerImpl> root_ptr2 =
5462 LayerImpl::Create(host_impl_->active_tree(), 4); 5471 LayerImpl::Create(host_impl_->active_tree(), 4);
5463 std::unique_ptr<LayerImpl> root_clip2 = 5472 std::unique_ptr<LayerImpl> inner_clip2 =
5464 LayerImpl::Create(host_impl_->active_tree(), 5); 5473 LayerImpl::Create(host_impl_->active_tree(), 5);
5465 std::unique_ptr<LayerImpl> root_scroll2 = 5474 std::unique_ptr<LayerImpl> inner_scroll2 =
5466 CreateScrollableLayer(6, surface_size, root_clip2.get()); 5475 CreateScrollableLayer(6, surface_size, inner_clip2.get());
5467 root_scroll2->test_properties()->is_container_for_fixed_position_layers = 5476 std::unique_ptr<LayerImpl> outer_clip2 =
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 =
5468 true; 5481 true;
5469 root_clip2->test_properties()->AddChild(std::move(root_scroll2)); 5482 outer_scroll2->test_properties()->is_container_for_fixed_position_layers =
5470 root_clip2->test_properties()->force_render_surface = true; 5483 true;
5471 root_ptr2->test_properties()->AddChild(std::move(root_clip2)); 5484 outer_clip2->test_properties()->AddChild(std::move(outer_scroll2));
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));
5472 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr2)); 5489 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr2));
5473 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 5490 host_impl_->active_tree()->BuildPropertyTreesForTesting();
5474 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 6, 5491 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 6,
5475 Layer::INVALID_ID); 5492 10);
5476 host_impl_->active_tree()->DidBecomeActive(); 5493 host_impl_->active_tree()->DidBecomeActive();
5477 5494
5478 // Scrolling should still work even though we did not draw yet. 5495 // Scrolling should still work even though we did not draw yet.
5479 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 5496 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
5480 host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), 5497 host_impl_->ScrollBegin(BeginState(gfx::Point(5, 5)).get(),
5481 InputHandler::WHEEL) 5498 InputHandler::WHEEL)
5482 .thread); 5499 .thread);
5483 } 5500 }
5484 5501
5485 TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { 5502 TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) {
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
6311 6328
6312 TEST_F(LayerTreeHostImplTest, OverscrollOnMainThread) { 6329 TEST_F(LayerTreeHostImplTest, OverscrollOnMainThread) {
6313 InputHandlerScrollResult scroll_result; 6330 InputHandlerScrollResult scroll_result;
6314 LayerTreeSettings settings = DefaultSettings(); 6331 LayerTreeSettings settings = DefaultSettings();
6315 CreateHostImpl(settings, CreateCompositorFrameSink()); 6332 CreateHostImpl(settings, CreateCompositorFrameSink());
6316 6333
6317 const gfx::Size content_size(50, 50); 6334 const gfx::Size content_size(50, 50);
6318 const gfx::Size viewport_size(50, 50); 6335 const gfx::Size viewport_size(50, 50);
6319 CreateBasicVirtualViewportLayers(viewport_size, content_size); 6336 CreateBasicVirtualViewportLayers(viewport_size, content_size);
6320 6337
6321 LayerImpl* scroll_layer = 6338 host_impl_->active_tree()
6322 host_impl_->active_tree()->InnerViewportScrollLayer(); 6339 ->InnerViewportScrollLayer()
6323 scroll_layer->set_main_thread_scrolling_reasons( 6340 ->set_main_thread_scrolling_reasons(
6324 MainThreadScrollingReason::kThreadedScrollingDisabled); 6341 MainThreadScrollingReason::kThreadedScrollingDisabled);
6342 host_impl_->active_tree()
6343 ->OuterViewportScrollLayer()
6344 ->set_main_thread_scrolling_reasons(
6345 MainThreadScrollingReason::kThreadedScrollingDisabled);
6346
6325 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 6347 host_impl_->active_tree()->BuildPropertyTreesForTesting();
6326 6348
6327 DrawFrame(); 6349 DrawFrame();
6328 6350
6329 // Overscroll initiated outside layers will be handled by the main thread. 6351 // Overscroll initiated outside layers will be handled by the main thread.
6330 EXPECT_EQ(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint( 6352 EXPECT_EQ(nullptr, host_impl_->active_tree()->FindLayerThatIsHitByPoint(
6331 gfx::PointF(0, 60))); 6353 gfx::PointF(0, 60)));
6332 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, 6354 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD,
6333 host_impl_ 6355 host_impl_
6334 ->ScrollBegin(BeginState(gfx::Point(0, 60)).get(), 6356 ->ScrollBegin(BeginState(gfx::Point(0, 60)).get(),
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
6469 host_impl_->ScrollBy( 6491 host_impl_->ScrollBy(
6470 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get()); 6492 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(100.f, 100.f)).get());
6471 host_impl_->ScrollEnd(EndState().get()); 6493 host_impl_->ScrollEnd(EndState().get());
6472 6494
6473 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), 6495 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f),
6474 outer_scroll_layer->CurrentScrollOffset()); 6496 outer_scroll_layer->CurrentScrollOffset());
6475 EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f), 6497 EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f),
6476 scroll_layer->CurrentScrollOffset()); 6498 scroll_layer->CurrentScrollOffset());
6477 } 6499 }
6478 } 6500 }
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
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 }
6479 6675
6480 TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) { 6676 TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) {
6481 InputHandlerScrollResult scroll_result; 6677 InputHandlerScrollResult scroll_result;
6482 LayerTreeSettings settings = DefaultSettings(); 6678 LayerTreeSettings settings = DefaultSettings();
6483 CreateHostImpl(settings, CreateCompositorFrameSink()); 6679 CreateHostImpl(settings, CreateCompositorFrameSink());
6484 6680
6485 const gfx::Size content_size(50, 50); 6681 const gfx::Size content_size(50, 50);
6486 const gfx::Size viewport_size(50, 50); 6682 const gfx::Size viewport_size(50, 50);
6487 CreateBasicVirtualViewportLayers(viewport_size, content_size); 6683 CreateBasicVirtualViewportLayers(viewport_size, content_size);
6488 6684
(...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after
8370 scroll_layer->test_properties()->AddChild(std::move(child_scroll)); 8566 scroll_layer->test_properties()->AddChild(std::move(child_scroll));
8371 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 8567 host_impl_->active_tree()->BuildPropertyTreesForTesting();
8372 8568
8373 DrawFrame(); 8569 DrawFrame();
8374 8570
8375 // We should not have scrolled |child_scroll| even though we technically "hit" 8571 // We should not have scrolled |child_scroll| even though we technically "hit"
8376 // it. The reason for this is that if the scrolling the scroll would not move 8572 // it. The reason for this is that if the scrolling the scroll would not move
8377 // any layer that is a drawn RSLL member, then we can ignore the hit. 8573 // any layer that is a drawn RSLL member, then we can ignore the hit.
8378 // 8574 //
8379 // Why SCROLL_STARTED? In this case, it's because we've bubbled out and 8575 // Why SCROLL_STARTED? In this case, it's because we've bubbled out and
8380 // started scrolling the inner viewport. 8576 // started scrolling the viewport.
8381 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 8577 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
8382 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), 8578 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(),
8383 InputHandler::WHEEL) 8579 InputHandler::WHEEL)
8384 .thread); 8580 .thread);
8385 8581
8386 EXPECT_EQ(2, host_impl_->CurrentlyScrollingLayer()->id()); 8582 EXPECT_EQ(117, host_impl_->CurrentlyScrollingLayer()->id());
8387 } 8583 }
8388 8584
8389 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) { 8585 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) {
8390 gfx::Size content_size(100, 100); 8586 gfx::Size content_size(100, 100);
8391 SetupScrollAndContentsLayers(content_size); 8587 SetupScrollAndContentsLayers(content_size);
8392 8588
8393 LayerImpl* root = host_impl_->active_tree()->LayerById(1); 8589 LayerImpl* root = host_impl_->active_tree()->LayerById(1);
8394 LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2); 8590 LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2);
8395 8591
8396 std::unique_ptr<LayerImpl> invisible_scroll_layer = 8592 std::unique_ptr<LayerImpl> invisible_scroll_layer =
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
9356 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); 9552 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset());
9357 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); 9553 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset());
9358 9554
9359 // Scrolling the viewport always sets the outer scroll layer as the 9555 // Scrolling the viewport always sets the outer scroll layer as the
9360 // currently scrolling layer. 9556 // currently scrolling layer.
9361 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9557 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9362 host_impl_ 9558 host_impl_
9363 ->ScrollBegin(BeginState(gfx::Point()).get(), 9559 ->ScrollBegin(BeginState(gfx::Point()).get(),
9364 InputHandler::TOUCHSCREEN) 9560 InputHandler::TOUCHSCREEN)
9365 .thread); 9561 .thread);
9366 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9562 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9367 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9563 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9368 host_impl_->FlingScrollBegin().thread); 9564 host_impl_->FlingScrollBegin().thread);
9369 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9565 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9370 9566
9371 gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f, 9567 gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f,
9372 inner_viewport.height() / 2.f); 9568 inner_viewport.height() / 2.f);
9373 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 9569 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
9374 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); 9570 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
9375 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9571 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9376 9572
9377 host_impl_->ScrollEnd(EndState().get()); 9573 host_impl_->ScrollEnd(EndState().get());
9378 host_impl_->ClearCurrentlyScrollingLayerForTesting(); 9574 host_impl_->ClearCurrentlyScrollingLayerForTesting();
9379 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); 9575 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer());
9380 9576
9381 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); 9577 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset());
9382 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); 9578 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset());
9383 9579
9384 // Fling past the inner viewport boundry, make sure outer viewport scrolls. 9580 // Fling past the inner viewport boundry, make sure outer viewport scrolls.
9385 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9581 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9386 host_impl_ 9582 host_impl_
9387 ->ScrollBegin(BeginState(gfx::Point()).get(), 9583 ->ScrollBegin(BeginState(gfx::Point()).get(),
9388 InputHandler::TOUCHSCREEN) 9584 InputHandler::TOUCHSCREEN)
9389 .thread); 9585 .thread);
9390 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9586 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9391 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9587 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9392 host_impl_->FlingScrollBegin().thread); 9588 host_impl_->FlingScrollBegin().thread);
9393 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9589 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9394 9590
9395 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 9591 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
9396 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); 9592 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
9397 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9593 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9398 9594
9399 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 9595 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
9400 outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); 9596 outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
9401 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9597 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9402 9598
9403 host_impl_->ScrollEnd(EndState().get()); 9599 host_impl_->ScrollEnd(EndState().get());
9404 host_impl_->ClearCurrentlyScrollingLayerForTesting(); 9600 host_impl_->ClearCurrentlyScrollingLayerForTesting();
9405 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); 9601 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer());
9406 9602
9407 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); 9603 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset());
9408 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); 9604 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset());
9409 } 9605 }
9410 } 9606 }
9411 9607
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
9540 9736
9541 TEST_F(LayerTreeHostImplVirtualViewportTest, 9737 TEST_F(LayerTreeHostImplVirtualViewportTest,
9542 ScrollBeginEventThatTargetsViewportLayerSkipsHitTest) { 9738 ScrollBeginEventThatTargetsViewportLayerSkipsHitTest) {
9543 gfx::Size content_size = gfx::Size(100, 160); 9739 gfx::Size content_size = gfx::Size(100, 160);
9544 gfx::Size outer_viewport = gfx::Size(50, 80); 9740 gfx::Size outer_viewport = gfx::Size(50, 80);
9545 gfx::Size inner_viewport = gfx::Size(25, 40); 9741 gfx::Size inner_viewport = gfx::Size(25, 40);
9546 9742
9547 SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); 9743 SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport);
9548 9744
9549 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); 9745 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer();
9550 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer();
9551 9746
9552 std::unique_ptr<LayerImpl> child = 9747 std::unique_ptr<LayerImpl> child =
9553 CreateScrollableLayer(10, outer_viewport, outer_scroll); 9748 CreateScrollableLayer(10, outer_viewport, outer_scroll);
9554 LayerImpl* child_scroll = child.get(); 9749 LayerImpl* child_scroll = child.get();
9555 outer_scroll->test_properties()->children[0]->test_properties()->AddChild( 9750 outer_scroll->test_properties()->children[0]->test_properties()->AddChild(
9556 std::move(child)); 9751 std::move(child));
9557 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 9752 host_impl_->active_tree()->BuildPropertyTreesForTesting();
9558 9753
9559 DrawFrame(); 9754 DrawFrame();
9560 9755
9561 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9756 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9562 host_impl_ 9757 host_impl_
9563 ->RootScrollBegin(BeginState(gfx::Point()).get(), 9758 ->RootScrollBegin(BeginState(gfx::Point()).get(),
9564 InputHandler::TOUCHSCREEN) 9759 InputHandler::TOUCHSCREEN)
9565 .thread); 9760 .thread);
9566 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); 9761 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(),
9762 host_impl_->ViewportMainScrollLayer());
9567 host_impl_->ScrollEnd(EndState().get()); 9763 host_impl_->ScrollEnd(EndState().get());
9568 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9764 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9569 host_impl_ 9765 host_impl_
9570 ->ScrollBegin(BeginState(gfx::Point()).get(), 9766 ->ScrollBegin(BeginState(gfx::Point()).get(),
9571 InputHandler::TOUCHSCREEN) 9767 InputHandler::TOUCHSCREEN)
9572 .thread); 9768 .thread);
9573 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll); 9769 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_scroll);
9574 host_impl_->ScrollEnd(EndState().get()); 9770 host_impl_->ScrollEnd(EndState().get());
9575 } 9771 }
9576 9772
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after
11146 ->test_properties() 11342 ->test_properties()
11147 ->children[0]; 11343 ->children[0];
11148 // The scroll done on the active tree is undone on the pending tree. 11344 // The scroll done on the active tree is undone on the pending tree.
11149 gfx::Transform translate; 11345 gfx::Transform translate;
11150 translate.Translate(0, accumulated_scroll); 11346 translate.Translate(0, accumulated_scroll);
11151 content_layer->test_properties()->transform = translate; 11347 content_layer->test_properties()->transform = translate;
11152 11348
11153 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); 11349 LayerTreeImpl* pending_tree = host_impl_->pending_tree();
11154 pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f); 11350 pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
11155 LayerImpl* last_scrolled_layer = pending_tree->LayerById( 11351 LayerImpl* last_scrolled_layer = pending_tree->LayerById(
11156 host_impl_->active_tree()->LastScrolledLayerId()); 11352 host_impl_->active_tree()->InnerViewportScrollLayer()->id());
11157 11353
11158 // When building property trees from impl side, the builder uses the scroll 11354 // When building property trees from impl side, the builder uses the scroll
11159 // offset of layer_impl to initialize the scroll offset in scroll tree: 11355 // offset of layer_impl to initialize the scroll offset in scroll tree:
11160 // scroll_tree.synced_scroll_offset.PushFromMainThread( 11356 // scroll_tree.synced_scroll_offset.PushFromMainThread(
11161 // layer->CurrentScrollOffset()). 11357 // layer->CurrentScrollOffset()).
11162 // However, layer_impl does not store scroll_offset, so it is using scroll 11358 // However, layer_impl does not store scroll_offset, so it is using scroll
11163 // tree's scroll offset to initialize itself. Usually this approach works 11359 // tree's scroll offset to initialize itself. Usually this approach works
11164 // because this is a simple assignment. However if scroll_offset's pending 11360 // because this is a simple assignment. However if scroll_offset's pending
11165 // delta is not zero, the delta would be counted twice. 11361 // delta is not zero, the delta would be counted twice.
11166 // This hacking here is to restore the damaged scroll offset. 11362 // This hacking here is to restore the damaged scroll offset.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
11210 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); 11406 EXPECT_TRUE(host_impl_->use_gpu_rasterization());
11211 11407
11212 // Re-initialize with a software output surface. 11408 // Re-initialize with a software output surface.
11213 compositor_frame_sink_ = FakeCompositorFrameSink::CreateSoftware(); 11409 compositor_frame_sink_ = FakeCompositorFrameSink::CreateSoftware();
11214 host_impl_->InitializeRenderer(compositor_frame_sink_.get()); 11410 host_impl_->InitializeRenderer(compositor_frame_sink_.get());
11215 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); 11411 EXPECT_FALSE(host_impl_->use_gpu_rasterization());
11216 } 11412 }
11217 11413
11218 } // namespace 11414 } // namespace
11219 } // namespace cc 11415 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698