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/top_controls_manager.h" | 5 #include "cc/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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 previous_root_scroll_offset_ = RootScrollLayerTotalScrollY(); | 134 previous_root_scroll_offset_ = RootScrollLayerTotalScrollY(); |
135 in_scroll_gesture_ = false; | 135 in_scroll_gesture_ = false; |
136 current_scroll_delta_ = 0.f; | 136 current_scroll_delta_ = 0.f; |
137 } | 137 } |
138 | 138 |
139 void TopControlsManager::Animate(base::TimeTicks monotonic_time) { | 139 void TopControlsManager::Animate(base::TimeTicks monotonic_time) { |
140 if (!top_controls_animation_ || !client_->haveRootScrollLayer()) | 140 if (!top_controls_animation_ || !client_->haveRootScrollLayer()) |
141 return; | 141 return; |
142 | 142 |
143 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF(); | 143 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF(); |
144 float new_offset = top_controls_animation_->getValue(time); | 144 float new_offset = top_controls_animation_->GetValue(time); |
145 gfx::Vector2dF scroll_vector(0.f, -(new_offset - controls_top_offset_)); | 145 gfx::Vector2dF scroll_vector(0.f, -(new_offset - controls_top_offset_)); |
146 ScrollInternal(scroll_vector); | 146 ScrollInternal(scroll_vector); |
147 client_->setNeedsRedraw(); | 147 client_->setNeedsRedraw(); |
148 | 148 |
149 if (IsAnimationCompleteAtTime(monotonic_time)) | 149 if (IsAnimationCompleteAtTime(monotonic_time)) |
150 ResetAnimations(); | 150 ResetAnimations(); |
151 } | 151 } |
152 | 152 |
153 void TopControlsManager::ResetAnimations() { | 153 void TopControlsManager::ResetAnimations() { |
154 if (top_controls_animation_) | 154 if (top_controls_animation_) |
155 top_controls_animation_.reset(); | 155 top_controls_animation_.reset(); |
156 | 156 |
157 animation_direction_ = NO_ANIMATION; | 157 animation_direction_ = NO_ANIMATION; |
158 } | 158 } |
159 | 159 |
160 float TopControlsManager::RootScrollLayerTotalScrollY() { | 160 float TopControlsManager::RootScrollLayerTotalScrollY() { |
161 return client_->rootScrollLayerTotalScrollY(); | 161 return client_->rootScrollLayerTotalScrollY(); |
162 } | 162 } |
163 | 163 |
164 void TopControlsManager::SetupAnimation(AnimationDirection direction) { | 164 void TopControlsManager::SetupAnimation(AnimationDirection direction) { |
165 top_controls_animation_ = KeyframedFloatAnimationCurve::create(); | 165 top_controls_animation_ = KeyframedFloatAnimationCurve::Create(); |
166 double start_time = | 166 double start_time = |
167 (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF(); | 167 (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF(); |
168 top_controls_animation_->addKeyframe( | 168 top_controls_animation_->AddKeyframe( |
169 FloatKeyframe::create(start_time, controls_top_offset_, | 169 FloatKeyframe::Create(start_time, controls_top_offset_, |
170 scoped_ptr<TimingFunction>())); | 170 scoped_ptr<TimingFunction>())); |
171 float max_ending_offset = | 171 float max_ending_offset = |
172 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_; | 172 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_; |
173 top_controls_animation_->addKeyframe( | 173 top_controls_animation_->AddKeyframe( |
174 FloatKeyframe::create(start_time + kShowHideMaxDurationMs, | 174 FloatKeyframe::Create(start_time + kShowHideMaxDurationMs, |
175 controls_top_offset_ + max_ending_offset, | 175 controls_top_offset_ + max_ending_offset, |
176 EaseTimingFunction::create())); | 176 EaseTimingFunction::create())); |
177 animation_direction_ = direction; | 177 animation_direction_ = direction; |
178 } | 178 } |
179 | 179 |
180 void TopControlsManager::StartAnimationIfNecessary() { | 180 void TopControlsManager::StartAnimationIfNecessary() { |
181 if (controls_top_offset_ != 0 | 181 if (controls_top_offset_ != 0 |
182 && controls_top_offset_ != -top_controls_height_) { | 182 && controls_top_offset_ != -top_controls_height_) { |
183 AnimationDirection show_controls = NO_ANIMATION; | 183 AnimationDirection show_controls = NO_ANIMATION; |
184 | 184 |
(...skipping 17 matching lines...) Expand all Loading... |
202 client_->setNeedsRedraw(); | 202 client_->setNeedsRedraw(); |
203 } | 203 } |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { | 207 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { |
208 if (!top_controls_animation_) | 208 if (!top_controls_animation_) |
209 return true; | 209 return true; |
210 | 210 |
211 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); | 211 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); |
212 float new_offset = top_controls_animation_->getValue(time_ms); | 212 float new_offset = top_controls_animation_->GetValue(time_ms); |
213 | 213 |
214 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || | 214 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || |
215 (animation_direction_ == HIDING_CONTROLS | 215 (animation_direction_ == HIDING_CONTROLS |
216 && new_offset <= -top_controls_height_)) { | 216 && new_offset <= -top_controls_height_)) { |
217 return true; | 217 return true; |
218 } | 218 } |
219 return false; | 219 return false; |
220 } | 220 } |
221 | 221 |
222 } // namespace cc | 222 } // namespace cc |
OLD | NEW |