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