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 2968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2979 EXPECT_EQ(current_offset.ToString(), | 2979 EXPECT_EQ(current_offset.ToString(), |
2980 scroll_layer->TotalScrollOffset().ToString()); | 2980 scroll_layer->TotalScrollOffset().ToString()); |
2981 } | 2981 } |
2982 | 2982 |
2983 TEST_F(LayerTreeHostImplTest, OverscrollRoot) { | 2983 TEST_F(LayerTreeHostImplTest, OverscrollRoot) { |
2984 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2984 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
2985 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 2985 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
2986 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 2986 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
2987 DrawFrame(); | 2987 DrawFrame(); |
2988 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2988 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
| 2989 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
2989 | 2990 |
2990 // In-bounds scrolling does not affect overscroll. | 2991 // In-bounds scrolling does not affect overscroll. |
2991 EXPECT_EQ(InputHandler::ScrollStarted, | 2992 EXPECT_EQ(InputHandler::ScrollStarted, |
2992 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 2993 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
2993 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 2994 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
2994 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 2995 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
| 2996 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
2995 | 2997 |
2996 // Overscroll events are reflected immediately. | 2998 // Overscroll events are reflected immediately. |
2997 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 50)); | 2999 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 50)); |
2998 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); | 3000 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); |
| 3001 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
2999 | 3002 |
3000 // In-bounds scrolling resets accumulated overscroll for the scrolled axes. | 3003 // In-bounds scrolling resets accumulated overscroll for the scrolled axes. |
3001 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -50)); | 3004 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -50)); |
3002 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); | 3005 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); |
3003 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10)); | 3006 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -10)); |
3004 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3007 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
3005 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, 0)); | 3008 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, 0)); |
3006 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3009 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
3007 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-15, 0)); | 3010 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(-15, 0)); |
3008 EXPECT_EQ(gfx::Vector2dF(-5, -10), host_impl_->accumulated_root_overscroll()); | 3011 EXPECT_EQ(gfx::Vector2dF(-5, -10), host_impl_->accumulated_root_overscroll()); |
3009 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 60)); | 3012 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 60)); |
3010 EXPECT_EQ(gfx::Vector2dF(-5, 10), host_impl_->accumulated_root_overscroll()); | 3013 EXPECT_EQ(gfx::Vector2dF(-5, 10), host_impl_->accumulated_root_overscroll()); |
3011 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, -60)); | 3014 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(10, -60)); |
3012 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3015 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
3013 | 3016 |
3014 // Overscroll accumulates within the scope of ScrollBegin/ScrollEnd as long | 3017 // Overscroll accumulates within the scope of ScrollBegin/ScrollEnd as long |
3015 // as no scroll occurs. | 3018 // as no scroll occurs. |
3016 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 3019 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
3017 EXPECT_EQ(gfx::Vector2dF(0, -30), host_impl_->accumulated_root_overscroll()); | 3020 EXPECT_EQ(gfx::Vector2dF(0, -30), host_impl_->accumulated_root_overscroll()); |
3018 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 3021 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
3019 EXPECT_EQ(gfx::Vector2dF(0, -50), host_impl_->accumulated_root_overscroll()); | 3022 EXPECT_EQ(gfx::Vector2dF(0, -50), host_impl_->accumulated_root_overscroll()); |
3020 // Overscroll resets on valid scroll. | 3023 // Overscroll resets on valid scroll. |
3021 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 3024 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
3022 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); | 3025 EXPECT_EQ(gfx::Vector2dF(0, 0), host_impl_->accumulated_root_overscroll()); |
3023 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); | 3026 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
3024 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); | 3027 EXPECT_EQ(gfx::Vector2dF(0, -10), host_impl_->accumulated_root_overscroll()); |
3025 host_impl_->ScrollEnd(); | 3028 host_impl_->ScrollEnd(); |
| 3029 |
| 3030 EXPECT_EQ(InputHandler::ScrollStarted, |
| 3031 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
| 3032 // Fling velocity is reflected immediately. |
| 3033 host_impl_->NotifyCurrentFlingVelocity(gfx::Vector2dF(10, 0)); |
| 3034 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); |
| 3035 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, -20)); |
| 3036 EXPECT_EQ(gfx::Vector2dF(0, -20), host_impl_->accumulated_root_overscroll()); |
| 3037 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); |
3026 } | 3038 } |
3027 | 3039 |
3028 | 3040 |
3029 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { | 3041 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { |
3030 // Scroll child layers beyond their maximum scroll range and make sure root | 3042 // Scroll child layers beyond their maximum scroll range and make sure root |
3031 // overscroll does not accumulate. | 3043 // overscroll does not accumulate. |
3032 gfx::Size surface_size(10, 10); | 3044 gfx::Size surface_size(10, 10); |
3033 scoped_ptr<LayerImpl> root_clip = | 3045 scoped_ptr<LayerImpl> root_clip = |
3034 LayerImpl::Create(host_impl_->active_tree(), 4); | 3046 LayerImpl::Create(host_impl_->active_tree(), 4); |
3035 scoped_ptr<LayerImpl> root = | 3047 scoped_ptr<LayerImpl> root = |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3068 host_impl_->ScrollBegin(gfx::Point(5, 5), | 3080 host_impl_->ScrollBegin(gfx::Point(5, 5), |
3069 InputHandler::NonBubblingGesture)); | 3081 InputHandler::NonBubblingGesture)); |
3070 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); | 3082 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
3071 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3083 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
3072 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 3084 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
3073 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_layer); | 3085 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_layer); |
3074 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3086 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
3075 host_impl_->ScrollEnd(); | 3087 host_impl_->ScrollEnd(); |
3076 | 3088 |
3077 // After scrolling the parent, another scroll on the opposite direction | 3089 // After scrolling the parent, another scroll on the opposite direction |
3078 // should scroll the child. | 3090 // should scroll the child, resetting the fling velocity. |
3079 scroll_delta = gfx::Vector2d(0, 70); | 3091 scroll_delta = gfx::Vector2d(0, 70); |
| 3092 host_impl_->NotifyCurrentFlingVelocity(gfx::Vector2dF(10, 0)); |
| 3093 EXPECT_EQ(gfx::Vector2dF(10, 0), host_impl_->current_fling_velocity()); |
3080 EXPECT_EQ(InputHandler::ScrollStarted, | 3094 EXPECT_EQ(InputHandler::ScrollStarted, |
3081 host_impl_->ScrollBegin(gfx::Point(5, 5), | 3095 host_impl_->ScrollBegin(gfx::Point(5, 5), |
3082 InputHandler::NonBubblingGesture)); | 3096 InputHandler::NonBubblingGesture)); |
3083 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); | 3097 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
3084 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 3098 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
3085 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); | 3099 EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); |
3086 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3100 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
| 3101 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
3087 host_impl_->ScrollEnd(); | 3102 host_impl_->ScrollEnd(); |
3088 } | 3103 } |
3089 } | 3104 } |
3090 | 3105 |
3091 TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { | 3106 TEST_F(LayerTreeHostImplTest, OverscrollChildEventBubbling) { |
3092 // When we try to scroll a non-scrollable child layer, the scroll delta | 3107 // When we try to scroll a non-scrollable child layer, the scroll delta |
3093 // should be applied to one of its ancestors if possible. Overscroll should | 3108 // should be applied to one of its ancestors if possible. Overscroll should |
3094 // be reflected only when it has bubbled up to the root scrolling layer. | 3109 // be reflected only when it has bubbled up to the root scrolling layer. |
3095 gfx::Size surface_size(10, 10); | 3110 gfx::Size surface_size(10, 10); |
3096 gfx::Size content_size(20, 20); | 3111 gfx::Size content_size(20, 20); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3130 LayerTreeSettings settings; | 3145 LayerTreeSettings settings; |
3131 CreateHostImpl(settings, CreateOutputSurface()); | 3146 CreateHostImpl(settings, CreateOutputSurface()); |
3132 | 3147 |
3133 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); | 3148 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(50, 50)); |
3134 LayerImpl* clip_layer = scroll_layer->parent()->parent(); | 3149 LayerImpl* clip_layer = scroll_layer->parent()->parent(); |
3135 clip_layer->SetBounds(gfx::Size(50, 50)); | 3150 clip_layer->SetBounds(gfx::Size(50, 50)); |
3136 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 3151 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
3137 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); | 3152 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f); |
3138 DrawFrame(); | 3153 DrawFrame(); |
3139 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); | 3154 EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); |
| 3155 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
3140 | 3156 |
3141 // Even though the layer can't scroll the overscroll still happens. | 3157 // Even though the layer can't scroll the overscroll still happens. |
3142 EXPECT_EQ(InputHandler::ScrollStarted, | 3158 EXPECT_EQ(InputHandler::ScrollStarted, |
3143 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 3159 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
3144 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 3160 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
3145 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); | 3161 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); |
| 3162 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
3146 } | 3163 } |
3147 | 3164 |
3148 TEST_F(LayerTreeHostImplTest, UnnecessaryGlowEffectCallsWhileScrollingUp) { | 3165 TEST_F(LayerTreeHostImplTest, UnnecessaryGlowEffectCallsWhileScrollingUp) { |
3149 // Edge glow effect should be applicable only upon reaching Edges | 3166 // Edge glow effect should be applicable only upon reaching Edges |
3150 // of the content. unnecessary glow effect calls shouldn't be | 3167 // of the content. unnecessary glow effect calls shouldn't be |
3151 // called while scrolling up without reaching the edge of the content. | 3168 // called while scrolling up without reaching the edge of the content. |
3152 gfx::Size surface_size(100, 100); | 3169 gfx::Size surface_size(100, 100); |
3153 gfx::Size content_size(200, 200); | 3170 gfx::Size content_size(200, 200); |
3154 scoped_ptr<LayerImpl> root_clip = | 3171 scoped_ptr<LayerImpl> root_clip = |
3155 LayerImpl::Create(host_impl_->active_tree(), 3); | 3172 LayerImpl::Create(host_impl_->active_tree(), 3); |
(...skipping 3068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6224 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, | 6241 EXPECT_EQ(host_impl_->global_tile_state().hard_memory_limit_in_bytes, |
6225 300u * 1024u * 1024u); | 6242 300u * 1024u * 1024u); |
6226 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, | 6243 EXPECT_EQ(host_impl_->global_tile_state().soft_memory_limit_in_bytes, |
6227 150u * 1024u * 1024u); | 6244 150u * 1024u * 1024u); |
6228 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes, | 6245 EXPECT_EQ(host_impl_->global_tile_state().unused_memory_limit_in_bytes, |
6229 75u * 1024u * 1024u); | 6246 75u * 1024u * 1024u); |
6230 } | 6247 } |
6231 | 6248 |
6232 } // namespace | 6249 } // namespace |
6233 } // namespace cc | 6250 } // namespace cc |
OLD | NEW |