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 "cc/animation/keyframed_animation_curve.h" | 10 #include "cc/animation/keyframed_animation_curve.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 client_->SetControlsTopOffset(controls_top_offset); | 161 client_->SetControlsTopOffset(controls_top_offset); |
162 | 162 |
163 client_->DidChangeTopControlsPosition(); | 163 client_->DidChangeTopControlsPosition(); |
164 } | 164 } |
165 | 165 |
166 gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) { | 166 gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) { |
167 if (!top_controls_animation_ || !client_->HaveRootScrollLayer()) | 167 if (!top_controls_animation_ || !client_->HaveRootScrollLayer()) |
168 return gfx::Vector2dF(); | 168 return gfx::Vector2dF(); |
169 | 169 |
170 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF(); | 170 base::TimeDelta time = monotonic_time - base::TimeTicks(); |
171 | 171 |
172 float old_offset = client_->ControlsTopOffset(); | 172 float old_offset = client_->ControlsTopOffset(); |
173 SetControlsTopOffset(top_controls_animation_->GetValue(time)); | 173 SetControlsTopOffset(top_controls_animation_->GetValue(time)); |
174 | 174 |
175 if (IsAnimationCompleteAtTime(monotonic_time)) | 175 if (IsAnimationCompleteAtTime(monotonic_time)) |
176 ResetAnimations(); | 176 ResetAnimations(); |
177 | 177 |
178 gfx::Vector2dF scroll_delta(0.f, client_->ControlsTopOffset() - old_offset); | 178 gfx::Vector2dF scroll_delta(0.f, client_->ControlsTopOffset() - old_offset); |
179 return scroll_delta; | 179 return scroll_delta; |
180 } | 180 } |
(...skipping 11 matching lines...) Expand all Loading... |
192 | 192 |
193 if (direction == HIDING_CONTROLS && | 193 if (direction == HIDING_CONTROLS && |
194 client_->ControlsTopOffset() == -top_controls_height_) { | 194 client_->ControlsTopOffset() == -top_controls_height_) { |
195 return; | 195 return; |
196 } | 196 } |
197 | 197 |
198 if (top_controls_animation_ && animation_direction_ == direction) | 198 if (top_controls_animation_ && animation_direction_ == direction) |
199 return; | 199 return; |
200 | 200 |
201 top_controls_animation_ = KeyframedFloatAnimationCurve::Create(); | 201 top_controls_animation_ = KeyframedFloatAnimationCurve::Create(); |
202 double start_time = | 202 base::TimeDelta start_time = gfx::FrameTime::Now() - base::TimeTicks(); |
203 (gfx::FrameTime::Now() - base::TimeTicks()).InMillisecondsF(); | |
204 top_controls_animation_->AddKeyframe( | 203 top_controls_animation_->AddKeyframe( |
205 FloatKeyframe::Create(start_time, client_->ControlsTopOffset(), nullptr)); | 204 FloatKeyframe::Create(start_time, client_->ControlsTopOffset(), nullptr)); |
206 float max_ending_offset = | 205 float max_ending_offset = |
207 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_; | 206 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_; |
208 top_controls_animation_->AddKeyframe( | 207 top_controls_animation_->AddKeyframe(FloatKeyframe::Create( |
209 FloatKeyframe::Create(start_time + kShowHideMaxDurationMs, | 208 start_time + base::TimeDelta::FromMilliseconds(kShowHideMaxDurationMs), |
210 client_->ControlsTopOffset() + max_ending_offset, | 209 client_->ControlsTopOffset() + max_ending_offset, |
211 EaseTimingFunction::Create())); | 210 EaseTimingFunction::Create())); |
212 animation_direction_ = direction; | 211 animation_direction_ = direction; |
213 client_->DidChangeTopControlsPosition(); | 212 client_->DidChangeTopControlsPosition(); |
214 } | 213 } |
215 | 214 |
216 void TopControlsManager::StartAnimationIfNecessary() { | 215 void TopControlsManager::StartAnimationIfNecessary() { |
217 if (client_->ControlsTopOffset() != 0 | 216 if (client_->ControlsTopOffset() != 0 |
218 && client_->ControlsTopOffset() != -top_controls_height_) { | 217 && client_->ControlsTopOffset() != -top_controls_height_) { |
219 AnimationDirection show_controls = NO_ANIMATION; | 218 AnimationDirection show_controls = NO_ANIMATION; |
220 | 219 |
221 if (client_->ControlsTopOffset() >= -top_controls_show_height_) { | 220 if (client_->ControlsTopOffset() >= -top_controls_show_height_) { |
(...skipping 12 matching lines...) Expand all Loading... |
234 | 233 |
235 if (show_controls != NO_ANIMATION) | 234 if (show_controls != NO_ANIMATION) |
236 SetupAnimation(show_controls); | 235 SetupAnimation(show_controls); |
237 } | 236 } |
238 } | 237 } |
239 | 238 |
240 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { | 239 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { |
241 if (!top_controls_animation_) | 240 if (!top_controls_animation_) |
242 return true; | 241 return true; |
243 | 242 |
244 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); | 243 base::TimeDelta animation_time = time - base::TimeTicks(); |
245 float new_offset = top_controls_animation_->GetValue(time_ms); | 244 float new_offset = top_controls_animation_->GetValue(animation_time); |
246 | 245 |
247 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || | 246 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || |
248 (animation_direction_ == HIDING_CONTROLS | 247 (animation_direction_ == HIDING_CONTROLS |
249 && new_offset <= -top_controls_height_)) { | 248 && new_offset <= -top_controls_height_)) { |
250 return true; | 249 return true; |
251 } | 250 } |
252 return false; | 251 return false; |
253 } | 252 } |
254 | 253 |
255 } // namespace cc | 254 } // namespace cc |
OLD | NEW |