Commit a764bf1f authored by haozhe's avatar haozhe Committed by Commit Bot

Add the owning_element to CSSAnimation class

The patch adds owning_element to CSSAnimation class. Now the
CSSAnimations have an owning_element and we will clear the owning
element if the animation disassociate from the owning_element.

The next follow up patches will add the owning_element to CSSTransition
and using owning element to compare the composite ordering.

As per spec: https://drafts.csswg.org/css-transitions-2/#owning-element
and: https://drafts.csswg.org/css-animations-2/#owning-element-section

Bug: 1047316

Change-Id: I5ddb54b13330f851b830547f02d9acaad91f3e1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2108613
Commit-Queue: Hao Sheng <haozhes@chromium.org>
Reviewed-by: default avatarMajid Valipour <majidvp@chromium.org>
Reviewed-by: default avatarKevin Ellis <kevers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753507}
parent eea1e99d
......@@ -124,7 +124,7 @@ Animation::AnimationClassPriority AnimationPriority(
Animation::AnimationClassPriority priority;
if (animation.IsCSSTransition())
priority = Animation::AnimationClassPriority::kCssTransitionPriority;
else if (animation.IsCSSAnimation())
else if (animation.IsCSSAnimation() && animation.IsOwned())
priority = Animation::AnimationClassPriority::kCssAnimationPriority;
else
priority = Animation::AnimationClassPriority::kDefaultPriority;
......
......@@ -119,6 +119,9 @@ class CORE_EXPORT Animation : public EventTargetWithInlineData,
virtual bool IsCSSAnimation() const { return false; }
virtual bool IsCSSTransition() const { return false; }
virtual Element* OwningElemnt() const { return nullptr; }
virtual void ClearOwningElement() {}
bool IsOwned() const { return !OwningElemnt(); }
// Returns whether the animation is finished.
bool Update(TimingUpdateReason);
......
......@@ -3,9 +3,9 @@
// found in the LICENSE file.
#include "third_party/blink/renderer/core/animation/css/css_animation.h"
#include "third_party/blink/renderer/core/animation/animation.h"
#include "third_party/blink/renderer/core/animation/css/css_animations.h"
#include "third_party/blink/renderer/core/animation/keyframe_effect.h"
#include "third_party/blink/renderer/core/dom/document.h"
namespace blink {
......@@ -16,7 +16,12 @@ CSSAnimation::CSSAnimation(ExecutionContext* execution_context,
const String& animation_name)
: Animation(execution_context, timeline, content),
animation_name_(animation_name),
ignore_css_play_state_(false) {}
ignore_css_play_state_(false) {
// The owning_element does not always equal to the target element of an
// animation. The following spec gives an example:
// https://drafts.csswg.org/css-animations-2/#owning-element-section
owning_element_ = To<KeyframeEffect>(effect())->target();
}
String CSSAnimation::playState() const {
FlushStyles();
......
......@@ -8,6 +8,7 @@
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/core/animation/animation.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/element.h"
namespace blink {
......@@ -22,6 +23,9 @@ class CORE_EXPORT CSSAnimation : public Animation {
bool IsCSSAnimation() const final { return true; }
void ClearOwningElement() final { owning_element_ = nullptr; }
Element* OwningElement() const { return owning_element_; }
const String& animationName() const { return animation_name_; }
// Animation overrides.
......@@ -48,6 +52,10 @@ class CORE_EXPORT CSSAnimation : public Animation {
// https://drafts.csswg.org/css-animations-2/#interaction-between-animation-play-state-and-web-animations-API
bool getIgnoreCSSPlayState() { return ignore_css_play_state_; }
void resetIgnoreCSSPlayState() { ignore_css_play_state_ = false; }
void Trace(blink::Visitor* visitor) override {
Animation::Trace(visitor);
visitor->Trace(owning_element_);
}
protected:
AnimationEffect::EventDelegate* CreateEventDelegate(
......@@ -74,6 +82,10 @@ class CORE_EXPORT CSSAnimation : public Animation {
// When set, the web-animation API is overruling the animation-play-state
// style.
bool ignore_css_play_state_;
// The owning element of an animation refers to the element or pseudo-element
// whose animation-name property was applied that generated the animation
// The spec: https://drafts.csswg.org/css-animations-2/#owning-element-section
Member<Element> owning_element_;
};
template <>
......
......@@ -558,6 +558,7 @@ void CSSAnimations::MaybeApplyPendingUpdate(Element* element) {
cancelled_indices[i] < cancelled_indices[i + 1]);
Animation& animation =
*running_animations_[cancelled_indices[i]]->animation;
animation.ClearOwningElement();
animation.cancel();
animation.Update(kTimingUpdateOnDemand);
running_animations_.EraseAt(cancelled_indices[i]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment