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

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

Issue 2816923002: change overlay scrollbar hover show to hover fade in (Closed)
Patch Set: merge FadeInDuration and FadeOutDuration to FadeDuration 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 2852 matching lines...) Expand 10 before | Expand all | Expand 10 after
2863 DrawFrame(); 2863 DrawFrame();
2864 2864
2865 // SetScrollInfo 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_fade_in_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 =
2876 base::TimeDelta::FromMilliseconds(20); 2876 base::TimeDelta::FromMilliseconds(20);
2877 settings.scrollbar_fade_out_duration = 2877 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20);
2878 base::TimeDelta::FromMilliseconds(20);
2879 2878
2880 // If no animator is set, scrollbar won't show and no animation is expected. 2879 // If no animator is set, scrollbar won't show and no animation is expected.
2881 bool expecting_animations = animator != LayerTreeSettings::NO_ANIMATOR; 2880 bool expecting_animations = animator != LayerTreeSettings::NO_ANIMATOR;
2882 2881
2883 SetupLayers(settings); 2882 SetupLayers(settings);
2884 2883
2885 base::TimeTicks fake_now = base::TimeTicks::Now(); 2884 base::TimeTicks fake_now = base::TimeTicks::Now();
2886 2885
2887 if (expecting_animations) { 2886 if (expecting_animations) {
2888 // A task will be posted to fade the initial scrollbar. 2887 // A task will be posted to fade the initial scrollbar.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
3087 3086
3088 TEST_F(LayerTreeHostImplTestScrollbarAnimation, NoAnimator) { 3087 TEST_F(LayerTreeHostImplTestScrollbarAnimation, NoAnimator) {
3089 RunTest(LayerTreeSettings::NO_ANIMATOR); 3088 RunTest(LayerTreeSettings::NO_ANIMATOR);
3090 } 3089 }
3091 3090
3092 class LayerTreeHostImplTestScrollbarOpacity : public LayerTreeHostImplTest { 3091 class LayerTreeHostImplTestScrollbarOpacity : public LayerTreeHostImplTest {
3093 protected: 3092 protected:
3094 void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { 3093 void RunTest(LayerTreeSettings::ScrollbarAnimator animator) {
3095 LayerTreeSettings settings = DefaultSettings(); 3094 LayerTreeSettings settings = DefaultSettings();
3096 settings.scrollbar_animator = animator; 3095 settings.scrollbar_animator = animator;
3097 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20); 3096 settings.scrollbar_fade_in_delay = base::TimeDelta::FromMilliseconds(20);
3098 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20); 3097 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20);
3099 settings.scrollbar_fade_out_duration = 3098 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20);
3100 base::TimeDelta::FromMilliseconds(20);
3101 gfx::Size content_size(100, 100); 3099 gfx::Size content_size(100, 100);
3102 3100
3103 // If no animator is set, scrollbar won't show and no animation is expected. 3101 // If no animator is set, scrollbar won't show and no animation is expected.
3104 bool expecting_animations = animator != LayerTreeSettings::NO_ANIMATOR; 3102 bool expecting_animations = animator != LayerTreeSettings::NO_ANIMATOR;
3105 3103
3106 CreateHostImpl(settings, CreateCompositorFrameSink()); 3104 CreateHostImpl(settings, CreateCompositorFrameSink());
3107 host_impl_->CreatePendingTree(); 3105 host_impl_->CreatePendingTree();
3108 CreateScrollAndContentsLayers(host_impl_->pending_tree(), content_size); 3106 CreateScrollAndContentsLayers(host_impl_->pending_tree(), content_size);
3109 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = 3107 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
3110 SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400, 3108 SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3186 RunTest(LayerTreeSettings::AURA_OVERLAY); 3184 RunTest(LayerTreeSettings::AURA_OVERLAY);
3187 } 3185 }
3188 3186
3189 TEST_F(LayerTreeHostImplTestScrollbarOpacity, NoAnimator) { 3187 TEST_F(LayerTreeHostImplTestScrollbarOpacity, NoAnimator) {
3190 RunTest(LayerTreeSettings::NO_ANIMATOR); 3188 RunTest(LayerTreeSettings::NO_ANIMATOR);
3191 } 3189 }
3192 3190
3193 TEST_F(LayerTreeHostImplTest, ScrollbarVisibilityChangeCausesRedrawAndCommit) { 3191 TEST_F(LayerTreeHostImplTest, ScrollbarVisibilityChangeCausesRedrawAndCommit) {
3194 LayerTreeSettings settings = DefaultSettings(); 3192 LayerTreeSettings settings = DefaultSettings();
3195 settings.scrollbar_animator = LayerTreeSettings::AURA_OVERLAY; 3193 settings.scrollbar_animator = LayerTreeSettings::AURA_OVERLAY;
3196 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20); 3194 settings.scrollbar_fade_in_delay = base::TimeDelta::FromMilliseconds(20);
3197 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20); 3195 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20);
3198 settings.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(20); 3196 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20);
3199 gfx::Size content_size(100, 100); 3197 gfx::Size content_size(100, 100);
3200 3198
3201 CreateHostImpl(settings, CreateCompositorFrameSink()); 3199 CreateHostImpl(settings, CreateCompositorFrameSink());
3202 host_impl_->CreatePendingTree(); 3200 host_impl_->CreatePendingTree();
3203 CreateScrollAndContentsLayers(host_impl_->pending_tree(), content_size); 3201 CreateScrollAndContentsLayers(host_impl_->pending_tree(), content_size);
3204 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = 3202 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
3205 SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400, 3203 SolidColorScrollbarLayerImpl::Create(host_impl_->pending_tree(), 400,
3206 VERTICAL, 10, 0, false, true); 3204 VERTICAL, 10, 0, false, true);
3207 scrollbar->test_properties()->opacity = 0.f; 3205 scrollbar->test_properties()->opacity = 0.f;
3208 LayerImpl* scroll = host_impl_->pending_tree()->OuterViewportScrollLayer(); 3206 LayerImpl* scroll = host_impl_->pending_tree()->OuterViewportScrollLayer();
(...skipping 17 matching lines...) Expand all
3226 animation_task_.Run(); 3224 animation_task_.Run();
3227 3225
3228 base::TimeTicks fake_now = base::TimeTicks::Now(); 3226 base::TimeTicks fake_now = base::TimeTicks::Now();
3229 scrollbar_controller->Animate(fake_now); 3227 scrollbar_controller->Animate(fake_now);
3230 fake_now += settings.scrollbar_fade_out_delay; 3228 fake_now += settings.scrollbar_fade_out_delay;
3231 scrollbar_controller->Animate(fake_now); 3229 scrollbar_controller->Animate(fake_now);
3232 3230
3233 ASSERT_TRUE(scrollbar_controller->ScrollbarsHidden()); 3231 ASSERT_TRUE(scrollbar_controller->ScrollbarsHidden());
3234 } 3232 }
3235 3233
3236 // Move the mouse over the scrollbar region. This should post a delayed show 3234 // Move the mouse over the scrollbar region. This should post a delayed fade
3237 // task. Execute it to show the scrollbars. 3235 // in task. Execute it to show the scrollbars.
3238 { 3236 {
3239 animation_task_ = base::Closure(); 3237 animation_task_ = base::Closure();
3240 scrollbar_controller->DidMouseMoveNear(VERTICAL, 0); 3238 scrollbar_controller->DidMouseMoveNear(VERTICAL, 0);
3241 ASSERT_FALSE(animation_task_.Equals(base::Closure())); 3239 ASSERT_FALSE(animation_task_.Equals(base::Closure()));
3242 ASSERT_FALSE(animation_task_.IsCancelled()); 3240 ASSERT_FALSE(animation_task_.IsCancelled());
3243 } 3241 }
3244 3242
3245 // The show task should cause the scrollbars to show. Ensure that we 3243 // The fade in task should cause the scrollbars to show. Ensure that we
3246 // requested a redraw and a commit. 3244 // requested a redraw and a commit.
3247 { 3245 {
3248 did_request_redraw_ = false; 3246 did_request_redraw_ = false;
3249 did_request_commit_ = false; 3247 did_request_commit_ = false;
3250 ASSERT_TRUE(scrollbar_controller->ScrollbarsHidden()); 3248 ASSERT_TRUE(scrollbar_controller->ScrollbarsHidden());
3251 animation_task_.Run(); 3249 animation_task_.Run();
3250
3251 base::TimeTicks fake_now = base::TimeTicks::Now();
3252 scrollbar_controller->Animate(fake_now);
3253 fake_now += settings.scrollbar_fade_duration;
3254 scrollbar_controller->Animate(fake_now);
3255
3252 ASSERT_FALSE(scrollbar_controller->ScrollbarsHidden()); 3256 ASSERT_FALSE(scrollbar_controller->ScrollbarsHidden());
3253 EXPECT_TRUE(did_request_redraw_); 3257 EXPECT_TRUE(did_request_redraw_);
3254 EXPECT_TRUE(did_request_commit_); 3258 EXPECT_TRUE(did_request_commit_);
3255 } 3259 }
3256 } 3260 }
3257 3261
3258 TEST_F(LayerTreeHostImplTest, ScrollbarInnerLargerThanOuter) { 3262 TEST_F(LayerTreeHostImplTest, ScrollbarInnerLargerThanOuter) {
3259 LayerTreeSettings settings = DefaultSettings(); 3263 LayerTreeSettings settings = DefaultSettings();
3260 CreateHostImpl(settings, CreateCompositorFrameSink()); 3264 CreateHostImpl(settings, CreateCompositorFrameSink());
3261 3265
(...skipping 23 matching lines...) Expand all
3285 child->SetBounds(inner_viewport_size); 3289 child->SetBounds(inner_viewport_size);
3286 3290
3287 horiz_scrollbar->SetScrollInfo(root_scroll->id(), root_scroll->element_id()); 3291 horiz_scrollbar->SetScrollInfo(root_scroll->id(), root_scroll->element_id());
3288 3292
3289 EXPECT_EQ(300, horiz_scrollbar->clip_layer_length()); 3293 EXPECT_EQ(300, horiz_scrollbar->clip_layer_length());
3290 } 3294 }
3291 3295
3292 TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) { 3296 TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) {
3293 LayerTreeSettings settings = DefaultSettings(); 3297 LayerTreeSettings settings = DefaultSettings();
3294 settings.scrollbar_animator = LayerTreeSettings::ANDROID_OVERLAY; 3298 settings.scrollbar_animator = LayerTreeSettings::ANDROID_OVERLAY;
3295 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20); 3299 settings.scrollbar_fade_in_delay = base::TimeDelta::FromMilliseconds(20);
3296 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20); 3300 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20);
3297 settings.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(20); 3301 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20);
3298 CreateHostImpl(settings, CreateCompositorFrameSink()); 3302 CreateHostImpl(settings, CreateCompositorFrameSink());
3299 3303
3300 gfx::Size viewport_size(300, 200); 3304 gfx::Size viewport_size(300, 200);
3301 gfx::Size content_size(1000, 1000); 3305 gfx::Size content_size(1000, 1000);
3302 3306
3303 const int vert_1_id = 10; 3307 const int vert_1_id = 10;
3304 const int horiz_1_id = 11; 3308 const int horiz_1_id = 11;
3305 const int vert_2_id = 12; 3309 const int vert_2_id = 12;
3306 const int horiz_2_id = 13; 3310 const int horiz_2_id = 13;
3307 const int child_clip_id = 14; 3311 const int child_clip_id = 14;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
3415 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( 3419 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset(
3416 gfx::ScrollOffset(20, 20)); 3420 gfx::ScrollOffset(20, 20));
3417 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 3421 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
3418 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(20, 20)); 3422 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(20, 20));
3419 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 3423 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
3420 } 3424 }
3421 3425
3422 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( 3426 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
3423 float device_scale_factor) { 3427 float device_scale_factor) {
3424 LayerTreeSettings settings = DefaultSettings(); 3428 LayerTreeSettings settings = DefaultSettings();
3425 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(500); 3429 settings.scrollbar_fade_in_delay = base::TimeDelta::FromMilliseconds(500);
3426 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(500); 3430 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(500);
3427 settings.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(300); 3431 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
3428 settings.scrollbar_animator = LayerTreeSettings::AURA_OVERLAY; 3432 settings.scrollbar_animator = LayerTreeSettings::AURA_OVERLAY;
3429 3433
3430 gfx::Size viewport_size(300, 200); 3434 gfx::Size viewport_size(300, 200);
3431 gfx::Size device_viewport_size = 3435 gfx::Size device_viewport_size =
3432 gfx::ScaleToFlooredSize(viewport_size, device_scale_factor); 3436 gfx::ScaleToFlooredSize(viewport_size, device_scale_factor);
3433 gfx::Size content_size(1000, 1000); 3437 gfx::Size content_size(1000, 1000);
3434 gfx::Size scrollbar_size(gfx::Size(15, viewport_size.height())); 3438 gfx::Size scrollbar_size(gfx::Size(15, viewport_size.height()));
3435 3439
3436 CreateHostImpl(settings, CreateCompositorFrameSink()); 3440 CreateHostImpl(settings, CreateCompositorFrameSink());
3437 host_impl_->active_tree()->SetDeviceScaleFactor(device_scale_factor); 3441 host_impl_->active_tree()->SetDeviceScaleFactor(device_scale_factor);
(...skipping 8606 matching lines...) Expand 10 before | Expand all | Expand 10 after
12044 12048
12045 // Re-initialize with a software output surface. 12049 // Re-initialize with a software output surface.
12046 compositor_frame_sink_ = FakeCompositorFrameSink::CreateSoftware(); 12050 compositor_frame_sink_ = FakeCompositorFrameSink::CreateSoftware();
12047 host_impl_->InitializeRenderer(compositor_frame_sink_.get()); 12051 host_impl_->InitializeRenderer(compositor_frame_sink_.get());
12048 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); 12052 EXPECT_FALSE(host_impl_->use_gpu_rasterization());
12049 } 12053 }
12050 12054
12051 void LayerTreeHostImplTest::SetupMouseMoveAtTestScrollbarStates( 12055 void LayerTreeHostImplTest::SetupMouseMoveAtTestScrollbarStates(
12052 bool main_thread_scrolling) { 12056 bool main_thread_scrolling) {
12053 LayerTreeSettings settings = DefaultSettings(); 12057 LayerTreeSettings settings = DefaultSettings();
12054 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(500); 12058 settings.scrollbar_fade_in_delay = base::TimeDelta::FromMilliseconds(500);
12055 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(500); 12059 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(500);
12056 settings.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(300); 12060 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
12057 settings.scrollbar_animator = LayerTreeSettings::AURA_OVERLAY; 12061 settings.scrollbar_animator = LayerTreeSettings::AURA_OVERLAY;
12058 12062
12059 gfx::Size viewport_size(300, 200); 12063 gfx::Size viewport_size(300, 200);
12060 gfx::Size content_size(1000, 1000); 12064 gfx::Size content_size(1000, 1000);
12061 gfx::Size child_layer_size(250, 150); 12065 gfx::Size child_layer_size(250, 150);
12062 gfx::Size scrollbar_size_1(gfx::Size(15, viewport_size.height())); 12066 gfx::Size scrollbar_size_1(gfx::Size(15, viewport_size.height()));
12063 gfx::Size scrollbar_size_2(gfx::Size(15, child_layer_size.height())); 12067 gfx::Size scrollbar_size_2(gfx::Size(15, child_layer_size.height()));
12064 12068
12065 const int scrollbar_1_id = 10; 12069 const int scrollbar_1_id = 10;
12066 const int scrollbar_2_id = 11; 12070 const int scrollbar_2_id = 11;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
12317 else 12321 else
12318 EXPECT_FALSE(tile->HasRasterTask()); 12322 EXPECT_FALSE(tile->HasRasterTask());
12319 } 12323 }
12320 Region expected_invalidation( 12324 Region expected_invalidation(
12321 raster_source->GetRectForImage(checkerable_image->uniqueID())); 12325 raster_source->GetRectForImage(checkerable_image->uniqueID()));
12322 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); 12326 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation()));
12323 } 12327 }
12324 12328
12325 } // namespace 12329 } // namespace
12326 } // namespace cc 12330 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698