Title: [221941] trunk/Source/WebCore
Revision
221941
Author
[email protected]
Date
2017-09-12 15:09:47 -0700 (Tue, 12 Sep 2017)

Log Message

AnimationBase should point to Element instead of RenderElement
https://bugs.webkit.org/show_bug.cgi?id=176807

Reviewed by Andreas Kling.

This is a step towards making animation system operate on elements and styles instead renderers.

No functional changes.

* page/animation/AnimationBase.cpp:
(WebCore::AnimationBase::AnimationBase):
(WebCore::AnimationBase::renderer const):
(WebCore::AnimationBase::compositedRenderer const):
(WebCore::AnimationBase::updateStateMachine):
(WebCore::AnimationBase::fireAnimationEventsIfNeeded):
(WebCore::AnimationBase::timeToNextService):
(WebCore::AnimationBase::freezeAtTime):
(WebCore::AnimationBase::getElapsedTime const):
* page/animation/AnimationBase.h:
(WebCore::AnimationBase::clear):
(WebCore::AnimationBase::renderer const): Deleted.
* page/animation/ImplicitAnimation.cpp:
(WebCore::ImplicitAnimation::shouldSendEventForListener const):
(WebCore::ImplicitAnimation::computeExtentOfTransformAnimation const):
(WebCore::ImplicitAnimation::startAnimation):
(WebCore::ImplicitAnimation::pauseAnimation):
(WebCore::ImplicitAnimation::endAnimation):
(WebCore::ImplicitAnimation::sendTransitionEvent):
(WebCore::ImplicitAnimation::reset):
* page/animation/KeyframeAnimation.cpp:
(WebCore::KeyframeAnimation::getAnimatedStyle):
(WebCore::KeyframeAnimation::computeExtentOfTransformAnimation const):
(WebCore::KeyframeAnimation::startAnimation):
(WebCore::KeyframeAnimation::pauseAnimation):
(WebCore::KeyframeAnimation::endAnimation):
(WebCore::KeyframeAnimation::shouldSendEventForListener const):
(WebCore::KeyframeAnimation::sendAnimationEvent):
(WebCore::KeyframeAnimation::resolveKeyframeStyles):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (221940 => 221941)


--- trunk/Source/WebCore/ChangeLog	2017-09-12 22:04:01 UTC (rev 221940)
+++ trunk/Source/WebCore/ChangeLog	2017-09-12 22:09:47 UTC (rev 221941)
@@ -1,3 +1,44 @@
+2017-09-12  Antti Koivisto  <[email protected]>
+
+        AnimationBase should point to Element instead of RenderElement
+        https://bugs.webkit.org/show_bug.cgi?id=176807
+
+        Reviewed by Andreas Kling.
+
+        This is a step towards making animation system operate on elements and styles instead renderers.
+
+        No functional changes.
+
+        * page/animation/AnimationBase.cpp:
+        (WebCore::AnimationBase::AnimationBase):
+        (WebCore::AnimationBase::renderer const):
+        (WebCore::AnimationBase::compositedRenderer const):
+        (WebCore::AnimationBase::updateStateMachine):
+        (WebCore::AnimationBase::fireAnimationEventsIfNeeded):
+        (WebCore::AnimationBase::timeToNextService):
+        (WebCore::AnimationBase::freezeAtTime):
+        (WebCore::AnimationBase::getElapsedTime const):
+        * page/animation/AnimationBase.h:
+        (WebCore::AnimationBase::clear):
+        (WebCore::AnimationBase::renderer const): Deleted.
+        * page/animation/ImplicitAnimation.cpp:
+        (WebCore::ImplicitAnimation::shouldSendEventForListener const):
+        (WebCore::ImplicitAnimation::computeExtentOfTransformAnimation const):
+        (WebCore::ImplicitAnimation::startAnimation):
+        (WebCore::ImplicitAnimation::pauseAnimation):
+        (WebCore::ImplicitAnimation::endAnimation):
+        (WebCore::ImplicitAnimation::sendTransitionEvent):
+        (WebCore::ImplicitAnimation::reset):
+        * page/animation/KeyframeAnimation.cpp:
+        (WebCore::KeyframeAnimation::getAnimatedStyle):
+        (WebCore::KeyframeAnimation::computeExtentOfTransformAnimation const):
+        (WebCore::KeyframeAnimation::startAnimation):
+        (WebCore::KeyframeAnimation::pauseAnimation):
+        (WebCore::KeyframeAnimation::endAnimation):
+        (WebCore::KeyframeAnimation::shouldSendEventForListener const):
+        (WebCore::KeyframeAnimation::sendAnimationEvent):
+        (WebCore::KeyframeAnimation::resolveKeyframeStyles):
+
 2017-09-12  Per Arne Vollan  <[email protected]>
 
         [Win] Add Modules/fetch to list of forwarding headers folders.

Modified: trunk/Source/WebCore/page/animation/AnimationBase.cpp (221940 => 221941)


--- trunk/Source/WebCore/page/animation/AnimationBase.cpp	2017-09-12 22:04:01 UTC (rev 221940)
+++ trunk/Source/WebCore/page/animation/AnimationBase.cpp	2017-09-12 22:09:47 UTC (rev 221941)
@@ -77,15 +77,29 @@
 }
 
 AnimationBase::AnimationBase(const Animation& animation, RenderElement* renderer, CompositeAnimation* compositeAnimation)
-    : m_object(renderer)
+    : m_element(renderer->element())
     , m_compositeAnimation(compositeAnimation)
     , m_animation(const_cast<Animation&>(animation))
 {
+    ASSERT(m_element);
     // Compute the total duration
     if (m_animation->iterationCount() > 0)
         m_totalDuration = m_animation->duration() * m_animation->iterationCount();
 }
 
+RenderElement* AnimationBase::renderer() const
+{
+    return m_element ? m_element->renderer() : nullptr;
+}
+
+RenderBoxModelObject* AnimationBase::compositedRenderer() const
+{
+    auto* renderer = this->renderer();
+    if (!renderer || !renderer->isComposited())
+        return nullptr;
+    return downcast<RenderBoxModelObject>(renderer);
+}
+
 void AnimationBase::setNeedsStyleRecalc(Element* element)
 {
     if (!element || element->document().renderTreeBeingDestroyed())
@@ -246,8 +260,8 @@
                 m_compositeAnimation->animationController().addToAnimationsWaitingForStyle(this);
 
                 // Trigger a render so we can start the animation
-                if (m_object && m_object->element())
-                    m_compositeAnimation->animationController().addElementChangeToDispatch(*m_object->element());
+                if (m_element)
+                    m_compositeAnimation->animationController().addElementChangeToDispatch(*m_element);
             } else {
                 ASSERT(!paused());
                 // We're waiting for the start timer to fire and we got a pause. Cancel the timer, pause and wait
@@ -313,8 +327,8 @@
                 goIntoEndingOrLoopingState();
 
                 // Dispatch updateStyleIfNeeded so we can start the animation
-                if (m_object && m_object->element())
-                    m_compositeAnimation->animationController().addElementChangeToDispatch(*m_object->element());
+                if (m_element)
+                    m_compositeAnimation->animationController().addElementChangeToDispatch(*m_element);
             } else {
                 // We are pausing while waiting for a start response. Cancel the animation and wait. When 
                 // we unpause, we will act as though the start timer just fired
@@ -357,7 +371,7 @@
                 LOG(Animations, "%p AnimationState %s -> Done (time is %f)", this, nameForState(m_animationState), param);
                 m_animationState = AnimationState::Done;
                 
-                if (m_object) {
+                if (m_element) {
                     if (m_animation->fillsForwards()) {
                         LOG(Animations, "%p AnimationState %s -> FillingForwards", this, nameForState(m_animationState));
                         m_animationState = AnimationState::FillingForwards;
@@ -365,8 +379,8 @@
                         resumeOverriddenAnimations();
 
                     // Fire off another style change so we can set the final value
-                    if (m_object->element())
-                        m_compositeAnimation->animationController().addElementChangeToDispatch(*m_object->element());
+                    if (m_element)
+                        m_compositeAnimation->animationController().addElementChangeToDispatch(*m_element);
                 }
             } else {
                 // We are pausing while running. Cancel the animation and wait
@@ -491,7 +505,7 @@
     if (m_animationState == AnimationState::StartWaitTimer) {
 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
         if (m_animation->trigger() && m_animation->trigger()->isScrollAnimationTrigger()) {
-            if (m_object) {
+            if (m_element) {
                 float offset = m_compositeAnimation->animationController().scrollPosition();
                 auto& scrollTrigger = downcast<ScrollAnimationTrigger>(*m_animation->trigger());
                 if (offset > scrollTrigger.startValue().value())
@@ -574,8 +588,8 @@
     if (m_animationState == AnimationState::StartWaitTimer) {
 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
         if (m_animation->trigger()->isScrollAnimationTrigger()) {
-            if (m_object) {
-                float currentScrollPosition = m_object->view().frameView().scrollPositionForFixedPosition().y().toFloat();
+            if (m_element) {
+                float currentScrollPosition = m_element->document().view()->scrollPositionForFixedPosition().y().toFloat();
                 auto& scrollTrigger = downcast<ScrollAnimationTrigger>(*m_animation->trigger());
                 if (currentScrollPosition >= scrollTrigger.startValue().value() && (!scrollTrigger.hasEndValue() || currentScrollPosition <= scrollTrigger.endValue().value()))
                     return 0_s;
@@ -726,8 +740,8 @@
     else
         m_pauseTime = m_startTime.value_or(0) + t - m_animation->delay();
 
-    if (m_object && m_object->isComposited())
-        downcast<RenderBoxModelObject>(*m_object).suspendAnimations(m_pauseTime.value());
+    if (auto* renderer = compositedRenderer())
+        renderer->suspendAnimations(m_pauseTime.value());
 }
 
 double AnimationBase::beginAnimationUpdateTime() const
@@ -743,7 +757,7 @@
 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
     if (m_animation->trigger() && m_animation->trigger()->isScrollAnimationTrigger()) {
         auto& scrollTrigger = downcast<ScrollAnimationTrigger>(*m_animation->trigger());
-        if (scrollTrigger.hasEndValue() && m_object) {
+        if (scrollTrigger.hasEndValue() && m_element) {
             float offset = m_compositeAnimation->animationController().scrollPosition();
             float startValue = scrollTrigger.startValue().value();
             if (offset < startValue)

Modified: trunk/Source/WebCore/page/animation/AnimationBase.h (221940 => 221941)


--- trunk/Source/WebCore/page/animation/AnimationBase.h	2017-09-12 22:04:01 UTC (rev 221940)
+++ trunk/Source/WebCore/page/animation/AnimationBase.h	2017-09-12 22:09:47 UTC (rev 221941)
@@ -38,6 +38,7 @@
 class Element;
 class FloatRect;
 class LayoutRect;
+class RenderBoxModelObject;
 class RenderElement;
 class RenderStyle;
 class TimingFunction;
@@ -50,11 +51,12 @@
     AnimationBase(const Animation& transition, RenderElement*, CompositeAnimation*);
     virtual ~AnimationBase() { }
 
-    RenderElement* renderer() const { return m_object; }
+    RenderElement* renderer() const;
+    RenderBoxModelObject* compositedRenderer() const;
     void clear()
     {
         endAnimation();
-        m_object = nullptr;
+        m_element = nullptr;
         m_compositeAnimation = nullptr;
     }
 
@@ -239,7 +241,7 @@
     bool computeTransformedExtentViaTransformList(const FloatRect& rendererBox, const RenderStyle&, LayoutRect& bounds) const;
     bool computeTransformedExtentViaMatrix(const FloatRect& rendererBox, const RenderStyle&, LayoutRect& bounds) const;
 
-    RenderElement* m_object;
+    Element* m_element;
     CompositeAnimation* m_compositeAnimation; // Ideally this would be a reference, but it has to be cleared if an animation is destroyed inside an event callback.
     Ref<Animation> m_animation;
 

Modified: trunk/Source/WebCore/page/animation/ImplicitAnimation.cpp (221940 => 221941)


--- trunk/Source/WebCore/page/animation/ImplicitAnimation.cpp	2017-09-12 22:04:01 UTC (rev 221940)
+++ trunk/Source/WebCore/page/animation/ImplicitAnimation.cpp	2017-09-12 22:09:47 UTC (rev 221941)
@@ -58,7 +58,7 @@
 
 bool ImplicitAnimation::shouldSendEventForListener(Document::ListenerType inListenerType) const
 {
-    return m_object->document().hasListenerType(inListenerType);
+    return m_element->document().hasListenerType(inListenerType);
 }
 
 bool ImplicitAnimation::animate(CompositeAnimation& compositeAnimation, RenderElement*, const RenderStyle*, const RenderStyle& targetStyle, std::unique_ptr<RenderStyle>& animatedStyle, bool& didBlendStyle)
@@ -102,12 +102,12 @@
 {
     ASSERT(hasStyle());
 
-    if (!is<RenderBox>(m_object))
+    if (!is<RenderBox>(renderer()))
         return true; // Non-boxes don't get transformed;
 
     ASSERT(m_animatingProperty == CSSPropertyTransform);
 
-    RenderBox& box = downcast<RenderBox>(*m_object);
+    RenderBox& box = downcast<RenderBox>(*renderer());
     FloatRect rendererBox = snapRectToDevicePixels(box.borderBoxRect(), box.document().deviceScaleFactor());
 
     LayoutRect startBounds = bounds;
@@ -133,27 +133,24 @@
 
 bool ImplicitAnimation::startAnimation(double timeOffset)
 {
-    if (m_object && m_object->isComposited())
-        return downcast<RenderBoxModelObject>(*m_object).startTransition(timeOffset, m_animatingProperty, m_fromStyle.get(), m_toStyle.get());
+    if (auto* renderer = compositedRenderer())
+        return renderer->startTransition(timeOffset, m_animatingProperty, m_fromStyle.get(), m_toStyle.get());
     return false;
 }
 
 void ImplicitAnimation::pauseAnimation(double timeOffset)
 {
-    if (!m_object)
-        return;
-
-    if (m_object->isComposited())
-        downcast<RenderBoxModelObject>(*m_object).transitionPaused(timeOffset, m_animatingProperty);
+    if (auto* renderer = compositedRenderer())
+        renderer->transitionPaused(timeOffset, m_animatingProperty);
     // Restore the original (unanimated) style
     if (!paused())
-        setNeedsStyleRecalc(m_object->element());
+        setNeedsStyleRecalc(m_element);
 }
 
 void ImplicitAnimation::endAnimation()
 {
-    if (m_object && m_object->isComposited())
-        downcast<RenderBoxModelObject>(*m_object).transitionFinished(m_animatingProperty);
+    if (auto* renderer = compositedRenderer())
+        renderer->transitionFinished(m_animatingProperty);
 }
 
 void ImplicitAnimation::onAnimationEnd(double elapsedTime)
@@ -179,7 +176,7 @@
             String propertyName = getPropertyNameString(m_animatingProperty);
                 
             // Dispatch the event
-            RefPtr<Element> element = m_object->element();
+            auto element = makeRefPtr(m_element);
 
             ASSERT(!element || element->document().pageCacheState() == Document::NotInPageCache);
             if (!element)
@@ -205,8 +202,8 @@
 
     m_toStyle = RenderStyle::clonePtr(to);
 
-    if (m_object && m_object->element())
-        Style::loadPendingResources(*m_toStyle, m_object->element()->document(), m_object->element());
+    if (m_element)
+        Style::loadPendingResources(*m_toStyle, m_element->document(), m_element);
 
     // Restart the transition.
     if (m_fromStyle && m_toStyle && !compositeAnimation.isSuspended())

Modified: trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp (221940 => 221941)


--- trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp	2017-09-12 22:04:01 UTC (rev 221940)
+++ trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp	2017-09-12 22:09:47 UTC (rev 221941)
@@ -223,7 +223,7 @@
         return;
 
     if (!animatedStyle)
-        animatedStyle = RenderStyle::clonePtr(m_object->style());
+        animatedStyle = RenderStyle::clonePtr(renderer()->style());
 
     for (auto propertyID : m_keyframes.properties()) {
         // Get the from/to styles and progress between
@@ -240,10 +240,10 @@
 {
     ASSERT(m_keyframes.containsProperty(CSSPropertyTransform));
 
-    if (!is<RenderBox>(m_object))
+    if (!is<RenderBox>(renderer()))
         return true; // Non-boxes don't get transformed;
 
-    RenderBox& box = downcast<RenderBox>(*m_object);
+    RenderBox& box = downcast<RenderBox>(*renderer());
     FloatRect rendererBox = snapRectToDevicePixels(box.borderBoxRect(), box.document().deviceScaleFactor());
 
     FloatRect cumulativeBounds = bounds;
@@ -277,40 +277,40 @@
 
 bool KeyframeAnimation::startAnimation(double timeOffset)
 {
-    if (m_object && m_object->isComposited())
-        return downcast<RenderBoxModelObject>(*m_object).startAnimation(timeOffset, m_animation.ptr(), m_keyframes);
+    if (auto* renderer = compositedRenderer())
+        return renderer->startAnimation(timeOffset, m_animation.ptr(), m_keyframes);
     return false;
 }
 
 void KeyframeAnimation::pauseAnimation(double timeOffset)
 {
-    if (!m_object)
+    if (!m_element)
         return;
 
-    if (m_object->isComposited())
-        downcast<RenderBoxModelObject>(*m_object).animationPaused(timeOffset, m_keyframes.animationName());
+    if (auto* renderer = compositedRenderer())
+        renderer->animationPaused(timeOffset, m_keyframes.animationName());
 
     // Restore the original (unanimated) style
     if (!paused())
-        setNeedsStyleRecalc(m_object->element());
+        setNeedsStyleRecalc(m_element);
 }
 
 void KeyframeAnimation::endAnimation()
 {
-    if (!m_object)
+    if (!m_element)
         return;
 
-    if (m_object->isComposited())
-        downcast<RenderBoxModelObject>(*m_object).animationFinished(m_keyframes.animationName());
+    if (auto* renderer = compositedRenderer())
+        renderer->animationFinished(m_keyframes.animationName());
 
     // Restore the original (unanimated) style
     if (!paused())
-        setNeedsStyleRecalc(m_object->element());
+        setNeedsStyleRecalc(m_element);
 }
 
 bool KeyframeAnimation::shouldSendEventForListener(Document::ListenerType listenerType) const
 {
-    return m_object->document().hasListenerType(listenerType);
+    return m_element->document().hasListenerType(listenerType);
 }
 
 void KeyframeAnimation::onAnimationStart(double elapsedTime)
@@ -349,7 +349,7 @@
 
     if (shouldSendEventForListener(listenerType)) {
         // Dispatch the event
-        RefPtr<Element> element = m_object->element();
+        auto element = makeRefPtr(m_element);
 
         ASSERT(!element || element->document().pageCacheState() == Document::NotInPageCache);
         if (!element)
@@ -389,17 +389,16 @@
 
 void KeyframeAnimation::resolveKeyframeStyles()
 {
-    if (!m_object || !m_object->element())
+    if (!m_element)
         return;
-    auto& element = *m_object->element();
 
-    if (auto* styleScope = Style::Scope::forOrdinal(element, m_animation->nameStyleScopeOrdinal()))
-        styleScope->resolver().keyframeStylesForAnimation(*m_object->element(), m_unanimatedStyle.get(), m_keyframes);
+    if (auto* styleScope = Style::Scope::forOrdinal(*m_element, m_animation->nameStyleScopeOrdinal()))
+        styleScope->resolver().keyframeStylesForAnimation(*m_element, m_unanimatedStyle.get(), m_keyframes);
 
     // Ensure resource loads for all the frames.
     for (auto& keyframe : m_keyframes.keyframes()) {
         if (auto* style = const_cast<RenderStyle*>(keyframe.style()))
-            Style::loadPendingResources(*style, element.document(), &element);
+            Style::loadPendingResources(*style, m_element->document(), m_element);
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to