diff options
author | Nicolas Roard <nicolasroard@google.com> | 2011-03-08 19:03:34 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-03-08 19:03:34 -0800 |
commit | 42046545ce1012ef3f925011573d265339778bed (patch) | |
tree | 8540372be9b44c833fdfe3dc258e17b1e0e64346 /WebCore/platform | |
parent | 67e4aa15702646d5ff50e9524f4e63eb9ed20122 (diff) | |
parent | 8d060c05a073fedcf8cd4142926ff5a5e1991de9 (diff) | |
download | external_webkit-42046545ce1012ef3f925011573d265339778bed.zip external_webkit-42046545ce1012ef3f925011573d265339778bed.tar.gz external_webkit-42046545ce1012ef3f925011573d265339778bed.tar.bz2 |
Merge "Fix 2453890: animation via css -webkit-transform" into honeycomb-mr1
Diffstat (limited to 'WebCore/platform')
3 files changed, 70 insertions, 26 deletions
diff --git a/WebCore/platform/graphics/android/AndroidAnimation.cpp b/WebCore/platform/graphics/android/AndroidAnimation.cpp index e01bf55..47fc82c 100644 --- a/WebCore/platform/graphics/android/AndroidAnimation.cpp +++ b/WebCore/platform/graphics/android/AndroidAnimation.cpp @@ -136,28 +136,25 @@ bool AndroidAnimation::checkIterationsAndProgress(double time, float* finalProgr } PassRefPtr<AndroidOpacityAnimation> AndroidOpacityAnimation::create( - float fromValue, - float toValue, const Animation* animation, + KeyframeValueList* operations, double beginTime) { - return adoptRef(new AndroidOpacityAnimation(fromValue, toValue, - animation, beginTime)); + return adoptRef(new AndroidOpacityAnimation(animation, operations, + beginTime)); } -AndroidOpacityAnimation::AndroidOpacityAnimation(float fromValue, float toValue, - const Animation* animation, +AndroidOpacityAnimation::AndroidOpacityAnimation(const Animation* animation, + KeyframeValueList* operations, double beginTime) : AndroidAnimation(animation, beginTime) - , m_fromValue(fromValue) - , m_toValue(toValue) + , m_operations(operations) { } AndroidOpacityAnimation::AndroidOpacityAnimation(AndroidOpacityAnimation* anim) : AndroidAnimation(anim) - , m_fromValue(anim->m_fromValue) - , m_toValue(anim->m_toValue) + , m_operations(anim->m_operations) { } @@ -175,8 +172,51 @@ bool AndroidOpacityAnimation::evaluate(LayerAndroid* layer, double time) if (progress < 0) // we still want to be evaluated until we get progress > 0 return true; - float value = m_fromValue + ((m_toValue - m_fromValue) * progress); + // First, we need to get the from and to values + + FloatAnimationValue* fromValue = 0; + FloatAnimationValue* toValue = 0; + + float distance = 0; + unsigned int foundAt = 0; + for (unsigned int i = 0; i < m_operations->size(); i++) { + FloatAnimationValue* value = (FloatAnimationValue*) m_operations->at(i); + float opacity = (float) value->value(); + float key = value->keyTime(); + float d = progress - key; + XLOG("[%d] Key %.2f, opacity %.4f", i, key, opacity); + if (!fromValue || (d > 0 && d < distance && i + 1 < m_operations->size())) { + fromValue = value; + distance = d; + foundAt = i; + } + } + + if (foundAt + 1 < m_operations->size()) + toValue = (FloatAnimationValue*) m_operations->at(foundAt + 1); + else + toValue = fromValue; + + XLOG("[layer %d] fromValue %x, key %.2f, toValue %x, key %.2f for progress %.2f", + layer->uniqueId(), + fromValue, fromValue->keyTime(), + toValue, toValue->keyTime(), progress); + + // We now have the correct two values to work with, let's compute the + // progress value + + float delta = toValue->keyTime() - fromValue->keyTime(); + float rprogress = (progress - fromValue->keyTime()) / delta; + XLOG("We picked keys %.2f to %.2f for progress %.2f, real progress %.2f", + fromValue->keyTime(), toValue->keyTime(), progress, rprogress); + progress = rprogress; + + float from = (float) fromValue->value(); + float to = (float) toValue->value(); + float value = from + ((to - from) * progress); + layer->setOpacity(value); + XLOG("AndroidOpacityAnimation::evaluate(%p, %p, %L) value=%.6f", this, layer, time, value); return true; } diff --git a/WebCore/platform/graphics/android/AndroidAnimation.h b/WebCore/platform/graphics/android/AndroidAnimation.h index 3cc1608..ed2789e 100644 --- a/WebCore/platform/graphics/android/AndroidAnimation.h +++ b/WebCore/platform/graphics/android/AndroidAnimation.h @@ -63,12 +63,11 @@ class AndroidAnimation : public RefCounted<AndroidAnimation> { class AndroidOpacityAnimation : public AndroidAnimation { public: - static PassRefPtr<AndroidOpacityAnimation> create(float fromValue, - float toValue, - const Animation* animation, - double beginTime); - AndroidOpacityAnimation(float fromValue, float toValue, - const Animation* animation, + static PassRefPtr<AndroidOpacityAnimation> create(const Animation* animation, + KeyframeValueList* operations, + double beginTime); + AndroidOpacityAnimation(const Animation* animation, + KeyframeValueList* operations, double beginTime); AndroidOpacityAnimation(AndroidOpacityAnimation* anim); virtual PassRefPtr<AndroidAnimation> copy(); @@ -76,8 +75,7 @@ class AndroidOpacityAnimation : public AndroidAnimation { virtual bool evaluate(LayerAndroid* layer, double time); private: - float m_fromValue; - float m_toValue; + KeyframeValueList* m_operations; }; class AndroidTransformAnimation : public AndroidAnimation { diff --git a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index 4cd48a8..54346e5 100644 --- a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -728,15 +728,21 @@ bool GraphicsLayerAndroid::createAnimationFromKeyframes(const KeyframeValueList& case AnimatedPropertyInvalid: break; case AnimatedPropertyWebkitTransform: break; case AnimatedPropertyBackgroundColor: break; + case AnimatedPropertyOpacity: { MLOG("ANIMATEDPROPERTYOPACITY"); - const FloatAnimationValue* startVal = - static_cast<const FloatAnimationValue*>(valueList.at(0)); - const FloatAnimationValue* endVal = - static_cast<const FloatAnimationValue*>(valueList.at(1)); - RefPtr<AndroidOpacityAnimation> anim = AndroidOpacityAnimation::create(startVal->value(), - endVal->value(), - animation, + + KeyframeValueList* operationsList = new KeyframeValueList(AnimatedPropertyOpacity); + for (unsigned int i = 0; i < valueList.size(); i++) { + FloatAnimationValue* originalValue = (FloatAnimationValue*)valueList.at(i); + FloatAnimationValue* value = new FloatAnimationValue(originalValue->keyTime(), + originalValue->value(), 0); + // TODO: pass the timing function originalValue->timingFunction()); + operationsList->insert(value); + } + + RefPtr<AndroidOpacityAnimation> anim = AndroidOpacityAnimation::create(animation, + operationsList, beginTime); if (keyframesName.isEmpty()) anim->setName(propertyIdToString(valueList.property())); |