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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 if (scroll_info.scrolls[i].layer_id != id) | 198 if (scroll_info.scrolls[i].layer_id != id) |
199 continue; | 199 continue; |
200 times_encountered++; | 200 times_encountered++; |
201 } | 201 } |
202 | 202 |
203 ASSERT_EQ(0, times_encountered); | 203 ASSERT_EQ(0, times_encountered); |
204 } | 204 } |
205 | 205 |
206 LayerImpl* CreateScrollAndContentsLayers(LayerTreeImpl* layer_tree_impl, | 206 LayerImpl* CreateScrollAndContentsLayers(LayerTreeImpl* layer_tree_impl, |
207 const gfx::Size& content_size) { | 207 const gfx::Size& content_size) { |
| 208 const int kInnerViewportScrollLayerId = 2; |
| 209 const int kInnerViewportClipLayerId = 4; |
| 210 const int kPageScaleLayerId = 5; |
208 scoped_ptr<LayerImpl> root = | 211 scoped_ptr<LayerImpl> root = |
209 LayerImpl::Create(layer_tree_impl, 1); | 212 LayerImpl::Create(layer_tree_impl, 1); |
210 root->SetBounds(content_size); | 213 root->SetBounds(content_size); |
211 root->SetContentBounds(content_size); | 214 root->SetContentBounds(content_size); |
212 root->SetPosition(gfx::PointF()); | 215 root->SetPosition(gfx::PointF()); |
213 root->SetAnchorPoint(gfx::PointF()); | 216 root->SetAnchorPoint(gfx::PointF()); |
214 | 217 |
215 scoped_ptr<LayerImpl> scroll = | 218 scoped_ptr<LayerImpl> scroll = |
216 LayerImpl::Create(layer_tree_impl, 2); | 219 LayerImpl::Create(layer_tree_impl, kInnerViewportScrollLayerId); |
217 LayerImpl* scroll_layer = scroll.get(); | 220 LayerImpl* scroll_layer = scroll.get(); |
218 scroll->SetScrollable(true); | 221 scroll->SetIsContainerForFixedPositionLayers(true); |
219 scroll->SetScrollOffset(gfx::Vector2d()); | 222 scroll->SetScrollOffset(gfx::Vector2d()); |
220 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | 223 |
221 content_size.height())); | 224 scoped_ptr<LayerImpl> clip = |
| 225 LayerImpl::Create(layer_tree_impl, kInnerViewportClipLayerId); |
| 226 clip->SetBounds( |
| 227 gfx::Size(content_size.width() / 2, content_size.height() / 2)); |
| 228 |
| 229 scoped_ptr<LayerImpl> page_scale = |
| 230 LayerImpl::Create(layer_tree_impl, kPageScaleLayerId); |
| 231 |
| 232 scroll->SetScrollClipLayer(clip->id()); |
222 scroll->SetBounds(content_size); | 233 scroll->SetBounds(content_size); |
223 scroll->SetContentBounds(content_size); | 234 scroll->SetContentBounds(content_size); |
224 scroll->SetPosition(gfx::PointF()); | 235 scroll->SetPosition(gfx::PointF()); |
225 scroll->SetAnchorPoint(gfx::PointF()); | 236 scroll->SetAnchorPoint(gfx::PointF()); |
| 237 scroll->SetIsContainerForFixedPositionLayers(true); |
226 | 238 |
227 scoped_ptr<LayerImpl> contents = | 239 scoped_ptr<LayerImpl> contents = |
228 LayerImpl::Create(layer_tree_impl, 3); | 240 LayerImpl::Create(layer_tree_impl, 3); |
229 contents->SetDrawsContent(true); | 241 contents->SetDrawsContent(true); |
230 contents->SetBounds(content_size); | 242 contents->SetBounds(content_size); |
231 contents->SetContentBounds(content_size); | 243 contents->SetContentBounds(content_size); |
232 contents->SetPosition(gfx::PointF()); | 244 contents->SetPosition(gfx::PointF()); |
233 contents->SetAnchorPoint(gfx::PointF()); | 245 contents->SetAnchorPoint(gfx::PointF()); |
234 | 246 |
235 scroll->AddChild(contents.Pass()); | 247 scroll->AddChild(contents.Pass()); |
236 root->AddChild(scroll.Pass()); | 248 page_scale->AddChild(scroll.Pass()); |
| 249 clip->AddChild(page_scale.Pass()); |
| 250 root->AddChild(clip.Pass()); |
237 | 251 |
238 layer_tree_impl->SetRootLayer(root.Pass()); | 252 layer_tree_impl->SetRootLayer(root.Pass()); |
| 253 layer_tree_impl->SetViewportLayersFromIds( |
| 254 kPageScaleLayerId, kInnerViewportScrollLayerId, Layer::INVALID_ID); |
| 255 |
239 return scroll_layer; | 256 return scroll_layer; |
240 } | 257 } |
241 | 258 |
242 LayerImpl* SetupScrollAndContentsLayers(const gfx::Size& content_size) { | 259 LayerImpl* SetupScrollAndContentsLayers(const gfx::Size& content_size) { |
243 LayerImpl* scroll_layer = CreateScrollAndContentsLayers( | 260 LayerImpl* scroll_layer = CreateScrollAndContentsLayers( |
244 host_impl_->active_tree(), content_size); | 261 host_impl_->active_tree(), content_size); |
245 host_impl_->active_tree()->DidBecomeActive(); | 262 host_impl_->active_tree()->DidBecomeActive(); |
246 return scroll_layer; | 263 return scroll_layer; |
247 } | 264 } |
248 | 265 |
249 scoped_ptr<LayerImpl> CreateScrollableLayer(int id, const gfx::Size& size) { | 266 // TODO(wjmaclean) Add clip-layer pointer to parameters. |
| 267 scoped_ptr<LayerImpl> CreateScrollableLayer(int id, |
| 268 const gfx::Size& size, |
| 269 LayerImpl* clip_layer) { |
| 270 DCHECK(clip_layer); |
| 271 DCHECK(id != clip_layer->id()); |
250 scoped_ptr<LayerImpl> layer = | 272 scoped_ptr<LayerImpl> layer = |
251 LayerImpl::Create(host_impl_->active_tree(), id); | 273 LayerImpl::Create(host_impl_->active_tree(), id); |
252 layer->SetScrollable(true); | 274 layer->SetScrollClipLayer(clip_layer->id()); |
253 layer->SetDrawsContent(true); | 275 layer->SetDrawsContent(true); |
254 layer->SetBounds(size); | 276 layer->SetBounds(size); |
255 layer->SetContentBounds(size); | 277 layer->SetContentBounds(size); |
256 layer->SetMaxScrollOffset(gfx::Vector2d(size.width() * 2, | 278 clip_layer->SetBounds(gfx::Size(size.width() / 2, size.height() / 2)); |
257 size.height() * 2)); | |
258 return layer.Pass(); | 279 return layer.Pass(); |
259 } | 280 } |
260 | 281 |
261 void DrawFrame() { | 282 void DrawFrame() { |
262 LayerTreeHostImpl::FrameData frame; | 283 LayerTreeHostImpl::FrameData frame; |
263 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, | 284 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, |
264 host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 285 host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
265 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 286 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
266 host_impl_->DidDrawAllLayers(frame); | 287 host_impl_->DidDrawAllLayers(frame); |
267 } | 288 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 | 437 |
417 scroll_info = host_impl_->ProcessScrollDeltas(); | 438 scroll_info = host_impl_->ProcessScrollDeltas(); |
418 ASSERT_EQ(scroll_info->scrolls.size(), 0u); | 439 ASSERT_EQ(scroll_info->scrolls.size(), 0u); |
419 ExpectClearedScrollDeltasRecursive(root); | 440 ExpectClearedScrollDeltasRecursive(root); |
420 } | 441 } |
421 | 442 |
422 TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) { | 443 TEST_F(LayerTreeHostImplTest, ScrollDeltaRepeatedScrolls) { |
423 gfx::Vector2d scroll_offset(20, 30); | 444 gfx::Vector2d scroll_offset(20, 30); |
424 gfx::Vector2d scroll_delta(11, -15); | 445 gfx::Vector2d scroll_delta(11, -15); |
425 { | 446 { |
| 447 scoped_ptr<LayerImpl> root_clip = |
| 448 LayerImpl::Create(host_impl_->active_tree(), 2); |
426 scoped_ptr<LayerImpl> root = | 449 scoped_ptr<LayerImpl> root = |
427 LayerImpl::Create(host_impl_->active_tree(), 1); | 450 LayerImpl::Create(host_impl_->active_tree(), 1); |
428 root->SetMaxScrollOffset(gfx::Vector2d(100, 100)); | 451 root_clip->SetBounds(gfx::Size(10, 10)); |
429 root->SetScrollOffset(scroll_offset); | 452 LayerImpl* root_layer = root.get(); |
430 root->SetScrollable(true); | 453 root_clip->AddChild(root.Pass()); |
431 root->ScrollBy(scroll_delta); | 454 root_layer->SetBounds(gfx::Size(110, 110)); |
432 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 455 root_layer->SetScrollClipLayer(root_clip->id()); |
| 456 root_layer->SetScrollOffset(scroll_offset); |
| 457 root_layer->ScrollBy(scroll_delta); |
| 458 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
433 } | 459 } |
434 LayerImpl* root = host_impl_->active_tree()->root_layer(); | 460 LayerImpl* root = host_impl_->active_tree()->root_layer()->children()[0]; |
435 | 461 |
436 scoped_ptr<ScrollAndScaleSet> scroll_info; | 462 scoped_ptr<ScrollAndScaleSet> scroll_info; |
437 | 463 |
438 scroll_info = host_impl_->ProcessScrollDeltas(); | 464 scroll_info = host_impl_->ProcessScrollDeltas(); |
439 ASSERT_EQ(scroll_info->scrolls.size(), 1u); | 465 ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
440 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scroll_delta); | 466 EXPECT_VECTOR_EQ(root->sent_scroll_delta(), scroll_delta); |
441 ExpectContains(*scroll_info, root->id(), scroll_delta); | 467 ExpectContains(*scroll_info, root->id(), scroll_delta); |
442 | 468 |
443 gfx::Vector2d scroll_delta2(-5, 27); | 469 gfx::Vector2d scroll_delta2(-5, 27); |
444 root->ScrollBy(scroll_delta2); | 470 root->ScrollBy(scroll_delta2); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 gfx::Point(), SCROLL_FORWARD)); | 741 gfx::Point(), SCROLL_FORWARD)); |
716 EXPECT_FALSE(host_impl_->ScrollVerticallyByPage( | 742 EXPECT_FALSE(host_impl_->ScrollVerticallyByPage( |
717 gfx::Point(), SCROLL_BACKWARD)); | 743 gfx::Point(), SCROLL_BACKWARD)); |
718 | 744 |
719 scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar( | 745 scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar( |
720 PaintedScrollbarLayerImpl::Create( | 746 PaintedScrollbarLayerImpl::Create( |
721 host_impl_->active_tree(), | 747 host_impl_->active_tree(), |
722 20, | 748 20, |
723 VERTICAL)); | 749 VERTICAL)); |
724 vertical_scrollbar->SetBounds(gfx::Size(15, 1000)); | 750 vertical_scrollbar->SetBounds(gfx::Size(15, 1000)); |
725 host_impl_->RootScrollLayer()->SetVerticalScrollbarLayer( | 751 host_impl_->InnerViewportScrollLayer()->AddScrollbar( |
726 vertical_scrollbar.get()); | 752 vertical_scrollbar.get()); |
727 | 753 |
728 // Trying to scroll with a vertical scrollbar will succeed. | 754 // Trying to scroll with a vertical scrollbar will succeed. |
729 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( | 755 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( |
730 gfx::Point(), SCROLL_FORWARD)); | 756 gfx::Point(), SCROLL_FORWARD)); |
731 EXPECT_FLOAT_EQ(875.f, host_impl_->RootScrollLayer()->ScrollDelta().y()); | 757 EXPECT_FLOAT_EQ(875.f, |
| 758 host_impl_->InnerViewportScrollLayer()->ScrollDelta().y()); |
732 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( | 759 EXPECT_TRUE(host_impl_->ScrollVerticallyByPage( |
733 gfx::Point(), SCROLL_BACKWARD)); | 760 gfx::Point(), SCROLL_BACKWARD)); |
734 } | 761 } |
735 | 762 |
736 // The user-scrollability breaks for zoomed-in pages. So disable this. | 763 // The user-scrollability breaks for zoomed-in pages. So disable this. |
737 // http://crbug.com/322223 | 764 // http://crbug.com/322223 |
738 TEST_F(LayerTreeHostImplTest, DISABLED_ScrollWithUserUnscrollableLayers) { | 765 TEST_F(LayerTreeHostImplTest, DISABLED_ScrollWithUserUnscrollableLayers) { |
739 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200)); | 766 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(200, 200)); |
740 host_impl_->SetViewportSize(gfx::Size(100, 100)); | 767 host_impl_->SetViewportSize(gfx::Size(100, 100)); |
741 | 768 |
742 gfx::Size overflow_size(400, 400); | 769 gfx::Size overflow_size(400, 400); |
743 ASSERT_EQ(1u, scroll_layer->children().size()); | 770 ASSERT_EQ(1u, scroll_layer->children().size()); |
744 LayerImpl* overflow = scroll_layer->children()[0]; | 771 LayerImpl* overflow = scroll_layer->children()[0]; |
745 overflow->SetBounds(overflow_size); | 772 overflow->SetBounds(overflow_size); |
746 overflow->SetContentBounds(overflow_size); | 773 overflow->SetContentBounds(overflow_size); |
747 overflow->SetScrollable(true); | 774 overflow->SetScrollClipLayer(scroll_layer->parent()->id()); |
748 overflow->SetMaxScrollOffset(gfx::Vector2d(overflow_size.width(), | |
749 overflow_size.height())); | |
750 overflow->SetScrollOffset(gfx::Vector2d()); | 775 overflow->SetScrollOffset(gfx::Vector2d()); |
751 overflow->SetPosition(gfx::PointF()); | 776 overflow->SetPosition(gfx::PointF()); |
752 overflow->SetAnchorPoint(gfx::PointF()); | 777 overflow->SetAnchorPoint(gfx::PointF()); |
753 | 778 |
754 DrawFrame(); | 779 DrawFrame(); |
755 gfx::Point scroll_position(10, 10); | 780 gfx::Point scroll_position(10, 10); |
756 | 781 |
757 EXPECT_EQ(InputHandler::ScrollStarted, | 782 EXPECT_EQ(InputHandler::ScrollStarted, |
758 host_impl_->ScrollBegin(scroll_position, InputHandler::Wheel)); | 783 host_impl_->ScrollBegin(scroll_position, InputHandler::Wheel)); |
759 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->TotalScrollOffset()); | 784 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->TotalScrollOffset()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 host_impl_->active_tree()->set_needs_update_draw_properties(); | 827 host_impl_->active_tree()->set_needs_update_draw_properties(); |
803 | 828 |
804 EXPECT_EQ(host_impl_->HaveTouchEventHandlersAt(gfx::Point()), false); | 829 EXPECT_EQ(host_impl_->HaveTouchEventHandlersAt(gfx::Point()), false); |
805 } | 830 } |
806 | 831 |
807 TEST_F(LayerTreeHostImplTest, ImplPinchZoom) { | 832 TEST_F(LayerTreeHostImplTest, ImplPinchZoom) { |
808 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 833 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
809 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 834 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
810 DrawFrame(); | 835 DrawFrame(); |
811 | 836 |
812 EXPECT_EQ(scroll_layer, host_impl_->RootScrollLayer()); | 837 EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer()); |
813 | 838 |
814 float min_page_scale = 1.f, max_page_scale = 4.f; | 839 float min_page_scale = 1.f, max_page_scale = 4.f; |
815 | 840 |
816 // The impl-based pinch zoom should adjust the max scroll position. | 841 // The impl-based pinch zoom should adjust the max scroll position. |
817 { | 842 { |
818 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 843 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
819 min_page_scale, | 844 min_page_scale, |
820 max_page_scale); | 845 max_page_scale); |
821 host_impl_->active_tree()->SetPageScaleDelta(1.f); | 846 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
822 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 847 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
823 | 848 |
824 float page_scale_delta = 2.f; | 849 float page_scale_delta = 2.f; |
825 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); | 850 host_impl_->ScrollBegin(gfx::Point(50, 50), InputHandler::Gesture); |
| 851 host_impl_->PinchGestureBegin(); |
826 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); | 852 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(50, 50)); |
827 host_impl_->PinchGestureEnd(); | 853 host_impl_->PinchGestureEnd(); |
828 host_impl_->ScrollEnd(); | 854 host_impl_->ScrollEnd(); |
829 EXPECT_TRUE(did_request_redraw_); | 855 EXPECT_TRUE(did_request_redraw_); |
830 EXPECT_TRUE(did_request_commit_); | 856 EXPECT_TRUE(did_request_commit_); |
831 | 857 |
832 scoped_ptr<ScrollAndScaleSet> scroll_info = | 858 scoped_ptr<ScrollAndScaleSet> scroll_info = |
833 host_impl_->ProcessScrollDeltas(); | 859 host_impl_->ProcessScrollDeltas(); |
834 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); | 860 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
835 | 861 |
836 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(), | 862 EXPECT_EQ(gfx::Vector2d(75, 75).ToString(), |
837 scroll_layer->max_scroll_offset().ToString()); | 863 scroll_layer->MaxScrollOffset().ToString()); |
838 } | 864 } |
839 | 865 |
840 // Scrolling after a pinch gesture should always be in local space. The | 866 // Scrolling after a pinch gesture should always be in local space. The |
841 // scroll deltas do not have the page scale factor applied. | 867 // scroll deltas do not have the page scale factor applied. |
842 { | 868 { |
843 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 869 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
844 min_page_scale, | 870 min_page_scale, |
845 max_page_scale); | 871 max_page_scale); |
846 host_impl_->active_tree()->SetPageScaleDelta(1.f); | 872 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
847 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 873 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
(...skipping 18 matching lines...) Expand all Loading... |
866 scroll_layer->id(), | 892 scroll_layer->id(), |
867 scroll_delta); | 893 scroll_delta); |
868 } | 894 } |
869 } | 895 } |
870 | 896 |
871 TEST_F(LayerTreeHostImplTest, PinchGesture) { | 897 TEST_F(LayerTreeHostImplTest, PinchGesture) { |
872 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 898 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
873 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 899 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
874 DrawFrame(); | 900 DrawFrame(); |
875 | 901 |
876 LayerImpl* scroll_layer = host_impl_->RootScrollLayer(); | 902 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
877 DCHECK(scroll_layer); | 903 DCHECK(scroll_layer); |
878 | 904 |
879 float min_page_scale = 1.f; | 905 float min_page_scale = 1.f; |
880 float max_page_scale = 4.f; | 906 float max_page_scale = 4.f; |
881 | 907 |
882 // Basic pinch zoom in gesture | 908 // Basic pinch zoom in gesture |
883 { | 909 { |
884 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, | 910 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, |
885 min_page_scale, | 911 min_page_scale, |
886 max_page_scale); | 912 max_page_scale); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); | 1012 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-10, -10)); |
987 } | 1013 } |
988 | 1014 |
989 // Two-finger panning should work when starting fully zoomed out. | 1015 // Two-finger panning should work when starting fully zoomed out. |
990 { | 1016 { |
991 host_impl_->active_tree()->SetPageScaleFactorAndLimits(0.5f, | 1017 host_impl_->active_tree()->SetPageScaleFactorAndLimits(0.5f, |
992 0.5f, | 1018 0.5f, |
993 4.f); | 1019 4.f); |
994 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 1020 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
995 scroll_layer->SetScrollOffset(gfx::Vector2d(0, 0)); | 1021 scroll_layer->SetScrollOffset(gfx::Vector2d(0, 0)); |
996 host_impl_->active_tree()->UpdateMaxScrollOffset(); | |
997 | 1022 |
998 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture); | 1023 host_impl_->ScrollBegin(gfx::Point(0, 0), InputHandler::Gesture); |
999 host_impl_->PinchGestureBegin(); | 1024 host_impl_->PinchGestureBegin(); |
1000 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); | 1025 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); |
1001 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); | 1026 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); |
1002 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10)); | 1027 host_impl_->ScrollBy(gfx::Point(0, 0), gfx::Vector2d(10, 10)); |
1003 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); | 1028 host_impl_->PinchGestureUpdate(1.f, gfx::Point(10, 10)); |
1004 host_impl_->PinchGestureEnd(); | 1029 host_impl_->PinchGestureEnd(); |
1005 host_impl_->ScrollEnd(); | 1030 host_impl_->ScrollEnd(); |
1006 | 1031 |
1007 scoped_ptr<ScrollAndScaleSet> scroll_info = | 1032 scoped_ptr<ScrollAndScaleSet> scroll_info = |
1008 host_impl_->ProcessScrollDeltas(); | 1033 host_impl_->ProcessScrollDeltas(); |
1009 EXPECT_EQ(scroll_info->page_scale_delta, 2.f); | 1034 EXPECT_EQ(scroll_info->page_scale_delta, 2.f); |
1010 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(20, 20)); | 1035 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(20, 20)); |
1011 } | 1036 } |
1012 } | 1037 } |
1013 | 1038 |
1014 TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { | 1039 TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { |
1015 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 1040 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
1016 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 1041 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
1017 DrawFrame(); | 1042 DrawFrame(); |
1018 | 1043 |
1019 LayerImpl* scroll_layer = host_impl_->RootScrollLayer(); | 1044 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
1020 DCHECK(scroll_layer); | 1045 DCHECK(scroll_layer); |
1021 | 1046 |
1022 float min_page_scale = 0.5f; | 1047 float min_page_scale = 0.5f; |
1023 float max_page_scale = 4.f; | 1048 float max_page_scale = 4.f; |
1024 base::TimeTicks start_time = base::TimeTicks() + | 1049 base::TimeTicks start_time = base::TimeTicks() + |
1025 base::TimeDelta::FromSeconds(1); | 1050 base::TimeDelta::FromSeconds(1); |
1026 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); | 1051 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
1027 base::TimeTicks halfway_through_animation = start_time + duration / 2; | 1052 base::TimeTicks halfway_through_animation = start_time + duration / 2; |
1028 base::TimeTicks end_time = start_time + duration; | 1053 base::TimeTicks end_time = start_time + duration; |
1029 | 1054 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 // Pushed to (0,0) via clamping against contents layer size. | 1104 // Pushed to (0,0) via clamping against contents layer size. |
1080 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); | 1105 ExpectContains(*scroll_info, scroll_layer->id(), gfx::Vector2d(-50, -50)); |
1081 } | 1106 } |
1082 } | 1107 } |
1083 | 1108 |
1084 TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) { | 1109 TEST_F(LayerTreeHostImplTest, PageScaleAnimationNoOp) { |
1085 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 1110 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
1086 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 1111 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
1087 DrawFrame(); | 1112 DrawFrame(); |
1088 | 1113 |
1089 LayerImpl* scroll_layer = host_impl_->RootScrollLayer(); | 1114 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
1090 DCHECK(scroll_layer); | 1115 DCHECK(scroll_layer); |
1091 | 1116 |
1092 float min_page_scale = 0.5f; | 1117 float min_page_scale = 0.5f; |
1093 float max_page_scale = 4.f; | 1118 float max_page_scale = 4.f; |
1094 base::TimeTicks start_time = base::TimeTicks() + | 1119 base::TimeTicks start_time = base::TimeTicks() + |
1095 base::TimeDelta::FromSeconds(1); | 1120 base::TimeDelta::FromSeconds(1); |
1096 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); | 1121 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100); |
1097 base::TimeTicks halfway_through_animation = start_time + duration / 2; | 1122 base::TimeTicks halfway_through_animation = start_time + duration / 2; |
1098 base::TimeTicks end_time = start_time + duration; | 1123 base::TimeTicks end_time = start_time + duration; |
1099 | 1124 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 host_impl_ = make_scoped_ptr(host_impl_override_time); | 1184 host_impl_ = make_scoped_ptr(host_impl_override_time); |
1160 host_impl_->InitializeRenderer(CreateOutputSurface()); | 1185 host_impl_->InitializeRenderer(CreateOutputSurface()); |
1161 host_impl_->SetViewportSize(viewport_size); | 1186 host_impl_->SetViewportSize(viewport_size); |
1162 | 1187 |
1163 scoped_ptr<LayerImpl> root = | 1188 scoped_ptr<LayerImpl> root = |
1164 LayerImpl::Create(host_impl_->active_tree(), 1); | 1189 LayerImpl::Create(host_impl_->active_tree(), 1); |
1165 root->SetBounds(viewport_size); | 1190 root->SetBounds(viewport_size); |
1166 | 1191 |
1167 scoped_ptr<LayerImpl> scroll = | 1192 scoped_ptr<LayerImpl> scroll = |
1168 LayerImpl::Create(host_impl_->active_tree(), 2); | 1193 LayerImpl::Create(host_impl_->active_tree(), 2); |
1169 scroll->SetScrollable(true); | 1194 scroll->SetScrollClipLayer(root->id()); |
1170 scroll->SetScrollOffset(gfx::Vector2d()); | 1195 scroll->SetScrollOffset(gfx::Vector2d()); |
1171 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | 1196 root->SetBounds(viewport_size); |
1172 content_size.height())); | |
1173 scroll->SetBounds(content_size); | 1197 scroll->SetBounds(content_size); |
1174 scroll->SetContentBounds(content_size); | 1198 scroll->SetContentBounds(content_size); |
| 1199 scroll->SetIsContainerForFixedPositionLayers(true); |
1175 | 1200 |
1176 scoped_ptr<LayerImpl> contents = | 1201 scoped_ptr<LayerImpl> contents = |
1177 LayerImpl::Create(host_impl_->active_tree(), 3); | 1202 LayerImpl::Create(host_impl_->active_tree(), 3); |
1178 contents->SetDrawsContent(true); | 1203 contents->SetDrawsContent(true); |
1179 contents->SetBounds(content_size); | 1204 contents->SetBounds(content_size); |
1180 contents->SetContentBounds(content_size); | 1205 contents->SetContentBounds(content_size); |
1181 | 1206 |
1182 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = | 1207 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = |
1183 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 4, VERTICAL); | 1208 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 4, VERTICAL); |
1184 scroll->SetVerticalScrollbarLayer(scrollbar.get()); | 1209 scrollbar->SetScrollLayerById(2); |
| 1210 scrollbar->SetClipLayerById(1); |
1185 | 1211 |
1186 scroll->AddChild(contents.Pass()); | 1212 scroll->AddChild(contents.Pass()); |
1187 root->AddChild(scroll.Pass()); | 1213 root->AddChild(scroll.Pass()); |
1188 root->AddChild(scrollbar.PassAs<LayerImpl>()); | 1214 root->AddChild(scrollbar.PassAs<LayerImpl>()); |
1189 | 1215 |
1190 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1216 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 1217 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
1191 host_impl_->active_tree()->DidBecomeActive(); | 1218 host_impl_->active_tree()->DidBecomeActive(); |
1192 DrawFrame(); | 1219 DrawFrame(); |
1193 | 1220 |
1194 base::TimeTicks fake_now = gfx::FrameTime::Now(); | 1221 base::TimeTicks fake_now = gfx::FrameTime::Now(); |
1195 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); | 1222 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
1196 | 1223 |
1197 // If no scroll happened recently, StartScrollbarAnimation should have no | 1224 // If no scroll happened recently, StartScrollbarAnimation should have no |
1198 // effect. | 1225 // effect. |
1199 host_impl_->StartScrollbarAnimation(); | 1226 host_impl_->StartScrollbarAnimation(); |
1200 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); | 1227 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); |
(...skipping 30 matching lines...) Expand all Loading... |
1231 // If no scroll happened recently, StartScrollbarAnimation should have no | 1258 // If no scroll happened recently, StartScrollbarAnimation should have no |
1232 // effect. | 1259 // effect. |
1233 fake_now += base::TimeDelta::FromMilliseconds(25); | 1260 fake_now += base::TimeDelta::FromMilliseconds(25); |
1234 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); | 1261 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
1235 host_impl_->StartScrollbarAnimation(); | 1262 host_impl_->StartScrollbarAnimation(); |
1236 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); | 1263 EXPECT_EQ(base::TimeDelta(), requested_scrollbar_animation_delay_); |
1237 EXPECT_FALSE(did_request_redraw_); | 1264 EXPECT_FALSE(did_request_redraw_); |
1238 | 1265 |
1239 // Setting the scroll offset outside a scroll should also cause the scrollbar | 1266 // Setting the scroll offset outside a scroll should also cause the scrollbar |
1240 // to appear and to schedule a fade. | 1267 // to appear and to schedule a fade. |
1241 host_impl_->RootScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); | 1268 host_impl_->InnerViewportScrollLayer()->SetScrollOffset(gfx::Vector2d(5, 5)); |
1242 host_impl_->StartScrollbarAnimation(); | 1269 host_impl_->StartScrollbarAnimation(); |
1243 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), | 1270 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), |
1244 requested_scrollbar_animation_delay_); | 1271 requested_scrollbar_animation_delay_); |
1245 EXPECT_FALSE(did_request_redraw_); | 1272 EXPECT_FALSE(did_request_redraw_); |
1246 requested_scrollbar_animation_delay_ = base::TimeDelta(); | 1273 requested_scrollbar_animation_delay_ = base::TimeDelta(); |
1247 | 1274 |
1248 // None of the above should have called CurrentFrameTimeTicks, so if we call | 1275 // None of the above should have called CurrentFrameTimeTicks, so if we call |
1249 // it now we should get the current time. | 1276 // it now we should get the current time. |
1250 fake_now += base::TimeDelta::FromMilliseconds(10); | 1277 fake_now += base::TimeDelta::FromMilliseconds(10); |
1251 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); | 1278 host_impl_override_time->SetCurrentPhysicalTimeTicksForTest(fake_now); |
(...skipping 13 matching lines...) Expand all Loading... |
1265 CreateHostImpl(settings, CreateOutputSurface()); | 1292 CreateHostImpl(settings, CreateOutputSurface()); |
1266 host_impl_->SetDeviceScaleFactor(device_scale_factor); | 1293 host_impl_->SetDeviceScaleFactor(device_scale_factor); |
1267 host_impl_->SetViewportSize(device_viewport_size); | 1294 host_impl_->SetViewportSize(device_viewport_size); |
1268 | 1295 |
1269 scoped_ptr<LayerImpl> root = | 1296 scoped_ptr<LayerImpl> root = |
1270 LayerImpl::Create(host_impl_->active_tree(), 1); | 1297 LayerImpl::Create(host_impl_->active_tree(), 1); |
1271 root->SetBounds(viewport_size); | 1298 root->SetBounds(viewport_size); |
1272 | 1299 |
1273 scoped_ptr<LayerImpl> scroll = | 1300 scoped_ptr<LayerImpl> scroll = |
1274 LayerImpl::Create(host_impl_->active_tree(), 2); | 1301 LayerImpl::Create(host_impl_->active_tree(), 2); |
1275 scroll->SetScrollable(true); | 1302 scroll->SetScrollClipLayer(root->id()); |
1276 scroll->SetScrollOffset(gfx::Vector2d()); | 1303 scroll->SetScrollOffset(gfx::Vector2d()); |
1277 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | |
1278 content_size.height())); | |
1279 scroll->SetBounds(content_size); | 1304 scroll->SetBounds(content_size); |
1280 scroll->SetContentBounds(content_size); | 1305 scroll->SetContentBounds(content_size); |
| 1306 scroll->SetIsContainerForFixedPositionLayers(true); |
1281 | 1307 |
1282 scoped_ptr<LayerImpl> contents = | 1308 scoped_ptr<LayerImpl> contents = |
1283 LayerImpl::Create(host_impl_->active_tree(), 3); | 1309 LayerImpl::Create(host_impl_->active_tree(), 3); |
1284 contents->SetDrawsContent(true); | 1310 contents->SetDrawsContent(true); |
1285 contents->SetBounds(content_size); | 1311 contents->SetBounds(content_size); |
1286 contents->SetContentBounds(content_size); | 1312 contents->SetContentBounds(content_size); |
1287 | 1313 |
1288 // The scrollbar is on the right side. | 1314 // The scrollbar is on the right side. |
1289 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = | 1315 scoped_ptr<PaintedScrollbarLayerImpl> scrollbar = |
1290 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 5, VERTICAL); | 1316 PaintedScrollbarLayerImpl::Create(host_impl_->active_tree(), 5, VERTICAL); |
1291 scrollbar->SetDrawsContent(true); | 1317 scrollbar->SetDrawsContent(true); |
1292 scrollbar->SetBounds(gfx::Size(15, viewport_size.height())); | 1318 scrollbar->SetBounds(gfx::Size(15, viewport_size.height())); |
1293 scrollbar->SetContentBounds(gfx::Size(15, viewport_size.height())); | 1319 scrollbar->SetContentBounds(gfx::Size(15, viewport_size.height())); |
1294 scrollbar->SetPosition(gfx::Point(285, 0)); | 1320 scrollbar->SetPosition(gfx::Point(285, 0)); |
1295 scroll->SetVerticalScrollbarLayer(scrollbar.get()); | 1321 scrollbar->SetScrollLayerById(2); |
1296 | 1322 |
1297 scroll->AddChild(contents.Pass()); | 1323 scroll->AddChild(contents.Pass()); |
1298 root->AddChild(scroll.Pass()); | 1324 root->AddChild(scroll.Pass()); |
1299 root->AddChild(scrollbar.PassAs<LayerImpl>()); | 1325 root->AddChild(scrollbar.PassAs<LayerImpl>()); |
1300 | 1326 |
1301 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1327 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 1328 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
1302 host_impl_->active_tree()->DidBecomeActive(); | 1329 host_impl_->active_tree()->DidBecomeActive(); |
1303 DrawFrame(); | 1330 DrawFrame(); |
1304 | 1331 |
1305 LayerImpl* root_scroll = host_impl_->active_tree()->RootScrollLayer(); | 1332 LayerImpl* root_scroll = |
| 1333 host_impl_->active_tree()->InnerViewportScrollLayer(); |
1306 ASSERT_TRUE(root_scroll->scrollbar_animation_controller()); | 1334 ASSERT_TRUE(root_scroll->scrollbar_animation_controller()); |
1307 ScrollbarAnimationControllerThinning* scrollbar_animation_controller = | 1335 ScrollbarAnimationControllerThinning* scrollbar_animation_controller = |
1308 static_cast<ScrollbarAnimationControllerThinning*>( | 1336 static_cast<ScrollbarAnimationControllerThinning*>( |
1309 root_scroll->scrollbar_animation_controller()); | 1337 root_scroll->scrollbar_animation_controller()); |
1310 scrollbar_animation_controller->set_mouse_move_distance_for_test(100.f); | 1338 scrollbar_animation_controller->set_mouse_move_distance_for_test(100.f); |
1311 | 1339 |
1312 host_impl_->MouseMoveAt(gfx::Point(1, 1)); | 1340 host_impl_->MouseMoveAt(gfx::Point(1, 1)); |
1313 EXPECT_FALSE(scrollbar_animation_controller->mouse_is_near_scrollbar()); | 1341 EXPECT_FALSE(scrollbar_animation_controller->mouse_is_near_scrollbar()); |
1314 | 1342 |
1315 host_impl_->MouseMoveAt(gfx::Point(200, 50)); | 1343 host_impl_->MouseMoveAt(gfx::Point(200, 50)); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1752 true, | 1780 true, |
1753 host_impl_->resource_provider())); | 1781 host_impl_->resource_provider())); |
1754 | 1782 |
1755 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 1783 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
1756 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 1784 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
1757 host_impl_->DidDrawAllLayers(frame); | 1785 host_impl_->DidDrawAllLayers(frame); |
1758 } | 1786 } |
1759 | 1787 |
1760 TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) { | 1788 TEST_F(LayerTreeHostImplTest, ScrollRootIgnored) { |
1761 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1789 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1762 root->SetScrollable(false); | 1790 root->SetScrollClipLayer(Layer::INVALID_ID); |
1763 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1791 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1764 DrawFrame(); | 1792 DrawFrame(); |
1765 | 1793 |
1766 // Scroll event is ignored because layer is not scrollable. | 1794 // Scroll event is ignored because layer is not scrollable. |
1767 EXPECT_EQ(InputHandler::ScrollIgnored, | 1795 EXPECT_EQ(InputHandler::ScrollIgnored, |
1768 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 1796 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
1769 EXPECT_FALSE(did_request_redraw_); | 1797 EXPECT_FALSE(did_request_redraw_); |
1770 EXPECT_FALSE(did_request_commit_); | 1798 EXPECT_FALSE(did_request_commit_); |
1771 } | 1799 } |
1772 | 1800 |
1773 TEST_F(LayerTreeHostImplTest, ScrollNonScrollableRootWithTopControls) { | 1801 TEST_F(LayerTreeHostImplTest, ScrollNonScrollableRootWithTopControls) { |
1774 LayerTreeSettings settings; | 1802 LayerTreeSettings settings; |
1775 settings.calculate_top_controls_position = true; | 1803 settings.calculate_top_controls_position = true; |
1776 settings.top_controls_height = 50; | 1804 settings.top_controls_height = 50; |
1777 | 1805 |
1778 CreateHostImpl(settings, CreateOutputSurface()); | 1806 CreateHostImpl(settings, CreateOutputSurface()); |
1779 | 1807 |
1780 gfx::Size layer_size(5, 5); | 1808 gfx::Size layer_size(10, 10); |
| 1809 gfx::Size clip_size(5, 5); |
1781 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1810 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1782 root->SetScrollable(true); | 1811 scoped_ptr<LayerImpl> root_clip = |
1783 root->SetMaxScrollOffset(gfx::Vector2d(layer_size.width(), | 1812 LayerImpl::Create(host_impl_->active_tree(), 2); |
1784 layer_size.height())); | 1813 root_clip->SetBounds(clip_size); |
| 1814 root->SetScrollClipLayer(root_clip->id()); |
1785 root->SetBounds(layer_size); | 1815 root->SetBounds(layer_size); |
1786 root->SetContentBounds(layer_size); | 1816 root->SetContentBounds(layer_size); |
1787 root->SetPosition(gfx::PointF()); | 1817 root->SetPosition(gfx::PointF()); |
1788 root->SetAnchorPoint(gfx::PointF()); | 1818 root->SetAnchorPoint(gfx::PointF()); |
1789 root->SetDrawsContent(false); | 1819 root->SetDrawsContent(false); |
1790 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1820 int root_id = root->id(); |
1791 host_impl_->active_tree()->FindRootScrollLayer(); | 1821 root_clip->AddChild(root.Pass()); |
| 1822 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 1823 host_impl_->active_tree()->SetViewportLayersFromIds( |
| 1824 root_id, root_id, Layer::INVALID_ID); |
1792 DrawFrame(); | 1825 DrawFrame(); |
1793 | 1826 |
1794 EXPECT_EQ(InputHandler::ScrollStarted, | 1827 EXPECT_EQ(InputHandler::ScrollStarted, |
1795 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); | 1828 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); |
1796 | 1829 |
1797 host_impl_->top_controls_manager()->ScrollBegin(); | 1830 host_impl_->top_controls_manager()->ScrollBegin(); |
1798 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); | 1831 host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); |
1799 host_impl_->top_controls_manager()->ScrollEnd(); | 1832 host_impl_->top_controls_manager()->ScrollEnd(); |
1800 EXPECT_EQ(host_impl_->top_controls_manager()->content_top_offset(), 0.f); | 1833 EXPECT_EQ(host_impl_->top_controls_manager()->content_top_offset(), 0.f); |
1801 | 1834 |
1802 host_impl_->ScrollEnd(); | 1835 host_impl_->ScrollEnd(); |
1803 | 1836 |
1804 EXPECT_EQ(InputHandler::ScrollStarted, | 1837 EXPECT_EQ(InputHandler::ScrollStarted, |
1805 host_impl_->ScrollBegin(gfx::Point(), | 1838 host_impl_->ScrollBegin(gfx::Point(), |
1806 InputHandler::Gesture)); | 1839 InputHandler::Gesture)); |
1807 } | 1840 } |
1808 | 1841 |
1809 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { | 1842 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { |
1810 // Test the configuration where a non-composited root layer is embedded in a | 1843 // Test the configuration where a non-composited root layer is embedded in a |
1811 // scrollable outer layer. | 1844 // scrollable outer layer. |
1812 gfx::Size surface_size(10, 10); | 1845 gfx::Size surface_size(10, 10); |
| 1846 gfx::Size contents_size(20, 20); |
1813 | 1847 |
1814 scoped_ptr<LayerImpl> content_layer = | 1848 scoped_ptr<LayerImpl> content_layer = |
1815 LayerImpl::Create(host_impl_->active_tree(), 1); | 1849 LayerImpl::Create(host_impl_->active_tree(), 1); |
1816 content_layer->SetDrawsContent(true); | 1850 content_layer->SetDrawsContent(true); |
1817 content_layer->SetPosition(gfx::PointF()); | 1851 content_layer->SetPosition(gfx::PointF()); |
1818 content_layer->SetAnchorPoint(gfx::PointF()); | 1852 content_layer->SetAnchorPoint(gfx::PointF()); |
1819 content_layer->SetBounds(surface_size); | 1853 content_layer->SetBounds(contents_size); |
1820 content_layer->SetContentBounds(gfx::Size(surface_size.width() * 2, | 1854 content_layer->SetContentBounds(contents_size); |
1821 surface_size.height() * 2)); | |
1822 content_layer->SetContentsScale(2.f, 2.f); | 1855 content_layer->SetContentsScale(2.f, 2.f); |
1823 | 1856 |
| 1857 scoped_ptr<LayerImpl> scroll_clip_layer = |
| 1858 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 1859 scroll_clip_layer->SetBounds(surface_size); |
| 1860 |
1824 scoped_ptr<LayerImpl> scroll_layer = | 1861 scoped_ptr<LayerImpl> scroll_layer = |
1825 LayerImpl::Create(host_impl_->active_tree(), 2); | 1862 LayerImpl::Create(host_impl_->active_tree(), 2); |
1826 scroll_layer->SetScrollable(true); | 1863 scroll_layer->SetScrollClipLayer(3); |
1827 scroll_layer->SetMaxScrollOffset(gfx::Vector2d(surface_size.width(), | 1864 scroll_layer->SetBounds(contents_size); |
1828 surface_size.height())); | 1865 scroll_layer->SetContentBounds(contents_size); |
1829 scroll_layer->SetBounds(surface_size); | |
1830 scroll_layer->SetContentBounds(surface_size); | |
1831 scroll_layer->SetPosition(gfx::PointF()); | 1866 scroll_layer->SetPosition(gfx::PointF()); |
1832 scroll_layer->SetAnchorPoint(gfx::PointF()); | 1867 scroll_layer->SetAnchorPoint(gfx::PointF()); |
1833 scroll_layer->AddChild(content_layer.Pass()); | 1868 scroll_layer->AddChild(content_layer.Pass()); |
| 1869 scroll_clip_layer->AddChild(scroll_layer.Pass()); |
1834 | 1870 |
1835 host_impl_->active_tree()->SetRootLayer(scroll_layer.Pass()); | 1871 host_impl_->active_tree()->SetRootLayer(scroll_clip_layer.Pass()); |
1836 host_impl_->SetViewportSize(surface_size); | 1872 host_impl_->SetViewportSize(surface_size); |
1837 DrawFrame(); | 1873 DrawFrame(); |
1838 | 1874 |
1839 EXPECT_EQ(InputHandler::ScrollStarted, | 1875 EXPECT_EQ(InputHandler::ScrollStarted, |
1840 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1876 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1841 InputHandler::Wheel)); | 1877 InputHandler::Wheel)); |
1842 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 1878 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
1843 host_impl_->ScrollEnd(); | 1879 host_impl_->ScrollEnd(); |
1844 EXPECT_TRUE(did_request_redraw_); | 1880 EXPECT_TRUE(did_request_redraw_); |
1845 EXPECT_TRUE(did_request_commit_); | 1881 EXPECT_TRUE(did_request_commit_); |
1846 } | 1882 } |
1847 | 1883 |
1848 TEST_F(LayerTreeHostImplTest, ScrollChildCallsCommitAndRedraw) { | 1884 TEST_F(LayerTreeHostImplTest, ScrollChildCallsCommitAndRedraw) { |
1849 gfx::Size surface_size(10, 10); | 1885 gfx::Size surface_size(10, 10); |
| 1886 gfx::Size contents_size(20, 20); |
1850 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1887 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1851 root->SetBounds(surface_size); | 1888 root->SetBounds(surface_size); |
1852 root->SetContentBounds(surface_size); | 1889 root->SetContentBounds(contents_size); |
1853 root->AddChild(CreateScrollableLayer(2, surface_size)); | 1890 root->AddChild(CreateScrollableLayer(2, contents_size, root.get())); |
1854 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1891 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1855 host_impl_->SetViewportSize(surface_size); | 1892 host_impl_->SetViewportSize(surface_size); |
1856 DrawFrame(); | 1893 DrawFrame(); |
1857 | 1894 |
1858 EXPECT_EQ(InputHandler::ScrollStarted, | 1895 EXPECT_EQ(InputHandler::ScrollStarted, |
1859 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1896 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1860 InputHandler::Wheel)); | 1897 InputHandler::Wheel)); |
1861 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 1898 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
1862 host_impl_->ScrollEnd(); | 1899 host_impl_->ScrollEnd(); |
1863 EXPECT_TRUE(did_request_redraw_); | 1900 EXPECT_TRUE(did_request_redraw_); |
1864 EXPECT_TRUE(did_request_commit_); | 1901 EXPECT_TRUE(did_request_commit_); |
1865 } | 1902 } |
1866 | 1903 |
1867 TEST_F(LayerTreeHostImplTest, ScrollMissesChild) { | 1904 TEST_F(LayerTreeHostImplTest, ScrollMissesChild) { |
1868 gfx::Size surface_size(10, 10); | 1905 gfx::Size surface_size(10, 10); |
1869 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1906 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1870 root->AddChild(CreateScrollableLayer(2, surface_size)); | 1907 root->AddChild(CreateScrollableLayer(2, surface_size, root.get())); |
1871 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1908 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1872 host_impl_->SetViewportSize(surface_size); | 1909 host_impl_->SetViewportSize(surface_size); |
1873 DrawFrame(); | 1910 DrawFrame(); |
1874 | 1911 |
1875 // Scroll event is ignored because the input coordinate is outside the layer | 1912 // Scroll event is ignored because the input coordinate is outside the layer |
1876 // boundaries. | 1913 // boundaries. |
1877 EXPECT_EQ(InputHandler::ScrollIgnored, | 1914 EXPECT_EQ(InputHandler::ScrollIgnored, |
1878 host_impl_->ScrollBegin(gfx::Point(15, 5), | 1915 host_impl_->ScrollBegin(gfx::Point(15, 5), |
1879 InputHandler::Wheel)); | 1916 InputHandler::Wheel)); |
1880 EXPECT_FALSE(did_request_redraw_); | 1917 EXPECT_FALSE(did_request_redraw_); |
1881 EXPECT_FALSE(did_request_commit_); | 1918 EXPECT_FALSE(did_request_commit_); |
1882 } | 1919 } |
1883 | 1920 |
1884 TEST_F(LayerTreeHostImplTest, ScrollMissesBackfacingChild) { | 1921 TEST_F(LayerTreeHostImplTest, ScrollMissesBackfacingChild) { |
1885 gfx::Size surface_size(10, 10); | 1922 gfx::Size surface_size(10, 10); |
1886 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1923 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1887 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, surface_size); | 1924 scoped_ptr<LayerImpl> child = |
| 1925 CreateScrollableLayer(2, surface_size, root.get()); |
1888 host_impl_->SetViewportSize(surface_size); | 1926 host_impl_->SetViewportSize(surface_size); |
1889 | 1927 |
1890 gfx::Transform matrix; | 1928 gfx::Transform matrix; |
1891 matrix.RotateAboutXAxis(180.0); | 1929 matrix.RotateAboutXAxis(180.0); |
1892 child->SetTransform(matrix); | 1930 child->SetTransform(matrix); |
1893 child->SetDoubleSided(false); | 1931 child->SetDoubleSided(false); |
1894 | 1932 |
1895 root->AddChild(child.Pass()); | 1933 root->AddChild(child.Pass()); |
1896 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1934 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1897 DrawFrame(); | 1935 DrawFrame(); |
1898 | 1936 |
1899 // Scroll event is ignored because the scrollable layer is not facing the | 1937 // Scroll event is ignored because the scrollable layer is not facing the |
1900 // viewer and there is nothing scrollable behind it. | 1938 // viewer and there is nothing scrollable behind it. |
1901 EXPECT_EQ(InputHandler::ScrollIgnored, | 1939 EXPECT_EQ(InputHandler::ScrollIgnored, |
1902 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1940 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1903 InputHandler::Wheel)); | 1941 InputHandler::Wheel)); |
1904 EXPECT_FALSE(did_request_redraw_); | 1942 EXPECT_FALSE(did_request_redraw_); |
1905 EXPECT_FALSE(did_request_commit_); | 1943 EXPECT_FALSE(did_request_commit_); |
1906 } | 1944 } |
1907 | 1945 |
1908 TEST_F(LayerTreeHostImplTest, ScrollBlockedByContentLayer) { | 1946 TEST_F(LayerTreeHostImplTest, ScrollBlockedByContentLayer) { |
1909 gfx::Size surface_size(10, 10); | 1947 gfx::Size surface_size(10, 10); |
1910 scoped_ptr<LayerImpl> content_layer = CreateScrollableLayer(1, surface_size); | 1948 scoped_ptr<LayerImpl> clip_layer = |
| 1949 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 1950 scoped_ptr<LayerImpl> content_layer = |
| 1951 CreateScrollableLayer(1, surface_size, clip_layer.get()); |
1911 content_layer->SetShouldScrollOnMainThread(true); | 1952 content_layer->SetShouldScrollOnMainThread(true); |
1912 content_layer->SetScrollable(false); | 1953 content_layer->SetScrollClipLayer(Layer::INVALID_ID); |
1913 | 1954 |
1914 scoped_ptr<LayerImpl> scroll_layer = CreateScrollableLayer(2, surface_size); | 1955 // Note: we can use the same clip layer for both since both calls to |
| 1956 // CreateScrollableLayer() use the same surface size. |
| 1957 scoped_ptr<LayerImpl> scroll_layer = |
| 1958 CreateScrollableLayer(2, surface_size, clip_layer.get()); |
1915 scroll_layer->AddChild(content_layer.Pass()); | 1959 scroll_layer->AddChild(content_layer.Pass()); |
| 1960 clip_layer->AddChild(scroll_layer.Pass()); |
1916 | 1961 |
1917 host_impl_->active_tree()->SetRootLayer(scroll_layer.Pass()); | 1962 host_impl_->active_tree()->SetRootLayer(clip_layer.Pass()); |
1918 host_impl_->SetViewportSize(surface_size); | 1963 host_impl_->SetViewportSize(surface_size); |
1919 DrawFrame(); | 1964 DrawFrame(); |
1920 | 1965 |
1921 // Scrolling fails because the content layer is asking to be scrolled on the | 1966 // Scrolling fails because the content layer is asking to be scrolled on the |
1922 // main thread. | 1967 // main thread. |
1923 EXPECT_EQ(InputHandler::ScrollOnMainThread, | 1968 EXPECT_EQ(InputHandler::ScrollOnMainThread, |
1924 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1969 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1925 InputHandler::Wheel)); | 1970 InputHandler::Wheel)); |
1926 } | 1971 } |
1927 | 1972 |
1928 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnMainThread) { | 1973 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnMainThread) { |
1929 gfx::Size surface_size(10, 10); | 1974 gfx::Size surface_size(20, 20); |
1930 float page_scale = 2.f; | 1975 float page_scale = 2.f; |
1931 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 1976 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1932 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 1977 scoped_ptr<LayerImpl> root_clip = |
1933 root->AddChild(root_scrolling.Pass()); | 1978 LayerImpl::Create(host_impl_->active_tree(), 2); |
| 1979 scoped_ptr<LayerImpl> root_scrolling = |
| 1980 CreateScrollableLayer(3, surface_size, root_clip.get()); |
| 1981 root_scrolling->SetIsContainerForFixedPositionLayers(true); |
| 1982 root_clip->AddChild(root_scrolling.Pass()); |
| 1983 root->AddChild(root_clip.Pass()); |
1934 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 1984 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 1985 // The behaviour in this test assumes the page scale is applied at a layer |
| 1986 // above the clip layer. |
| 1987 host_impl_->active_tree()->SetViewportLayersFromIds(1, 3, Layer::INVALID_ID); |
1935 host_impl_->active_tree()->DidBecomeActive(); | 1988 host_impl_->active_tree()->DidBecomeActive(); |
1936 host_impl_->SetViewportSize(surface_size); | 1989 host_impl_->SetViewportSize(surface_size); |
1937 DrawFrame(); | 1990 DrawFrame(); |
1938 | 1991 |
1939 LayerImpl* root_scroll = host_impl_->active_tree()->RootScrollLayer(); | 1992 LayerImpl* root_scroll = |
| 1993 host_impl_->active_tree()->InnerViewportScrollLayer(); |
1940 | 1994 |
1941 gfx::Vector2d scroll_delta(0, 10); | 1995 gfx::Vector2d scroll_delta(0, 10); |
1942 gfx::Vector2d expected_scroll_delta = scroll_delta; | 1996 gfx::Vector2d expected_scroll_delta = scroll_delta; |
1943 gfx::Vector2d expected_max_scroll = root_scroll->max_scroll_offset(); | 1997 gfx::Vector2d expected_max_scroll = root_scroll->MaxScrollOffset(); |
1944 EXPECT_EQ(InputHandler::ScrollStarted, | 1998 EXPECT_EQ(InputHandler::ScrollStarted, |
1945 host_impl_->ScrollBegin(gfx::Point(5, 5), | 1999 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1946 InputHandler::Wheel)); | 2000 InputHandler::Wheel)); |
1947 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2001 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
1948 host_impl_->ScrollEnd(); | 2002 host_impl_->ScrollEnd(); |
1949 | 2003 |
1950 // Set new page scale from main thread. | 2004 // Set new page scale from main thread. |
1951 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, | 2005 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, |
1952 page_scale, | 2006 page_scale, |
1953 page_scale); | 2007 page_scale); |
1954 | 2008 |
1955 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 2009 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
1956 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); | 2010 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); |
1957 | 2011 |
1958 // The scroll range should also have been updated. | 2012 // The scroll range should also have been updated. |
1959 EXPECT_EQ(expected_max_scroll, root_scroll->max_scroll_offset()); | 2013 EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); |
1960 | 2014 |
1961 // The page scale delta remains constant because the impl thread did not | 2015 // The page scale delta remains constant because the impl thread did not |
1962 // scale. | 2016 // scale. |
1963 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); | 2017 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
1964 } | 2018 } |
1965 | 2019 |
1966 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnImplThread) { | 2020 TEST_F(LayerTreeHostImplTest, ScrollRootAndChangePageScaleOnImplThread) { |
1967 gfx::Size surface_size(10, 10); | 2021 gfx::Size surface_size(20, 20); |
1968 float page_scale = 2.f; | 2022 float page_scale = 2.f; |
1969 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 2023 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
1970 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 2024 scoped_ptr<LayerImpl> root_clip = |
1971 root->AddChild(root_scrolling.Pass()); | 2025 LayerImpl::Create(host_impl_->active_tree(), 2); |
| 2026 scoped_ptr<LayerImpl> root_scrolling = |
| 2027 CreateScrollableLayer(3, surface_size, root_clip.get()); |
| 2028 root_scrolling->SetIsContainerForFixedPositionLayers(true); |
| 2029 root_clip->AddChild(root_scrolling.Pass()); |
| 2030 root->AddChild(root_clip.Pass()); |
1972 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2031 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 2032 // The behaviour in this test assumes the page scale is applied at a layer |
| 2033 // above the clip layer. |
| 2034 host_impl_->active_tree()->SetViewportLayersFromIds(1, 3, Layer::INVALID_ID); |
1973 host_impl_->active_tree()->DidBecomeActive(); | 2035 host_impl_->active_tree()->DidBecomeActive(); |
1974 host_impl_->SetViewportSize(surface_size); | 2036 host_impl_->SetViewportSize(surface_size); |
1975 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, page_scale); | 2037 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 1.f, page_scale); |
1976 DrawFrame(); | 2038 DrawFrame(); |
1977 | 2039 |
1978 LayerImpl* root_scroll = host_impl_->active_tree()->RootScrollLayer(); | 2040 LayerImpl* root_scroll = |
| 2041 host_impl_->active_tree()->InnerViewportScrollLayer(); |
1979 | 2042 |
1980 gfx::Vector2d scroll_delta(0, 10); | 2043 gfx::Vector2d scroll_delta(0, 10); |
1981 gfx::Vector2d expected_scroll_delta = scroll_delta; | 2044 gfx::Vector2d expected_scroll_delta = scroll_delta; |
1982 gfx::Vector2d expected_max_scroll = root_scroll->max_scroll_offset(); | 2045 gfx::Vector2d expected_max_scroll = root_scroll->MaxScrollOffset(); |
1983 EXPECT_EQ(InputHandler::ScrollStarted, | 2046 EXPECT_EQ(InputHandler::ScrollStarted, |
1984 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2047 host_impl_->ScrollBegin(gfx::Point(5, 5), |
1985 InputHandler::Wheel)); | 2048 InputHandler::Wheel)); |
1986 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2049 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
1987 host_impl_->ScrollEnd(); | 2050 host_impl_->ScrollEnd(); |
1988 | 2051 |
1989 // Set new page scale on impl thread by pinching. | 2052 // Set new page scale on impl thread by pinching. |
1990 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); | 2053 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); |
1991 host_impl_->PinchGestureBegin(); | 2054 host_impl_->PinchGestureBegin(); |
1992 host_impl_->PinchGestureUpdate(page_scale, gfx::Point()); | 2055 host_impl_->PinchGestureUpdate(page_scale, gfx::Point()); |
1993 host_impl_->PinchGestureEnd(); | 2056 host_impl_->PinchGestureEnd(); |
1994 host_impl_->ScrollEnd(); | 2057 host_impl_->ScrollEnd(); |
1995 DrawOneFrame(); | 2058 DrawOneFrame(); |
1996 | 2059 |
1997 // The scroll delta is not scaled because the main thread did not scale. | 2060 // The scroll delta is not scaled because the main thread did not scale. |
1998 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 2061 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
1999 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); | 2062 ExpectContains(*scroll_info.get(), root_scroll->id(), expected_scroll_delta); |
2000 | 2063 |
2001 // The scroll range should also have been updated. | 2064 // The scroll range should also have been updated. |
2002 EXPECT_EQ(expected_max_scroll, root_scroll->max_scroll_offset()); | 2065 EXPECT_EQ(expected_max_scroll, root_scroll->MaxScrollOffset()); |
2003 | 2066 |
2004 // The page scale delta should match the new scale on the impl side. | 2067 // The page scale delta should match the new scale on the impl side. |
2005 EXPECT_EQ(page_scale, host_impl_->active_tree()->total_page_scale_factor()); | 2068 EXPECT_EQ(page_scale, host_impl_->active_tree()->total_page_scale_factor()); |
2006 } | 2069 } |
2007 | 2070 |
2008 TEST_F(LayerTreeHostImplTest, PageScaleDeltaAppliedToRootScrollLayerOnly) { | 2071 TEST_F(LayerTreeHostImplTest, PageScaleDeltaAppliedToRootScrollLayerOnly) { |
2009 gfx::Size surface_size(10, 10); | 2072 gfx::Size surface_size(10, 10); |
2010 float default_page_scale = 1.f; | 2073 float default_page_scale = 1.f; |
2011 gfx::Transform default_page_scale_matrix; | 2074 gfx::Transform default_page_scale_matrix; |
2012 default_page_scale_matrix.Scale(default_page_scale, default_page_scale); | 2075 default_page_scale_matrix.Scale(default_page_scale, default_page_scale); |
2013 | 2076 |
2014 float new_page_scale = 2.f; | 2077 float new_page_scale = 2.f; |
2015 gfx::Transform new_page_scale_matrix; | 2078 gfx::Transform new_page_scale_matrix; |
2016 new_page_scale_matrix.Scale(new_page_scale, new_page_scale); | 2079 new_page_scale_matrix.Scale(new_page_scale, new_page_scale); |
2017 | 2080 |
2018 // Create a normal scrollable root layer and another scrollable child layer. | 2081 // Create a normal scrollable root layer and another scrollable child layer. |
2019 LayerImpl* scroll = SetupScrollAndContentsLayers(surface_size); | 2082 LayerImpl* scroll = SetupScrollAndContentsLayers(surface_size); |
2020 LayerImpl* root = host_impl_->active_tree()->root_layer(); | 2083 LayerImpl* root = host_impl_->active_tree()->root_layer(); |
2021 LayerImpl* child = scroll->children()[0]; | 2084 LayerImpl* child = scroll->children()[0]; |
2022 | 2085 |
| 2086 scoped_ptr<LayerImpl> scrollable_child_clip = |
| 2087 LayerImpl::Create(host_impl_->active_tree(), 6); |
2023 scoped_ptr<LayerImpl> scrollable_child = | 2088 scoped_ptr<LayerImpl> scrollable_child = |
2024 CreateScrollableLayer(4, surface_size); | 2089 CreateScrollableLayer(7, surface_size, scrollable_child_clip.get()); |
2025 child->AddChild(scrollable_child.Pass()); | 2090 scrollable_child_clip->AddChild(scrollable_child.Pass()); |
| 2091 child->AddChild(scrollable_child_clip.Pass()); |
2026 LayerImpl* grand_child = child->children()[0]; | 2092 LayerImpl* grand_child = child->children()[0]; |
2027 | 2093 |
2028 // Set new page scale on impl thread by pinching. | 2094 // Set new page scale on impl thread by pinching. |
2029 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); | 2095 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); |
2030 host_impl_->PinchGestureBegin(); | 2096 host_impl_->PinchGestureBegin(); |
2031 host_impl_->PinchGestureUpdate(new_page_scale, gfx::Point()); | 2097 host_impl_->PinchGestureUpdate(new_page_scale, gfx::Point()); |
2032 host_impl_->PinchGestureEnd(); | 2098 host_impl_->PinchGestureEnd(); |
2033 host_impl_->ScrollEnd(); | 2099 host_impl_->ScrollEnd(); |
2034 DrawOneFrame(); | 2100 DrawOneFrame(); |
2035 | 2101 |
(...skipping 20 matching lines...) Expand all Loading... |
2056 EXPECT_EQ(new_page_scale, scroll->draw_transform().matrix().getDouble(1, 1)); | 2122 EXPECT_EQ(new_page_scale, scroll->draw_transform().matrix().getDouble(1, 1)); |
2057 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(0, 0)); | 2123 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(0, 0)); |
2058 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(1, 1)); | 2124 EXPECT_EQ(new_page_scale, child->draw_transform().matrix().getDouble(1, 1)); |
2059 EXPECT_EQ(new_page_scale, | 2125 EXPECT_EQ(new_page_scale, |
2060 grand_child->draw_transform().matrix().getDouble(0, 0)); | 2126 grand_child->draw_transform().matrix().getDouble(0, 0)); |
2061 EXPECT_EQ(new_page_scale, | 2127 EXPECT_EQ(new_page_scale, |
2062 grand_child->draw_transform().matrix().getDouble(1, 1)); | 2128 grand_child->draw_transform().matrix().getDouble(1, 1)); |
2063 } | 2129 } |
2064 | 2130 |
2065 TEST_F(LayerTreeHostImplTest, ScrollChildAndChangePageScaleOnMainThread) { | 2131 TEST_F(LayerTreeHostImplTest, ScrollChildAndChangePageScaleOnMainThread) { |
2066 gfx::Size surface_size(10, 10); | 2132 gfx::Size surface_size(30, 30); |
2067 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 2133 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 2134 root->SetBounds(gfx::Size(5, 5)); |
2068 scoped_ptr<LayerImpl> root_scrolling = | 2135 scoped_ptr<LayerImpl> root_scrolling = |
2069 LayerImpl::Create(host_impl_->active_tree(), 2); | 2136 LayerImpl::Create(host_impl_->active_tree(), 2); |
2070 root_scrolling->SetBounds(surface_size); | 2137 root_scrolling->SetBounds(surface_size); |
2071 root_scrolling->SetContentBounds(surface_size); | 2138 root_scrolling->SetContentBounds(surface_size); |
2072 root_scrolling->SetScrollable(true); | 2139 root_scrolling->SetScrollClipLayer(root->id()); |
| 2140 root_scrolling->SetIsContainerForFixedPositionLayers(true); |
| 2141 LayerImpl* root_scrolling_ptr = root_scrolling.get(); |
2073 root->AddChild(root_scrolling.Pass()); | 2142 root->AddChild(root_scrolling.Pass()); |
2074 int child_scroll_layer_id = 3; | 2143 int child_scroll_layer_id = 3; |
2075 scoped_ptr<LayerImpl> child_scrolling = | 2144 scoped_ptr<LayerImpl> child_scrolling = CreateScrollableLayer( |
2076 CreateScrollableLayer(child_scroll_layer_id, surface_size); | 2145 child_scroll_layer_id, surface_size, root_scrolling_ptr); |
2077 LayerImpl* child = child_scrolling.get(); | 2146 LayerImpl* child = child_scrolling.get(); |
2078 root->AddChild(child_scrolling.Pass()); | 2147 root_scrolling_ptr->AddChild(child_scrolling.Pass()); |
2079 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2148 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 2149 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
2080 host_impl_->active_tree()->DidBecomeActive(); | 2150 host_impl_->active_tree()->DidBecomeActive(); |
2081 host_impl_->SetViewportSize(surface_size); | 2151 host_impl_->SetViewportSize(surface_size); |
2082 DrawFrame(); | 2152 DrawFrame(); |
2083 | 2153 |
2084 gfx::Vector2d scroll_delta(0, 10); | 2154 gfx::Vector2d scroll_delta(0, 10); |
2085 gfx::Vector2d expected_scroll_delta(scroll_delta); | 2155 gfx::Vector2d expected_scroll_delta(scroll_delta); |
2086 gfx::Vector2d expected_max_scroll(child->max_scroll_offset()); | 2156 gfx::Vector2d expected_max_scroll(child->MaxScrollOffset()); |
2087 EXPECT_EQ(InputHandler::ScrollStarted, | 2157 EXPECT_EQ(InputHandler::ScrollStarted, |
2088 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2158 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2089 InputHandler::Wheel)); | 2159 InputHandler::Wheel)); |
2090 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2160 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2091 host_impl_->ScrollEnd(); | 2161 host_impl_->ScrollEnd(); |
2092 | 2162 |
2093 float page_scale = 2.f; | 2163 float page_scale = 2.f; |
2094 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, | 2164 host_impl_->active_tree()->SetPageScaleFactorAndLimits(page_scale, |
2095 1.f, | 2165 1.f, |
2096 page_scale); | 2166 page_scale); |
2097 | 2167 |
2098 DrawOneFrame(); | 2168 DrawOneFrame(); |
2099 | 2169 |
2100 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 2170 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
2101 ExpectContains( | 2171 ExpectContains( |
2102 *scroll_info.get(), child_scroll_layer_id, expected_scroll_delta); | 2172 *scroll_info.get(), child_scroll_layer_id, expected_scroll_delta); |
2103 | 2173 |
2104 // The scroll range should not have changed. | 2174 // The scroll range should not have changed. |
2105 EXPECT_EQ(child->max_scroll_offset(), expected_max_scroll); | 2175 EXPECT_EQ(child->MaxScrollOffset(), expected_max_scroll); |
2106 | 2176 |
2107 // The page scale delta remains constant because the impl thread did not | 2177 // The page scale delta remains constant because the impl thread did not |
2108 // scale. | 2178 // scale. |
2109 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); | 2179 EXPECT_EQ(1.f, host_impl_->active_tree()->page_scale_delta()); |
2110 } | 2180 } |
2111 | 2181 |
2112 TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { | 2182 TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { |
2113 // Scroll a child layer beyond its maximum scroll range and make sure the | 2183 // Scroll a child layer beyond its maximum scroll range and make sure the |
2114 // parent layer is scrolled on the axis on which the child was unable to | 2184 // parent layer is scrolled on the axis on which the child was unable to |
2115 // scroll. | 2185 // scroll. |
2116 gfx::Size surface_size(10, 10); | 2186 gfx::Size surface_size(10, 10); |
2117 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, surface_size); | 2187 gfx::Size content_size(20, 20); |
| 2188 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
| 2189 root->SetBounds(surface_size); |
2118 | 2190 |
2119 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(3, surface_size); | 2191 scoped_ptr<LayerImpl> grand_child = |
2120 grand_child->SetScrollOffset(gfx::Vector2d(0, 5)); | 2192 CreateScrollableLayer(3, content_size, root.get()); |
2121 | 2193 |
2122 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, surface_size); | 2194 scoped_ptr<LayerImpl> child = |
2123 child->SetScrollOffset(gfx::Vector2d(3, 0)); | 2195 CreateScrollableLayer(2, content_size, root.get()); |
| 2196 LayerImpl* grand_child_layer = grand_child.get(); |
2124 child->AddChild(grand_child.Pass()); | 2197 child->AddChild(grand_child.Pass()); |
2125 | 2198 |
| 2199 LayerImpl* child_layer = child.get(); |
2126 root->AddChild(child.Pass()); | 2200 root->AddChild(child.Pass()); |
2127 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2201 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
2128 host_impl_->active_tree()->DidBecomeActive(); | 2202 host_impl_->active_tree()->DidBecomeActive(); |
2129 host_impl_->SetViewportSize(surface_size); | 2203 host_impl_->SetViewportSize(surface_size); |
| 2204 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 5)); |
| 2205 child_layer->SetScrollOffset(gfx::Vector2d(3, 0)); |
| 2206 |
2130 DrawFrame(); | 2207 DrawFrame(); |
2131 { | 2208 { |
2132 gfx::Vector2d scroll_delta(-8, -7); | 2209 gfx::Vector2d scroll_delta(-8, -7); |
2133 EXPECT_EQ(InputHandler::ScrollStarted, | 2210 EXPECT_EQ(InputHandler::ScrollStarted, |
2134 host_impl_->ScrollBegin(gfx::Point(), | 2211 host_impl_->ScrollBegin(gfx::Point(), |
2135 InputHandler::Wheel)); | 2212 InputHandler::Wheel)); |
2136 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2213 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2137 host_impl_->ScrollEnd(); | 2214 host_impl_->ScrollEnd(); |
2138 | 2215 |
2139 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2216 scoped_ptr<ScrollAndScaleSet> scroll_info = |
2140 host_impl_->ProcessScrollDeltas(); | 2217 host_impl_->ProcessScrollDeltas(); |
2141 | 2218 |
2142 // The grand child should have scrolled up to its limit. | 2219 // The grand child should have scrolled up to its limit. |
2143 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; | 2220 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; |
2144 LayerImpl* grand_child = child->children()[0]; | 2221 LayerImpl* grand_child = child->children()[0]; |
2145 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, -5)); | 2222 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, -5)); |
2146 | 2223 |
2147 // The child should have only scrolled on the other axis. | 2224 // The child should have only scrolled on the other axis. |
2148 ExpectContains(*scroll_info.get(), child->id(), gfx::Vector2d(-3, 0)); | 2225 ExpectContains(*scroll_info.get(), child->id(), gfx::Vector2d(-3, 0)); |
2149 } | 2226 } |
2150 } | 2227 } |
2151 | 2228 |
2152 TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { | 2229 TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { |
2153 // Scroll a child layer beyond its maximum scroll range and make sure the | 2230 // Scroll a child layer beyond its maximum scroll range and make sure the |
2154 // the scroll doesn't bubble up to the parent layer. | 2231 // the scroll doesn't bubble up to the parent layer. |
2155 gfx::Size surface_size(10, 10); | 2232 gfx::Size surface_size(20, 20); |
2156 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 2233 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
2157 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 2234 scoped_ptr<LayerImpl> root_scrolling = |
| 2235 CreateScrollableLayer(2, surface_size, root.get()); |
| 2236 root_scrolling->SetIsContainerForFixedPositionLayers(true); |
2158 | 2237 |
2159 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(4, surface_size); | 2238 scoped_ptr<LayerImpl> grand_child = |
2160 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); | 2239 CreateScrollableLayer(4, surface_size, root.get()); |
2161 | 2240 |
2162 scoped_ptr<LayerImpl> child = CreateScrollableLayer(3, surface_size); | 2241 scoped_ptr<LayerImpl> child = |
2163 child->SetScrollOffset(gfx::Vector2d(0, 3)); | 2242 CreateScrollableLayer(3, surface_size, root.get()); |
| 2243 LayerImpl* grand_child_layer = grand_child.get(); |
2164 child->AddChild(grand_child.Pass()); | 2244 child->AddChild(grand_child.Pass()); |
2165 | 2245 |
| 2246 LayerImpl* child_layer = child.get(); |
2166 root_scrolling->AddChild(child.Pass()); | 2247 root_scrolling->AddChild(child.Pass()); |
2167 root->AddChild(root_scrolling.Pass()); | 2248 root->AddChild(root_scrolling.Pass()); |
2168 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2249 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 2250 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
2169 host_impl_->active_tree()->DidBecomeActive(); | 2251 host_impl_->active_tree()->DidBecomeActive(); |
2170 host_impl_->SetViewportSize(surface_size); | 2252 host_impl_->SetViewportSize(surface_size); |
| 2253 |
| 2254 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 2)); |
| 2255 child_layer->SetScrollOffset(gfx::Vector2d(0, 3)); |
| 2256 |
2171 DrawFrame(); | 2257 DrawFrame(); |
2172 { | 2258 { |
2173 gfx::Vector2d scroll_delta(0, -10); | 2259 gfx::Vector2d scroll_delta(0, -10); |
2174 EXPECT_EQ(InputHandler::ScrollStarted, | 2260 EXPECT_EQ(InputHandler::ScrollStarted, |
2175 host_impl_->ScrollBegin(gfx::Point(), | 2261 host_impl_->ScrollBegin(gfx::Point(), |
2176 InputHandler::NonBubblingGesture)); | 2262 InputHandler::NonBubblingGesture)); |
2177 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2263 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2178 host_impl_->ScrollEnd(); | 2264 host_impl_->ScrollEnd(); |
2179 | 2265 |
2180 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2266 scoped_ptr<ScrollAndScaleSet> scroll_info = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2238 EXPECT_EQ(grand_child, host_impl_->CurrentlyScrollingLayer()); | 2324 EXPECT_EQ(grand_child, host_impl_->CurrentlyScrollingLayer()); |
2239 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2325 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2240 host_impl_->ScrollEnd(); | 2326 host_impl_->ScrollEnd(); |
2241 | 2327 |
2242 scroll_info = host_impl_->ProcessScrollDeltas(); | 2328 scroll_info = host_impl_->ProcessScrollDeltas(); |
2243 | 2329 |
2244 // Should have scrolled by half the amount in layer space (5 - 2/2) | 2330 // Should have scrolled by half the amount in layer space (5 - 2/2) |
2245 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, 4)); | 2331 ExpectContains(*scroll_info.get(), grand_child->id(), gfx::Vector2d(0, 4)); |
2246 } | 2332 } |
2247 } | 2333 } |
2248 | |
2249 TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) { | 2334 TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) { |
2250 // When we try to scroll a non-scrollable child layer, the scroll delta | 2335 // When we try to scroll a non-scrollable child layer, the scroll delta |
2251 // should be applied to one of its ancestors if possible. | 2336 // should be applied to one of its ancestors if possible. |
2252 gfx::Size surface_size(10, 10); | 2337 gfx::Size surface_size(10, 10); |
2253 gfx::Size content_size(20, 20); | 2338 gfx::Size content_size(20, 20); |
2254 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 2339 scoped_ptr<LayerImpl> root_clip = |
2255 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 2340 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 2341 scoped_ptr<LayerImpl> root = |
| 2342 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 2343 // Make 'root' the clip layer for child: since they have the same sizes the |
| 2344 // child will have zero max_scroll_offset and scrolls will bubble. |
| 2345 scoped_ptr<LayerImpl> child = |
| 2346 CreateScrollableLayer(2, content_size, root.get()); |
| 2347 child->SetIsContainerForFixedPositionLayers(true); |
| 2348 root->SetBounds(content_size); |
2256 | 2349 |
2257 child->SetScrollable(false); | 2350 int root_scroll_id = root->id(); |
2258 root->AddChild(child.Pass()); | 2351 root->AddChild(child.Pass()); |
| 2352 root_clip->AddChild(root.Pass()); |
2259 | 2353 |
2260 host_impl_->SetViewportSize(surface_size); | 2354 host_impl_->SetViewportSize(surface_size); |
2261 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2355 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 2356 host_impl_->active_tree()->SetViewportLayersFromIds(3, 2, Layer::INVALID_ID); |
2262 host_impl_->active_tree()->DidBecomeActive(); | 2357 host_impl_->active_tree()->DidBecomeActive(); |
2263 DrawFrame(); | 2358 DrawFrame(); |
2264 { | 2359 { |
2265 gfx::Vector2d scroll_delta(0, 4); | 2360 gfx::Vector2d scroll_delta(0, 4); |
2266 EXPECT_EQ(InputHandler::ScrollStarted, | 2361 EXPECT_EQ(InputHandler::ScrollStarted, |
2267 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2362 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2268 InputHandler::Wheel)); | 2363 InputHandler::Wheel)); |
2269 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2364 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2270 host_impl_->ScrollEnd(); | 2365 host_impl_->ScrollEnd(); |
2271 | 2366 |
2272 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2367 scoped_ptr<ScrollAndScaleSet> scroll_info = |
2273 host_impl_->ProcessScrollDeltas(); | 2368 host_impl_->ProcessScrollDeltas(); |
2274 | 2369 |
2275 // Only the root should have scrolled. | 2370 // Only the root scroll should have scrolled. |
2276 ASSERT_EQ(scroll_info->scrolls.size(), 1u); | 2371 ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
2277 ExpectContains(*scroll_info.get(), | 2372 ExpectContains(*scroll_info.get(), root_scroll_id, scroll_delta); |
2278 host_impl_->active_tree()->root_layer()->id(), | |
2279 scroll_delta); | |
2280 } | 2373 } |
2281 } | 2374 } |
2282 | 2375 |
2283 TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { | 2376 TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { |
2284 gfx::Size surface_size(10, 10); | 2377 gfx::Size surface_size(10, 10); |
2285 host_impl_->active_tree()->SetRootLayer( | 2378 scoped_ptr<LayerImpl> root_clip = |
2286 CreateScrollableLayer(1, surface_size)); | 2379 LayerImpl::Create(host_impl_->active_tree(), 1); |
| 2380 scoped_ptr<LayerImpl> root_scroll = |
| 2381 CreateScrollableLayer(2, surface_size, root_clip.get()); |
| 2382 root_scroll->SetIsContainerForFixedPositionLayers(true); |
| 2383 root_clip->AddChild(root_scroll.Pass()); |
| 2384 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 2385 host_impl_->active_tree()->SetViewportLayersFromIds(1, 2, Layer::INVALID_ID); |
2287 host_impl_->active_tree()->DidBecomeActive(); | 2386 host_impl_->active_tree()->DidBecomeActive(); |
2288 host_impl_->SetViewportSize(surface_size); | 2387 host_impl_->SetViewportSize(surface_size); |
2289 | 2388 |
2290 // Draw one frame and then immediately rebuild the layer tree to mimic a tree | 2389 // Draw one frame and then immediately rebuild the layer tree to mimic a tree |
2291 // synchronization. | 2390 // synchronization. |
2292 DrawFrame(); | 2391 DrawFrame(); |
2293 host_impl_->active_tree()->DetachLayerTree(); | 2392 host_impl_->active_tree()->DetachLayerTree(); |
2294 host_impl_->active_tree()->SetRootLayer( | 2393 scoped_ptr<LayerImpl> root_clip2 = |
2295 CreateScrollableLayer(2, surface_size)); | 2394 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 2395 scoped_ptr<LayerImpl> root_scroll2 = |
| 2396 CreateScrollableLayer(4, surface_size, root_clip2.get()); |
| 2397 root_scroll2->SetIsContainerForFixedPositionLayers(true); |
| 2398 root_clip2->AddChild(root_scroll2.Pass()); |
| 2399 host_impl_->active_tree()->SetRootLayer(root_clip2.Pass()); |
| 2400 host_impl_->active_tree()->SetViewportLayersFromIds(3, 4, Layer::INVALID_ID); |
2296 host_impl_->active_tree()->DidBecomeActive(); | 2401 host_impl_->active_tree()->DidBecomeActive(); |
2297 | 2402 |
2298 // Scrolling should still work even though we did not draw yet. | 2403 // Scrolling should still work even though we did not draw yet. |
2299 EXPECT_EQ(InputHandler::ScrollStarted, | 2404 EXPECT_EQ(InputHandler::ScrollStarted, |
2300 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2405 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2301 InputHandler::Wheel)); | 2406 InputHandler::Wheel)); |
2302 } | 2407 } |
2303 | 2408 |
2304 TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { | 2409 TEST_F(LayerTreeHostImplTest, ScrollAxisAlignedRotatedLayer) { |
2305 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2410 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2338 | 2443 |
2339 // The layer should have scrolled down in its local coordinates. | 2444 // The layer should have scrolled down in its local coordinates. |
2340 scroll_info = host_impl_->ProcessScrollDeltas(); | 2445 scroll_info = host_impl_->ProcessScrollDeltas(); |
2341 ExpectContains(*scroll_info.get(), | 2446 ExpectContains(*scroll_info.get(), |
2342 scroll_layer->id(), | 2447 scroll_layer->id(), |
2343 wheel_scroll_delta); | 2448 wheel_scroll_delta); |
2344 } | 2449 } |
2345 | 2450 |
2346 TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { | 2451 TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) { |
2347 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2452 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
2348 int child_layer_id = 4; | 2453 int child_clip_layer_id = 6; |
| 2454 int child_layer_id = 7; |
2349 float child_layer_angle = -20.f; | 2455 float child_layer_angle = -20.f; |
2350 | 2456 |
2351 // Create a child layer that is rotated to a non-axis-aligned angle. | 2457 // Create a child layer that is rotated to a non-axis-aligned angle. |
| 2458 scoped_ptr<LayerImpl> clip_layer = |
| 2459 LayerImpl::Create(host_impl_->active_tree(), child_clip_layer_id); |
2352 scoped_ptr<LayerImpl> child = CreateScrollableLayer( | 2460 scoped_ptr<LayerImpl> child = CreateScrollableLayer( |
2353 child_layer_id, | 2461 child_layer_id, scroll_layer->content_bounds(), clip_layer.get()); |
2354 scroll_layer->content_bounds()); | |
2355 gfx::Transform rotate_transform; | 2462 gfx::Transform rotate_transform; |
2356 rotate_transform.Translate(-50.0, -50.0); | 2463 rotate_transform.Translate(-50.0, -50.0); |
2357 rotate_transform.Rotate(child_layer_angle); | 2464 rotate_transform.Rotate(child_layer_angle); |
2358 rotate_transform.Translate(50.0, 50.0); | 2465 rotate_transform.Translate(50.0, 50.0); |
2359 child->SetTransform(rotate_transform); | 2466 clip_layer->SetTransform(rotate_transform); |
2360 | 2467 |
2361 // Only allow vertical scrolling. | 2468 // Only allow vertical scrolling. |
2362 child->SetMaxScrollOffset(gfx::Vector2d(0, child->content_bounds().height())); | 2469 clip_layer->SetBounds( |
2363 scroll_layer->AddChild(child.Pass()); | 2470 gfx::Size(child->bounds().width(), child->bounds().height() / 2)); |
| 2471 // The rotation depends on the layer's anchor point, and the child layer is a |
| 2472 // different size than the clip, so make sure the clip layer's anchor lines |
| 2473 // up over the child. |
| 2474 clip_layer->SetAnchorPoint(gfx::PointF(0.5, 1.0)); |
| 2475 LayerImpl* child_ptr = child.get(); |
| 2476 clip_layer->AddChild(child.Pass()); |
| 2477 scroll_layer->AddChild(clip_layer.Pass()); |
2364 | 2478 |
2365 gfx::Size surface_size(50, 50); | 2479 gfx::Size surface_size(50, 50); |
2366 host_impl_->SetViewportSize(surface_size); | 2480 host_impl_->SetViewportSize(surface_size); |
2367 DrawFrame(); | 2481 DrawFrame(); |
2368 { | 2482 { |
2369 // Scroll down in screen coordinates with a gesture. | 2483 // Scroll down in screen coordinates with a gesture. |
2370 gfx::Vector2d gesture_scroll_delta(0, 10); | 2484 gfx::Vector2d gesture_scroll_delta(0, 10); |
2371 EXPECT_EQ(InputHandler::ScrollStarted, | 2485 EXPECT_EQ(InputHandler::ScrollStarted, |
2372 host_impl_->ScrollBegin(gfx::Point(1, 1), | 2486 host_impl_->ScrollBegin(gfx::Point(1, 1), |
2373 InputHandler::Gesture)); | 2487 InputHandler::Gesture)); |
2374 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 2488 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
2375 host_impl_->ScrollEnd(); | 2489 host_impl_->ScrollEnd(); |
2376 | 2490 |
2377 // The child layer should have scrolled down in its local coordinates an | 2491 // The child layer should have scrolled down in its local coordinates an |
2378 // amount proportional to the angle between it and the input scroll delta. | 2492 // amount proportional to the angle between it and the input scroll delta. |
2379 gfx::Vector2d expected_scroll_delta( | 2493 gfx::Vector2d expected_scroll_delta( |
2380 0, | 2494 0, |
2381 gesture_scroll_delta.y() * | 2495 gesture_scroll_delta.y() * |
2382 std::cos(MathUtil::Deg2Rad(child_layer_angle))); | 2496 std::cos(MathUtil::Deg2Rad(child_layer_angle))); |
2383 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2497 scoped_ptr<ScrollAndScaleSet> scroll_info = |
2384 host_impl_->ProcessScrollDeltas(); | 2498 host_impl_->ProcessScrollDeltas(); |
2385 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); | 2499 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); |
2386 | 2500 |
2387 // The root scroll layer should not have scrolled, because the input delta | 2501 // The root scroll layer should not have scrolled, because the input delta |
2388 // was close to the layer's axis of movement. | 2502 // was close to the layer's axis of movement. |
2389 EXPECT_EQ(scroll_info->scrolls.size(), 1u); | 2503 EXPECT_EQ(scroll_info->scrolls.size(), 1u); |
2390 } | 2504 } |
2391 { | 2505 { |
2392 // Now reset and scroll the same amount horizontally. | 2506 // Now reset and scroll the same amount horizontally. |
2393 scroll_layer->children()[1]->SetScrollDelta( | 2507 child_ptr->SetScrollDelta(gfx::Vector2dF()); |
2394 gfx::Vector2dF()); | |
2395 gfx::Vector2d gesture_scroll_delta(10, 0); | 2508 gfx::Vector2d gesture_scroll_delta(10, 0); |
2396 EXPECT_EQ(InputHandler::ScrollStarted, | 2509 EXPECT_EQ(InputHandler::ScrollStarted, |
2397 host_impl_->ScrollBegin(gfx::Point(1, 1), | 2510 host_impl_->ScrollBegin(gfx::Point(1, 1), |
2398 InputHandler::Gesture)); | 2511 InputHandler::Gesture)); |
2399 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 2512 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
2400 host_impl_->ScrollEnd(); | 2513 host_impl_->ScrollEnd(); |
2401 | 2514 |
2402 // The child layer should have scrolled down in its local coordinates an | 2515 // The child layer should have scrolled down in its local coordinates an |
2403 // amount proportional to the angle between it and the input scroll delta. | 2516 // amount proportional to the angle between it and the input scroll delta. |
2404 gfx::Vector2d expected_scroll_delta( | 2517 gfx::Vector2d expected_scroll_delta( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2518 gfx::Vector2dF getter_return_value_; | 2631 gfx::Vector2dF getter_return_value_; |
2519 gfx::Vector2dF max_scroll_offset_; | 2632 gfx::Vector2dF max_scroll_offset_; |
2520 gfx::SizeF scrollable_size_; | 2633 gfx::SizeF scrollable_size_; |
2521 float page_scale_factor_; | 2634 float page_scale_factor_; |
2522 }; | 2635 }; |
2523 | 2636 |
2524 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { | 2637 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { |
2525 TestScrollOffsetDelegate scroll_delegate; | 2638 TestScrollOffsetDelegate scroll_delegate; |
2526 host_impl_->SetViewportSize(gfx::Size(10, 20)); | 2639 host_impl_->SetViewportSize(gfx::Size(10, 20)); |
2527 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2640 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2641 LayerImpl* clip_layer = scroll_layer->parent()->parent(); |
| 2642 clip_layer->SetBounds(gfx::Size(10, 20)); |
2528 | 2643 |
2529 // Setting the delegate results in the current scroll offset being set. | 2644 // Setting the delegate results in the current scroll offset being set. |
2530 gfx::Vector2dF initial_scroll_delta(10.f, 10.f); | 2645 gfx::Vector2dF initial_scroll_delta(10.f, 10.f); |
2531 scroll_layer->SetScrollOffset(gfx::Vector2d()); | 2646 scroll_layer->SetScrollOffset(gfx::Vector2d()); |
2532 scroll_layer->SetScrollDelta(initial_scroll_delta); | 2647 scroll_layer->SetScrollDelta(initial_scroll_delta); |
2533 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate); | 2648 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate); |
2534 EXPECT_EQ(initial_scroll_delta.ToString(), | 2649 EXPECT_EQ(initial_scroll_delta.ToString(), |
2535 scroll_delegate.last_set_scroll_offset().ToString()); | 2650 scroll_delegate.last_set_scroll_offset().ToString()); |
2536 | 2651 |
2537 // Setting the delegate results in the scrollable_size, max_scroll_offset and | 2652 // 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... |
2641 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 2756 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
2642 EXPECT_EQ(gfx::Vector2dF(0, -20), host_impl_->accumulated_root_overscroll()); | 2757 EXPECT_EQ(gfx::Vector2dF(0, -20), host_impl_->accumulated_root_overscroll()); |
2643 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); | 2758 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); |
2644 } | 2759 } |
2645 | 2760 |
2646 | 2761 |
2647 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { | 2762 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { |
2648 // Scroll child layers beyond their maximum scroll range and make sure root | 2763 // Scroll child layers beyond their maximum scroll range and make sure root |
2649 // overscroll does not accumulate. | 2764 // overscroll does not accumulate. |
2650 gfx::Size surface_size(10, 10); | 2765 gfx::Size surface_size(10, 10); |
2651 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, surface_size); | 2766 scoped_ptr<LayerImpl> root_clip = |
| 2767 LayerImpl::Create(host_impl_->active_tree(), 4); |
| 2768 scoped_ptr<LayerImpl> root = |
| 2769 CreateScrollableLayer(1, surface_size, root_clip.get()); |
2652 | 2770 |
2653 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(3, surface_size); | 2771 scoped_ptr<LayerImpl> grand_child = |
2654 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); | 2772 CreateScrollableLayer(3, surface_size, root_clip.get()); |
2655 | 2773 |
2656 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, surface_size); | 2774 scoped_ptr<LayerImpl> child = |
2657 child->SetScrollOffset(gfx::Vector2d(0, 3)); | 2775 CreateScrollableLayer(2, surface_size, root_clip.get()); |
| 2776 LayerImpl* grand_child_layer = grand_child.get(); |
2658 child->AddChild(grand_child.Pass()); | 2777 child->AddChild(grand_child.Pass()); |
2659 | 2778 |
| 2779 LayerImpl* child_layer = child.get(); |
2660 root->AddChild(child.Pass()); | 2780 root->AddChild(child.Pass()); |
2661 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2781 root_clip->AddChild(root.Pass()); |
| 2782 child_layer->SetScrollOffset(gfx::Vector2d(0, 3)); |
| 2783 grand_child_layer->SetScrollOffset(gfx::Vector2d(0, 2)); |
| 2784 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
2662 host_impl_->active_tree()->DidBecomeActive(); | 2785 host_impl_->active_tree()->DidBecomeActive(); |
2663 host_impl_->SetViewportSize(surface_size); | 2786 host_impl_->SetViewportSize(surface_size); |
2664 DrawFrame(); | 2787 DrawFrame(); |
2665 { | 2788 { |
2666 gfx::Vector2d scroll_delta(0, -10); | 2789 gfx::Vector2d scroll_delta(0, -10); |
2667 EXPECT_EQ(InputHandler::ScrollStarted, | 2790 EXPECT_EQ(InputHandler::ScrollStarted, |
2668 host_impl_->ScrollBegin(gfx::Point(), | 2791 host_impl_->ScrollBegin(gfx::Point(), |
2669 InputHandler::NonBubblingGesture)); | 2792 InputHandler::NonBubblingGesture)); |
2670 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2793 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2671 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2794 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2672 host_impl_->ScrollEnd(); | 2795 host_impl_->ScrollEnd(); |
2673 | 2796 |
2674 LayerImpl* child = host_impl_->active_tree()->root_layer()->children()[0]; | |
2675 LayerImpl* grand_child = child->children()[0]; | |
2676 | |
2677 // The next time we scroll we should only scroll the parent, but overscroll | 2797 // The next time we scroll we should only scroll the parent, but overscroll |
2678 // should still not reach the root layer. | 2798 // should still not reach the root layer. |
2679 scroll_delta = gfx::Vector2d(0, -30); | 2799 scroll_delta = gfx::Vector2d(0, -30); |
2680 EXPECT_EQ(InputHandler::ScrollStarted, | 2800 EXPECT_EQ(InputHandler::ScrollStarted, |
2681 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2801 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2682 InputHandler::NonBubblingGesture)); | 2802 InputHandler::NonBubblingGesture)); |
2683 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 2803 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
2684 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2804 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2685 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2805 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2686 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); | 2806 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_layer); |
2687 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2807 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2688 host_impl_->ScrollEnd(); | 2808 host_impl_->ScrollEnd(); |
2689 | 2809 |
2690 // After scrolling the parent, another scroll on the opposite direction | 2810 // After scrolling the parent, another scroll on the opposite direction |
2691 // should scroll the child, resetting the fling velocity. | 2811 // should scroll the child, resetting the fling velocity. |
2692 scroll_delta = gfx::Vector2d(0, 70); | 2812 scroll_delta = gfx::Vector2d(0, 70); |
2693 host_impl_->NotifyCurrentFlingVelocity(gfx::Vector2dF(10, 0)); | 2813 host_impl_->NotifyCurrentFlingVelocity(gfx::Vector2dF(10, 0)); |
2694 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); | 2814 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); |
2695 EXPECT_EQ(InputHandler::ScrollStarted, | 2815 EXPECT_EQ(InputHandler::ScrollStarted, |
2696 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2816 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2697 InputHandler::NonBubblingGesture)); | 2817 InputHandler::NonBubblingGesture)); |
2698 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 2818 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
2699 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2819 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2700 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child); | 2820 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
2701 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2821 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2702 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | 2822 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
2703 host_impl_->ScrollEnd(); | 2823 host_impl_->ScrollEnd(); |
2704 } | 2824 } |
2705 } | 2825 } |
2706 | 2826 |
2707 TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { | 2827 TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { |
2708 // When we try to scroll a non-scrollable child layer, the scroll delta | 2828 // When we try to scroll a non-scrollable child layer, the scroll delta |
2709 // should be applied to one of its ancestors if possible. Overscroll should | 2829 // should be applied to one of its ancestors if possible. Overscroll should |
2710 // be reflected only when it has bubbled up to the root scrolling layer. | 2830 // be reflected only when it has bubbled up to the root scrolling layer. |
2711 gfx::Size surface_size(10, 10); | 2831 gfx::Size surface_size(10, 10); |
2712 gfx::Size content_size(20, 20); | 2832 gfx::Size content_size(20, 20); |
2713 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 2833 scoped_ptr<LayerImpl> root_clip = |
2714 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 2834 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 2835 scoped_ptr<LayerImpl> root = |
| 2836 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 2837 root->SetIsContainerForFixedPositionLayers(true); |
| 2838 scoped_ptr<LayerImpl> child = |
| 2839 CreateScrollableLayer(2, content_size, root_clip.get()); |
2715 | 2840 |
2716 child->SetScrollable(false); | 2841 child->SetScrollClipLayer(Layer::INVALID_ID); |
2717 root->AddChild(child.Pass()); | 2842 root->AddChild(child.Pass()); |
| 2843 root_clip->AddChild(root.Pass()); |
2718 | 2844 |
2719 host_impl_->SetViewportSize(surface_size); | 2845 host_impl_->SetViewportSize(surface_size); |
2720 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 2846 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 2847 host_impl_->active_tree()->SetViewportLayersFromIds(3, 1, Layer::INVALID_ID); |
2721 host_impl_->active_tree()->DidBecomeActive(); | 2848 host_impl_->active_tree()->DidBecomeActive(); |
2722 DrawFrame(); | 2849 DrawFrame(); |
2723 { | 2850 { |
2724 gfx::Vector2d scroll_delta(0, 8); | 2851 gfx::Vector2d scroll_delta(0, 8); |
2725 EXPECT_EQ(InputHandler::ScrollStarted, | 2852 EXPECT_EQ(InputHandler::ScrollStarted, |
2726 host_impl_->ScrollBegin(gfx::Point(5, 5), | 2853 host_impl_->ScrollBegin(gfx::Point(5, 5), |
2727 InputHandler::Wheel)); | 2854 InputHandler::Wheel)); |
2728 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2855 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2729 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2856 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2730 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2857 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2731 EXPECT_EQ(gfx::Vector2dF(0, 6), host_impl_->accumulated_root_overscroll()); | 2858 EXPECT_EQ(gfx::Vector2dF(0, 6), host_impl_->accumulated_root_overscroll()); |
2732 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2859 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2733 EXPECT_EQ(gfx::Vector2dF(0, 14), host_impl_->accumulated_root_overscroll()); | 2860 EXPECT_EQ(gfx::Vector2dF(0, 14), host_impl_->accumulated_root_overscroll()); |
2734 host_impl_->ScrollEnd(); | 2861 host_impl_->ScrollEnd(); |
2735 } | 2862 } |
2736 } | 2863 } |
2737 | 2864 |
2738 TEST_F(LayerTreeHostImplTest, OverscrollAlways) { | 2865 TEST_F(LayerTreeHostImplTest, OverscrollAlways) { |
2739 LayerTreeSettings settings; | 2866 LayerTreeSettings settings; |
2740 CreateHostImpl(settings, CreateOutputSurface()); | 2867 CreateHostImpl(settings, CreateOutputSurface()); |
2741 | 2868 |
2742 SetupScrollAndContentsLayers(gfx::Size(50, 50)); | 2869 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); |
| 2870 LayerImpl* clip_layer = scroll_layer->parent()->parent(); |
| 2871 clip_layer->SetBounds(gfx::Size(50, 50)); |
2743 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 2872 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
2744 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 2873 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
2745 DrawFrame(); | 2874 DrawFrame(); |
2746 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2875 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
2747 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | 2876 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
2748 | 2877 |
2749 // Even though the layer can't scroll the overscroll still happens. | 2878 // Even though the layer can't scroll the overscroll still happens. |
2750 EXPECT_EQ(InputHandler::ScrollStarted, | 2879 EXPECT_EQ(InputHandler::ScrollStarted, |
2751 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 2880 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
2752 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 2881 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
(...skipping 2060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4813 scoped_ptr<FakePictureLayerImpl> scoped_content_layer = | 4942 scoped_ptr<FakePictureLayerImpl> scoped_content_layer = |
4814 FakePictureLayerImpl::CreateWithPile(host_impl_->pending_tree(), 3, pile); | 4943 FakePictureLayerImpl::CreateWithPile(host_impl_->pending_tree(), 3, pile); |
4815 LayerImpl* content_layer = scoped_content_layer.get(); | 4944 LayerImpl* content_layer = scoped_content_layer.get(); |
4816 scrolling_layer->AddChild(scoped_content_layer.PassAs<LayerImpl>()); | 4945 scrolling_layer->AddChild(scoped_content_layer.PassAs<LayerImpl>()); |
4817 content_layer->SetBounds(content_layer_bounds); | 4946 content_layer->SetBounds(content_layer_bounds); |
4818 content_layer->SetDrawsContent(true); | 4947 content_layer->SetDrawsContent(true); |
4819 | 4948 |
4820 root->SetBounds(root_size); | 4949 root->SetBounds(root_size); |
4821 | 4950 |
4822 gfx::Vector2d scroll_offset(100000, 0); | 4951 gfx::Vector2d scroll_offset(100000, 0); |
4823 scrolling_layer->SetScrollable(true); | 4952 scrolling_layer->SetScrollClipLayer(root->id()); |
4824 scrolling_layer->SetMaxScrollOffset(scroll_offset); | |
4825 scrolling_layer->SetScrollOffset(scroll_offset); | 4953 scrolling_layer->SetScrollOffset(scroll_offset); |
4826 | 4954 |
4827 host_impl_->ActivatePendingTree(); | 4955 host_impl_->ActivatePendingTree(); |
4828 | 4956 |
4829 host_impl_->active_tree()->UpdateDrawProperties(); | 4957 host_impl_->active_tree()->UpdateDrawProperties(); |
4830 ASSERT_EQ(1u, host_impl_->active_tree()->RenderSurfaceLayerList().size()); | 4958 ASSERT_EQ(1u, host_impl_->active_tree()->RenderSurfaceLayerList().size()); |
4831 | 4959 |
4832 LayerTreeHostImpl::FrameData frame; | 4960 LayerTreeHostImpl::FrameData frame; |
4833 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, | 4961 EXPECT_EQ(DrawSwapReadbackResult::DRAW_SUCCESS, |
4834 host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 4962 host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5268 // released, and the texture deleted. | 5396 // released, and the texture deleted. |
5269 EXPECT_TRUE(context_provider->HasOneRef()); | 5397 EXPECT_TRUE(context_provider->HasOneRef()); |
5270 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); | 5398 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); |
5271 } | 5399 } |
5272 | 5400 |
5273 TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { | 5401 TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { |
5274 // When flinging via touch, only the child should scroll (we should not | 5402 // When flinging via touch, only the child should scroll (we should not |
5275 // bubble). | 5403 // bubble). |
5276 gfx::Size surface_size(10, 10); | 5404 gfx::Size surface_size(10, 10); |
5277 gfx::Size content_size(20, 20); | 5405 gfx::Size content_size(20, 20); |
5278 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 5406 scoped_ptr<LayerImpl> root_clip = |
5279 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 5407 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 5408 scoped_ptr<LayerImpl> root = |
| 5409 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 5410 root->SetIsContainerForFixedPositionLayers(true); |
| 5411 scoped_ptr<LayerImpl> child = |
| 5412 CreateScrollableLayer(2, content_size, root_clip.get()); |
5280 | 5413 |
5281 root->AddChild(child.Pass()); | 5414 root->AddChild(child.Pass()); |
| 5415 int root_id = root->id(); |
| 5416 root_clip->AddChild(root.Pass()); |
5282 | 5417 |
5283 host_impl_->SetViewportSize(surface_size); | 5418 host_impl_->SetViewportSize(surface_size); |
5284 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 5419 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
| 5420 host_impl_->active_tree()->SetViewportLayersFromIds(3, 1, Layer::INVALID_ID); |
5285 host_impl_->active_tree()->DidBecomeActive(); | 5421 host_impl_->active_tree()->DidBecomeActive(); |
5286 DrawFrame(); | 5422 DrawFrame(); |
5287 { | 5423 { |
5288 EXPECT_EQ(InputHandler::ScrollStarted, | 5424 EXPECT_EQ(InputHandler::ScrollStarted, |
5289 host_impl_->ScrollBegin(gfx::Point(), | 5425 host_impl_->ScrollBegin(gfx::Point(), |
5290 InputHandler::Gesture)); | 5426 InputHandler::Gesture)); |
5291 | 5427 |
5292 EXPECT_EQ(InputHandler::ScrollStarted, | 5428 EXPECT_EQ(InputHandler::ScrollStarted, |
5293 host_impl_->FlingScrollBegin()); | 5429 host_impl_->FlingScrollBegin()); |
5294 | 5430 |
5295 gfx::Vector2d scroll_delta(0, 100); | 5431 gfx::Vector2d scroll_delta(0, 100); |
5296 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5432 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5297 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5433 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5298 | 5434 |
5299 host_impl_->ScrollEnd(); | 5435 host_impl_->ScrollEnd(); |
5300 | 5436 |
5301 scoped_ptr<ScrollAndScaleSet> scroll_info = | 5437 scoped_ptr<ScrollAndScaleSet> scroll_info = |
5302 host_impl_->ProcessScrollDeltas(); | 5438 host_impl_->ProcessScrollDeltas(); |
5303 | 5439 |
5304 // Only the child should have scrolled. | 5440 // Only the child should have scrolled. |
5305 ASSERT_EQ(1u, scroll_info->scrolls.size()); | 5441 ASSERT_EQ(1u, scroll_info->scrolls.size()); |
5306 ExpectNone(*scroll_info.get(), | 5442 ExpectNone(*scroll_info.get(), root_id); |
5307 host_impl_->active_tree()->root_layer()->id()); | |
5308 } | 5443 } |
5309 } | 5444 } |
5310 | 5445 |
5311 TEST_F(LayerTreeHostImplTest, TouchFlingShouldLockToFirstScrolledLayer) { | 5446 TEST_F(LayerTreeHostImplTest, TouchFlingShouldLockToFirstScrolledLayer) { |
5312 // Scroll a child layer beyond its maximum scroll range and make sure the | 5447 // Scroll a child layer beyond its maximum scroll range and make sure the |
5313 // the scroll doesn't bubble up to the parent layer. | 5448 // the scroll doesn't bubble up to the parent layer. |
5314 gfx::Size surface_size(10, 10); | 5449 gfx::Size surface_size(10, 10); |
5315 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); | 5450 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_->active_tree(), 1); |
5316 scoped_ptr<LayerImpl> root_scrolling = CreateScrollableLayer(2, surface_size); | 5451 scoped_ptr<LayerImpl> root_scrolling = |
| 5452 CreateScrollableLayer(2, surface_size, root.get()); |
5317 | 5453 |
5318 scoped_ptr<LayerImpl> grand_child = CreateScrollableLayer(4, surface_size); | 5454 scoped_ptr<LayerImpl> grand_child = |
| 5455 CreateScrollableLayer(4, surface_size, root.get()); |
5319 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); | 5456 grand_child->SetScrollOffset(gfx::Vector2d(0, 2)); |
5320 | 5457 |
5321 scoped_ptr<LayerImpl> child = CreateScrollableLayer(3, surface_size); | 5458 scoped_ptr<LayerImpl> child = |
| 5459 CreateScrollableLayer(3, surface_size, root.get()); |
5322 child->SetScrollOffset(gfx::Vector2d(0, 4)); | 5460 child->SetScrollOffset(gfx::Vector2d(0, 4)); |
5323 child->AddChild(grand_child.Pass()); | 5461 child->AddChild(grand_child.Pass()); |
5324 | 5462 |
5325 root_scrolling->AddChild(child.Pass()); | 5463 root_scrolling->AddChild(child.Pass()); |
5326 root->AddChild(root_scrolling.Pass()); | 5464 root->AddChild(root_scrolling.Pass()); |
5327 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 5465 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
5328 host_impl_->active_tree()->DidBecomeActive(); | 5466 host_impl_->active_tree()->DidBecomeActive(); |
5329 host_impl_->SetViewportSize(surface_size); | 5467 host_impl_->SetViewportSize(surface_size); |
5330 DrawFrame(); | 5468 DrawFrame(); |
5331 { | 5469 { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5371 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); | 5509 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child); |
5372 host_impl_->ScrollEnd(); | 5510 host_impl_->ScrollEnd(); |
5373 } | 5511 } |
5374 } | 5512 } |
5375 | 5513 |
5376 TEST_F(LayerTreeHostImplTest, WheelFlingShouldBubble) { | 5514 TEST_F(LayerTreeHostImplTest, WheelFlingShouldBubble) { |
5377 // When flinging via wheel, the root should eventually scroll (we should | 5515 // When flinging via wheel, the root should eventually scroll (we should |
5378 // bubble). | 5516 // bubble). |
5379 gfx::Size surface_size(10, 10); | 5517 gfx::Size surface_size(10, 10); |
5380 gfx::Size content_size(20, 20); | 5518 gfx::Size content_size(20, 20); |
5381 scoped_ptr<LayerImpl> root = CreateScrollableLayer(1, content_size); | 5519 scoped_ptr<LayerImpl> root_clip = |
5382 scoped_ptr<LayerImpl> child = CreateScrollableLayer(2, content_size); | 5520 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 5521 scoped_ptr<LayerImpl> root_scroll = |
| 5522 CreateScrollableLayer(1, content_size, root_clip.get()); |
| 5523 int root_scroll_id = root_scroll->id(); |
| 5524 scoped_ptr<LayerImpl> child = |
| 5525 CreateScrollableLayer(2, content_size, root_clip.get()); |
5383 | 5526 |
5384 root->AddChild(child.Pass()); | 5527 root_scroll->AddChild(child.Pass()); |
| 5528 root_clip->AddChild(root_scroll.Pass()); |
5385 | 5529 |
5386 host_impl_->SetViewportSize(surface_size); | 5530 host_impl_->SetViewportSize(surface_size); |
5387 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 5531 host_impl_->active_tree()->SetRootLayer(root_clip.Pass()); |
5388 host_impl_->active_tree()->DidBecomeActive(); | 5532 host_impl_->active_tree()->DidBecomeActive(); |
5389 DrawFrame(); | 5533 DrawFrame(); |
5390 { | 5534 { |
5391 EXPECT_EQ(InputHandler::ScrollStarted, | 5535 EXPECT_EQ(InputHandler::ScrollStarted, |
5392 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 5536 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
5393 | 5537 |
5394 EXPECT_EQ(InputHandler::ScrollStarted, | 5538 EXPECT_EQ(InputHandler::ScrollStarted, |
5395 host_impl_->FlingScrollBegin()); | 5539 host_impl_->FlingScrollBegin()); |
5396 | 5540 |
5397 gfx::Vector2d scroll_delta(0, 100); | 5541 gfx::Vector2d scroll_delta(0, 100); |
5398 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5542 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5399 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 5543 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
5400 | 5544 |
5401 host_impl_->ScrollEnd(); | 5545 host_impl_->ScrollEnd(); |
5402 | 5546 |
5403 scoped_ptr<ScrollAndScaleSet> scroll_info = | 5547 scoped_ptr<ScrollAndScaleSet> scroll_info = |
5404 host_impl_->ProcessScrollDeltas(); | 5548 host_impl_->ProcessScrollDeltas(); |
5405 | 5549 |
5406 // The root should have scrolled. | 5550 // The root should have scrolled. |
5407 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 5551 ASSERT_EQ(2u, scroll_info->scrolls.size()); |
5408 ExpectContains(*scroll_info.get(), | 5552 ExpectContains(*scroll_info.get(), root_scroll_id, gfx::Vector2d(0, 10)); |
5409 host_impl_->active_tree()->root_layer()->id(), | |
5410 gfx::Vector2d(0, 10)); | |
5411 } | 5553 } |
5412 } | 5554 } |
5413 | 5555 |
5414 // Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed | 5556 // Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed |
5415 // to CompositorFrameMetadata after SwapBuffers(); | 5557 // to CompositorFrameMetadata after SwapBuffers(); |
5416 TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) { | 5558 TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) { |
5417 scoped_ptr<SolidColorLayerImpl> root = | 5559 scoped_ptr<SolidColorLayerImpl> root = |
5418 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); | 5560 SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); |
5419 root->SetAnchorPoint(gfx::PointF()); | 5561 root->SetAnchorPoint(gfx::PointF()); |
5420 root->SetPosition(gfx::PointF()); | 5562 root->SetPosition(gfx::PointF()); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5519 &set_needs_redraw_count)); | 5661 &set_needs_redraw_count)); |
5520 // Empty damage rect won't signal the monitor. | 5662 // Empty damage rect won't signal the monitor. |
5521 host_impl_->SetNeedsRedrawRect(gfx::Rect()); | 5663 host_impl_->SetNeedsRedrawRect(gfx::Rect()); |
5522 EXPECT_EQ(0, set_needs_commit_count); | 5664 EXPECT_EQ(0, set_needs_commit_count); |
5523 EXPECT_EQ(2, set_needs_redraw_count); | 5665 EXPECT_EQ(2, set_needs_redraw_count); |
5524 } | 5666 } |
5525 } | 5667 } |
5526 | 5668 |
5527 } // namespace | 5669 } // namespace |
5528 } // namespace cc | 5670 } // namespace cc |
OLD | NEW |