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

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

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

Powered by Google App Engine
This is Rietveld 408576698