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 <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 2994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3005 EXPECT_EQ(current_offset.ToString(), | 3005 EXPECT_EQ(current_offset.ToString(), |
3006 scroll_layer->TotalScrollOffset().ToString()); | 3006 scroll_layer->TotalScrollOffset().ToString()); |
3007 } | 3007 } |
3008 | 3008 |
3009 TEST_F(LayerTreeHostImplTest, OverscrollRoot) { | 3009 TEST_F(LayerTreeHostImplTest, OverscrollRoot) { |
3010 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 3010 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
3011 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 3011 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
3012 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 3012 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
3013 DrawFrame(); | 3013 DrawFrame(); |
3014 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3014 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
3015 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | |
3016 | 3015 |
3017 // In-bounds scrolling does not affect overscroll. | 3016 // In-bounds scrolling does not affect overscroll. |
3018 EXPECT_EQ(InputHandler::ScrollStarted, | 3017 EXPECT_EQ(InputHandler::ScrollStarted, |
3019 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 3018 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
3020 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 3019 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
3021 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3020 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
3022 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | |
3023 | 3021 |
3024 // Overscroll events are reflected immediately. | 3022 // Overscroll events are reflected immediately. |
3025 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 50)); | 3023 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 50)); |
3026 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); | 3024 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); |
3027 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | |
3028 | 3025 |
3029 // In-bounds scrolling resets accumulated overscroll for the scrolled axes. | 3026 // In-bounds scrolling resets accumulated overscroll for the scrolled axes. |
3030 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -50)); | 3027 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -50)); |
3031 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); | 3028 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); |
3032 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10)); | 3029 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10)); |
3033 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3030 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
3034 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, 0)); | 3031 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, 0)); |
3035 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3032 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
3036 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-15, 0)); | 3033 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-15, 0)); |
3037 EXPECT_EQ(gfx::Vector2dF(-5, -10), host_impl_->accumulated_root_overscroll()); | 3034 EXPECT_EQ(gfx::Vector2dF(-5, -10), host_impl_->accumulated_root_overscroll()); |
3038 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 60)); | 3035 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 60)); |
3039 EXPECT_EQ(gfx::Vector2dF(-5, 10), host_impl_->accumulated_root_overscroll()); | 3036 EXPECT_EQ(gfx::Vector2dF(-5, 10), host_impl_->accumulated_root_overscroll()); |
3040 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, -60)); | 3037 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, -60)); |
3041 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3038 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
3042 | 3039 |
3043 // Overscroll accumulates within the scope of ScrollBegin/ScrollEnd as long | 3040 // Overscroll accumulates within the scope of ScrollBegin/ScrollEnd as long |
3044 // as no scroll occurs. | 3041 // as no scroll occurs. |
3045 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 3042 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
3046 EXPECT_EQ(gfx::Vector2dF(0, -30), host_impl_->accumulated_root_overscroll()); | 3043 EXPECT_EQ(gfx::Vector2dF(0, -30), host_impl_->accumulated_root_overscroll()); |
3047 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 3044 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
3048 EXPECT_EQ(gfx::Vector2dF(0, -50), host_impl_->accumulated_root_overscroll()); | 3045 EXPECT_EQ(gfx::Vector2dF(0, -50), host_impl_->accumulated_root_overscroll()); |
3049 // Overscroll resets on valid scroll. | 3046 // Overscroll resets on valid scroll. |
3050 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 3047 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
3051 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); | 3048 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); |
3052 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 3049 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
3053 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3050 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
3054 host_impl_->ScrollEnd(); | 3051 host_impl_->ScrollEnd(); |
3055 | |
3056 EXPECT_EQ(InputHandler::ScrollStarted, | |
3057 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | |
3058 // Fling velocity is reflected immediately. | |
3059 host_impl_->NotifyCurrentFlingVelocity(gfx::Vector2dF(10, 0)); | |
3060 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); | |
3061 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | |
3062 EXPECT_EQ(gfx::Vector2dF(0, -20), host_impl_->accumulated_root_overscroll()); | |
3063 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); | |
3064 } | 3052 } |
3065 | 3053 |
3066 | 3054 |
3067 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { | 3055 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { |
3068 // Scroll child layers beyond their maximum scroll range and make sure root | 3056 // Scroll child layers beyond their maximum scroll range and make sure root |
3069 // overscroll does not accumulate. | 3057 // overscroll does not accumulate. |
3070 gfx::Size surface_size(10, 10); | 3058 gfx::Size surface_size(10, 10); |
3071 scoped_ptr<LayerImpl> root_clip = | 3059 scoped_ptr<LayerImpl> root_clip = |
3072 LayerImpl::Create(host_impl_->active_tree(), 4); | 3060 LayerImpl::Create(host_impl_->active_tree(), 4); |
3073 scoped_ptr<LayerImpl> root = | 3061 scoped_ptr<LayerImpl> root = |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3106 host_impl_->ScrollBegin(gfx::Point(5, 5), | 3094 host_impl_->ScrollBegin(gfx::Point(5, 5), |
3107 InputHandler::NonBubblingGesture)); | 3095 InputHandler::NonBubblingGesture)); |
3108 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); | 3096 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
3109 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3097 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
3110 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 3098 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
3111 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_layer); | 3099 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_layer); |
3112 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3100 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
3113 host_impl_->ScrollEnd(); | 3101 host_impl_->ScrollEnd(); |
3114 | 3102 |
3115 // After scrolling the parent, another scroll on the opposite direction | 3103 // After scrolling the parent, another scroll on the opposite direction |
3116 // should scroll the child, resetting the fling velocity. | 3104 // should scroll the child. |
3117 scroll_delta = gfx::Vector2d(0, 70); | 3105 scroll_delta = gfx::Vector2d(0, 70); |
3118 host_impl_->NotifyCurrentFlingVelocity(gfx::Vector2dF(10, 0)); | |
3119 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); | |
3120 EXPECT_EQ(InputHandler::ScrollStarted, | 3106 EXPECT_EQ(InputHandler::ScrollStarted, |
3121 host_impl_->ScrollBegin(gfx::Point(5, 5), | 3107 host_impl_->ScrollBegin(gfx::Point(5, 5), |
3122 InputHandler::NonBubblingGesture)); | 3108 InputHandler::NonBubblingGesture)); |
3123 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); | 3109 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
3124 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 3110 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
3125 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); | 3111 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
3126 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3112 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
3127 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | |
3128 host_impl_->ScrollEnd(); | 3113 host_impl_->ScrollEnd(); |
3129 } | 3114 } |
3130 } | 3115 } |
3131 | 3116 |
3132 TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { | 3117 TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { |
3133 // When we try to scroll a non-scrollable child layer, the scroll delta | 3118 // When we try to scroll a non-scrollable child layer, the scroll delta |
3134 // should be applied to one of its ancestors if possible. Overscroll should | 3119 // should be applied to one of its ancestors if possible. Overscroll should |
3135 // be reflected only when it has bubbled up to the root scrolling layer. | 3120 // be reflected only when it has bubbled up to the root scrolling layer. |
3136 gfx::Size surface_size(10, 10); | 3121 gfx::Size surface_size(10, 10); |
3137 gfx::Size content_size(20, 20); | 3122 gfx::Size content_size(20, 20); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3171 LayerTreeSettings settings; | 3156 LayerTreeSettings settings; |
3172 CreateHostImpl(settings, CreateOutputSurface()); | 3157 CreateHostImpl(settings, CreateOutputSurface()); |
3173 | 3158 |
3174 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); | 3159 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); |
3175 LayerImpl* clip_layer = scroll_layer->parent()->parent(); | 3160 LayerImpl* clip_layer = scroll_layer->parent()->parent(); |
3176 clip_layer->SetBounds(gfx::Size(50, 50)); | 3161 clip_layer->SetBounds(gfx::Size(50, 50)); |
3177 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 3162 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
3178 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 3163 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
3179 DrawFrame(); | 3164 DrawFrame(); |
3180 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3165 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
3181 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | |
3182 | 3166 |
3183 // Even though the layer can't scroll the overscroll still happens. | 3167 // Even though the layer can't scroll the overscroll still happens. |
3184 EXPECT_EQ(InputHandler::ScrollStarted, | 3168 EXPECT_EQ(InputHandler::ScrollStarted, |
3185 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 3169 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
3186 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 3170 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
3187 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); | 3171 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); |
3188 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | |
3189 } | 3172 } |
3190 | 3173 |
3191 TEST_F(LayerTreeHostImplTest, UnnecessaryGlowEffectCallsWhileScrollingUp) { | 3174 TEST_F(LayerTreeHostImplTest, UnnecessaryGlowEffectCallsWhileScrollingUp) { |
3192 // Edge glow effect should be applicable only upon reaching Edges | 3175 // Edge glow effect should be applicable only upon reaching Edges |
3193 // of the content. unnecessary glow effect calls shouldn't be | 3176 // of the content. unnecessary glow effect calls shouldn't be |
3194 // called while scrolling up without reaching the edge of the content. | 3177 // called while scrolling up without reaching the edge of the content. |
3195 gfx::Size surface_size(100, 100); | 3178 gfx::Size surface_size(100, 100); |
3196 gfx::Size content_size(200, 200); | 3179 gfx::Size content_size(200, 200); |
3197 scoped_ptr<LayerImpl> root_clip = | 3180 scoped_ptr<LayerImpl> root_clip = |
3198 LayerImpl::Create(host_impl_->active_tree(), 3); | 3181 LayerImpl::Create(host_impl_->active_tree(), 3); |
(...skipping 3068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6267 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, | 6250 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, |
6268 300u * 1024u * 1024u); | 6251 300u * 1024u * 1024u); |
6269 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, | 6252 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, |
6270 150u * 1024u * 1024u); | 6253 150u * 1024u * 1024u); |
6271 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes, | 6254 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes, |
6272 75u * 1024u * 1024u); | 6255 75u * 1024u * 1024u); |
6273 } | 6256 } |
6274 | 6257 |
6275 } // namespace | 6258 } // namespace |
6276 } // namespace cc | 6259 } // namespace cc |
OLD | NEW |