Skip to content

Commit

Permalink
[web-animations] add support for canceling style-originated animation…
Browse files Browse the repository at this point in the history
…s silently

https://bugs.webkit.org/show_bug.cgi?id=271365

Reviewed by Antti Koivisto.

When we will be adding animation support for the `display` property (see bug 267762) we will
need to resolve animations even when the underlying style has `display: none` to see whether
animations yield a different value. In that process, we may create style-originated animations
that will ultimately be canceled once we're certain `display: none` is still set.

In 276414@main we created a list of style-originated animations created during a style update.

We now add support for canceling that group of style-originated animations in a way that is not
script observable, or "silently" in Web Animations parlance.

Once we get to add animation support for the `display` property proper, we will add a call to
`StyleOriginatedAnimation::cancelFromStyle()` with the list of newly-created style-originated
animations that require silent cancelation.

* Source/WebCore/animation/StyleOriginatedAnimation.cpp:
(WebCore::StyleOriginatedAnimation::cancel):
(WebCore::StyleOriginatedAnimation::cancelFromStyle):
* Source/WebCore/animation/StyleOriginatedAnimation.h:
* Source/WebCore/animation/WebAnimation.cpp:
(WebCore::WebAnimation::cancel):
* Source/WebCore/animation/WebAnimation.h:
* Source/WebCore/style/Styleable.cpp:
(WebCore::Styleable::cancelStyleOriginatedAnimations const):
* Source/WebCore/style/Styleable.h:
(WebCore::Styleable::cancelStyleOriginatedAnimations):

Canonical link: https://commits.webkit.org/276453@main
  • Loading branch information
graouts committed Mar 21, 2024
1 parent 18960f2 commit 28a06fc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Source/WebCore/animation/StyleOriginatedAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void StyleOriginatedAnimation::setTimeline(RefPtr<AnimationTimeline>&& newTimeli
WebAnimation::setTimeline(WTFMove(newTimeline));
}

void StyleOriginatedAnimation::cancel()
void StyleOriginatedAnimation::cancel(WebAnimation::Silently silently)
{
auto cancelationTime = 0_s;

Expand All @@ -213,14 +213,14 @@ void StyleOriginatedAnimation::cancel()
}
}

WebAnimation::cancel();
WebAnimation::cancel(silently);

invalidateDOMEvents(shouldFireEvents, cancelationTime);
}

void StyleOriginatedAnimation::cancelFromStyle()
void StyleOriginatedAnimation::cancelFromStyle(WebAnimation::Silently silently)
{
cancel();
cancel(silently);
disassociateFromOwningElement();
}

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/animation/StyleOriginatedAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class StyleOriginatedAnimation : public WebAnimation {
const std::optional<const Styleable> owningElement() const;
const Animation& backingAnimation() const { return m_backingAnimation; }
void setBackingAnimation(const Animation&);
void cancelFromStyle();
void cancelFromStyle(WebAnimation::Silently = WebAnimation::Silently::No);

std::optional<double> bindingsStartTime() const final;
std::optional<double> bindingsCurrentTime() const final;
Expand All @@ -63,7 +63,7 @@ class StyleOriginatedAnimation : public WebAnimation {
ExceptionOr<void> bindingsPause() override;

void setTimeline(RefPtr<AnimationTimeline>&&) final;
void cancel() final;
void cancel(WebAnimation::Silently = WebAnimation::Silently::No) final;

void tick() override;

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/animation/WebAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ Seconds WebAnimation::effectEndTime() const
return m_effect ? m_effect->endTime() : 0_s;
}

void WebAnimation::cancel()
void WebAnimation::cancel(Silently silently)
{
LOG_WITH_STREAM(Animations, stream << "WebAnimation " << this << " cancel() (current time is " << currentTime() << ")");

Expand Down Expand Up @@ -762,7 +762,7 @@ void WebAnimation::cancel()
// 3. Make animation's start time unresolved.
m_startTime = std::nullopt;

timingDidChange(DidSeek::No, SynchronouslyNotify::No);
timingDidChange(DidSeek::No, SynchronouslyNotify::No, silently);

invalidateEffect();

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/animation/WebAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class WebAnimation : public RefCounted<WebAnimation>, public EventTarget, public
using FinishedPromise = DOMPromiseProxyWithResolveCallback<IDLInterface<WebAnimation>>;
FinishedPromise& finished() { return m_finishedPromise.get(); }

virtual void cancel();
enum class Silently : bool { No, Yes };
virtual void cancel(Silently = Silently::No);
ExceptionOr<void> finish();
ExceptionOr<void> play();
void updatePlaybackRate(double);
Expand Down Expand Up @@ -175,7 +176,6 @@ class WebAnimation : public RefCounted<WebAnimation>, public EventTarget, public
private:
enum class DidSeek : bool { No, Yes };
enum class SynchronouslyNotify : bool { No, Yes };
enum class Silently : bool { No, Yes };
enum class RespectHoldTime : bool { No, Yes };
enum class AutoRewind : bool { No, Yes };
enum class TimeToRunPendingTask : uint8_t { NotScheduled, ASAP, WhenReady };
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/style/Styleable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ void Styleable::willChangeRenderer() const
}
}

void Styleable::cancelStyleOriginatedAnimations() const
void Styleable::cancelStyleOriginatedAnimations(const WeakStyleOriginatedAnimations& animationsToCancelSilently) const
{
if (auto* animations = this->animations()) {
for (auto& animation : *animations) {
if (auto* styleOriginatedAnimation = dynamicDowncast<StyleOriginatedAnimation>(animation.get())) {
styleOriginatedAnimation->cancelFromStyle();
styleOriginatedAnimation->cancelFromStyle(animationsToCancelSilently.contains(styleOriginatedAnimation) ? WebAnimation::Silently::Yes : WebAnimation::Silently::No);
setLastStyleChangeEventStyle(nullptr);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/style/Styleable.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ struct Styleable {
void elementWasRemoved() const;

void willChangeRenderer() const;
void cancelStyleOriginatedAnimations() const;
void cancelStyleOriginatedAnimations(const WeakStyleOriginatedAnimations& = { }) const;

void animationWasAdded(WebAnimation&) const;
void animationWasRemoved(WebAnimation&) const;
Expand Down

0 comments on commit 28a06fc

Please sign in to comment.