| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_thinning.h" | 5 #include "cc/input/scrollbar_animation_controller_thinning.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "cc/layers/layer_impl.h" | 9 #include "cc/layers/layer_impl.h" |
| 10 #include "cc/layers/scrollbar_layer_impl_base.h" | 10 #include "cc/layers/scrollbar_layer_impl_base.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 ApplyOpacity(1.f - progress); | 65 ApplyOpacity(1.f - progress); |
| 66 else | 66 else |
| 67 ApplyThumbThicknessScale(ThumbThicknessScaleAt(progress)); | 67 ApplyThumbThicknessScale(ThumbThicknessScaleAt(progress)); |
| 68 | 68 |
| 69 client_->SetNeedsRedrawForScrollbarAnimation(); | 69 client_->SetNeedsRedrawForScrollbarAnimation(); |
| 70 if (progress == 1.f) { | 70 if (progress == 1.f) { |
| 71 StopAnimation(); | 71 StopAnimation(); |
| 72 if (current_animating_property_ == THICKNESS) { | 72 if (current_animating_property_ == THICKNESS) { |
| 73 thickness_change_ = NONE; | 73 thickness_change_ = NONE; |
| 74 SetCurrentAnimatingProperty(OPACITY); | 74 SetCurrentAnimatingProperty(OPACITY); |
| 75 PostDelayedAnimationTask(false); | 75 if (!mouse_is_near_scrollbar_) { |
| 76 PostDelayedAnimationTask(false); |
| 77 } |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 } | 80 } |
| 79 | 81 |
| 80 const base::TimeDelta& ScrollbarAnimationControllerThinning::Duration() { | 82 const base::TimeDelta& ScrollbarAnimationControllerThinning::Duration() { |
| 81 if (current_animating_property_ == OPACITY) | 83 if (current_animating_property_ == OPACITY) |
| 82 return fade_duration_; | 84 return fade_duration_; |
| 83 else | 85 else |
| 84 return thinning_duration_; | 86 return thinning_duration_; |
| 85 } | 87 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 100 | 102 |
| 101 captured_ = false; | 103 captured_ = false; |
| 102 StopAnimation(); | 104 StopAnimation(); |
| 103 | 105 |
| 104 if (!mouse_is_near_scrollbar_) { | 106 if (!mouse_is_near_scrollbar_) { |
| 105 SetCurrentAnimatingProperty(THICKNESS); | 107 SetCurrentAnimatingProperty(THICKNESS); |
| 106 thickness_change_ = DECREASE; | 108 thickness_change_ = DECREASE; |
| 107 StartAnimation(); | 109 StartAnimation(); |
| 108 } else { | 110 } else { |
| 109 SetCurrentAnimatingProperty(OPACITY); | 111 SetCurrentAnimatingProperty(OPACITY); |
| 110 PostDelayedAnimationTask(false); | |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 void ScrollbarAnimationControllerThinning::DidMouseLeave() { | 115 void ScrollbarAnimationControllerThinning::DidMouseLeave() { |
| 115 if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_) | 116 if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_) |
| 116 return; | 117 return; |
| 117 | 118 |
| 118 mouse_is_over_scrollbar_ = false; | 119 mouse_is_over_scrollbar_ = false; |
| 119 mouse_is_near_scrollbar_ = false; | 120 mouse_is_near_scrollbar_ = false; |
| 120 | 121 |
| 121 if (captured_ || opacity_ == 0.0f) | 122 if (captured_ || opacity_ == 0.0f) |
| 122 return; | 123 return; |
| 123 | 124 |
| 124 thickness_change_ = DECREASE; | 125 thickness_change_ = DECREASE; |
| 125 SetCurrentAnimatingProperty(THICKNESS); | 126 SetCurrentAnimatingProperty(THICKNESS); |
| 126 StartAnimation(); | 127 StartAnimation(); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) { | 130 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) { |
| 130 if (captured_) | 131 if (captured_) |
| 131 return; | 132 return; |
| 132 | 133 |
| 133 ScrollbarAnimationController::DidScrollUpdate(on_resize); | 134 ScrollbarAnimationController::DidScrollUpdate(on_resize); |
| 134 ApplyOpacity(1.f); | 135 ApplyOpacity(1.f); |
| 135 ApplyThumbThicknessScale(mouse_is_near_scrollbar_ ? 1.f | 136 ApplyThumbThicknessScale(mouse_is_near_scrollbar_ ? 1.f |
| 136 : kIdleThicknessScale); | 137 : kIdleThicknessScale); |
| 137 SetCurrentAnimatingProperty(OPACITY); | 138 SetCurrentAnimatingProperty(OPACITY); |
| 139 |
| 140 // Don't fade out the scrollbar when mouse is near. |
| 141 if (mouse_is_near_scrollbar_) |
| 142 StopAnimation(); |
| 143 } |
| 144 |
| 145 void ScrollbarAnimationControllerThinning::DidScrollEnd() { |
| 146 ScrollbarAnimationController::DidScrollEnd(); |
| 147 |
| 148 // Don't fade out the scrollbar when mouse is near. |
| 149 if (mouse_is_near_scrollbar_) |
| 150 StopAnimation(); |
| 138 } | 151 } |
| 139 | 152 |
| 140 void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) { | 153 void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) { |
| 141 bool mouse_is_over_scrollbar = distance == 0.0f; | 154 bool mouse_is_over_scrollbar = distance == 0.0f; |
| 142 bool mouse_is_near_scrollbar = | 155 bool mouse_is_near_scrollbar = |
| 143 distance < mouse_move_distance_to_trigger_animation_; | 156 distance < mouse_move_distance_to_trigger_animation_; |
| 144 | 157 |
| 145 if (captured_ || opacity_ == 0.0f) { | 158 if (captured_ || opacity_ == 0.0f) { |
| 146 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar; | 159 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar; |
| 147 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; | 160 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 if (current_animating_property_ == property) | 256 if (current_animating_property_ == property) |
| 244 return; | 257 return; |
| 245 | 258 |
| 246 StopAnimation(); | 259 StopAnimation(); |
| 247 current_animating_property_ = property; | 260 current_animating_property_ = property; |
| 248 if (current_animating_property_ == THICKNESS) | 261 if (current_animating_property_ == THICKNESS) |
| 249 ApplyOpacity(1.f); | 262 ApplyOpacity(1.f); |
| 250 } | 263 } |
| 251 | 264 |
| 252 } // namespace cc | 265 } // namespace cc |
| OLD | NEW |