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

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

Issue 2816063003: Replace layer id with Element id for tracking scrollbar animation controllers (Closed)
Patch Set: Address reviewer comments, pull element_id.h change to another patch Created 3 years, 8 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 scroll->SetBounds(scroll_content_size); 1034 scroll->SetBounds(scroll_content_size);
1035 scroll->SetScrollClipLayer(clip->id()); 1035 scroll->SetScrollClipLayer(clip->id());
1036 scroll->SetElementId(LayerIdToElementIdForTesting(scroll->id())); 1036 scroll->SetElementId(LayerIdToElementIdForTesting(scroll->id()));
1037 scroll->SetDrawsContent(true); 1037 scroll->SetDrawsContent(true);
1038 1038
1039 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = 1039 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
1040 SolidColorScrollbarLayerImpl::Create(layer_tree_impl, 4, VERTICAL, 10, 0, 1040 SolidColorScrollbarLayerImpl::Create(layer_tree_impl, 4, VERTICAL, 10, 0,
1041 false, true); 1041 false, true);
1042 scrollbar->SetBounds(scrollbar_size); 1042 scrollbar->SetBounds(scrollbar_size);
1043 scrollbar->SetPosition(gfx::PointF(345, 0)); 1043 scrollbar->SetPosition(gfx::PointF(345, 0));
1044 scrollbar->SetScrollLayerId(scroll->id()); 1044 scrollbar->SetScrollInfo(scroll->id(), scroll->element_id());
1045 scrollbar->SetDrawsContent(true); 1045 scrollbar->SetDrawsContent(true);
1046 scrollbar->test_properties()->opacity = 1.f; 1046 scrollbar->test_properties()->opacity = 1.f;
1047 1047
1048 std::unique_ptr<LayerImpl> squash1 = LayerImpl::Create(layer_tree_impl, 5); 1048 std::unique_ptr<LayerImpl> squash1 = LayerImpl::Create(layer_tree_impl, 5);
1049 squash1->SetBounds(gfx::Size(140, 300)); 1049 squash1->SetBounds(gfx::Size(140, 300));
1050 squash1->SetPosition(gfx::PointF(220, 0)); 1050 squash1->SetPosition(gfx::PointF(220, 0));
1051 squash1->SetDrawsContent(true); 1051 squash1->SetDrawsContent(true);
1052 1052
1053 std::unique_ptr<LayerImpl> squash2 = LayerImpl::Create(layer_tree_impl, 6); 1053 std::unique_ptr<LayerImpl> squash2 = LayerImpl::Create(layer_tree_impl, 6);
1054 squash2->SetBounds(gfx::Size(140, 300)); 1054 squash2->SetBounds(gfx::Size(140, 300));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 scroll->SetBounds(scroll_content_size); 1106 scroll->SetBounds(scroll_content_size);
1107 scroll->SetScrollClipLayer(clip->id()); 1107 scroll->SetScrollClipLayer(clip->id());
1108 scroll->SetElementId(LayerIdToElementIdForTesting(scroll->id())); 1108 scroll->SetElementId(LayerIdToElementIdForTesting(scroll->id()));
1109 scroll->SetDrawsContent(true); 1109 scroll->SetDrawsContent(true);
1110 1110
1111 std::unique_ptr<SolidColorScrollbarLayerImpl> drawn_scrollbar = 1111 std::unique_ptr<SolidColorScrollbarLayerImpl> drawn_scrollbar =
1112 SolidColorScrollbarLayerImpl::Create(layer_tree_impl, 4, VERTICAL, 10, 0, 1112 SolidColorScrollbarLayerImpl::Create(layer_tree_impl, 4, VERTICAL, 10, 0,
1113 false, true); 1113 false, true);
1114 drawn_scrollbar->SetBounds(scrollbar_size); 1114 drawn_scrollbar->SetBounds(scrollbar_size);
1115 drawn_scrollbar->SetPosition(gfx::PointF(345, 0)); 1115 drawn_scrollbar->SetPosition(gfx::PointF(345, 0));
1116 drawn_scrollbar->SetScrollLayerId(scroll->id()); 1116 drawn_scrollbar->SetScrollInfo(scroll->id(), scroll->element_id());
1117 drawn_scrollbar->SetDrawsContent(true); 1117 drawn_scrollbar->SetDrawsContent(true);
1118 drawn_scrollbar->test_properties()->opacity = 1.f; 1118 drawn_scrollbar->test_properties()->opacity = 1.f;
1119 1119
1120 std::unique_ptr<LayerImpl> squash = LayerImpl::Create(layer_tree_impl, 5); 1120 std::unique_ptr<LayerImpl> squash = LayerImpl::Create(layer_tree_impl, 5);
1121 squash->SetBounds(gfx::Size(140, 300)); 1121 squash->SetBounds(gfx::Size(140, 300));
1122 squash->SetPosition(gfx::PointF(220, 0)); 1122 squash->SetPosition(gfx::PointF(220, 0));
1123 squash->SetDrawsContent(true); 1123 squash->SetDrawsContent(true);
1124 1124
1125 scroll->test_properties()->AddChild(std::move(drawn_scrollbar)); 1125 scroll->test_properties()->AddChild(std::move(drawn_scrollbar));
1126 scroll->test_properties()->AddChild(std::move(squash)); 1126 scroll->test_properties()->AddChild(std::move(squash));
(...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after
2849 gfx::Size(content_size.width() / 2, content_size.height() / 2)); 2849 gfx::Size(content_size.width() / 2, content_size.height() / 2));
2850 2850
2851 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = 2851 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
2852 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 400, 2852 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 400,
2853 VERTICAL, 10, 0, false, true); 2853 VERTICAL, 10, 0, false, true);
2854 scrollbar->test_properties()->opacity = 0.f; 2854 scrollbar->test_properties()->opacity = 0.f;
2855 EXPECT_FLOAT_EQ(0.f, scrollbar->test_properties()->opacity); 2855 EXPECT_FLOAT_EQ(0.f, scrollbar->test_properties()->opacity);
2856 2856
2857 LayerImpl* scroll = host_impl_->active_tree()->OuterViewportScrollLayer(); 2857 LayerImpl* scroll = host_impl_->active_tree()->OuterViewportScrollLayer();
2858 LayerImpl* root = host_impl_->active_tree()->InnerViewportContainerLayer(); 2858 LayerImpl* root = host_impl_->active_tree()->InnerViewportContainerLayer();
2859 scrollbar->SetScrollLayerId(scroll->id()); 2859 scrollbar->SetScrollInfo(scroll->id(), scroll->element_id());
2860 root->test_properties()->AddChild(std::move(scrollbar)); 2860 root->test_properties()->AddChild(std::move(scrollbar));
2861 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 2861 host_impl_->active_tree()->BuildPropertyTreesForTesting();
2862 host_impl_->active_tree()->DidBecomeActive(); 2862 host_impl_->active_tree()->DidBecomeActive();
2863 DrawFrame(); 2863 DrawFrame();
2864 2864
2865 // SetScrollLayerId will initialize the scrollbar which will cause it to 2865 // SetScrollInfo will initialize the scrollbar which will cause it to
2866 // show and request a redraw. 2866 // show and request a redraw.
2867 did_request_redraw_ = false; 2867 did_request_redraw_ = false;
2868 } 2868 }
2869 2869
2870 void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { 2870 void RunTest(LayerTreeSettings::ScrollbarAnimator animator) {
2871 LayerTreeSettings settings = DefaultSettings(); 2871 LayerTreeSettings settings = DefaultSettings();
2872 settings.scrollbar_animator = animator; 2872 settings.scrollbar_animator = animator;
2873 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20); 2873 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20);
2874 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20); 2874 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20);
2875 settings.scrollbar_fade_out_resize_delay = 2875 settings.scrollbar_fade_out_resize_delay =
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
3106 CreateHostImpl(settings, CreateCompositorFrameSink()); 3106 CreateHostImpl(settings, CreateCompositorFrameSink());
3107 host_impl_->CreatePendingTree(); 3107 host_impl_->CreatePendingTree();
3108 CreateScrollAndContentsLayers(host_impl_->pending_tree(), content_size); 3108 CreateScrollAndContentsLayers(host_impl_->pending_tree(), content_size);
3109 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = 3109 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
3110 SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400, 3110 SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400,
3111 VERTICAL, 10, 0, false, true); 3111 VERTICAL, 10, 0, false, true);
3112 scrollbar->test_properties()->opacity = 0.f; 3112 scrollbar->test_properties()->opacity = 0.f;
3113 LayerImpl* scroll = host_impl_->pending_tree()->OuterViewportScrollLayer(); 3113 LayerImpl* scroll = host_impl_->pending_tree()->OuterViewportScrollLayer();
3114 LayerImpl* container = 3114 LayerImpl* container =
3115 host_impl_->pending_tree()->InnerViewportContainerLayer(); 3115 host_impl_->pending_tree()->InnerViewportContainerLayer();
3116 scrollbar->SetScrollLayerId(scroll->id()); 3116 scrollbar->SetScrollInfo(scroll->id(), scroll->element_id());
3117 container->test_properties()->AddChild(std::move(scrollbar)); 3117 container->test_properties()->AddChild(std::move(scrollbar));
3118 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); 3118 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
3119 host_impl_->pending_tree()->BuildPropertyTreesForTesting(); 3119 host_impl_->pending_tree()->BuildPropertyTreesForTesting();
3120 host_impl_->ActivateSyncTree(); 3120 host_impl_->ActivateSyncTree();
3121 3121
3122 LayerImpl* active_scrollbar_layer = 3122 LayerImpl* active_scrollbar_layer =
3123 host_impl_->active_tree()->LayerById(400); 3123 host_impl_->active_tree()->LayerById(400);
3124 3124
3125 EffectNode* active_tree_node = 3125 EffectNode* active_tree_node =
3126 host_impl_->active_tree()->property_trees()->effect_tree.Node( 3126 host_impl_->active_tree()->property_trees()->effect_tree.Node(
3127 active_scrollbar_layer->effect_tree_index()); 3127 active_scrollbar_layer->effect_tree_index());
3128 EXPECT_FLOAT_EQ(active_scrollbar_layer->Opacity(), 3128 EXPECT_FLOAT_EQ(active_scrollbar_layer->Opacity(),
3129 active_tree_node->opacity); 3129 active_tree_node->opacity);
3130 3130
3131 if (expecting_animations) { 3131 if (expecting_animations) {
3132 host_impl_->ScrollbarAnimationControllerForId(scroll->id()) 3132 host_impl_->ScrollbarAnimationControllerForElementId(scroll->element_id())
3133 ->DidMouseMoveNear(VERTICAL, 0); 3133 ->DidMouseMoveNear(VERTICAL, 0);
3134 } else { 3134 } else {
3135 EXPECT_EQ(nullptr, 3135 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForElementId(
3136 host_impl_->ScrollbarAnimationControllerForId(scroll->id())); 3136 scroll->element_id()));
3137 } 3137 }
3138 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), 3138 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(),
3139 InputHandler::WHEEL); 3139 InputHandler::WHEEL);
3140 host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2dF(0, 5)).get()); 3140 host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2dF(0, 5)).get());
3141 host_impl_->ScrollEnd(EndState().get()); 3141 host_impl_->ScrollEnd(EndState().get());
3142 host_impl_->CreatePendingTree(); 3142 host_impl_->CreatePendingTree();
3143 // To test the case where the effect tree index of scrollbar layer changes, 3143 // To test the case where the effect tree index of scrollbar layer changes,
3144 // we force the container layer to create a render surface. 3144 // we force the container layer to create a render surface.
3145 container = host_impl_->pending_tree()->InnerViewportContainerLayer(); 3145 container = host_impl_->pending_tree()->InnerViewportContainerLayer();
3146 container->test_properties()->force_render_surface = true; 3146 container->test_properties()->force_render_surface = true;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3201 CreateHostImpl(settings, CreateCompositorFrameSink()); 3201 CreateHostImpl(settings, CreateCompositorFrameSink());
3202 host_impl_->CreatePendingTree(); 3202 host_impl_->CreatePendingTree();
3203 CreateScrollAndContentsLayers(host_impl_->pending_tree(), content_size); 3203 CreateScrollAndContentsLayers(host_impl_->pending_tree(), content_size);
3204 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = 3204 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
3205 SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400, 3205 SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400,
3206 VERTICAL, 10, 0, false, true); 3206 VERTICAL, 10, 0, false, true);
3207 scrollbar->test_properties()->opacity = 0.f; 3207 scrollbar->test_properties()->opacity = 0.f;
3208 LayerImpl* scroll = host_impl_->pending_tree()->OuterViewportScrollLayer(); 3208 LayerImpl* scroll = host_impl_->pending_tree()->OuterViewportScrollLayer();
3209 LayerImpl* container = 3209 LayerImpl* container =
3210 host_impl_->pending_tree()->InnerViewportContainerLayer(); 3210 host_impl_->pending_tree()->InnerViewportContainerLayer();
3211 scrollbar->SetScrollLayerId(scroll->id()); 3211 scrollbar->SetScrollInfo(scroll->id(), scroll->element_id());
3212 container->test_properties()->AddChild(std::move(scrollbar)); 3212 container->test_properties()->AddChild(std::move(scrollbar));
3213 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); 3213 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f);
3214 host_impl_->pending_tree()->BuildPropertyTreesForTesting(); 3214 host_impl_->pending_tree()->BuildPropertyTreesForTesting();
3215 host_impl_->ActivateSyncTree(); 3215 host_impl_->ActivateSyncTree();
3216 3216
3217 ScrollbarAnimationController* scrollbar_controller = 3217 ScrollbarAnimationController* scrollbar_controller =
3218 host_impl_->ScrollbarAnimationControllerForId(scroll->id()); 3218 host_impl_->ScrollbarAnimationControllerForElementId(
3219 scroll->element_id());
3219 3220
3220 // Scrollbars will flash shown but we should have a fade out animation 3221 // Scrollbars will flash shown but we should have a fade out animation
3221 // queued. Run it and fade out the scrollbars. 3222 // queued. Run it and fade out the scrollbars.
3222 { 3223 {
3223 ASSERT_FALSE(animation_task_.Equals(base::Closure())); 3224 ASSERT_FALSE(animation_task_.Equals(base::Closure()));
3224 ASSERT_FALSE(animation_task_.IsCancelled()); 3225 ASSERT_FALSE(animation_task_.IsCancelled());
3225 animation_task_.Run(); 3226 animation_task_.Run();
3226 3227
3227 base::TimeTicks fake_now = base::TimeTicks::Now(); 3228 base::TimeTicks fake_now = base::TimeTicks::Now();
3228 scrollbar_controller->Animate(fake_now); 3229 scrollbar_controller->Animate(fake_now);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3276 std::unique_ptr<SolidColorScrollbarLayerImpl> horiz_scrollbar = 3277 std::unique_ptr<SolidColorScrollbarLayerImpl> horiz_scrollbar =
3277 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), horiz_id, 3278 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), horiz_id,
3278 HORIZONTAL, 5, 5, true, true); 3279 HORIZONTAL, 5, 5, true, true);
3279 std::unique_ptr<LayerImpl> child = 3280 std::unique_ptr<LayerImpl> child =
3280 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); 3281 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id);
3281 child->SetBounds(content_size); 3282 child->SetBounds(content_size);
3282 std::unique_ptr<LayerImpl> child_clip = 3283 std::unique_ptr<LayerImpl> child_clip =
3283 LayerImpl::Create(host_impl_->active_tree(), child_clip_id); 3284 LayerImpl::Create(host_impl_->active_tree(), child_clip_id);
3284 child->SetBounds(inner_viewport_size); 3285 child->SetBounds(inner_viewport_size);
3285 3286
3286 horiz_scrollbar->SetScrollLayerId(root_scroll->id()); 3287 horiz_scrollbar->SetScrollInfo(root_scroll->id(), root_scroll->element_id());
3287 3288
3288 EXPECT_EQ(300, horiz_scrollbar->clip_layer_length()); 3289 EXPECT_EQ(300, horiz_scrollbar->clip_layer_length());
3289 } 3290 }
3290 3291
3291 TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) { 3292 TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) {
3292 LayerTreeSettings settings = DefaultSettings(); 3293 LayerTreeSettings settings = DefaultSettings();
3293 settings.scrollbar_animator = LayerTreeSettings::ANDROID_OVERLAY; 3294 settings.scrollbar_animator = LayerTreeSettings::ANDROID_OVERLAY;
3294 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20); 3295 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20);
3295 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20); 3296 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20);
3296 settings.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(20); 3297 settings.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(20);
(...skipping 30 matching lines...) Expand all
3327 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); 3328 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id);
3328 child->SetBounds(content_size); 3329 child->SetBounds(content_size);
3329 std::unique_ptr<LayerImpl> child_clip = 3330 std::unique_ptr<LayerImpl> child_clip =
3330 LayerImpl::Create(host_impl_->active_tree(), child_clip_id); 3331 LayerImpl::Create(host_impl_->active_tree(), child_clip_id);
3331 child->SetBounds(viewport_size); 3332 child->SetBounds(viewport_size);
3332 LayerImpl* child_ptr = child.get(); 3333 LayerImpl* child_ptr = child.get();
3333 LayerImpl* child_clip_ptr = child_clip.get(); 3334 LayerImpl* child_clip_ptr = child_clip.get();
3334 3335
3335 // Check scrollbar registration on the viewport layers. 3336 // Check scrollbar registration on the viewport layers.
3336 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); 3337 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size());
3337 EXPECT_EQ(nullptr, 3338 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForElementId(
3338 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3339 root_scroll->element_id()));
3339 vert_1_scrollbar->SetScrollLayerId(root_scroll->id()); 3340 vert_1_scrollbar->SetScrollInfo(root_scroll->id(), root_scroll->element_id());
3340 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); 3341 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size());
3341 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3342 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId(
3342 horiz_1_scrollbar->SetScrollLayerId(root_scroll->id()); 3343 root_scroll->element_id()));
3344 horiz_1_scrollbar->SetScrollInfo(root_scroll->id(),
3345 root_scroll->element_id());
3343 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); 3346 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(root_scroll->id()).size());
3344 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3347 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId(
3348 root_scroll->element_id()));
3345 3349
3346 // Changing one of the viewport layers should result in a scrollbar animation 3350 // Changing one of the viewport layers should result in a scrollbar animation
3347 // update. 3351 // update.
3348 animation_task_ = base::Closure(); 3352 animation_task_ = base::Closure();
3349 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBoundsDelta( 3353 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBoundsDelta(
3350 gfx::Vector2dF(10, 10)); 3354 gfx::Vector2dF(10, 10));
3351 EXPECT_FALSE(animation_task_.Equals(base::Closure())); 3355 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
3352 animation_task_ = base::Closure(); 3356 animation_task_ = base::Closure();
3353 host_impl_->active_tree()->OuterViewportScrollLayer()->SetCurrentScrollOffset( 3357 host_impl_->active_tree()->OuterViewportScrollLayer()->SetCurrentScrollOffset(
3354 gfx::ScrollOffset(10, 10)); 3358 gfx::ScrollOffset(10, 10));
3355 EXPECT_FALSE(animation_task_.Equals(base::Closure())); 3359 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
3356 animation_task_ = base::Closure(); 3360 animation_task_ = base::Closure();
3357 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( 3361 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset(
3358 gfx::ScrollOffset(10, 10)); 3362 gfx::ScrollOffset(10, 10));
3359 EXPECT_FALSE(animation_task_.Equals(base::Closure())); 3363 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
3360 animation_task_ = base::Closure(); 3364 animation_task_ = base::Closure();
3361 3365
3362 // Check scrollbar registration on a sublayer. 3366 // Check scrollbar registration on a sublayer.
3363 child->SetScrollClipLayer(child_clip->id()); 3367 child->SetScrollClipLayer(child_clip->id());
3364 child->SetElementId(LayerIdToElementIdForTesting(child->id())); 3368 child->SetElementId(LayerIdToElementIdForTesting(child->id()));
3369 ElementId child_scroll_element_id = child->element_id();
3365 child_clip->test_properties()->AddChild(std::move(child)); 3370 child_clip->test_properties()->AddChild(std::move(child));
3366 root_scroll->test_properties()->AddChild(std::move(child_clip)); 3371 root_scroll->test_properties()->AddChild(std::move(child_clip));
3367 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3372 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3368 EXPECT_EQ(nullptr, 3373 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForElementId(
3369 host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); 3374 child_scroll_element_id));
3370 vert_2_scrollbar->SetScrollLayerId(child_scroll_id); 3375 vert_2_scrollbar->SetScrollInfo(child_scroll_id, child_scroll_element_id);
3371 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3376 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3372 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); 3377 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId(
3373 horiz_2_scrollbar->SetScrollLayerId(child_scroll_id); 3378 child_scroll_element_id));
3379 horiz_2_scrollbar->SetScrollInfo(child_scroll_id, child_scroll_element_id);
3374 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3380 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3375 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); 3381 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId(
3382 child_scroll_element_id));
3376 3383
3377 // Changing one of the child layers should result in a scrollbar animation 3384 // Changing one of the child layers should result in a scrollbar animation
3378 // update. 3385 // update.
3379 animation_task_ = base::Closure(); 3386 animation_task_ = base::Closure();
3380 child_clip_ptr->SetBounds(gfx::Size(200, 200)); 3387 child_clip_ptr->SetBounds(gfx::Size(200, 200));
3381 EXPECT_FALSE(animation_task_.Equals(base::Closure())); 3388 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
3382 animation_task_ = base::Closure(); 3389 animation_task_ = base::Closure();
3383 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(10, 10)); 3390 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(10, 10));
3384 EXPECT_FALSE(animation_task_.Equals(base::Closure())); 3391 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
3385 animation_task_ = base::Closure(); 3392 animation_task_ = base::Closure();
3386 3393
3387 // Check scrollbar unregistration. 3394 // Check scrollbar unregistration.
3388 vert_1_scrollbar.reset(); 3395 vert_1_scrollbar.reset();
3389 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); 3396 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size());
3390 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3397 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId(
3398 root_scroll->element_id()));
3391 horiz_1_scrollbar.reset(); 3399 horiz_1_scrollbar.reset();
3392 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); 3400 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size());
3393 EXPECT_EQ(nullptr, 3401 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForElementId(
3394 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3402 root_scroll->element_id()));
3395 3403
3396 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3404 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3397 vert_2_scrollbar.reset(); 3405 vert_2_scrollbar.reset();
3398 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3406 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3399 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); 3407 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId(
3408 child_scroll_element_id));
3400 horiz_2_scrollbar.reset(); 3409 horiz_2_scrollbar.reset();
3401 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3410 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3402 EXPECT_EQ(nullptr, 3411 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForElementId(
3403 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3412 root_scroll->element_id()));
3404 3413
3405 // Changing scroll offset should no longer trigger any animation. 3414 // Changing scroll offset should no longer trigger any animation.
3406 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( 3415 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset(
3407 gfx::ScrollOffset(20, 20)); 3416 gfx::ScrollOffset(20, 20));
3408 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 3417 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
3409 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(20, 20)); 3418 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(20, 20));
3410 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 3419 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
3411 } 3420 }
3412 3421
3413 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( 3422 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
(...skipping 16 matching lines...) Expand all
3430 3439
3431 CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); 3440 CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size);
3432 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( 3441 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds(
3433 viewport_size); 3442 viewport_size);
3434 LayerImpl* root_scroll = 3443 LayerImpl* root_scroll =
3435 host_impl_->active_tree()->OuterViewportScrollLayer(); 3444 host_impl_->active_tree()->OuterViewportScrollLayer();
3436 // The scrollbar is on the left side. 3445 // The scrollbar is on the left side.
3437 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = 3446 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
3438 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 6, 3447 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 6,
3439 VERTICAL, 5, 5, true, true); 3448 VERTICAL, 5, 5, true, true);
3440 scrollbar->SetScrollLayerId(root_scroll->id()); 3449 scrollbar->SetScrollInfo(root_scroll->id(), root_scroll->element_id());
3441 scrollbar->SetDrawsContent(true); 3450 scrollbar->SetDrawsContent(true);
3442 scrollbar->SetBounds(scrollbar_size); 3451 scrollbar->SetBounds(scrollbar_size);
3443 scrollbar->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size)); 3452 scrollbar->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size));
3444 host_impl_->active_tree() 3453 host_impl_->active_tree()
3445 ->InnerViewportContainerLayer() 3454 ->InnerViewportContainerLayer()
3446 ->test_properties() 3455 ->test_properties()
3447 ->AddChild(std::move(scrollbar)); 3456 ->AddChild(std::move(scrollbar));
3448 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 3457 host_impl_->active_tree()->BuildPropertyTreesForTesting();
3449 host_impl_->active_tree()->DidBecomeActive(); 3458 host_impl_->active_tree()->DidBecomeActive();
3450 3459
3451 DrawFrame(); 3460 DrawFrame();
3452 host_impl_->active_tree()->UpdateDrawProperties(false); 3461 host_impl_->active_tree()->UpdateDrawProperties(false);
3453 3462
3454 ScrollbarAnimationController* scrollbar_animation_controller = 3463 ScrollbarAnimationController* scrollbar_animation_controller =
3455 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id()); 3464 host_impl_->ScrollbarAnimationControllerForElementId(
3465 root_scroll->element_id());
3456 3466
3457 const float kMouseDistanceToTriggerAnimation = 3467 const float kMouseDistanceToTriggerAnimation =
3458 SingleScrollbarAnimationControllerThinning:: 3468 SingleScrollbarAnimationControllerThinning::
3459 kDefaultMouseMoveDistanceToTriggerAnimation; 3469 kDefaultMouseMoveDistanceToTriggerAnimation;
3460 3470
3461 host_impl_->MouseMoveAt( 3471 host_impl_->MouseMoveAt(
3462 gfx::Point(15 + kMouseDistanceToTriggerAnimation * 2, 1)); 3472 gfx::Point(15 + kMouseDistanceToTriggerAnimation * 2, 1));
3463 EXPECT_FALSE(scrollbar_animation_controller->MouseIsNearScrollbar(VERTICAL)); 3473 EXPECT_FALSE(scrollbar_animation_controller->MouseIsNearScrollbar(VERTICAL));
3464 3474
3465 host_impl_->MouseMoveAt( 3475 host_impl_->MouseMoveAt(
(...skipping 8603 matching lines...) Expand 10 before | Expand all | Expand 10 after
12069 if (main_thread_scrolling) { 12079 if (main_thread_scrolling) {
12070 root_scroll->set_main_thread_scrolling_reasons( 12080 root_scroll->set_main_thread_scrolling_reasons(
12071 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); 12081 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
12072 } 12082 }
12073 12083
12074 // scrollbar_1 on root scroll. 12084 // scrollbar_1 on root scroll.
12075 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar_1 = 12085 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar_1 =
12076 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 12086 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(),
12077 scrollbar_1_id, VERTICAL, 5, 5, true, 12087 scrollbar_1_id, VERTICAL, 5, 5, true,
12078 true); 12088 true);
12079 scrollbar_1->SetScrollLayerId(root_scroll->id()); 12089 scrollbar_1->SetScrollInfo(root_scroll->id(), root_scroll->element_id());
12080 scrollbar_1->SetDrawsContent(true); 12090 scrollbar_1->SetDrawsContent(true);
12081 scrollbar_1->SetBounds(scrollbar_size_1); 12091 scrollbar_1->SetBounds(scrollbar_size_1);
12082 scrollbar_1->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size_1)); 12092 scrollbar_1->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size_1));
12083 host_impl_->active_tree() 12093 host_impl_->active_tree()
12084 ->InnerViewportContainerLayer() 12094 ->InnerViewportContainerLayer()
12085 ->test_properties() 12095 ->test_properties()
12086 ->AddChild(std::move(scrollbar_1)); 12096 ->AddChild(std::move(scrollbar_1));
12087 12097
12088 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 12098 host_impl_->active_tree()->BuildPropertyTreesForTesting();
12089 host_impl_->active_tree()->DidBecomeActive(); 12099 host_impl_->active_tree()->DidBecomeActive();
12090 12100
12091 DrawFrame(); 12101 DrawFrame();
12092 host_impl_->active_tree()->UpdateDrawProperties(false); 12102 host_impl_->active_tree()->UpdateDrawProperties(false);
12093 12103
12094 ScrollbarAnimationController* scrollbar_1_animation_controller = 12104 ScrollbarAnimationController* scrollbar_1_animation_controller =
12095 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id()); 12105 host_impl_->ScrollbarAnimationControllerForElementId(
12106 root_scroll->element_id());
12096 EXPECT_TRUE(scrollbar_1_animation_controller); 12107 EXPECT_TRUE(scrollbar_1_animation_controller);
12097 12108
12098 const float kMouseDistanceToTriggerAnimation = 12109 const float kMouseDistanceToTriggerAnimation =
12099 SingleScrollbarAnimationControllerThinning:: 12110 SingleScrollbarAnimationControllerThinning::
12100 kDefaultMouseMoveDistanceToTriggerAnimation; 12111 kDefaultMouseMoveDistanceToTriggerAnimation;
12101 12112
12102 // Mouse moves close to the scrollbar, goes over the scrollbar, and 12113 // Mouse moves close to the scrollbar, goes over the scrollbar, and
12103 // moves back to where it was. 12114 // moves back to where it was.
12104 host_impl_->MouseMoveAt( 12115 host_impl_->MouseMoveAt(
12105 gfx::Point(15 + kMouseDistanceToTriggerAnimation, 150)); 12116 gfx::Point(15 + kMouseDistanceToTriggerAnimation, 150));
(...skipping 28 matching lines...) Expand all
12134 true); 12145 true);
12135 std::unique_ptr<LayerImpl> child_clip = 12146 std::unique_ptr<LayerImpl> child_clip =
12136 LayerImpl::Create(host_impl_->active_tree(), child_clip_id); 12147 LayerImpl::Create(host_impl_->active_tree(), child_clip_id);
12137 std::unique_ptr<LayerImpl> child = 12148 std::unique_ptr<LayerImpl> child =
12138 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); 12149 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id);
12139 child->SetPosition(gfx::PointF(50, 50)); 12150 child->SetPosition(gfx::PointF(50, 50));
12140 child->SetBounds(child_layer_size); 12151 child->SetBounds(child_layer_size);
12141 child->SetDrawsContent(true); 12152 child->SetDrawsContent(true);
12142 child->SetScrollClipLayer(child_clip_id); 12153 child->SetScrollClipLayer(child_clip_id);
12143 child->SetElementId(LayerIdToElementIdForTesting(child->id())); 12154 child->SetElementId(LayerIdToElementIdForTesting(child->id()));
12155 ElementId child_element_id = child->element_id();
12144 12156
12145 if (main_thread_scrolling) { 12157 if (main_thread_scrolling) {
12146 child->set_main_thread_scrolling_reasons( 12158 child->set_main_thread_scrolling_reasons(
12147 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); 12159 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
12148 } 12160 }
12149 12161
12150 scrollbar_2->SetScrollLayerId(child_scroll_id); 12162 scrollbar_2->SetScrollInfo(child_scroll_id, child_element_id);
12151 scrollbar_2->SetDrawsContent(true); 12163 scrollbar_2->SetDrawsContent(true);
12152 scrollbar_2->SetBounds(scrollbar_size_2); 12164 scrollbar_2->SetBounds(scrollbar_size_2);
12153 12165
12154 child->test_properties()->AddChild(std::move(scrollbar_2)); 12166 child->test_properties()->AddChild(std::move(scrollbar_2));
12155 child_clip->test_properties()->AddChild(std::move(child)); 12167 child_clip->test_properties()->AddChild(std::move(child));
12156 root_scroll->test_properties()->AddChild(std::move(child_clip)); 12168 root_scroll->test_properties()->AddChild(std::move(child_clip));
12157 12169
12158 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 12170 host_impl_->active_tree()->BuildPropertyTreesForTesting();
12159 host_impl_->active_tree()->DidBecomeActive(); 12171 host_impl_->active_tree()->DidBecomeActive();
12160 12172
12161 ScrollbarAnimationController* scrollbar_2_animation_controller = 12173 ScrollbarAnimationController* scrollbar_2_animation_controller =
12162 host_impl_->ScrollbarAnimationControllerForId(child_scroll_id); 12174 host_impl_->ScrollbarAnimationControllerForElementId(child_element_id);
12163 EXPECT_TRUE(scrollbar_2_animation_controller); 12175 EXPECT_TRUE(scrollbar_2_animation_controller);
12164 12176
12165 // Mouse goes over scrollbar_2, moves close to scrollbar_2, moves close to 12177 // Mouse goes over scrollbar_2, moves close to scrollbar_2, moves close to
12166 // scrollbar_1, goes over scrollbar_1. 12178 // scrollbar_1, goes over scrollbar_1.
12167 host_impl_->MouseMoveAt(gfx::Point(60, 150)); 12179 host_impl_->MouseMoveAt(gfx::Point(60, 150));
12168 EXPECT_FALSE( 12180 EXPECT_FALSE(
12169 scrollbar_1_animation_controller->MouseIsNearScrollbar(VERTICAL)); 12181 scrollbar_1_animation_controller->MouseIsNearScrollbar(VERTICAL));
12170 EXPECT_FALSE( 12182 EXPECT_FALSE(
12171 scrollbar_1_animation_controller->MouseIsOverScrollbar(VERTICAL)); 12183 scrollbar_1_animation_controller->MouseIsOverScrollbar(VERTICAL));
12172 EXPECT_TRUE(scrollbar_2_animation_controller->MouseIsNearScrollbar(VERTICAL)); 12184 EXPECT_TRUE(scrollbar_2_animation_controller->MouseIsNearScrollbar(VERTICAL));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
12213 animation_task_ = base::Closure(); 12225 animation_task_ = base::Closure();
12214 12226
12215 host_impl_->MouseDown(); 12227 host_impl_->MouseDown();
12216 host_impl_->MouseUp(); 12228 host_impl_->MouseUp();
12217 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 12229 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
12218 12230
12219 // Near scrollbar_1, then mouse down and unregister 12231 // Near scrollbar_1, then mouse down and unregister
12220 // scrollbar_2_animation_controller, then mouse up should not cause crash. 12232 // scrollbar_2_animation_controller, then mouse up should not cause crash.
12221 host_impl_->MouseMoveAt(gfx::Point(40, 150)); 12233 host_impl_->MouseMoveAt(gfx::Point(40, 150));
12222 host_impl_->MouseDown(); 12234 host_impl_->MouseDown();
12223 host_impl_->UnregisterScrollbarAnimationController(root_scroll->id()); 12235 host_impl_->UnregisterScrollbarAnimationController(root_scroll->element_id());
12224 host_impl_->MouseUp(); 12236 host_impl_->MouseUp();
12225 } 12237 }
12226 12238
12227 TEST_F(LayerTreeHostImplTest, 12239 TEST_F(LayerTreeHostImplTest,
12228 LayerTreeHostImplTestScrollbarStatesInMainThreadScorlling) { 12240 LayerTreeHostImplTestScrollbarStatesInMainThreadScrolling) {
12229 SetupMouseMoveAtTestScrollbarStates(true); 12241 SetupMouseMoveAtTestScrollbarStates(true);
12230 } 12242 }
12231 12243
12232 TEST_F(LayerTreeHostImplTest, 12244 TEST_F(LayerTreeHostImplTest,
12233 LayerTreeHostImplTestScrollbarStatesInNotMainThreadScorlling) { 12245 LayerTreeHostImplTestScrollbarStatesInNotMainThreadScrolling) {
12234 SetupMouseMoveAtTestScrollbarStates(false); 12246 SetupMouseMoveAtTestScrollbarStates(false);
12235 } 12247 }
12236 12248
12237 TEST_F(LayerTreeHostImplTest, CheckerImagingTileInvalidation) { 12249 TEST_F(LayerTreeHostImplTest, CheckerImagingTileInvalidation) {
12238 LayerTreeSettings settings = DefaultSettings(); 12250 LayerTreeSettings settings = DefaultSettings();
12239 settings.enable_checker_imaging = true; 12251 settings.enable_checker_imaging = true;
12240 settings.default_tile_size = gfx::Size(256, 256); 12252 settings.default_tile_size = gfx::Size(256, 256);
12241 settings.max_untiled_layer_size = gfx::Size(256, 256); 12253 settings.max_untiled_layer_size = gfx::Size(256, 256);
12242 CreateHostImpl(settings, CreateCompositorFrameSink()); 12254 CreateHostImpl(settings, CreateCompositorFrameSink());
12243 gfx::Size layer_size = gfx::Size(750, 750); 12255 gfx::Size layer_size = gfx::Size(750, 750);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
12305 else 12317 else
12306 EXPECT_FALSE(tile->HasRasterTask()); 12318 EXPECT_FALSE(tile->HasRasterTask());
12307 } 12319 }
12308 Region expected_invalidation( 12320 Region expected_invalidation(
12309 raster_source->GetRectForImage(checkerable_image->uniqueID())); 12321 raster_source->GetRectForImage(checkerable_image->uniqueID()));
12310 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); 12322 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation()));
12311 } 12323 }
12312 12324
12313 } // namespace 12325 } // namespace
12314 } // namespace cc 12326 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698