OLD | NEW |
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 2901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2912 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = | 2912 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
2913 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 400, | 2913 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 400, |
2914 VERTICAL, 10, 0, false, true); | 2914 VERTICAL, 10, 0, false, true); |
2915 scrollbar->test_properties()->opacity = 0.f; | 2915 scrollbar->test_properties()->opacity = 0.f; |
2916 EXPECT_FLOAT_EQ(0.f, scrollbar->test_properties()->opacity); | 2916 EXPECT_FLOAT_EQ(0.f, scrollbar->test_properties()->opacity); |
2917 | 2917 |
2918 LayerImpl* scroll = host_impl_->active_tree()->OuterViewportScrollLayer(); | 2918 LayerImpl* scroll = host_impl_->active_tree()->OuterViewportScrollLayer(); |
2919 LayerImpl* root = host_impl_->active_tree()->InnerViewportContainerLayer(); | 2919 LayerImpl* root = host_impl_->active_tree()->InnerViewportContainerLayer(); |
2920 scrollbar->SetScrollElementId(scroll->element_id()); | 2920 scrollbar->SetScrollElementId(scroll->element_id()); |
2921 root->test_properties()->AddChild(std::move(scrollbar)); | 2921 root->test_properties()->AddChild(std::move(scrollbar)); |
| 2922 scroll->set_needs_show_scrollbars(true); |
2922 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 2923 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
2923 host_impl_->active_tree()->DidBecomeActive(); | 2924 host_impl_->active_tree()->DidBecomeActive(); |
| 2925 host_impl_->active_tree()->HandleScrollbarShowRequestsFromMain(); |
2924 DrawFrame(); | 2926 DrawFrame(); |
2925 | 2927 |
2926 // SetScrollElementId will initialize the scrollbar which will cause it to | 2928 // SetScrollElementId will initialize the scrollbar which will cause it to |
2927 // show and request a redraw. | 2929 // show and request a redraw. |
2928 did_request_redraw_ = false; | 2930 did_request_redraw_ = false; |
2929 } | 2931 } |
2930 | 2932 |
2931 void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { | 2933 void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { |
2932 LayerTreeSettings settings = DefaultSettings(); | 2934 LayerTreeSettings settings = DefaultSettings(); |
2933 settings.scrollbar_animator = animator; | 2935 settings.scrollbar_animator = animator; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3049 host_impl_->Animate(); | 3051 host_impl_->Animate(); |
3050 EXPECT_TRUE(did_request_next_frame_); | 3052 EXPECT_TRUE(did_request_next_frame_); |
3051 did_request_next_frame_ = false; | 3053 did_request_next_frame_ = false; |
3052 EXPECT_TRUE(did_request_redraw_); | 3054 EXPECT_TRUE(did_request_redraw_); |
3053 did_request_redraw_ = false; | 3055 did_request_redraw_ = false; |
3054 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | 3056 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
3055 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | 3057 EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
3056 host_impl_->DidFinishImplFrame(); | 3058 host_impl_->DidFinishImplFrame(); |
3057 } | 3059 } |
3058 | 3060 |
3059 // Setting the scroll offset outside a scroll should also cause the | 3061 // Setting the scroll offset outside a scroll should not cause the |
3060 // scrollbar to appear and to schedule a scrollbar animation. | 3062 // scrollbar to appear or schedule a scrollbar animation. |
3061 if (host_impl_->active_tree() | 3063 if (host_impl_->active_tree() |
3062 ->property_trees() | 3064 ->property_trees() |
3063 ->scroll_tree.UpdateScrollOffsetBaseForTesting( | 3065 ->scroll_tree.UpdateScrollOffsetBaseForTesting( |
3064 host_impl_->InnerViewportScrollLayer()->id(), | 3066 host_impl_->InnerViewportScrollLayer()->id(), |
3065 gfx::ScrollOffset(5, 5))) | 3067 gfx::ScrollOffset(5, 5))) |
3066 host_impl_->active_tree()->DidUpdateScrollOffset( | 3068 host_impl_->active_tree()->DidUpdateScrollOffset( |
3067 host_impl_->InnerViewportScrollLayer()->id()); | 3069 host_impl_->InnerViewportScrollLayer()->id()); |
3068 EXPECT_FALSE(did_request_next_frame_); | 3070 EXPECT_FALSE(did_request_next_frame_); |
3069 EXPECT_FALSE(did_request_redraw_); | 3071 EXPECT_FALSE(did_request_redraw_); |
3070 if (expecting_animations) { | |
3071 EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), | |
3072 requested_animation_delay_); | |
3073 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | |
3074 requested_animation_delay_ = base::TimeDelta(); | |
3075 animation_task_ = base::Closure(); | |
3076 } else { | |
3077 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
3078 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
3079 } | |
3080 | |
3081 if (expecting_animations) { | |
3082 // Scrolling should have stopped the animation, so we should not be | |
3083 // getting redraws. | |
3084 begin_frame_args = | |
3085 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 5, fake_now); | |
3086 host_impl_->WillBeginImplFrame(begin_frame_args); | |
3087 host_impl_->Animate(); | |
3088 EXPECT_FALSE(did_request_next_frame_); | |
3089 did_request_next_frame_ = false; | |
3090 EXPECT_FALSE(did_request_redraw_); | |
3091 did_request_redraw_ = false; | |
3092 host_impl_->DidFinishImplFrame(); | |
3093 } | |
3094 | |
3095 // For Andrdoid, scrollbar animation is not triggered unnecessarily. | |
3096 // For Aura Overlay Scrollbar, scrollbar appears even if scroll offset did | |
3097 // not change. | |
3098 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | |
3099 InputHandler::WHEEL); | |
3100 host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2dF(5, 0)).get()); | |
3101 EXPECT_FALSE(did_request_next_frame_); | |
3102 EXPECT_TRUE(did_request_redraw_); | |
3103 did_request_redraw_ = false; | |
3104 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | 3072 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
3105 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | 3073 EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
3106 | 3074 |
3107 host_impl_->ScrollEnd(EndState().get()); | |
3108 EXPECT_FALSE(did_request_next_frame_); | |
3109 EXPECT_FALSE(did_request_redraw_); | |
3110 if (animator == LayerTreeSettings::AURA_OVERLAY) { | |
3111 EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), | |
3112 requested_animation_delay_); | |
3113 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | |
3114 requested_animation_delay_ = base::TimeDelta(); | |
3115 animation_task_ = base::Closure(); | |
3116 } else { | |
3117 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
3118 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
3119 } | |
3120 | |
3121 // Changing page scale triggers scrollbar animation. | 3075 // Changing page scale triggers scrollbar animation. |
3122 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f); | 3076 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f); |
3123 host_impl_->active_tree()->SetPageScaleOnActiveTree(1.1f); | 3077 host_impl_->active_tree()->SetPageScaleOnActiveTree(1.1f); |
3124 EXPECT_FALSE(did_request_next_frame_); | 3078 EXPECT_FALSE(did_request_next_frame_); |
3125 EXPECT_FALSE(did_request_redraw_); | 3079 EXPECT_FALSE(did_request_redraw_); |
3126 if (expecting_animations) { | 3080 if (expecting_animations) { |
3127 EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), | 3081 EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), |
3128 requested_animation_delay_); | 3082 requested_animation_delay_); |
3129 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 3083 EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
3130 requested_animation_delay_ = base::TimeDelta(); | 3084 requested_animation_delay_ = base::TimeDelta(); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3260 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = | 3214 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
3261 SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400, | 3215 SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400, |
3262 VERTICAL, 10, 0, false, true); | 3216 VERTICAL, 10, 0, false, true); |
3263 scrollbar->test_properties()->opacity = 0.f; | 3217 scrollbar->test_properties()->opacity = 0.f; |
3264 LayerImpl* scroll = host_impl_->pending_tree()->OuterViewportScrollLayer(); | 3218 LayerImpl* scroll = host_impl_->pending_tree()->OuterViewportScrollLayer(); |
3265 LayerImpl* container = | 3219 LayerImpl* container = |
3266 host_impl_->pending_tree()->InnerViewportContainerLayer(); | 3220 host_impl_->pending_tree()->InnerViewportContainerLayer(); |
3267 scrollbar->SetScrollElementId(scroll->element_id()); | 3221 scrollbar->SetScrollElementId(scroll->element_id()); |
3268 container->test_properties()->AddChild(std::move(scrollbar)); | 3222 container->test_properties()->AddChild(std::move(scrollbar)); |
3269 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); | 3223 host_impl_->pending_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
| 3224 scroll->set_needs_show_scrollbars(true); |
3270 host_impl_->pending_tree()->BuildPropertyTreesForTesting(); | 3225 host_impl_->pending_tree()->BuildPropertyTreesForTesting(); |
3271 host_impl_->ActivateSyncTree(); | 3226 host_impl_->ActivateSyncTree(); |
3272 | 3227 |
3273 ScrollbarAnimationController* scrollbar_controller = | 3228 ScrollbarAnimationController* scrollbar_controller = |
3274 host_impl_->ScrollbarAnimationControllerForElementId( | 3229 host_impl_->ScrollbarAnimationControllerForElementId( |
3275 scroll->element_id()); | 3230 scroll->element_id()); |
3276 | 3231 |
3277 // Scrollbars will flash shown but we should have a fade out animation | 3232 // Scrollbars will flash shown but we should have a fade out animation |
3278 // queued. Run it and fade out the scrollbars. | 3233 // queued. Run it and fade out the scrollbars. |
3279 { | 3234 { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3400 root_scroll->element_id())); | 3355 root_scroll->element_id())); |
3401 vert_1_scrollbar->SetScrollElementId(root_scroll->element_id()); | 3356 vert_1_scrollbar->SetScrollElementId(root_scroll->element_id()); |
3402 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); | 3357 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); |
3403 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( | 3358 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( |
3404 root_scroll->element_id())); | 3359 root_scroll->element_id())); |
3405 horiz_1_scrollbar->SetScrollElementId(root_scroll->element_id()); | 3360 horiz_1_scrollbar->SetScrollElementId(root_scroll->element_id()); |
3406 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); | 3361 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); |
3407 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( | 3362 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( |
3408 root_scroll->element_id())); | 3363 root_scroll->element_id())); |
3409 | 3364 |
3410 // Changing one of the viewport layers should result in a scrollbar animation | 3365 // Scrolling the viewport should result in a scrollbar animation update. |
3411 // update. | |
3412 animation_task_ = base::Closure(); | 3366 animation_task_ = base::Closure(); |
3413 host_impl_->active_tree() | 3367 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
3414 ->InnerViewportContainerLayer() | 3368 host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(10, 10)).get()); |
3415 ->SetViewportBoundsDelta(gfx::Vector2dF(10, 10)); | 3369 host_impl_->ScrollEnd(EndState().get()); |
3416 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | |
3417 animation_task_ = base::Closure(); | |
3418 host_impl_->active_tree()->OuterViewportScrollLayer()->SetCurrentScrollOffset( | |
3419 gfx::ScrollOffset(10, 10)); | |
3420 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | |
3421 animation_task_ = base::Closure(); | |
3422 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( | |
3423 gfx::ScrollOffset(10, 10)); | |
3424 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 3370 EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
3425 animation_task_ = base::Closure(); | 3371 animation_task_ = base::Closure(); |
3426 | 3372 |
3427 // Check scrollbar registration on a sublayer. | 3373 // Check scrollbar registration on a sublayer. |
3428 child->SetScrollClipLayer(child_clip->id()); | 3374 child->SetScrollClipLayer(child_clip->id()); |
3429 child->SetElementId(LayerIdToElementIdForTesting(child->id())); | 3375 child->SetElementId(LayerIdToElementIdForTesting(child->id())); |
3430 ElementId child_scroll_element_id = child->element_id(); | 3376 ElementId child_scroll_element_id = child->element_id(); |
3431 child_clip->test_properties()->AddChild(std::move(child)); | 3377 child_clip->test_properties()->AddChild(std::move(child)); |
3432 root_scroll->test_properties()->AddChild(std::move(child_clip)); | 3378 root_scroll->test_properties()->AddChild(std::move(child_clip)); |
3433 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); | 3379 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); |
3434 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForElementId( | 3380 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForElementId( |
3435 child_scroll_element_id)); | 3381 child_scroll_element_id)); |
3436 vert_2_scrollbar->SetScrollElementId(child_scroll_element_id); | 3382 vert_2_scrollbar->SetScrollElementId(child_scroll_element_id); |
3437 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); | 3383 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); |
3438 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( | 3384 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( |
3439 child_scroll_element_id)); | 3385 child_scroll_element_id)); |
3440 horiz_2_scrollbar->SetScrollElementId(child_scroll_element_id); | 3386 horiz_2_scrollbar->SetScrollElementId(child_scroll_element_id); |
3441 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); | 3387 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); |
3442 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( | 3388 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( |
3443 child_scroll_element_id)); | 3389 child_scroll_element_id)); |
3444 | 3390 |
3445 // Changing one of the child layers should result in a scrollbar animation | 3391 // Changing one of the child layers should result in a scrollbar animation |
3446 // update. | 3392 // update. |
3447 animation_task_ = base::Closure(); | 3393 animation_task_ = base::Closure(); |
3448 child_clip_ptr->SetBounds(gfx::Size(200, 200)); | 3394 child_clip_ptr->SetBounds(gfx::Size(200, 200)); |
3449 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 3395 child_ptr->set_needs_show_scrollbars(true); |
3450 animation_task_ = base::Closure(); | 3396 host_impl_->active_tree()->HandleScrollbarShowRequestsFromMain(); |
3451 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(10, 10)); | |
3452 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 3397 EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
3453 animation_task_ = base::Closure(); | 3398 animation_task_ = base::Closure(); |
3454 | 3399 |
3455 // Check scrollbar unregistration. | 3400 // Check scrollbar unregistration. |
3456 vert_1_scrollbar.reset(); | 3401 vert_1_scrollbar.reset(); |
3457 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); | 3402 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); |
3458 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( | 3403 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( |
3459 root_scroll->element_id())); | 3404 root_scroll->element_id())); |
3460 horiz_1_scrollbar.reset(); | 3405 horiz_1_scrollbar.reset(); |
3461 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); | 3406 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); |
(...skipping 8773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12235 host_impl_->MouseMoveAt(gfx::Point(10, 150)); | 12180 host_impl_->MouseMoveAt(gfx::Point(10, 150)); |
12236 EXPECT_TRUE(scrollbar_1_animation_controller->MouseIsNearScrollbar(VERTICAL)); | 12181 EXPECT_TRUE(scrollbar_1_animation_controller->MouseIsNearScrollbar(VERTICAL)); |
12237 EXPECT_TRUE(scrollbar_1_animation_controller->MouseIsOverScrollbar(VERTICAL)); | 12182 EXPECT_TRUE(scrollbar_1_animation_controller->MouseIsOverScrollbar(VERTICAL)); |
12238 EXPECT_FALSE( | 12183 EXPECT_FALSE( |
12239 scrollbar_2_animation_controller->MouseIsNearScrollbar(VERTICAL)); | 12184 scrollbar_2_animation_controller->MouseIsNearScrollbar(VERTICAL)); |
12240 EXPECT_FALSE( | 12185 EXPECT_FALSE( |
12241 scrollbar_2_animation_controller->MouseIsOverScrollbar(VERTICAL)); | 12186 scrollbar_2_animation_controller->MouseIsOverScrollbar(VERTICAL)); |
12242 | 12187 |
12243 // Capture scrollbar_1, then move mouse to scrollbar_2's layer, should post an | 12188 // Capture scrollbar_1, then move mouse to scrollbar_2's layer, should post an |
12244 // event to fade out scrollbar_1. | 12189 // event to fade out scrollbar_1. |
| 12190 scrollbar_1_animation_controller->DidScrollUpdate(); |
12245 animation_task_ = base::Closure(); | 12191 animation_task_ = base::Closure(); |
12246 | 12192 |
12247 host_impl_->MouseDown(); | 12193 host_impl_->MouseDown(); |
12248 host_impl_->MouseMoveAt(gfx::Point(100, 150)); | 12194 host_impl_->MouseMoveAt(gfx::Point(100, 150)); |
12249 host_impl_->MouseUp(); | 12195 host_impl_->MouseUp(); |
12250 | 12196 |
12251 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 12197 EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
12252 | 12198 |
12253 // Near scrollbar_1, then mouse down and up, should not post an event to fade | 12199 // Near scrollbar_1, then mouse down and up, should not post an event to fade |
12254 // out scrollbar_1. | 12200 // out scrollbar_1. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12348 else | 12294 else |
12349 EXPECT_FALSE(tile->HasRasterTask()); | 12295 EXPECT_FALSE(tile->HasRasterTask()); |
12350 } | 12296 } |
12351 Region expected_invalidation( | 12297 Region expected_invalidation( |
12352 raster_source->GetRectForImage(checkerable_image->uniqueID())); | 12298 raster_source->GetRectForImage(checkerable_image->uniqueID())); |
12353 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); | 12299 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); |
12354 } | 12300 } |
12355 | 12301 |
12356 } // namespace | 12302 } // namespace |
12357 } // namespace cc | 12303 } // namespace cc |
OLD | NEW |