// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <algorithm>
+
#include "cc/animation/keyframed_animation_curve.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/box_f.h"
return progress;
}
-scoped_ptr<TimingFunction> CloneTimingFunction(
- const TimingFunction* timing_function) {
- DCHECK(timing_function);
- scoped_ptr<AnimationCurve> curve(timing_function->Clone());
- return scoped_ptr<TimingFunction>(
- static_cast<TimingFunction*>(curve.release()));
-}
-
} // namespace
Keyframe::Keyframe(double time, scoped_ptr<TimingFunction> timing_function)
scoped_ptr<ColorKeyframe> ColorKeyframe::Clone() const {
scoped_ptr<TimingFunction> func;
if (timing_function())
- func = CloneTimingFunction(timing_function());
+ func = timing_function()->Clone();
return ColorKeyframe::Create(Time(), Value(), func.Pass());
}
scoped_ptr<FloatKeyframe> FloatKeyframe::Clone() const {
scoped_ptr<TimingFunction> func;
if (timing_function())
- func = CloneTimingFunction(timing_function());
+ func = timing_function()->Clone();
return FloatKeyframe::Create(Time(), Value(), func.Pass());
}
scoped_ptr<TransformKeyframe> TransformKeyframe::Clone() const {
scoped_ptr<TimingFunction> func;
if (timing_function())
- func = CloneTimingFunction(timing_function());
+ func = timing_function()->Clone();
return TransformKeyframe::Create(Time(), Value(), func.Pass());
}
scoped_ptr<FilterKeyframe> FilterKeyframe::Clone() const {
scoped_ptr<TimingFunction> func;
if (timing_function())
- func = CloneTimingFunction(timing_function());
+ func = timing_function()->Clone();
return FilterKeyframe::Create(Time(), Value(), func.Pass());
}
return true;
}
+bool KeyframedTransformAnimationCurve::AffectsScale() const {
+ for (size_t i = 0; i < keyframes_.size(); ++i) {
+ if (keyframes_[i]->Value().AffectsScale())
+ return true;
+ }
+ return false;
+}
+
+bool KeyframedTransformAnimationCurve::IsTranslation() const {
+ for (size_t i = 0; i < keyframes_.size(); ++i) {
+ if (!keyframes_[i]->Value().IsTranslation() &&
+ !keyframes_[i]->Value().IsIdentity())
+ return false;
+ }
+ return true;
+}
+
+bool KeyframedTransformAnimationCurve::MaximumTargetScale(
+ bool forward_direction,
+ float* max_scale) const {
+ DCHECK_GE(keyframes_.size(), 2ul);
+ *max_scale = 0.f;
+
+ // If |forward_direction| is true, then skip the first frame, otherwise
+ // skip the last frame, since that is the original position in the animation.
+ size_t start = 1;
+ size_t end = keyframes_.size();
+ if (!forward_direction) {
+ --start;
+ --end;
+ }
+
+ for (size_t i = start; i < end; ++i) {
+ gfx::Vector3dF target_scale_for_segment;
+ if (!keyframes_[i]->Value().ScaleComponent(&target_scale_for_segment))
+ return false;
+ float max_scale_for_segment =
+ fmax(std::abs(target_scale_for_segment.x()),
+ fmax(std::abs(target_scale_for_segment.y()),
+ std::abs(target_scale_for_segment.z())));
+ *max_scale = fmax(*max_scale, max_scale_for_segment);
+ }
+ return true;
+}
+
scoped_ptr<KeyframedFilterAnimationCurve> KeyframedFilterAnimationCurve::
Create() {
return make_scoped_ptr(new KeyframedFilterAnimationCurve);