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

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

Powered by Google App Engine
This is Rietveld 408576698