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

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: Update element_id comment, some cleanups per reviewer comments 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 8596 matching lines...) Expand 10 before | Expand all | Expand 10 after
12062 if (main_thread_scrolling) { 12072 if (main_thread_scrolling) {
12063 root_scroll->set_main_thread_scrolling_reasons( 12073 root_scroll->set_main_thread_scrolling_reasons(
12064 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); 12074 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
12065 } 12075 }
12066 12076
12067 // scrollbar_1 on root scroll. 12077 // scrollbar_1 on root scroll.
12068 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar_1 = 12078 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar_1 =
12069 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 12079 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(),
12070 scrollbar_1_id, VERTICAL, 5, 5, true, 12080 scrollbar_1_id, VERTICAL, 5, 5, true,
12071 true); 12081 true);
12072 scrollbar_1->SetScrollLayerId(root_scroll->id()); 12082 scrollbar_1->SetScrollInfo(root_scroll->id(), root_scroll->element_id());
12073 scrollbar_1->SetDrawsContent(true); 12083 scrollbar_1->SetDrawsContent(true);
12074 scrollbar_1->SetBounds(scrollbar_size_1); 12084 scrollbar_1->SetBounds(scrollbar_size_1);
12075 scrollbar_1->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size_1)); 12085 scrollbar_1->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size_1));
12076 host_impl_->active_tree() 12086 host_impl_->active_tree()
12077 ->InnerViewportContainerLayer() 12087 ->InnerViewportContainerLayer()
12078 ->test_properties() 12088 ->test_properties()
12079 ->AddChild(std::move(scrollbar_1)); 12089 ->AddChild(std::move(scrollbar_1));
12080 12090
12081 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 12091 host_impl_->active_tree()->BuildPropertyTreesForTesting();
12082 host_impl_->active_tree()->DidBecomeActive(); 12092 host_impl_->active_tree()->DidBecomeActive();
12083 12093
12084 DrawFrame(); 12094 DrawFrame();
12085 host_impl_->active_tree()->UpdateDrawProperties(false); 12095 host_impl_->active_tree()->UpdateDrawProperties(false);
12086 12096
12087 ScrollbarAnimationController* scrollbar_1_animation_controller = 12097 ScrollbarAnimationController* scrollbar_1_animation_controller =
12088 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id()); 12098 host_impl_->ScrollbarAnimationControllerForElementId(
12099 root_scroll->element_id());
12089 EXPECT_TRUE(scrollbar_1_animation_controller); 12100 EXPECT_TRUE(scrollbar_1_animation_controller);
12090 12101
12091 const float kMouseDistanceToTriggerAnimation = 12102 const float kMouseDistanceToTriggerAnimation =
12092 SingleScrollbarAnimationControllerThinning:: 12103 SingleScrollbarAnimationControllerThinning::
12093 kDefaultMouseMoveDistanceToTriggerAnimation; 12104 kDefaultMouseMoveDistanceToTriggerAnimation;
12094 12105
12095 // Mouse moves close to the scrollbar, goes over the scrollbar, and 12106 // Mouse moves close to the scrollbar, goes over the scrollbar, and
12096 // moves back to where it was. 12107 // moves back to where it was.
12097 host_impl_->MouseMoveAt( 12108 host_impl_->MouseMoveAt(
12098 gfx::Point(15 + kMouseDistanceToTriggerAnimation, 150)); 12109 gfx::Point(15 + kMouseDistanceToTriggerAnimation, 150));
(...skipping 28 matching lines...) Expand all
12127 true); 12138 true);
12128 std::unique_ptr<LayerImpl> child_clip = 12139 std::unique_ptr<LayerImpl> child_clip =
12129 LayerImpl::Create(host_impl_->active_tree(), child_clip_id); 12140 LayerImpl::Create(host_impl_->active_tree(), child_clip_id);
12130 std::unique_ptr<LayerImpl> child = 12141 std::unique_ptr<LayerImpl> child =
12131 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); 12142 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id);
12132 child->SetPosition(gfx::PointF(50, 50)); 12143 child->SetPosition(gfx::PointF(50, 50));
12133 child->SetBounds(child_layer_size); 12144 child->SetBounds(child_layer_size);
12134 child->SetDrawsContent(true); 12145 child->SetDrawsContent(true);
12135 child->SetScrollClipLayer(child_clip_id); 12146 child->SetScrollClipLayer(child_clip_id);
12136 child->SetElementId(LayerIdToElementIdForTesting(child->id())); 12147 child->SetElementId(LayerIdToElementIdForTesting(child->id()));
12148 ElementId child_element_id = child->element_id();
12137 12149
12138 if (main_thread_scrolling) { 12150 if (main_thread_scrolling) {
12139 child->set_main_thread_scrolling_reasons( 12151 child->set_main_thread_scrolling_reasons(
12140 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); 12152 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
12141 } 12153 }
12142 12154
12143 scrollbar_2->SetScrollLayerId(child_scroll_id); 12155 scrollbar_2->SetScrollInfo(child_scroll_id, child_element_id);
12144 scrollbar_2->SetDrawsContent(true); 12156 scrollbar_2->SetDrawsContent(true);
12145 scrollbar_2->SetBounds(scrollbar_size_2); 12157 scrollbar_2->SetBounds(scrollbar_size_2);
12146 12158
12147 child->test_properties()->AddChild(std::move(scrollbar_2)); 12159 child->test_properties()->AddChild(std::move(scrollbar_2));
12148 child_clip->test_properties()->AddChild(std::move(child)); 12160 child_clip->test_properties()->AddChild(std::move(child));
12149 root_scroll->test_properties()->AddChild(std::move(child_clip)); 12161 root_scroll->test_properties()->AddChild(std::move(child_clip));
12150 12162
12151 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 12163 host_impl_->active_tree()->BuildPropertyTreesForTesting();
12152 host_impl_->active_tree()->DidBecomeActive(); 12164 host_impl_->active_tree()->DidBecomeActive();
12153 12165
12154 ScrollbarAnimationController* scrollbar_2_animation_controller = 12166 ScrollbarAnimationController* scrollbar_2_animation_controller =
12155 host_impl_->ScrollbarAnimationControllerForId(child_scroll_id); 12167 host_impl_->ScrollbarAnimationControllerForElementId(child_element_id);
12156 EXPECT_TRUE(scrollbar_2_animation_controller); 12168 EXPECT_TRUE(scrollbar_2_animation_controller);
12157 12169
12158 // Mouse goes over scrollbar_2, moves close to scrollbar_2, moves close to 12170 // Mouse goes over scrollbar_2, moves close to scrollbar_2, moves close to
12159 // scrollbar_1, goes over scrollbar_1. 12171 // scrollbar_1, goes over scrollbar_1.
12160 host_impl_->MouseMoveAt(gfx::Point(60, 150)); 12172 host_impl_->MouseMoveAt(gfx::Point(60, 150));
12161 EXPECT_FALSE( 12173 EXPECT_FALSE(
12162 scrollbar_1_animation_controller->MouseIsNearScrollbar(VERTICAL)); 12174 scrollbar_1_animation_controller->MouseIsNearScrollbar(VERTICAL));
12163 EXPECT_FALSE( 12175 EXPECT_FALSE(
12164 scrollbar_1_animation_controller->MouseIsOverScrollbar(VERTICAL)); 12176 scrollbar_1_animation_controller->MouseIsOverScrollbar(VERTICAL));
12165 EXPECT_TRUE(scrollbar_2_animation_controller->MouseIsNearScrollbar(VERTICAL)); 12177 EXPECT_TRUE(scrollbar_2_animation_controller->MouseIsNearScrollbar(VERTICAL));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
12206 animation_task_ = base::Closure(); 12218 animation_task_ = base::Closure();
12207 12219
12208 host_impl_->MouseDown(); 12220 host_impl_->MouseDown();
12209 host_impl_->MouseUp(); 12221 host_impl_->MouseUp();
12210 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 12222 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
12211 12223
12212 // Near scrollbar_1, then mouse down and unregister 12224 // Near scrollbar_1, then mouse down and unregister
12213 // scrollbar_2_animation_controller, then mouse up should not cause crash. 12225 // scrollbar_2_animation_controller, then mouse up should not cause crash.
12214 host_impl_->MouseMoveAt(gfx::Point(40, 150)); 12226 host_impl_->MouseMoveAt(gfx::Point(40, 150));
12215 host_impl_->MouseDown(); 12227 host_impl_->MouseDown();
12216 host_impl_->UnregisterScrollbarAnimationController(root_scroll->id()); 12228 host_impl_->UnregisterScrollbarAnimationController(root_scroll->element_id());
12217 host_impl_->MouseUp(); 12229 host_impl_->MouseUp();
12218 } 12230 }
12219 12231
12220 TEST_F(LayerTreeHostImplTest, 12232 TEST_F(LayerTreeHostImplTest,
12221 LayerTreeHostImplTestScrollbarStatesInMainThreadScorlling) { 12233 LayerTreeHostImplTestScrollbarStatesInMainThreadScrolling) {
12222 SetupMouseMoveAtTestScrollbarStates(true); 12234 SetupMouseMoveAtTestScrollbarStates(true);
12223 } 12235 }
12224 12236
12225 TEST_F(LayerTreeHostImplTest, 12237 TEST_F(LayerTreeHostImplTest,
12226 LayerTreeHostImplTestScrollbarStatesInNotMainThreadScorlling) { 12238 LayerTreeHostImplTestScrollbarStatesInNotMainThreadScrolling) {
12227 SetupMouseMoveAtTestScrollbarStates(false); 12239 SetupMouseMoveAtTestScrollbarStates(false);
12228 } 12240 }
12229 12241
12230 TEST_F(LayerTreeHostImplTest, CheckerImagingTileInvalidation) { 12242 TEST_F(LayerTreeHostImplTest, CheckerImagingTileInvalidation) {
12231 LayerTreeSettings settings = DefaultSettings(); 12243 LayerTreeSettings settings = DefaultSettings();
12232 settings.enable_checker_imaging = true; 12244 settings.enable_checker_imaging = true;
12233 settings.default_tile_size = gfx::Size(256, 256); 12245 settings.default_tile_size = gfx::Size(256, 256);
12234 settings.max_untiled_layer_size = gfx::Size(256, 256); 12246 settings.max_untiled_layer_size = gfx::Size(256, 256);
12235 CreateHostImpl(settings, CreateCompositorFrameSink()); 12247 CreateHostImpl(settings, CreateCompositorFrameSink());
12236 gfx::Size layer_size = gfx::Size(750, 750); 12248 gfx::Size layer_size = gfx::Size(750, 750);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
12298 else 12310 else
12299 EXPECT_FALSE(tile->HasRasterTask()); 12311 EXPECT_FALSE(tile->HasRasterTask());
12300 } 12312 }
12301 Region expected_invalidation( 12313 Region expected_invalidation(
12302 raster_source->GetRectForImage(checkerable_image->uniqueID())); 12314 raster_source->GetRectForImage(checkerable_image->uniqueID()));
12303 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); 12315 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation()));
12304 } 12316 }
12305 12317
12306 } // namespace 12318 } // namespace
12307 } // namespace cc 12319 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698