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