Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[SVG] Handle endEvent for svg animations
https://bugs.webkit.org/show_bug.cgi?id=121587

Patch by Antoine Quint <graouts@apple.com> on 2015-10-12
Reviewed by Dean Jackson.

Source/WebCore:

Add support for the "endEvent" SVG event triggered when an animation completes, as
specified in http://www.w3.org/TR/SMIL3/smil-timing.html#q135. This event doesn't
bubble and can't be canceled. Added test coverage for the event through the DOM
Events API as well as the declarative SMIL Animation syntax.

Adapted from a Chromium patch by pavan.e@samsung.com
https://chromium.googlesource.com/chromium/blink/+/4d415ca0268231aa80e3552fe21bf3480a6978f8

Tests: svg/animations/end-event-declarative-expected.svg
       svg/animations/end-event-declarative.svg
       svg/animations/end-event-script-expected.svg
       svg/animations/end-event-script.svg

* svg/animation/SMILTimeContainer.cpp:
(WebCore::SMILTimeContainer::updateAnimations):
* svg/animation/SVGSMILElement.cpp:
(WebCore::smilEndEventSender):
(WebCore::SVGSMILElement::~SVGSMILElement):
(WebCore::SVGSMILElement::progress):
(WebCore::SVGSMILElement::dispatchPendingEvent):
* svg/animation/SVGSMILElement.h:
(WebCore::SVGSMILElement::hasConditionsConnected):

LayoutTests:

Tests for the "endEvent" event for SVG animations.

* svg/animations/end-event-declarative-expected.svg: Added.
* svg/animations/end-event-declarative.svg: Added.
* svg/animations/end-event-script-expected.svg: Added.
* svg/animations/end-event-script.svg: Added.

Canonical link: https://commits.webkit.org/168177@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190890 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
graouts authored and webkit-commit-queue committed Oct 12, 2015
1 parent 53beb1b commit 72f9fb5
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 5 deletions.
14 changes: 14 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,17 @@
2015-10-12 Antoine Quint <graouts@apple.com>

[SVG] Handle endEvent for svg animations
https://bugs.webkit.org/show_bug.cgi?id=121587

Reviewed by Dean Jackson.

Tests for the "endEvent" event for SVG animations.

* svg/animations/end-event-declarative-expected.svg: Added.
* svg/animations/end-event-declarative.svg: Added.
* svg/animations/end-event-script-expected.svg: Added.
* svg/animations/end-event-script.svg: Added.

2015-10-12 Brady Eidson <beidson@apple.com>

Modern IDB: Start version change transaction for connections to new database.
Expand Down
5 changes: 5 additions & 0 deletions LayoutTests/svg/animations/end-event-declarative-expected.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions LayoutTests/svg/animations/end-event-declarative.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions LayoutTests/svg/animations/end-event-script-expected.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions LayoutTests/svg/animations/end-event-script.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,33 @@
2015-10-12 Antoine Quint <graouts@apple.com>

[SVG] Handle endEvent for svg animations
https://bugs.webkit.org/show_bug.cgi?id=121587

Reviewed by Dean Jackson.

Add support for the "endEvent" SVG event triggered when an animation completes, as
specified in http://www.w3.org/TR/SMIL3/smil-timing.html#q135. This event doesn't
bubble and can't be canceled. Added test coverage for the event through the DOM
Events API as well as the declarative SMIL Animation syntax.

Adapted from a Chromium patch by pavan.e@samsung.com
https://chromium.googlesource.com/chromium/blink/+/4d415ca0268231aa80e3552fe21bf3480a6978f8

Tests: svg/animations/end-event-declarative-expected.svg
svg/animations/end-event-declarative.svg
svg/animations/end-event-script-expected.svg
svg/animations/end-event-script.svg

* svg/animation/SMILTimeContainer.cpp:
(WebCore::SMILTimeContainer::updateAnimations):
* svg/animation/SVGSMILElement.cpp:
(WebCore::smilEndEventSender):
(WebCore::SVGSMILElement::~SVGSMILElement):
(WebCore::SVGSMILElement::progress):
(WebCore::SVGSMILElement::dispatchPendingEvent):
* svg/animation/SVGSMILElement.h:
(WebCore::SVGSMILElement::hasConditionsConnected):

2015-10-12 Per Arne Vollan <peavo@outlook.com>

[Curl] Increase limit of parallel network requests.
Expand Down
8 changes: 8 additions & 0 deletions Source/WebCore/svg/animation/SMILTimeContainer.cpp
Expand Up @@ -262,6 +262,14 @@ void SMILTimeContainer::updateAnimations(SMILTime elapsed, bool seekToTime)
#endif

AnimationsVector animationsToApply;
for (auto& it : m_scheduledAnimations) {
AnimationsVector* scheduled = it.value.get();
for (auto* animation : *scheduled) {
if (!animation->hasConditionsConnected())
animation->connectConditions();
}
}

for (auto& it : m_scheduledAnimations) {
AnimationsVector* scheduled = it.value.get();

Expand Down
27 changes: 23 additions & 4 deletions Source/WebCore/svg/animation/SVGSMILElement.cpp
Expand Up @@ -30,6 +30,7 @@
#include "Document.h"
#include "Event.h"
#include "EventListener.h"
#include "EventSender.h"
#include "FloatConversion.h"
#include "FrameView.h"
#include "HTMLNames.h"
Expand All @@ -45,7 +46,13 @@
#include <wtf/Vector.h>

namespace WebCore {


static SMILEventSender& smilEndEventSender()
{
static NeverDestroyed<SMILEventSender> sender("endEvent");
return sender;
}

// This is used for duration type time values that can't be negative.
static const double invalidCachedTime = -1.;

Expand Down Expand Up @@ -135,6 +142,7 @@ SVGSMILElement::SVGSMILElement(const QualifiedName& tagName, Document& doc)
SVGSMILElement::~SVGSMILElement()
{
clearResourceReferences();
smilEndEventSender().cancelEvent(*this);
disconnectConditions();
if (m_timeContainer && m_targetElement && hasValidAttributeName())
m_timeContainer->unschedule(this, m_targetElement, m_attributeName);
Expand Down Expand Up @@ -1048,9 +1056,6 @@ bool SVGSMILElement::progress(SMILTime elapsed, SVGSMILElement* resultElement, b
ASSERT(m_timeContainer);
ASSERT(m_isWaitingForFirstInterval || m_intervalBegin.isFinite());

if (!m_conditionsConnected)
connectConditions();

if (!m_intervalBegin.isFinite()) {
ASSERT(m_activeState == Inactive);
m_nextProgressTime = SMILTime::unresolved();
Expand Down Expand Up @@ -1107,11 +1112,18 @@ bool SVGSMILElement::progress(SMILTime elapsed, SVGSMILElement* resultElement, b
}

if (oldActiveState == Active && m_activeState != Active) {
smilEndEventSender().dispatchEventSoon(*this);
endedActiveInterval();
if (m_activeState != Frozen)
clearAnimatedType(m_targetElement);
}

// Triggering all the pending events if the animation timeline is changed.
if (seekToTime) {
if (m_activeState == Inactive || m_activeState == Frozen)
smilEndEventSender().dispatchEventSoon(*this);
}

m_nextProgressTime = calculateNextProgressTime(elapsed);
return animationIsContributing;
}
Expand Down Expand Up @@ -1187,4 +1199,11 @@ void SVGSMILElement::endedActiveInterval()
clearTimesWithDynamicOrigins(m_endTimes);
}

void SVGSMILElement::dispatchPendingEvent(SMILEventSender* eventSender)
{
ASSERT(eventSender == &smilEndEventSender());
const AtomicString& eventType = eventSender->eventType();
dispatchEvent(Event::create(eventType, false, false));
}

}
11 changes: 10 additions & 1 deletion Source/WebCore/svg/animation/SVGSMILElement.h
Expand Up @@ -33,6 +33,11 @@

namespace WebCore {

class SVGSMILElement;

template<typename T> class EventSender;
typedef EventSender<SVGSMILElement> SMILEventSender;

class ConditionEventListener;
class SMILTimeContainer;

Expand Down Expand Up @@ -107,6 +112,11 @@ class SVGSMILElement : public SVGElement {
virtual void clearAnimatedType(SVGElement* targetElement) = 0;
virtual void applyResultsToTarget() = 0;

void connectConditions();
bool hasConditionsConnected() const { return m_conditionsConnected; }

void dispatchPendingEvent(SMILEventSender*);

protected:
void addBeginTime(SMILTime eventTime, SMILTime endTime, SMILTimeWithOrigin::Origin = SMILTimeWithOrigin::ParserOrigin);
void addEndTime(SMILTime eventTime, SMILTime endTime, SMILTimeWithOrigin::Origin = SMILTimeWithOrigin::ParserOrigin);
Expand Down Expand Up @@ -168,7 +178,6 @@ class SVGSMILElement : public SVGElement {
void parseBeginOrEnd(const String&, BeginOrEnd beginOrEnd);
Element* eventBaseFor(const Condition&);

void connectConditions();
void disconnectConditions();

// Event base timing
Expand Down

0 comments on commit 72f9fb5

Please sign in to comment.