diff options
author | Kristian Monsen <kristianm@google.com> | 2010-09-08 12:18:00 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2010-09-11 12:08:58 +0100 |
commit | 5ddde30071f639962dd557c453f2ad01f8f0fd00 (patch) | |
tree | 775803c4ab35af50aa5f5472cd1fb95fe9d5152d /WebCore/page/animation | |
parent | 3e63d9b33b753ca86d0765d1b3d711114ba9e34f (diff) | |
download | external_webkit-5ddde30071f639962dd557c453f2ad01f8f0fd00.zip external_webkit-5ddde30071f639962dd557c453f2ad01f8f0fd00.tar.gz external_webkit-5ddde30071f639962dd557c453f2ad01f8f0fd00.tar.bz2 |
Merge WebKit at r66666 : Initial merge by git.
Change-Id: I57dedeb49859adc9c539e760f0e749768c66626f
Diffstat (limited to 'WebCore/page/animation')
-rw-r--r-- | WebCore/page/animation/AnimationBase.cpp | 12 | ||||
-rw-r--r-- | WebCore/page/animation/KeyframeAnimation.cpp | 146 | ||||
-rw-r--r-- | WebCore/page/animation/KeyframeAnimation.h | 4 |
3 files changed, 96 insertions, 66 deletions
diff --git a/WebCore/page/animation/AnimationBase.cpp b/WebCore/page/animation/AnimationBase.cpp index 4f304e2..d4926ea 100644 --- a/WebCore/page/animation/AnimationBase.cpp +++ b/WebCore/page/animation/AnimationBase.cpp @@ -644,10 +644,10 @@ void AnimationBase::ensurePropertyMap() gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitTransformOriginX, &RenderStyle::transformOriginX, &RenderStyle::setTransformOriginX)); gPropertyWrappers->append(new PropertyWrapper<Length>(CSSPropertyWebkitTransformOriginY, &RenderStyle::transformOriginY, &RenderStyle::setTransformOriginY)); gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyWebkitTransformOriginZ, &RenderStyle::transformOriginZ, &RenderStyle::setTransformOriginZ)); - gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius)); - gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius)); - gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius)); - gPropertyWrappers->append(new PropertyWrapper<const IntSize&>(CSSPropertyBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius)); + gPropertyWrappers->append(new PropertyWrapper<const LengthSize&>(CSSPropertyBorderTopLeftRadius, &RenderStyle::borderTopLeftRadius, &RenderStyle::setBorderTopLeftRadius)); + gPropertyWrappers->append(new PropertyWrapper<const LengthSize&>(CSSPropertyBorderTopRightRadius, &RenderStyle::borderTopRightRadius, &RenderStyle::setBorderTopRightRadius)); + gPropertyWrappers->append(new PropertyWrapper<const LengthSize&>(CSSPropertyBorderBottomLeftRadius, &RenderStyle::borderBottomLeftRadius, &RenderStyle::setBorderBottomLeftRadius)); + gPropertyWrappers->append(new PropertyWrapper<const LengthSize&>(CSSPropertyBorderBottomRightRadius, &RenderStyle::borderBottomRightRadius, &RenderStyle::setBorderBottomRightRadius)); gPropertyWrappers->append(new PropertyWrapper<EVisibility>(CSSPropertyVisibility, &RenderStyle::visibility, &RenderStyle::setVisibility)); gPropertyWrappers->append(new PropertyWrapper<float>(CSSPropertyZoom, &RenderStyle::zoom, &RenderStyle::setZoom)); @@ -1114,7 +1114,7 @@ void AnimationBase::updateStateMachine(AnimStateInput input, double param) } else { bool started = startAnimation(beginAnimationUpdateTime() - m_startTime); m_compAnim->animationController()->addToStartTimeResponseWaitList(this, started); - m_isAccelerated = !started; + m_isAccelerated = started; } } break; @@ -1242,7 +1242,7 @@ double AnimationBase::progress(double scale, double offset, const TimingFunction int integralTime = static_cast<int>(fractionalTime); fractionalTime -= integralTime; - if (m_animation->direction() && (integralTime & 1)) + if ((m_animation->direction() == Animation::AnimationDirectionAlternate) && (integralTime & 1)) fractionalTime = 1 - fractionalTime; if (scale != 1 || offset) diff --git a/WebCore/page/animation/KeyframeAnimation.cpp b/WebCore/page/animation/KeyframeAnimation.cpp index 2f2cfc0..01ec2f1 100644 --- a/WebCore/page/animation/KeyframeAnimation.cpp +++ b/WebCore/page/animation/KeyframeAnimation.cpp @@ -62,41 +62,67 @@ KeyframeAnimation::~KeyframeAnimation() endAnimation(); } -void KeyframeAnimation::getKeyframeAnimationInterval(const RenderStyle*& fromStyle, const RenderStyle*& toStyle, double& prog) const +void KeyframeAnimation::fetchIntervalEndpointsForProperty(int property, const RenderStyle*& fromStyle, const RenderStyle*& toStyle, double& prog) const { // Find the first key double elapsedTime = getElapsedTime(); - double t = m_animation->duration() ? (elapsedTime / m_animation->duration()) : 1; + double fractionalTime = m_animation->duration() ? (elapsedTime / m_animation->duration()) : 1; - ASSERT(t >= 0); - if (t < 0) - t = 0; + ASSERT(fractionalTime >= 0); + if (fractionalTime < 0) + fractionalTime = 0; - int i = static_cast<int>(t); - t -= i; - if (m_animation->direction() && (i & 1)) - t = 1 - t; + // FIXME: share this code with AnimationBase::progress(). + int iteration = static_cast<int>(fractionalTime); + fractionalTime -= iteration; + + bool reversing = (m_animation->direction() == Animation::AnimationDirectionAlternate) && (iteration & 1); + if (reversing) + fractionalTime = 1 - fractionalTime; - double scale = 1; - double offset = 0; - Vector<KeyframeValue>::const_iterator endKeyframes = m_keyframes.endKeyframes(); - for (Vector<KeyframeValue>::const_iterator it = m_keyframes.beginKeyframes(); it != endKeyframes; ++it) { - if (t < it->key()) { - // The first key should always be 0, so we should never succeed on the first key - if (!fromStyle) - break; - scale = 1.0 / (it->key() - offset); - toStyle = it->style(); + size_t numKeyframes = m_keyframes.size(); + if (!numKeyframes) + return; + + ASSERT(!m_keyframes[0].key()); + ASSERT(m_keyframes[m_keyframes.size() - 1].key() == 1); + + int prevIndex = -1; + int nextIndex = -1; + + // FIXME: with a lot of keys, this linear search will be slow. We could binary search. + for (size_t i = 0; i < numKeyframes; ++i) { + const KeyframeValue& currKeyFrame = m_keyframes[i]; + + if (!currKeyFrame.containsProperty(property)) + continue; + + if (fractionalTime < currKeyFrame.key()) { + nextIndex = i; break; } - - offset = it->key(); - fromStyle = it->style(); + + prevIndex = i; } - if (!fromStyle || !toStyle) - return; + double scale = 1; + double offset = 0; + + if (prevIndex == -1) + prevIndex = 0; + + if (nextIndex == -1) + nextIndex = m_keyframes.size() - 1; + + const KeyframeValue& prevKeyframe = m_keyframes[prevIndex]; + const KeyframeValue& nextKeyframe = m_keyframes[nextIndex]; + + fromStyle = prevKeyframe.style(); + toStyle = nextKeyframe.style(); + + offset = prevKeyframe.key(); + scale = 1.0 / (nextKeyframe.key() - prevKeyframe.key()); const TimingFunction* timingFunction = 0; if (fromStyle->animations() && fromStyle->animations()->size() > 0) { @@ -131,18 +157,9 @@ void KeyframeAnimation::animate(CompositeAnimation*, RenderObject*, const Render // through to the style blend so that we get the fromStyle. if (waitingToStart() && m_animation->delay() > 0 && !m_animation->fillsBackwards()) return; - - // FIXME: we need to be more efficient about determining which keyframes we are animating between. - // We should cache the last pair or something. - // Get the from/to styles and progress between - const RenderStyle* fromStyle = 0; - const RenderStyle* toStyle = 0; - double progress; - getKeyframeAnimationInterval(fromStyle, toStyle, progress); - - // If either style is 0 we have an invalid case, just stop the animation. - if (!fromStyle || !toStyle) { + // If we have no keyframes, don't animate. + if (!m_keyframes.size()) { updateStateMachine(AnimationStateInputEndAnimation, -1); return; } @@ -152,9 +169,19 @@ void KeyframeAnimation::animate(CompositeAnimation*, RenderObject*, const Render if (!animatedStyle) animatedStyle = RenderStyle::clone(targetStyle); + // FIXME: we need to be more efficient about determining which keyframes we are animating between. + // We should cache the last pair or something. HashSet<int>::const_iterator endProperties = m_keyframes.endProperties(); for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != endProperties; ++it) { - bool needsAnim = blendProperties(this, *it, animatedStyle.get(), fromStyle, toStyle, progress); + int property = *it; + + // Get the from/to styles and progress between + const RenderStyle* fromStyle = 0; + const RenderStyle* toStyle = 0; + double progress; + fetchIntervalEndpointsForProperty(property, fromStyle, toStyle, progress); + + bool needsAnim = blendProperties(this, property, animatedStyle.get(), fromStyle, toStyle, progress); if (needsAnim) setAnimating(); else { @@ -175,26 +202,29 @@ void KeyframeAnimation::getAnimatedStyle(RefPtr<RenderStyle>& animatedStyle) if (waitingToStart() && m_animation->delay() > 0 && !m_animation->fillsBackwards()) return; - // Get the from/to styles and progress between - const RenderStyle* fromStyle = 0; - const RenderStyle* toStyle = 0; - double progress; - getKeyframeAnimationInterval(fromStyle, toStyle, progress); - - // If either style is 0 we have an invalid case - if (!fromStyle || !toStyle) + if (!m_keyframes.size()) return; if (!animatedStyle) animatedStyle = RenderStyle::clone(m_object->style()); HashSet<int>::const_iterator endProperties = m_keyframes.endProperties(); - for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != endProperties; ++it) - blendProperties(this, *it, animatedStyle.get(), fromStyle, toStyle, progress); + for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != endProperties; ++it) { + int property = *it; + + // Get the from/to styles and progress between + const RenderStyle* fromStyle = 0; + const RenderStyle* toStyle = 0; + double progress; + fetchIntervalEndpointsForProperty(property, fromStyle, toStyle, progress); + + blendProperties(this, property, animatedStyle.get(), fromStyle, toStyle, progress); + } } bool KeyframeAnimation::hasAnimationForProperty(int property) const { + // FIXME: why not just m_keyframes.containsProperty()? HashSet<int>::const_iterator end = m_keyframes.endProperties(); for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != end; ++it) { if (*it == property) @@ -346,27 +376,27 @@ void KeyframeAnimation::validateTransformFunctionList() if (m_keyframes.size() < 2 || !m_keyframes.containsProperty(CSSPropertyWebkitTransform)) return; - Vector<KeyframeValue>::const_iterator end = m_keyframes.endKeyframes(); - // Empty transforms match anything, so find the first non-empty entry as the reference - size_t firstIndex = 0; - Vector<KeyframeValue>::const_iterator firstIt = end; - - for (Vector<KeyframeValue>::const_iterator it = m_keyframes.beginKeyframes(); it != end; ++it, ++firstIndex) { - if (it->style()->transform().operations().size() > 0) { - firstIt = it; + size_t numKeyframes = m_keyframes.size(); + size_t firstNonEmptyTransformKeyframeIndex = numKeyframes; + + for (size_t i = 0; i < numKeyframes; ++i) { + const KeyframeValue& currentKeyframe = m_keyframes[i]; + if (currentKeyframe.style()->transform().operations().size()) { + firstNonEmptyTransformKeyframeIndex = i; break; } } - if (firstIt == end) + if (firstNonEmptyTransformKeyframeIndex == numKeyframes) return; - const TransformOperations* firstVal = &firstIt->style()->transform(); + const TransformOperations* firstVal = &m_keyframes[firstNonEmptyTransformKeyframeIndex].style()->transform(); // See if the keyframes are valid - for (Vector<KeyframeValue>::const_iterator it = firstIt+1; it != end; ++it) { - const TransformOperations* val = &it->style()->transform(); + for (size_t i = firstNonEmptyTransformKeyframeIndex + 1; i < numKeyframes; ++i) { + const KeyframeValue& currentKeyframe = m_keyframes[i]; + const TransformOperations* val = ¤tKeyframe.style()->transform(); // A null transform matches anything if (val->operations().isEmpty()) diff --git a/WebCore/page/animation/KeyframeAnimation.h b/WebCore/page/animation/KeyframeAnimation.h index fab0ae8..a187f35 100644 --- a/WebCore/page/animation/KeyframeAnimation.h +++ b/WebCore/page/animation/KeyframeAnimation.h @@ -82,8 +82,8 @@ private: KeyframeAnimation(const Animation* animation, RenderObject*, int index, CompositeAnimation*, RenderStyle* unanimatedStyle); virtual ~KeyframeAnimation(); - // Get the styles surrounding the current animation time and the progress between them - void getKeyframeAnimationInterval(const RenderStyle*& fromStyle, const RenderStyle*& toStyle, double& progress) const; + // Get the styles for the given property surrounding the current animation time and the progress between them. + void fetchIntervalEndpointsForProperty(int property, const RenderStyle*& fromStyle, const RenderStyle*& toStyle, double& progress) const; // The keyframes that we are blending. KeyframeList m_keyframes; |