Chromium Code Reviews| 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/single_scrollbar_animation_controller_thinning.h" | 5 #include "cc/input/single_scrollbar_animation_controller_thinning.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 SingleScrollbarAnimationControllerThinning( | 29 SingleScrollbarAnimationControllerThinning( |
| 30 ElementId scroll_element_id, | 30 ElementId scroll_element_id, |
| 31 ScrollbarOrientation orientation, | 31 ScrollbarOrientation orientation, |
| 32 ScrollbarAnimationControllerClient* client, | 32 ScrollbarAnimationControllerClient* client, |
| 33 base::TimeDelta thinning_duration) | 33 base::TimeDelta thinning_duration) |
| 34 : client_(client), | 34 : client_(client), |
| 35 is_animating_(false), | 35 is_animating_(false), |
| 36 scroll_element_id_(scroll_element_id), | 36 scroll_element_id_(scroll_element_id), |
| 37 orientation_(orientation), | 37 orientation_(orientation), |
| 38 captured_(false), | 38 captured_(false), |
| 39 mouse_is_over_scrollbar_(false), | 39 mouse_is_over_scrollbar_thumb_(false), |
| 40 mouse_is_near_scrollbar_thumb_(false), | |
| 40 mouse_is_near_scrollbar_(false), | 41 mouse_is_near_scrollbar_(false), |
| 41 thickness_change_(NONE), | 42 thickness_change_(NONE), |
| 42 thinning_duration_(thinning_duration) { | 43 thinning_duration_(thinning_duration) { |
| 43 ApplyThumbThicknessScale(kIdleThicknessScale); | 44 ApplyThumbThicknessScale(kIdleThicknessScale); |
| 44 } | 45 } |
| 45 | 46 |
| 46 bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) { | 47 bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) { |
| 47 if (!is_animating_) | 48 if (!is_animating_) |
| 48 return false; | 49 return false; |
| 49 | 50 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 is_animating_ = true; | 86 is_animating_ = true; |
| 86 last_awaken_time_ = base::TimeTicks(); | 87 last_awaken_time_ = base::TimeTicks(); |
| 87 client_->SetNeedsAnimateForScrollbarAnimation(); | 88 client_->SetNeedsAnimateForScrollbarAnimation(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void SingleScrollbarAnimationControllerThinning::StopAnimation() { | 91 void SingleScrollbarAnimationControllerThinning::StopAnimation() { |
| 91 is_animating_ = false; | 92 is_animating_ = false; |
| 92 } | 93 } |
| 93 | 94 |
| 94 void SingleScrollbarAnimationControllerThinning::DidMouseDown() { | 95 void SingleScrollbarAnimationControllerThinning::DidMouseDown() { |
| 95 if (!mouse_is_over_scrollbar_) | 96 if (!mouse_is_over_scrollbar_thumb_) |
| 96 return; | 97 return; |
| 97 | 98 |
| 98 StopAnimation(); | 99 StopAnimation(); |
| 99 captured_ = true; | 100 captured_ = true; |
| 100 ApplyThumbThicknessScale(1.f); | 101 ApplyThumbThicknessScale(1.f); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void SingleScrollbarAnimationControllerThinning::DidMouseUp() { | 104 void SingleScrollbarAnimationControllerThinning::DidMouseUp() { |
| 104 if (!captured_) | 105 if (!captured_) |
| 105 return; | 106 return; |
| 106 | 107 |
| 107 captured_ = false; | 108 captured_ = false; |
| 108 StopAnimation(); | 109 StopAnimation(); |
| 109 | 110 |
| 110 if (!mouse_is_near_scrollbar_) { | 111 if (!mouse_is_near_scrollbar_thumb_) { |
| 111 thickness_change_ = DECREASE; | 112 thickness_change_ = DECREASE; |
| 112 StartAnimation(); | 113 StartAnimation(); |
| 113 } else { | 114 } else { |
| 114 thickness_change_ = NONE; | 115 thickness_change_ = NONE; |
| 115 } | 116 } |
| 116 } | 117 } |
| 117 | 118 |
| 118 void SingleScrollbarAnimationControllerThinning::DidMouseLeave() { | 119 void SingleScrollbarAnimationControllerThinning::DidMouseLeave() { |
| 119 if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_) | 120 if (!mouse_is_over_scrollbar_thumb_ && !mouse_is_near_scrollbar_thumb_) |
| 120 return; | 121 return; |
| 121 | 122 |
| 122 mouse_is_over_scrollbar_ = false; | 123 mouse_is_over_scrollbar_thumb_ = false; |
| 123 mouse_is_near_scrollbar_ = false; | 124 mouse_is_near_scrollbar_thumb_ = false; |
| 124 | 125 |
| 125 if (captured_) | 126 if (captured_) |
| 126 return; | 127 return; |
| 127 | 128 |
| 128 thickness_change_ = DECREASE; | 129 thickness_change_ = DECREASE; |
| 129 StartAnimation(); | 130 StartAnimation(); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void SingleScrollbarAnimationControllerThinning::DidMouseMoveNear( | 133 void SingleScrollbarAnimationControllerThinning::DidMouseMoveNear( |
|
bokan
2017/04/25 19:36:21
This can also just be DidMoveMouse
| |
| 133 float distance) { | 134 float distance_to_scrollbar, |
|
bokan
2017/04/25 19:36:21
Why does the thinning controller need to know the
| |
| 134 bool mouse_is_over_scrollbar = distance == 0.0f; | 135 float distance_to_thumb) { |
| 135 bool mouse_is_near_scrollbar = | 136 mouse_is_near_scrollbar_ = |
| 136 distance < kDefaultMouseMoveDistanceToTriggerAnimation; | 137 distance_to_scrollbar < kDefaultMouseMoveDistanceToTriggerAnimation; |
| 137 | 138 |
| 138 if (!captured_ && mouse_is_near_scrollbar != mouse_is_near_scrollbar_) { | 139 bool mouse_is_over_scrollbar_thumb = distance_to_thumb == 0.0f; |
| 139 thickness_change_ = mouse_is_near_scrollbar ? INCREASE : DECREASE; | 140 bool mouse_is_near_scrollbar_thumb = |
| 141 distance_to_thumb < kDefaultMouseMoveDistanceToTriggerAnimation; | |
| 142 | |
| 143 if (!captured_ && | |
| 144 mouse_is_near_scrollbar_thumb != mouse_is_near_scrollbar_thumb_) { | |
| 145 thickness_change_ = mouse_is_near_scrollbar_thumb ? INCREASE : DECREASE; | |
| 140 StartAnimation(); | 146 StartAnimation(); |
| 141 } | 147 } |
| 142 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar; | 148 mouse_is_near_scrollbar_thumb_ = mouse_is_near_scrollbar_thumb; |
| 143 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; | 149 mouse_is_over_scrollbar_thumb_ = mouse_is_over_scrollbar_thumb; |
| 144 } | 150 } |
| 145 | 151 |
| 146 float SingleScrollbarAnimationControllerThinning::ThumbThicknessScaleAt( | 152 float SingleScrollbarAnimationControllerThinning::ThumbThicknessScaleAt( |
| 147 float progress) { | 153 float progress) { |
| 148 if (thickness_change_ == NONE) | 154 if (thickness_change_ == NONE) |
| 149 return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale; | 155 return mouse_is_near_scrollbar_thumb_ ? 1.f : kIdleThicknessScale; |
| 150 float factor = thickness_change_ == INCREASE ? progress : (1.f - progress); | 156 float factor = thickness_change_ == INCREASE ? progress : (1.f - progress); |
| 151 return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale; | 157 return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale; |
| 152 } | 158 } |
| 153 | 159 |
| 154 float SingleScrollbarAnimationControllerThinning::AdjustScale( | 160 float SingleScrollbarAnimationControllerThinning::AdjustScale( |
| 155 float new_value, | 161 float new_value, |
| 156 float current_value, | 162 float current_value, |
| 157 AnimationChange animation_change, | 163 AnimationChange animation_change, |
| 158 float min_value, | 164 float min_value, |
| 159 float max_value) { | 165 float max_value) { |
| 160 float result; | 166 float result; |
| 161 if (animation_change == INCREASE && current_value > new_value) | 167 if (animation_change == INCREASE && current_value > new_value) |
| 162 result = current_value; | 168 result = current_value; |
| 163 else if (animation_change == DECREASE && current_value < new_value) | 169 else if (animation_change == DECREASE && current_value < new_value) |
| 164 result = current_value; | 170 result = current_value; |
| 165 else | 171 else |
| 166 result = new_value; | 172 result = new_value; |
| 167 if (result > max_value) | 173 if (result > max_value) |
| 168 return max_value; | 174 return max_value; |
| 169 if (result < min_value) | 175 if (result < min_value) |
| 170 return min_value; | 176 return min_value; |
| 171 return result; | 177 return result; |
| 172 } | 178 } |
| 173 | 179 |
| 174 void SingleScrollbarAnimationControllerThinning::UpdateThumbThicknessScale() { | 180 void SingleScrollbarAnimationControllerThinning::UpdateThumbThicknessScale() { |
| 175 StopAnimation(); | 181 StopAnimation(); |
| 176 ApplyThumbThicknessScale(mouse_is_near_scrollbar_ ? 1.f | 182 ApplyThumbThicknessScale( |
| 177 : kIdleThicknessScale); | 183 mouse_is_near_scrollbar_thumb_ ? 1.f : kIdleThicknessScale); |
| 178 } | 184 } |
| 179 | 185 |
| 180 void SingleScrollbarAnimationControllerThinning::ApplyThumbThicknessScale( | 186 void SingleScrollbarAnimationControllerThinning::ApplyThumbThicknessScale( |
| 181 float thumb_thickness_scale) { | 187 float thumb_thickness_scale) { |
| 182 for (auto* scrollbar : client_->ScrollbarsFor(scroll_element_id_)) { | 188 for (auto* scrollbar : client_->ScrollbarsFor(scroll_element_id_)) { |
| 183 if (scrollbar->orientation() != orientation_) | 189 if (scrollbar->orientation() != orientation_) |
| 184 continue; | 190 continue; |
| 185 if (!scrollbar->is_overlay_scrollbar()) | 191 if (!scrollbar->is_overlay_scrollbar()) |
| 186 continue; | 192 continue; |
| 187 | 193 |
| 188 float scale = AdjustScale(thumb_thickness_scale, | 194 float scale = AdjustScale(thumb_thickness_scale, |
| 189 scrollbar->thumb_thickness_scale_factor(), | 195 scrollbar->thumb_thickness_scale_factor(), |
| 190 thickness_change_, kIdleThicknessScale, 1); | 196 thickness_change_, kIdleThicknessScale, 1); |
| 191 | 197 |
| 192 scrollbar->SetThumbThicknessScaleFactor(scale); | 198 scrollbar->SetThumbThicknessScaleFactor(scale); |
| 193 } | 199 } |
| 194 } | 200 } |
| 195 | 201 |
| 196 } // namespace cc | 202 } // namespace cc |
| OLD | NEW |