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()->ShowScrollbars(); | |
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()->InnerViewportContainerLayer()->SetBoundsDelta( | 3367 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::WHEEL); |
3414 gfx::Vector2dF(10, 10)); | 3368 host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(10, 10)).get()); |
3415 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 3369 host_impl_->ScrollEnd(EndState().get()); |
3416 animation_task_ = base::Closure(); | |
3417 host_impl_->active_tree()->OuterViewportScrollLayer()->SetCurrentScrollOffset( | |
3418 gfx::ScrollOffset(10, 10)); | |
3419 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | |
3420 animation_task_ = base::Closure(); | |
3421 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( | |
3422 gfx::ScrollOffset(10, 10)); | |
3423 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 3370 EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
3424 animation_task_ = base::Closure(); | 3371 animation_task_ = base::Closure(); |
3425 | 3372 |
3426 // Check scrollbar registration on a sublayer. | 3373 // Check scrollbar registration on a sublayer. |
3427 child->SetScrollClipLayer(child_clip->id()); | 3374 child->SetScrollClipLayer(child_clip->id()); |
3428 child->SetElementId(LayerIdToElementIdForTesting(child->id())); | 3375 child->SetElementId(LayerIdToElementIdForTesting(child->id())); |
3429 ElementId child_scroll_element_id = child->element_id(); | 3376 ElementId child_scroll_element_id = child->element_id(); |
3430 child_clip->test_properties()->AddChild(std::move(child)); | 3377 child_clip->test_properties()->AddChild(std::move(child)); |
3431 root_scroll->test_properties()->AddChild(std::move(child_clip)); | 3378 root_scroll->test_properties()->AddChild(std::move(child_clip)); |
3432 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); | 3379 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); |
3433 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForElementId( | 3380 EXPECT_EQ(nullptr, host_impl_->ScrollbarAnimationControllerForElementId( |
3434 child_scroll_element_id)); | 3381 child_scroll_element_id)); |
3435 vert_2_scrollbar->SetScrollElementId(child_scroll_element_id); | 3382 vert_2_scrollbar->SetScrollElementId(child_scroll_element_id); |
3436 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); | 3383 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); |
3437 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( | 3384 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( |
3438 child_scroll_element_id)); | 3385 child_scroll_element_id)); |
3439 horiz_2_scrollbar->SetScrollElementId(child_scroll_element_id); | 3386 horiz_2_scrollbar->SetScrollElementId(child_scroll_element_id); |
3440 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); | 3387 EXPECT_EQ(2ul, host_impl_->ScrollbarsFor(child_scroll_element_id).size()); |
3441 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( | 3388 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( |
3442 child_scroll_element_id)); | 3389 child_scroll_element_id)); |
3443 | 3390 |
3444 // 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 |
3445 // update. | 3392 // update. |
3446 animation_task_ = base::Closure(); | 3393 animation_task_ = base::Closure(); |
3447 child_clip_ptr->SetBounds(gfx::Size(200, 200)); | 3394 child_clip_ptr->SetBounds(gfx::Size(200, 200)); |
3448 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 3395 child_ptr->set_needs_show_scrollbars(true); |
3449 animation_task_ = base::Closure(); | 3396 host_impl_->active_tree()->ShowScrollbars(); |
3450 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(10, 10)); | |
3451 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 3397 EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
3452 animation_task_ = base::Closure(); | 3398 animation_task_ = base::Closure(); |
3453 | 3399 |
3454 // Check scrollbar unregistration. | 3400 // Check scrollbar unregistration. |
3455 vert_1_scrollbar.reset(); | 3401 vert_1_scrollbar.reset(); |
3456 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); | 3402 EXPECT_EQ(1ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); |
3457 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( | 3403 EXPECT_TRUE(host_impl_->ScrollbarAnimationControllerForElementId( |
3458 root_scroll->element_id())); | 3404 root_scroll->element_id())); |
3459 horiz_1_scrollbar.reset(); | 3405 horiz_1_scrollbar.reset(); |
3460 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); | 3406 EXPECT_EQ(0ul, host_impl_->ScrollbarsFor(root_scroll->element_id()).size()); |
(...skipping 8801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12262 host_impl_->MouseMoveAt(gfx::Point(10, 150)); | 12208 host_impl_->MouseMoveAt(gfx::Point(10, 150)); |
12263 EXPECT_TRUE(scrollbar_1_animation_controller->MouseIsNearScrollbar(VERTICAL)); | 12209 EXPECT_TRUE(scrollbar_1_animation_controller->MouseIsNearScrollbar(VERTICAL)); |
12264 EXPECT_TRUE(scrollbar_1_animation_controller->MouseIsOverScrollbar(VERTICAL)); | 12210 EXPECT_TRUE(scrollbar_1_animation_controller->MouseIsOverScrollbar(VERTICAL)); |
12265 EXPECT_FALSE( | 12211 EXPECT_FALSE( |
12266 scrollbar_2_animation_controller->MouseIsNearScrollbar(VERTICAL)); | 12212 scrollbar_2_animation_controller->MouseIsNearScrollbar(VERTICAL)); |
12267 EXPECT_FALSE( | 12213 EXPECT_FALSE( |
12268 scrollbar_2_animation_controller->MouseIsOverScrollbar(VERTICAL)); | 12214 scrollbar_2_animation_controller->MouseIsOverScrollbar(VERTICAL)); |
12269 | 12215 |
12270 // Capture scrollbar_1, then move mouse to scrollbar_2's layer, should post an | 12216 // Capture scrollbar_1, then move mouse to scrollbar_2's layer, should post an |
12271 // event to fade out scrollbar_1. | 12217 // event to fade out scrollbar_1. |
12218 scrollbar_1_animation_controller->DidScrollUpdate(); | |
bokan
2017/04/25 22:56:48
Do you know why this wasn't previously needed?
skobes
2017/04/27 00:46:31
The test was counting on the scrollbar to be made
bokan
2017/04/27 19:38:58
Got it, thanks for the explanation.
| |
12272 animation_task_ = base::Closure(); | 12219 animation_task_ = base::Closure(); |
12273 | 12220 |
12274 host_impl_->MouseDown(); | 12221 host_impl_->MouseDown(); |
12275 host_impl_->MouseMoveAt(gfx::Point(100, 150)); | 12222 host_impl_->MouseMoveAt(gfx::Point(100, 150)); |
12276 host_impl_->MouseUp(); | 12223 host_impl_->MouseUp(); |
12277 | 12224 |
12278 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 12225 EXPECT_FALSE(animation_task_.Equals(base::Closure())); |
12279 | 12226 |
12280 // Near scrollbar_1, then mouse down and up, should not post an event to fade | 12227 // Near scrollbar_1, then mouse down and up, should not post an event to fade |
12281 // out scrollbar_1. | 12228 // out scrollbar_1. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12375 else | 12322 else |
12376 EXPECT_FALSE(tile->HasRasterTask()); | 12323 EXPECT_FALSE(tile->HasRasterTask()); |
12377 } | 12324 } |
12378 Region expected_invalidation( | 12325 Region expected_invalidation( |
12379 raster_source->GetRectForImage(checkerable_image->uniqueID())); | 12326 raster_source->GetRectForImage(checkerable_image->uniqueID())); |
12380 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); | 12327 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); |
12381 } | 12328 } |
12382 | 12329 |
12383 } // namespace | 12330 } // namespace |
12384 } // namespace cc | 12331 } // namespace cc |
OLD | NEW |