| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/input/single_scrollbar_animation_controller_thinning.h" | 5 #include "cc/input/single_scrollbar_animation_controller_thinning.h" |
| 6 | 6 |
| 7 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 7 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| 8 #include "cc/test/fake_impl_task_runner_provider.h" | 8 #include "cc/test/fake_impl_task_runner_provider.h" |
| 9 #include "cc/test/fake_layer_tree_host_impl.h" | 9 #include "cc/test/fake_layer_tree_host_impl.h" |
| 10 #include "cc/test/geometry_test_utils.h" | 10 #include "cc/test/geometry_test_utils.h" |
| 11 #include "cc/test/test_task_graph_runner.h" | 11 #include "cc/test/test_task_graph_runner.h" |
| 12 #include "cc/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using testing::AtLeast; | 16 using testing::AtLeast; |
| 17 using testing::Mock; | 17 using testing::Mock; |
| 18 using testing::NiceMock; | 18 using testing::NiceMock; |
| 19 using testing::_; | 19 using testing::_; |
| 20 | 20 |
| 21 namespace cc { | 21 namespace cc { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const float kIdleThicknessScale = | 24 const float kIdleThicknessScale = |
| 25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale; | 25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale; |
| 26 const float kDefaultMouseMoveDistanceToTriggerAnimation = | 26 const float kMouseMoveDistanceToTriggerExpand = |
| 27 SingleScrollbarAnimationControllerThinning:: | 27 SingleScrollbarAnimationControllerThinning:: |
| 28 kDefaultMouseMoveDistanceToTriggerAnimation; | 28 kMouseMoveDistanceToTriggerExpand; |
| 29 const float kMouseMoveDistanceToTriggerFadeIn = |
| 30 ScrollbarAnimationController::kMouseMoveDistanceToTriggerFadeIn; |
| 29 | 31 |
| 30 class MockSingleScrollbarAnimationControllerClient | 32 class MockSingleScrollbarAnimationControllerClient |
| 31 : public ScrollbarAnimationControllerClient { | 33 : public ScrollbarAnimationControllerClient { |
| 32 public: | 34 public: |
| 33 explicit MockSingleScrollbarAnimationControllerClient( | 35 explicit MockSingleScrollbarAnimationControllerClient( |
| 34 LayerTreeHostImpl* host_impl) | 36 LayerTreeHostImpl* host_impl) |
| 35 : host_impl_(host_impl) {} | 37 : host_impl_(host_impl) {} |
| 36 virtual ~MockSingleScrollbarAnimationControllerClient() {} | 38 virtual ~MockSingleScrollbarAnimationControllerClient() {} |
| 37 | 39 |
| 38 ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override { | 40 ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 67 LayerImpl::Create(host_impl_.active_tree(), 3); | 69 LayerImpl::Create(host_impl_.active_tree(), 3); |
| 68 scroll_layer->SetElementId( | 70 scroll_layer->SetElementId( |
| 69 LayerIdToElementIdForTesting(scroll_layer->id())); | 71 LayerIdToElementIdForTesting(scroll_layer->id())); |
| 70 clip_layer_ = clip.get(); | 72 clip_layer_ = clip.get(); |
| 71 scroll_layer->SetScrollClipLayer(clip_layer_->id()); | 73 scroll_layer->SetScrollClipLayer(clip_layer_->id()); |
| 72 LayerImpl* scroll_layer_ptr = scroll_layer.get(); | 74 LayerImpl* scroll_layer_ptr = scroll_layer.get(); |
| 73 | 75 |
| 74 const int kId = 2; | 76 const int kId = 2; |
| 75 const int kThumbThickness = 10; | 77 const int kThumbThickness = 10; |
| 76 const int kTrackStart = 0; | 78 const int kTrackStart = 0; |
| 79 const int kTrackLength = 100; |
| 77 const bool kIsLeftSideVerticalScrollbar = false; | 80 const bool kIsLeftSideVerticalScrollbar = false; |
| 78 const bool kIsOverlayScrollbar = true; | 81 const bool kIsOverlayScrollbar = true; |
| 79 | 82 |
| 80 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = | 83 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
| 81 SolidColorScrollbarLayerImpl::Create( | 84 SolidColorScrollbarLayerImpl::Create( |
| 82 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, | 85 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, |
| 83 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 86 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
| 84 scrollbar_layer_ = scrollbar.get(); | 87 scrollbar_layer_ = scrollbar.get(); |
| 85 | 88 |
| 86 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); | 89 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); |
| 87 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); | 90 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); |
| 88 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 91 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
| 89 | 92 |
| 93 scrollbar_layer_->SetBounds(gfx::Size(kThumbThickness, kTrackLength)); |
| 94 scrollbar_layer_->SetPosition(gfx::PointF(90, 0)); |
| 90 scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); | 95 scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); |
| 91 scrollbar_layer_->test_properties()->opacity_can_animate = true; | 96 scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 92 clip_layer_->SetBounds(gfx::Size(100, 100)); | 97 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 93 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 98 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 94 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 99 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 95 | 100 |
| 96 scrollbar_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 101 scrollbar_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
| 97 scroll_layer_ptr->element_id(), HORIZONTAL, &client_, | 102 scroll_layer_ptr->element_id(), HORIZONTAL, &client_, |
| 98 kThinningDuration); | 103 kThinningDuration); |
| 99 } | 104 } |
| 100 | 105 |
| 101 FakeImplTaskRunnerProvider task_runner_provider_; | 106 FakeImplTaskRunnerProvider task_runner_provider_; |
| 102 TestTaskGraphRunner task_graph_runner_; | 107 TestTaskGraphRunner task_graph_runner_; |
| 103 FakeLayerTreeHostImpl host_impl_; | 108 FakeLayerTreeHostImpl host_impl_; |
| 104 std::unique_ptr<SingleScrollbarAnimationControllerThinning> | 109 std::unique_ptr<SingleScrollbarAnimationControllerThinning> |
| 105 scrollbar_controller_; | 110 scrollbar_controller_; |
| 106 LayerImpl* clip_layer_; | 111 LayerImpl* clip_layer_; |
| 107 SolidColorScrollbarLayerImpl* scrollbar_layer_; | 112 SolidColorScrollbarLayerImpl* scrollbar_layer_; |
| 108 NiceMock<MockSingleScrollbarAnimationControllerClient> client_; | 113 NiceMock<MockSingleScrollbarAnimationControllerClient> client_; |
| 109 }; | 114 }; |
| 110 | 115 |
| 116 // Return a point with given offset from the top-left of scrollbar. |
| 117 gfx::PointF NearScrollbar(float offset_x, float offset_y) { |
| 118 gfx::PointF p(90, 0); |
| 119 p.Offset(offset_x, offset_y); |
| 120 return p; |
| 121 } |
| 122 |
| 111 // Check initialization of scrollbar. Should start thin. | 123 // Check initialization of scrollbar. Should start thin. |
| 112 TEST_F(SingleScrollbarAnimationControllerThinningTest, Idle) { | 124 TEST_F(SingleScrollbarAnimationControllerThinningTest, Idle) { |
| 113 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 125 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 114 scrollbar_layer_->thumb_thickness_scale_factor()); | 126 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 115 } | 127 } |
| 116 | 128 |
| 117 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when | 129 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when |
| 118 // moved away. | 130 // moved away. |
| 119 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseNear) { | 131 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseNear) { |
| 120 base::TimeTicks time; | 132 base::TimeTicks time; |
| 121 time += base::TimeDelta::FromSeconds(1); | 133 time += base::TimeDelta::FromSeconds(1); |
| 122 | 134 |
| 123 scrollbar_controller_->DidMouseMoveNear(1); | 135 scrollbar_controller_->DidMouseMove(NearScrollbar(-1, 0)); |
| 124 scrollbar_controller_->Animate(time); | 136 scrollbar_controller_->Animate(time); |
| 125 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 137 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 126 scrollbar_layer_->thumb_thickness_scale_factor()); | 138 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 127 | 139 |
| 128 // Should animate to thickened. | 140 // Should animate to thickened. |
| 129 time += kThinningDuration; | 141 time += kThinningDuration; |
| 130 scrollbar_controller_->Animate(time); | 142 scrollbar_controller_->Animate(time); |
| 131 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 143 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 132 | 144 |
| 133 // Subsequent moves within the nearness threshold should not change anything. | 145 // Subsequent moves within the nearness threshold should not change anything. |
| 134 scrollbar_controller_->DidMouseMoveNear(2); | 146 scrollbar_controller_->DidMouseMove(NearScrollbar(-2, 0)); |
| 135 scrollbar_controller_->Animate(time); | 147 scrollbar_controller_->Animate(time); |
| 136 time += base::TimeDelta::FromSeconds(10); | 148 time += base::TimeDelta::FromSeconds(10); |
| 137 scrollbar_controller_->Animate(time); | 149 scrollbar_controller_->Animate(time); |
| 138 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 150 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 139 | 151 |
| 140 // Now move away from bar. | 152 // Now move away from thumb. |
| 141 scrollbar_controller_->DidMouseMoveNear( | 153 scrollbar_controller_->DidMouseMove( |
| 142 kDefaultMouseMoveDistanceToTriggerAnimation); | 154 NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0)); |
| 143 scrollbar_controller_->Animate(time); | 155 scrollbar_controller_->Animate(time); |
| 144 time += kThinningDuration; | 156 time += kThinningDuration; |
| 145 scrollbar_controller_->Animate(time); | 157 scrollbar_controller_->Animate(time); |
| 158 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 159 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 160 |
| 161 // Move away from track. |
| 162 scrollbar_controller_->DidMouseMove( |
| 163 NearScrollbar(-kMouseMoveDistanceToTriggerFadeIn, 0)); |
| 164 scrollbar_controller_->Animate(time); |
| 165 time += kThinningDuration; |
| 166 scrollbar_controller_->Animate(time); |
| 146 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 167 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 147 scrollbar_layer_->thumb_thickness_scale_factor()); | 168 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 148 } | 169 } |
| 149 | 170 |
| 150 // Move the pointer over the scrollbar. Make sure it gets thick that it gets | 171 // Move the pointer over the scrollbar. Make sure it gets thick that it gets |
| 151 // thin when moved away. | 172 // thin when moved away. |
| 152 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseOver) { | 173 TEST_F(SingleScrollbarAnimationControllerThinningTest, MouseOver) { |
| 153 base::TimeTicks time; | 174 base::TimeTicks time; |
| 154 time += base::TimeDelta::FromSeconds(1); | 175 time += base::TimeDelta::FromSeconds(1); |
| 155 | 176 |
| 156 scrollbar_controller_->DidMouseMoveNear(0); | 177 scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0)); |
| 157 scrollbar_controller_->Animate(time); | 178 scrollbar_controller_->Animate(time); |
| 158 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 179 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 159 scrollbar_layer_->thumb_thickness_scale_factor()); | 180 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 160 | 181 |
| 161 // Should animate to thickened. | 182 // Should animate to thickened. |
| 162 time += kThinningDuration; | 183 time += kThinningDuration; |
| 163 scrollbar_controller_->Animate(time); | 184 scrollbar_controller_->Animate(time); |
| 164 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 185 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 165 | 186 |
| 166 // Subsequent moves should not change anything. | 187 // Subsequent moves should not change anything. |
| 167 scrollbar_controller_->DidMouseMoveNear(0); | 188 scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0)); |
| 168 scrollbar_controller_->Animate(time); | 189 scrollbar_controller_->Animate(time); |
| 169 time += base::TimeDelta::FromSeconds(10); | 190 time += base::TimeDelta::FromSeconds(10); |
| 170 scrollbar_controller_->Animate(time); | 191 scrollbar_controller_->Animate(time); |
| 171 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 192 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 172 | 193 |
| 173 // Moving off the scrollbar but still withing the "near" threshold should do | 194 // Moving off the scrollbar but still withing the "near" threshold should do |
| 174 // nothing. | 195 // nothing. |
| 175 scrollbar_controller_->DidMouseMoveNear( | 196 scrollbar_controller_->DidMouseMove( |
| 176 kDefaultMouseMoveDistanceToTriggerAnimation - 1.f); | 197 NearScrollbar(-kMouseMoveDistanceToTriggerExpand + 1, 0)); |
| 177 scrollbar_controller_->Animate(time); | 198 scrollbar_controller_->Animate(time); |
| 178 time += base::TimeDelta::FromSeconds(10); | 199 time += base::TimeDelta::FromSeconds(10); |
| 179 scrollbar_controller_->Animate(time); | 200 scrollbar_controller_->Animate(time); |
| 180 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 201 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 181 | 202 |
| 182 // Now move away from bar. | 203 // Now move away from thumb. |
| 183 scrollbar_controller_->DidMouseMoveNear( | 204 scrollbar_controller_->DidMouseMove( |
| 184 kDefaultMouseMoveDistanceToTriggerAnimation); | 205 NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0)); |
| 185 scrollbar_controller_->Animate(time); | 206 scrollbar_controller_->Animate(time); |
| 186 time += kThinningDuration; | 207 time += kThinningDuration; |
| 187 scrollbar_controller_->Animate(time); | 208 scrollbar_controller_->Animate(time); |
| 188 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 209 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 189 scrollbar_layer_->thumb_thickness_scale_factor()); | 210 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 190 } | 211 } |
| 191 | 212 |
| 192 // First move the pointer over the scrollbar off of it. Make sure the thinning | 213 // First move the pointer over the scrollbar off of it. Make sure the thinning |
| 193 // animation kicked off in DidMouseMoveOffScrollbar gets overridden by the | 214 // animation kicked off in DidMouseMoveOffScrollbar gets overridden by the |
| 194 // thickening animation in the DidMouseMoveNear call. | 215 // thickening animation in the DidMouseMove call. |
| 195 TEST_F(SingleScrollbarAnimationControllerThinningTest, | 216 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 196 MouseNearThenAwayWhileAnimating) { | 217 MouseNearThenAwayWhileAnimating) { |
| 197 base::TimeTicks time; | 218 base::TimeTicks time; |
| 198 time += base::TimeDelta::FromSeconds(1); | 219 time += base::TimeDelta::FromSeconds(1); |
| 199 | 220 |
| 200 scrollbar_controller_->DidMouseMoveNear(0); | 221 scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0)); |
| 201 scrollbar_controller_->Animate(time); | 222 scrollbar_controller_->Animate(time); |
| 202 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 223 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 203 scrollbar_layer_->thumb_thickness_scale_factor()); | 224 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 204 | 225 |
| 205 // Should animate to thickened. | 226 // Should animate to thickened. |
| 206 time += kThinningDuration; | 227 time += kThinningDuration; |
| 207 scrollbar_controller_->Animate(time); | 228 scrollbar_controller_->Animate(time); |
| 208 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 229 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 209 | 230 |
| 210 // This is tricky. The DidMouseLeave() is sent before the | 231 // This is tricky. The DidMouseLeave() is sent before the |
| 211 // subsequent DidMouseMoveNear(), if the mouse moves in that direction. | 232 // subsequent DidMouseMove(), if the mouse moves in that direction. |
| 212 // This results in the thumb thinning. We want to make sure that when the | 233 // This results in the thumb thinning. We want to make sure that when the |
| 213 // thumb starts expanding it doesn't first narrow to the idle thinness. | 234 // thumb starts expanding it doesn't first narrow to the idle thinness. |
| 214 time += base::TimeDelta::FromSeconds(1); | 235 time += base::TimeDelta::FromSeconds(1); |
| 215 scrollbar_controller_->DidMouseLeave(); | 236 scrollbar_controller_->DidMouseLeave(); |
| 216 scrollbar_controller_->Animate(time); | 237 scrollbar_controller_->Animate(time); |
| 217 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 238 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 218 | 239 |
| 219 // Let the animation run half of the way through the thinning animation. | 240 // Let the animation run half of the way through the thinning animation. |
| 220 time += kThinningDuration / 2; | 241 time += kThinningDuration / 2; |
| 221 scrollbar_controller_->Animate(time); | 242 scrollbar_controller_->Animate(time); |
| 222 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 243 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 223 scrollbar_layer_->thumb_thickness_scale_factor()); | 244 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 224 | 245 |
| 225 // Now we get a notification for the mouse moving over the scroller. The | 246 // Now we get a notification for the mouse moving over the scroller. The |
| 226 // animation is reset to the thickening direction but we won't start | 247 // animation is reset to the thickening direction but we won't start |
| 227 // thickening until the new animation catches up to the current thickness. | 248 // thickening until the new animation catches up to the current thickness. |
| 228 scrollbar_controller_->DidMouseMoveNear(1); | 249 scrollbar_controller_->DidMouseMove(NearScrollbar(-1, 0)); |
| 229 scrollbar_controller_->Animate(time); | 250 scrollbar_controller_->Animate(time); |
| 230 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 251 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 231 scrollbar_layer_->thumb_thickness_scale_factor()); | 252 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 232 | 253 |
| 233 // Until we reach the half way point, the animation will have no effect. | 254 // Until we reach the half way point, the animation will have no effect. |
| 234 time += kThinningDuration / 4; | 255 time += kThinningDuration / 4; |
| 235 scrollbar_controller_->Animate(time); | 256 scrollbar_controller_->Animate(time); |
| 236 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 257 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 237 scrollbar_layer_->thumb_thickness_scale_factor()); | 258 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 238 | 259 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 256 | 277 |
| 257 // First move the pointer on the scrollbar, then press it, then away. | 278 // First move the pointer on the scrollbar, then press it, then away. |
| 258 // Confirm that the bar gets thick. Then mouse up. Confirm that | 279 // Confirm that the bar gets thick. Then mouse up. Confirm that |
| 259 // the bar gets thin. | 280 // the bar gets thin. |
| 260 TEST_F(SingleScrollbarAnimationControllerThinningTest, | 281 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 261 MouseCaptureAndReleaseOutOfBar) { | 282 MouseCaptureAndReleaseOutOfBar) { |
| 262 base::TimeTicks time; | 283 base::TimeTicks time; |
| 263 time += base::TimeDelta::FromSeconds(1); | 284 time += base::TimeDelta::FromSeconds(1); |
| 264 | 285 |
| 265 // Move over the scrollbar. | 286 // Move over the scrollbar. |
| 266 scrollbar_controller_->DidMouseMoveNear(0); | 287 scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0)); |
| 267 scrollbar_controller_->Animate(time); | 288 scrollbar_controller_->Animate(time); |
| 268 time += kThinningDuration; | 289 time += kThinningDuration; |
| 269 scrollbar_controller_->Animate(time); | 290 scrollbar_controller_->Animate(time); |
| 270 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 291 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 271 | 292 |
| 272 // Capture | 293 // Capture |
| 273 scrollbar_controller_->DidMouseDown(); | 294 scrollbar_controller_->DidMouseDown(); |
| 274 time += base::TimeDelta::FromSeconds(1); | 295 time += base::TimeDelta::FromSeconds(1); |
| 275 scrollbar_controller_->Animate(time); | 296 scrollbar_controller_->Animate(time); |
| 276 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 297 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 277 | 298 |
| 278 // Should stay thick for a while. | 299 // Should stay thick for a while. |
| 279 time += base::TimeDelta::FromSeconds(10); | 300 time += base::TimeDelta::FromSeconds(10); |
| 280 scrollbar_controller_->Animate(time); | 301 scrollbar_controller_->Animate(time); |
| 281 | 302 |
| 282 // Move outside the "near" threshold. Because the scrollbar is captured it | 303 // Move outside the "near" threshold. Because the scrollbar is captured it |
| 283 // should remain thick. | 304 // should remain thick. |
| 284 scrollbar_controller_->DidMouseMoveNear( | 305 scrollbar_controller_->DidMouseMove( |
| 285 kDefaultMouseMoveDistanceToTriggerAnimation); | 306 NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0)); |
| 286 time += kThinningDuration; | 307 time += kThinningDuration; |
| 287 scrollbar_controller_->Animate(time); | 308 scrollbar_controller_->Animate(time); |
| 288 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 309 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 289 | 310 |
| 290 // Release. | 311 // Release. |
| 291 scrollbar_controller_->DidMouseUp(); | 312 scrollbar_controller_->DidMouseUp(); |
| 292 | 313 |
| 293 // Should become thin. | 314 // Should become thin. |
| 294 time += base::TimeDelta::FromSeconds(1); | 315 time += base::TimeDelta::FromSeconds(1); |
| 295 scrollbar_controller_->Animate(time); | 316 scrollbar_controller_->Animate(time); |
| 296 time += kThinningDuration; | 317 time += kThinningDuration; |
| 297 scrollbar_controller_->Animate(time); | 318 scrollbar_controller_->Animate(time); |
| 298 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 319 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 299 scrollbar_layer_->thumb_thickness_scale_factor()); | 320 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 300 } | 321 } |
| 301 | 322 |
| 302 // First move the pointer on the scrollbar, then press it, then away. Confirm | 323 // First move the pointer on the scrollbar, then press it, then away. Confirm |
| 303 // that the bar gets thick. Then move point on the scrollbar and mouse up. | 324 // that the bar gets thick. Then move point on the scrollbar and mouse up. |
| 304 // Confirm that the bar stays thick. | 325 // Confirm that the bar stays thick. |
| 305 TEST_F(SingleScrollbarAnimationControllerThinningTest, | 326 TEST_F(SingleScrollbarAnimationControllerThinningTest, |
| 306 MouseCaptureAndReleaseOnBar) { | 327 MouseCaptureAndReleaseOnBar) { |
| 307 base::TimeTicks time; | 328 base::TimeTicks time; |
| 308 time += base::TimeDelta::FromSeconds(1); | 329 time += base::TimeDelta::FromSeconds(1); |
| 309 | 330 |
| 310 // Move over scrollbar. | 331 // Move over scrollbar. |
| 311 scrollbar_controller_->DidMouseMoveNear(0); | 332 scrollbar_controller_->DidMouseMove(NearScrollbar(0, 0)); |
| 312 scrollbar_controller_->Animate(time); | 333 scrollbar_controller_->Animate(time); |
| 313 time += kThinningDuration; | 334 time += kThinningDuration; |
| 314 scrollbar_controller_->Animate(time); | 335 scrollbar_controller_->Animate(time); |
| 315 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 336 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 316 | 337 |
| 317 // Capture. Nothing should change. | 338 // Capture. Nothing should change. |
| 318 scrollbar_controller_->DidMouseDown(); | 339 scrollbar_controller_->DidMouseDown(); |
| 319 time += base::TimeDelta::FromSeconds(1); | 340 time += base::TimeDelta::FromSeconds(1); |
| 320 scrollbar_controller_->Animate(time); | 341 scrollbar_controller_->Animate(time); |
| 321 time += base::TimeDelta::FromSeconds(10); | 342 time += base::TimeDelta::FromSeconds(10); |
| 322 scrollbar_controller_->Animate(time); | 343 scrollbar_controller_->Animate(time); |
| 323 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 344 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 324 | 345 |
| 325 // Move away from scrollbar. Nothing should change. | 346 // Move away from scrollbar. Nothing should change. |
| 326 scrollbar_controller_->DidMouseMoveNear( | 347 scrollbar_controller_->DidMouseMove( |
| 327 kDefaultMouseMoveDistanceToTriggerAnimation); | 348 NearScrollbar(kMouseMoveDistanceToTriggerExpand, 0)); |
| 328 time += base::TimeDelta::FromSeconds(1); | 349 time += base::TimeDelta::FromSeconds(1); |
| 329 scrollbar_controller_->Animate(time); | 350 scrollbar_controller_->Animate(time); |
| 330 time += base::TimeDelta::FromSeconds(10); | 351 time += base::TimeDelta::FromSeconds(10); |
| 331 scrollbar_controller_->Animate(time); | 352 scrollbar_controller_->Animate(time); |
| 332 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 353 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 333 | 354 |
| 334 // Move over scrollbar and release. Since we're near the scrollbar, it should | 355 // Move over scrollbar and release. Since we're near the scrollbar, it should |
| 335 // remain thick. | 356 // remain thick. |
| 336 scrollbar_controller_->DidMouseMoveNear(0); | 357 scrollbar_controller_->DidMouseMove( |
| 358 NearScrollbar(-kMouseMoveDistanceToTriggerExpand + 1, 0)); |
| 337 scrollbar_controller_->DidMouseUp(); | 359 scrollbar_controller_->DidMouseUp(); |
| 338 time += base::TimeDelta::FromSeconds(1); | 360 time += base::TimeDelta::FromSeconds(1); |
| 339 scrollbar_controller_->Animate(time); | 361 scrollbar_controller_->Animate(time); |
| 340 time += base::TimeDelta::FromSeconds(10); | 362 time += base::TimeDelta::FromSeconds(10); |
| 341 scrollbar_controller_->Animate(time); | 363 scrollbar_controller_->Animate(time); |
| 342 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 364 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 343 } | 365 } |
| 344 | 366 |
| 345 // Tests that the thickening/thinning effects are animated. | 367 // Tests that the thickening/thinning effects are animated. |
| 346 TEST_F(SingleScrollbarAnimationControllerThinningTest, ThicknessAnimated) { | 368 TEST_F(SingleScrollbarAnimationControllerThinningTest, ThicknessAnimated) { |
| 347 base::TimeTicks time; | 369 base::TimeTicks time; |
| 348 time += base::TimeDelta::FromSeconds(1); | 370 time += base::TimeDelta::FromSeconds(1); |
| 349 | 371 |
| 350 // Move mouse near scrollbar. Test that at half the duration time, the | 372 // Move mouse near scrollbar. Test that at half the duration time, the |
| 351 // thickness is half way through its animation. | 373 // thickness is half way through its animation. |
| 352 scrollbar_controller_->DidMouseMoveNear(1); | 374 scrollbar_controller_->DidMouseMove(NearScrollbar(-1, 0)); |
| 353 scrollbar_controller_->Animate(time); | 375 scrollbar_controller_->Animate(time); |
| 354 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 376 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 355 scrollbar_layer_->thumb_thickness_scale_factor()); | 377 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 356 | 378 |
| 357 time += kThinningDuration / 2; | 379 time += kThinningDuration / 2; |
| 358 scrollbar_controller_->Animate(time); | 380 scrollbar_controller_->Animate(time); |
| 359 EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2.0f, | 381 EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2.0f, |
| 360 scrollbar_layer_->thumb_thickness_scale_factor()); | 382 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 361 | 383 |
| 362 time += kThinningDuration / 2; | 384 time += kThinningDuration / 2; |
| 363 scrollbar_controller_->Animate(time); | 385 scrollbar_controller_->Animate(time); |
| 364 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 386 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 365 | 387 |
| 366 // Move mouse away from scrollbar. Same check. | 388 // Move mouse away from scrollbar. Same check. |
| 367 time += base::TimeDelta::FromSeconds(1); | 389 time += base::TimeDelta::FromSeconds(1); |
| 368 scrollbar_controller_->DidMouseMoveNear( | 390 scrollbar_controller_->DidMouseMove( |
| 369 kDefaultMouseMoveDistanceToTriggerAnimation); | 391 NearScrollbar(-kMouseMoveDistanceToTriggerExpand, 0)); |
| 370 scrollbar_controller_->Animate(time); | 392 scrollbar_controller_->Animate(time); |
| 371 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 393 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 372 | 394 |
| 373 time += kThinningDuration / 2; | 395 time += kThinningDuration / 2; |
| 374 scrollbar_controller_->Animate(time); | 396 scrollbar_controller_->Animate(time); |
| 375 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, | 397 EXPECT_FLOAT_EQ(1.0f - (1.0f - kIdleThicknessScale) / 2.0f, |
| 376 scrollbar_layer_->thumb_thickness_scale_factor()); | 398 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 377 | 399 |
| 378 time += kThinningDuration / 2; | 400 time += kThinningDuration / 2; |
| 379 scrollbar_controller_->Animate(time); | 401 scrollbar_controller_->Animate(time); |
| 380 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 402 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 381 scrollbar_layer_->thumb_thickness_scale_factor()); | 403 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 382 } | 404 } |
| 383 | 405 |
| 384 } // namespace | 406 } // namespace |
| 385 } // namespace cc | 407 } // namespace cc |
| OLD | NEW |