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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (scroll_info.scrolls[i].layer_id != id) | 197 if (scroll_info.scrolls[i].layer_id != id) |
198 continue; | 198 continue; |
199 times_encountered++; | 199 times_encountered++; |
200 } | 200 } |
201 | 201 |
202 ASSERT_EQ(0, times_encountered); | 202 ASSERT_EQ(0, times_encountered); |
203 } | 203 } |
204 | 204 |
205 LayerImpl* CreateScrollAndContentsLayers(LayerTreeImpl* layer_tree_impl, | 205 LayerImpl* CreateScrollAndContentsLayers(LayerTreeImpl* layer_tree_impl, |
206 gfx::Size content_size) { | 206 gfx::Size content_size) { |
| 207 const int kInnerViewportScrollLayerId = 2; |
| 208 const int kInnerViewportClipLayerId = 4; |
| 209 const int kPageScaleLayerId = 5; |
207 scoped_ptr<LayerImpl> root = | 210 scoped_ptr<LayerImpl> root = |
208 LayerImpl::Create(layer_tree_impl, 1); | 211 LayerImpl::Create(layer_tree_impl, 1); |
209 root->SetBounds(content_size); | 212 root->SetBounds(content_size); |
210 root->SetContentBounds(content_size); | 213 root->SetContentBounds(content_size); |
211 root->SetPosition(gfx::PointF()); | 214 root->SetPosition(gfx::PointF()); |
212 root->SetAnchorPoint(gfx::PointF()); | 215 root->SetAnchorPoint(gfx::PointF()); |
213 | 216 |
214 scoped_ptr<LayerImpl> scroll = | 217 scoped_ptr<LayerImpl> scroll = |
215 LayerImpl::Create(layer_tree_impl, 2); | 218 LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); |
216 LayerImpl* scroll_layer = scroll.get(); | 219 LayerImpl* scroll_layer = scroll.get(); |
217 scroll->SetScrollable(true); | |
218 scroll->SetScrollOffset(gfx::Vector2d()); | 220 scroll->SetScrollOffset(gfx::Vector2d()); |
219 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | 221 |
220 content_size.height())); | 222 scoped_ptr<LayerImpl> clip = |
| 223 LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); |
| 224 clip->SetBounds( |
| 225 gfx::Size(content_size.width() / 2, content_size.height() / 2)); |
| 226 |
| 227 scoped_ptr<LayerImpl> page_scale = |
| 228 LayerImpl::Create(layer_tree_impl, kPageScaleLayerId); |
| 229 |
| 230 scroll->SetScrollClipLayer(clip->id()); |
221 scroll->SetBounds(content_size); | 231 scroll->SetBounds(content_size); |
222 scroll->SetContentBounds(content_size); | 232 scroll->SetContentBounds(content_size); |
223 scroll->SetPosition(gfx::PointF()); | 233 scroll->SetPosition(gfx::PointF()); |
224 scroll->SetAnchorPoint(gfx::PointF()); | 234 scroll->SetAnchorPoint(gfx::PointF()); |
225 | 235 |
226 scoped_ptr<LayerImpl> contents = | 236 scoped_ptr<LayerImpl> contents = |
227 LayerImpl::Create(layer_tree_impl, 3); | 237 LayerImpl::Create(layer_tree_impl, 3); |
228 contents->SetDrawsContent(true); | 238 contents->SetDrawsContent(true); |
229 contents->SetBounds(content_size); | 239 contents->SetBounds(content_size); |
230 contents->SetContentBounds(content_size); | 240 contents->SetContentBounds(content_size); |
231 contents->SetPosition(gfx::PointF()); | 241 contents->SetPosition(gfx::PointF()); |
232 contents->SetAnchorPoint(gfx::PointF()); | 242 contents->SetAnchorPoint(gfx::PointF()); |
233 | 243 |
234 scroll->AddChild(contents.Pass()); | 244 scroll->AddChild(contents.Pass()); |
235 root->AddChild(scroll.Pass()); | 245 page_scale->AddChild(scroll.Pass()); |
| 246 clip->AddChild(page_scale.Pass()); |
| 247 root->AddChild(clip.Pass()); |
236 | 248 |
237 layer_tree_impl->SetRootLayer(root.Pass()); | 249 layer_tree_impl->SetRootLayer(root.Pass()); |
| 250 layer_tree_impl->SetViewportLayersFromIds( |
| 251 kPageScaleLayerId, kInnerViewportScrollLayerId, Layer::INVALID_ID); |
| 252 |
238 return scroll_layer; | 253 return scroll_layer; |
239 } | 254 } |
240 | 255 |
241 LayerImpl* SetupScrollAndContentsLayers(gfx::Size content_size) { | 256 LayerImpl* SetupScrollAndContentsLayers(gfx::Size content_size) { |
242 LayerImpl* scroll_layer = CreateScrollAndContentsLayers( | 257 LayerImpl* scroll_layer = CreateScrollAndContentsLayers( |
243 host_impl_->active_tree(), content_size); | 258 host_impl_->active_tree(), content_size); |
244 host_impl_->active_tree()->DidBecomeActive(); | 259 host_impl_->active_tree()->DidBecomeActive(); |
245 return scroll_layer; | 260 return scroll_layer; |
246 } | 261 } |
247 | 262 |
248 scoped_ptr<LayerImpl> CreateScrollableLayer(int id, gfx::Size size) { | 263 // TODO(wjmaclean) Add clip-layer pointer to parameters. |
| 264 scoped_ptr<LayerImpl> CreateScrollableLayer(int id, |
| 265 gfx::Size size, |
| 266 LayerImpl* clip_layer) { |
| 267 DCHECK(clip_layer); |
| 268 DCHECK(id != clip_layer->id()); |
249 scoped_ptr<LayerImpl> layer = | 269 scoped_ptr<LayerImpl> layer = |
250 LayerImpl::Create(host_impl_->active_tree(), id); | 270 LayerImpl::Create(host_impl_->active_tree(), id); |
251 layer->SetScrollable(true); | 271 layer->SetScrollClipLayer(clip_layer->id()); |
252 layer->SetDrawsContent(true); | 272 layer->SetDrawsContent(true); |
253 layer->SetBounds(size); | 273 layer->SetBounds(size); |
254 layer->SetContentBounds(size); | 274 layer->SetContentBounds(size); |
255 layer->SetMaxScrollOffset(gfx::Vector2d(size.width() * 2, | 275 clip_layer->SetBounds(gfx::Size(size.width() / 2, size.height() / 2)); |
256 size.height() * 2)); | |
257 return layer.Pass(); | 276 return layer.Pass(); |
258 } | 277 } |
259 | 278 |
260 void DrawFrame() { | 279 void DrawFrame() { |
261 LayerTreeHostImpl::FrameData frame; | 280 LayerTreeHostImpl::FrameData frame; |
262 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 281 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
263 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 282 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
264 host_impl_->DidDrawAllLayers(frame); | 283 host_impl_->DidDrawAllLayers(frame); |
265 } | 284 } |
266 | 285 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 433 |
415 scroll_info = host_impl_->ProcessScrollDeltas(); | 434 scroll_info = host_impl_->ProcessScrollDeltas(); |
416 ASSERT_EQ(scroll_info->scrolls.size(), 0u); | 435 ASSERT_EQ(scroll_info->scrolls.size(), 0u); |
417 ExpectClearedScrollDeltasRecursive(root); | 436 ExpectClearedScrollDeltasRecursive(root); |
418 } | 437 } |
419 | 438 |
420 TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) { | 439 TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) { |
421 gfx::Vector2d scroll_offset(20, 30); | 440 gfx::Vector2d scroll_offset(20, 30); |
422 gfx::Vector2d scroll_delta(11, -15); | 441 gfx::Vector2d scroll_delta(11, -15); |
423 { | 442 { |
| 443 scoped_ptr<LayerImpl> root_clip = |
| 444 LayerImpl::Create(host_impl_->active_tree(), 2); |
424 scoped_ptr<LayerImpl> root = | 445 scoped_ptr<LayerImpl> root = |
425 LayerImpl::Create(host_impl_->active_tree(), 1); | 446 LayerImpl::Create(host_impl_->active_tree(), 1); |
426 root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 447 root_clip->SetBounds(gfx::Size(10, 10)); |
427 root->SetScrollOffset(scroll_offset); | 448 LayerImpl* root_layer = root.get(); |
428 root->SetScrollable(true); | 449 root_clip->AddChild(root.Pass()); |
429 root->ScrollBy(scroll_delta); | 450 root_layer->SetBounds(gfx::Size(110, 110)); |
430 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 451 root_layer->SetScrollClipLayer(root_clip->id()); |
| 452 root_layer->SetScrollOffset(scroll_offset); |
| 453 root_layer->ScrollBy(scroll_delta); |
| 454 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
431 } | 455 } |
432 LayerImpl* root = host_impl_->active_tree()->root_layer(); | 456 LayerImpl* root = host_impl_->active_tree()->root_layer()->children()[0]; |
433 | 457 |
434 scoped_ptr<ScrollAndScaleSet> scroll_info; | 458 scoped_ptr<ScrollAndScaleSet> scroll_info; |
435 | 459 |
436 scroll_info = host_impl_->ProcessScrollDeltas(); | 460 scroll_info = host_impl_->ProcessScrollDeltas(); |
437 ASSERT_EQ(scroll_info->scrolls.size(), 1u); | 461 ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
438 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scroll_delta); | 462 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scroll_delta); |
439 ExpectContains(*scroll_info, root->id(), scroll_delta); | 463 ExpectContains(*scroll_info, root->id(), scroll_delta); |
440 | 464 |
441 gfx::Vector2d scroll_delta2(-5, 27); | 465 gfx::Vector2d scroll_delta2(-5, 27); |
442 root->ScrollBy(scroll_delta2); | 466 root->ScrollBy(scroll_delta2); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 gfx::Point(), SCROLL_FORWARD)); | 737 gfx::Point(), SCROLL_FORWARD)); |
714 EXPECT_FALSE(host_impl_->ScrollVerticallyByPage( | 738 EXPECT_FALSE(host_impl_->ScrollVerticallyByPage( |
715 gfx::Point(), SCROLL_BACKWARD)); | 739 gfx::Point(), SCROLL_BACKWARD)); |
716 | 740 |
717 scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar( | 741 scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar( |
718 PaintedScrollbarLayerImpl::Create( | 742 PaintedScrollbarLayerImpl::Create( |
719 host_impl_->active_tree(), | 743 host_impl_->active_tree(), |
720 20, | 744 20, |
721 VERTICAL)); | 745 VERTICAL)); |
722 vertical_scrollbar->SetBounds(gfx::Size(15, 1000)); | 746 vertical_scrollbar->SetBounds(gfx::Size(15, 1000)); |
723 host_impl_->RootScrollLayer()->SetVerticalScrollbarLayer( | 747 host_impl_->InnerViewportScrollLayer()->AddScrollbar( |
724 vertical_scrollbar.get()); | 748 vertical_scrollbar.get()); |
725 | 749 |
726 // Trying to scroll with a vertical scrollbar will succeed. | 750 // Trying to scroll with a vertical scrollbar will succeed. |
727 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( | 751 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( |
728 gfx::Point(), SCROLL_FORWARD)); | 752 gfx::Point(), SCROLL_FORWARD)); |
729 EXPECT_FLOAT_EQ(875.f, host_impl_->RootScrollLayer()->ScrollDelta().y()); | 753 EXPECT_FLOAT_EQ(875.f, |
| 754 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y()); |
730 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( | 755 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( |
731 gfx::Point(), SCROLL_BACKWARD)); | 756 gfx::Point(), SCROLL_BACKWARD)); |
732 } | 757 } |
733 | 758 |
734 // The user-scrollability breaks for zoomed-in pages. So disable this. | 759 // The user-scrollability breaks for zoomed-in pages. So disable this. |
735 // http://crbug.com/322223 | 760 // http://crbug.com/322223 |
736 TEST_F(LayerTreeHostImplTest, DISABLED_ScrollWithUserUnscrollableLayers) { | 761 TEST_F(LayerTreeHostImplTest, DISABLED_ScrollWithUserUnscrollableLayers) { |
737 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200)); | 762 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
738 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 763 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
739 | 764 |
740 gfx::Size overflow_size(400, 400); | 765 gfx::Size overflow_size(400, 400); |
741 ASSERT_EQ(1u, scroll_layer->children().size()); | 766 ASSERT_EQ(1u, scroll_layer->children().size()); |
742 LayerImpl* overflow = scroll_layer->children()[0]; | 767 LayerImpl* overflow = scroll_layer->children()[0]; |
743 overflow->SetBounds(overflow_size); | 768 overflow->SetBounds(overflow_size); |
744 overflow->SetContentBounds(overflow_size); | 769 overflow->SetContentBounds(overflow_size); |
745 overflow->SetScrollable(true); | 770 overflow->SetScrollClipLayer(scroll_layer->parent()->id()); |
746 overflow->SetMaxScrollOffset(gfx::Vector2d(overflow_size.width(), | |
747 overflow_size.height())); | |
748 overflow->SetScrollOffset(gfx::Vector2d()); | 771 overflow->SetScrollOffset(gfx::Vector2d()); |
749 overflow->SetPosition(gfx::PointF()); | 772 overflow->SetPosition(gfx::PointF()); |
750 overflow->SetAnchorPoint(gfx::PointF()); | 773 overflow->SetAnchorPoint(gfx::PointF()); |
751 | 774 |
752 DrawFrame(); | 775 DrawFrame(); |
753 gfx::Point scroll_position(10, 10); | 776 gfx::Point scroll_position(10, 10); |
754 | 777 |
755 EXPECT_EQ(InputHandler::ScrollStarted, | 778 EXPECT_EQ(InputHandler::ScrollStarted, |
756 host_impl_->ScrollBegin(scroll_position, InputHandler::Wheel)); | 779 host_impl_->ScrollBegin(scroll_position, InputHandler::Wheel)); |
757 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->TotalScrollOffset()); | 780 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->TotalScrollOffset()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 host_impl_->active_tree()->set_needs_update_draw_properties(); | 823 host_impl_->active_tree()->set_needs_update_draw_properties(); |
801 | 824 |
802 EXPECT_EQ(host_impl_->HaveTouchEventHandlersAt(gfx::Point()), false); | 825 EXPECT_EQ(host_impl_->HaveTouchEventHandlersAt(gfx::Point()), false); |
803 } | 826 } |
804 | 827 |
805 TEST_F(LayerTreeHostImplTest, ImplPinchZoom) { | 828 TEST_F(LayerTreeHostImplTest, ImplPinchZoom) { |
806 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 829 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
807 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 830 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
808 DrawFrame(); | 831 DrawFrame(); |
809 | 832 |
810 EXPECT_EQ(scroll_layer, host_impl_->RootScrollLayer()); | 833 EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer()); |
811 | 834 |
812 float min_page_scale = 1.f, max_page_scale = 4.f; | 835 float min_page_scale = 1.f, max_page_scale = 4.f; |
813 | 836 |
814 // The impl-based pinch zoom should adjust the max scroll position. | 837 // The impl-based pinch zoom should adjust the max scroll position. |
815 { | 838 { |
816 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 839 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
817 min_page_scale, | 840 min_page_scale, |
818 max_page_scale); | 841 max_page_scale); |
819 host_impl_->active_tree()->SetPageScaleDelta(1.f); | 842 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
820 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 843 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
821 | 844 |
822 float page_scale_delta = 2.f; | 845 float page_scale_delta = 2.f; |
823 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); | 846 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); |
| 847 host_impl_->PinchGestureBegin(); |
824 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); | 848 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); |
825 host_impl_->PinchGestureEnd(); | 849 host_impl_->PinchGestureEnd(); |
826 host_impl_->ScrollEnd(); | 850 host_impl_->ScrollEnd(); |
827 EXPECT_TRUE(did_request_redraw_); | 851 EXPECT_TRUE(did_request_redraw_); |
828 EXPECT_TRUE(did_request_commit_); | 852 EXPECT_TRUE(did_request_commit_); |
829 | 853 |
830 scoped_ptr<ScrollAndScaleSet> scroll_info = | 854 scoped_ptr<ScrollAndScaleSet> scroll_info = |
831 host_impl_->ProcessScrollDeltas(); | 855 host_impl_->ProcessScrollDeltas(); |
832 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); | 856 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
833 | 857 |
834 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(), | 858 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(), |
835 scroll_layer->max_scroll_offset().ToString()); | 859 scroll_layer->MaxScrollOffset().ToString()); |
836 } | 860 } |
837 | 861 |
838 // Scrolling after a pinch gesture should always be in local space. The | 862 // Scrolling after a pinch gesture should always be in local space. The |
839 // scroll deltas do not have the page scale factor applied. | 863 // scroll deltas do not have the page scale factor applied. |
840 { | 864 { |
841 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 865 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
842 min_page_scale, | 866 min_page_scale, |
843 max_page_scale); | 867 max_page_scale); |
844 host_impl_->active_tree()->SetPageScaleDelta(1.f); | 868 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
845 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 869 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
(...skipping 18 matching lines...) Expand all Loading... |
864 scroll_layer->id(), | 888 scroll_layer->id(), |
865 scroll_delta); | 889 scroll_delta); |
866 } | 890 } |
867 } | 891 } |
868 | 892 |
869 TEST_F(LayerTreeHostImplTest, PinchGesture) { | 893 TEST_F(LayerTreeHostImplTest, PinchGesture) { |
870 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 894 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
871 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 895 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
872 DrawFrame(); | 896 DrawFrame(); |
873 | 897 |
874 LayerImpl* scroll_layer = host_impl_->RootScrollLayer(); | 898 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
875 DCHECK(scroll_layer); | 899 DCHECK(scroll_layer); |
876 | 900 |
877 float min_page_scale = 1.f; | 901 float min_page_scale = 1.f; |
878 float max_page_scale = 4.f; | 902 float max_page_scale = 4.f; |
879 | 903 |
880 // Basic pinch zoom in gesture | 904 // Basic pinch zoom in gesture |
881 { | 905 { |
882 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 906 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
883 min_page_scale, | 907 min_page_scale, |
884 max_page_scale); | 908 max_page_scale); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); | 1008 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); |
985 } | 1009 } |
986 | 1010 |
987 // Two-finger panning should work when starting fully zoomed out. | 1011 // Two-finger panning should work when starting fully zoomed out. |
988 { | 1012 { |
989 host_impl_->active_tree()->SetPageScaleFactorAndLimits(0.5f, | 1013 host_impl_->active_tree()->SetPageScaleFactorAndLimits(0.5f, |
990 0.5f, | 1014 0.5f, |
991 4.f); | 1015 4.f); |
992 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 1016 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
993 scroll_layer->SetScrollOffset(gfx::Vector2d(0, 0)); | 1017 scroll_layer->SetScrollOffset(gfx::Vector2d(0, 0)); |
994 host_impl_->active_tree()->UpdateMaxScrollOffset(); | |
995 | 1018 |
996 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture); | 1019 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture); |
997 host_impl_->PinchGestureBegin(); | 1020 host_impl_->PinchGestureBegin(); |
998 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); | 1021 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); |
999 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); | 1022 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); |
1000 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10)); | 1023 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10)); |
1001 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); | 1024 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); |
1002 host_impl_->PinchGestureEnd(); | 1025 host_impl_->PinchGestureEnd(); |
1003 host_impl_->ScrollEnd(); | 1026 host_impl_->ScrollEnd(); |
1004 | 1027 |
1005 scoped_ptr<ScrollAndScaleSet> scroll_info = | 1028 scoped_ptr<ScrollAndScaleSet> scroll_info = |
1006 host_impl_->ProcessScrollDeltas(); | 1029 host_impl_->ProcessScrollDeltas(); |
1007 EXPECT_EQ(scroll_info->page_scale_delta, 2.f); | 1030 EXPECT_EQ(scroll_info->page_scale_delta, 2.f); |
1008 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(20, 20)); | 1031 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(20, 20)); |
1009 } | 1032 } |
1010 } | 1033 } |
1011 | 1034 |
1012 TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { | 1035 TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { |
1013 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 1036 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
1014 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 1037 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
1015 DrawFrame(); | 1038 DrawFrame(); |
1016 | 1039 |
1017 LayerImpl* scroll_layer = host_impl_->RootScrollLayer(); | 1040 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
1018 DCHECK(scroll_layer); | 1041 DCHECK(scroll_layer); |
1019 | 1042 |
1020 float min_page_scale = 0.5f; | 1043 float min_page_scale = 0.5f; |
1021 float max_page_scale = 4.f; | 1044 float max_page_scale = 4.f; |
1022 base::TimeTicks start_time = base::TimeTicks() + | 1045 base::TimeTicks start_time = base::TimeTicks() + |
1023 base::TimeDelta::FromSeconds(1); | 1046 base::TimeDelta::FromSeconds(1); |
1024 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); | 1047 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
1025 base::TimeTicks halfway_through_animation = start_time + duration / 2; | 1048 base::TimeTicks halfway_through_animation = start_time + duration / 2; |
1026 base::TimeTicks end_time = start_time + duration; | 1049 base::TimeTicks end_time = start_time + duration; |
1027 | 1050 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 // Pushed to (0,0) via clamping against contents layer size. | 1100 // Pushed to (0,0) via clamping against contents layer size. |
1078 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); | 1101 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); |
1079 } | 1102 } |
1080 } | 1103 } |
1081 | 1104 |
1082 TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) { | 1105 TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) { |
1083 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 1106 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
1084 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 1107 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
1085 DrawFrame(); | 1108 DrawFrame(); |
1086 | 1109 |
1087 LayerImpl* scroll_layer = host_impl_->RootScrollLayer(); | 1110 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
1088 DCHECK(scroll_layer); | 1111 DCHECK(scroll_layer); |
1089 | 1112 |
1090 float min_page_scale = 0.5f; | 1113 float min_page_scale = 0.5f; |
1091 float max_page_scale = 4.f; | 1114 float max_page_scale = 4.f; |
1092 base::TimeTicks start_time = base::TimeTicks() + | 1115 base::TimeTicks start_time = base::TimeTicks() + |
1093 base::TimeDelta::FromSeconds(1); | 1116 base::TimeDelta::FromSeconds(1); |
1094 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); | 1117 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
1095 base::TimeTicks halfway_through_animation = start_time + duration / 2; | 1118 base::TimeTicks halfway_through_animation = start_time + duration / 2; |
1096 base::TimeTicks end_time = start_time + duration; | 1119 base::TimeTicks end_time = start_time + duration; |
1097 | 1120 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 host_impl_ = make_scoped_ptr(host_impl_override_time); | 1180 host_impl_ = make_scoped_ptr(host_impl_override_time); |
1158 host_impl_->InitializeRenderer(CreateOutputSurface()); | 1181 host_impl_->InitializeRenderer(CreateOutputSurface()); |
1159 host_impl_->SetViewportSize(viewport_size); | 1182 host_impl_->SetViewportSize(viewport_size); |
1160 | 1183 |
1161 scoped_ptr<LayerImpl> root = | 1184 scoped_ptr<LayerImpl> root = |
1162 LayerImpl::Create(host_impl_->active_tree(), 1); | 1185 LayerImpl::Create(host_impl_->active_tree(), 1); |
1163 root->SetBounds(viewport_size); | 1186 root->SetBounds(viewport_size); |
1164 | 1187 |
1165 scoped_ptr<LayerImpl> scroll = | 1188 scoped_ptr<LayerImpl> scroll = |
1166 LayerImpl::Create(host_impl_->active_tree(), 2); | 1189 LayerImpl::Create(host_impl_->active_tree(), 2); |
1167 scroll->SetScrollable(true); | 1190 scroll->SetScrollClipLayer(root->id()); |
1168 scroll->SetScrollOffset(gfx::Vector2d()); | 1191 scroll->SetScrollOffset(gfx::Vector2d()); |
1169 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | 1192 root->SetBounds(viewport_size); |
1170 content_size.height())); | |
1171 scroll->SetBounds(content_size); | 1193 scroll->SetBounds(content_size); |
1172 scroll->SetContentBounds(content_size); | 1194 scroll->SetContentBounds(content_size); |
1173 | 1195 |
1174 scoped_ptr<LayerImpl> contents = | 1196 scoped_ptr<LayerImpl> contents = |
1175 LayerImpl::Create(host_impl_->active_tree(), 3); | 1197 LayerImpl::Create(host_impl_->active_tree(), 3); |
1176 contents->SetDrawsContent(true); | 1198 contents->SetDrawsContent(true); |
1177 contents->SetBounds(content_size); | 1199 contents->SetBounds(content_size); |
1178 contents->SetContentBounds(content_size); | 1200 contents->SetContentBounds(content_size); |
1179 | 1201 |
1180 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = | 1202 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = |
1181 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 4, VERTICAL); | 1203 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 4, VERTICAL); |
1182 scroll->SetVerticalScrollbarLayer(scrollbar.get()); | 1204 scrollbar->SetScrollLayerById(2); |
| 1205 scrollbar->SetClipLayerById(1); |
1183 | 1206 |
1184 scroll->AddChild(contents.Pass()); | 1207 scroll->AddChild(contents.Pass()); |
1185 root->AddChild(scroll.Pass()); | 1208 root->AddChild(scroll.Pass()); |
1186 root->AddChild(scrollbar.PassAs<LayerImpl>()); | 1209 root->AddChild(scrollbar.PassAs<LayerImpl>()); |
1187 | 1210 |
1188 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1211 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 1212 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
1189 host_impl_->active_tree()->DidBecomeActive(); | 1213 host_impl_->active_tree()->DidBecomeActive(); |
1190 DrawFrame(); | 1214 DrawFrame(); |
1191 | 1215 |
1192 base::TimeTicks fake_now = gfx::FrameTime::Now(); | 1216 base::TimeTicks fake_now = gfx::FrameTime::Now(); |
1193 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); | 1217 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
1194 | 1218 |
1195 // If no scroll happened recently, StartScrollbarAnimation should have no | 1219 // If no scroll happened recently, StartScrollbarAnimation should have no |
1196 // effect. | 1220 // effect. |
1197 host_impl_->StartScrollbarAnimation(); | 1221 host_impl_->StartScrollbarAnimation(); |
1198 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); | 1222 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); |
(...skipping 30 matching lines...) Expand all Loading... |
1229 // If no scroll happened recently, StartScrollbarAnimation should have no | 1253 // If no scroll happened recently, StartScrollbarAnimation should have no |
1230 // effect. | 1254 // effect. |
1231 fake_now += base::TimeDelta::FromMilliseconds(25); | 1255 fake_now += base::TimeDelta::FromMilliseconds(25); |
1232 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); | 1256 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
1233 host_impl_->StartScrollbarAnimation(); | 1257 host_impl_->StartScrollbarAnimation(); |
1234 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); | 1258 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); |
1235 EXPECT_FALSE(did_request_redraw_); | 1259 EXPECT_FALSE(did_request_redraw_); |
1236 | 1260 |
1237 // Setting the scroll offset outside a scroll should also cause the scrollbar | 1261 // Setting the scroll offset outside a scroll should also cause the scrollbar |
1238 // to appear and to schedule a fade. | 1262 // to appear and to schedule a fade. |
1239 host_impl_->RootScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); | 1263 host_impl_->InnerViewportScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); |
1240 host_impl_->StartScrollbarAnimation(); | 1264 host_impl_->StartScrollbarAnimation(); |
1241 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), | 1265 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), |
1242 requested_scrollbar_animation_delay_); | 1266 requested_scrollbar_animation_delay_); |
1243 EXPECT_FALSE(did_request_redraw_); | 1267 EXPECT_FALSE(did_request_redraw_); |
1244 requested_scrollbar_animation_delay_ = base::TimeDelta(); | 1268 requested_scrollbar_animation_delay_ = base::TimeDelta(); |
1245 | 1269 |
1246 // None of the above should have called CurrentFrameTimeTicks, so if we call | 1270 // None of the above should have called CurrentFrameTimeTicks, so if we call |
1247 // it now we should get the current time. | 1271 // it now we should get the current time. |
1248 fake_now += base::TimeDelta::FromMilliseconds(10); | 1272 fake_now += base::TimeDelta::FromMilliseconds(10); |
1249 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); | 1273 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
(...skipping 13 matching lines...) Expand all Loading... |
1263 CreateHostImpl(settings, CreateOutputSurface()); | 1287 CreateHostImpl(settings, CreateOutputSurface()); |
1264 host_impl_->SetDeviceScaleFactor(device_scale_factor); | 1288 host_impl_->SetDeviceScaleFactor(device_scale_factor); |
1265 host_impl_->SetViewportSize(device_viewport_size); | 1289 host_impl_->SetViewportSize(device_viewport_size); |
1266 | 1290 |
1267 scoped_ptr<LayerImpl> root = | 1291 scoped_ptr<LayerImpl> root = |
1268 LayerImpl::Create(host_impl_->active_tree(), 1); | 1292 LayerImpl::Create(host_impl_->active_tree(), 1); |
1269 root->SetBounds(viewport_size); | 1293 root->SetBounds(viewport_size); |
1270 | 1294 |
1271 scoped_ptr<LayerImpl> scroll = | 1295 scoped_ptr<LayerImpl> scroll = |
1272 LayerImpl::Create(host_impl_->active_tree(), 2); | 1296 LayerImpl::Create(host_impl_->active_tree(), 2); |
1273 scroll->SetScrollable(true); | 1297 scroll->SetScrollClipLayer(root->id()); |
1274 scroll->SetScrollOffset(gfx::Vector2d()); | 1298 scroll->SetScrollOffset(gfx::Vector2d()); |
1275 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | |
1276 content_size.height())); | |
1277 scroll->SetBounds(content_size); | 1299 scroll->SetBounds(content_size); |
1278 scroll->SetContentBounds(content_size); | 1300 scroll->SetContentBounds(content_size); |
1279 | 1301 |
1280 scoped_ptr<LayerImpl> contents = | 1302 scoped_ptr<LayerImpl> contents = |
1281 LayerImpl::Create(host_impl_->active_tree(), 3); | 1303 LayerImpl::Create(host_impl_->active_tree(), 3); |
1282 contents->SetDrawsContent(true); | 1304 contents->SetDrawsContent(true); |
1283 contents->SetBounds(content_size); | 1305 contents->SetBounds(content_size); |
1284 contents->SetContentBounds(content_size); | 1306 contents->SetContentBounds(content_size); |
1285 | 1307 |
1286 // The scrollbar is on the right side. | 1308 // The scrollbar is on the right side. |
1287 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = | 1309 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = |
1288 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 5, VERTICAL); | 1310 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 5, VERTICAL); |
1289 scrollbar->SetDrawsContent(true); | 1311 scrollbar->SetDrawsContent(true); |
1290 scrollbar->SetBounds(gfx::Size(15, viewport_size.height())); | 1312 scrollbar->SetBounds(gfx::Size(15, viewport_size.height())); |
1291 scrollbar->SetContentBounds(gfx::Size(15, viewport_size.height())); | 1313 scrollbar->SetContentBounds(gfx::Size(15, viewport_size.height())); |
1292 scrollbar->SetPosition(gfx::Point(285, 0)); | 1314 scrollbar->SetPosition(gfx::Point(285, 0)); |
1293 scroll->SetVerticalScrollbarLayer(scrollbar.get()); | 1315 scrollbar->SetScrollLayerById(2); |
1294 | 1316 |
1295 scroll->AddChild(contents.Pass()); | 1317 scroll->AddChild(contents.Pass()); |
1296 root->AddChild(scroll.Pass()); | 1318 root->AddChild(scroll.Pass()); |
1297 root->AddChild(scrollbar.PassAs<LayerImpl>()); | 1319 root->AddChild(scrollbar.PassAs<LayerImpl>()); |
1298 | 1320 |
1299 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1321 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 1322 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
1300 host_impl_->active_tree()->DidBecomeActive(); | 1323 host_impl_->active_tree()->DidBecomeActive(); |
1301 DrawFrame(); | 1324 DrawFrame(); |
1302 | 1325 |
1303 LayerImpl* root_scroll = host_impl_->active_tree()->RootScrollLayer(); | 1326 LayerImpl* root_scroll = |
| 1327 host_impl_->active_tree()->InnerViewportScrollLayer(); |
1304 ASSERT_TRUE(root_scroll->scrollbar_animation_controller()); | 1328 ASSERT_TRUE(root_scroll->scrollbar_animation_controller()); |
1305 ScrollbarAnimationControllerThinning* scrollbar_animation_controller = | 1329 ScrollbarAnimationControllerThinning* scrollbar_animation_controller = |
1306 static_cast<ScrollbarAnimationControllerThinning*>( | 1330 static_cast<ScrollbarAnimationControllerThinning*>( |
1307 root_scroll->scrollbar_animation_controller()); | 1331 root_scroll->scrollbar_animation_controller()); |
1308 scrollbar_animation_controller->set_mouse_move_distance_for_test(100.f); | 1332 scrollbar_animation_controller->set_mouse_move_distance_for_test(100.f); |
1309 | 1333 |
1310 host_impl_->MouseMoveAt(gfx::Point(1, 1)); | 1334 host_impl_->MouseMoveAt(gfx::Point(1, 1)); |
1311 EXPECT_FALSE(scrollbar_animation_controller->mouse_is_near_scrollbar()); | 1335 EXPECT_FALSE(scrollbar_animation_controller->mouse_is_near_scrollbar()); |
1312 | 1336 |
1313 host_impl_->MouseMoveAt(gfx::Point(200, 50)); | 1337 host_impl_->MouseMoveAt(gfx::Point(200, 50)); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 true, | 1765 true, |
1742 host_impl_->resource_provider())); | 1766 host_impl_->resource_provider())); |
1743 | 1767 |
1744 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 1768 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
1745 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 1769 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
1746 host_impl_->DidDrawAllLayers(frame); | 1770 host_impl_->DidDrawAllLayers(frame); |
1747 } | 1771 } |
1748 | 1772 |
1749 TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) { | 1773 TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) { |
1750 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1774 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1751 root->SetScrollable(false); | 1775 root->SetScrollClipLayer(Layer::INVALID_ID); |
1752 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1776 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1753 DrawFrame(); | 1777 DrawFrame(); |
1754 | 1778 |
1755 // Scroll event is ignored because layer is not scrollable. | 1779 // Scroll event is ignored because layer is not scrollable. |
1756 EXPECT_EQ(InputHandler::ScrollIgnored, | 1780 EXPECT_EQ(InputHandler::ScrollIgnored, |
1757 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 1781 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
1758 EXPECT_FALSE(did_request_redraw_); | 1782 EXPECT_FALSE(did_request_redraw_); |
1759 EXPECT_FALSE(did_request_commit_); | 1783 EXPECT_FALSE(did_request_commit_); |
1760 } | 1784 } |
1761 | 1785 |
1762 TEST_F(LayerTreeHostImplTest, ScrollNonScrollableRootWithTopControls) { | 1786 TEST_F(LayerTreeHostImplTest, ScrollNonScrollableRootWithTopControls) { |
1763 LayerTreeSettings settings; | 1787 LayerTreeSettings settings; |
1764 settings.calculate_top_controls_position = true; | 1788 settings.calculate_top_controls_position = true; |
1765 settings.top_controls_height = 50; | 1789 settings.top_controls_height = 50; |
1766 | 1790 |
1767 CreateHostImpl(settings, CreateOutputSurface()); | 1791 CreateHostImpl(settings, CreateOutputSurface()); |
1768 | 1792 |
1769 gfx::Size layer_size(5, 5); | 1793 gfx::Size layer_size(10, 10); |
| 1794 gfx::Size clip_size(5, 5); |
1770 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1795 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1771 root->SetScrollable(true); | 1796 scoped_ptr<LayerImpl> root_clip = |
1772 root->SetMaxScrollOffset(gfx::Vector2d(layer_size.width(), | 1797 LayerImpl::Create(host_impl_->active_tree(), 2); |
1773 layer_size.height())); | 1798 root_clip->SetBounds(clip_size); |
| 1799 root->SetScrollClipLayer(root_clip->id()); |
1774 root->SetBounds(layer_size); | 1800 root->SetBounds(layer_size); |
1775 root->SetContentBounds(layer_size); | 1801 root->SetContentBounds(layer_size); |
1776 root->SetPosition(gfx::PointF()); | 1802 root->SetPosition(gfx::PointF()); |
1777 root->SetAnchorPoint(gfx::PointF()); | 1803 root->SetAnchorPoint(gfx::PointF()); |
1778 root->SetDrawsContent(false); | 1804 root->SetDrawsContent(false); |
1779 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1805 int root_id = root->id(); |
1780 host_impl_->active_tree()->FindRootScrollLayer(); | 1806 root_clip->AddChild(root.Pass()); |
| 1807 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 1808 host_impl_->active_tree()->SetViewportLayersFromIds( |
| 1809 root_id, root_id, Layer::INVALID_ID); |
1781 DrawFrame(); | 1810 DrawFrame(); |
1782 | 1811 |
1783 EXPECT_EQ(InputHandler::ScrollIgnored, | 1812 EXPECT_EQ(InputHandler::ScrollIgnored, |
1784 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 1813 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
1785 | 1814 |
1786 host_impl_->top_controls_manager()->ScrollBegin(); | 1815 host_impl_->top_controls_manager()->ScrollBegin(); |
1787 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); | 1816 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); |
1788 host_impl_->top_controls_manager()->ScrollEnd(); | 1817 host_impl_->top_controls_manager()->ScrollEnd(); |
1789 EXPECT_EQ(host_impl_->top_controls_manager()->content_top_offset(), 0.f); | 1818 EXPECT_EQ(host_impl_->top_controls_manager()->content_top_offset(), 0.f); |
1790 | 1819 |
1791 EXPECT_EQ(InputHandler::ScrollStarted, | 1820 EXPECT_EQ(InputHandler::ScrollStarted, |
1792 host_impl_->ScrollBegin(gfx::Point(), | 1821 host_impl_->ScrollBegin(gfx::Point(), |
1793 InputHandler::Gesture)); | 1822 InputHandler::Gesture)); |
1794 } | 1823 } |
1795 | 1824 |
1796 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { | 1825 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { |
1797 // Test the configuration where a non-composited root layer is embedded in a | 1826 // Test the configuration where a non-composited root layer is embedded in a |
1798 // scrollable outer layer. | 1827 // scrollable outer layer. |
1799 gfx::Size surface_size(10, 10); | 1828 gfx::Size surface_size(10, 10); |
| 1829 gfx::Size contents_size(20, 20); |
1800 | 1830 |
1801 scoped_ptr<LayerImpl> content_layer = | 1831 scoped_ptr<LayerImpl> content_layer = |
1802 LayerImpl::Create(host_impl_->active_tree(), 1); | 1832 LayerImpl::Create(host_impl_->active_tree(), 1); |
1803 content_layer->SetDrawsContent(true); | 1833 content_layer->SetDrawsContent(true); |
1804 content_layer->SetPosition(gfx::PointF()); | 1834 content_layer->SetPosition(gfx::PointF()); |
1805 content_layer->SetAnchorPoint(gfx::PointF()); | 1835 content_layer->SetAnchorPoint(gfx::PointF()); |
1806 content_layer->SetBounds(surface_size); | 1836 content_layer->SetBounds(surface_size); |
1807 content_layer->SetContentBounds(gfx::Size(surface_size.width() * 2, | 1837 content_layer->SetContentBounds(contents_size); |
1808 surface_size.height() * 2)); | |
1809 content_layer->SetContentsScale(2.f, 2.f); | 1838 content_layer->SetContentsScale(2.f, 2.f); |
1810 | 1839 |
| 1840 scoped_ptr<LayerImpl> scroll_clip_layer = |
| 1841 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 1842 scroll_clip_layer->SetBounds(surface_size); |
| 1843 |
1811 scoped_ptr<LayerImpl> scroll_layer = | 1844 scoped_ptr<LayerImpl> scroll_layer = |
1812 LayerImpl::Create(host_impl_->active_tree(), 2); | 1845 LayerImpl::Create(host_impl_->active_tree(), 2); |
1813 scroll_layer->SetScrollable(true); | 1846 scroll_layer->SetScrollClipLayer(3); |
1814 scroll_layer->SetMaxScrollOffset(gfx::Vector2d(surface_size.width(), | 1847 scroll_layer->SetBounds(contents_size); |
1815 surface_size.height())); | 1848 scroll_layer->SetContentBounds(contents_size); |
1816 scroll_layer->SetBounds(surface_size); | |
1817 scroll_layer->SetContentBounds(surface_size); | |
1818 scroll_layer->SetPosition(gfx::PointF()); | 1849 scroll_layer->SetPosition(gfx::PointF()); |
1819 scroll_layer->SetAnchorPoint(gfx::PointF()); | 1850 scroll_layer->SetAnchorPoint(gfx::PointF()); |
1820 scroll_layer->AddChild(content_layer.Pass()); | 1851 scroll_layer->AddChild(content_layer.Pass()); |
| 1852 scroll_clip_layer->AddChild(scroll_layer.Pass()); |
1821 | 1853 |
1822 host_impl_->active_tree()->SetRootLayer(scroll_layer.Pass()); | 1854 host_impl_->active_tree()->SetRootLayer(scroll_clip_layer.Pass()); |
1823 host_impl_->SetViewportSize(surface_size); | 1855 host_impl_->SetViewportSize(surface_size); |
1824 DrawFrame(); | 1856 DrawFrame(); |
1825 | 1857 |
1826 EXPECT_EQ(InputHandler::ScrollStarted, | 1858 EXPECT_EQ(InputHandler::ScrollStarted, |
1827 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1859 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1828 InputHandler::Wheel)); | 1860 InputHandler::Wheel)); |
1829 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 1861 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
1830 host_impl_->ScrollEnd(); | 1862 host_impl_->ScrollEnd(); |
1831 EXPECT_TRUE(did_request_redraw_); | 1863 EXPECT_TRUE(did_request_redraw_); |
1832 EXPECT_TRUE(did_request_commit_); | 1864 EXPECT_TRUE(did_request_commit_); |
1833 } | 1865 } |
1834 | 1866 |
1835 TEST_F(LayerTreeHostImplTest, ScrollChildCallsCommitAndRedraw) { | 1867 TEST_F(LayerTreeHostImplTest, ScrollChildCallsCommitAndRedraw) { |
1836 gfx::Size surface_size(10, 10); | 1868 gfx::Size surface_size(10, 10); |
| 1869 gfx::Size contents_size(20, 20); |
1837 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1870 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1838 root->SetBounds(surface_size); | 1871 root->SetBounds(surface_size); |
1839 root->SetContentBounds(surface_size); | 1872 root->SetContentBounds(contents_size); |
1840 root->AddChild(CreateScrollableLayer(2, surface_size)); | 1873 root->AddChild(CreateScrollableLayer(2, contents_size, root.get())); |
1841 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1874 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1842 host_impl_->SetViewportSize(surface_size); | 1875 host_impl_->SetViewportSize(surface_size); |
1843 DrawFrame(); | 1876 DrawFrame(); |
1844 | 1877 |
1845 EXPECT_EQ(InputHandler::ScrollStarted, | 1878 EXPECT_EQ(InputHandler::ScrollStarted, |
1846 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1879 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1847 InputHandler::Wheel)); | 1880 InputHandler::Wheel)); |
1848 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 1881 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
1849 host_impl_->ScrollEnd(); | 1882 host_impl_->ScrollEnd(); |
1850 EXPECT_TRUE(did_request_redraw_); | 1883 EXPECT_TRUE(did_request_redraw_); |
1851 EXPECT_TRUE(did_request_commit_); | 1884 EXPECT_TRUE(did_request_commit_); |
1852 } | 1885 } |
1853 | 1886 |
1854 TEST_F(LayerTreeHostImplTest, ScrollMissesChild) { | 1887 TEST_F(LayerTreeHostImplTest, ScrollMissesChild) { |
1855 gfx::Size surface_size(10, 10); | 1888 gfx::Size surface_size(10, 10); |
1856 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1889 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1857 root->AddChild(CreateScrollableLayer(2, surface_size)); | 1890 root->AddChild(CreateScrollableLayer(2, surface_size, root.get())); |
1858 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1891 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1859 host_impl_->SetViewportSize(surface_size); | 1892 host_impl_->SetViewportSize(surface_size); |
1860 DrawFrame(); | 1893 DrawFrame(); |
1861 | 1894 |
1862 // Scroll event is ignored because the input coordinate is outside the layer | 1895 // Scroll event is ignored because the input coordinate is outside the layer |
1863 // boundaries. | 1896 // boundaries. |
1864 EXPECT_EQ(InputHandler::ScrollIgnored, | 1897 EXPECT_EQ(InputHandler::ScrollIgnored, |
1865 host_impl_->ScrollBegin(gfx::Point(15, 5), | 1898 host_impl_->ScrollBegin(gfx::Point(15, 5), |
1866 InputHandler::Wheel)); | 1899 InputHandler::Wheel)); |
1867 EXPECT_FALSE(did_request_redraw_); | 1900 EXPECT_FALSE(did_request_redraw_); |
1868 EXPECT_FALSE(did_request_commit_); | 1901 EXPECT_FALSE(did_request_commit_); |
1869 } | 1902 } |
1870 | 1903 |
1871 TEST_F(LayerTreeHostImplTest, ScrollMissesBackfacingChild) { | 1904 TEST_F(LayerTreeHostImplTest, ScrollMissesBackfacingChild) { |
1872 gfx::Size surface_size(10, 10); | 1905 gfx::Size surface_size(10, 10); |
1873 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1906 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1874 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, surface_size); | 1907 scoped_ptr<LayerImpl> child = |
| 1908 CreateScrollableLayer(2, surface_size, root.get()); |
1875 host_impl_->SetViewportSize(surface_size); | 1909 host_impl_->SetViewportSize(surface_size); |
1876 | 1910 |
1877 gfx::Transform matrix; | 1911 gfx::Transform matrix; |
1878 matrix.RotateAboutXAxis(180.0); | 1912 matrix.RotateAboutXAxis(180.0); |
1879 child->SetTransform(matrix); | 1913 child->SetTransform(matrix); |
1880 child->SetDoubleSided(false); | 1914 child->SetDoubleSided(false); |
1881 | 1915 |
1882 root->AddChild(child.Pass()); | 1916 root->AddChild(child.Pass()); |
1883 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1917 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1884 DrawFrame(); | 1918 DrawFrame(); |
1885 | 1919 |
1886 // Scroll event is ignored because the scrollable layer is not facing the | 1920 // Scroll event is ignored because the scrollable layer is not facing the |
1887 // viewer and there is nothing scrollable behind it. | 1921 // viewer and there is nothing scrollable behind it. |
1888 EXPECT_EQ(InputHandler::ScrollIgnored, | 1922 EXPECT_EQ(InputHandler::ScrollIgnored, |
1889 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1923 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1890 InputHandler::Wheel)); | 1924 InputHandler::Wheel)); |
1891 EXPECT_FALSE(did_request_redraw_); | 1925 EXPECT_FALSE(did_request_redraw_); |
1892 EXPECT_FALSE(did_request_commit_); | 1926 EXPECT_FALSE(did_request_commit_); |
1893 } | 1927 } |
1894 | 1928 |
1895 TEST_F(LayerTreeHostImplTest, ScrollBlockedByContentLayer) { | 1929 TEST_F(LayerTreeHostImplTest, ScrollBlockedByContentLayer) { |
1896 gfx::Size surface_size(10, 10); | 1930 gfx::Size surface_size(10, 10); |
1897 scoped_ptr<LayerImpl> content_layer = CreateScrollableLayer(1, surface_size); | 1931 scoped_ptr<LayerImpl> clip_layer = |
| 1932 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 1933 scoped_ptr<LayerImpl> content_layer = |
| 1934 CreateScrollableLayer(1, surface_size, clip_layer.get()); |
1898 content_layer->SetShouldScrollOnMainThread(true); | 1935 content_layer->SetShouldScrollOnMainThread(true); |
1899 content_layer->SetScrollable(false); | 1936 content_layer->SetScrollClipLayer(Layer::INVALID_ID); |
1900 | 1937 |
1901 scoped_ptr<LayerImpl> scroll_layer = CreateScrollableLayer(2, surface_size); | 1938 // Note: we can use the same clip layer for both since both calls to |
| 1939 // CreateScrollableLayer() use the same surface size. |
| 1940 scoped_ptr<LayerImpl> scroll_layer = |
| 1941 CreateScrollableLayer(2, surface_size, clip_layer.get()); |
1902 scroll_layer->AddChild(content_layer.Pass()); | 1942 scroll_layer->AddChild(content_layer.Pass()); |
| 1943 clip_layer->AddChild(scroll_layer.Pass()); |
1903 | 1944 |
1904 host_impl_->active_tree()->SetRootLayer(scroll_layer.Pass()); | 1945 host_impl_->active_tree()->SetRootLayer(clip_layer.Pass()); |
1905 host_impl_->SetViewportSize(surface_size); | 1946 host_impl_->SetViewportSize(surface_size); |
1906 DrawFrame(); | 1947 DrawFrame(); |
1907 | 1948 |
1908 // Scrolling fails because the content layer is asking to be scrolled on the | 1949 // Scrolling fails because the content layer is asking to be scrolled on the |
1909 // main thread. | 1950 // main thread. |
1910 EXPECT_EQ(InputHandler::ScrollOnMainThread, | 1951 EXPECT_EQ(InputHandler::ScrollOnMainThread, |
1911 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1952 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1912 InputHandler::Wheel)); | 1953 InputHandler::Wheel)); |
1913 } | 1954 } |
1914 | 1955 |
1915 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnMainThread) { | 1956 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnMainThread) { |
1916 gfx::Size surface_size(10, 10); | 1957 gfx::Size surface_size(20, 20); |
1917 float page_scale = 2.f; | 1958 float page_scale = 2.f; |
1918 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1959 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1919 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 1960 scoped_ptr<LayerImpl> root_clip = |
1920 root->AddChild(root_scrolling.Pass()); | 1961 LayerImpl::Create(host_impl_->active_tree(), 2); |
| 1962 scoped_ptr<LayerImpl> root_scrolling = |
| 1963 CreateScrollableLayer(3, surface_size, root_clip.get()); |
| 1964 root_clip->AddChild(root_scrolling.Pass()); |
| 1965 root->AddChild(root_clip.Pass()); |
1921 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1966 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 1967 // The behaviour in this test assumes the page scale is applied at a layer |
| 1968 // above the clip layer. |
| 1969 host_impl_->active_tree()->SetViewportLayersFromIds(1, 3, Layer::INVALID_ID); |
1922 host_impl_->active_tree()->DidBecomeActive(); | 1970 host_impl_->active_tree()->DidBecomeActive(); |
1923 host_impl_->SetViewportSize(surface_size); | 1971 host_impl_->SetViewportSize(surface_size); |
1924 DrawFrame(); | 1972 DrawFrame(); |
1925 | 1973 |
1926 LayerImpl* root_scroll = host_impl_->active_tree()->RootScrollLayer(); | 1974 LayerImpl* root_scroll = |
| 1975 host_impl_->active_tree()->InnerViewportScrollLayer(); |
1927 | 1976 |
1928 gfx::Vector2d scroll_delta(0, 10); | 1977 gfx::Vector2d scroll_delta(0, 10); |
1929 gfx::Vector2d expected_scroll_delta = scroll_delta; | 1978 gfx::Vector2d expected_scroll_delta = scroll_delta; |
1930 gfx::Vector2d expected_max_scroll = root_scroll->max_scroll_offset(); | 1979 gfx::Vector2d expected_max_scroll = root_scroll->MaxScrollOffset(); |
1931 EXPECT_EQ(InputHandler::ScrollStarted, | 1980 EXPECT_EQ(InputHandler::ScrollStarted, |
1932 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1981 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1933 InputHandler::Wheel)); | 1982 InputHandler::Wheel)); |
1934 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 1983 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
1935 host_impl_->ScrollEnd(); | 1984 host_impl_->ScrollEnd(); |
1936 | 1985 |
1937 // Set new page scale from main thread. | 1986 // Set new page scale from main thread. |
1938 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, | 1987 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, |
1939 page_scale, | 1988 page_scale, |
1940 page_scale); | 1989 page_scale); |
1941 | 1990 |
1942 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 1991 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
1943 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); | 1992 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); |
1944 | 1993 |
1945 // The scroll range should also have been updated. | 1994 // The scroll range should also have been updated. |
1946 EXPECT_EQ(expected_max_scroll, root_scroll->max_scroll_offset()); | 1995 EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); |
1947 | 1996 |
1948 // The page scale delta remains constant because the impl thread did not | 1997 // The page scale delta remains constant because the impl thread did not |
1949 // scale. | 1998 // scale. |
1950 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); | 1999 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
1951 } | 2000 } |
1952 | 2001 |
1953 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnImplThread) { | 2002 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnImplThread) { |
1954 gfx::Size surface_size(10, 10); | 2003 gfx::Size surface_size(20, 20); |
1955 float page_scale = 2.f; | 2004 float page_scale = 2.f; |
1956 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 2005 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1957 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 2006 scoped_ptr<LayerImpl> root_clip = |
1958 root->AddChild(root_scrolling.Pass()); | 2007 LayerImpl::Create(host_impl_->active_tree(), 2); |
| 2008 scoped_ptr<LayerImpl> root_scrolling = |
| 2009 CreateScrollableLayer(3, surface_size, root_clip.get()); |
| 2010 root_clip->AddChild(root_scrolling.Pass()); |
| 2011 root->AddChild(root_clip.Pass()); |
1959 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2012 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 2013 // The behaviour in this test assumes the page scale is applied at a layer |
| 2014 // above the clip layer. |
| 2015 host_impl_->active_tree()->SetViewportLayersFromIds(1, 3, Layer::INVALID_ID); |
1960 host_impl_->active_tree()->DidBecomeActive(); | 2016 host_impl_->active_tree()->DidBecomeActive(); |
1961 host_impl_->SetViewportSize(surface_size); | 2017 host_impl_->SetViewportSize(surface_size); |
1962 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, page_scale); | 2018 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, page_scale); |
1963 DrawFrame(); | 2019 DrawFrame(); |
1964 | 2020 |
1965 LayerImpl* root_scroll = host_impl_->active_tree()->RootScrollLayer(); | 2021 LayerImpl* root_scroll = |
| 2022 host_impl_->active_tree()->InnerViewportScrollLayer(); |
1966 | 2023 |
1967 gfx::Vector2d scroll_delta(0, 10); | 2024 gfx::Vector2d scroll_delta(0, 10); |
1968 gfx::Vector2d expected_scroll_delta = scroll_delta; | 2025 gfx::Vector2d expected_scroll_delta = scroll_delta; |
1969 gfx::Vector2d expected_max_scroll = root_scroll->max_scroll_offset(); | 2026 gfx::Vector2d expected_max_scroll = root_scroll->MaxScrollOffset(); |
1970 EXPECT_EQ(InputHandler::ScrollStarted, | 2027 EXPECT_EQ(InputHandler::ScrollStarted, |
1971 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2028 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1972 InputHandler::Wheel)); | 2029 InputHandler::Wheel)); |
1973 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2030 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
1974 host_impl_->ScrollEnd(); | 2031 host_impl_->ScrollEnd(); |
1975 | 2032 |
1976 // Set new page scale on impl thread by pinching. | 2033 // Set new page scale on impl thread by pinching. |
1977 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); | 2034 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); |
1978 host_impl_->PinchGestureBegin(); | 2035 host_impl_->PinchGestureBegin(); |
1979 host_impl_->PinchGestureUpdate(page_scale, gfx::Point()); | 2036 host_impl_->PinchGestureUpdate(page_scale, gfx::Point()); |
1980 host_impl_->PinchGestureEnd(); | 2037 host_impl_->PinchGestureEnd(); |
1981 host_impl_->ScrollEnd(); | 2038 host_impl_->ScrollEnd(); |
1982 DrawOneFrame(); | 2039 DrawOneFrame(); |
1983 | 2040 |
1984 // The scroll delta is not scaled because the main thread did not scale. | 2041 // The scroll delta is not scaled because the main thread did not scale. |
1985 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 2042 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
1986 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); | 2043 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); |
1987 | 2044 |
1988 // The scroll range should also have been updated. | 2045 // The scroll range should also have been updated. |
1989 EXPECT_EQ(expected_max_scroll, root_scroll->max_scroll_offset()); | 2046 EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); |
1990 | 2047 |
1991 // The page scale delta should match the new scale on the impl side. | 2048 // The page scale delta should match the new scale on the impl side. |
1992 EXPECT_EQ(page_scale, host_impl_->active_tree()->total_page_scale_factor()); | 2049 EXPECT_EQ(page_scale, host_impl_->active_tree()->total_page_scale_factor()); |
1993 } | 2050 } |
1994 | 2051 |
1995 TEST_F(LayerTreeHostImplTest, PageScaleDeltaAppliedToRootScrollLayerOnly) { | 2052 TEST_F(LayerTreeHostImplTest, PageScaleDeltaAppliedToRootScrollLayerOnly) { |
1996 gfx::Size surface_size(10, 10); | 2053 gfx::Size surface_size(10, 10); |
1997 float default_page_scale = 1.f; | 2054 float default_page_scale = 1.f; |
1998 gfx::Transform default_page_scale_matrix; | 2055 gfx::Transform default_page_scale_matrix; |
1999 default_page_scale_matrix.Scale(default_page_scale, default_page_scale); | 2056 default_page_scale_matrix.Scale(default_page_scale, default_page_scale); |
2000 | 2057 |
2001 float new_page_scale = 2.f; | 2058 float new_page_scale = 2.f; |
2002 gfx::Transform new_page_scale_matrix; | 2059 gfx::Transform new_page_scale_matrix; |
2003 new_page_scale_matrix.Scale(new_page_scale, new_page_scale); | 2060 new_page_scale_matrix.Scale(new_page_scale, new_page_scale); |
2004 | 2061 |
2005 // Create a normal scrollable root layer and another scrollable child layer. | 2062 // Create a normal scrollable root layer and another scrollable child layer. |
2006 LayerImpl* scroll = SetupScrollAndContentsLayers(surface_size); | 2063 LayerImpl* scroll = SetupScrollAndContentsLayers(surface_size); |
2007 LayerImpl* root = host_impl_->active_tree()->root_layer(); | 2064 LayerImpl* root = host_impl_->active_tree()->root_layer(); |
2008 LayerImpl* child = scroll->children()[0]; | 2065 LayerImpl* child = scroll->children()[0]; |
2009 | 2066 |
| 2067 scoped_ptr<LayerImpl> scrollable_child_clip = |
| 2068 LayerImpl::Create(host_impl_->active_tree(), 6); |
2010 scoped_ptr<LayerImpl> scrollable_child = | 2069 scoped_ptr<LayerImpl> scrollable_child = |
2011 CreateScrollableLayer(4, surface_size); | 2070 CreateScrollableLayer(7, surface_size, scrollable_child_clip.get()); |
2012 child->AddChild(scrollable_child.Pass()); | 2071 scrollable_child_clip->AddChild(scrollable_child.Pass()); |
| 2072 child->AddChild(scrollable_child_clip.Pass()); |
2013 LayerImpl* grand_child = child->children()[0]; | 2073 LayerImpl* grand_child = child->children()[0]; |
2014 | 2074 |
2015 // Set new page scale on impl thread by pinching. | 2075 // Set new page scale on impl thread by pinching. |
2016 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); | 2076 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); |
2017 host_impl_->PinchGestureBegin(); | 2077 host_impl_->PinchGestureBegin(); |
2018 host_impl_->PinchGestureUpdate(new_page_scale, gfx::Point()); | 2078 host_impl_->PinchGestureUpdate(new_page_scale, gfx::Point()); |
2019 host_impl_->PinchGestureEnd(); | 2079 host_impl_->PinchGestureEnd(); |
2020 host_impl_->ScrollEnd(); | 2080 host_impl_->ScrollEnd(); |
2021 DrawOneFrame(); | 2081 DrawOneFrame(); |
2022 | 2082 |
(...skipping 19 matching lines...) Expand all Loading... |
2042 EXPECT_EQ(new_page_scale, scroll->draw_transform().matrix().getDouble(1, 1)); | 2102 EXPECT_EQ(new_page_scale, scroll->draw_transform().matrix().getDouble(1, 1)); |
2043 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(0, 0)); | 2103 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(0, 0)); |
2044 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(1, 1)); | 2104 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(1, 1)); |
2045 EXPECT_EQ(new_page_scale, | 2105 EXPECT_EQ(new_page_scale, |
2046 grand_child->draw_transform().matrix().getDouble(0, 0)); | 2106 grand_child->draw_transform().matrix().getDouble(0, 0)); |
2047 EXPECT_EQ(new_page_scale, | 2107 EXPECT_EQ(new_page_scale, |
2048 grand_child->draw_transform().matrix().getDouble(1, 1)); | 2108 grand_child->draw_transform().matrix().getDouble(1, 1)); |
2049 } | 2109 } |
2050 | 2110 |
2051 TEST_F(LayerTreeHostImplTest, ScrollChildAndChangePageScaleOnMainThread) { | 2111 TEST_F(LayerTreeHostImplTest, ScrollChildAndChangePageScaleOnMainThread) { |
2052 gfx::Size surface_size(10, 10); | 2112 gfx::Size surface_size(30, 30); |
2053 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 2113 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 2114 root->SetBounds(gfx::Size(5, 5)); |
2054 scoped_ptr<LayerImpl> root_scrolling = | 2115 scoped_ptr<LayerImpl> root_scrolling = |
2055 LayerImpl::Create(host_impl_->active_tree(), 2); | 2116 LayerImpl::Create(host_impl_->active_tree(), 2); |
2056 root_scrolling->SetBounds(surface_size); | 2117 root_scrolling->SetBounds(surface_size); |
2057 root_scrolling->SetContentBounds(surface_size); | 2118 root_scrolling->SetContentBounds(surface_size); |
2058 root_scrolling->SetScrollable(true); | 2119 root_scrolling->SetScrollClipLayer(root->id()); |
| 2120 LayerImpl* root_scrolling_ptr = root_scrolling.get(); |
2059 root->AddChild(root_scrolling.Pass()); | 2121 root->AddChild(root_scrolling.Pass()); |
2060 int child_scroll_layer_id = 3; | 2122 int child_scroll_layer_id = 3; |
2061 scoped_ptr<LayerImpl> child_scrolling = | 2123 scoped_ptr<LayerImpl> child_scrolling = CreateScrollableLayer( |
2062 CreateScrollableLayer(child_scroll_layer_id, surface_size); | 2124 child_scroll_layer_id, surface_size, root_scrolling_ptr); |
2063 LayerImpl* child = child_scrolling.get(); | 2125 LayerImpl* child = child_scrolling.get(); |
2064 root->AddChild(child_scrolling.Pass()); | 2126 root_scrolling_ptr->AddChild(child_scrolling.Pass()); |
2065 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2127 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 2128 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
2066 host_impl_->active_tree()->DidBecomeActive(); | 2129 host_impl_->active_tree()->DidBecomeActive(); |
2067 host_impl_->SetViewportSize(surface_size); | 2130 host_impl_->SetViewportSize(surface_size); |
2068 DrawFrame(); | 2131 DrawFrame(); |
2069 | 2132 |
2070 gfx::Vector2d scroll_delta(0, 10); | 2133 gfx::Vector2d scroll_delta(0, 10); |
2071 gfx::Vector2d expected_scroll_delta(scroll_delta); | 2134 gfx::Vector2d expected_scroll_delta(scroll_delta); |
2072 gfx::Vector2d expected_max_scroll(child->max_scroll_offset()); | 2135 gfx::Vector2d expected_max_scroll(child->MaxScrollOffset()); |
2073 EXPECT_EQ(InputHandler::ScrollStarted, | 2136 EXPECT_EQ(InputHandler::ScrollStarted, |
2074 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2137 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2075 InputHandler::Wheel)); | 2138 InputHandler::Wheel)); |
2076 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2139 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2077 host_impl_->ScrollEnd(); | 2140 host_impl_->ScrollEnd(); |
2078 | 2141 |
2079 float page_scale = 2.f; | 2142 float page_scale = 2.f; |
2080 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, | 2143 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, |
2081 1.f, | 2144 1.f, |
2082 page_scale); | 2145 page_scale); |
2083 | 2146 |
2084 DrawOneFrame(); | 2147 DrawOneFrame(); |
2085 | 2148 |
2086 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 2149 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
2087 ExpectContains( | 2150 ExpectContains( |
2088 *scroll_info.get(), child_scroll_layer_id, expected_scroll_delta); | 2151 *scroll_info.get(), child_scroll_layer_id, expected_scroll_delta); |
2089 | 2152 |
2090 // The scroll range should not have changed. | 2153 // The scroll range should not have changed. |
2091 EXPECT_EQ(child->max_scroll_offset(), expected_max_scroll); | 2154 EXPECT_EQ(child->MaxScrollOffset(), expected_max_scroll); |
2092 | 2155 |
2093 // The page scale delta remains constant because the impl thread did not | 2156 // The page scale delta remains constant because the impl thread did not |
2094 // scale. | 2157 // scale. |
2095 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); | 2158 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
2096 } | 2159 } |
2097 | 2160 |
2098 TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { | 2161 TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { |
2099 // Scroll a child layer beyond its maximum scroll range and make sure the | 2162 // Scroll a child layer beyond its maximum scroll range and make sure the |
2100 // parent layer is scrolled on the axis on which the child was unable to | 2163 // parent layer is scrolled on the axis on which the child was unable to |
2101 // scroll. | 2164 // scroll. |
2102 gfx::Size surface_size(10, 10); | 2165 gfx::Size surface_size(10, 10); |
2103 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, surface_size); | 2166 gfx::Size content_size(20, 20); |
| 2167 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 2168 root->SetBounds(surface_size); |
2104 | 2169 |
2105 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(3, surface_size); | 2170 scoped_ptr<LayerImpl> grand_child = |
2106 grand_child->SetScrollOffset(gfx::Vector2d(0, 5)); | 2171 CreateScrollableLayer(3, content_size, root.get()); |
2107 | 2172 |
2108 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, surface_size); | 2173 scoped_ptr<LayerImpl> child = |
2109 child->SetScrollOffset(gfx::Vector2d(3, 0)); | 2174 CreateScrollableLayer(2, content_size, root.get()); |
| 2175 LayerImpl* grand_child_layer = grand_child.get(); |
2110 child->AddChild(grand_child.Pass()); | 2176 child->AddChild(grand_child.Pass()); |
2111 | 2177 |
| 2178 LayerImpl* child_layer = child.get(); |
2112 root->AddChild(child.Pass()); | 2179 root->AddChild(child.Pass()); |
2113 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2180 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
2114 host_impl_->active_tree()->DidBecomeActive(); | 2181 host_impl_->active_tree()->DidBecomeActive(); |
2115 host_impl_->SetViewportSize(surface_size); | 2182 host_impl_->SetViewportSize(surface_size); |
| 2183 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 5)); |
| 2184 child_layer->SetScrollOffset(gfx::Vector2d(3, 0)); |
| 2185 |
2116 DrawFrame(); | 2186 DrawFrame(); |
2117 { | 2187 { |
2118 gfx::Vector2d scroll_delta(-8, -7); | 2188 gfx::Vector2d scroll_delta(-8, -7); |
2119 EXPECT_EQ(InputHandler::ScrollStarted, | 2189 EXPECT_EQ(InputHandler::ScrollStarted, |
2120 host_impl_->ScrollBegin(gfx::Point(), | 2190 host_impl_->ScrollBegin(gfx::Point(), |
2121 InputHandler::Wheel)); | 2191 InputHandler::Wheel)); |
2122 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2192 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2123 host_impl_->ScrollEnd(); | 2193 host_impl_->ScrollEnd(); |
2124 | 2194 |
2125 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2195 scoped_ptr<ScrollAndScaleSet> scroll_info = |
2126 host_impl_->ProcessScrollDeltas(); | 2196 host_impl_->ProcessScrollDeltas(); |
2127 | 2197 |
2128 // The grand child should have scrolled up to its limit. | 2198 // The grand child should have scrolled up to its limit. |
2129 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; | 2199 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; |
2130 LayerImpl* grand_child = child->children()[0]; | 2200 LayerImpl* grand_child = child->children()[0]; |
2131 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, -5)); | 2201 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, -5)); |
2132 | 2202 |
2133 // The child should have only scrolled on the other axis. | 2203 // The child should have only scrolled on the other axis. |
2134 ExpectContains(*scroll_info.get(), child->id(), gfx::Vector2d(-3, 0)); | 2204 ExpectContains(*scroll_info.get(), child->id(), gfx::Vector2d(-3, 0)); |
2135 } | 2205 } |
2136 } | 2206 } |
2137 | 2207 |
2138 TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { | 2208 TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { |
2139 // Scroll a child layer beyond its maximum scroll range and make sure the | 2209 // Scroll a child layer beyond its maximum scroll range and make sure the |
2140 // the scroll doesn't bubble up to the parent layer. | 2210 // the scroll doesn't bubble up to the parent layer. |
2141 gfx::Size surface_size(10, 10); | 2211 gfx::Size surface_size(20, 20); |
2142 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 2212 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
2143 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 2213 scoped_ptr<LayerImpl> root_scrolling = |
| 2214 CreateScrollableLayer(2, surface_size, root.get()); |
2144 | 2215 |
2145 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(4, surface_size); | 2216 scoped_ptr<LayerImpl> grand_child = |
2146 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); | 2217 CreateScrollableLayer(4, surface_size, root.get()); |
2147 | 2218 |
2148 scoped_ptr<LayerImpl> child = CreateScrollableLayer(3, surface_size); | 2219 scoped_ptr<LayerImpl> child = |
2149 child->SetScrollOffset(gfx::Vector2d(0, 3)); | 2220 CreateScrollableLayer(3, surface_size, root.get()); |
| 2221 LayerImpl* grand_child_layer = grand_child.get(); |
2150 child->AddChild(grand_child.Pass()); | 2222 child->AddChild(grand_child.Pass()); |
2151 | 2223 |
| 2224 LayerImpl* child_layer = child.get(); |
2152 root_scrolling->AddChild(child.Pass()); | 2225 root_scrolling->AddChild(child.Pass()); |
2153 root->AddChild(root_scrolling.Pass()); | 2226 root->AddChild(root_scrolling.Pass()); |
2154 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2227 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 2228 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
2155 host_impl_->active_tree()->DidBecomeActive(); | 2229 host_impl_->active_tree()->DidBecomeActive(); |
2156 host_impl_->SetViewportSize(surface_size); | 2230 host_impl_->SetViewportSize(surface_size); |
| 2231 |
| 2232 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 2)); |
| 2233 child_layer->SetScrollOffset(gfx::Vector2d(0, 3)); |
| 2234 |
2157 DrawFrame(); | 2235 DrawFrame(); |
2158 { | 2236 { |
2159 gfx::Vector2d scroll_delta(0, -10); | 2237 gfx::Vector2d scroll_delta(0, -10); |
2160 EXPECT_EQ(InputHandler::ScrollStarted, | 2238 EXPECT_EQ(InputHandler::ScrollStarted, |
2161 host_impl_->ScrollBegin(gfx::Point(), | 2239 host_impl_->ScrollBegin(gfx::Point(), |
2162 InputHandler::NonBubblingGesture)); | 2240 InputHandler::NonBubblingGesture)); |
2163 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2241 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2164 host_impl_->ScrollEnd(); | 2242 host_impl_->ScrollEnd(); |
2165 | 2243 |
2166 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2244 scoped_ptr<ScrollAndScaleSet> scroll_info = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2224 EXPECT_EQ(grand_child, host_impl_->CurrentlyScrollingLayer()); | 2302 EXPECT_EQ(grand_child, host_impl_->CurrentlyScrollingLayer()); |
2225 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2303 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2226 host_impl_->ScrollEnd(); | 2304 host_impl_->ScrollEnd(); |
2227 | 2305 |
2228 scroll_info = host_impl_->ProcessScrollDeltas(); | 2306 scroll_info = host_impl_->ProcessScrollDeltas(); |
2229 | 2307 |
2230 // Should have scrolled by half the amount in layer space (5 - 2/2) | 2308 // Should have scrolled by half the amount in layer space (5 - 2/2) |
2231 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, 4)); | 2309 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, 4)); |
2232 } | 2310 } |
2233 } | 2311 } |
2234 | |
2235 TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) { | 2312 TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) { |
2236 // When we try to scroll a non-scrollable child layer, the scroll delta | 2313 // When we try to scroll a non-scrollable child layer, the scroll delta |
2237 // should be applied to one of its ancestors if possible. | 2314 // should be applied to one of its ancestors if possible. |
2238 gfx::Size surface_size(10, 10); | 2315 gfx::Size surface_size(10, 10); |
2239 gfx::Size content_size(20, 20); | 2316 gfx::Size content_size(20, 20); |
2240 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 2317 scoped_ptr<LayerImpl> root_clip = |
2241 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 2318 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 2319 scoped_ptr<LayerImpl> root = |
| 2320 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 2321 // Make 'root' the clip layer for child: since they have the same sizes the |
| 2322 // child will have zero max_scroll_offset and scrolls will bubble. |
| 2323 scoped_ptr<LayerImpl> child = |
| 2324 CreateScrollableLayer(2, content_size, root.get()); |
| 2325 root->SetBounds(content_size); |
2242 | 2326 |
2243 child->SetScrollable(false); | 2327 int root_scroll_id = root->id(); |
2244 root->AddChild(child.Pass()); | 2328 root->AddChild(child.Pass()); |
| 2329 root_clip->AddChild(root.Pass()); |
2245 | 2330 |
2246 host_impl_->SetViewportSize(surface_size); | 2331 host_impl_->SetViewportSize(surface_size); |
2247 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2332 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 2333 host_impl_->active_tree()->SetViewportLayersFromIds(3, 2, Layer::INVALID_ID); |
2248 host_impl_->active_tree()->DidBecomeActive(); | 2334 host_impl_->active_tree()->DidBecomeActive(); |
2249 DrawFrame(); | 2335 DrawFrame(); |
2250 { | 2336 { |
2251 gfx::Vector2d scroll_delta(0, 4); | 2337 gfx::Vector2d scroll_delta(0, 4); |
2252 EXPECT_EQ(InputHandler::ScrollStarted, | 2338 EXPECT_EQ(InputHandler::ScrollStarted, |
2253 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2339 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2254 InputHandler::Wheel)); | 2340 InputHandler::Wheel)); |
2255 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2341 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2256 host_impl_->ScrollEnd(); | 2342 host_impl_->ScrollEnd(); |
2257 | 2343 |
2258 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2344 scoped_ptr<ScrollAndScaleSet> scroll_info = |
2259 host_impl_->ProcessScrollDeltas(); | 2345 host_impl_->ProcessScrollDeltas(); |
2260 | 2346 |
2261 // Only the root should have scrolled. | 2347 // Only the root scroll should have scrolled. |
2262 ASSERT_EQ(scroll_info->scrolls.size(), 1u); | 2348 ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
2263 ExpectContains(*scroll_info.get(), | 2349 ExpectContains(*scroll_info.get(), root_scroll_id, scroll_delta); |
2264 host_impl_->active_tree()->root_layer()->id(), | |
2265 scroll_delta); | |
2266 } | 2350 } |
2267 } | 2351 } |
2268 | 2352 |
2269 TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { | 2353 TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { |
2270 gfx::Size surface_size(10, 10); | 2354 gfx::Size surface_size(10, 10); |
2271 host_impl_->active_tree()->SetRootLayer( | 2355 scoped_ptr<LayerImpl> root_clip = |
2272 CreateScrollableLayer(1, surface_size)); | 2356 LayerImpl::Create(host_impl_->active_tree(), 1); |
| 2357 scoped_ptr<LayerImpl> root_scroll = |
| 2358 CreateScrollableLayer(2, surface_size, root_clip.get()); |
| 2359 root_clip->AddChild(root_scroll.Pass()); |
| 2360 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 2361 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
2273 host_impl_->active_tree()->DidBecomeActive(); | 2362 host_impl_->active_tree()->DidBecomeActive(); |
2274 host_impl_->SetViewportSize(surface_size); | 2363 host_impl_->SetViewportSize(surface_size); |
2275 | 2364 |
2276 // Draw one frame and then immediately rebuild the layer tree to mimic a tree | 2365 // Draw one frame and then immediately rebuild the layer tree to mimic a tree |
2277 // synchronization. | 2366 // synchronization. |
2278 DrawFrame(); | 2367 DrawFrame(); |
2279 host_impl_->active_tree()->DetachLayerTree(); | 2368 host_impl_->active_tree()->DetachLayerTree(); |
2280 host_impl_->active_tree()->SetRootLayer( | 2369 scoped_ptr<LayerImpl> root_clip2 = |
2281 CreateScrollableLayer(2, surface_size)); | 2370 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 2371 scoped_ptr<LayerImpl> root_scroll2 = |
| 2372 CreateScrollableLayer(4, surface_size, root_clip2.get()); |
| 2373 root_clip2->AddChild(root_scroll2.Pass()); |
| 2374 host_impl_->active_tree()->SetRootLayer(root_clip2.Pass()); |
| 2375 host_impl_->active_tree()->SetViewportLayersFromIds(3, 4, Layer::INVALID_ID); |
2282 host_impl_->active_tree()->DidBecomeActive(); | 2376 host_impl_->active_tree()->DidBecomeActive(); |
2283 | 2377 |
2284 // Scrolling should still work even though we did not draw yet. | 2378 // Scrolling should still work even though we did not draw yet. |
2285 EXPECT_EQ(InputHandler::ScrollStarted, | 2379 EXPECT_EQ(InputHandler::ScrollStarted, |
2286 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2380 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2287 InputHandler::Wheel)); | 2381 InputHandler::Wheel)); |
2288 } | 2382 } |
2289 | 2383 |
2290 TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { | 2384 TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { |
2291 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2385 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2324 | 2418 |
2325 // The layer should have scrolled down in its local coordinates. | 2419 // The layer should have scrolled down in its local coordinates. |
2326 scroll_info = host_impl_->ProcessScrollDeltas(); | 2420 scroll_info = host_impl_->ProcessScrollDeltas(); |
2327 ExpectContains(*scroll_info.get(), | 2421 ExpectContains(*scroll_info.get(), |
2328 scroll_layer->id(), | 2422 scroll_layer->id(), |
2329 wheel_scroll_delta); | 2423 wheel_scroll_delta); |
2330 } | 2424 } |
2331 | 2425 |
2332 TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { | 2426 TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { |
2333 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2427 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
2334 int child_layer_id = 4; | 2428 int child_layer_id = 6; |
2335 float child_layer_angle = -20.f; | 2429 float child_layer_angle = -20.f; |
2336 | 2430 |
2337 // Create a child layer that is rotated to a non-axis-aligned angle. | 2431 // Create a child layer that is rotated to a non-axis-aligned angle. |
| 2432 LayerImpl* clip_layer = host_impl_->active_tree()->root_layer(); |
2338 scoped_ptr<LayerImpl> child = CreateScrollableLayer( | 2433 scoped_ptr<LayerImpl> child = CreateScrollableLayer( |
2339 child_layer_id, | 2434 child_layer_id, scroll_layer->content_bounds(), clip_layer); |
2340 scroll_layer->content_bounds()); | |
2341 gfx::Transform rotate_transform; | 2435 gfx::Transform rotate_transform; |
2342 rotate_transform.Translate(-50.0, -50.0); | 2436 rotate_transform.Translate(-50.0, -50.0); |
2343 rotate_transform.Rotate(child_layer_angle); | 2437 rotate_transform.Rotate(child_layer_angle); |
2344 rotate_transform.Translate(50.0, 50.0); | 2438 rotate_transform.Translate(50.0, 50.0); |
2345 child->SetTransform(rotate_transform); | 2439 child->SetTransform(rotate_transform); |
2346 | 2440 |
2347 // Only allow vertical scrolling. | 2441 // Only allow vertical scrolling. |
2348 child->SetMaxScrollOffset(gfx::Vector2d(0, child->content_bounds().height())); | 2442 clip_layer->SetBounds(gfx::Size(child->bounds().width(), 0)); |
2349 scroll_layer->AddChild(child.Pass()); | 2443 scroll_layer->AddChild(child.Pass()); |
2350 | 2444 |
2351 gfx::Size surface_size(50, 50); | 2445 gfx::Size surface_size(50, 50); |
2352 host_impl_->SetViewportSize(surface_size); | 2446 host_impl_->SetViewportSize(surface_size); |
2353 DrawFrame(); | 2447 DrawFrame(); |
2354 { | 2448 { |
2355 // Scroll down in screen coordinates with a gesture. | 2449 // Scroll down in screen coordinates with a gesture. |
2356 gfx::Vector2d gesture_scroll_delta(0, 10); | 2450 gfx::Vector2d gesture_scroll_delta(0, 10); |
2357 EXPECT_EQ(InputHandler::ScrollStarted, | 2451 EXPECT_EQ(InputHandler::ScrollStarted, |
2358 host_impl_->ScrollBegin(gfx::Point(1, 1), | 2452 host_impl_->ScrollBegin(gfx::Point(1, 1), |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2503 gfx::Vector2dF getter_return_value_; | 2597 gfx::Vector2dF getter_return_value_; |
2504 gfx::Vector2dF max_scroll_offset_; | 2598 gfx::Vector2dF max_scroll_offset_; |
2505 gfx::SizeF scrollable_size_; | 2599 gfx::SizeF scrollable_size_; |
2506 float page_scale_factor_; | 2600 float page_scale_factor_; |
2507 }; | 2601 }; |
2508 | 2602 |
2509 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { | 2603 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { |
2510 TestScrollOffsetDelegate scroll_delegate; | 2604 TestScrollOffsetDelegate scroll_delegate; |
2511 host_impl_->SetViewportSize(gfx::Size(10, 20)); | 2605 host_impl_->SetViewportSize(gfx::Size(10, 20)); |
2512 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2606 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2607 LayerImpl* clip_layer = scroll_layer->parent()->parent(); |
| 2608 clip_layer->SetBounds(gfx::Size(10, 20)); |
2513 | 2609 |
2514 // Setting the delegate results in the current scroll offset being set. | 2610 // Setting the delegate results in the current scroll offset being set. |
2515 gfx::Vector2dF initial_scroll_delta(10.f, 10.f); | 2611 gfx::Vector2dF initial_scroll_delta(10.f, 10.f); |
2516 scroll_layer->SetScrollOffset(gfx::Vector2d()); | 2612 scroll_layer->SetScrollOffset(gfx::Vector2d()); |
2517 scroll_layer->SetScrollDelta(initial_scroll_delta); | 2613 scroll_layer->SetScrollDelta(initial_scroll_delta); |
2518 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate); | 2614 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate); |
2519 EXPECT_EQ(initial_scroll_delta.ToString(), | 2615 EXPECT_EQ(initial_scroll_delta.ToString(), |
2520 scroll_delegate.last_set_scroll_offset().ToString()); | 2616 scroll_delegate.last_set_scroll_offset().ToString()); |
2521 | 2617 |
2522 // Setting the delegate results in the scrollable_size, max_scroll_offset and | 2618 // 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... |
2626 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 2722 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
2627 EXPECT_EQ(gfx::Vector2dF(0, -20), host_impl_->accumulated_root_overscroll()); | 2723 EXPECT_EQ(gfx::Vector2dF(0, -20), host_impl_->accumulated_root_overscroll()); |
2628 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); | 2724 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); |
2629 } | 2725 } |
2630 | 2726 |
2631 | 2727 |
2632 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { | 2728 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { |
2633 // Scroll child layers beyond their maximum scroll range and make sure root | 2729 // Scroll child layers beyond their maximum scroll range and make sure root |
2634 // overscroll does not accumulate. | 2730 // overscroll does not accumulate. |
2635 gfx::Size surface_size(10, 10); | 2731 gfx::Size surface_size(10, 10); |
2636 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, surface_size); | 2732 scoped_ptr<LayerImpl> root_clip = |
| 2733 LayerImpl::Create(host_impl_->active_tree(), 4); |
| 2734 scoped_ptr<LayerImpl> root = |
| 2735 CreateScrollableLayer(1, surface_size, root_clip.get()); |
2637 | 2736 |
2638 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(3, surface_size); | 2737 scoped_ptr<LayerImpl> grand_child = |
2639 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); | 2738 CreateScrollableLayer(3, surface_size, root_clip.get()); |
2640 | 2739 |
2641 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, surface_size); | 2740 scoped_ptr<LayerImpl> child = |
2642 child->SetScrollOffset(gfx::Vector2d(0, 3)); | 2741 CreateScrollableLayer(2, surface_size, root_clip.get()); |
| 2742 LayerImpl* grand_child_layer = grand_child.get(); |
2643 child->AddChild(grand_child.Pass()); | 2743 child->AddChild(grand_child.Pass()); |
2644 | 2744 |
| 2745 LayerImpl* child_layer = child.get(); |
2645 root->AddChild(child.Pass()); | 2746 root->AddChild(child.Pass()); |
2646 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2747 root_clip->AddChild(root.Pass()); |
| 2748 child_layer->SetScrollOffset(gfx::Vector2d(0, 3)); |
| 2749 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 2)); |
| 2750 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
2647 host_impl_->active_tree()->DidBecomeActive(); | 2751 host_impl_->active_tree()->DidBecomeActive(); |
2648 host_impl_->SetViewportSize(surface_size); | 2752 host_impl_->SetViewportSize(surface_size); |
2649 DrawFrame(); | 2753 DrawFrame(); |
2650 { | 2754 { |
2651 gfx::Vector2d scroll_delta(0, -10); | 2755 gfx::Vector2d scroll_delta(0, -10); |
2652 EXPECT_EQ(InputHandler::ScrollStarted, | 2756 EXPECT_EQ(InputHandler::ScrollStarted, |
2653 host_impl_->ScrollBegin(gfx::Point(), | 2757 host_impl_->ScrollBegin(gfx::Point(), |
2654 InputHandler::NonBubblingGesture)); | 2758 InputHandler::NonBubblingGesture)); |
2655 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2759 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2656 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2760 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2657 host_impl_->ScrollEnd(); | 2761 host_impl_->ScrollEnd(); |
2658 | 2762 |
2659 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; | |
2660 LayerImpl* grand_child = child->children()[0]; | |
2661 | |
2662 // The next time we scroll we should only scroll the parent, but overscroll | 2763 // The next time we scroll we should only scroll the parent, but overscroll |
2663 // should still not reach the root layer. | 2764 // should still not reach the root layer. |
2664 scroll_delta = gfx::Vector2d(0, -30); | 2765 scroll_delta = gfx::Vector2d(0, -30); |
2665 EXPECT_EQ(InputHandler::ScrollStarted, | 2766 EXPECT_EQ(InputHandler::ScrollStarted, |
2666 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2767 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2667 InputHandler::NonBubblingGesture)); | 2768 InputHandler::NonBubblingGesture)); |
2668 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 2769 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
2669 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2770 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2670 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2771 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2671 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); | 2772 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_layer); |
2672 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2773 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2673 host_impl_->ScrollEnd(); | 2774 host_impl_->ScrollEnd(); |
2674 | 2775 |
2675 // After scrolling the parent, another scroll on the opposite direction | 2776 // After scrolling the parent, another scroll on the opposite direction |
2676 // should scroll the child, resetting the fling velocity. | 2777 // should scroll the child, resetting the fling velocity. |
2677 scroll_delta = gfx::Vector2d(0, 70); | 2778 scroll_delta = gfx::Vector2d(0, 70); |
2678 host_impl_->NotifyCurrentFlingVelocity(gfx::Vector2dF(10, 0)); | 2779 host_impl_->NotifyCurrentFlingVelocity(gfx::Vector2dF(10, 0)); |
2679 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); | 2780 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); |
2680 EXPECT_EQ(InputHandler::ScrollStarted, | 2781 EXPECT_EQ(InputHandler::ScrollStarted, |
2681 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2782 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2682 InputHandler::NonBubblingGesture)); | 2783 InputHandler::NonBubblingGesture)); |
2683 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 2784 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
2684 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2785 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2685 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 2786 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
2686 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2787 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2687 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | 2788 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
2688 host_impl_->ScrollEnd(); | 2789 host_impl_->ScrollEnd(); |
2689 } | 2790 } |
2690 } | 2791 } |
2691 | 2792 |
2692 TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { | 2793 TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { |
2693 // When we try to scroll a non-scrollable child layer, the scroll delta | 2794 // When we try to scroll a non-scrollable child layer, the scroll delta |
2694 // should be applied to one of its ancestors if possible. Overscroll should | 2795 // should be applied to one of its ancestors if possible. Overscroll should |
2695 // be reflected only when it has bubbled up to the root scrolling layer. | 2796 // be reflected only when it has bubbled up to the root scrolling layer. |
2696 gfx::Size surface_size(10, 10); | 2797 gfx::Size surface_size(10, 10); |
2697 gfx::Size content_size(20, 20); | 2798 gfx::Size content_size(20, 20); |
2698 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 2799 scoped_ptr<LayerImpl> root_clip = |
2699 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 2800 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 2801 scoped_ptr<LayerImpl> root = |
| 2802 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 2803 scoped_ptr<LayerImpl> child = |
| 2804 CreateScrollableLayer(2, content_size, root_clip.get()); |
2700 | 2805 |
2701 child->SetScrollable(false); | 2806 child->SetScrollClipLayer(Layer::INVALID_ID); |
2702 root->AddChild(child.Pass()); | 2807 root->AddChild(child.Pass()); |
| 2808 root_clip->AddChild(root.Pass()); |
2703 | 2809 |
2704 host_impl_->SetViewportSize(surface_size); | 2810 host_impl_->SetViewportSize(surface_size); |
2705 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2811 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 2812 host_impl_->active_tree()->SetViewportLayersFromIds(3, 1, Layer::INVALID_ID); |
2706 host_impl_->active_tree()->DidBecomeActive(); | 2813 host_impl_->active_tree()->DidBecomeActive(); |
2707 DrawFrame(); | 2814 DrawFrame(); |
2708 { | 2815 { |
2709 gfx::Vector2d scroll_delta(0, 8); | 2816 gfx::Vector2d scroll_delta(0, 8); |
2710 EXPECT_EQ(InputHandler::ScrollStarted, | 2817 EXPECT_EQ(InputHandler::ScrollStarted, |
2711 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2818 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2712 InputHandler::Wheel)); | 2819 InputHandler::Wheel)); |
2713 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2820 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2714 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2821 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2715 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2822 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2716 EXPECT_EQ(gfx::Vector2dF(0, 6), host_impl_->accumulated_root_overscroll()); | 2823 EXPECT_EQ(gfx::Vector2dF(0, 6), host_impl_->accumulated_root_overscroll()); |
2717 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2824 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2718 EXPECT_EQ(gfx::Vector2dF(0, 14), host_impl_->accumulated_root_overscroll()); | 2825 EXPECT_EQ(gfx::Vector2dF(0, 14), host_impl_->accumulated_root_overscroll()); |
2719 host_impl_->ScrollEnd(); | 2826 host_impl_->ScrollEnd(); |
2720 } | 2827 } |
2721 } | 2828 } |
2722 | 2829 |
2723 TEST_F(LayerTreeHostImplTest, OverscrollAlways) { | 2830 TEST_F(LayerTreeHostImplTest, OverscrollAlways) { |
2724 LayerTreeSettings settings; | 2831 LayerTreeSettings settings; |
2725 settings.always_overscroll = true; | 2832 settings.always_overscroll = true; |
2726 CreateHostImpl(settings, CreateOutputSurface()); | 2833 CreateHostImpl(settings, CreateOutputSurface()); |
2727 | 2834 |
2728 SetupScrollAndContentsLayers(gfx::Size(50, 50)); | 2835 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); |
| 2836 LayerImpl* clip_layer = scroll_layer->parent()->parent(); |
| 2837 clip_layer->SetBounds(gfx::Size(50, 50)); |
2729 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 2838 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
2730 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 2839 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
2731 DrawFrame(); | 2840 DrawFrame(); |
2732 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2841 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2733 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | 2842 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
2734 | 2843 |
2735 // Even though the layer can't scroll the overscroll still happens. | 2844 // Even though the layer can't scroll the overscroll still happens. |
2736 EXPECT_EQ(InputHandler::ScrollStarted, | 2845 EXPECT_EQ(InputHandler::ScrollStarted, |
2737 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 2846 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
2738 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 2847 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
(...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4748 scoped_ptr<FakePictureLayerImpl> scoped_content_layer = | 4857 scoped_ptr<FakePictureLayerImpl> scoped_content_layer = |
4749 FakePictureLayerImpl::CreateWithPile(host_impl_->pending_tree(), 3, pile); | 4858 FakePictureLayerImpl::CreateWithPile(host_impl_->pending_tree(), 3, pile); |
4750 LayerImpl* content_layer = scoped_content_layer.get(); | 4859 LayerImpl* content_layer = scoped_content_layer.get(); |
4751 scrolling_layer->AddChild(scoped_content_layer.PassAs<LayerImpl>()); | 4860 scrolling_layer->AddChild(scoped_content_layer.PassAs<LayerImpl>()); |
4752 content_layer->SetBounds(content_layer_bounds); | 4861 content_layer->SetBounds(content_layer_bounds); |
4753 content_layer->SetDrawsContent(true); | 4862 content_layer->SetDrawsContent(true); |
4754 | 4863 |
4755 root->SetBounds(root_size); | 4864 root->SetBounds(root_size); |
4756 | 4865 |
4757 gfx::Vector2d scroll_offset(100000, 0); | 4866 gfx::Vector2d scroll_offset(100000, 0); |
4758 scrolling_layer->SetScrollable(true); | 4867 scrolling_layer->SetScrollClipLayer(root->id()); |
4759 scrolling_layer->SetMaxScrollOffset(scroll_offset); | |
4760 scrolling_layer->SetScrollOffset(scroll_offset); | 4868 scrolling_layer->SetScrollOffset(scroll_offset); |
4761 | 4869 |
4762 host_impl_->ActivatePendingTree(); | 4870 host_impl_->ActivatePendingTree(); |
4763 | 4871 |
4764 host_impl_->active_tree()->UpdateDrawProperties(); | 4872 host_impl_->active_tree()->UpdateDrawProperties(); |
4765 ASSERT_EQ(1u, host_impl_->active_tree()->RenderSurfaceLayerList().size()); | 4873 ASSERT_EQ(1u, host_impl_->active_tree()->RenderSurfaceLayerList().size()); |
4766 | 4874 |
4767 LayerTreeHostImpl::FrameData frame; | 4875 LayerTreeHostImpl::FrameData frame; |
4768 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 4876 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
4769 | 4877 |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5181 // released, and the texture deleted. | 5289 // released, and the texture deleted. |
5182 EXPECT_TRUE(context_provider->HasOneRef()); | 5290 EXPECT_TRUE(context_provider->HasOneRef()); |
5183 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); | 5291 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); |
5184 } | 5292 } |
5185 | 5293 |
5186 TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { | 5294 TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { |
5187 // When flinging via touch, only the child should scroll (we should not | 5295 // When flinging via touch, only the child should scroll (we should not |
5188 // bubble). | 5296 // bubble). |
5189 gfx::Size surface_size(10, 10); | 5297 gfx::Size surface_size(10, 10); |
5190 gfx::Size content_size(20, 20); | 5298 gfx::Size content_size(20, 20); |
5191 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 5299 scoped_ptr<LayerImpl> root_clip = |
5192 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 5300 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 5301 scoped_ptr<LayerImpl> root = |
| 5302 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 5303 scoped_ptr<LayerImpl> child = |
| 5304 CreateScrollableLayer(2, content_size, root_clip.get()); |
5193 | 5305 |
5194 root->AddChild(child.Pass()); | 5306 root->AddChild(child.Pass()); |
| 5307 int root_id = root->id(); |
| 5308 root_clip->AddChild(root.Pass()); |
5195 | 5309 |
5196 host_impl_->SetViewportSize(surface_size); | 5310 host_impl_->SetViewportSize(surface_size); |
5197 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 5311 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 5312 host_impl_->active_tree()->SetViewportLayersFromIds(3, 1, Layer::INVALID_ID); |
5198 host_impl_->active_tree()->DidBecomeActive(); | 5313 host_impl_->active_tree()->DidBecomeActive(); |
5199 DrawFrame(); | 5314 DrawFrame(); |
5200 { | 5315 { |
5201 EXPECT_EQ(InputHandler::ScrollStarted, | 5316 EXPECT_EQ(InputHandler::ScrollStarted, |
5202 host_impl_->ScrollBegin(gfx::Point(), | 5317 host_impl_->ScrollBegin(gfx::Point(), |
5203 InputHandler::Gesture)); | 5318 InputHandler::Gesture)); |
5204 | 5319 |
5205 EXPECT_EQ(InputHandler::ScrollStarted, | 5320 EXPECT_EQ(InputHandler::ScrollStarted, |
5206 host_impl_->FlingScrollBegin()); | 5321 host_impl_->FlingScrollBegin()); |
5207 | 5322 |
5208 gfx::Vector2d scroll_delta(0, 100); | 5323 gfx::Vector2d scroll_delta(0, 100); |
5209 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5324 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5210 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5325 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5211 | 5326 |
5212 host_impl_->ScrollEnd(); | 5327 host_impl_->ScrollEnd(); |
5213 | 5328 |
5214 scoped_ptr<ScrollAndScaleSet> scroll_info = | 5329 scoped_ptr<ScrollAndScaleSet> scroll_info = |
5215 host_impl_->ProcessScrollDeltas(); | 5330 host_impl_->ProcessScrollDeltas(); |
5216 | 5331 |
5217 // Only the child should have scrolled. | 5332 // Only the child should have scrolled. |
5218 ASSERT_EQ(1u, scroll_info->scrolls.size()); | 5333 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
5219 ExpectNone(*scroll_info.get(), | 5334 ExpectNone(*scroll_info.get(), root_id); |
5220 host_impl_->active_tree()->root_layer()->id()); | |
5221 } | 5335 } |
5222 } | 5336 } |
5223 | 5337 |
5224 TEST_F(LayerTreeHostImplTest, TouchFlingShouldLockToFirstScrolledLayer) { | 5338 TEST_F(LayerTreeHostImplTest, TouchFlingShouldLockToFirstScrolledLayer) { |
5225 // Scroll a child layer beyond its maximum scroll range and make sure the | 5339 // Scroll a child layer beyond its maximum scroll range and make sure the |
5226 // the scroll doesn't bubble up to the parent layer. | 5340 // the scroll doesn't bubble up to the parent layer. |
5227 gfx::Size surface_size(10, 10); | 5341 gfx::Size surface_size(10, 10); |
5228 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 5342 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
5229 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 5343 scoped_ptr<LayerImpl> root_scrolling = |
| 5344 CreateScrollableLayer(2, surface_size, root.get()); |
5230 | 5345 |
5231 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(4, surface_size); | 5346 scoped_ptr<LayerImpl> grand_child = |
| 5347 CreateScrollableLayer(4, surface_size, root.get()); |
5232 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); | 5348 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); |
5233 | 5349 |
5234 scoped_ptr<LayerImpl> child = CreateScrollableLayer(3, surface_size); | 5350 scoped_ptr<LayerImpl> child = |
| 5351 CreateScrollableLayer(3, surface_size, root.get()); |
5235 child->SetScrollOffset(gfx::Vector2d(0, 4)); | 5352 child->SetScrollOffset(gfx::Vector2d(0, 4)); |
5236 child->AddChild(grand_child.Pass()); | 5353 child->AddChild(grand_child.Pass()); |
5237 | 5354 |
5238 root_scrolling->AddChild(child.Pass()); | 5355 root_scrolling->AddChild(child.Pass()); |
5239 root->AddChild(root_scrolling.Pass()); | 5356 root->AddChild(root_scrolling.Pass()); |
5240 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 5357 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
5241 host_impl_->active_tree()->DidBecomeActive(); | 5358 host_impl_->active_tree()->DidBecomeActive(); |
5242 host_impl_->SetViewportSize(surface_size); | 5359 host_impl_->SetViewportSize(surface_size); |
5243 DrawFrame(); | 5360 DrawFrame(); |
5244 { | 5361 { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5284 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); | 5401 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); |
5285 host_impl_->ScrollEnd(); | 5402 host_impl_->ScrollEnd(); |
5286 } | 5403 } |
5287 } | 5404 } |
5288 | 5405 |
5289 TEST_F(LayerTreeHostImplTest, WheelFlingShouldBubble) { | 5406 TEST_F(LayerTreeHostImplTest, WheelFlingShouldBubble) { |
5290 // When flinging via wheel, the root should eventually scroll (we should | 5407 // When flinging via wheel, the root should eventually scroll (we should |
5291 // bubble). | 5408 // bubble). |
5292 gfx::Size surface_size(10, 10); | 5409 gfx::Size surface_size(10, 10); |
5293 gfx::Size content_size(20, 20); | 5410 gfx::Size content_size(20, 20); |
5294 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 5411 scoped_ptr<LayerImpl> root_clip = |
5295 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 5412 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 5413 scoped_ptr<LayerImpl> root_scroll = |
| 5414 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 5415 int root_scroll_id = root_scroll->id(); |
| 5416 scoped_ptr<LayerImpl> child = |
| 5417 CreateScrollableLayer(2, content_size, root_clip.get()); |
5296 | 5418 |
5297 root->AddChild(child.Pass()); | 5419 root_scroll->AddChild(child.Pass()); |
| 5420 root_clip->AddChild(root_scroll.Pass()); |
5298 | 5421 |
5299 host_impl_->SetViewportSize(surface_size); | 5422 host_impl_->SetViewportSize(surface_size); |
5300 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 5423 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
5301 host_impl_->active_tree()->DidBecomeActive(); | 5424 host_impl_->active_tree()->DidBecomeActive(); |
5302 DrawFrame(); | 5425 DrawFrame(); |
5303 { | 5426 { |
5304 EXPECT_EQ(InputHandler::ScrollStarted, | 5427 EXPECT_EQ(InputHandler::ScrollStarted, |
5305 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 5428 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
5306 | 5429 |
5307 EXPECT_EQ(InputHandler::ScrollStarted, | 5430 EXPECT_EQ(InputHandler::ScrollStarted, |
5308 host_impl_->FlingScrollBegin()); | 5431 host_impl_->FlingScrollBegin()); |
5309 | 5432 |
5310 gfx::Vector2d scroll_delta(0, 100); | 5433 gfx::Vector2d scroll_delta(0, 100); |
5311 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5434 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5312 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5435 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5313 | 5436 |
5314 host_impl_->ScrollEnd(); | 5437 host_impl_->ScrollEnd(); |
5315 | 5438 |
5316 scoped_ptr<ScrollAndScaleSet> scroll_info = | 5439 scoped_ptr<ScrollAndScaleSet> scroll_info = |
5317 host_impl_->ProcessScrollDeltas(); | 5440 host_impl_->ProcessScrollDeltas(); |
5318 | 5441 |
5319 // The root should have scrolled. | 5442 // The root should have scrolled. |
5320 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 5443 ASSERT_EQ(2u, scroll_info->scrolls.size()); |
5321 ExpectContains(*scroll_info.get(), | 5444 ExpectContains(*scroll_info.get(), root_scroll_id, gfx::Vector2d(0, 10)); |
5322 host_impl_->active_tree()->root_layer()->id(), | |
5323 gfx::Vector2d(0, 10)); | |
5324 } | 5445 } |
5325 } | 5446 } |
5326 | 5447 |
5327 // Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed | 5448 // Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed |
5328 // to CompositorFrameMetadata after SwapBuffers(); | 5449 // to CompositorFrameMetadata after SwapBuffers(); |
5329 TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) { | 5450 TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) { |
5330 scoped_ptr<SolidColorLayerImpl> root = | 5451 scoped_ptr<SolidColorLayerImpl> root = |
5331 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | 5452 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
5332 root->SetAnchorPoint(gfx::PointF()); | 5453 root->SetAnchorPoint(gfx::PointF()); |
5333 root->SetPosition(gfx::PointF()); | 5454 root->SetPosition(gfx::PointF()); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5431 &set_needs_redraw_count)); | 5552 &set_needs_redraw_count)); |
5432 // Empty damage rect won't signal the monitor. | 5553 // Empty damage rect won't signal the monitor. |
5433 host_impl_->SetNeedsRedrawRect(gfx::Rect()); | 5554 host_impl_->SetNeedsRedrawRect(gfx::Rect()); |
5434 EXPECT_EQ(0, set_needs_commit_count); | 5555 EXPECT_EQ(0, set_needs_commit_count); |
5435 EXPECT_EQ(2, set_needs_redraw_count); | 5556 EXPECT_EQ(2, set_needs_redraw_count); |
5436 } | 5557 } |
5437 } | 5558 } |
5438 | 5559 |
5439 } // namespace | 5560 } // namespace |
5440 } // namespace cc | 5561 } // namespace cc |
OLD | NEW |