| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/scrollbar_animation_controller.h" | 5 #include "cc/input/scrollbar_animation_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "cc/trees/layer_tree_impl.h" | 10 #include "cc/trees/layer_tree_impl.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 : client_(client), | 46 : client_(client), |
| 47 fade_out_delay_(fade_out_delay), | 47 fade_out_delay_(fade_out_delay), |
| 48 fade_out_resize_delay_(fade_out_resize_delay), | 48 fade_out_resize_delay_(fade_out_resize_delay), |
| 49 need_trigger_scrollbar_show_(false), | 49 need_trigger_scrollbar_show_(false), |
| 50 is_animating_(false), | 50 is_animating_(false), |
| 51 scroll_layer_id_(scroll_layer_id), | 51 scroll_layer_id_(scroll_layer_id), |
| 52 currently_scrolling_(false), | 52 currently_scrolling_(false), |
| 53 scroll_gesture_has_scrolled_(false), | 53 scroll_gesture_has_scrolled_(false), |
| 54 opacity_(0.0f), | 54 opacity_(0.0f), |
| 55 fade_out_duration_(fade_out_duration), | 55 fade_out_duration_(fade_out_duration), |
| 56 show_scrollbars_on_scroll_gesture_(false), | |
| 57 need_thinning_animation_(false), | 56 need_thinning_animation_(false), |
| 58 weak_factory_(this) { | 57 weak_factory_(this) { |
| 59 ApplyOpacityToScrollbars(0.0f); | 58 ApplyOpacityToScrollbars(0.0f); |
| 60 } | 59 } |
| 61 | 60 |
| 62 ScrollbarAnimationController::ScrollbarAnimationController( | 61 ScrollbarAnimationController::ScrollbarAnimationController( |
| 63 int scroll_layer_id, | 62 int scroll_layer_id, |
| 64 ScrollbarAnimationControllerClient* client, | 63 ScrollbarAnimationControllerClient* client, |
| 65 base::TimeDelta show_delay, | 64 base::TimeDelta show_delay, |
| 66 base::TimeDelta fade_out_delay, | 65 base::TimeDelta fade_out_delay, |
| 67 base::TimeDelta fade_out_resize_delay, | 66 base::TimeDelta fade_out_resize_delay, |
| 68 base::TimeDelta fade_out_duration, | 67 base::TimeDelta fade_out_duration, |
| 69 base::TimeDelta thinning_duration) | 68 base::TimeDelta thinning_duration) |
| 70 : client_(client), | 69 : client_(client), |
| 71 show_delay_(show_delay), | 70 show_delay_(show_delay), |
| 72 fade_out_delay_(fade_out_delay), | 71 fade_out_delay_(fade_out_delay), |
| 73 fade_out_resize_delay_(fade_out_resize_delay), | 72 fade_out_resize_delay_(fade_out_resize_delay), |
| 74 need_trigger_scrollbar_show_(false), | 73 need_trigger_scrollbar_show_(false), |
| 75 is_animating_(false), | 74 is_animating_(false), |
| 76 scroll_layer_id_(scroll_layer_id), | 75 scroll_layer_id_(scroll_layer_id), |
| 77 currently_scrolling_(false), | 76 currently_scrolling_(false), |
| 78 scroll_gesture_has_scrolled_(false), | 77 scroll_gesture_has_scrolled_(false), |
| 79 opacity_(0.0f), | 78 opacity_(0.0f), |
| 80 fade_out_duration_(fade_out_duration), | 79 fade_out_duration_(fade_out_duration), |
| 81 show_scrollbars_on_scroll_gesture_(true), | |
| 82 need_thinning_animation_(true), | 80 need_thinning_animation_(true), |
| 83 weak_factory_(this) { | 81 weak_factory_(this) { |
| 84 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 82 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
| 85 scroll_layer_id, ScrollbarOrientation::VERTICAL, client, | 83 scroll_layer_id, ScrollbarOrientation::VERTICAL, client, |
| 86 thinning_duration); | 84 thinning_duration); |
| 87 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 85 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
| 88 scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client, | 86 scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client, |
| 89 thinning_duration); | 87 thinning_duration); |
| 90 ApplyOpacityToScrollbars(0.0f); | 88 ApplyOpacityToScrollbars(0.0f); |
| 91 } | 89 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return animated; | 159 return animated; |
| 162 } | 160 } |
| 163 | 161 |
| 164 float ScrollbarAnimationController::AnimationProgressAtTime( | 162 float ScrollbarAnimationController::AnimationProgressAtTime( |
| 165 base::TimeTicks now) { | 163 base::TimeTicks now) { |
| 166 base::TimeDelta delta = now - last_awaken_time_; | 164 base::TimeDelta delta = now - last_awaken_time_; |
| 167 float progress = delta.InSecondsF() / fade_out_duration_.InSecondsF(); | 165 float progress = delta.InSecondsF() / fade_out_duration_.InSecondsF(); |
| 168 return std::max(std::min(progress, 1.f), 0.f); | 166 return std::max(std::min(progress, 1.f), 0.f); |
| 169 } | 167 } |
| 170 | 168 |
| 169 void ScrollbarAnimationController::DidScrollBegin() { |
| 170 currently_scrolling_ = true; |
| 171 } |
| 172 |
| 171 void ScrollbarAnimationController::RunAnimationFrame(float progress) { | 173 void ScrollbarAnimationController::RunAnimationFrame(float progress) { |
| 172 ApplyOpacityToScrollbars(1.f - progress); | 174 ApplyOpacityToScrollbars(1.f - progress); |
| 173 if (progress == 1.f) | 175 if (progress == 1.f) |
| 174 StopAnimation(); | 176 StopAnimation(); |
| 175 } | 177 } |
| 176 | 178 |
| 177 void ScrollbarAnimationController::DidScrollBegin() { | 179 void ScrollbarAnimationController::DidScrollUpdate(bool on_resize) { |
| 178 currently_scrolling_ = true; | |
| 179 } | |
| 180 | |
| 181 void ScrollbarAnimationController::DidScrollEnd() { | |
| 182 bool has_scrolled = scroll_gesture_has_scrolled_; | |
| 183 scroll_gesture_has_scrolled_ = false; | |
| 184 | |
| 185 currently_scrolling_ = false; | |
| 186 | |
| 187 // We don't fade out scrollbar if they need thinning animation and mouse is | |
| 188 // near. | |
| 189 if (need_thinning_animation_ && MouseIsNearAnyScrollbar()) | |
| 190 return; | |
| 191 | |
| 192 if (has_scrolled) | |
| 193 PostDelayedFadeOut(false); | |
| 194 } | |
| 195 | |
| 196 void ScrollbarAnimationController::DidScrollUpdate() { | |
| 197 if (need_thinning_animation_ && Captured()) | 180 if (need_thinning_animation_ && Captured()) |
| 198 return; | 181 return; |
| 199 | 182 |
| 200 StopAnimation(); | 183 StopAnimation(); |
| 201 | 184 |
| 202 // As an optimization, we avoid spamming fade delay tasks during active fast | 185 // As an optimization, we avoid spamming fade delay tasks during active fast |
| 203 // scrolls. But if we're not within one, we need to post every scroll update. | 186 // scrolls. But if we're not within one, we need to post every scroll update. |
| 204 if (!currently_scrolling_) { | 187 if (!currently_scrolling_) { |
| 205 // We don't fade out scrollbar if they need thinning animation and mouse is | 188 // We don't fade out scrollbar if they need thinning animation and mouse is |
| 206 // near. | 189 // near. |
| 207 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) | 190 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) |
| 208 PostDelayedFadeOut(false); | 191 PostDelayedFadeOut(on_resize); |
| 209 } else { | 192 } else { |
| 210 scroll_gesture_has_scrolled_ = true; | 193 scroll_gesture_has_scrolled_ = true; |
| 211 } | 194 } |
| 212 | 195 |
| 213 Show(); | 196 Show(); |
| 214 | 197 |
| 215 if (need_thinning_animation_) { | 198 if (need_thinning_animation_) { |
| 216 vertical_controller_->UpdateThumbThicknessScale(); | 199 vertical_controller_->UpdateThumbThicknessScale(); |
| 217 horizontal_controller_->UpdateThumbThicknessScale(); | 200 horizontal_controller_->UpdateThumbThicknessScale(); |
| 218 } | 201 } |
| 219 } | 202 } |
| 220 | 203 |
| 221 void ScrollbarAnimationController::WillUpdateScroll() { | 204 void ScrollbarAnimationController::DidScrollEnd() { |
| 222 if (show_scrollbars_on_scroll_gesture_) | 205 bool has_scrolled = scroll_gesture_has_scrolled_; |
| 223 DidScrollUpdate(); | 206 scroll_gesture_has_scrolled_ = false; |
| 224 } | |
| 225 | 207 |
| 226 void ScrollbarAnimationController::DidResize() { | 208 currently_scrolling_ = false; |
| 227 StopAnimation(); | 209 |
| 228 Show(); | 210 // We don't fade out scrollbar if they need thinning animation and mouse is |
| 229 // We should use the gesture delay rather than the resize delay if we're in a | 211 // near. |
| 230 // gesture scroll, even if it is resizing. | 212 if (need_thinning_animation_ && MouseIsNearAnyScrollbar()) |
| 231 PostDelayedFadeOut(!currently_scrolling_); | 213 return; |
| 214 |
| 215 if (has_scrolled) |
| 216 PostDelayedFadeOut(false); |
| 232 } | 217 } |
| 233 | 218 |
| 234 void ScrollbarAnimationController::DidMouseDown() { | 219 void ScrollbarAnimationController::DidMouseDown() { |
| 235 if (!need_thinning_animation_ || ScrollbarsHidden()) | 220 if (!need_thinning_animation_ || ScrollbarsHidden()) |
| 236 return; | 221 return; |
| 237 | 222 |
| 238 vertical_controller_->DidMouseDown(); | 223 vertical_controller_->DidMouseDown(); |
| 239 horizontal_controller_->DidMouseDown(); | 224 horizontal_controller_->DidMouseDown(); |
| 240 } | 225 } |
| 241 | 226 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 if (opacity_ != opacity) | 364 if (opacity_ != opacity) |
| 380 client_->SetNeedsRedrawForScrollbarAnimation(); | 365 client_->SetNeedsRedrawForScrollbarAnimation(); |
| 381 | 366 |
| 382 opacity_ = opacity; | 367 opacity_ = opacity; |
| 383 | 368 |
| 384 if (previouslyVisible != currentlyVisible) | 369 if (previouslyVisible != currentlyVisible) |
| 385 client_->DidChangeScrollbarVisibility(); | 370 client_->DidChangeScrollbarVisibility(); |
| 386 } | 371 } |
| 387 | 372 |
| 388 } // namespace cc | 373 } // namespace cc |
| OLD | NEW |