OSDN Git Service

Fix CSS animation bugs
authorNicolas Roard <nicolasroard@google.com>
Wed, 9 Mar 2011 01:06:17 +0000 (17:06 -0800)
committerNicolas Roard <nicolasroard@google.com>
Wed, 9 Mar 2011 03:04:37 +0000 (19:04 -0800)
- we were replacing animations by new ones regardless of their types, so
  when two anims (i.e. transform and opacity) where set on the same
  layer, we'd only run the last one
- the selection of the keys for keyframes animations was buggy

bug:2453890
Change-Id: I03da3f6c2ba1f5bf778e099e52d71d2f5e67d27e

WebCore/platform/graphics/android/AndroidAnimation.cpp
WebCore/platform/graphics/android/AndroidAnimation.h
WebCore/platform/graphics/android/LayerAndroid.cpp

index 47fc82c..3280d07 100644 (file)
@@ -54,7 +54,8 @@ long AndroidAnimation::instancesCount()
     return gDebugAndroidAnimationInstances;
 }
 
-AndroidAnimation::AndroidAnimation(const Animation* animation,
+AndroidAnimation::AndroidAnimation(AndroidAnimationType type,
+                                   const Animation* animation,
                                    double beginTime)
     : m_beginTime(beginTime)
     , m_duration(animation->duration())
@@ -63,6 +64,7 @@ AndroidAnimation::AndroidAnimation(const Animation* animation,
     , m_direction(animation->direction())
     , m_currentDirection(false)
     , m_timingFunction(animation->timingFunction())
+    , m_type(type)
 {
     ASSERT(m_timingFunction);
 
@@ -80,6 +82,7 @@ AndroidAnimation::AndroidAnimation(AndroidAnimation* anim)
     , m_direction(anim->m_direction)
     , m_currentDirection(false)
     , m_timingFunction(anim->m_timingFunction)
+    , m_type(anim->m_type)
 {
     gDebugAndroidAnimationInstances++;
 }
@@ -147,7 +150,7 @@ PassRefPtr<AndroidOpacityAnimation> AndroidOpacityAnimation::create(
 AndroidOpacityAnimation::AndroidOpacityAnimation(const Animation* animation,
                                                  KeyframeValueList* operations,
                                                  double beginTime)
-    : AndroidAnimation(animation, beginTime)
+    : AndroidAnimation(AndroidAnimation::OPACITY, animation, beginTime)
     , m_operations(operations)
 {
 }
@@ -231,7 +234,7 @@ PassRefPtr<AndroidTransformAnimation> AndroidTransformAnimation::create(
 AndroidTransformAnimation::AndroidTransformAnimation(const Animation* animation,
                                                      KeyframeValueList* operations,
                                                      double beginTime)
-    : AndroidAnimation(animation, beginTime)
+    : AndroidAnimation(AndroidAnimation::TRANSFORM, animation, beginTime)
     , m_operations(operations)
 {
 }
@@ -275,9 +278,9 @@ bool AndroidTransformAnimation::evaluate(LayerAndroid* layer, double time)
         TransformAnimationValue* value = (TransformAnimationValue*) m_operations->at(i);
         TransformOperations* values = (TransformOperations*) value->value();
         float key = value->keyTime();
-        float d = fabs(progress - key);
+        float d = progress - key;
         XLOG("[%d] Key %.2f, %d values", i, key, values->size());
-        if (!fromValue || (d < distance && i + 1 < m_operations->size())) {
+        if (!fromValue || (d > 0 && d < distance && i + 1 < m_operations->size())) {
             fromValue = value;
             distance = d;
             foundAt = i;
index ed2789e..d682103 100644 (file)
@@ -35,7 +35,13 @@ class TimingFunction;
 
 class AndroidAnimation : public RefCounted<AndroidAnimation> {
   public:
-    AndroidAnimation(const Animation* animation,
+    enum AndroidAnimationType {
+        UNDEFINED,
+        OPACITY,
+        TRANSFORM
+    };
+    AndroidAnimation(AndroidAnimationType type,
+                     const Animation* animation,
                      double beginTime);
     AndroidAnimation(AndroidAnimation* anim);
 
@@ -48,6 +54,7 @@ class AndroidAnimation : public RefCounted<AndroidAnimation> {
     static long instancesCount();
     void setName(const String& name) { m_name = name; }
     String name() { return m_name; }
+    AndroidAnimationType type() { return m_type; }
 
   protected:
     double m_beginTime;
@@ -59,6 +66,7 @@ class AndroidAnimation : public RefCounted<AndroidAnimation> {
     bool m_currentDirection;
     RefPtr<TimingFunction> m_timingFunction;
     String m_name;
+    AndroidAnimationType m_type;
 };
 
 class AndroidOpacityAnimation : public AndroidAnimation {
index 714fa40..7d68f03 100644 (file)
@@ -243,7 +243,8 @@ bool LayerAndroid::evaluateAnimations(double time) const
 void LayerAndroid::addAnimation(PassRefPtr<AndroidAnimation> prpAnim)
 {
     RefPtr<AndroidAnimation> anim = prpAnim;
-    if (m_animations.get(anim->name()))
+    RefPtr<AndroidAnimation> currentAnim = m_animations.get(anim->name());
+    if (currentAnim && currentAnim->type() == anim->type())
         removeAnimation(anim->name());
     m_animations.add(anim->name(), anim);
 }