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

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: Fix tests Created 4 years, 3 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 1827 matching lines...) Expand 10 before | Expand all | Expand 10 after
6469 host_impl_->ScrollBy( 6469 host_impl_->ScrollBy(
6470 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());
6471 host_impl_->ScrollEnd(EndState().get()); 6471 host_impl_->ScrollEnd(EndState().get());
6472 6472
6473 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), 6473 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f),
6474 outer_scroll_layer->CurrentScrollOffset()); 6474 outer_scroll_layer->CurrentScrollOffset());
6475 EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f), 6475 EXPECT_VECTOR_EQ(gfx::Vector2dF(50.f, 50.f),
6476 scroll_layer->CurrentScrollOffset()); 6476 scroll_layer->CurrentScrollOffset());
6477 } 6477 }
6478 } 6478 }
6479 // Test that scrolls chain correctly when a child scroller on the page (e.g. a
6480 // scrolling div) is set as the outer viewport but scrolls start from a layer
6481 // that's not a descendant of the outer viewport. This happens in the
6482 // rootScroller proposal.
6483 TEST_F(LayerTreeHostImplTest, RootScrollerScrollNonDescendant) {
6484 const gfx::Size content_size(300, 300);
6485 const gfx::Size viewport_size(300, 300);
6486
6487 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree();
6488
6489 LayerImpl* content_layer =
6490 CreateBasicVirtualViewportLayers(viewport_size, content_size);
6491 LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer();
6492
6493 LayerImpl* outer_scroll_layer = nullptr;
6494 LayerImpl* sibling_scroll_layer = nullptr;
6495
6496 // Initialization: Add a scrolling layer, simulating an ordinary DIV, to be
6497 // set as the outer viewport. Add a sibling scrolling layer that isn't a child
6498 // of the outer viewport scroll layer.
6499 {
6500 std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10);
6501 clip->SetBounds(content_size);
6502 clip->SetPosition(gfx::PointF(100, 100));
6503
6504 std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11);
6505 scroll->SetBounds(gfx::Size(1200, 1200));
6506 scroll->SetScrollClipLayer(clip->id());
6507 scroll->SetDrawsContent(true);
6508
6509 outer_scroll_layer = scroll.get();
tdresser 2016/09/23 15:59:58 Having a raw pointer point to something owned by a
bokan 2016/09/23 19:57:01 It's because we std::move them into the layer tree
tdresser 2016/09/23 20:40:30 D'oh, sure, that's fine.
6510
6511 clip->test_properties()->AddChild(std::move(scroll));
6512 content_layer->test_properties()->AddChild(std::move(clip));
6513
6514 // Create the non-descendant.
6515 std::unique_ptr<LayerImpl> clip2 = LayerImpl::Create(layer_tree_impl, 14);
6516 clip2->SetBounds(gfx::Size(600, 600));
6517 clip2->SetPosition(gfx::PointF());
6518
6519 std::unique_ptr<LayerImpl> scroll2 = LayerImpl::Create(layer_tree_impl, 15);
6520 scroll2->SetBounds(gfx::Size(1200, 1200));
6521 scroll2->SetScrollClipLayer(clip2->id());
6522 scroll2->SetDrawsContent(true);
6523
6524 sibling_scroll_layer = scroll2.get();
6525
6526 clip2->test_properties()->AddChild(std::move(scroll2));
6527 content_layer->test_properties()->AddChild(std::move(clip2));
6528
6529 layer_tree_impl->SetViewportLayersFromIds(
6530 Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(),
6531 inner_scroll_layer->id(), outer_scroll_layer->id());
6532 layer_tree_impl->BuildPropertyTreesForTesting();
6533
6534 ASSERT_EQ(outer_scroll_layer, layer_tree_impl->OuterViewportScrollLayer());
6535 }
6536
6537 // Scrolls should target the non-descendant scroller. Chaining should not
6538 // propagate to the outer viewport scroll layer.
6539 {
6540 // This should fully scroll the layer.
6541 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(),
6542 InputHandler::TOUCHSCREEN);
6543 host_impl_->ScrollBy(
6544 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(1000.f, 1000.f)).get());
6545 host_impl_->ScrollEnd(EndState().get());
6546
6547 EXPECT_VECTOR_EQ(gfx::Vector2dF(600.f, 600.f),
6548 sibling_scroll_layer->CurrentScrollOffset());
6549 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6550 outer_scroll_layer->CurrentScrollOffset());
tdresser 2016/09/23 15:59:58 Shouldn't outer_scroll_layer be deleted by the tim
bokan 2016/09/23 19:57:01 The unique_ptr's are std::moved into the layer tre
6551
6552 // Scrolling now should chain up but, since the outer viewport is a sibling
6553 // rather than an ancestor, we shouldn't chain to it.
6554 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(),
6555 InputHandler::TOUCHSCREEN);
6556 host_impl_->ScrollBy(
6557 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(1000.f, 1000.f)).get());
6558 host_impl_->ScrollEnd(EndState().get());
6559
6560 EXPECT_VECTOR_EQ(gfx::Vector2dF(600.f, 600.f),
6561 sibling_scroll_layer->CurrentScrollOffset());
6562 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6563 outer_scroll_layer->CurrentScrollOffset());
6564 }
6565
6566 float min_page_scale = 1.f, max_page_scale = 4.f;
6567 float page_scale_factor = 1.f;
6568 host_impl_->active_tree()->PushPageScaleFromMainThread(
6569 page_scale_factor, min_page_scale, max_page_scale);
6570
6571 gfx::Vector2dF viewport_size_vec(viewport_size.width(),
6572 viewport_size.height());
6573
6574 // Reset the scroll offset.
6575 sibling_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset());
6576
6577 // Now pinch-zoom in. Anchoring should cause scrolling only on the inner
6578 // viewport layer.
6579 {
6580 // Pinch in to the middle of the screen. The inner viewport should scroll
6581 // to keep the gesture anchored but not the outer or the sibling scroller.
6582 page_scale_factor = 2.f;
6583 gfx::Point anchor(viewport_size.width() / 2, viewport_size.height() / 2);
6584 host_impl_->ScrollBegin(BeginState(anchor).get(),
6585 InputHandler::TOUCHSCREEN);
6586 host_impl_->PinchGestureBegin();
6587 host_impl_->PinchGestureUpdate(page_scale_factor, anchor);
6588 host_impl_->PinchGestureEnd();
6589
6590 EXPECT_VECTOR_EQ(gfx::Vector2dF(anchor.x() / 2, anchor.y() / 2),
6591 inner_scroll_layer->CurrentScrollOffset());
6592
6593 host_impl_->ScrollBy(UpdateState(anchor, viewport_size_vec).get());
6594
6595 EXPECT_VECTOR_EQ(ScaleVector2d(viewport_size_vec, 1.f / page_scale_factor),
6596 inner_scroll_layer->CurrentScrollOffset());
6597 // TODO(bokan): This doesn't yet work but we'll probably want to fix this
6598 // at some point.
6599 // EXPECT_VECTOR_EQ(
6600 // gfx::Vector2dF(),
6601 // outer_scroll_layer->CurrentScrollOffset());
6602 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6603 sibling_scroll_layer->CurrentScrollOffset());
6604
6605 host_impl_->ScrollEnd(EndState().get());
6606 }
6607
6608 // Reset the scroll offsets
6609 sibling_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset());
6610 inner_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset());
6611 outer_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset());
6612
6613 // Scrolls over the sibling while pinched in should scroll the sibling first,
6614 // but then chain up to the inner viewport so that the user can still pan
6615 // around. The outer viewport should be unaffected.
6616 {
6617 // This should fully scroll the sibling but, because we latch to the
6618 // scroller, it shouldn't chain up to the inner viewport yet.
6619 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(),
6620 InputHandler::TOUCHSCREEN);
6621 host_impl_->ScrollBy(
6622 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(2000.f, 2000.f)).get());
6623 host_impl_->ScrollEnd(EndState().get());
6624
6625 EXPECT_VECTOR_EQ(gfx::Vector2dF(600.f, 600.f),
6626 sibling_scroll_layer->CurrentScrollOffset());
6627 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6628 inner_scroll_layer->CurrentScrollOffset());
6629
6630 // Scrolling now should chain up to the inner viewport.
6631 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(),
6632 InputHandler::TOUCHSCREEN);
6633 host_impl_->ScrollBy(
6634 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(2000.f, 2000.f)).get());
6635 host_impl_->ScrollEnd(EndState().get());
6636
6637 EXPECT_VECTOR_EQ(ScaleVector2d(viewport_size_vec, 1 / page_scale_factor),
6638 inner_scroll_layer->CurrentScrollOffset());
6639 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6640 outer_scroll_layer->CurrentScrollOffset());
6641
6642 // No more scrolling should be possible.
6643 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(),
6644 InputHandler::TOUCHSCREEN);
6645 host_impl_->ScrollBy(
6646 UpdateState(gfx::Point(0, 0), gfx::Vector2dF(2000.f, 2000.f)).get());
6647 host_impl_->ScrollEnd(EndState().get());
6648
6649 EXPECT_VECTOR_EQ(gfx::Vector2dF(),
6650 outer_scroll_layer->CurrentScrollOffset());
6651 }
6652 }
6479 6653
6480 TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) { 6654 TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) {
6481 InputHandlerScrollResult scroll_result; 6655 InputHandlerScrollResult scroll_result;
6482 LayerTreeSettings settings = DefaultSettings(); 6656 LayerTreeSettings settings = DefaultSettings();
6483 CreateHostImpl(settings, CreateCompositorFrameSink()); 6657 CreateHostImpl(settings, CreateCompositorFrameSink());
6484 6658
6485 const gfx::Size content_size(50, 50); 6659 const gfx::Size content_size(50, 50);
6486 const gfx::Size viewport_size(50, 50); 6660 const gfx::Size viewport_size(50, 50);
6487 CreateBasicVirtualViewportLayers(viewport_size, content_size); 6661 CreateBasicVirtualViewportLayers(viewport_size, content_size);
6488 6662
(...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after
8370 scroll_layer->test_properties()->AddChild(std::move(child_scroll)); 8544 scroll_layer->test_properties()->AddChild(std::move(child_scroll));
8371 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 8545 host_impl_->active_tree()->BuildPropertyTreesForTesting();
8372 8546
8373 DrawFrame(); 8547 DrawFrame();
8374 8548
8375 // We should not have scrolled |child_scroll| even though we technically "hit" 8549 // 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 8550 // 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. 8551 // any layer that is a drawn RSLL member, then we can ignore the hit.
8378 // 8552 //
8379 // Why SCROLL_STARTED? In this case, it's because we've bubbled out and 8553 // Why SCROLL_STARTED? In this case, it's because we've bubbled out and
8380 // started scrolling the inner viewport. 8554 // started scrolling the viewport.
8381 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 8555 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
8382 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), 8556 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(),
8383 InputHandler::WHEEL) 8557 InputHandler::WHEEL)
8384 .thread); 8558 .thread);
8385 8559
8386 EXPECT_EQ(2, host_impl_->CurrentlyScrollingLayer()->id()); 8560 EXPECT_EQ(117, host_impl_->CurrentlyScrollingLayer()->id());
8387 } 8561 }
8388 8562
8389 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) { 8563 TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) {
8390 gfx::Size content_size(100, 100); 8564 gfx::Size content_size(100, 100);
8391 SetupScrollAndContentsLayers(content_size); 8565 SetupScrollAndContentsLayers(content_size);
8392 8566
8393 LayerImpl* root = host_impl_->active_tree()->LayerById(1); 8567 LayerImpl* root = host_impl_->active_tree()->LayerById(1);
8394 LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2); 8568 LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2);
8395 8569
8396 std::unique_ptr<LayerImpl> invisible_scroll_layer = 8570 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()); 9530 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset());
9357 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); 9531 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset());
9358 9532
9359 // Scrolling the viewport always sets the outer scroll layer as the 9533 // Scrolling the viewport always sets the outer scroll layer as the
9360 // currently scrolling layer. 9534 // currently scrolling layer.
9361 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9535 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9362 host_impl_ 9536 host_impl_
9363 ->ScrollBegin(BeginState(gfx::Point()).get(), 9537 ->ScrollBegin(BeginState(gfx::Point()).get(),
9364 InputHandler::TOUCHSCREEN) 9538 InputHandler::TOUCHSCREEN)
9365 .thread); 9539 .thread);
9366 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9540 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9367 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9541 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9368 host_impl_->FlingScrollBegin().thread); 9542 host_impl_->FlingScrollBegin().thread);
9369 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9543 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9370 9544
9371 gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f, 9545 gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f,
9372 inner_viewport.height() / 2.f); 9546 inner_viewport.height() / 2.f);
9373 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 9547 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
9374 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); 9548 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
9375 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9549 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9376 9550
9377 host_impl_->ScrollEnd(EndState().get()); 9551 host_impl_->ScrollEnd(EndState().get());
9378 host_impl_->ClearCurrentlyScrollingLayerForTesting(); 9552 host_impl_->ClearCurrentlyScrollingLayerForTesting();
9379 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); 9553 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer());
9380 9554
9381 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); 9555 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset());
9382 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); 9556 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset());
9383 9557
9384 // Fling past the inner viewport boundry, make sure outer viewport scrolls. 9558 // Fling past the inner viewport boundry, make sure outer viewport scrolls.
9385 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9559 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9386 host_impl_ 9560 host_impl_
9387 ->ScrollBegin(BeginState(gfx::Point()).get(), 9561 ->ScrollBegin(BeginState(gfx::Point()).get(),
9388 InputHandler::TOUCHSCREEN) 9562 InputHandler::TOUCHSCREEN)
9389 .thread); 9563 .thread);
9390 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9564 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9391 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, 9565 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD,
9392 host_impl_->FlingScrollBegin().thread); 9566 host_impl_->FlingScrollBegin().thread);
9393 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9567 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9394 9568
9395 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 9569 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
9396 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); 9570 inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
9397 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9571 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9398 9572
9399 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); 9573 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get());
9400 outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); 9574 outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y());
9401 EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); 9575 EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer());
9402 9576
9403 host_impl_->ScrollEnd(EndState().get()); 9577 host_impl_->ScrollEnd(EndState().get());
9404 host_impl_->ClearCurrentlyScrollingLayerForTesting(); 9578 host_impl_->ClearCurrentlyScrollingLayerForTesting();
9405 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); 9579 EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer());
9406 9580
9407 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset()); 9581 EXPECT_VECTOR_EQ(inner_expected, inner_scroll->CurrentScrollOffset());
9408 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset()); 9582 EXPECT_VECTOR_EQ(outer_expected, outer_scroll->CurrentScrollOffset());
9409 } 9583 }
9410 } 9584 }
9411 9585
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after
11159 ->test_properties() 11333 ->test_properties()
11160 ->children[0]; 11334 ->children[0];
11161 // The scroll done on the active tree is undone on the pending tree. 11335 // The scroll done on the active tree is undone on the pending tree.
11162 gfx::Transform translate; 11336 gfx::Transform translate;
11163 translate.Translate(0, accumulated_scroll); 11337 translate.Translate(0, accumulated_scroll);
11164 content_layer->test_properties()->transform = translate; 11338 content_layer->test_properties()->transform = translate;
11165 11339
11166 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); 11340 LayerTreeImpl* pending_tree = host_impl_->pending_tree();
11167 pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f); 11341 pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
11168 LayerImpl* last_scrolled_layer = pending_tree->LayerById( 11342 LayerImpl* last_scrolled_layer = pending_tree->LayerById(
11169 host_impl_->active_tree()->LastScrolledLayerId()); 11343 host_impl_->active_tree()->InnerViewportScrollLayer()->id());
bokan 2016/09/23 01:53:55 The LastScrolledLayerId is set using SetCurrentlyS
tdresser 2016/09/23 15:59:58 This seems a bit scary – it should be a pretty sim
bokan 2016/09/23 19:57:01 It's not as straightforward as it seems. This curr
11170 11344
11171 // When building property trees from impl side, the builder uses the scroll 11345 // When building property trees from impl side, the builder uses the scroll
11172 // offset of layer_impl to initialize the scroll offset in scroll tree: 11346 // offset of layer_impl to initialize the scroll offset in scroll tree:
11173 // scroll_tree.synced_scroll_offset.PushFromMainThread( 11347 // scroll_tree.synced_scroll_offset.PushFromMainThread(
11174 // layer->CurrentScrollOffset()). 11348 // layer->CurrentScrollOffset()).
11175 // However, layer_impl does not store scroll_offset, so it is using scroll 11349 // However, layer_impl does not store scroll_offset, so it is using scroll
11176 // tree's scroll offset to initialize itself. Usually this approach works 11350 // tree's scroll offset to initialize itself. Usually this approach works
11177 // because this is a simple assignment. However if scroll_offset's pending 11351 // because this is a simple assignment. However if scroll_offset's pending
11178 // delta is not zero, the delta would be counted twice. 11352 // delta is not zero, the delta would be counted twice.
11179 // This hacking here is to restore the damaged scroll offset. 11353 // This hacking here is to restore the damaged scroll offset.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
11223 EXPECT_TRUE(host_impl_->use_gpu_rasterization()); 11397 EXPECT_TRUE(host_impl_->use_gpu_rasterization());
11224 11398
11225 // Re-initialize with a software output surface. 11399 // Re-initialize with a software output surface.
11226 compositor_frame_sink_ = FakeCompositorFrameSink::CreateSoftware(); 11400 compositor_frame_sink_ = FakeCompositorFrameSink::CreateSoftware();
11227 host_impl_->InitializeRenderer(compositor_frame_sink_.get()); 11401 host_impl_->InitializeRenderer(compositor_frame_sink_.get());
11228 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); 11402 EXPECT_FALSE(host_impl_->use_gpu_rasterization());
11229 } 11403 }
11230 11404
11231 } // namespace 11405 } // namespace
11232 } // namespace cc 11406 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698