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

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: Fix flaky LayerTreeHostImplTestScrollbarOpacity.Android 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_->ScrollbarAnimationControllerForId(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_->ScrollbarAnimationControllerForId(
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_->ScrollbarAnimationControllerForId(scroll->element_id());
3219 3219
3220 // Scrollbars will flash shown but we should have a fade out animation 3220 // Scrollbars will flash shown but we should have a fade out animation
3221 // queued. Run it and fade out the scrollbars. 3221 // queued. Run it and fade out the scrollbars.
3222 { 3222 {
3223 ASSERT_FALSE(animation_task_.Equals(base::Closure())); 3223 ASSERT_FALSE(animation_task_.Equals(base::Closure()));
3224 ASSERT_FALSE(animation_task_.IsCancelled()); 3224 ASSERT_FALSE(animation_task_.IsCancelled());
3225 animation_task_.Run(); 3225 animation_task_.Run();
3226 3226
3227 base::TimeTicks fake_now = base::TimeTicks::Now(); 3227 base::TimeTicks fake_now = base::TimeTicks::Now();
3228 scrollbar_controller->Animate(fake_now); 3228 scrollbar_controller->Animate(fake_now);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3276 std::unique_ptr<SolidColorScrollbarLayerImpl> horiz_scrollbar = 3276 std::unique_ptr<SolidColorScrollbarLayerImpl> horiz_scrollbar =
3277 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), horiz_id, 3277 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), horiz_id,
3278 HORIZONTAL, 5, 5, true, true); 3278 HORIZONTAL, 5, 5, true, true);
3279 std::unique_ptr<LayerImpl> child = 3279 std::unique_ptr<LayerImpl> child =
3280 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); 3280 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id);
3281 child->SetBounds(content_size); 3281 child->SetBounds(content_size);
3282 std::unique_ptr<LayerImpl> child_clip = 3282 std::unique_ptr<LayerImpl> child_clip =
3283 LayerImpl::Create(host_impl_->active_tree(), child_clip_id); 3283 LayerImpl::Create(host_impl_->active_tree(), child_clip_id);
3284 child->SetBounds(inner_viewport_size); 3284 child->SetBounds(inner_viewport_size);
3285 3285
3286 horiz_scrollbar->SetScrollLayerId(root_scroll->id()); 3286 horiz_scrollbar->SetScrollInfo(root_scroll->id(), root_scroll->element_id());
3287 3287
3288 EXPECT_EQ(300, horiz_scrollbar->clip_layer_length()); 3288 EXPECT_EQ(300, horiz_scrollbar->clip_layer_length());
3289 } 3289 }
3290 3290
3291 TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) { 3291 TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) {
3292 LayerTreeSettings settings = DefaultSettings(); 3292 LayerTreeSettings settings = DefaultSettings();
3293 settings.scrollbar_animator = LayerTreeSettings::ANDROID_OVERLAY; 3293 settings.scrollbar_animator = LayerTreeSettings::ANDROID_OVERLAY;
3294 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20); 3294 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20);
3295 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20); 3295 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20);
3296 settings.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(20); 3296 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); 3327 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id);
3328 child->SetBounds(content_size); 3328 child->SetBounds(content_size);
3329 std::unique_ptr<LayerImpl> child_clip = 3329 std::unique_ptr<LayerImpl> child_clip =
3330 LayerImpl::Create(host_impl_->active_tree(), child_clip_id); 3330 LayerImpl::Create(host_impl_->active_tree(), child_clip_id);
3331 child->SetBounds(viewport_size); 3331 child->SetBounds(viewport_size);
3332 LayerImpl* child_ptr = child.get(); 3332 LayerImpl* child_ptr = child.get();
3333 LayerImpl* child_clip_ptr = child_clip.get(); 3333 LayerImpl* child_clip_ptr = child_clip.get();
3334 3334
3335 // Check scrollbar registration on the viewport layers. 3335 // Check scrollbar registration on the viewport layers.
3336 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); 3336 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size());
3337 EXPECT_EQ(nullptr, 3337 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForId(
3338 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3338 root_scroll->element_id()));
3339 vert_1_scrollbar->SetScrollLayerId(root_scroll->id()); 3339 vert_1_scrollbar->SetScrollInfo(root_scroll->id(), root_scroll->element_id());
3340 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); 3340 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size());
3341 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3341 EXPECT_TRUE(
3342 horiz_1_scrollbar->SetScrollLayerId(root_scroll->id()); 3342 host_impl_->ScrollbarAnimationControllerForId(root_scroll->element_id()));
3343 horiz_1_scrollbar->SetScrollInfo(root_scroll->id(),
3344 root_scroll->element_id());
3343 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); 3345 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(root_scroll->id()).size());
3344 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3346 EXPECT_TRUE(
3347 host_impl_->ScrollbarAnimationControllerForId(root_scroll->element_id()));
3345 3348
3346 // Changing one of the viewport layers should result in a scrollbar animation 3349 // Changing one of the viewport layers should result in a scrollbar animation
3347 // update. 3350 // update.
3348 animation_task_ = base::Closure(); 3351 animation_task_ = base::Closure();
3349 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBoundsDelta( 3352 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBoundsDelta(
3350 gfx::Vector2dF(10, 10)); 3353 gfx::Vector2dF(10, 10));
3351 EXPECT_FALSE(animation_task_.Equals(base::Closure())); 3354 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
3352 animation_task_ = base::Closure(); 3355 animation_task_ = base::Closure();
3353 host_impl_->active_tree()->OuterViewportScrollLayer()->SetCurrentScrollOffset( 3356 host_impl_->active_tree()->OuterViewportScrollLayer()->SetCurrentScrollOffset(
3354 gfx::ScrollOffset(10, 10)); 3357 gfx::ScrollOffset(10, 10));
3355 EXPECT_FALSE(animation_task_.Equals(base::Closure())); 3358 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
3356 animation_task_ = base::Closure(); 3359 animation_task_ = base::Closure();
3357 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( 3360 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset(
3358 gfx::ScrollOffset(10, 10)); 3361 gfx::ScrollOffset(10, 10));
3359 EXPECT_FALSE(animation_task_.Equals(base::Closure())); 3362 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
3360 animation_task_ = base::Closure(); 3363 animation_task_ = base::Closure();
3361 3364
3362 // Check scrollbar registration on a sublayer. 3365 // Check scrollbar registration on a sublayer.
3363 child->SetScrollClipLayer(child_clip->id()); 3366 child->SetScrollClipLayer(child_clip->id());
3364 child->SetElementId(LayerIdToElementIdForTesting(child->id())); 3367 child->SetElementId(LayerIdToElementIdForTesting(child->id()));
3368 ElementId child_scroll_element_id = child->element_id();
3365 child_clip->test_properties()->AddChild(std::move(child)); 3369 child_clip->test_properties()->AddChild(std::move(child));
3366 root_scroll->test_properties()->AddChild(std::move(child_clip)); 3370 root_scroll->test_properties()->AddChild(std::move(child_clip));
3367 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3371 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3368 EXPECT_EQ(nullptr, 3372 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForId(
3369 host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); 3373 child_scroll_element_id));
3370 vert_2_scrollbar->SetScrollLayerId(child_scroll_id); 3374 vert_2_scrollbar->SetScrollInfo(child_scroll_id, child_scroll_element_id);
3371 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3375 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3372 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); 3376 EXPECT_TRUE(
3373 horiz_2_scrollbar->SetScrollLayerId(child_scroll_id); 3377 host_impl_->ScrollbarAnimationControllerForId(child_scroll_element_id));
3378 horiz_2_scrollbar->SetScrollInfo(child_scroll_id, child_scroll_element_id);
3374 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3379 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3375 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); 3380 EXPECT_TRUE(
3381 host_impl_->ScrollbarAnimationControllerForId(child_scroll_element_id));
3376 3382
3377 // Changing one of the child layers should result in a scrollbar animation 3383 // Changing one of the child layers should result in a scrollbar animation
3378 // update. 3384 // update.
3379 animation_task_ = base::Closure(); 3385 animation_task_ = base::Closure();
3380 child_clip_ptr->SetBounds(gfx::Size(200, 200)); 3386 child_clip_ptr->SetBounds(gfx::Size(200, 200));
3381 EXPECT_FALSE(animation_task_.Equals(base::Closure())); 3387 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
3382 animation_task_ = base::Closure(); 3388 animation_task_ = base::Closure();
3383 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(10, 10)); 3389 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(10, 10));
3384 EXPECT_FALSE(animation_task_.Equals(base::Closure())); 3390 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
3385 animation_task_ = base::Closure(); 3391 animation_task_ = base::Closure();
3386 3392
3387 // Check scrollbar unregistration. 3393 // Check scrollbar unregistration.
3388 vert_1_scrollbar.reset(); 3394 vert_1_scrollbar.reset();
3389 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); 3395 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->id()).size());
3390 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3396 EXPECT_TRUE(
3397 host_impl_->ScrollbarAnimationControllerForId(root_scroll->element_id()));
3391 horiz_1_scrollbar.reset(); 3398 horiz_1_scrollbar.reset();
3392 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size()); 3399 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->id()).size());
3393 EXPECT_EQ(nullptr, 3400 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForId(
3394 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3401 root_scroll->element_id()));
3395 3402
3396 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3403 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3397 vert_2_scrollbar.reset(); 3404 vert_2_scrollbar.reset();
3398 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3405 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3399 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); 3406 EXPECT_TRUE(
3407 host_impl_->ScrollbarAnimationControllerForId(child_scroll_element_id));
3400 horiz_2_scrollbar.reset(); 3408 horiz_2_scrollbar.reset();
3401 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size()); 3409 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_id).size());
3402 EXPECT_EQ(nullptr, 3410 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForId(
3403 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); 3411 root_scroll->element_id()));
3404 3412
3405 // Changing scroll offset should no longer trigger any animation. 3413 // Changing scroll offset should no longer trigger any animation.
3406 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( 3414 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset(
3407 gfx::ScrollOffset(20, 20)); 3415 gfx::ScrollOffset(20, 20));
3408 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 3416 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
3409 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(20, 20)); 3417 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(20, 20));
3410 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 3418 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
3411 } 3419 }
3412 3420
3413 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( 3421 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
(...skipping 16 matching lines...) Expand all
3430 3438
3431 CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); 3439 CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size);
3432 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( 3440 host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds(
3433 viewport_size); 3441 viewport_size);
3434 LayerImpl* root_scroll = 3442 LayerImpl* root_scroll =
3435 host_impl_->active_tree()->OuterViewportScrollLayer(); 3443 host_impl_->active_tree()->OuterViewportScrollLayer();
3436 // The scrollbar is on the left side. 3444 // The scrollbar is on the left side.
3437 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = 3445 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
3438 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 6, 3446 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 6,
3439 VERTICAL, 5, 5, true, true); 3447 VERTICAL, 5, 5, true, true);
3440 scrollbar->SetScrollLayerId(root_scroll->id()); 3448 scrollbar->SetScrollInfo(root_scroll->id(), root_scroll->element_id());
3441 scrollbar->SetDrawsContent(true); 3449 scrollbar->SetDrawsContent(true);
3442 scrollbar->SetBounds(scrollbar_size); 3450 scrollbar->SetBounds(scrollbar_size);
3443 scrollbar->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size)); 3451 scrollbar->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size));
3444 host_impl_->active_tree() 3452 host_impl_->active_tree()
3445 ->InnerViewportContainerLayer() 3453 ->InnerViewportContainerLayer()
3446 ->test_properties() 3454 ->test_properties()
3447 ->AddChild(std::move(scrollbar)); 3455 ->AddChild(std::move(scrollbar));
3448 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 3456 host_impl_->active_tree()->BuildPropertyTreesForTesting();
3449 host_impl_->active_tree()->DidBecomeActive(); 3457 host_impl_->active_tree()->DidBecomeActive();
3450 3458
3451 DrawFrame(); 3459 DrawFrame();
3452 host_impl_->active_tree()->UpdateDrawProperties(false); 3460 host_impl_->active_tree()->UpdateDrawProperties(false);
3453 3461
3454 ScrollbarAnimationController* scrollbar_animation_controller = 3462 ScrollbarAnimationController* scrollbar_animation_controller =
3455 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id()); 3463 host_impl_->ScrollbarAnimationControllerForId(root_scroll->element_id());
3456 3464
3457 const float kMouseDistanceToTriggerAnimation = 3465 const float kMouseDistanceToTriggerAnimation =
3458 SingleScrollbarAnimationControllerThinning:: 3466 SingleScrollbarAnimationControllerThinning::
3459 kDefaultMouseMoveDistanceToTriggerAnimation; 3467 kDefaultMouseMoveDistanceToTriggerAnimation;
3460 3468
3461 host_impl_->MouseMoveAt( 3469 host_impl_->MouseMoveAt(
3462 gfx::Point(15 + kMouseDistanceToTriggerAnimation * 2, 1)); 3470 gfx::Point(15 + kMouseDistanceToTriggerAnimation * 2, 1));
3463 EXPECT_FALSE(scrollbar_animation_controller->MouseIsNearScrollbar(VERTICAL)); 3471 EXPECT_FALSE(scrollbar_animation_controller->MouseIsNearScrollbar(VERTICAL));
3464 3472
3465 host_impl_->MouseMoveAt( 3473 host_impl_->MouseMoveAt(
(...skipping 8594 matching lines...) Expand 10 before | Expand all | Expand 10 after
12060 if (main_thread_scrolling) { 12068 if (main_thread_scrolling) {
12061 root_scroll->set_main_thread_scrolling_reasons( 12069 root_scroll->set_main_thread_scrolling_reasons(
12062 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); 12070 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
12063 } 12071 }
12064 12072
12065 // scrollbar_1 on root scroll. 12073 // scrollbar_1 on root scroll.
12066 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar_1 = 12074 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar_1 =
12067 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 12075 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(),
12068 scrollbar_1_id, VERTICAL, 5, 5, true, 12076 scrollbar_1_id, VERTICAL, 5, 5, true,
12069 true); 12077 true);
12070 scrollbar_1->SetScrollLayerId(root_scroll->id()); 12078 scrollbar_1->SetScrollInfo(root_scroll->id(), root_scroll->element_id());
12071 scrollbar_1->SetDrawsContent(true); 12079 scrollbar_1->SetDrawsContent(true);
12072 scrollbar_1->SetBounds(scrollbar_size_1); 12080 scrollbar_1->SetBounds(scrollbar_size_1);
12073 scrollbar_1->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size_1)); 12081 scrollbar_1->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size_1));
12074 host_impl_->active_tree() 12082 host_impl_->active_tree()
12075 ->InnerViewportContainerLayer() 12083 ->InnerViewportContainerLayer()
12076 ->test_properties() 12084 ->test_properties()
12077 ->AddChild(std::move(scrollbar_1)); 12085 ->AddChild(std::move(scrollbar_1));
12078 12086
12079 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 12087 host_impl_->active_tree()->BuildPropertyTreesForTesting();
12080 host_impl_->active_tree()->DidBecomeActive(); 12088 host_impl_->active_tree()->DidBecomeActive();
12081 12089
12082 DrawFrame(); 12090 DrawFrame();
12083 host_impl_->active_tree()->UpdateDrawProperties(false); 12091 host_impl_->active_tree()->UpdateDrawProperties(false);
12084 12092
12085 ScrollbarAnimationController* scrollbar_1_animation_controller = 12093 ScrollbarAnimationController* scrollbar_1_animation_controller =
12086 host_impl_->ScrollbarAnimationControllerForId(root_scroll->id()); 12094 host_impl_->ScrollbarAnimationControllerForId(root_scroll->element_id());
12087 EXPECT_TRUE(scrollbar_1_animation_controller); 12095 EXPECT_TRUE(scrollbar_1_animation_controller);
12088 12096
12089 const float kMouseDistanceToTriggerAnimation = 12097 const float kMouseDistanceToTriggerAnimation =
12090 SingleScrollbarAnimationControllerThinning:: 12098 SingleScrollbarAnimationControllerThinning::
12091 kDefaultMouseMoveDistanceToTriggerAnimation; 12099 kDefaultMouseMoveDistanceToTriggerAnimation;
12092 12100
12093 // Mouse moves close to the scrollbar, goes over the scrollbar, and 12101 // Mouse moves close to the scrollbar, goes over the scrollbar, and
12094 // moves back to where it was. 12102 // moves back to where it was.
12095 host_impl_->MouseMoveAt( 12103 host_impl_->MouseMoveAt(
12096 gfx::Point(15 + kMouseDistanceToTriggerAnimation, 150)); 12104 gfx::Point(15 + kMouseDistanceToTriggerAnimation, 150));
(...skipping 28 matching lines...) Expand all
12125 true); 12133 true);
12126 std::unique_ptr<LayerImpl> child_clip = 12134 std::unique_ptr<LayerImpl> child_clip =
12127 LayerImpl::Create(host_impl_->active_tree(), child_clip_id); 12135 LayerImpl::Create(host_impl_->active_tree(), child_clip_id);
12128 std::unique_ptr<LayerImpl> child = 12136 std::unique_ptr<LayerImpl> child =
12129 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); 12137 LayerImpl::Create(host_impl_->active_tree(), child_scroll_id);
12130 child->SetPosition(gfx::PointF(50, 50)); 12138 child->SetPosition(gfx::PointF(50, 50));
12131 child->SetBounds(child_layer_size); 12139 child->SetBounds(child_layer_size);
12132 child->SetDrawsContent(true); 12140 child->SetDrawsContent(true);
12133 child->SetScrollClipLayer(child_clip_id); 12141 child->SetScrollClipLayer(child_clip_id);
12134 child->SetElementId(LayerIdToElementIdForTesting(child->id())); 12142 child->SetElementId(LayerIdToElementIdForTesting(child->id()));
12143 ElementId child_element_id = child->element_id();
12135 12144
12136 if (main_thread_scrolling) { 12145 if (main_thread_scrolling) {
12137 child->set_main_thread_scrolling_reasons( 12146 child->set_main_thread_scrolling_reasons(
12138 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); 12147 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
12139 } 12148 }
12140 12149
12141 scrollbar_2->SetScrollLayerId(child_scroll_id); 12150 scrollbar_2->SetScrollInfo(child_scroll_id, child_element_id);
12142 scrollbar_2->SetDrawsContent(true); 12151 scrollbar_2->SetDrawsContent(true);
12143 scrollbar_2->SetBounds(scrollbar_size_2); 12152 scrollbar_2->SetBounds(scrollbar_size_2);
12144 12153
12145 child->test_properties()->AddChild(std::move(scrollbar_2)); 12154 child->test_properties()->AddChild(std::move(scrollbar_2));
12146 child_clip->test_properties()->AddChild(std::move(child)); 12155 child_clip->test_properties()->AddChild(std::move(child));
12147 root_scroll->test_properties()->AddChild(std::move(child_clip)); 12156 root_scroll->test_properties()->AddChild(std::move(child_clip));
12148 12157
12149 host_impl_->active_tree()->BuildPropertyTreesForTesting(); 12158 host_impl_->active_tree()->BuildPropertyTreesForTesting();
12150 host_impl_->active_tree()->DidBecomeActive(); 12159 host_impl_->active_tree()->DidBecomeActive();
12151 12160
12152 ScrollbarAnimationController* scrollbar_2_animation_controller = 12161 ScrollbarAnimationController* scrollbar_2_animation_controller =
12153 host_impl_->ScrollbarAnimationControllerForId(child_scroll_id); 12162 host_impl_->ScrollbarAnimationControllerForId(child_element_id);
12154 EXPECT_TRUE(scrollbar_2_animation_controller); 12163 EXPECT_TRUE(scrollbar_2_animation_controller);
12155 12164
12156 // Mouse goes over scrollbar_2, moves close to scrollbar_2, moves close to 12165 // Mouse goes over scrollbar_2, moves close to scrollbar_2, moves close to
12157 // scrollbar_1, goes over scrollbar_1. 12166 // scrollbar_1, goes over scrollbar_1.
12158 host_impl_->MouseMoveAt(gfx::Point(60, 150)); 12167 host_impl_->MouseMoveAt(gfx::Point(60, 150));
12159 EXPECT_FALSE( 12168 EXPECT_FALSE(
12160 scrollbar_1_animation_controller->MouseIsNearScrollbar(VERTICAL)); 12169 scrollbar_1_animation_controller->MouseIsNearScrollbar(VERTICAL));
12161 EXPECT_FALSE( 12170 EXPECT_FALSE(
12162 scrollbar_1_animation_controller->MouseIsOverScrollbar(VERTICAL)); 12171 scrollbar_1_animation_controller->MouseIsOverScrollbar(VERTICAL));
12163 EXPECT_TRUE(scrollbar_2_animation_controller->MouseIsNearScrollbar(VERTICAL)); 12172 EXPECT_TRUE(scrollbar_2_animation_controller->MouseIsNearScrollbar(VERTICAL));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
12204 animation_task_ = base::Closure(); 12213 animation_task_ = base::Closure();
12205 12214
12206 host_impl_->MouseDown(); 12215 host_impl_->MouseDown();
12207 host_impl_->MouseUp(); 12216 host_impl_->MouseUp();
12208 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 12217 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
12209 12218
12210 // Near scrollbar_1, then mouse down and unregister 12219 // Near scrollbar_1, then mouse down and unregister
12211 // scrollbar_2_animation_controller, then mouse up should not cause crash. 12220 // scrollbar_2_animation_controller, then mouse up should not cause crash.
12212 host_impl_->MouseMoveAt(gfx::Point(40, 150)); 12221 host_impl_->MouseMoveAt(gfx::Point(40, 150));
12213 host_impl_->MouseDown(); 12222 host_impl_->MouseDown();
12214 host_impl_->UnregisterScrollbarAnimationController(root_scroll->id()); 12223 host_impl_->UnregisterScrollbarAnimationController(root_scroll->element_id());
12215 host_impl_->MouseUp(); 12224 host_impl_->MouseUp();
12216 } 12225 }
12217 12226
12218 TEST_F(LayerTreeHostImplTest, 12227 TEST_F(LayerTreeHostImplTest,
12219 LayerTreeHostImplTestScrollbarStatesInMainThreadScorlling) { 12228 LayerTreeHostImplTestScrollbarStatesInMainThreadScrolling) {
12220 SetupMouseMoveAtTestScrollbarStates(true); 12229 SetupMouseMoveAtTestScrollbarStates(true);
12221 } 12230 }
12222 12231
12223 TEST_F(LayerTreeHostImplTest, 12232 TEST_F(LayerTreeHostImplTest,
12224 LayerTreeHostImplTestScrollbarStatesInNotMainThreadScorlling) { 12233 LayerTreeHostImplTestScrollbarStatesInNotMainThreadScrolling) {
12225 SetupMouseMoveAtTestScrollbarStates(false); 12234 SetupMouseMoveAtTestScrollbarStates(false);
12226 } 12235 }
12227 12236
12228 TEST_F(LayerTreeHostImplTest, CheckerImagingTileInvalidation) { 12237 TEST_F(LayerTreeHostImplTest, CheckerImagingTileInvalidation) {
12229 LayerTreeSettings settings = DefaultSettings(); 12238 LayerTreeSettings settings = DefaultSettings();
12230 settings.enable_checker_imaging = true; 12239 settings.enable_checker_imaging = true;
12231 settings.default_tile_size = gfx::Size(256, 256); 12240 settings.default_tile_size = gfx::Size(256, 256);
12232 settings.max_untiled_layer_size = gfx::Size(256, 256); 12241 settings.max_untiled_layer_size = gfx::Size(256, 256);
12233 CreateHostImpl(settings, CreateCompositorFrameSink()); 12242 CreateHostImpl(settings, CreateCompositorFrameSink());
12234 gfx::Size layer_size = gfx::Size(750, 750); 12243 gfx::Size layer_size = gfx::Size(750, 750);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
12296 else 12305 else
12297 EXPECT_FALSE(tile->HasRasterTask()); 12306 EXPECT_FALSE(tile->HasRasterTask());
12298 } 12307 }
12299 Region expected_invalidation( 12308 Region expected_invalidation(
12300 raster_source->GetRectForImage(checkerable_image->uniqueID())); 12309 raster_source->GetRectForImage(checkerable_image->uniqueID()));
12301 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); 12310 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation()));
12302 } 12311 }
12303 12312
12304 } // namespace 12313 } // namespace
12305 } // namespace cc 12314 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698