⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243304 in webkit


Ignore:
Timestamp:
Mar 21, 2019, 11:33:11 AM (7 years ago)
Author:
Alan Bujtas
Message:

[ContentChangeObserver] Add support for observing implicit transitions
https://bugs.webkit.org/show_bug.cgi?id=195914
<rdar://problem/49091959>

Reviewed by Simon Fraser.

This patch is in preparation for observing elements with property "left" implicit transitions.

This is not a continuous tracking, we are only interested in the start and the end state.
The idea here is to register hidden elements only and check if they become visible by
the end of the transition (and ignore if the transition gets "canceled").

  • page/animation/AnimationBase.h:
  • page/animation/ImplicitAnimation.cpp:

(WebCore::ImplicitAnimation::ImplicitAnimation):
(WebCore::ImplicitAnimation::~ImplicitAnimation):
(WebCore::ImplicitAnimation::clear):
(WebCore::ImplicitAnimation::onAnimationEnd):

  • page/animation/ImplicitAnimation.h:
  • page/ios/ContentChangeObserver.cpp:

(WebCore::ContentChangeObserver::didAddTransition):
(WebCore::ContentChangeObserver::removeTransitionIfNeeded):
(WebCore::ContentChangeObserver::didFinishTransition):
(WebCore::ContentChangeObserver::didRemoveTransition):
(WebCore::ContentChangeObserver::didInstallDOMTimer):

  • page/ios/ContentChangeObserver.h:

(WebCore::ContentChangeObserver::isObservingTransitions const):
(WebCore::ContentChangeObserver::isObservedPropertyForTransition const):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r243303 r243304  
     12019-03-21  Zalan Bujtas  <zalan@apple.com>
     2
     3        [ContentChangeObserver] Add support for observing implicit transitions
     4        https://bugs.webkit.org/show_bug.cgi?id=195914
     5        <rdar://problem/49091959>
     6
     7        Reviewed by Simon Fraser.
     8
     9        This patch is in preparation for observing elements with property "left" implicit transitions.
     10
     11        This is not a continuous tracking, we are only interested in the start and the end state.
     12        The idea here is to register hidden elements only and check if they become visible by
     13        the end of the transition (and ignore if the transition gets "canceled").
     14
     15        * page/animation/AnimationBase.h:
     16        * page/animation/ImplicitAnimation.cpp:
     17        (WebCore::ImplicitAnimation::ImplicitAnimation):
     18        (WebCore::ImplicitAnimation::~ImplicitAnimation):
     19        (WebCore::ImplicitAnimation::clear):
     20        (WebCore::ImplicitAnimation::onAnimationEnd):
     21        * page/animation/ImplicitAnimation.h:
     22        * page/ios/ContentChangeObserver.cpp:
     23        (WebCore::ContentChangeObserver::didAddTransition):
     24        (WebCore::ContentChangeObserver::removeTransitionIfNeeded):
     25        (WebCore::ContentChangeObserver::didFinishTransition):
     26        (WebCore::ContentChangeObserver::didRemoveTransition):
     27        (WebCore::ContentChangeObserver::didInstallDOMTimer):
     28        * page/ios/ContentChangeObserver.h:
     29        (WebCore::ContentChangeObserver::isObservingTransitions const):
     30        (WebCore::ContentChangeObserver::isObservedPropertyForTransition const):
     31
    1322019-03-21  Devin Rousso  <drousso@apple.com>
    233
  • trunk/Source/WebCore/page/animation/AnimationBase.h

    r243112 r243304  
    6262    const RenderStyle& currentStyle() const override;
    6363    RenderElement* renderer() const override;
    64     void clear();
     64    virtual void clear();
    6565
    6666    double duration() const;
  • trunk/Source/WebCore/page/animation/ImplicitAnimation.cpp

    r243112 r243304  
    3333#include "CSSPropertyAnimation.h"
    3434#include "CompositeAnimation.h"
     35#if PLATFORM(IOS_FAMILY)
     36#include "ContentChangeObserver.h"
     37#endif
    3538#include "EventNames.h"
    3639#include "GeometryUtilities.h"
     
    4750    , m_animatingProperty(animatingProperty)
    4851{
     52#if PLATFORM(IOS_FAMILY)
     53    element.document().contentChangeObserver().didAddTransition(element, transition);
     54#endif
    4955    ASSERT(animatingProperty != CSSPropertyInvalid);
    5056}
     
    5258ImplicitAnimation::~ImplicitAnimation()
    5359{
     60#if PLATFORM(IOS_FAMILY)
     61    if (auto* element = this->element())
     62        element->document().contentChangeObserver().didRemoveTransition(*element, m_animatingProperty);
     63#endif
    5464    // // Make sure to tell the renderer that we are ending. This will make sure any accelerated animations are removed.
    5565    if (!postActive())
     
    159169}
    160170
     171void ImplicitAnimation::clear()
     172{
     173#if PLATFORM(IOS_FAMILY)
     174    if (auto* element = this->element())
     175        element->document().contentChangeObserver().didRemoveTransition(*element, m_animatingProperty);
     176#endif
     177    AnimationBase::clear();
     178}
     179
    161180void ImplicitAnimation::endAnimation(bool)
    162181{
     
    167186void ImplicitAnimation::onAnimationEnd(double elapsedTime)
    168187{
     188#if PLATFORM(IOS_FAMILY)
     189    if (auto* element = this->element())
     190        element->document().contentChangeObserver().didFinishTransition(*element, m_animatingProperty);
     191#endif
    169192    // If we have a keyframe animation on this property, this transition is being overridden. The keyframe
    170193    // animation keeps an unanimated style in case a transition starts while the keyframe animation is
  • trunk/Source/WebCore/page/animation/ImplicitAnimation.h

    r240012 r243304  
    8080    const RenderStyle& unanimatedStyle() const override { return *m_fromStyle; }
    8181
     82    void clear() override;
     83
    8284protected:
    8385    bool shouldSendEventForListener(Document::ListenerType) const;   
  • trunk/Source/WebCore/page/ios/ContentChangeObserver.cpp

    r243017 r243304  
    4040namespace WebCore {
    4141
     42static const Seconds maximumDelayForTimers { 300_ms };
     43static const Seconds maximumDelayForTransitions { 300_ms };
     44
    4245ContentChangeObserver::ContentChangeObserver(Document& document)
    4346    : m_document(document)
     
    8285}
    8386
     87void ContentChangeObserver::didAddTransition(const Element& element, const Animation& transition)
     88{
     89    if (!m_document.settings().contentChangeObserverEnabled())
     90        return;
     91    if (hasVisibleChangeState())
     92        return;
     93    if (!isObservingTransitions())
     94        return;
     95    if (!transition.isDurationSet() || !transition.isPropertySet())
     96        return;
     97    if (!isObservedPropertyForTransition(transition.property()))
     98        return;
     99    auto transitionEnd = Seconds { transition.duration() + std::max<double>(0, transition.isDelaySet() ? transition.delay() : 0) };
     100    if (transitionEnd > maximumDelayForTransitions)
     101        return;
     102    LOG_WITH_STREAM(ContentObservation, stream << "didAddTransition: transition created on " << &element << " (" << transitionEnd.milliseconds() << "ms).");
     103
     104    m_elementsWithTransition.add(&element);
     105    // FIXME: report state change.
     106}
     107
     108void ContentChangeObserver::didFinishTransition(const Element& element, CSSPropertyID propertyID)
     109{
     110    if (!isObservedPropertyForTransition(propertyID))
     111        return;
     112    if (!m_elementsWithTransition.take(&element))
     113        return;
     114    LOG_WITH_STREAM(ContentObservation, stream << "didFinishTransition: transition finished (" << &element << ").");
     115    // FIXME: report state change.
     116}
     117
     118void ContentChangeObserver::didRemoveTransition(const Element& element, CSSPropertyID propertyID)
     119{
     120    if (!isObservedPropertyForTransition(propertyID))
     121        return;
     122    if (!m_elementsWithTransition.take(&element))
     123        return;
     124    LOG_WITH_STREAM(ContentObservation, stream << "didRemoveTransition: transition got interrupted (" << &element << ").");
     125    // FIXME: report state change.
     126}
     127
    84128void ContentChangeObserver::didInstallDOMTimer(const DOMTimer& timer, Seconds timeout, bool singleShot)
    85129{
     
    88132    if (m_document.activeDOMObjectsAreSuspended())
    89133        return;
    90     if (timeout > 300_ms || !singleShot)
     134    if (timeout > maximumDelayForTimers || !singleShot)
    91135        return;
    92136    if (!isObservingDOMTimerScheduling())
  • trunk/Source/WebCore/page/ios/ContentChangeObserver.h

    r243290 r243304  
    3131#include "Timer.h"
    3232#include "WKContentObservation.h"
     33#include <wtf/HashSet.h>
    3334
    3435namespace WebCore {
    3536
     37class Animation;
    3638class DOMTimer;
    3739class Document;
     
    4749    void didInstallDOMTimer(const DOMTimer&, Seconds timeout, bool singleShot);
    4850    void didRemoveDOMTimer(const DOMTimer&);
     51
     52    void didAddTransition(const Element&, const Animation&);
     53    void didFinishTransition(const Element&, CSSPropertyID);
     54    void didRemoveTransition(const Element&, CSSPropertyID);
     55
    4956    WEBCORE_EXPORT void willNotProceedWithClick();
    5057    WEBCORE_EXPORT static void didRecognizeLongPress(Frame& mainFrame);
     
    115122    void setShouldObserveDOMTimerScheduling(bool observe) { m_isObservingDOMTimerScheduling = observe; }
    116123    bool isObservingDOMTimerScheduling() const { return m_isObservingDOMTimerScheduling; }
     124    bool isObservingTransitions() const { return m_isObservingTransitions; }
     125    bool isObservedPropertyForTransition(CSSPropertyID propertyId) const { return propertyId == CSSPropertyLeft; }
    117126    void domTimerExecuteDidStart(const DOMTimer&);
    118127    void domTimerExecuteDidFinish(const DOMTimer&);
     
    168177    Timer m_contentObservationTimer;
    169178    HashSet<const DOMTimer*> m_DOMTimerList;
     179    // FIXME: Move over to WeakHashSet when it starts supporting const.
     180    HashSet<const Element*> m_elementsWithTransition;
    170181    bool m_touchEventIsBeingDispatched { false };
    171182    bool m_isWaitingForStyleRecalc { false };
     
    175186    bool m_mouseMovedEventIsBeingDispatched { false };
    176187    bool m_isBetweenTouchEndAndMouseMoved { false };
     188    bool m_isObservingTransitions { false };
    177189};
    178190
Note: See TracChangeset for help on using the changeset viewer.