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