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