| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/page_scale_animation.h" | 5 #include "cc/input/page_scale_animation.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "cc/animation/timing_function.h" | 10 #include "cc/animation/timing_function.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 159 } |
| 160 | 160 |
| 161 gfx::SizeF PageScaleAnimation::ViewportSizeAt(float interp) const { | 161 gfx::SizeF PageScaleAnimation::ViewportSizeAt(float interp) const { |
| 162 return gfx::ScaleSize(viewport_size_, 1.f / PageScaleFactorAt(interp)); | 162 return gfx::ScaleSize(viewport_size_, 1.f / PageScaleFactorAt(interp)); |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool PageScaleAnimation::IsAnimationStarted() const { | 165 bool PageScaleAnimation::IsAnimationStarted() const { |
| 166 return start_time_ >= 0; | 166 return start_time_ >= 0; |
| 167 } | 167 } |
| 168 | 168 |
| 169 void PageScaleAnimation::StartAnimation(double time) { | 169 void PageScaleAnimation::StartAnimation(base::TimeTicks time) { |
| 170 DCHECK_GT(0, start_time_); | 170 DCHECK_GT(0, start_time_); |
| 171 start_time_ = time; | 171 start_time_ = (time - base::TimeTicks()).InSecondsF(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 gfx::Vector2dF PageScaleAnimation::ScrollOffsetAtTime(double time) const { | 174 gfx::Vector2dF PageScaleAnimation::ScrollOffsetAtTime( |
| 175 base::TimeTicks time) const { |
| 175 DCHECK_GE(start_time_, 0); | 176 DCHECK_GE(start_time_, 0); |
| 176 return ScrollOffsetAt(InterpAtTime(time)); | 177 return ScrollOffsetAt(InterpAtTime(time)); |
| 177 } | 178 } |
| 178 | 179 |
| 179 float PageScaleAnimation::PageScaleFactorAtTime(double time) const { | 180 float PageScaleAnimation::PageScaleFactorAtTime(base::TimeTicks time) const { |
| 180 DCHECK_GE(start_time_, 0); | 181 DCHECK_GE(start_time_, 0); |
| 181 return PageScaleFactorAt(InterpAtTime(time)); | 182 return PageScaleFactorAt(InterpAtTime(time)); |
| 182 } | 183 } |
| 183 | 184 |
| 184 bool PageScaleAnimation::IsAnimationCompleteAtTime(double time) const { | 185 bool PageScaleAnimation::IsAnimationCompleteAtTime(base::TimeTicks time) const { |
| 185 DCHECK_GE(start_time_, 0); | 186 DCHECK_GE(start_time_, 0); |
| 186 return time >= end_time(); | 187 return (time - base::TimeTicks()).InSecondsF() >= end_time(); |
| 187 } | 188 } |
| 188 | 189 |
| 189 float PageScaleAnimation::InterpAtTime(double time) const { | 190 float PageScaleAnimation::InterpAtTime(base::TimeTicks time) const { |
| 190 DCHECK_GE(start_time_, 0); | 191 DCHECK_GE(start_time_, 0); |
| 191 DCHECK_GE(time, start_time_); | 192 DCHECK_GE((time - base::TimeTicks()).InSecondsF(), start_time_); |
| 192 if (IsAnimationCompleteAtTime(time)) | 193 if (IsAnimationCompleteAtTime(time)) |
| 193 return 1.f; | 194 return 1.f; |
| 194 | 195 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); |
| 195 const double normalized_time = (time - start_time_) / duration_; | 196 const double normalized_time = (monotonic_time - start_time_) / duration_; |
| 196 return timing_function_->GetValue(normalized_time); | 197 return timing_function_->GetValue(normalized_time); |
| 197 } | 198 } |
| 198 | 199 |
| 199 gfx::Vector2dF PageScaleAnimation::ScrollOffsetAt(float interp) const { | 200 gfx::Vector2dF PageScaleAnimation::ScrollOffsetAt(float interp) const { |
| 200 if (interp <= 0.f) | 201 if (interp <= 0.f) |
| 201 return start_scroll_offset_; | 202 return start_scroll_offset_; |
| 202 if (interp >= 1.f) | 203 if (interp >= 1.f) |
| 203 return target_scroll_offset_; | 204 return target_scroll_offset_; |
| 204 | 205 |
| 205 return AnchorAt(interp) - ViewportRelativeAnchorAt(interp); | 206 return AnchorAt(interp) - ViewportRelativeAnchorAt(interp); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 233 | 234 |
| 234 // Linearly interpolate the magnitude in log scale. | 235 // Linearly interpolate the magnitude in log scale. |
| 235 float diff = target_page_scale_factor_ / start_page_scale_factor_; | 236 float diff = target_page_scale_factor_ / start_page_scale_factor_; |
| 236 float log_diff = log(diff); | 237 float log_diff = log(diff); |
| 237 log_diff *= interp; | 238 log_diff *= interp; |
| 238 diff = exp(log_diff); | 239 diff = exp(log_diff); |
| 239 return start_page_scale_factor_ * diff; | 240 return start_page_scale_factor_ * diff; |
| 240 } | 241 } |
| 241 | 242 |
| 242 } // namespace cc | 243 } // namespace cc |
| OLD | NEW |