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

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

Issue 2843293004: change overlay scrollbar hover show to hover fade in (Closed)
Patch Set: Created 3 years, 7 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 // SetScrollLayerId will initialize the scrollbar which will cause it to 2865 // SetScrollLayerId 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 10 matching lines...) Expand all
3219 3214
3220 // Scrollbars will flash shown but we should have a fade out animation 3215 // Scrollbars will flash shown but we should have a fade out animation
3221 // queued. Run it and fade out the scrollbars. 3216 // queued. Run it and fade out the scrollbars.
3222 { 3217 {
3223 ASSERT_FALSE(animation_task_.Equals(base::Closure())); 3218 ASSERT_FALSE(animation_task_.Equals(base::Closure()));
3224 ASSERT_FALSE(animation_task_.IsCancelled()); 3219 ASSERT_FALSE(animation_task_.IsCancelled());
3225 animation_task_.Run(); 3220 animation_task_.Run();
3226 3221
3227 base::TimeTicks fake_now = base::TimeTicks::Now(); 3222 base::TimeTicks fake_now = base::TimeTicks::Now();
3228 scrollbar_controller->Animate(fake_now); 3223 scrollbar_controller->Animate(fake_now);
3229 fake_now += settings.scrollbar_fade_out_delay; 3224 fake_now += settings.scrollbar_fade_delay;
3230 scrollbar_controller->Animate(fake_now); 3225 scrollbar_controller->Animate(fake_now);
3231 3226
3232 ASSERT_TRUE(scrollbar_controller->ScrollbarsHidden()); 3227 ASSERT_TRUE(scrollbar_controller->ScrollbarsHidden());
3233 } 3228 }
3234 3229
3235 // Move the mouse over the scrollbar region. This should post a delayed show 3230 // Move the mouse over the scrollbar region. This should post a delayed fade
3236 // task. Execute it to show the scrollbars. 3231 // in task. Execute it to show the scrollbars.
3237 { 3232 {
3238 animation_task_ = base::Closure(); 3233 animation_task_ = base::Closure();
3239 scrollbar_controller->DidMouseMoveNear(VERTICAL, 0); 3234 scrollbar_controller->DidMouseMoveNear(VERTICAL, 0);
3240 ASSERT_FALSE(animation_task_.Equals(base::Closure())); 3235 ASSERT_FALSE(animation_task_.Equals(base::Closure()));
3241 ASSERT_FALSE(animation_task_.IsCancelled()); 3236 ASSERT_FALSE(animation_task_.IsCancelled());
3242 } 3237 }
3243 3238
3244 // The show task should cause the scrollbars to show. Ensure that we 3239 // The fade in task should cause the scrollbars to show. Ensure that we
3245 // requested a redraw and a commit. 3240 // requested a redraw and a commit.
3246 { 3241 {
3247 did_request_redraw_ = false; 3242 did_request_redraw_ = false;
3248 did_request_commit_ = false; 3243 did_request_commit_ = false;
3249 ASSERT_TRUE(scrollbar_controller->ScrollbarsHidden()); 3244 ASSERT_TRUE(scrollbar_controller->ScrollbarsHidden());
3250 animation_task_.Run(); 3245 animation_task_.Run();
3246
3247 base::TimeTicks fake_now = base::TimeTicks::Now();
3248 scrollbar_controller->Animate(fake_now);
3249 fake_now += settings.scrollbar_fade_duration;
3250 scrollbar_controller->Animate(fake_now);
3251
3251 ASSERT_FALSE(scrollbar_controller->ScrollbarsHidden()); 3252 ASSERT_FALSE(scrollbar_controller->ScrollbarsHidden());
3252 EXPECT_TRUE(did_request_redraw_); 3253 EXPECT_TRUE(did_request_redraw_);
3253 EXPECT_TRUE(did_request_commit_); 3254 EXPECT_TRUE(did_request_commit_);
3254 } 3255 }
3255 } 3256 }
3256 3257
3257 TEST_F(LayerTreeHostImplTest, ScrollbarInnerLargerThanOuter) { 3258 TEST_F(LayerTreeHostImplTest, ScrollbarInnerLargerThanOuter) {
3258 LayerTreeSettings settings = DefaultSettings(); 3259 LayerTreeSettings settings = DefaultSettings();
3259 CreateHostImpl(settings, CreateCompositorFrameSink()); 3260 CreateHostImpl(settings, CreateCompositorFrameSink());
3260 3261
(...skipping 23 matching lines...) Expand all
3284 child->SetBounds(inner_viewport_size); 3285 child->SetBounds(inner_viewport_size);
3285 3286
3286 horiz_scrollbar->SetScrollLayerId(root_scroll->id()); 3287 horiz_scrollbar->SetScrollLayerId(root_scroll->id());
3287 3288
3288 EXPECT_EQ(300, horiz_scrollbar->clip_layer_length()); 3289 EXPECT_EQ(300, horiz_scrollbar->clip_layer_length());
3289 } 3290 }
3290 3291
3291 TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) { 3292 TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) {
3292 LayerTreeSettings settings = DefaultSettings(); 3293 LayerTreeSettings settings = DefaultSettings();
3293 settings.scrollbar_animator = LayerTreeSettings::ANDROID_OVERLAY; 3294 settings.scrollbar_animator = LayerTreeSettings::ANDROID_OVERLAY;
3294 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20); 3295 settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(20);
3295 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(20); 3296 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20);
3296 settings.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(20);
3297 CreateHostImpl(settings, CreateCompositorFrameSink()); 3297 CreateHostImpl(settings, CreateCompositorFrameSink());
3298 3298
3299 gfx::Size viewport_size(300, 200); 3299 gfx::Size viewport_size(300, 200);
3300 gfx::Size content_size(1000, 1000); 3300 gfx::Size content_size(1000, 1000);
3301 3301
3302 const int vert_1_id = 10; 3302 const int vert_1_id = 10;
3303 const int horiz_1_id = 11; 3303 const int horiz_1_id = 11;
3304 const int vert_2_id = 12; 3304 const int vert_2_id = 12;
3305 const int horiz_2_id = 13; 3305 const int horiz_2_id = 13;
3306 const int child_clip_id = 14; 3306 const int child_clip_id = 14;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3406 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset( 3406 host_impl_->active_tree()->InnerViewportScrollLayer()->SetCurrentScrollOffset(
3407 gfx::ScrollOffset(20, 20)); 3407 gfx::ScrollOffset(20, 20));
3408 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 3408 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
3409 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(20, 20)); 3409 child_ptr->SetCurrentScrollOffset(gfx::ScrollOffset(20, 20));
3410 EXPECT_TRUE(animation_task_.Equals(base::Closure())); 3410 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
3411 } 3411 }
3412 3412
3413 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( 3413 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
3414 float device_scale_factor) { 3414 float device_scale_factor) {
3415 LayerTreeSettings settings = DefaultSettings(); 3415 LayerTreeSettings settings = DefaultSettings();
3416 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(500); 3416 settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(500);
3417 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(500); 3417 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
3418 settings.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(300);
3419 settings.scrollbar_animator = LayerTreeSettings::AURA_OVERLAY; 3418 settings.scrollbar_animator = LayerTreeSettings::AURA_OVERLAY;
3420 3419
3421 gfx::Size viewport_size(300, 200); 3420 gfx::Size viewport_size(300, 200);
3422 gfx::Size device_viewport_size = 3421 gfx::Size device_viewport_size =
3423 gfx::ScaleToFlooredSize(viewport_size, device_scale_factor); 3422 gfx::ScaleToFlooredSize(viewport_size, device_scale_factor);
3424 gfx::Size content_size(1000, 1000); 3423 gfx::Size content_size(1000, 1000);
3425 gfx::Size scrollbar_size(gfx::Size(15, viewport_size.height())); 3424 gfx::Size scrollbar_size(gfx::Size(15, viewport_size.height()));
3426 3425
3427 CreateHostImpl(settings, CreateCompositorFrameSink()); 3426 CreateHostImpl(settings, CreateCompositorFrameSink());
3428 host_impl_->active_tree()->SetDeviceScaleFactor(device_scale_factor); 3427 host_impl_->active_tree()->SetDeviceScaleFactor(device_scale_factor);
(...skipping 8598 matching lines...) Expand 10 before | Expand all | Expand 10 after
12027 12026
12028 // Re-initialize with a software output surface. 12027 // Re-initialize with a software output surface.
12029 compositor_frame_sink_ = FakeCompositorFrameSink::CreateSoftware(); 12028 compositor_frame_sink_ = FakeCompositorFrameSink::CreateSoftware();
12030 host_impl_->InitializeRenderer(compositor_frame_sink_.get()); 12029 host_impl_->InitializeRenderer(compositor_frame_sink_.get());
12031 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); 12030 EXPECT_FALSE(host_impl_->use_gpu_rasterization());
12032 } 12031 }
12033 12032
12034 void LayerTreeHostImplTest::SetupMouseMoveAtTestScrollbarStates( 12033 void LayerTreeHostImplTest::SetupMouseMoveAtTestScrollbarStates(
12035 bool main_thread_scrolling) { 12034 bool main_thread_scrolling) {
12036 LayerTreeSettings settings = DefaultSettings(); 12035 LayerTreeSettings settings = DefaultSettings();
12037 settings.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(500); 12036 settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(500);
12038 settings.scrollbar_fade_out_delay = base::TimeDelta::FromMilliseconds(500); 12037 settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300);
12039 settings.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(300);
12040 settings.scrollbar_animator = LayerTreeSettings::AURA_OVERLAY; 12038 settings.scrollbar_animator = LayerTreeSettings::AURA_OVERLAY;
12041 12039
12042 gfx::Size viewport_size(300, 200); 12040 gfx::Size viewport_size(300, 200);
12043 gfx::Size content_size(1000, 1000); 12041 gfx::Size content_size(1000, 1000);
12044 gfx::Size child_layer_size(250, 150); 12042 gfx::Size child_layer_size(250, 150);
12045 gfx::Size scrollbar_size_1(gfx::Size(15, viewport_size.height())); 12043 gfx::Size scrollbar_size_1(gfx::Size(15, viewport_size.height()));
12046 gfx::Size scrollbar_size_2(gfx::Size(15, child_layer_size.height())); 12044 gfx::Size scrollbar_size_2(gfx::Size(15, child_layer_size.height()));
12047 12045
12048 const int scrollbar_1_id = 10; 12046 const int scrollbar_1_id = 10;
12049 const int scrollbar_2_id = 11; 12047 const int scrollbar_2_id = 11;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
12298 else 12296 else
12299 EXPECT_FALSE(tile->HasRasterTask()); 12297 EXPECT_FALSE(tile->HasRasterTask());
12300 } 12298 }
12301 Region expected_invalidation( 12299 Region expected_invalidation(
12302 raster_source->GetRectForImage(checkerable_image->uniqueID())); 12300 raster_source->GetRectForImage(checkerable_image->uniqueID()));
12303 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); 12301 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation()));
12304 } 12302 }
12305 12303
12306 } // namespace 12304 } // namespace
12307 } // namespace cc 12305 } // 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