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/top_controls_manager.h" | 5 #include "cc/input/top_controls_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 if (animate) { | 75 if (animate) { |
| 76 SetupAnimation(visibility_restriction_ == ALWAYS_SHOWN ? | 76 SetupAnimation(visibility_restriction_ == ALWAYS_SHOWN ? |
| 77 SHOWING_CONTROLS : HIDING_CONTROLS); | 77 SHOWING_CONTROLS : HIDING_CONTROLS); |
| 78 } else { | 78 } else { |
| 79 controls_top_offset_ = final_controls_position; | 79 controls_top_offset_ = final_controls_position; |
| 80 } | 80 } |
| 81 client_->DidChangeTopControlsPosition(); | 81 client_->DidChangeTopControlsPosition(); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 void TopControlsManager::ShowTopControls(bool show) { | |
| 86 if (show) { | |
| 87 DCHECK(visibility_restriction_ != ALWAYS_HIDDEN); | |
| 88 SetupAnimation(SHOWING_CONTROLS); | |
| 89 } else { | |
| 90 DCHECK(visibility_restriction_ != ALWAYS_SHOWN); | |
| 91 SetupAnimation(HIDING_CONTROLS); | |
| 92 } | |
| 93 } | |
| 94 | |
|
Ted C
2013/04/16 02:05:58
remove extra line
Michael van Ouwerkerk
2013/04/16 15:02:47
Done.
| |
| 95 | |
| 85 void TopControlsManager::ScrollBegin() { | 96 void TopControlsManager::ScrollBegin() { |
| 86 ResetAnimations(); | 97 ResetAnimations(); |
| 87 current_scroll_delta_ = 0.f; | 98 current_scroll_delta_ = 0.f; |
| 88 controls_scroll_begin_offset_ = controls_top_offset_; | 99 controls_scroll_begin_offset_ = controls_top_offset_; |
| 89 } | 100 } |
| 90 | 101 |
| 91 gfx::Vector2dF TopControlsManager::ScrollBy( | 102 gfx::Vector2dF TopControlsManager::ScrollBy( |
| 92 const gfx::Vector2dF pending_delta) { | 103 const gfx::Vector2dF pending_delta) { |
| 93 if (visibility_restriction_ == ALWAYS_SHOWN && pending_delta.y() > 0) | 104 if (visibility_restriction_ == ALWAYS_SHOWN && pending_delta.y() > 0) |
| 94 return pending_delta; | 105 return pending_delta; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 } | 157 } |
| 147 | 158 |
| 148 void TopControlsManager::ResetAnimations() { | 159 void TopControlsManager::ResetAnimations() { |
| 149 if (top_controls_animation_) | 160 if (top_controls_animation_) |
| 150 top_controls_animation_.reset(); | 161 top_controls_animation_.reset(); |
| 151 | 162 |
| 152 animation_direction_ = NO_ANIMATION; | 163 animation_direction_ = NO_ANIMATION; |
| 153 } | 164 } |
| 154 | 165 |
| 155 void TopControlsManager::SetupAnimation(AnimationDirection direction) { | 166 void TopControlsManager::SetupAnimation(AnimationDirection direction) { |
| 167 DCHECK(direction != NO_ANIMATION); | |
| 168 | |
| 169 if (direction == SHOWING_CONTROLS && controls_top_offset_ == 0) | |
| 170 return; | |
| 171 | |
| 172 if (direction == HIDING_CONTROLS && | |
| 173 controls_top_offset_ == -top_controls_height_) | |
|
Ted C
2013/04/16 02:05:58
if I recall, I think you need braces if the condit
Michael van Ouwerkerk
2013/04/16 15:02:47
Done.
| |
| 174 return; | |
| 175 | |
| 176 if (top_controls_animation_ && animation_direction_ == direction) | |
| 177 return; | |
| 178 | |
| 156 top_controls_animation_ = KeyframedFloatAnimationCurve::Create(); | 179 top_controls_animation_ = KeyframedFloatAnimationCurve::Create(); |
| 157 double start_time = | 180 double start_time = |
| 158 (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF(); | 181 (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF(); |
| 159 top_controls_animation_->AddKeyframe( | 182 top_controls_animation_->AddKeyframe( |
| 160 FloatKeyframe::Create(start_time, controls_top_offset_, | 183 FloatKeyframe::Create(start_time, controls_top_offset_, |
| 161 scoped_ptr<TimingFunction>())); | 184 scoped_ptr<TimingFunction>())); |
| 162 float max_ending_offset = | 185 float max_ending_offset = |
| 163 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_; | 186 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_; |
| 164 top_controls_animation_->AddKeyframe( | 187 top_controls_animation_->AddKeyframe( |
| 165 FloatKeyframe::Create(start_time + kShowHideMaxDurationMs, | 188 FloatKeyframe::Create(start_time + kShowHideMaxDurationMs, |
| 166 controls_top_offset_ + max_ending_offset, | 189 controls_top_offset_ + max_ending_offset, |
| 167 EaseTimingFunction::Create())); | 190 EaseTimingFunction::Create())); |
| 168 animation_direction_ = direction; | 191 animation_direction_ = direction; |
| 192 client_->DidChangeTopControlsPosition(); | |
| 169 } | 193 } |
| 170 | 194 |
| 171 void TopControlsManager::StartAnimationIfNecessary() { | 195 void TopControlsManager::StartAnimationIfNecessary() { |
| 172 if (controls_top_offset_ != 0 | 196 if (controls_top_offset_ != 0 |
| 173 && controls_top_offset_ != -top_controls_height_) { | 197 && controls_top_offset_ != -top_controls_height_) { |
| 174 AnimationDirection show_controls = NO_ANIMATION; | 198 AnimationDirection show_controls = NO_ANIMATION; |
| 175 | 199 |
| 176 if (controls_top_offset_ >= -top_controls_show_height_) { | 200 if (controls_top_offset_ >= -top_controls_show_height_) { |
| 177 // If we're showing so much that the hide threshold won't trigger, show. | 201 // If we're showing so much that the hide threshold won't trigger, show. |
| 178 show_controls = SHOWING_CONTROLS; | 202 show_controls = SHOWING_CONTROLS; |
| 179 } else if (controls_top_offset_ <= -top_controls_hide_height_) { | 203 } else if (controls_top_offset_ <= -top_controls_hide_height_) { |
| 180 // If we're showing so little that the show threshold won't trigger, hide. | 204 // If we're showing so little that the show threshold won't trigger, hide. |
| 181 show_controls = HIDING_CONTROLS; | 205 show_controls = HIDING_CONTROLS; |
| 182 } else { | 206 } else { |
| 183 // If we could be either showing or hiding, we determine which one to | 207 // If we could be either showing or hiding, we determine which one to |
| 184 // do based on whether or not the total scroll delta was moving up or | 208 // do based on whether or not the total scroll delta was moving up or |
| 185 // down. | 209 // down. |
| 186 show_controls = current_scroll_delta_ <= 0.f ? | 210 show_controls = current_scroll_delta_ <= 0.f ? |
| 187 SHOWING_CONTROLS : HIDING_CONTROLS; | 211 SHOWING_CONTROLS : HIDING_CONTROLS; |
| 188 } | 212 } |
| 189 | 213 |
| 190 if (show_controls != NO_ANIMATION && | 214 if (show_controls != NO_ANIMATION) { |
| 191 (!top_controls_animation_ || animation_direction_ != show_controls)) { | |
| 192 SetupAnimation(show_controls); | 215 SetupAnimation(show_controls); |
| 193 client_->DidChangeTopControlsPosition(); | 216 client_->DidChangeTopControlsPosition(); |
|
Ted C
2013/04/16 02:05:58
can remove this because it is called in Setup
Michael van Ouwerkerk
2013/04/16 15:02:47
Done.
| |
| 194 } | 217 } |
| 195 } | 218 } |
| 196 } | 219 } |
| 197 | 220 |
| 198 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { | 221 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { |
| 199 if (!top_controls_animation_) | 222 if (!top_controls_animation_) |
| 200 return true; | 223 return true; |
| 201 | 224 |
| 202 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); | 225 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); |
| 203 float new_offset = top_controls_animation_->GetValue(time_ms); | 226 float new_offset = top_controls_animation_->GetValue(time_ms); |
| 204 | 227 |
| 205 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || | 228 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || |
| 206 (animation_direction_ == HIDING_CONTROLS | 229 (animation_direction_ == HIDING_CONTROLS |
| 207 && new_offset <= -top_controls_height_)) { | 230 && new_offset <= -top_controls_height_)) { |
| 208 return true; | 231 return true; |
| 209 } | 232 } |
| 210 return false; | 233 return false; |
| 211 } | 234 } |
| 212 | 235 |
| 213 } // namespace cc | 236 } // namespace cc |
| OLD | NEW |