| 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" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 | 13 |
| 14 std::unique_ptr<ScrollbarAnimationController> | 14 std::unique_ptr<ScrollbarAnimationController> |
| 15 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( | 15 ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( |
| 16 int scroll_layer_id, | 16 int scroll_layer_id, |
| 17 ScrollbarAnimationControllerClient* client, | 17 ScrollbarAnimationControllerClient* client, |
| 18 base::TimeDelta fade_out_delay, | 18 base::TimeDelta fade_out_delay, |
| 19 base::TimeDelta fade_out_resize_delay, | 19 base::TimeDelta fade_out_resize_delay, |
| 20 base::TimeDelta fade_out_duration) { | 20 base::TimeDelta fade_duration) { |
| 21 return base::WrapUnique(new ScrollbarAnimationController( | 21 return base::WrapUnique( |
| 22 scroll_layer_id, client, fade_out_delay, fade_out_resize_delay, | 22 new ScrollbarAnimationController(scroll_layer_id, client, fade_out_delay, |
| 23 fade_out_duration)); | 23 fade_out_resize_delay, fade_duration)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 std::unique_ptr<ScrollbarAnimationController> | 26 std::unique_ptr<ScrollbarAnimationController> |
| 27 ScrollbarAnimationController::CreateScrollbarAnimationControllerAuraOverlay( | 27 ScrollbarAnimationController::CreateScrollbarAnimationControllerAuraOverlay( |
| 28 int scroll_layer_id, | 28 int scroll_layer_id, |
| 29 ScrollbarAnimationControllerClient* client, | 29 ScrollbarAnimationControllerClient* client, |
| 30 base::TimeDelta show_delay, | 30 base::TimeDelta fade_in_delay, |
| 31 base::TimeDelta fade_out_delay, | 31 base::TimeDelta fade_out_delay, |
| 32 base::TimeDelta fade_out_resize_delay, | 32 base::TimeDelta fade_out_resize_delay, |
| 33 base::TimeDelta fade_out_duration, | 33 base::TimeDelta fade_duration, |
| 34 base::TimeDelta thinning_duration) { | 34 base::TimeDelta thinning_duration) { |
| 35 return base::WrapUnique(new ScrollbarAnimationController( | 35 return base::WrapUnique(new ScrollbarAnimationController( |
| 36 scroll_layer_id, client, show_delay, fade_out_delay, | 36 scroll_layer_id, client, fade_in_delay, fade_out_delay, |
| 37 fade_out_resize_delay, fade_out_duration, thinning_duration)); | 37 fade_out_resize_delay, fade_duration, thinning_duration)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 ScrollbarAnimationController::ScrollbarAnimationController( | 40 ScrollbarAnimationController::ScrollbarAnimationController( |
| 41 int scroll_layer_id, | 41 int scroll_layer_id, |
| 42 ScrollbarAnimationControllerClient* client, | 42 ScrollbarAnimationControllerClient* client, |
| 43 base::TimeDelta fade_out_delay, | 43 base::TimeDelta fade_out_delay, |
| 44 base::TimeDelta fade_out_resize_delay, | 44 base::TimeDelta fade_out_resize_delay, |
| 45 base::TimeDelta fade_out_duration) | 45 base::TimeDelta fade_duration) |
| 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 fade_duration_(fade_duration), |
| 49 need_trigger_scrollbar_show_(false), | 50 need_trigger_scrollbar_show_(false), |
| 50 is_animating_(false), | 51 is_animating_(false), |
| 52 animation_change_(NONE), |
| 51 scroll_layer_id_(scroll_layer_id), | 53 scroll_layer_id_(scroll_layer_id), |
| 52 currently_scrolling_(false), | 54 currently_scrolling_(false), |
| 53 show_in_fast_scroll_(false), | 55 show_in_fast_scroll_(false), |
| 54 opacity_(0.0f), | 56 opacity_(0.0f), |
| 55 fade_out_duration_(fade_out_duration), | |
| 56 show_scrollbars_on_scroll_gesture_(false), | 57 show_scrollbars_on_scroll_gesture_(false), |
| 57 need_thinning_animation_(false), | 58 need_thinning_animation_(false), |
| 58 weak_factory_(this) { | 59 weak_factory_(this) { |
| 59 ApplyOpacityToScrollbars(0.0f); | 60 ApplyOpacityToScrollbars(0.0f); |
| 60 } | 61 } |
| 61 | 62 |
| 62 ScrollbarAnimationController::ScrollbarAnimationController( | 63 ScrollbarAnimationController::ScrollbarAnimationController( |
| 63 int scroll_layer_id, | 64 int scroll_layer_id, |
| 64 ScrollbarAnimationControllerClient* client, | 65 ScrollbarAnimationControllerClient* client, |
| 65 base::TimeDelta show_delay, | 66 base::TimeDelta fade_in_delay, |
| 66 base::TimeDelta fade_out_delay, | 67 base::TimeDelta fade_out_delay, |
| 67 base::TimeDelta fade_out_resize_delay, | 68 base::TimeDelta fade_out_resize_delay, |
| 68 base::TimeDelta fade_out_duration, | 69 base::TimeDelta fade_duration, |
| 69 base::TimeDelta thinning_duration) | 70 base::TimeDelta thinning_duration) |
| 70 : client_(client), | 71 : client_(client), |
| 71 show_delay_(show_delay), | 72 fade_in_delay_(fade_in_delay), |
| 72 fade_out_delay_(fade_out_delay), | 73 fade_out_delay_(fade_out_delay), |
| 73 fade_out_resize_delay_(fade_out_resize_delay), | 74 fade_out_resize_delay_(fade_out_resize_delay), |
| 75 fade_duration_(fade_duration), |
| 74 need_trigger_scrollbar_show_(false), | 76 need_trigger_scrollbar_show_(false), |
| 75 is_animating_(false), | 77 is_animating_(false), |
| 78 animation_change_(NONE), |
| 76 scroll_layer_id_(scroll_layer_id), | 79 scroll_layer_id_(scroll_layer_id), |
| 77 currently_scrolling_(false), | 80 currently_scrolling_(false), |
| 78 show_in_fast_scroll_(false), | 81 show_in_fast_scroll_(false), |
| 79 opacity_(0.0f), | 82 opacity_(0.0f), |
| 80 fade_out_duration_(fade_out_duration), | |
| 81 show_scrollbars_on_scroll_gesture_(true), | 83 show_scrollbars_on_scroll_gesture_(true), |
| 82 need_thinning_animation_(true), | 84 need_thinning_animation_(true), |
| 83 weak_factory_(this) { | 85 weak_factory_(this) { |
| 84 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 86 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
| 85 scroll_layer_id, ScrollbarOrientation::VERTICAL, client, | 87 scroll_layer_id, ScrollbarOrientation::VERTICAL, client, |
| 86 thinning_duration); | 88 thinning_duration); |
| 87 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create( | 89 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create( |
| 88 scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client, | 90 scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client, |
| 89 thinning_duration); | 91 thinning_duration); |
| 90 ApplyOpacityToScrollbars(0.0f); | 92 ApplyOpacityToScrollbars(0.0f); |
| 91 } | 93 } |
| 92 | 94 |
| 93 ScrollbarAnimationController::~ScrollbarAnimationController() {} | 95 ScrollbarAnimationController::~ScrollbarAnimationController() {} |
| 94 | 96 |
| 95 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { | 97 ScrollbarSet ScrollbarAnimationController::Scrollbars() const { |
| 96 return client_->ScrollbarsFor(scroll_layer_id_); | 98 return client_->ScrollbarsFor(scroll_layer_id_); |
| 97 } | 99 } |
| 98 | 100 |
| 99 SingleScrollbarAnimationControllerThinning& | 101 SingleScrollbarAnimationControllerThinning& |
| 100 ScrollbarAnimationController::GetScrollbarAnimationController( | 102 ScrollbarAnimationController::GetScrollbarAnimationController( |
| 101 ScrollbarOrientation orientation) const { | 103 ScrollbarOrientation orientation) const { |
| 102 DCHECK(need_thinning_animation_); | 104 DCHECK(need_thinning_animation_); |
| 103 if (orientation == ScrollbarOrientation::VERTICAL) | 105 if (orientation == ScrollbarOrientation::VERTICAL) |
| 104 return *(vertical_controller_.get()); | 106 return *(vertical_controller_.get()); |
| 105 else | 107 else |
| 106 return *(horizontal_controller_.get()); | 108 return *(horizontal_controller_.get()); |
| 107 } | 109 } |
| 108 | 110 |
| 109 void ScrollbarAnimationController::StartAnimation() { | 111 void ScrollbarAnimationController::StartAnimation() { |
| 110 delayed_scrollbar_show_.Cancel(); | 112 DCHECK(animation_change_ != NONE); |
| 111 delayed_scrollbar_fade_out_.Cancel(); | 113 delayed_scrollbar_animation_.Cancel(); |
| 112 is_animating_ = true; | 114 is_animating_ = true; |
| 113 last_awaken_time_ = base::TimeTicks(); | 115 last_awaken_time_ = base::TimeTicks(); |
| 114 client_->SetNeedsAnimateForScrollbarAnimation(); | 116 client_->SetNeedsAnimateForScrollbarAnimation(); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void ScrollbarAnimationController::StopAnimation() { | 119 void ScrollbarAnimationController::StopAnimation() { |
| 118 delayed_scrollbar_show_.Cancel(); | 120 delayed_scrollbar_animation_.Cancel(); |
| 119 delayed_scrollbar_fade_out_.Cancel(); | |
| 120 is_animating_ = false; | 121 is_animating_ = false; |
| 122 animation_change_ = NONE; |
| 121 } | 123 } |
| 122 | 124 |
| 123 void ScrollbarAnimationController::PostDelayedShow() { | 125 void ScrollbarAnimationController::PostDelayedAnimation( |
| 124 DCHECK(delayed_scrollbar_fade_out_.IsCancelled()); | 126 AnimationChange animation_change, |
| 125 delayed_scrollbar_show_.Cancel(); | 127 bool on_resize) { |
| 126 delayed_scrollbar_show_.Reset(base::Bind(&ScrollbarAnimationController::Show, | 128 animation_change_ = animation_change; |
| 127 weak_factory_.GetWeakPtr())); | |
| 128 client_->PostDelayedScrollbarAnimationTask(delayed_scrollbar_show_.callback(), | |
| 129 show_delay_); | |
| 130 } | |
| 131 | 129 |
| 132 void ScrollbarAnimationController::PostDelayedFadeOut(bool on_resize) { | 130 base::TimeDelta delay; |
| 133 DCHECK(delayed_scrollbar_show_.IsCancelled()); | 131 if (animation_change == FADE_IN) { |
| 134 base::TimeDelta delay = on_resize ? fade_out_resize_delay_ : fade_out_delay_; | 132 delay = fade_in_delay_; |
| 135 delayed_scrollbar_fade_out_.Cancel(); | 133 } else { |
| 136 delayed_scrollbar_fade_out_.Reset( | 134 delay = on_resize ? fade_out_resize_delay_ : fade_out_delay_; |
| 135 } |
| 136 |
| 137 delayed_scrollbar_animation_.Cancel(); |
| 138 delayed_scrollbar_animation_.Reset( |
| 137 base::Bind(&ScrollbarAnimationController::StartAnimation, | 139 base::Bind(&ScrollbarAnimationController::StartAnimation, |
| 138 weak_factory_.GetWeakPtr())); | 140 weak_factory_.GetWeakPtr())); |
| 139 client_->PostDelayedScrollbarAnimationTask( | 141 client_->PostDelayedScrollbarAnimationTask( |
| 140 delayed_scrollbar_fade_out_.callback(), delay); | 142 delayed_scrollbar_animation_.callback(), delay); |
| 141 } | 143 } |
| 142 | 144 |
| 143 bool ScrollbarAnimationController::Animate(base::TimeTicks now) { | 145 bool ScrollbarAnimationController::Animate(base::TimeTicks now) { |
| 144 bool animated = false; | 146 bool animated = false; |
| 145 | 147 |
| 146 if (is_animating_) { | 148 if (is_animating_) { |
| 149 DCHECK(animation_change_ != NONE); |
| 147 if (last_awaken_time_.is_null()) | 150 if (last_awaken_time_.is_null()) |
| 148 last_awaken_time_ = now; | 151 last_awaken_time_ = now; |
| 149 | 152 |
| 150 float progress = AnimationProgressAtTime(now); | 153 float progress = AnimationProgressAtTime(now); |
| 151 RunAnimationFrame(progress); | 154 RunAnimationFrame(progress); |
| 152 | 155 |
| 153 if (is_animating_) | 156 if (is_animating_) |
| 154 client_->SetNeedsAnimateForScrollbarAnimation(); | 157 client_->SetNeedsAnimateForScrollbarAnimation(); |
| 155 animated = true; | 158 animated = true; |
| 156 } | 159 } |
| 157 | 160 |
| 158 if (need_thinning_animation_) { | 161 if (need_thinning_animation_) { |
| 159 animated |= vertical_controller_->Animate(now); | 162 animated |= vertical_controller_->Animate(now); |
| 160 animated |= horizontal_controller_->Animate(now); | 163 animated |= horizontal_controller_->Animate(now); |
| 161 } | 164 } |
| 162 | 165 |
| 163 return animated; | 166 return animated; |
| 164 } | 167 } |
| 165 | 168 |
| 166 float ScrollbarAnimationController::AnimationProgressAtTime( | 169 float ScrollbarAnimationController::AnimationProgressAtTime( |
| 167 base::TimeTicks now) { | 170 base::TimeTicks now) { |
| 168 base::TimeDelta delta = now - last_awaken_time_; | 171 base::TimeDelta delta = now - last_awaken_time_; |
| 169 float progress = delta.InSecondsF() / fade_out_duration_.InSecondsF(); | 172 float progress = delta.InSecondsF() / fade_duration_.InSecondsF(); |
| 170 return std::max(std::min(progress, 1.f), 0.f); | 173 return std::max(std::min(progress, 1.f), 0.f); |
| 171 } | 174 } |
| 172 | 175 |
| 173 void ScrollbarAnimationController::RunAnimationFrame(float progress) { | 176 void ScrollbarAnimationController::RunAnimationFrame(float progress) { |
| 174 ApplyOpacityToScrollbars(1.f - progress); | 177 float opacity; |
| 178 |
| 179 DCHECK(animation_change_ != NONE); |
| 180 if (animation_change_ == FADE_IN) { |
| 181 opacity = std::max(progress, opacity_); |
| 182 } else { |
| 183 opacity = std::min(1.f - progress, opacity_); |
| 184 } |
| 185 |
| 186 ApplyOpacityToScrollbars(opacity); |
| 175 if (progress == 1.f) | 187 if (progress == 1.f) |
| 176 StopAnimation(); | 188 StopAnimation(); |
| 177 } | 189 } |
| 178 | 190 |
| 179 void ScrollbarAnimationController::DidScrollBegin() { | 191 void ScrollbarAnimationController::DidScrollBegin() { |
| 180 currently_scrolling_ = true; | 192 currently_scrolling_ = true; |
| 181 } | 193 } |
| 182 | 194 |
| 183 void ScrollbarAnimationController::DidScrollEnd() { | 195 void ScrollbarAnimationController::DidScrollEnd() { |
| 184 bool has_scrolled = show_in_fast_scroll_; | 196 bool has_scrolled = show_in_fast_scroll_; |
| 185 show_in_fast_scroll_ = false; | 197 show_in_fast_scroll_ = false; |
| 186 | 198 |
| 187 currently_scrolling_ = false; | 199 currently_scrolling_ = false; |
| 188 | 200 |
| 189 // We don't fade out scrollbar if they need thinning animation and mouse is | 201 // We don't fade out scrollbar if they need thinning animation and mouse is |
| 190 // near. | 202 // near. |
| 191 if (need_thinning_animation_ && MouseIsNearAnyScrollbar()) | 203 if (need_thinning_animation_ && MouseIsNearAnyScrollbar()) |
| 192 return; | 204 return; |
| 193 | 205 |
| 194 if (has_scrolled) | 206 if (has_scrolled) |
| 195 PostDelayedFadeOut(false); | 207 PostDelayedAnimation(FADE_OUT, false); |
| 196 } | 208 } |
| 197 | 209 |
| 198 void ScrollbarAnimationController::DidScrollUpdate() { | 210 void ScrollbarAnimationController::DidScrollUpdate() { |
| 199 if (need_thinning_animation_ && Captured()) | 211 if (need_thinning_animation_ && Captured()) |
| 200 return; | 212 return; |
| 201 | 213 |
| 202 StopAnimation(); | 214 StopAnimation(); |
| 203 | 215 |
| 216 Show(); |
| 217 |
| 204 // As an optimization, we avoid spamming fade delay tasks during active fast | 218 // As an optimization, we avoid spamming fade delay tasks during active fast |
| 205 // scrolls. But if we're not within one, we need to post every scroll update. | 219 // scrolls. But if we're not within one, we need to post every scroll update. |
| 206 if (!currently_scrolling_) { | 220 if (!currently_scrolling_) { |
| 207 // We don't fade out scrollbar if they need thinning animation and mouse is | 221 // We don't fade out scrollbar if they need thinning animation and mouse is |
| 208 // near. | 222 // near. |
| 209 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) | 223 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) |
| 210 PostDelayedFadeOut(false); | 224 PostDelayedAnimation(FADE_OUT, false); |
| 211 } else { | 225 } else { |
| 212 show_in_fast_scroll_ = true; | 226 show_in_fast_scroll_ = true; |
| 213 } | 227 } |
| 214 | 228 |
| 215 Show(); | |
| 216 | |
| 217 if (need_thinning_animation_) { | 229 if (need_thinning_animation_) { |
| 218 vertical_controller_->UpdateThumbThicknessScale(); | 230 vertical_controller_->UpdateThumbThicknessScale(); |
| 219 horizontal_controller_->UpdateThumbThicknessScale(); | 231 horizontal_controller_->UpdateThumbThicknessScale(); |
| 220 } | 232 } |
| 221 } | 233 } |
| 222 | 234 |
| 223 void ScrollbarAnimationController::WillUpdateScroll() { | 235 void ScrollbarAnimationController::WillUpdateScroll() { |
| 224 if (show_scrollbars_on_scroll_gesture_) | 236 if (show_scrollbars_on_scroll_gesture_) |
| 225 DidScrollUpdate(); | 237 DidScrollUpdate(); |
| 226 } | 238 } |
| 227 | 239 |
| 228 void ScrollbarAnimationController::DidRequestShowFromMainThread() { | 240 void ScrollbarAnimationController::DidRequestShowFromMainThread() { |
| 229 DidScrollUpdate(); | 241 DidScrollUpdate(); |
| 230 } | 242 } |
| 231 | 243 |
| 232 void ScrollbarAnimationController::DidResize() { | 244 void ScrollbarAnimationController::DidResize() { |
| 233 StopAnimation(); | 245 StopAnimation(); |
| 234 Show(); | 246 Show(); |
| 235 | 247 |
| 236 // As an optimization, we avoid spamming fade delay tasks during active fast | 248 // As an optimization, we avoid spamming fade delay tasks during active fast |
| 237 // scrolls. | 249 // scrolls. |
| 238 if (!currently_scrolling_) { | 250 if (!currently_scrolling_) { |
| 239 PostDelayedFadeOut(true); | 251 PostDelayedAnimation(FADE_OUT, true); |
| 240 } else { | 252 } else { |
| 241 show_in_fast_scroll_ = true; | 253 show_in_fast_scroll_ = true; |
| 242 } | 254 } |
| 243 } | 255 } |
| 244 | 256 |
| 245 void ScrollbarAnimationController::DidMouseDown() { | 257 void ScrollbarAnimationController::DidMouseDown() { |
| 246 if (!need_thinning_animation_ || ScrollbarsHidden()) | 258 if (!need_thinning_animation_ || ScrollbarsHidden()) |
| 247 return; | 259 return; |
| 248 | 260 |
| 249 vertical_controller_->DidMouseDown(); | 261 vertical_controller_->DidMouseDown(); |
| 250 horizontal_controller_->DidMouseDown(); | 262 horizontal_controller_->DidMouseDown(); |
| 251 } | 263 } |
| 252 | 264 |
| 253 void ScrollbarAnimationController::DidMouseUp() { | 265 void ScrollbarAnimationController::DidMouseUp() { |
| 254 if (!need_thinning_animation_ || !Captured()) | 266 if (!need_thinning_animation_ || !Captured()) |
| 255 return; | 267 return; |
| 256 | 268 |
| 257 vertical_controller_->DidMouseUp(); | 269 vertical_controller_->DidMouseUp(); |
| 258 horizontal_controller_->DidMouseUp(); | 270 horizontal_controller_->DidMouseUp(); |
| 259 | 271 |
| 260 if (!MouseIsNearAnyScrollbar()) | 272 if (!MouseIsNearAnyScrollbar()) |
| 261 PostDelayedFadeOut(false); | 273 PostDelayedAnimation(FADE_OUT, false); |
| 262 } | 274 } |
| 263 | 275 |
| 264 void ScrollbarAnimationController::DidMouseLeave() { | 276 void ScrollbarAnimationController::DidMouseLeave() { |
| 265 if (!need_thinning_animation_) | 277 if (!need_thinning_animation_) |
| 266 return; | 278 return; |
| 267 | 279 |
| 268 vertical_controller_->DidMouseLeave(); | 280 vertical_controller_->DidMouseLeave(); |
| 269 horizontal_controller_->DidMouseLeave(); | 281 horizontal_controller_->DidMouseLeave(); |
| 270 | 282 |
| 271 delayed_scrollbar_show_.Cancel(); | 283 delayed_scrollbar_animation_.Cancel(); |
| 272 need_trigger_scrollbar_show_ = false; | 284 need_trigger_scrollbar_show_ = false; |
| 273 | 285 |
| 274 if (ScrollbarsHidden() || Captured()) | 286 if (ScrollbarsHidden() || Captured()) |
| 275 return; | 287 return; |
| 276 | 288 |
| 277 PostDelayedFadeOut(false); | 289 PostDelayedAnimation(FADE_OUT, false); |
| 278 } | 290 } |
| 279 | 291 |
| 280 void ScrollbarAnimationController::DidMouseMoveNear( | 292 void ScrollbarAnimationController::DidMouseMoveNear( |
| 281 ScrollbarOrientation orientation, | 293 ScrollbarOrientation orientation, |
| 282 float distance) { | 294 float distance) { |
| 283 if (!need_thinning_animation_) | 295 if (!need_thinning_animation_) |
| 284 return; | 296 return; |
| 285 | 297 |
| 286 bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_; | 298 bool need_trigger_scrollbar_show_before = need_trigger_scrollbar_show_; |
| 287 | 299 |
| 288 GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance); | 300 GetScrollbarAnimationController(orientation).DidMouseMoveNear(distance); |
| 289 | 301 |
| 290 need_trigger_scrollbar_show_ = | 302 need_trigger_scrollbar_show_ = |
| 291 CalcNeedTriggerScrollbarShow(orientation, distance); | 303 CalcNeedTriggerScrollbarShow(orientation, distance); |
| 292 | 304 |
| 293 if (Captured()) | 305 if (Captured()) |
| 294 return; | 306 return; |
| 295 | 307 |
| 296 if (ScrollbarsHidden()) { | 308 if (ScrollbarsHidden()) { |
| 297 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { | 309 if (need_trigger_scrollbar_show_before != need_trigger_scrollbar_show_) { |
| 298 if (need_trigger_scrollbar_show_) { | 310 if (need_trigger_scrollbar_show_) { |
| 299 PostDelayedShow(); | 311 PostDelayedAnimation(FADE_IN, false); |
| 300 } else { | 312 } else { |
| 301 delayed_scrollbar_show_.Cancel(); | 313 delayed_scrollbar_animation_.Cancel(); |
| 302 } | 314 } |
| 303 } | 315 } |
| 304 } else { | 316 } else { |
| 305 if (MouseIsNearAnyScrollbar()) { | 317 if (MouseIsNearAnyScrollbar()) { |
| 306 Show(); | 318 Show(); |
| 307 StopAnimation(); | 319 StopAnimation(); |
| 308 } else if (!is_animating_) { | 320 } else if (!is_animating_) { |
| 309 PostDelayedFadeOut(false); | 321 PostDelayedAnimation(FADE_OUT, false); |
| 310 } | 322 } |
| 311 } | 323 } |
| 312 } | 324 } |
| 313 | 325 |
| 314 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( | 326 bool ScrollbarAnimationController::CalcNeedTriggerScrollbarShow( |
| 315 ScrollbarOrientation orientation, | 327 ScrollbarOrientation orientation, |
| 316 float distance) const { | 328 float distance) const { |
| 317 DCHECK(need_thinning_animation_); | 329 DCHECK(need_thinning_animation_); |
| 318 | 330 |
| 319 if (vertical_controller_->mouse_is_over_scrollbar() || | 331 if (vertical_controller_->mouse_is_over_scrollbar() || |
| 320 horizontal_controller_->mouse_is_over_scrollbar()) | 332 horizontal_controller_->mouse_is_over_scrollbar()) |
| 321 return true; | 333 return true; |
| 322 | 334 |
| 323 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { | 335 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { |
| 324 if (scrollbar->orientation() != orientation) | 336 if (scrollbar->orientation() != orientation) |
| 325 continue; | 337 continue; |
| 326 | 338 |
| 327 if (distance < kMouseMoveDistanceToTriggerShow) | 339 if (distance < kMouseMoveDistanceToTriggerFadeIn) |
| 328 return true; | 340 return true; |
| 329 } | 341 } |
| 330 | 342 |
| 331 return false; | 343 return false; |
| 332 } | 344 } |
| 333 | 345 |
| 334 bool ScrollbarAnimationController::MouseIsOverScrollbar( | 346 bool ScrollbarAnimationController::MouseIsOverScrollbar( |
| 335 ScrollbarOrientation orientation) const { | 347 ScrollbarOrientation orientation) const { |
| 336 DCHECK(need_thinning_animation_); | 348 DCHECK(need_thinning_animation_); |
| 337 return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar(); | 349 return GetScrollbarAnimationController(orientation).mouse_is_over_scrollbar(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 352 bool ScrollbarAnimationController::ScrollbarsHidden() const { | 364 bool ScrollbarAnimationController::ScrollbarsHidden() const { |
| 353 return opacity_ == 0.0f; | 365 return opacity_ == 0.0f; |
| 354 } | 366 } |
| 355 | 367 |
| 356 bool ScrollbarAnimationController::Captured() const { | 368 bool ScrollbarAnimationController::Captured() const { |
| 357 DCHECK(need_thinning_animation_); | 369 DCHECK(need_thinning_animation_); |
| 358 return vertical_controller_->captured() || horizontal_controller_->captured(); | 370 return vertical_controller_->captured() || horizontal_controller_->captured(); |
| 359 } | 371 } |
| 360 | 372 |
| 361 void ScrollbarAnimationController::Show() { | 373 void ScrollbarAnimationController::Show() { |
| 362 delayed_scrollbar_show_.Cancel(); | 374 delayed_scrollbar_animation_.Cancel(); |
| 363 ApplyOpacityToScrollbars(1.0f); | 375 ApplyOpacityToScrollbars(1.0f); |
| 364 } | 376 } |
| 365 | 377 |
| 366 void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) { | 378 void ScrollbarAnimationController::ApplyOpacityToScrollbars(float opacity) { |
| 367 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { | 379 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { |
| 368 if (!scrollbar->is_overlay_scrollbar()) | 380 if (!scrollbar->is_overlay_scrollbar()) |
| 369 continue; | 381 continue; |
| 370 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0; | 382 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0; |
| 371 scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity); | 383 scrollbar->SetOverlayScrollbarLayerOpacityAnimated(effective_opacity); |
| 372 } | 384 } |
| 373 | 385 |
| 374 bool previouslyVisible = opacity_ > 0.0f; | 386 bool previouslyVisible = opacity_ > 0.0f; |
| 375 bool currentlyVisible = opacity > 0.0f; | 387 bool currentlyVisible = opacity > 0.0f; |
| 376 | 388 |
| 377 if (opacity_ != opacity) | 389 if (opacity_ != opacity) |
| 378 client_->SetNeedsRedrawForScrollbarAnimation(); | 390 client_->SetNeedsRedrawForScrollbarAnimation(); |
| 379 | 391 |
| 380 opacity_ = opacity; | 392 opacity_ = opacity; |
| 381 | 393 |
| 382 if (previouslyVisible != currentlyVisible) | 394 if (previouslyVisible != currentlyVisible) |
| 383 client_->DidChangeScrollbarVisibility(); | 395 client_->DidChangeScrollbarVisibility(); |
| 384 } | 396 } |
| 385 | 397 |
| 386 } // namespace cc | 398 } // namespace cc |
| OLD | NEW |