Upstream version 11.39.250.0
[platform/framework/web/crosswalk.git] / src / cc / animation / keyframed_animation_curve.cc
index 39266b1..eaa0ea0 100644 (file)
@@ -2,6 +2,8 @@
 // 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"
@@ -38,14 +40,6 @@ float GetProgress(double t, size_t i, const Keyframes& keyframes) {
   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)
@@ -79,7 +73,7 @@ SkColor ColorKeyframe::Value() const { return value_; }
 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());
 }
 
@@ -106,7 +100,7 @@ float FloatKeyframe::Value() const {
 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());
 }
 
@@ -133,7 +127,7 @@ const TransformOperations& TransformKeyframe::Value() const {
 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());
 }
 
@@ -160,7 +154,7 @@ const FilterOperations& FilterKeyframe::Value() const {
 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());
 }
 
@@ -333,6 +327,51 @@ bool KeyframedTransformAnimationCurve::AnimatedBoundsForBox(
   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);