OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 if (scroll_info.scrolls[i].layer_id != id) | 199 if (scroll_info.scrolls[i].layer_id != id) |
200 continue; | 200 continue; |
201 times_encountered++; | 201 times_encountered++; |
202 } | 202 } |
203 | 203 |
204 ASSERT_EQ(0, times_encountered); | 204 ASSERT_EQ(0, times_encountered); |
205 } | 205 } |
206 | 206 |
207 LayerImpl* CreateScrollAndContentsLayers(LayerTreeImpl* layer_tree_impl, | 207 LayerImpl* CreateScrollAndContentsLayers(LayerTreeImpl* layer_tree_impl, |
208 gfx::Size content_size) { | 208 gfx::Size content_size) { |
| 209 const int INNER_VIEWPORT_SCROLL_LAYER_ID = 2; |
| 210 const int INNER_VIEWPORT_CLIP_LAYER_ID = 4; |
| 211 const int PAGE_SCALE_ID = 5; |
209 scoped_ptr<LayerImpl> root = | 212 scoped_ptr<LayerImpl> root = |
210 LayerImpl::Create(layer_tree_impl, 1); | 213 LayerImpl::Create(layer_tree_impl, 1); |
211 root->SetBounds(content_size); | 214 root->SetBounds(content_size); |
212 root->SetContentBounds(content_size); | 215 root->SetContentBounds(content_size); |
213 root->SetPosition(gfx::PointF()); | 216 root->SetPosition(gfx::PointF()); |
214 root->SetAnchorPoint(gfx::PointF()); | 217 root->SetAnchorPoint(gfx::PointF()); |
215 | 218 |
216 scoped_ptr<LayerImpl> scroll = | 219 scoped_ptr<LayerImpl> scroll = |
217 LayerImpl::Create(layer_tree_impl, 2); | 220 LayerImpl::Create(layer_tree_impl, INNER_VIEWPORT_SCROLL_LAYER_ID); |
218 LayerImpl* scroll_layer = scroll.get(); | 221 LayerImpl* scroll_layer = scroll.get(); |
219 scroll->SetScrollable(true); | |
220 scroll->SetScrollOffset(gfx::Vector2d()); | 222 scroll->SetScrollOffset(gfx::Vector2d()); |
221 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | 223 |
222 content_size.height())); | 224 scoped_ptr<LayerImpl> clip = |
| 225 LayerImpl::Create(layer_tree_impl, INNER_VIEWPORT_CLIP_LAYER_ID); |
| 226 // TODO(wjmaclean) Check that this new value of MaxScrollOffset doesn't |
| 227 // throw off the rest of the tests. |
| 228 clip->SetBounds( |
| 229 gfx::Size(content_size.width() / 2, content_size.height() / 2)); |
| 230 |
| 231 scoped_ptr<LayerImpl> page_scale = |
| 232 LayerImpl::Create(layer_tree_impl, PAGE_SCALE_ID); |
| 233 |
| 234 scroll->SetScrollable(clip->id()); |
223 scroll->SetBounds(content_size); | 235 scroll->SetBounds(content_size); |
224 scroll->SetContentBounds(content_size); | 236 scroll->SetContentBounds(content_size); |
225 scroll->SetPosition(gfx::PointF()); | 237 scroll->SetPosition(gfx::PointF()); |
226 scroll->SetAnchorPoint(gfx::PointF()); | 238 scroll->SetAnchorPoint(gfx::PointF()); |
227 | 239 |
228 scoped_ptr<LayerImpl> contents = | 240 scoped_ptr<LayerImpl> contents = |
229 LayerImpl::Create(layer_tree_impl, 3); | 241 LayerImpl::Create(layer_tree_impl, 3); |
230 contents->SetDrawsContent(true); | 242 contents->SetDrawsContent(true); |
231 contents->SetBounds(content_size); | 243 contents->SetBounds(content_size); |
232 contents->SetContentBounds(content_size); | 244 contents->SetContentBounds(content_size); |
233 contents->SetPosition(gfx::PointF()); | 245 contents->SetPosition(gfx::PointF()); |
234 contents->SetAnchorPoint(gfx::PointF()); | 246 contents->SetAnchorPoint(gfx::PointF()); |
235 | 247 |
236 scroll->AddChild(contents.Pass()); | 248 scroll->AddChild(contents.Pass()); |
237 root->AddChild(scroll.Pass()); | 249 page_scale->AddChild(scroll.Pass()); |
| 250 clip->AddChild(page_scale.Pass()); |
| 251 root->AddChild(clip.Pass()); |
238 | 252 |
239 layer_tree_impl->SetRootLayer(root.Pass()); | 253 layer_tree_impl->SetRootLayer(root.Pass()); |
| 254 layer_tree_impl->SetViewportLayersFromIds( |
| 255 PAGE_SCALE_ID, INNER_VIEWPORT_SCROLL_LAYER_ID, Layer::INVALID_ID); |
| 256 |
240 return scroll_layer; | 257 return scroll_layer; |
241 } | 258 } |
242 | 259 |
243 LayerImpl* SetupScrollAndContentsLayers(gfx::Size content_size) { | 260 LayerImpl* SetupScrollAndContentsLayers(gfx::Size content_size) { |
244 LayerImpl* scroll_layer = CreateScrollAndContentsLayers( | 261 LayerImpl* scroll_layer = CreateScrollAndContentsLayers( |
245 host_impl_->active_tree(), content_size); | 262 host_impl_->active_tree(), content_size); |
246 host_impl_->active_tree()->DidBecomeActive(); | 263 host_impl_->active_tree()->DidBecomeActive(); |
247 return scroll_layer; | 264 return scroll_layer; |
248 } | 265 } |
249 | 266 |
250 scoped_ptr<LayerImpl> CreateScrollableLayer(int id, gfx::Size size) { | 267 // TODO(wjmaclean) Add clip-layer pointer to parameters. |
| 268 scoped_ptr<LayerImpl> CreateScrollableLayer(int id, |
| 269 gfx::Size size, |
| 270 LayerImpl* clip_layer) { |
| 271 DCHECK(clip_layer); |
| 272 DCHECK(id != clip_layer->id()); |
251 scoped_ptr<LayerImpl> layer = | 273 scoped_ptr<LayerImpl> layer = |
252 LayerImpl::Create(host_impl_->active_tree(), id); | 274 LayerImpl::Create(host_impl_->active_tree(), id); |
253 layer->SetScrollable(true); | 275 layer->SetScrollable(clip_layer->id()); |
254 layer->SetDrawsContent(true); | 276 layer->SetDrawsContent(true); |
255 layer->SetBounds(size); | 277 layer->SetBounds(size); |
256 layer->SetContentBounds(size); | 278 layer->SetContentBounds(size); |
257 layer->SetMaxScrollOffset(gfx::Vector2d(size.width() * 2, | 279 clip_layer->SetBounds(gfx::Size(size.width() / 2, size.height() / 2)); |
258 size.height() * 2)); | |
259 return layer.Pass(); | 280 return layer.Pass(); |
260 } | 281 } |
261 | 282 |
262 void InitializeRendererAndDrawFrame() { | 283 void InitializeRendererAndDrawFrame() { |
263 host_impl_->InitializeRenderer(CreateOutputSurface()); | 284 host_impl_->InitializeRenderer(CreateOutputSurface()); |
264 DrawFrame(); | 285 DrawFrame(); |
265 } | 286 } |
266 | 287 |
267 void DrawFrame() { | 288 void DrawFrame() { |
268 LayerTreeHostImpl::FrameData frame; | 289 LayerTreeHostImpl::FrameData frame; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 | 453 |
433 scroll_info = host_impl_->ProcessScrollDeltas(); | 454 scroll_info = host_impl_->ProcessScrollDeltas(); |
434 ASSERT_EQ(scroll_info->scrolls.size(), 0u); | 455 ASSERT_EQ(scroll_info->scrolls.size(), 0u); |
435 ExpectClearedScrollDeltasRecursive(root); | 456 ExpectClearedScrollDeltasRecursive(root); |
436 } | 457 } |
437 | 458 |
438 TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) { | 459 TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) { |
439 gfx::Vector2d scroll_offset(20, 30); | 460 gfx::Vector2d scroll_offset(20, 30); |
440 gfx::Vector2d scroll_delta(11, -15); | 461 gfx::Vector2d scroll_delta(11, -15); |
441 { | 462 { |
| 463 scoped_ptr<LayerImpl> root_clip = |
| 464 LayerImpl::Create(host_impl_->active_tree(), 2); |
442 scoped_ptr<LayerImpl> root = | 465 scoped_ptr<LayerImpl> root = |
443 LayerImpl::Create(host_impl_->active_tree(), 1); | 466 LayerImpl::Create(host_impl_->active_tree(), 1); |
444 root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 467 root_clip->SetBounds(gfx::Size(10, 10)); |
445 root->SetScrollOffset(scroll_offset); | 468 LayerImpl* root_layer = root.get(); |
446 root->SetScrollable(true); | 469 root_clip->AddChild(root.Pass()); |
447 root->ScrollBy(scroll_delta); | 470 root_layer->SetBounds(gfx::Size(110, 110)); |
448 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 471 root_layer->SetScrollable(root_clip->id()); |
| 472 root_layer->SetScrollOffset(scroll_offset); |
| 473 root_layer->ScrollBy(scroll_delta); |
| 474 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
449 } | 475 } |
450 LayerImpl* root = host_impl_->active_tree()->root_layer(); | 476 LayerImpl* root = host_impl_->active_tree()->root_layer()->children()[0]; |
451 | 477 |
452 scoped_ptr<ScrollAndScaleSet> scroll_info; | 478 scoped_ptr<ScrollAndScaleSet> scroll_info; |
453 | 479 |
454 scroll_info = host_impl_->ProcessScrollDeltas(); | 480 scroll_info = host_impl_->ProcessScrollDeltas(); |
455 ASSERT_EQ(scroll_info->scrolls.size(), 1u); | 481 ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
456 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scroll_delta); | 482 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scroll_delta); |
457 ExpectContains(*scroll_info, root->id(), scroll_delta); | 483 ExpectContains(*scroll_info, root->id(), scroll_delta); |
458 | 484 |
459 gfx::Vector2d scroll_delta2(-5, 27); | 485 gfx::Vector2d scroll_delta2(-5, 27); |
460 root->ScrollBy(scroll_delta2); | 486 root->ScrollBy(scroll_delta2); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 gfx::Point(), SCROLL_FORWARD)); | 760 gfx::Point(), SCROLL_FORWARD)); |
735 EXPECT_FALSE(host_impl_->ScrollVerticallyByPage( | 761 EXPECT_FALSE(host_impl_->ScrollVerticallyByPage( |
736 gfx::Point(), SCROLL_BACKWARD)); | 762 gfx::Point(), SCROLL_BACKWARD)); |
737 | 763 |
738 scoped_ptr<cc::PaintedScrollbarLayerImpl> vertical_scrollbar( | 764 scoped_ptr<cc::PaintedScrollbarLayerImpl> vertical_scrollbar( |
739 cc::PaintedScrollbarLayerImpl::Create( | 765 cc::PaintedScrollbarLayerImpl::Create( |
740 host_impl_->active_tree(), | 766 host_impl_->active_tree(), |
741 20, | 767 20, |
742 VERTICAL)); | 768 VERTICAL)); |
743 vertical_scrollbar->SetBounds(gfx::Size(15, 1000)); | 769 vertical_scrollbar->SetBounds(gfx::Size(15, 1000)); |
744 host_impl_->RootScrollLayer()->SetVerticalScrollbarLayer( | 770 host_impl_->InnerViewportScrollLayer()->AddScrollbar( |
745 vertical_scrollbar.get()); | 771 vertical_scrollbar.get()); |
746 | 772 |
747 // Trying to scroll with a vertical scrollbar will succeed. | 773 // Trying to scroll with a vertical scrollbar will succeed. |
748 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( | 774 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( |
749 gfx::Point(), SCROLL_FORWARD)); | 775 gfx::Point(), SCROLL_FORWARD)); |
750 EXPECT_FLOAT_EQ(875.f, host_impl_->RootScrollLayer()->ScrollDelta().y()); | 776 EXPECT_FLOAT_EQ(875.f, host_impl_->InnerViewportScrollLayer()->ScrollDelta().y
()); |
751 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( | 777 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( |
752 gfx::Point(), SCROLL_BACKWARD)); | 778 gfx::Point(), SCROLL_BACKWARD)); |
753 } | 779 } |
754 | 780 |
755 TEST_F(LayerTreeHostImplTest, ScrollWithUserUnscrollableLayers) { | 781 TEST_F(LayerTreeHostImplTest, ScrollWithUserUnscrollableLayers) { |
756 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200)); | 782 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
757 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 783 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
758 | 784 |
759 gfx::Size overflow_size(400, 400); | 785 gfx::Size overflow_size(400, 400); |
760 ASSERT_EQ(1u, scroll_layer->children().size()); | 786 ASSERT_EQ(1u, scroll_layer->children().size()); |
761 LayerImpl* overflow = scroll_layer->children()[0]; | 787 LayerImpl* overflow = scroll_layer->children()[0]; |
762 overflow->SetBounds(overflow_size); | 788 overflow->SetBounds(overflow_size); |
763 overflow->SetContentBounds(overflow_size); | 789 overflow->SetContentBounds(overflow_size); |
764 overflow->SetScrollable(true); | 790 overflow->SetScrollable(scroll_layer->parent()->id()); |
765 overflow->SetMaxScrollOffset(gfx::Vector2d(overflow_size.width(), | 791 // overflow->SetMaxScrollOffset(gfx::Vector2d(overflow_size.width(), |
766 overflow_size.height())); | 792 // overflow_size.height())); |
767 overflow->SetScrollOffset(gfx::Vector2d()); | 793 overflow->SetScrollOffset(gfx::Vector2d()); |
768 overflow->SetPosition(gfx::PointF()); | 794 overflow->SetPosition(gfx::PointF()); |
769 overflow->SetAnchorPoint(gfx::PointF()); | 795 overflow->SetAnchorPoint(gfx::PointF()); |
770 | 796 |
771 InitializeRendererAndDrawFrame(); | 797 InitializeRendererAndDrawFrame(); |
772 gfx::Point scroll_position(10, 10); | 798 gfx::Point scroll_position(10, 10); |
773 | 799 |
774 EXPECT_EQ(InputHandler::ScrollStarted, | 800 EXPECT_EQ(InputHandler::ScrollStarted, |
775 host_impl_->ScrollBegin(scroll_position, InputHandler::Wheel)); | 801 host_impl_->ScrollBegin(scroll_position, InputHandler::Wheel)); |
776 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->TotalScrollOffset()); | 802 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->TotalScrollOffset()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 host_impl_->active_tree()->set_needs_update_draw_properties(); | 845 host_impl_->active_tree()->set_needs_update_draw_properties(); |
820 | 846 |
821 EXPECT_EQ(host_impl_->HaveTouchEventHandlersAt(gfx::Point()), false); | 847 EXPECT_EQ(host_impl_->HaveTouchEventHandlersAt(gfx::Point()), false); |
822 } | 848 } |
823 | 849 |
824 TEST_F(LayerTreeHostImplTest, ImplPinchZoom) { | 850 TEST_F(LayerTreeHostImplTest, ImplPinchZoom) { |
825 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 851 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
826 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 852 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
827 InitializeRendererAndDrawFrame(); | 853 InitializeRendererAndDrawFrame(); |
828 | 854 |
829 EXPECT_EQ(scroll_layer, host_impl_->RootScrollLayer()); | 855 EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer()); |
830 | 856 |
831 float min_page_scale = 1.f, max_page_scale = 4.f; | 857 float min_page_scale = 1.f, max_page_scale = 4.f; |
832 | 858 |
833 // The impl-based pinch zoom should adjust the max scroll position. | 859 // The impl-based pinch zoom should adjust the max scroll position. |
834 { | 860 { |
835 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 861 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
836 min_page_scale, | 862 min_page_scale, |
837 max_page_scale); | 863 max_page_scale); |
838 host_impl_->active_tree()->SetPageScaleDelta(1.f); | 864 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
839 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 865 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
840 | 866 |
841 float page_scale_delta = 2.f; | 867 float page_scale_delta = 2.f; |
842 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); | 868 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); |
| 869 host_impl_->PinchGestureBegin(); |
843 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); | 870 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); |
844 host_impl_->PinchGestureEnd(); | 871 host_impl_->PinchGestureEnd(); |
845 host_impl_->ScrollEnd(); | 872 host_impl_->ScrollEnd(); |
846 EXPECT_TRUE(did_request_redraw_); | 873 EXPECT_TRUE(did_request_redraw_); |
847 EXPECT_TRUE(did_request_commit_); | 874 EXPECT_TRUE(did_request_commit_); |
848 | 875 |
849 scoped_ptr<ScrollAndScaleSet> scroll_info = | 876 scoped_ptr<ScrollAndScaleSet> scroll_info = |
850 host_impl_->ProcessScrollDeltas(); | 877 host_impl_->ProcessScrollDeltas(); |
851 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); | 878 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
852 | 879 |
853 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(), | 880 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(), |
854 scroll_layer->max_scroll_offset().ToString()); | 881 scroll_layer->MaxScrollOffset().ToString()); |
855 } | 882 } |
856 | 883 |
857 // Scrolling after a pinch gesture should always be in local space. The | 884 // Scrolling after a pinch gesture should always be in local space. The |
858 // scroll deltas do not have the page scale factor applied. | 885 // scroll deltas do not have the page scale factor applied. |
859 { | 886 { |
860 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 887 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
861 min_page_scale, | 888 min_page_scale, |
862 max_page_scale); | 889 max_page_scale); |
863 host_impl_->active_tree()->SetPageScaleDelta(1.f); | 890 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
864 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 891 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
(...skipping 18 matching lines...) Expand all Loading... |
883 scroll_layer->id(), | 910 scroll_layer->id(), |
884 scroll_delta); | 911 scroll_delta); |
885 } | 912 } |
886 } | 913 } |
887 | 914 |
888 TEST_F(LayerTreeHostImplTest, PinchGesture) { | 915 TEST_F(LayerTreeHostImplTest, PinchGesture) { |
889 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 916 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
890 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 917 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
891 InitializeRendererAndDrawFrame(); | 918 InitializeRendererAndDrawFrame(); |
892 | 919 |
893 LayerImpl* scroll_layer = host_impl_->RootScrollLayer(); | 920 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
894 DCHECK(scroll_layer); | 921 DCHECK(scroll_layer); |
895 | 922 |
896 float min_page_scale = 1.f; | 923 float min_page_scale = 1.f; |
897 float max_page_scale = 4.f; | 924 float max_page_scale = 4.f; |
898 | 925 |
899 // Basic pinch zoom in gesture | 926 // Basic pinch zoom in gesture |
900 { | 927 { |
901 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 928 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
902 min_page_scale, | 929 min_page_scale, |
903 max_page_scale); | 930 max_page_scale); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); | 1030 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); |
1004 } | 1031 } |
1005 | 1032 |
1006 // Two-finger panning should work when starting fully zoomed out. | 1033 // Two-finger panning should work when starting fully zoomed out. |
1007 { | 1034 { |
1008 host_impl_->active_tree()->SetPageScaleFactorAndLimits(0.5f, | 1035 host_impl_->active_tree()->SetPageScaleFactorAndLimits(0.5f, |
1009 0.5f, | 1036 0.5f, |
1010 4.f); | 1037 4.f); |
1011 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 1038 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
1012 scroll_layer->SetScrollOffset(gfx::Vector2d(0, 0)); | 1039 scroll_layer->SetScrollOffset(gfx::Vector2d(0, 0)); |
1013 host_impl_->active_tree()->UpdateMaxScrollOffset(); | |
1014 | 1040 |
1015 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture); | 1041 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture); |
1016 host_impl_->PinchGestureBegin(); | 1042 host_impl_->PinchGestureBegin(); |
1017 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); | 1043 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); |
1018 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); | 1044 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); |
1019 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10)); | 1045 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10)); |
1020 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); | 1046 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); |
1021 host_impl_->PinchGestureEnd(); | 1047 host_impl_->PinchGestureEnd(); |
1022 host_impl_->ScrollEnd(); | 1048 host_impl_->ScrollEnd(); |
1023 | 1049 |
1024 scoped_ptr<ScrollAndScaleSet> scroll_info = | 1050 scoped_ptr<ScrollAndScaleSet> scroll_info = |
1025 host_impl_->ProcessScrollDeltas(); | 1051 host_impl_->ProcessScrollDeltas(); |
1026 EXPECT_EQ(scroll_info->page_scale_delta, 2.f); | 1052 EXPECT_EQ(scroll_info->page_scale_delta, 2.f); |
1027 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(20, 20)); | 1053 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(20, 20)); |
1028 } | 1054 } |
1029 } | 1055 } |
1030 | 1056 |
1031 TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { | 1057 TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { |
1032 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 1058 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
1033 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 1059 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
1034 InitializeRendererAndDrawFrame(); | 1060 InitializeRendererAndDrawFrame(); |
1035 | 1061 |
1036 LayerImpl* scroll_layer = host_impl_->RootScrollLayer(); | 1062 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
1037 DCHECK(scroll_layer); | 1063 DCHECK(scroll_layer); |
1038 | 1064 |
1039 float min_page_scale = 0.5f; | 1065 float min_page_scale = 0.5f; |
1040 float max_page_scale = 4.f; | 1066 float max_page_scale = 4.f; |
1041 base::TimeTicks start_time = base::TimeTicks() + | 1067 base::TimeTicks start_time = base::TimeTicks() + |
1042 base::TimeDelta::FromSeconds(1); | 1068 base::TimeDelta::FromSeconds(1); |
1043 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); | 1069 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
1044 base::TimeTicks halfway_through_animation = start_time + duration / 2; | 1070 base::TimeTicks halfway_through_animation = start_time + duration / 2; |
1045 base::TimeTicks end_time = start_time + duration; | 1071 base::TimeTicks end_time = start_time + duration; |
1046 | 1072 |
1047 // Non-anchor zoom-in | 1073 // Non-anchor zoom-in |
1048 { | 1074 { |
1049 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 1075 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
1050 min_page_scale, | 1076 min_page_scale, |
1051 max_page_scale); | 1077 max_page_scale); |
1052 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); | 1078 scroll_layer->SetScrollOffset(gfx::Vector2d(10, 10)); |
1053 | 1079 |
1054 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration); | 1080 host_impl_->StartPageScaleAnimation(gfx::Vector2d(), false, 2.f, duration); |
1055 did_request_redraw_ = false; | 1081 did_request_redraw_ = false; |
1056 host_impl_->Animate(start_time, base::Time()); | 1082 host_impl_->Animate(start_time, base::Time()); |
1057 EXPECT_TRUE(did_request_redraw_); | 1083 EXPECT_TRUE(did_request_redraw_); |
1058 | 1084 |
1059 did_request_redraw_ = false; | 1085 did_request_redraw_ = false; |
1060 host_impl_->Animate(halfway_through_animation, base::Time()); | 1086 host_impl_->Animate(halfway_through_animation, base::Time()); |
1061 EXPECT_TRUE(did_request_redraw_); | 1087 EXPECT_TRUE(did_request_redraw_); |
1062 | 1088 |
1063 did_request_redraw_ = false; | 1089 did_request_redraw_ = false; |
1064 did_request_commit_ = false; | 1090 did_request_commit_ = false; |
1065 host_impl_->Animate(end_time, base::Time()); | 1091 host_impl_->Animate(end_time, base::Time()); |
1066 EXPECT_TRUE(did_request_commit_); | 1092 EXPECT_TRUE(did_request_commit_); |
1067 | 1093 |
1068 scoped_ptr<ScrollAndScaleSet> scroll_info = | 1094 scoped_ptr<ScrollAndScaleSet> scroll_info = |
1069 host_impl_->ProcessScrollDeltas(); | 1095 host_impl_->ProcessScrollDeltas(); |
1070 EXPECT_EQ(scroll_info->page_scale_delta, 2); | 1096 EXPECT_EQ(scroll_info->page_scale_delta, 2); |
1071 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); | 1097 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); |
1072 } | 1098 } |
1073 | 1099 |
1074 // Anchor zoom-out | 1100 // Anchor zoom-out |
1075 { | 1101 { |
1076 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 1102 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
1077 min_page_scale, | 1103 min_page_scale, |
1078 max_page_scale); | 1104 max_page_scale); |
1079 scroll_layer->SetScrollOffset(gfx::Vector2d(50, 50)); | 1105 scroll_layer->SetScrollOffset(gfx::Vector2d(10, 10)); |
1080 | 1106 |
1081 host_impl_->StartPageScaleAnimation( | 1107 host_impl_->StartPageScaleAnimation( |
1082 gfx::Vector2d(25, 25), true, min_page_scale, duration); | 1108 gfx::Vector2d(5, 5), true, min_page_scale, duration); |
1083 did_request_redraw_ = false; | 1109 did_request_redraw_ = false; |
1084 host_impl_->Animate(start_time, base::Time()); | 1110 host_impl_->Animate(start_time, base::Time()); |
1085 EXPECT_TRUE(did_request_redraw_); | 1111 EXPECT_TRUE(did_request_redraw_); |
1086 | 1112 |
1087 did_request_redraw_ = false; | 1113 did_request_redraw_ = false; |
1088 did_request_commit_ = false; | 1114 did_request_commit_ = false; |
1089 host_impl_->Animate(end_time, base::Time()); | 1115 host_impl_->Animate(end_time, base::Time()); |
1090 EXPECT_TRUE(did_request_redraw_); | 1116 EXPECT_TRUE(did_request_redraw_); |
1091 EXPECT_TRUE(did_request_commit_); | 1117 EXPECT_TRUE(did_request_commit_); |
1092 | 1118 |
1093 scoped_ptr<ScrollAndScaleSet> scroll_info = | 1119 scoped_ptr<ScrollAndScaleSet> scroll_info = |
1094 host_impl_->ProcessScrollDeltas(); | 1120 host_impl_->ProcessScrollDeltas(); |
1095 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); | 1121 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); |
1096 // Pushed to (0,0) via clamping against contents layer size. | 1122 // Pushed to (0,0) via clamping against contents layer size. |
1097 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); | 1123 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); |
1098 } | 1124 } |
1099 } | 1125 } |
1100 | 1126 |
1101 TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) { | 1127 TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) { |
1102 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 1128 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
1103 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 1129 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
1104 InitializeRendererAndDrawFrame(); | 1130 InitializeRendererAndDrawFrame(); |
1105 | 1131 |
1106 LayerImpl* scroll_layer = host_impl_->RootScrollLayer(); | 1132 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
1107 DCHECK(scroll_layer); | 1133 DCHECK(scroll_layer); |
1108 | 1134 |
1109 float min_page_scale = 0.5f; | 1135 float min_page_scale = 0.5f; |
1110 float max_page_scale = 4.f; | 1136 float max_page_scale = 4.f; |
1111 base::TimeTicks start_time = base::TimeTicks() + | 1137 base::TimeTicks start_time = base::TimeTicks() + |
1112 base::TimeDelta::FromSeconds(1); | 1138 base::TimeDelta::FromSeconds(1); |
1113 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); | 1139 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
1114 base::TimeTicks halfway_through_animation = start_time + duration / 2; | 1140 base::TimeTicks halfway_through_animation = start_time + duration / 2; |
1115 base::TimeTicks end_time = start_time + duration; | 1141 base::TimeTicks end_time = start_time + duration; |
1116 | 1142 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 host_impl_ = make_scoped_ptr<LayerTreeHostImpl>(host_impl_override_time); | 1201 host_impl_ = make_scoped_ptr<LayerTreeHostImpl>(host_impl_override_time); |
1176 host_impl_->InitializeRenderer(CreateOutputSurface()); | 1202 host_impl_->InitializeRenderer(CreateOutputSurface()); |
1177 host_impl_->SetViewportSize(viewport_size); | 1203 host_impl_->SetViewportSize(viewport_size); |
1178 | 1204 |
1179 scoped_ptr<LayerImpl> root = | 1205 scoped_ptr<LayerImpl> root = |
1180 LayerImpl::Create(host_impl_->active_tree(), 1); | 1206 LayerImpl::Create(host_impl_->active_tree(), 1); |
1181 root->SetBounds(viewport_size); | 1207 root->SetBounds(viewport_size); |
1182 | 1208 |
1183 scoped_ptr<LayerImpl> scroll = | 1209 scoped_ptr<LayerImpl> scroll = |
1184 LayerImpl::Create(host_impl_->active_tree(), 2); | 1210 LayerImpl::Create(host_impl_->active_tree(), 2); |
1185 scroll->SetScrollable(true); | 1211 scroll->SetScrollable(root->id()); |
1186 scroll->SetScrollOffset(gfx::Vector2d()); | 1212 scroll->SetScrollOffset(gfx::Vector2d()); |
1187 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | 1213 root->SetBounds(viewport_size); |
1188 content_size.height())); | |
1189 scroll->SetBounds(content_size); | 1214 scroll->SetBounds(content_size); |
1190 scroll->SetContentBounds(content_size); | 1215 scroll->SetContentBounds(content_size); |
1191 | 1216 |
1192 scoped_ptr<LayerImpl> contents = | 1217 scoped_ptr<LayerImpl> contents = |
1193 LayerImpl::Create(host_impl_->active_tree(), 3); | 1218 LayerImpl::Create(host_impl_->active_tree(), 3); |
1194 contents->SetDrawsContent(true); | 1219 contents->SetDrawsContent(true); |
1195 contents->SetBounds(content_size); | 1220 contents->SetBounds(content_size); |
1196 contents->SetContentBounds(content_size); | 1221 contents->SetContentBounds(content_size); |
1197 | 1222 |
1198 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = | 1223 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = |
1199 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 4, VERTICAL); | 1224 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 4, VERTICAL); |
1200 scroll->SetVerticalScrollbarLayer(scrollbar.get()); | 1225 scrollbar->SetScrollLayerById(2); |
| 1226 scrollbar->SetClipLayerById(1); |
1201 | 1227 |
1202 scroll->AddChild(contents.Pass()); | 1228 scroll->AddChild(contents.Pass()); |
1203 root->AddChild(scroll.Pass()); | 1229 root->AddChild(scroll.Pass()); |
1204 root->AddChild(scrollbar.PassAs<LayerImpl>()); | 1230 root->AddChild(scrollbar.PassAs<LayerImpl>()); |
1205 | 1231 |
1206 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1232 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 1233 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
1207 host_impl_->active_tree()->DidBecomeActive(); | 1234 host_impl_->active_tree()->DidBecomeActive(); |
1208 InitializeRendererAndDrawFrame(); | 1235 InitializeRendererAndDrawFrame(); |
1209 | 1236 |
1210 base::TimeTicks fake_now = base::TimeTicks::Now(); | 1237 base::TimeTicks fake_now = base::TimeTicks::Now(); |
1211 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); | 1238 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
1212 | 1239 |
1213 // If no scroll happened recently, StartScrollbarAnimation should have no | 1240 // If no scroll happened recently, StartScrollbarAnimation should have no |
1214 // effect. | 1241 // effect. |
1215 host_impl_->StartScrollbarAnimation(); | 1242 host_impl_->StartScrollbarAnimation(); |
1216 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); | 1243 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); |
(...skipping 30 matching lines...) Expand all Loading... |
1247 // If no scroll happened recently, StartScrollbarAnimation should have no | 1274 // If no scroll happened recently, StartScrollbarAnimation should have no |
1248 // effect. | 1275 // effect. |
1249 fake_now += base::TimeDelta::FromMilliseconds(25); | 1276 fake_now += base::TimeDelta::FromMilliseconds(25); |
1250 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); | 1277 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
1251 host_impl_->StartScrollbarAnimation(); | 1278 host_impl_->StartScrollbarAnimation(); |
1252 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); | 1279 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); |
1253 EXPECT_FALSE(did_request_redraw_); | 1280 EXPECT_FALSE(did_request_redraw_); |
1254 | 1281 |
1255 // Setting the scroll offset outside a scroll should also cause the scrollbar | 1282 // Setting the scroll offset outside a scroll should also cause the scrollbar |
1256 // to appear and to schedule a fade. | 1283 // to appear and to schedule a fade. |
1257 host_impl_->RootScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); | 1284 host_impl_->InnerViewportScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); |
1258 host_impl_->StartScrollbarAnimation(); | 1285 host_impl_->StartScrollbarAnimation(); |
1259 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), | 1286 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), |
1260 requested_scrollbar_animation_delay_); | 1287 requested_scrollbar_animation_delay_); |
1261 EXPECT_FALSE(did_request_redraw_); | 1288 EXPECT_FALSE(did_request_redraw_); |
1262 requested_scrollbar_animation_delay_ = base::TimeDelta(); | 1289 requested_scrollbar_animation_delay_ = base::TimeDelta(); |
1263 | 1290 |
1264 // None of the above should have called CurrentFrameTimeTicks, so if we call | 1291 // None of the above should have called CurrentFrameTimeTicks, so if we call |
1265 // it now we should get the current time. | 1292 // it now we should get the current time. |
1266 fake_now += base::TimeDelta::FromMilliseconds(10); | 1293 fake_now += base::TimeDelta::FromMilliseconds(10); |
1267 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); | 1294 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
(...skipping 15 matching lines...) Expand all Loading... |
1283 host_impl_->InitializeRenderer(CreateOutputSurface()); | 1310 host_impl_->InitializeRenderer(CreateOutputSurface()); |
1284 host_impl_->SetDeviceScaleFactor(device_scale_factor); | 1311 host_impl_->SetDeviceScaleFactor(device_scale_factor); |
1285 host_impl_->SetViewportSize(device_viewport_size); | 1312 host_impl_->SetViewportSize(device_viewport_size); |
1286 | 1313 |
1287 scoped_ptr<LayerImpl> root = | 1314 scoped_ptr<LayerImpl> root = |
1288 LayerImpl::Create(host_impl_->active_tree(), 1); | 1315 LayerImpl::Create(host_impl_->active_tree(), 1); |
1289 root->SetBounds(viewport_size); | 1316 root->SetBounds(viewport_size); |
1290 | 1317 |
1291 scoped_ptr<LayerImpl> scroll = | 1318 scoped_ptr<LayerImpl> scroll = |
1292 LayerImpl::Create(host_impl_->active_tree(), 2); | 1319 LayerImpl::Create(host_impl_->active_tree(), 2); |
1293 scroll->SetScrollable(true); | 1320 scroll->SetScrollable(root->id()); |
1294 scroll->SetScrollOffset(gfx::Vector2d()); | 1321 scroll->SetScrollOffset(gfx::Vector2d()); |
1295 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | |
1296 content_size.height())); | |
1297 scroll->SetBounds(content_size); | 1322 scroll->SetBounds(content_size); |
1298 scroll->SetContentBounds(content_size); | 1323 scroll->SetContentBounds(content_size); |
1299 | 1324 |
1300 scoped_ptr<LayerImpl> contents = | 1325 scoped_ptr<LayerImpl> contents = |
1301 LayerImpl::Create(host_impl_->active_tree(), 3); | 1326 LayerImpl::Create(host_impl_->active_tree(), 3); |
1302 contents->SetDrawsContent(true); | 1327 contents->SetDrawsContent(true); |
1303 contents->SetBounds(content_size); | 1328 contents->SetBounds(content_size); |
1304 contents->SetContentBounds(content_size); | 1329 contents->SetContentBounds(content_size); |
1305 | 1330 |
1306 // The scrollbar is on the right side. | 1331 // The scrollbar is on the right side. |
1307 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = | 1332 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = |
1308 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 5, VERTICAL); | 1333 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 5, VERTICAL); |
1309 scrollbar->SetDrawsContent(true); | 1334 scrollbar->SetDrawsContent(true); |
1310 scrollbar->SetBounds(gfx::Size(15, viewport_size.height())); | 1335 scrollbar->SetBounds(gfx::Size(15, viewport_size.height())); |
1311 scrollbar->SetContentBounds(gfx::Size(15, viewport_size.height())); | 1336 scrollbar->SetContentBounds(gfx::Size(15, viewport_size.height())); |
1312 scrollbar->SetPosition(gfx::Point(285, 0)); | 1337 scrollbar->SetPosition(gfx::Point(285, 0)); |
1313 scroll->SetVerticalScrollbarLayer(scrollbar.get()); | 1338 scrollbar->SetScrollLayerById(2); |
1314 | 1339 |
1315 scroll->AddChild(contents.Pass()); | 1340 scroll->AddChild(contents.Pass()); |
1316 root->AddChild(scroll.Pass()); | 1341 root->AddChild(scroll.Pass()); |
1317 root->AddChild(scrollbar.PassAs<LayerImpl>()); | 1342 root->AddChild(scrollbar.PassAs<LayerImpl>()); |
1318 | 1343 |
1319 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1344 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 1345 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
1320 host_impl_->active_tree()->DidBecomeActive(); | 1346 host_impl_->active_tree()->DidBecomeActive(); |
1321 InitializeRendererAndDrawFrame(); | 1347 InitializeRendererAndDrawFrame(); |
1322 | 1348 |
1323 LayerImpl* root_scroll = host_impl_->active_tree()->RootScrollLayer(); | 1349 LayerImpl* root_scroll = |
| 1350 host_impl_->active_tree()->InnerViewportScrollLayer(); |
1324 ASSERT_TRUE(root_scroll->scrollbar_animation_controller()); | 1351 ASSERT_TRUE(root_scroll->scrollbar_animation_controller()); |
1325 ScrollbarAnimationControllerThinning* scrollbar_animation_controller = | 1352 ScrollbarAnimationControllerThinning* scrollbar_animation_controller = |
1326 static_cast<ScrollbarAnimationControllerThinning*>( | 1353 static_cast<ScrollbarAnimationControllerThinning*>( |
1327 root_scroll->scrollbar_animation_controller()); | 1354 root_scroll->scrollbar_animation_controller()); |
1328 scrollbar_animation_controller->set_mouse_move_distance_for_test(100.f); | 1355 scrollbar_animation_controller->set_mouse_move_distance_for_test(100.f); |
1329 | 1356 |
1330 host_impl_->MouseMoveAt(gfx::Point(1, 1)); | 1357 host_impl_->MouseMoveAt(gfx::Point(1, 1)); |
1331 EXPECT_FALSE(did_request_redraw_); | 1358 EXPECT_FALSE(did_request_redraw_); |
1332 | 1359 |
1333 did_request_redraw_ = false; | 1360 did_request_redraw_ = false; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); | 1424 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); |
1398 host_impl_->PinchGestureBegin(); | 1425 host_impl_->PinchGestureBegin(); |
1399 host_impl_->PinchGestureUpdate(2.f, gfx::Point()); | 1426 host_impl_->PinchGestureUpdate(2.f, gfx::Point()); |
1400 host_impl_->PinchGestureEnd(); | 1427 host_impl_->PinchGestureEnd(); |
1401 host_impl_->ScrollEnd(); | 1428 host_impl_->ScrollEnd(); |
1402 { | 1429 { |
1403 CompositorFrameMetadata metadata = | 1430 CompositorFrameMetadata metadata = |
1404 host_impl_->MakeCompositorFrameMetadata(); | 1431 host_impl_->MakeCompositorFrameMetadata(); |
1405 EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); | 1432 EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); |
1406 EXPECT_EQ(2.f, metadata.page_scale_factor); | 1433 EXPECT_EQ(2.f, metadata.page_scale_factor); |
1407 EXPECT_EQ(gfx::SizeF(25.f, 25.f), metadata.viewport_size); | 1434 EXPECT_EQ(gfx::SizeF(50.f, 50.f), metadata.viewport_size); |
1408 EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); | 1435 EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); |
1409 EXPECT_EQ(0.5f, metadata.min_page_scale_factor); | 1436 EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
1410 EXPECT_EQ(4.f, metadata.max_page_scale_factor); | 1437 EXPECT_EQ(4.f, metadata.max_page_scale_factor); |
1411 } | 1438 } |
1412 | 1439 |
1413 // Likewise if set from the main thread. | 1440 // Likewise if set from the main thread. |
1414 host_impl_->ProcessScrollDeltas(); | 1441 host_impl_->ProcessScrollDeltas(); |
1415 host_impl_->active_tree()->SetPageScaleFactorAndLimits(4.f, 0.5f, 4.f); | 1442 host_impl_->active_tree()->SetPageScaleFactorAndLimits(4.f, 0.5f, 4.f); |
1416 host_impl_->active_tree()->SetPageScaleDelta(1.f); | 1443 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
1417 { | 1444 { |
1418 CompositorFrameMetadata metadata = | 1445 CompositorFrameMetadata metadata = |
1419 host_impl_->MakeCompositorFrameMetadata(); | 1446 host_impl_->MakeCompositorFrameMetadata(); |
1420 EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); | 1447 EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset); |
1421 EXPECT_EQ(4.f, metadata.page_scale_factor); | 1448 EXPECT_EQ(4.f, metadata.page_scale_factor); |
1422 EXPECT_EQ(gfx::SizeF(12.5f, 12.5f), metadata.viewport_size); | 1449 EXPECT_EQ(gfx::SizeF(50.f, 50.f), metadata.viewport_size); |
1423 EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); | 1450 EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size); |
1424 EXPECT_EQ(0.5f, metadata.min_page_scale_factor); | 1451 EXPECT_EQ(0.5f, metadata.min_page_scale_factor); |
1425 EXPECT_EQ(4.f, metadata.max_page_scale_factor); | 1452 EXPECT_EQ(4.f, metadata.max_page_scale_factor); |
1426 } | 1453 } |
1427 } | 1454 } |
1428 | 1455 |
1429 class DidDrawCheckLayer : public TiledLayerImpl { | 1456 class DidDrawCheckLayer : public TiledLayerImpl { |
1430 public: | 1457 public: |
1431 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { | 1458 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { |
1432 return scoped_ptr<LayerImpl>(new DidDrawCheckLayer(tree_impl, id)); | 1459 return scoped_ptr<LayerImpl>(new DidDrawCheckLayer(tree_impl, id)); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1764 true, | 1791 true, |
1765 host_impl_->resource_provider())); | 1792 host_impl_->resource_provider())); |
1766 | 1793 |
1767 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 1794 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
1768 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); | 1795 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); |
1769 host_impl_->DidDrawAllLayers(frame); | 1796 host_impl_->DidDrawAllLayers(frame); |
1770 } | 1797 } |
1771 | 1798 |
1772 TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) { | 1799 TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) { |
1773 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1800 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1774 root->SetScrollable(false); | 1801 root->SetScrollable(Layer::INVALID_ID); |
1775 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1802 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1776 InitializeRendererAndDrawFrame(); | 1803 InitializeRendererAndDrawFrame(); |
1777 | 1804 |
1778 // Scroll event is ignored because layer is not scrollable. | 1805 // Scroll event is ignored because layer is not scrollable. |
1779 EXPECT_EQ(InputHandler::ScrollIgnored, | 1806 EXPECT_EQ(InputHandler::ScrollIgnored, |
1780 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 1807 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
1781 EXPECT_FALSE(did_request_redraw_); | 1808 EXPECT_FALSE(did_request_redraw_); |
1782 EXPECT_FALSE(did_request_commit_); | 1809 EXPECT_FALSE(did_request_commit_); |
1783 } | 1810 } |
1784 | 1811 |
1785 TEST_F(LayerTreeHostImplTest, ScrollNonScrollableRootWithTopControls) { | 1812 TEST_F(LayerTreeHostImplTest, ScrollNonScrollableRootWithTopControls) { |
1786 LayerTreeSettings settings; | 1813 LayerTreeSettings settings; |
1787 settings.calculate_top_controls_position = true; | 1814 settings.calculate_top_controls_position = true; |
1788 settings.top_controls_height = 50; | 1815 settings.top_controls_height = 50; |
1789 | 1816 |
1790 host_impl_ = LayerTreeHostImpl::Create( | 1817 host_impl_ = LayerTreeHostImpl::Create( |
1791 settings, this, &proxy_, &stats_instrumentation_, NULL); | 1818 settings, this, &proxy_, &stats_instrumentation_, NULL); |
1792 host_impl_->InitializeRenderer(CreateOutputSurface()); | 1819 host_impl_->InitializeRenderer(CreateOutputSurface()); |
1793 host_impl_->SetViewportSize(gfx::Size(10, 10)); | 1820 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
1794 | 1821 |
1795 gfx::Size layer_size(5, 5); | 1822 gfx::Size layer_size(10, 10); |
| 1823 gfx::Size clip_size(5, 5); |
1796 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1824 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1797 root->SetScrollable(true); | 1825 scoped_ptr<LayerImpl> root_clip = |
1798 root->SetMaxScrollOffset(gfx::Vector2d(layer_size.width(), | 1826 LayerImpl::Create(host_impl_->active_tree(), 2); |
1799 layer_size.height())); | 1827 root_clip->SetBounds(clip_size); |
| 1828 root->SetScrollable(root_clip->id()); |
1800 root->SetBounds(layer_size); | 1829 root->SetBounds(layer_size); |
1801 root->SetContentBounds(layer_size); | 1830 root->SetContentBounds(layer_size); |
1802 root->SetPosition(gfx::PointF()); | 1831 root->SetPosition(gfx::PointF()); |
1803 root->SetAnchorPoint(gfx::PointF()); | 1832 root->SetAnchorPoint(gfx::PointF()); |
1804 root->SetDrawsContent(false); | 1833 root->SetDrawsContent(false); |
1805 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1834 int root_id = root->id(); |
1806 host_impl_->active_tree()->FindRootScrollLayer(); | 1835 root_clip->AddChild(root.Pass()); |
| 1836 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 1837 host_impl_->active_tree()->SetViewportLayersFromIds( |
| 1838 root_id, root_id, Layer::INVALID_ID); |
1807 InitializeRendererAndDrawFrame(); | 1839 InitializeRendererAndDrawFrame(); |
1808 | 1840 |
1809 EXPECT_EQ(InputHandler::ScrollIgnored, | 1841 EXPECT_EQ(InputHandler::ScrollIgnored, |
1810 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 1842 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
1811 | 1843 |
1812 host_impl_->top_controls_manager()->ScrollBegin(); | 1844 host_impl_->top_controls_manager()->ScrollBegin(); |
1813 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); | 1845 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); |
1814 host_impl_->top_controls_manager()->ScrollEnd(); | 1846 host_impl_->top_controls_manager()->ScrollEnd(); |
1815 EXPECT_EQ(host_impl_->top_controls_manager()->content_top_offset(), 0.f); | 1847 EXPECT_EQ(host_impl_->top_controls_manager()->content_top_offset(), 0.f); |
1816 | 1848 |
1817 EXPECT_EQ(InputHandler::ScrollStarted, | 1849 EXPECT_EQ(InputHandler::ScrollStarted, |
1818 host_impl_->ScrollBegin(gfx::Point(), | 1850 host_impl_->ScrollBegin(gfx::Point(), |
1819 InputHandler::Gesture)); | 1851 InputHandler::Gesture)); |
1820 } | 1852 } |
1821 | 1853 |
1822 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { | 1854 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { |
1823 // Test the configuration where a non-composited root layer is embedded in a | 1855 // Test the configuration where a non-composited root layer is embedded in a |
1824 // scrollable outer layer. | 1856 // scrollable outer layer. |
1825 gfx::Size surface_size(10, 10); | 1857 gfx::Size surface_size(10, 10); |
| 1858 gfx::Size contents_size(20, 20); |
1826 | 1859 |
1827 scoped_ptr<LayerImpl> content_layer = | 1860 scoped_ptr<LayerImpl> content_layer = |
1828 LayerImpl::Create(host_impl_->active_tree(), 1); | 1861 LayerImpl::Create(host_impl_->active_tree(), 1); |
1829 content_layer->SetDrawsContent(true); | 1862 content_layer->SetDrawsContent(true); |
1830 content_layer->SetPosition(gfx::PointF()); | 1863 content_layer->SetPosition(gfx::PointF()); |
1831 content_layer->SetAnchorPoint(gfx::PointF()); | 1864 content_layer->SetAnchorPoint(gfx::PointF()); |
1832 content_layer->SetBounds(surface_size); | 1865 content_layer->SetBounds(surface_size); |
1833 content_layer->SetContentBounds(gfx::Size(surface_size.width() * 2, | 1866 content_layer->SetContentBounds(contents_size); |
1834 surface_size.height() * 2)); | |
1835 content_layer->SetContentsScale(2.f, 2.f); | 1867 content_layer->SetContentsScale(2.f, 2.f); |
1836 | 1868 |
| 1869 scoped_ptr<LayerImpl> scroll_clip_layer = |
| 1870 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 1871 scroll_clip_layer->SetBounds(surface_size); |
| 1872 |
1837 scoped_ptr<LayerImpl> scroll_layer = | 1873 scoped_ptr<LayerImpl> scroll_layer = |
1838 LayerImpl::Create(host_impl_->active_tree(), 2); | 1874 LayerImpl::Create(host_impl_->active_tree(), 2); |
1839 scroll_layer->SetScrollable(true); | 1875 scroll_layer->SetScrollable(3); |
1840 scroll_layer->SetMaxScrollOffset(gfx::Vector2d(surface_size.width(), | 1876 scroll_layer->SetBounds(contents_size); |
1841 surface_size.height())); | 1877 scroll_layer->SetContentBounds(contents_size); |
1842 scroll_layer->SetBounds(surface_size); | |
1843 scroll_layer->SetContentBounds(surface_size); | |
1844 scroll_layer->SetPosition(gfx::PointF()); | 1878 scroll_layer->SetPosition(gfx::PointF()); |
1845 scroll_layer->SetAnchorPoint(gfx::PointF()); | 1879 scroll_layer->SetAnchorPoint(gfx::PointF()); |
1846 scroll_layer->AddChild(content_layer.Pass()); | 1880 scroll_layer->AddChild(content_layer.Pass()); |
| 1881 scroll_clip_layer->AddChild(scroll_layer.Pass()); |
1847 | 1882 |
1848 host_impl_->active_tree()->SetRootLayer(scroll_layer.Pass()); | 1883 host_impl_->active_tree()->SetRootLayer(scroll_clip_layer.Pass()); |
1849 host_impl_->SetViewportSize(surface_size); | 1884 host_impl_->SetViewportSize(surface_size); |
1850 InitializeRendererAndDrawFrame(); | 1885 InitializeRendererAndDrawFrame(); |
1851 | 1886 |
1852 EXPECT_EQ(InputHandler::ScrollStarted, | 1887 EXPECT_EQ(InputHandler::ScrollStarted, |
1853 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1888 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1854 InputHandler::Wheel)); | 1889 InputHandler::Wheel)); |
1855 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 1890 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
1856 host_impl_->ScrollEnd(); | 1891 host_impl_->ScrollEnd(); |
1857 EXPECT_TRUE(did_request_redraw_); | 1892 EXPECT_TRUE(did_request_redraw_); |
1858 EXPECT_TRUE(did_request_commit_); | 1893 EXPECT_TRUE(did_request_commit_); |
1859 } | 1894 } |
1860 | 1895 |
1861 TEST_F(LayerTreeHostImplTest, ScrollChildCallsCommitAndRedraw) { | 1896 TEST_F(LayerTreeHostImplTest, ScrollChildCallsCommitAndRedraw) { |
1862 gfx::Size surface_size(10, 10); | 1897 gfx::Size surface_size(10, 10); |
| 1898 gfx::Size contents_size(20,20); |
1863 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1899 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1864 root->SetBounds(surface_size); | 1900 root->SetBounds(surface_size); |
1865 root->SetContentBounds(surface_size); | 1901 root->SetContentBounds(contents_size); |
1866 root->AddChild(CreateScrollableLayer(2, surface_size)); | 1902 root->AddChild(CreateScrollableLayer(2, contents_size, root.get())); |
1867 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1903 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1868 host_impl_->SetViewportSize(surface_size); | 1904 host_impl_->SetViewportSize(surface_size); |
1869 InitializeRendererAndDrawFrame(); | 1905 InitializeRendererAndDrawFrame(); |
1870 | 1906 |
1871 EXPECT_EQ(InputHandler::ScrollStarted, | 1907 EXPECT_EQ(InputHandler::ScrollStarted, |
1872 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1908 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1873 InputHandler::Wheel)); | 1909 InputHandler::Wheel)); |
1874 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 1910 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
1875 host_impl_->ScrollEnd(); | 1911 host_impl_->ScrollEnd(); |
1876 EXPECT_TRUE(did_request_redraw_); | 1912 EXPECT_TRUE(did_request_redraw_); |
1877 EXPECT_TRUE(did_request_commit_); | 1913 EXPECT_TRUE(did_request_commit_); |
1878 } | 1914 } |
1879 | 1915 |
1880 TEST_F(LayerTreeHostImplTest, ScrollMissesChild) { | 1916 TEST_F(LayerTreeHostImplTest, ScrollMissesChild) { |
1881 gfx::Size surface_size(10, 10); | 1917 gfx::Size surface_size(10, 10); |
1882 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1918 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1883 root->AddChild(CreateScrollableLayer(2, surface_size)); | 1919 root->AddChild(CreateScrollableLayer(2, surface_size, root.get())); |
1884 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1920 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1885 host_impl_->SetViewportSize(surface_size); | 1921 host_impl_->SetViewportSize(surface_size); |
1886 InitializeRendererAndDrawFrame(); | 1922 InitializeRendererAndDrawFrame(); |
1887 | 1923 |
1888 // Scroll event is ignored because the input coordinate is outside the layer | 1924 // Scroll event is ignored because the input coordinate is outside the layer |
1889 // boundaries. | 1925 // boundaries. |
1890 EXPECT_EQ(InputHandler::ScrollIgnored, | 1926 EXPECT_EQ(InputHandler::ScrollIgnored, |
1891 host_impl_->ScrollBegin(gfx::Point(15, 5), | 1927 host_impl_->ScrollBegin(gfx::Point(15, 5), |
1892 InputHandler::Wheel)); | 1928 InputHandler::Wheel)); |
1893 EXPECT_FALSE(did_request_redraw_); | 1929 EXPECT_FALSE(did_request_redraw_); |
1894 EXPECT_FALSE(did_request_commit_); | 1930 EXPECT_FALSE(did_request_commit_); |
1895 } | 1931 } |
1896 | 1932 |
1897 TEST_F(LayerTreeHostImplTest, ScrollMissesBackfacingChild) { | 1933 TEST_F(LayerTreeHostImplTest, ScrollMissesBackfacingChild) { |
1898 gfx::Size surface_size(10, 10); | 1934 gfx::Size surface_size(10, 10); |
1899 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1935 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1900 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, surface_size); | 1936 scoped_ptr<LayerImpl> child = |
| 1937 CreateScrollableLayer(2, surface_size, root.get()); |
1901 host_impl_->SetViewportSize(surface_size); | 1938 host_impl_->SetViewportSize(surface_size); |
1902 | 1939 |
1903 gfx::Transform matrix; | 1940 gfx::Transform matrix; |
1904 matrix.RotateAboutXAxis(180.0); | 1941 matrix.RotateAboutXAxis(180.0); |
1905 child->SetTransform(matrix); | 1942 child->SetTransform(matrix); |
1906 child->SetDoubleSided(false); | 1943 child->SetDoubleSided(false); |
1907 | 1944 |
1908 root->AddChild(child.Pass()); | 1945 root->AddChild(child.Pass()); |
1909 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1946 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1910 InitializeRendererAndDrawFrame(); | 1947 InitializeRendererAndDrawFrame(); |
1911 | 1948 |
1912 // Scroll event is ignored because the scrollable layer is not facing the | 1949 // Scroll event is ignored because the scrollable layer is not facing the |
1913 // viewer and there is nothing scrollable behind it. | 1950 // viewer and there is nothing scrollable behind it. |
1914 EXPECT_EQ(InputHandler::ScrollIgnored, | 1951 EXPECT_EQ(InputHandler::ScrollIgnored, |
1915 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1952 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1916 InputHandler::Wheel)); | 1953 InputHandler::Wheel)); |
1917 EXPECT_FALSE(did_request_redraw_); | 1954 EXPECT_FALSE(did_request_redraw_); |
1918 EXPECT_FALSE(did_request_commit_); | 1955 EXPECT_FALSE(did_request_commit_); |
1919 } | 1956 } |
1920 | 1957 |
1921 TEST_F(LayerTreeHostImplTest, ScrollBlockedByContentLayer) { | 1958 TEST_F(LayerTreeHostImplTest, ScrollBlockedByContentLayer) { |
1922 gfx::Size surface_size(10, 10); | 1959 gfx::Size surface_size(10, 10); |
1923 scoped_ptr<LayerImpl> content_layer = CreateScrollableLayer(1, surface_size); | 1960 scoped_ptr<LayerImpl> clip_layer = |
| 1961 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 1962 scoped_ptr<LayerImpl> content_layer = |
| 1963 CreateScrollableLayer(1, surface_size, clip_layer.get()); |
1924 content_layer->SetShouldScrollOnMainThread(true); | 1964 content_layer->SetShouldScrollOnMainThread(true); |
1925 content_layer->SetScrollable(false); | 1965 content_layer->SetScrollable(Layer::INVALID_ID); |
1926 | 1966 |
1927 scoped_ptr<LayerImpl> scroll_layer = CreateScrollableLayer(2, surface_size); | 1967 // Note: we can use the same clip layer for both since both calls to |
| 1968 // CreateScrollableLayer() use the same surface size. |
| 1969 scoped_ptr<LayerImpl> scroll_layer = |
| 1970 CreateScrollableLayer(2, surface_size, clip_layer.get()); |
1928 scroll_layer->AddChild(content_layer.Pass()); | 1971 scroll_layer->AddChild(content_layer.Pass()); |
| 1972 clip_layer->AddChild(scroll_layer.Pass()); |
1929 | 1973 |
1930 host_impl_->active_tree()->SetRootLayer(scroll_layer.Pass()); | 1974 host_impl_->active_tree()->SetRootLayer(clip_layer.Pass()); |
1931 host_impl_->SetViewportSize(surface_size); | 1975 host_impl_->SetViewportSize(surface_size); |
1932 InitializeRendererAndDrawFrame(); | 1976 InitializeRendererAndDrawFrame(); |
1933 | 1977 |
1934 // Scrolling fails because the content layer is asking to be scrolled on the | 1978 // Scrolling fails because the content layer is asking to be scrolled on the |
1935 // main thread. | 1979 // main thread. |
1936 EXPECT_EQ(InputHandler::ScrollOnMainThread, | 1980 EXPECT_EQ(InputHandler::ScrollOnMainThread, |
1937 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1981 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1938 InputHandler::Wheel)); | 1982 InputHandler::Wheel)); |
1939 } | 1983 } |
1940 | 1984 |
1941 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnMainThread) { | 1985 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnMainThread) { |
1942 gfx::Size surface_size(10, 10); | 1986 gfx::Size surface_size(20, 20); |
1943 float page_scale = 2.f; | 1987 float page_scale = 2.f; |
1944 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1988 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1945 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 1989 scoped_ptr<LayerImpl> root_scrolling = |
| 1990 CreateScrollableLayer(2, surface_size, root.get()); |
1946 root->AddChild(root_scrolling.Pass()); | 1991 root->AddChild(root_scrolling.Pass()); |
1947 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1992 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 1993 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
1948 host_impl_->active_tree()->DidBecomeActive(); | 1994 host_impl_->active_tree()->DidBecomeActive(); |
1949 host_impl_->SetViewportSize(surface_size); | 1995 host_impl_->SetViewportSize(surface_size); |
1950 InitializeRendererAndDrawFrame(); | 1996 InitializeRendererAndDrawFrame(); |
1951 | 1997 |
1952 LayerImpl* root_scroll = host_impl_->active_tree()->RootScrollLayer(); | 1998 LayerImpl* root_scroll = |
| 1999 host_impl_->active_tree()->InnerViewportScrollLayer(); |
1953 | 2000 |
1954 gfx::Vector2d scroll_delta(0, 10); | 2001 gfx::Vector2d scroll_delta(0, 10); |
1955 gfx::Vector2d expected_scroll_delta = scroll_delta; | 2002 gfx::Vector2d expected_scroll_delta = scroll_delta; |
1956 gfx::Vector2d expected_max_scroll = root_scroll->max_scroll_offset(); | 2003 gfx::Vector2d expected_max_scroll = root_scroll->MaxScrollOffset(); |
1957 EXPECT_EQ(InputHandler::ScrollStarted, | 2004 EXPECT_EQ(InputHandler::ScrollStarted, |
1958 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2005 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1959 InputHandler::Wheel)); | 2006 InputHandler::Wheel)); |
1960 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2007 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
1961 host_impl_->ScrollEnd(); | 2008 host_impl_->ScrollEnd(); |
1962 | 2009 |
1963 // Set new page scale from main thread. | 2010 // Set new page scale from main thread. |
1964 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, | 2011 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, |
1965 page_scale, | 2012 page_scale, |
1966 page_scale); | 2013 page_scale); |
1967 | 2014 |
1968 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 2015 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
1969 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); | 2016 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); |
1970 | 2017 |
1971 // The scroll range should also have been updated. | 2018 // The scroll range should also have been updated. |
1972 EXPECT_EQ(expected_max_scroll, root_scroll->max_scroll_offset()); | 2019 EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); |
1973 | 2020 |
1974 // The page scale delta remains constant because the impl thread did not | 2021 // The page scale delta remains constant because the impl thread did not |
1975 // scale. | 2022 // scale. |
1976 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); | 2023 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
1977 } | 2024 } |
1978 | 2025 |
1979 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnImplThread) { | 2026 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnImplThread) { |
1980 gfx::Size surface_size(10, 10); | 2027 gfx::Size surface_size(20, 20); |
1981 float page_scale = 2.f; | 2028 float page_scale = 2.f; |
1982 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 2029 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1983 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 2030 scoped_ptr<LayerImpl> root_scrolling = |
| 2031 CreateScrollableLayer(2, surface_size, root.get()); |
1984 root->AddChild(root_scrolling.Pass()); | 2032 root->AddChild(root_scrolling.Pass()); |
1985 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2033 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 2034 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
1986 host_impl_->active_tree()->DidBecomeActive(); | 2035 host_impl_->active_tree()->DidBecomeActive(); |
1987 host_impl_->SetViewportSize(surface_size); | 2036 host_impl_->SetViewportSize(surface_size); |
1988 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, page_scale); | 2037 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, page_scale); |
1989 InitializeRendererAndDrawFrame(); | 2038 InitializeRendererAndDrawFrame(); |
1990 | 2039 |
1991 LayerImpl* root_scroll = host_impl_->active_tree()->RootScrollLayer(); | 2040 LayerImpl* root_scroll = |
| 2041 host_impl_->active_tree()->InnerViewportScrollLayer(); |
1992 | 2042 |
1993 gfx::Vector2d scroll_delta(0, 10); | 2043 gfx::Vector2d scroll_delta(0, 10); |
1994 gfx::Vector2d expected_scroll_delta = scroll_delta; | 2044 gfx::Vector2d expected_scroll_delta = scroll_delta; |
1995 gfx::Vector2d expected_max_scroll = root_scroll->max_scroll_offset(); | 2045 gfx::Vector2d expected_max_scroll = root_scroll->MaxScrollOffset(); |
1996 EXPECT_EQ(InputHandler::ScrollStarted, | 2046 EXPECT_EQ(InputHandler::ScrollStarted, |
1997 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2047 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1998 InputHandler::Wheel)); | 2048 InputHandler::Wheel)); |
1999 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2049 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2000 host_impl_->ScrollEnd(); | 2050 host_impl_->ScrollEnd(); |
2001 | 2051 |
2002 // Set new page scale on impl thread by pinching. | 2052 // Set new page scale on impl thread by pinching. |
2003 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); | 2053 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); |
2004 host_impl_->PinchGestureBegin(); | 2054 host_impl_->PinchGestureBegin(); |
2005 host_impl_->PinchGestureUpdate(page_scale, gfx::Point()); | 2055 host_impl_->PinchGestureUpdate(page_scale, gfx::Point()); |
2006 host_impl_->PinchGestureEnd(); | 2056 host_impl_->PinchGestureEnd(); |
2007 host_impl_->ScrollEnd(); | 2057 host_impl_->ScrollEnd(); |
2008 DrawOneFrame(); | 2058 DrawOneFrame(); |
2009 | 2059 |
2010 // The scroll delta is not scaled because the main thread did not scale. | 2060 // The scroll delta is not scaled because the main thread did not scale. |
2011 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 2061 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
2012 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); | 2062 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); |
2013 | 2063 |
2014 // The scroll range should also have been updated. | 2064 // The scroll range should also have been updated. |
2015 EXPECT_EQ(expected_max_scroll, root_scroll->max_scroll_offset()); | 2065 EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); |
2016 | 2066 |
2017 // The page scale delta should match the new scale on the impl side. | 2067 // The page scale delta should match the new scale on the impl side. |
2018 EXPECT_EQ(page_scale, host_impl_->active_tree()->total_page_scale_factor()); | 2068 EXPECT_EQ(page_scale, host_impl_->active_tree()->total_page_scale_factor()); |
2019 } | 2069 } |
2020 | 2070 |
2021 TEST_F(LayerTreeHostImplTest, PageScaleDeltaAppliedToRootScrollLayerOnly) { | 2071 TEST_F(LayerTreeHostImplTest, PageScaleDeltaAppliedToRootScrollLayerOnly) { |
2022 gfx::Size surface_size(10, 10); | 2072 gfx::Size surface_size(10, 10); |
2023 float default_page_scale = 1.f; | 2073 float default_page_scale = 1.f; |
2024 gfx::Transform default_page_scale_matrix; | 2074 gfx::Transform default_page_scale_matrix; |
2025 default_page_scale_matrix.Scale(default_page_scale, default_page_scale); | 2075 default_page_scale_matrix.Scale(default_page_scale, default_page_scale); |
2026 | 2076 |
2027 float new_page_scale = 2.f; | 2077 float new_page_scale = 2.f; |
2028 gfx::Transform new_page_scale_matrix; | 2078 gfx::Transform new_page_scale_matrix; |
2029 new_page_scale_matrix.Scale(new_page_scale, new_page_scale); | 2079 new_page_scale_matrix.Scale(new_page_scale, new_page_scale); |
2030 | 2080 |
2031 // Create a normal scrollable root layer and another scrollable child layer. | 2081 // Create a normal scrollable root layer and another scrollable child layer. |
2032 LayerImpl* scroll = SetupScrollAndContentsLayers(surface_size); | 2082 LayerImpl* scroll = SetupScrollAndContentsLayers(surface_size); |
2033 LayerImpl* root = host_impl_->active_tree()->root_layer(); | 2083 LayerImpl* root = host_impl_->active_tree()->root_layer(); |
2034 LayerImpl* child = scroll->children()[0]; | 2084 LayerImpl* child = scroll->children()[0]; |
2035 | 2085 |
| 2086 scoped_ptr<LayerImpl> scrollable_child_clip = |
| 2087 LayerImpl::Create(host_impl_->active_tree(), 6); |
2036 scoped_ptr<LayerImpl> scrollable_child = | 2088 scoped_ptr<LayerImpl> scrollable_child = |
2037 CreateScrollableLayer(4, surface_size); | 2089 CreateScrollableLayer(7, surface_size, scrollable_child_clip.get()); |
2038 child->AddChild(scrollable_child.Pass()); | 2090 scrollable_child_clip->AddChild(scrollable_child.Pass()); |
| 2091 child->AddChild(scrollable_child_clip.Pass()); |
2039 LayerImpl* grand_child = child->children()[0]; | 2092 LayerImpl* grand_child = child->children()[0]; |
2040 | 2093 |
2041 // Set new page scale on impl thread by pinching. | 2094 // Set new page scale on impl thread by pinching. |
2042 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); | 2095 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); |
2043 host_impl_->PinchGestureBegin(); | 2096 host_impl_->PinchGestureBegin(); |
2044 host_impl_->PinchGestureUpdate(new_page_scale, gfx::Point()); | 2097 host_impl_->PinchGestureUpdate(new_page_scale, gfx::Point()); |
2045 host_impl_->PinchGestureEnd(); | 2098 host_impl_->PinchGestureEnd(); |
2046 host_impl_->ScrollEnd(); | 2099 host_impl_->ScrollEnd(); |
2047 DrawOneFrame(); | 2100 DrawOneFrame(); |
2048 | 2101 |
(...skipping 19 matching lines...) Expand all Loading... |
2068 EXPECT_EQ(new_page_scale, scroll->draw_transform().matrix().getDouble(1, 1)); | 2121 EXPECT_EQ(new_page_scale, scroll->draw_transform().matrix().getDouble(1, 1)); |
2069 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(0, 0)); | 2122 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(0, 0)); |
2070 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(1, 1)); | 2123 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(1, 1)); |
2071 EXPECT_EQ(new_page_scale, | 2124 EXPECT_EQ(new_page_scale, |
2072 grand_child->draw_transform().matrix().getDouble(0, 0)); | 2125 grand_child->draw_transform().matrix().getDouble(0, 0)); |
2073 EXPECT_EQ(new_page_scale, | 2126 EXPECT_EQ(new_page_scale, |
2074 grand_child->draw_transform().matrix().getDouble(1, 1)); | 2127 grand_child->draw_transform().matrix().getDouble(1, 1)); |
2075 } | 2128 } |
2076 | 2129 |
2077 TEST_F(LayerTreeHostImplTest, ScrollChildAndChangePageScaleOnMainThread) { | 2130 TEST_F(LayerTreeHostImplTest, ScrollChildAndChangePageScaleOnMainThread) { |
2078 gfx::Size surface_size(10, 10); | 2131 gfx::Size surface_size(30, 30); |
2079 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 2132 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 2133 root->SetBounds(gfx::Size(5, 5)); |
2080 scoped_ptr<LayerImpl> root_scrolling = | 2134 scoped_ptr<LayerImpl> root_scrolling = |
2081 LayerImpl::Create(host_impl_->active_tree(), 2); | 2135 LayerImpl::Create(host_impl_->active_tree(), 2); |
2082 root_scrolling->SetBounds(surface_size); | 2136 root_scrolling->SetBounds(surface_size); |
2083 root_scrolling->SetContentBounds(surface_size); | 2137 root_scrolling->SetContentBounds(surface_size); |
2084 root_scrolling->SetScrollable(true); | 2138 root_scrolling->SetScrollable(root->id()); |
2085 root->AddChild(root_scrolling.Pass()); | 2139 root->AddChild(root_scrolling.Pass()); |
2086 int child_scroll_layer_id = 3; | 2140 int child_scroll_layer_id = 3; |
2087 scoped_ptr<LayerImpl> child_scrolling = | 2141 scoped_ptr<LayerImpl> child_scrolling = |
2088 CreateScrollableLayer(child_scroll_layer_id, surface_size); | 2142 CreateScrollableLayer(child_scroll_layer_id, surface_size, root.get()); |
2089 LayerImpl* child = child_scrolling.get(); | 2143 LayerImpl* child = child_scrolling.get(); |
2090 root->AddChild(child_scrolling.Pass()); | 2144 root->AddChild(child_scrolling.Pass()); |
2091 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2145 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 2146 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
2092 host_impl_->active_tree()->DidBecomeActive(); | 2147 host_impl_->active_tree()->DidBecomeActive(); |
2093 host_impl_->SetViewportSize(surface_size); | 2148 host_impl_->SetViewportSize(surface_size); |
2094 InitializeRendererAndDrawFrame(); | 2149 InitializeRendererAndDrawFrame(); |
2095 | 2150 |
2096 gfx::Vector2d scroll_delta(0, 10); | 2151 gfx::Vector2d scroll_delta(0, 10); |
2097 gfx::Vector2d expected_scroll_delta(scroll_delta); | 2152 gfx::Vector2d expected_scroll_delta(scroll_delta); |
2098 gfx::Vector2d expected_max_scroll(child->max_scroll_offset()); | 2153 gfx::Vector2d expected_max_scroll(child->MaxScrollOffset()); |
2099 EXPECT_EQ(InputHandler::ScrollStarted, | 2154 EXPECT_EQ(InputHandler::ScrollStarted, |
2100 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2155 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2101 InputHandler::Wheel)); | 2156 InputHandler::Wheel)); |
2102 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2157 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2103 host_impl_->ScrollEnd(); | 2158 host_impl_->ScrollEnd(); |
2104 | 2159 |
2105 float page_scale = 2.f; | 2160 float page_scale = 2.f; |
2106 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, | 2161 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, |
2107 1.f, | 2162 1.f, |
2108 page_scale); | 2163 page_scale); |
2109 | 2164 |
2110 DrawOneFrame(); | 2165 DrawOneFrame(); |
2111 | 2166 |
2112 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 2167 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
2113 ExpectContains( | 2168 ExpectContains( |
2114 *scroll_info.get(), child_scroll_layer_id, expected_scroll_delta); | 2169 *scroll_info.get(), child_scroll_layer_id, expected_scroll_delta); |
2115 | 2170 |
2116 // The scroll range should not have changed. | 2171 // The scroll range should not have changed. |
2117 EXPECT_EQ(child->max_scroll_offset(), expected_max_scroll); | 2172 EXPECT_EQ(child->MaxScrollOffset(), expected_max_scroll); |
2118 | 2173 |
2119 // The page scale delta remains constant because the impl thread did not | 2174 // The page scale delta remains constant because the impl thread did not |
2120 // scale. | 2175 // scale. |
2121 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); | 2176 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
2122 } | 2177 } |
2123 | 2178 |
2124 TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { | 2179 TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { |
2125 // Scroll a child layer beyond its maximum scroll range and make sure the | 2180 // Scroll a child layer beyond its maximum scroll range and make sure the |
2126 // parent layer is scrolled on the axis on which the child was unable to | 2181 // parent layer is scrolled on the axis on which the child was unable to |
2127 // scroll. | 2182 // scroll. |
2128 gfx::Size surface_size(10, 10); | 2183 gfx::Size surface_size(10, 10); |
2129 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, surface_size); | 2184 gfx::Size content_size(20, 20); |
| 2185 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 2186 root->SetBounds(surface_size); |
2130 | 2187 |
2131 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(3, surface_size); | 2188 scoped_ptr<LayerImpl> grand_child = |
2132 grand_child->SetScrollOffset(gfx::Vector2d(0, 5)); | 2189 CreateScrollableLayer(3, content_size, root.get()); |
2133 | 2190 |
2134 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, surface_size); | 2191 scoped_ptr<LayerImpl> child = |
2135 child->SetScrollOffset(gfx::Vector2d(3, 0)); | 2192 CreateScrollableLayer(2, content_size, root.get()); |
| 2193 LayerImpl* grand_child_layer = grand_child.get(); |
2136 child->AddChild(grand_child.Pass()); | 2194 child->AddChild(grand_child.Pass()); |
2137 | 2195 |
| 2196 LayerImpl* child_layer = child.get(); |
2138 root->AddChild(child.Pass()); | 2197 root->AddChild(child.Pass()); |
2139 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2198 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
2140 host_impl_->active_tree()->DidBecomeActive(); | 2199 host_impl_->active_tree()->DidBecomeActive(); |
2141 host_impl_->SetViewportSize(surface_size); | 2200 host_impl_->SetViewportSize(surface_size); |
| 2201 |
| 2202 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 5)); |
| 2203 child_layer->SetScrollOffset(gfx::Vector2d(3, 0)); |
| 2204 |
2142 InitializeRendererAndDrawFrame(); | 2205 InitializeRendererAndDrawFrame(); |
2143 { | 2206 { |
2144 gfx::Vector2d scroll_delta(-8, -7); | 2207 gfx::Vector2d scroll_delta(-8, -7); |
2145 EXPECT_EQ(InputHandler::ScrollStarted, | 2208 EXPECT_EQ(InputHandler::ScrollStarted, |
2146 host_impl_->ScrollBegin(gfx::Point(), | 2209 host_impl_->ScrollBegin(gfx::Point(), |
2147 InputHandler::Wheel)); | 2210 InputHandler::Wheel)); |
2148 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2211 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2149 host_impl_->ScrollEnd(); | 2212 host_impl_->ScrollEnd(); |
2150 | 2213 |
2151 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2214 scoped_ptr<ScrollAndScaleSet> scroll_info = |
2152 host_impl_->ProcessScrollDeltas(); | 2215 host_impl_->ProcessScrollDeltas(); |
2153 | 2216 |
2154 // The grand child should have scrolled up to its limit. | 2217 // The grand child should have scrolled up to its limit. |
2155 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; | 2218 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; |
2156 LayerImpl* grand_child = child->children()[0]; | 2219 LayerImpl* grand_child = child->children()[0]; |
2157 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, -5)); | 2220 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, -5)); |
2158 | 2221 |
2159 // The child should have only scrolled on the other axis. | 2222 // The child should have only scrolled on the other axis. |
2160 ExpectContains(*scroll_info.get(), child->id(), gfx::Vector2d(-3, 0)); | 2223 ExpectContains(*scroll_info.get(), child->id(), gfx::Vector2d(-3, 0)); |
2161 } | 2224 } |
2162 } | 2225 } |
2163 | 2226 |
2164 TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { | 2227 TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { |
2165 // Scroll a child layer beyond its maximum scroll range and make sure the | 2228 // Scroll a child layer beyond its maximum scroll range and make sure the |
2166 // the scroll doesn't bubble up to the parent layer. | 2229 // the scroll doesn't bubble up to the parent layer. |
2167 gfx::Size surface_size(10, 10); | 2230 gfx::Size surface_size(20, 20); |
2168 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 2231 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
2169 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 2232 scoped_ptr<LayerImpl> root_scrolling = |
| 2233 CreateScrollableLayer(2, surface_size, root.get()); |
2170 | 2234 |
2171 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(4, surface_size); | 2235 scoped_ptr<LayerImpl> grand_child = |
2172 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); | 2236 CreateScrollableLayer(4, surface_size, root.get()); |
2173 | 2237 |
2174 scoped_ptr<LayerImpl> child = CreateScrollableLayer(3, surface_size); | 2238 scoped_ptr<LayerImpl> child = |
2175 child->SetScrollOffset(gfx::Vector2d(0, 3)); | 2239 CreateScrollableLayer(3, surface_size, root.get()); |
| 2240 LayerImpl* grand_child_layer = grand_child.get(); |
2176 child->AddChild(grand_child.Pass()); | 2241 child->AddChild(grand_child.Pass()); |
2177 | 2242 |
| 2243 LayerImpl* child_layer = child.get(); |
2178 root_scrolling->AddChild(child.Pass()); | 2244 root_scrolling->AddChild(child.Pass()); |
2179 root->AddChild(root_scrolling.Pass()); | 2245 root->AddChild(root_scrolling.Pass()); |
2180 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2246 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 2247 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
2181 host_impl_->active_tree()->DidBecomeActive(); | 2248 host_impl_->active_tree()->DidBecomeActive(); |
2182 host_impl_->SetViewportSize(surface_size); | 2249 host_impl_->SetViewportSize(surface_size); |
| 2250 |
| 2251 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 2)); |
| 2252 child_layer->SetScrollOffset(gfx::Vector2d(0, 3)); |
| 2253 |
2183 InitializeRendererAndDrawFrame(); | 2254 InitializeRendererAndDrawFrame(); |
2184 { | 2255 { |
2185 gfx::Vector2d scroll_delta(0, -10); | 2256 gfx::Vector2d scroll_delta(0, -10); |
2186 EXPECT_EQ(InputHandler::ScrollStarted, | 2257 EXPECT_EQ(InputHandler::ScrollStarted, |
2187 host_impl_->ScrollBegin(gfx::Point(), | 2258 host_impl_->ScrollBegin(gfx::Point(), |
2188 InputHandler::NonBubblingGesture)); | 2259 InputHandler::NonBubblingGesture)); |
2189 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2260 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2190 host_impl_->ScrollEnd(); | 2261 host_impl_->ScrollEnd(); |
2191 | 2262 |
2192 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2263 scoped_ptr<ScrollAndScaleSet> scroll_info = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2250 EXPECT_EQ(grand_child, host_impl_->CurrentlyScrollingLayer()); | 2321 EXPECT_EQ(grand_child, host_impl_->CurrentlyScrollingLayer()); |
2251 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2322 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2252 host_impl_->ScrollEnd(); | 2323 host_impl_->ScrollEnd(); |
2253 | 2324 |
2254 scroll_info = host_impl_->ProcessScrollDeltas(); | 2325 scroll_info = host_impl_->ProcessScrollDeltas(); |
2255 | 2326 |
2256 // Should have scrolled by half the amount in layer space (5 - 2/2) | 2327 // Should have scrolled by half the amount in layer space (5 - 2/2) |
2257 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, 4)); | 2328 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, 4)); |
2258 } | 2329 } |
2259 } | 2330 } |
2260 | |
2261 TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) { | 2331 TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) { |
2262 // When we try to scroll a non-scrollable child layer, the scroll delta | 2332 // When we try to scroll a non-scrollable child layer, the scroll delta |
2263 // should be applied to one of its ancestors if possible. | 2333 // should be applied to one of its ancestors if possible. |
2264 gfx::Size surface_size(10, 10); | 2334 gfx::Size surface_size(10, 10); |
2265 gfx::Size content_size(20, 20); | 2335 gfx::Size content_size(20, 20); |
2266 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 2336 scoped_ptr<LayerImpl> root_clip = |
2267 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 2337 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 2338 scoped_ptr<LayerImpl> root = |
| 2339 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 2340 // Make 'root' the clip layer for child: since they have the same sizes the |
| 2341 // child will have zero max_scroll_offset and scrolls will bubble. |
| 2342 scoped_ptr<LayerImpl> child = |
| 2343 CreateScrollableLayer(2, content_size, root.get()); |
| 2344 root->SetBounds(content_size); |
2268 | 2345 |
2269 child->SetScrollable(false); | 2346 int root_scroll_id = root->id(); |
2270 root->AddChild(child.Pass()); | 2347 root->AddChild(child.Pass()); |
| 2348 root_clip->AddChild(root.Pass()); |
2271 | 2349 |
2272 host_impl_->SetViewportSize(surface_size); | 2350 host_impl_->SetViewportSize(surface_size); |
2273 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2351 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 2352 host_impl_->active_tree()->SetViewportLayersFromIds(3, 2, Layer::INVALID_ID); |
2274 host_impl_->active_tree()->DidBecomeActive(); | 2353 host_impl_->active_tree()->DidBecomeActive(); |
2275 InitializeRendererAndDrawFrame(); | 2354 InitializeRendererAndDrawFrame(); |
2276 { | 2355 { |
2277 gfx::Vector2d scroll_delta(0, 4); | 2356 gfx::Vector2d scroll_delta(0, 4); |
2278 EXPECT_EQ(InputHandler::ScrollStarted, | 2357 EXPECT_EQ(InputHandler::ScrollStarted, |
2279 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2358 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2280 InputHandler::Wheel)); | 2359 InputHandler::Wheel)); |
2281 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2360 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2282 host_impl_->ScrollEnd(); | 2361 host_impl_->ScrollEnd(); |
2283 | 2362 |
2284 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2363 scoped_ptr<ScrollAndScaleSet> scroll_info = |
2285 host_impl_->ProcessScrollDeltas(); | 2364 host_impl_->ProcessScrollDeltas(); |
2286 | 2365 |
2287 // Only the root should have scrolled. | 2366 // Only the root scroll should have scrolled. |
2288 ASSERT_EQ(scroll_info->scrolls.size(), 1u); | 2367 ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
2289 ExpectContains(*scroll_info.get(), | 2368 ExpectContains(*scroll_info.get(), root_scroll_id, scroll_delta); |
2290 host_impl_->active_tree()->root_layer()->id(), | |
2291 scroll_delta); | |
2292 } | 2369 } |
2293 } | 2370 } |
2294 | 2371 |
2295 TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { | 2372 TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { |
2296 gfx::Size surface_size(10, 10); | 2373 gfx::Size surface_size(10, 10); |
2297 host_impl_->active_tree()->SetRootLayer( | 2374 scoped_ptr<LayerImpl> root_clip = |
2298 CreateScrollableLayer(1, surface_size)); | 2375 LayerImpl::Create(host_impl_->active_tree(), 1); |
| 2376 scoped_ptr<LayerImpl> root_scroll = |
| 2377 CreateScrollableLayer(2, surface_size, root_clip.get()); |
| 2378 root_clip->AddChild(root_scroll.Pass()); |
| 2379 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 2380 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
2299 host_impl_->active_tree()->DidBecomeActive(); | 2381 host_impl_->active_tree()->DidBecomeActive(); |
2300 host_impl_->SetViewportSize(surface_size); | 2382 host_impl_->SetViewportSize(surface_size); |
2301 | 2383 |
2302 // Draw one frame and then immediately rebuild the layer tree to mimic a tree | 2384 // Draw one frame and then immediately rebuild the layer tree to mimic a tree |
2303 // synchronization. | 2385 // synchronization. |
2304 InitializeRendererAndDrawFrame(); | 2386 InitializeRendererAndDrawFrame(); |
2305 host_impl_->active_tree()->DetachLayerTree(); | 2387 host_impl_->active_tree()->DetachLayerTree(); |
2306 host_impl_->active_tree()->SetRootLayer( | 2388 scoped_ptr<LayerImpl> root_clip2 = |
2307 CreateScrollableLayer(2, surface_size)); | 2389 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 2390 scoped_ptr<LayerImpl> root_scroll2 = |
| 2391 CreateScrollableLayer(4, surface_size, root_clip2.get()); |
| 2392 root_clip2->AddChild(root_scroll2.Pass()); |
| 2393 host_impl_->active_tree()->SetRootLayer(root_clip2.Pass()); |
| 2394 host_impl_->active_tree()->SetViewportLayersFromIds(3, 4, Layer::INVALID_ID); |
2308 host_impl_->active_tree()->DidBecomeActive(); | 2395 host_impl_->active_tree()->DidBecomeActive(); |
2309 | 2396 |
2310 // Scrolling should still work even though we did not draw yet. | 2397 // Scrolling should still work even though we did not draw yet. |
2311 EXPECT_EQ(InputHandler::ScrollStarted, | 2398 EXPECT_EQ(InputHandler::ScrollStarted, |
2312 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2399 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2313 InputHandler::Wheel)); | 2400 InputHandler::Wheel)); |
2314 } | 2401 } |
2315 | 2402 |
2316 TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { | 2403 TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { |
2317 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2404 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2350 | 2437 |
2351 // The layer should have scrolled down in its local coordinates. | 2438 // The layer should have scrolled down in its local coordinates. |
2352 scroll_info = host_impl_->ProcessScrollDeltas(); | 2439 scroll_info = host_impl_->ProcessScrollDeltas(); |
2353 ExpectContains(*scroll_info.get(), | 2440 ExpectContains(*scroll_info.get(), |
2354 scroll_layer->id(), | 2441 scroll_layer->id(), |
2355 wheel_scroll_delta); | 2442 wheel_scroll_delta); |
2356 } | 2443 } |
2357 | 2444 |
2358 TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { | 2445 TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { |
2359 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2446 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
2360 int child_layer_id = 4; | 2447 int child_layer_id = 6; |
2361 float child_layer_angle = -20.f; | 2448 float child_layer_angle = -20.f; |
2362 | 2449 |
2363 // Create a child layer that is rotated to a non-axis-aligned angle. | 2450 // Create a child layer that is rotated to a non-axis-aligned angle. |
2364 scoped_ptr<LayerImpl> child = CreateScrollableLayer( | 2451 scoped_ptr<LayerImpl> child = CreateScrollableLayer( |
2365 child_layer_id, | 2452 child_layer_id, |
2366 scroll_layer->content_bounds()); | 2453 scroll_layer->content_bounds(), host_impl_->active_tree()->root_layer()); |
2367 gfx::Transform rotate_transform; | 2454 gfx::Transform rotate_transform; |
2368 rotate_transform.Translate(-50.0, -50.0); | 2455 rotate_transform.Translate(-50.0, -50.0); |
2369 rotate_transform.Rotate(child_layer_angle); | 2456 rotate_transform.Rotate(child_layer_angle); |
2370 rotate_transform.Translate(50.0, 50.0); | 2457 rotate_transform.Translate(50.0, 50.0); |
2371 child->SetTransform(rotate_transform); | 2458 child->SetTransform(rotate_transform); |
2372 | 2459 |
2373 // Only allow vertical scrolling. | 2460 // Only allow vertical scrolling. |
2374 child->SetMaxScrollOffset(gfx::Vector2d(0, child->content_bounds().height())); | 2461 // child->SetMaxScrollOffset(gfx::Vector2d(0, child->content_bounds().height())
); // WJM |
2375 scroll_layer->AddChild(child.Pass()); | 2462 scroll_layer->AddChild(child.Pass()); |
2376 | 2463 |
2377 gfx::Size surface_size(50, 50); | 2464 gfx::Size surface_size(50, 50); |
2378 host_impl_->SetViewportSize(surface_size); | 2465 host_impl_->SetViewportSize(surface_size); |
2379 InitializeRendererAndDrawFrame(); | 2466 InitializeRendererAndDrawFrame(); |
2380 { | 2467 { |
2381 // Scroll down in screen coordinates with a gesture. | 2468 // Scroll down in screen coordinates with a gesture. |
2382 gfx::Vector2d gesture_scroll_delta(0, 10); | 2469 gfx::Vector2d gesture_scroll_delta(0, 10); |
2383 EXPECT_EQ(InputHandler::ScrollStarted, | 2470 EXPECT_EQ(InputHandler::ScrollStarted, |
2384 host_impl_->ScrollBegin(gfx::Point(1, 1), | 2471 host_impl_->ScrollBegin(gfx::Point(1, 1), |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2529 gfx::Vector2dF getter_return_value_; | 2616 gfx::Vector2dF getter_return_value_; |
2530 gfx::Vector2dF max_scroll_offset_; | 2617 gfx::Vector2dF max_scroll_offset_; |
2531 gfx::SizeF scrollable_size_; | 2618 gfx::SizeF scrollable_size_; |
2532 float page_scale_factor_; | 2619 float page_scale_factor_; |
2533 }; | 2620 }; |
2534 | 2621 |
2535 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { | 2622 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { |
2536 TestScrollOffsetDelegate scroll_delegate; | 2623 TestScrollOffsetDelegate scroll_delegate; |
2537 host_impl_->SetViewportSize(gfx::Size(10, 20)); | 2624 host_impl_->SetViewportSize(gfx::Size(10, 20)); |
2538 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2625 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2626 LayerImpl* clip_layer = scroll_layer->parent()->parent(); |
| 2627 clip_layer->SetBounds(gfx::Size(10, 20)); |
2539 | 2628 |
2540 // Setting the delegate results in the current scroll offset being set. | 2629 // Setting the delegate results in the current scroll offset being set. |
2541 gfx::Vector2dF initial_scroll_delta(10.f, 10.f); | 2630 gfx::Vector2dF initial_scroll_delta(10.f, 10.f); |
2542 scroll_layer->SetScrollOffset(gfx::Vector2d()); | 2631 scroll_layer->SetScrollOffset(gfx::Vector2d()); |
2543 scroll_layer->SetScrollDelta(initial_scroll_delta); | 2632 scroll_layer->SetScrollDelta(initial_scroll_delta); |
2544 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate); | 2633 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate); |
2545 EXPECT_EQ(initial_scroll_delta.ToString(), | 2634 EXPECT_EQ(initial_scroll_delta.ToString(), |
2546 scroll_delegate.last_set_scroll_offset().ToString()); | 2635 scroll_delegate.last_set_scroll_offset().ToString()); |
2547 | 2636 |
2548 // Setting the delegate results in the scrollable_size, max_scroll_offset and | 2637 // Setting the delegate results in the scrollable_size, max_scroll_offset and |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2652 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 2741 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
2653 EXPECT_EQ(gfx::Vector2dF(0, -20), host_impl_->accumulated_root_overscroll()); | 2742 EXPECT_EQ(gfx::Vector2dF(0, -20), host_impl_->accumulated_root_overscroll()); |
2654 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); | 2743 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); |
2655 } | 2744 } |
2656 | 2745 |
2657 | 2746 |
2658 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { | 2747 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { |
2659 // Scroll child layers beyond their maximum scroll range and make sure root | 2748 // Scroll child layers beyond their maximum scroll range and make sure root |
2660 // overscroll does not accumulate. | 2749 // overscroll does not accumulate. |
2661 gfx::Size surface_size(10, 10); | 2750 gfx::Size surface_size(10, 10); |
2662 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, surface_size); | 2751 scoped_ptr<LayerImpl> root_clip = |
| 2752 LayerImpl::Create(host_impl_->active_tree(), 4); |
| 2753 scoped_ptr<LayerImpl> root = |
| 2754 CreateScrollableLayer(1, surface_size, root_clip.get()); |
2663 | 2755 |
2664 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(3, surface_size); | 2756 scoped_ptr<LayerImpl> grand_child = |
2665 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); | 2757 CreateScrollableLayer(3, surface_size, root_clip.get()); |
2666 | 2758 |
2667 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, surface_size); | 2759 scoped_ptr<LayerImpl> child = |
2668 child->SetScrollOffset(gfx::Vector2d(0, 3)); | 2760 CreateScrollableLayer(2, surface_size, root_clip.get()); |
| 2761 LayerImpl* grand_child_layer = grand_child.get(); |
2669 child->AddChild(grand_child.Pass()); | 2762 child->AddChild(grand_child.Pass()); |
2670 | 2763 |
| 2764 LayerImpl* child_layer = child.get(); |
2671 root->AddChild(child.Pass()); | 2765 root->AddChild(child.Pass()); |
2672 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2766 root_clip->AddChild(root.Pass()); |
| 2767 child_layer->SetScrollOffset(gfx::Vector2d(0, 3)); |
| 2768 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 2)); |
| 2769 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
2673 host_impl_->active_tree()->DidBecomeActive(); | 2770 host_impl_->active_tree()->DidBecomeActive(); |
2674 host_impl_->SetViewportSize(surface_size); | 2771 host_impl_->SetViewportSize(surface_size); |
2675 InitializeRendererAndDrawFrame(); | 2772 InitializeRendererAndDrawFrame(); |
2676 { | 2773 { |
2677 gfx::Vector2d scroll_delta(0, -10); | 2774 gfx::Vector2d scroll_delta(0, -10); |
2678 EXPECT_EQ(InputHandler::ScrollStarted, | 2775 EXPECT_EQ(InputHandler::ScrollStarted, |
2679 host_impl_->ScrollBegin(gfx::Point(), | 2776 host_impl_->ScrollBegin(gfx::Point(), |
2680 InputHandler::NonBubblingGesture)); | 2777 InputHandler::NonBubblingGesture)); |
2681 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2778 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2682 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2779 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2683 host_impl_->ScrollEnd(); | 2780 host_impl_->ScrollEnd(); |
2684 | 2781 |
2685 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; | |
2686 LayerImpl* grand_child = child->children()[0]; | |
2687 | |
2688 // The next time we scroll we should only scroll the parent, but overscroll | 2782 // The next time we scroll we should only scroll the parent, but overscroll |
2689 // should still not reach the root layer. | 2783 // should still not reach the root layer. |
2690 scroll_delta = gfx::Vector2d(0, -30); | 2784 scroll_delta = gfx::Vector2d(0, -30); |
2691 EXPECT_EQ(InputHandler::ScrollStarted, | 2785 EXPECT_EQ(InputHandler::ScrollStarted, |
2692 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2786 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2693 InputHandler::NonBubblingGesture)); | 2787 InputHandler::NonBubblingGesture)); |
2694 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 2788 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
2695 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2789 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2696 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2790 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2697 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); | 2791 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_layer); |
2698 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2792 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2699 host_impl_->ScrollEnd(); | 2793 host_impl_->ScrollEnd(); |
2700 | 2794 |
2701 // After scrolling the parent, another scroll on the opposite direction | 2795 // After scrolling the parent, another scroll on the opposite direction |
2702 // should scroll the child, resetting the fling velocity. | 2796 // should scroll the child, resetting the fling velocity. |
2703 scroll_delta = gfx::Vector2d(0, 70); | 2797 scroll_delta = gfx::Vector2d(0, 70); |
2704 host_impl_->NotifyCurrentFlingVelocity(gfx::Vector2dF(10, 0)); | 2798 host_impl_->NotifyCurrentFlingVelocity(gfx::Vector2dF(10, 0)); |
2705 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); | 2799 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); |
2706 EXPECT_EQ(InputHandler::ScrollStarted, | 2800 EXPECT_EQ(InputHandler::ScrollStarted, |
2707 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2801 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2708 InputHandler::NonBubblingGesture)); | 2802 InputHandler::NonBubblingGesture)); |
2709 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 2803 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
2710 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2804 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2711 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 2805 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
2712 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2806 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2713 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | 2807 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
2714 host_impl_->ScrollEnd(); | 2808 host_impl_->ScrollEnd(); |
2715 } | 2809 } |
2716 } | 2810 } |
2717 | 2811 |
2718 TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { | 2812 TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { |
2719 // When we try to scroll a non-scrollable child layer, the scroll delta | 2813 // When we try to scroll a non-scrollable child layer, the scroll delta |
2720 // should be applied to one of its ancestors if possible. Overscroll should | 2814 // should be applied to one of its ancestors if possible. Overscroll should |
2721 // be reflected only when it has bubbled up to the root scrolling layer. | 2815 // be reflected only when it has bubbled up to the root scrolling layer. |
2722 gfx::Size surface_size(10, 10); | 2816 gfx::Size surface_size(10, 10); |
2723 gfx::Size content_size(20, 20); | 2817 gfx::Size content_size(20, 20); |
2724 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 2818 scoped_ptr<LayerImpl> root_clip = |
2725 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 2819 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 2820 scoped_ptr<LayerImpl> root = |
| 2821 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 2822 scoped_ptr<LayerImpl> child = |
| 2823 CreateScrollableLayer(2, content_size, root_clip.get()); |
2726 | 2824 |
2727 child->SetScrollable(false); | 2825 child->SetScrollable(Layer::INVALID_ID); |
2728 root->AddChild(child.Pass()); | 2826 root->AddChild(child.Pass()); |
| 2827 root_clip->AddChild(root.Pass()); |
2729 | 2828 |
2730 host_impl_->SetViewportSize(surface_size); | 2829 host_impl_->SetViewportSize(surface_size); |
2731 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2830 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 2831 host_impl_->active_tree()->SetViewportLayersFromIds(3, 1, Layer::INVALID_ID); |
2732 host_impl_->active_tree()->DidBecomeActive(); | 2832 host_impl_->active_tree()->DidBecomeActive(); |
2733 InitializeRendererAndDrawFrame(); | 2833 InitializeRendererAndDrawFrame(); |
2734 { | 2834 { |
2735 gfx::Vector2d scroll_delta(0, 8); | 2835 gfx::Vector2d scroll_delta(0, 8); |
2736 EXPECT_EQ(InputHandler::ScrollStarted, | 2836 EXPECT_EQ(InputHandler::ScrollStarted, |
2737 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2837 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2738 InputHandler::Wheel)); | 2838 InputHandler::Wheel)); |
2739 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2839 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2740 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2840 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2741 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2841 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2742 EXPECT_EQ(gfx::Vector2dF(0, 6), host_impl_->accumulated_root_overscroll()); | 2842 EXPECT_EQ(gfx::Vector2dF(0, 6), host_impl_->accumulated_root_overscroll()); |
2743 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2843 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2744 EXPECT_EQ(gfx::Vector2dF(0, 14), host_impl_->accumulated_root_overscroll()); | 2844 EXPECT_EQ(gfx::Vector2dF(0, 14), host_impl_->accumulated_root_overscroll()); |
2745 host_impl_->ScrollEnd(); | 2845 host_impl_->ScrollEnd(); |
2746 } | 2846 } |
2747 } | 2847 } |
2748 | 2848 |
2749 TEST_F(LayerTreeHostImplTest, OverscrollAlways) { | 2849 TEST_F(LayerTreeHostImplTest, OverscrollAlways) { |
2750 LayerTreeSettings settings; | 2850 LayerTreeSettings settings; |
2751 settings.always_overscroll = true; | 2851 settings.always_overscroll = true; |
2752 host_impl_ = LayerTreeHostImpl::Create( | 2852 host_impl_ = LayerTreeHostImpl::Create( |
2753 settings, this, &proxy_, &stats_instrumentation_, NULL); | 2853 settings, this, &proxy_, &stats_instrumentation_, NULL); |
2754 | 2854 |
2755 SetupScrollAndContentsLayers(gfx::Size(50, 50)); | 2855 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); |
| 2856 LayerImpl* clip_layer = scroll_layer->parent()->parent(); |
| 2857 clip_layer->SetBounds(gfx::Size(50, 50)); |
2756 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 2858 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
2757 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 2859 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
2758 InitializeRendererAndDrawFrame(); | 2860 InitializeRendererAndDrawFrame(); |
2759 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2861 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2760 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | 2862 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
2761 | 2863 |
2762 // Even though the layer can't scroll the overscroll still happens. | 2864 // Even though the layer can't scroll the overscroll still happens. |
2763 EXPECT_EQ(InputHandler::ScrollStarted, | 2865 EXPECT_EQ(InputHandler::ScrollStarted, |
2764 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 2866 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
2765 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 2867 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
(...skipping 2151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4917 scoped_ptr<FakePictureLayerImpl> scoped_content_layer = | 5019 scoped_ptr<FakePictureLayerImpl> scoped_content_layer = |
4918 FakePictureLayerImpl::CreateWithPile(host_impl_->pending_tree(), 3, pile); | 5020 FakePictureLayerImpl::CreateWithPile(host_impl_->pending_tree(), 3, pile); |
4919 LayerImpl* content_layer = scoped_content_layer.get(); | 5021 LayerImpl* content_layer = scoped_content_layer.get(); |
4920 scrolling_layer->AddChild(scoped_content_layer.PassAs<LayerImpl>()); | 5022 scrolling_layer->AddChild(scoped_content_layer.PassAs<LayerImpl>()); |
4921 content_layer->SetBounds(content_layer_bounds); | 5023 content_layer->SetBounds(content_layer_bounds); |
4922 content_layer->SetDrawsContent(true); | 5024 content_layer->SetDrawsContent(true); |
4923 | 5025 |
4924 root->SetBounds(root_size); | 5026 root->SetBounds(root_size); |
4925 | 5027 |
4926 gfx::Vector2d scroll_offset(100000, 0); | 5028 gfx::Vector2d scroll_offset(100000, 0); |
4927 scrolling_layer->SetScrollable(true); | 5029 scrolling_layer->SetScrollable(root->id()); |
4928 scrolling_layer->SetMaxScrollOffset(scroll_offset); | |
4929 scrolling_layer->SetScrollOffset(scroll_offset); | 5030 scrolling_layer->SetScrollOffset(scroll_offset); |
4930 | 5031 |
4931 host_impl_->ActivatePendingTree(); | 5032 host_impl_->ActivatePendingTree(); |
4932 | 5033 |
4933 host_impl_->active_tree()->UpdateDrawProperties(); | 5034 host_impl_->active_tree()->UpdateDrawProperties(); |
4934 ASSERT_EQ(1u, host_impl_->active_tree()->RenderSurfaceLayerList().size()); | 5035 ASSERT_EQ(1u, host_impl_->active_tree()->RenderSurfaceLayerList().size()); |
4935 | 5036 |
4936 LayerTreeHostImpl::FrameData frame; | 5037 LayerTreeHostImpl::FrameData frame; |
4937 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 5038 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
4938 | 5039 |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5346 // released, and the texture deleted. | 5447 // released, and the texture deleted. |
5347 EXPECT_TRUE(context_provider->HasOneRef()); | 5448 EXPECT_TRUE(context_provider->HasOneRef()); |
5348 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); | 5449 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); |
5349 } | 5450 } |
5350 | 5451 |
5351 TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { | 5452 TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { |
5352 // When flinging via touch, only the child should scroll (we should not | 5453 // When flinging via touch, only the child should scroll (we should not |
5353 // bubble). | 5454 // bubble). |
5354 gfx::Size surface_size(10, 10); | 5455 gfx::Size surface_size(10, 10); |
5355 gfx::Size content_size(20, 20); | 5456 gfx::Size content_size(20, 20); |
5356 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 5457 scoped_ptr<LayerImpl> root_clip = |
5357 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 5458 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 5459 scoped_ptr<LayerImpl> root_scroll = |
| 5460 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 5461 int root_scroll_id = root_scroll->id(); |
| 5462 scoped_ptr<LayerImpl> child = |
| 5463 CreateScrollableLayer(2, content_size, root_clip.get()); |
5358 | 5464 |
5359 root->AddChild(child.Pass()); | 5465 root_scroll->AddChild(child.Pass()); |
| 5466 root_clip->AddChild(root_scroll.Pass()); |
5360 | 5467 |
5361 host_impl_->SetViewportSize(surface_size); | 5468 host_impl_->SetViewportSize(surface_size); |
5362 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 5469 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
5363 host_impl_->active_tree()->DidBecomeActive(); | 5470 host_impl_->active_tree()->DidBecomeActive(); |
5364 InitializeRendererAndDrawFrame(); | 5471 InitializeRendererAndDrawFrame(); |
5365 { | 5472 { |
5366 EXPECT_EQ(InputHandler::ScrollStarted, | 5473 EXPECT_EQ(InputHandler::ScrollStarted, |
5367 host_impl_->ScrollBegin(gfx::Point(), | 5474 host_impl_->ScrollBegin(gfx::Point(), |
5368 InputHandler::Gesture)); | 5475 InputHandler::Gesture)); |
5369 | 5476 |
5370 EXPECT_EQ(InputHandler::ScrollStarted, | 5477 EXPECT_EQ(InputHandler::ScrollStarted, |
5371 host_impl_->FlingScrollBegin()); | 5478 host_impl_->FlingScrollBegin()); |
5372 | 5479 |
5373 gfx::Vector2d scroll_delta(0, 100); | 5480 gfx::Vector2d scroll_delta(0, 100); |
5374 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5481 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5375 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5482 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5376 | 5483 |
5377 host_impl_->ScrollEnd(); | 5484 host_impl_->ScrollEnd(); |
5378 | 5485 |
5379 scoped_ptr<ScrollAndScaleSet> scroll_info = | 5486 scoped_ptr<ScrollAndScaleSet> scroll_info = |
5380 host_impl_->ProcessScrollDeltas(); | 5487 host_impl_->ProcessScrollDeltas(); |
5381 | 5488 |
5382 // Only the child should have scrolled. | 5489 // Only the child should have scrolled. |
5383 ASSERT_EQ(1u, scroll_info->scrolls.size()); | 5490 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
5384 ExpectNone(*scroll_info.get(), | 5491 ExpectNone(*scroll_info.get(), root_scroll_id); |
5385 host_impl_->active_tree()->root_layer()->id()); | |
5386 } | 5492 } |
5387 } | 5493 } |
5388 | 5494 |
5389 TEST_F(LayerTreeHostImplTest, TouchFlingShouldBubbleIfPrecedingScrollBubbled) { | 5495 TEST_F(LayerTreeHostImplTest, TouchFlingShouldBubbleIfPrecedingScrollBubbled) { |
5390 // When flinging via touch, bubble scrolls if the touch scroll | 5496 // When flinging via touch, bubble scrolls if the touch scroll |
5391 // immediately preceding the fling bubbled. | 5497 // immediately preceding the fling bubbled. |
5392 gfx::Size surface_size(10, 10); | 5498 gfx::Size surface_size(10, 10); |
5393 gfx::Size root_content_size(10, 20); | 5499 gfx::Size root_content_size(10, 20); |
5394 gfx::Size child_content_size(40, 40); | 5500 gfx::Size child_content_size(40, 40); |
5395 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, root_content_size); | |
5396 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, child_content_size); | |
5397 | 5501 |
5398 root->AddChild(child.Pass()); | 5502 scoped_ptr<LayerImpl> root_clip = |
| 5503 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 5504 scoped_ptr<LayerImpl> root_scroll = |
| 5505 CreateScrollableLayer(1, root_content_size, root_clip.get()); |
| 5506 int root_scroll_id = root_scroll->id(); |
| 5507 scoped_ptr<LayerImpl> child = |
| 5508 CreateScrollableLayer(2, child_content_size, root_clip.get()); |
| 5509 root_clip->SetBounds(surface_size); |
| 5510 |
| 5511 root_scroll->AddChild(child.Pass()); |
| 5512 root_clip->AddChild(root_scroll.Pass()); |
5399 | 5513 |
5400 host_impl_->SetViewportSize(surface_size); | 5514 host_impl_->SetViewportSize(surface_size); |
5401 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 5515 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
5402 host_impl_->active_tree()->DidBecomeActive(); | 5516 host_impl_->active_tree()->DidBecomeActive(); |
5403 InitializeRendererAndDrawFrame(); | 5517 InitializeRendererAndDrawFrame(); |
5404 { | 5518 { |
5405 EXPECT_EQ(InputHandler::ScrollStarted, | 5519 EXPECT_EQ(InputHandler::ScrollStarted, |
5406 host_impl_->ScrollBegin(gfx::Point(), | 5520 host_impl_->ScrollBegin(gfx::Point(), |
5407 InputHandler::Gesture)); | 5521 InputHandler::Gesture)); |
5408 | 5522 |
5409 // Touch scroll before starting the fling. The second scroll should bubble. | 5523 // Touch scroll before starting the fling. The second scroll should bubble. |
5410 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 100))); | 5524 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 100))); |
5411 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 5))); | 5525 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 5))); |
5412 | 5526 |
5413 scoped_ptr<ScrollAndScaleSet> scroll_info = | 5527 scoped_ptr<ScrollAndScaleSet> scroll_info = |
5414 host_impl_->ProcessScrollDeltas(); | 5528 host_impl_->ProcessScrollDeltas(); |
5415 | 5529 |
5416 // The root should have (partially) scrolled. | 5530 // The root should have (partially) scrolled. |
5417 EXPECT_EQ(2u, scroll_info->scrolls.size()); | 5531 EXPECT_EQ(2u, scroll_info->scrolls.size()); |
5418 ExpectContains(*scroll_info.get(), | 5532 ExpectContains(*scroll_info.get(), root_scroll_id, gfx::Vector2d(0, 5)); |
5419 host_impl_->active_tree()->root_layer()->id(), | |
5420 gfx::Vector2d(0, 5)); | |
5421 | 5533 |
5422 EXPECT_EQ(InputHandler::ScrollStarted, | 5534 EXPECT_EQ(InputHandler::ScrollStarted, |
5423 host_impl_->FlingScrollBegin()); | 5535 host_impl_->FlingScrollBegin()); |
5424 | 5536 |
5425 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 5))); | 5537 EXPECT_TRUE(host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 5))); |
5426 host_impl_->ScrollEnd(); | 5538 host_impl_->ScrollEnd(); |
5427 | 5539 |
5428 // The root should have (fully) scrolled from the fling. | 5540 // The root should have (fully) scrolled from the fling. |
5429 scroll_info = host_impl_->ProcessScrollDeltas(); | 5541 scroll_info = host_impl_->ProcessScrollDeltas(); |
5430 EXPECT_EQ(2u, scroll_info->scrolls.size()); | 5542 EXPECT_EQ(2u, scroll_info->scrolls.size()); |
5431 ExpectContains(*scroll_info.get(), | 5543 ExpectContains(*scroll_info.get(), root_scroll_id, gfx::Vector2d(0, 10)); |
5432 host_impl_->active_tree()->root_layer()->id(), | |
5433 gfx::Vector2d(0, 10)); | |
5434 } | 5544 } |
5435 } | 5545 } |
5436 | 5546 |
5437 TEST_F(LayerTreeHostImplTest, WheelFlingShouldBubble) { | 5547 TEST_F(LayerTreeHostImplTest, WheelFlingShouldBubble) { |
5438 // When flinging via wheel, the root should eventually scroll (we should | 5548 // When flinging via wheel, the root should eventually scroll (we should |
5439 // bubble). | 5549 // bubble). |
5440 gfx::Size surface_size(10, 10); | 5550 gfx::Size surface_size(10, 10); |
5441 gfx::Size content_size(20, 20); | 5551 gfx::Size content_size(20, 20); |
5442 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 5552 scoped_ptr<LayerImpl> root_clip = |
5443 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 5553 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 5554 scoped_ptr<LayerImpl> root = |
| 5555 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 5556 scoped_ptr<LayerImpl> child = |
| 5557 CreateScrollableLayer(2, content_size, root_clip.get()); |
5444 | 5558 |
5445 root->AddChild(child.Pass()); | 5559 root->AddChild(child.Pass()); |
| 5560 int root_id = root->id(); |
| 5561 root_clip->AddChild(root.Pass()); |
5446 | 5562 |
5447 host_impl_->SetViewportSize(surface_size); | 5563 host_impl_->SetViewportSize(surface_size); |
5448 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 5564 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 5565 host_impl_->active_tree()->SetViewportLayersFromIds(3, 1, Layer::INVALID_ID); |
5449 host_impl_->active_tree()->DidBecomeActive(); | 5566 host_impl_->active_tree()->DidBecomeActive(); |
5450 InitializeRendererAndDrawFrame(); | 5567 InitializeRendererAndDrawFrame(); |
5451 { | 5568 { |
5452 EXPECT_EQ(InputHandler::ScrollStarted, | 5569 EXPECT_EQ(InputHandler::ScrollStarted, |
5453 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 5570 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
5454 | 5571 |
5455 EXPECT_EQ(InputHandler::ScrollStarted, | 5572 EXPECT_EQ(InputHandler::ScrollStarted, |
5456 host_impl_->FlingScrollBegin()); | 5573 host_impl_->FlingScrollBegin()); |
5457 | 5574 |
5458 gfx::Vector2d scroll_delta(0, 100); | 5575 gfx::Vector2d scroll_delta(0, 100); |
5459 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5576 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5460 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5577 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5461 | 5578 |
5462 host_impl_->ScrollEnd(); | 5579 host_impl_->ScrollEnd(); |
5463 | 5580 |
5464 scoped_ptr<ScrollAndScaleSet> scroll_info = | 5581 scoped_ptr<ScrollAndScaleSet> scroll_info = |
5465 host_impl_->ProcessScrollDeltas(); | 5582 host_impl_->ProcessScrollDeltas(); |
5466 | 5583 |
5467 // The root should have scrolled. | 5584 // The root should have scrolled. |
5468 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 5585 ASSERT_EQ(2u, scroll_info->scrolls.size()); |
5469 ExpectContains(*scroll_info.get(), | 5586 ExpectContains(*scroll_info.get(), root_id, gfx::Vector2d(0, 10)); |
5470 host_impl_->active_tree()->root_layer()->id(), | |
5471 gfx::Vector2d(0, 10)); | |
5472 } | 5587 } |
5473 } | 5588 } |
5474 | |
5475 } // namespace | 5589 } // namespace |
5476 } // namespace cc | 5590 } // namespace cc |
OLD | NEW |