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

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

Powered by Google App Engine
This is Rietveld 408576698