Commit 6b9c836f authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

AnimationEvent: store elapsed time in an AnimationTimeDelta

As part of the rewriting of Blink Animation Engine we're replacing the way the
elapsed time is represented inside an AnimationEvent. The spec mentions it must
be a double but we can use AnimationTimeDelta as the internal representation.

Bug: 737867
Change-Id: I38041957586d2d151eea6dddc908bb176eadf97d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1907248Reviewed-by: default avatarKevin Ellis <kevers@chromium.org>
Commit-Queue: Sergio Villar <svillar@igalia.com>
Cr-Commit-Position: refs/heads/master@{#714259}
parent 76367552
......@@ -1104,7 +1104,7 @@ EventTarget* CSSAnimations::AnimationEventDelegate::GetEventTarget() const {
void CSSAnimations::AnimationEventDelegate::MaybeDispatch(
Document::ListenerType listener_type,
const AtomicString& event_name,
double elapsed_time) {
const AnimationTimeDelta& elapsed_time) {
if (animation_target_->GetDocument().HasListenerType(listener_type)) {
String pseudo_element_name = PseudoElement::PseudoElementNameForEvents(
animation_target_->GetPseudoId());
......@@ -1132,7 +1132,8 @@ void CSSAnimations::AnimationEventDelegate::OnEventCondition(
(previous_phase_ == Timing::kPhaseNone ||
previous_phase_ == Timing::kPhaseBefore)) {
const double start_delay = animation_node.SpecifiedTiming().start_delay;
const double elapsed_time = start_delay < 0 ? -start_delay : 0;
const auto& elapsed_time =
AnimationTimeDelta::FromSecondsD(start_delay < 0 ? -start_delay : 0);
MaybeDispatch(Document::kAnimationStartListener,
event_type_names::kAnimationstart, elapsed_time);
}
......@@ -1149,15 +1150,15 @@ void CSSAnimations::AnimationEventDelegate::OnEventCondition(
animation_node.SpecifiedTiming().iteration_duration.value() *
(previous_iteration_.value() + 1);
MaybeDispatch(Document::kAnimationIterationListener,
event_type_names::kAnimationiteration,
elapsed_time.InSecondsF());
event_type_names::kAnimationiteration, elapsed_time);
}
if (current_phase == Timing::kPhaseAfter &&
previous_phase_ != Timing::kPhaseAfter) {
MaybeDispatch(Document::kAnimationEndListener,
event_type_names::kAnimationend,
animation_node.SpecifiedTiming().ActiveDuration());
AnimationTimeDelta::FromSecondsD(
animation_node.SpecifiedTiming().ActiveDuration()));
}
previous_phase_ = current_phase;
......
......@@ -213,7 +213,7 @@ class CORE_EXPORT CSSAnimations final {
void MaybeDispatch(Document::ListenerType,
const AtomicString& event_name,
double elapsed_time);
const AnimationTimeDelta& elapsed_time);
Member<Element> animation_target_;
const AtomicString name_;
Timing::Phase previous_phase_;
......
......@@ -29,18 +29,19 @@
namespace blink {
AnimationEvent::AnimationEvent() : elapsed_time_(0.0) {}
AnimationEvent::AnimationEvent() = default;
AnimationEvent::AnimationEvent(const AtomicString& type,
const AnimationEventInit* initializer)
: Event(type, initializer),
animation_name_(initializer->animationName()),
elapsed_time_(initializer->elapsedTime()),
elapsed_time_(
AnimationTimeDelta::FromSecondsD(initializer->elapsedTime())),
pseudo_element_(initializer->pseudoElement()) {}
AnimationEvent::AnimationEvent(const AtomicString& type,
const String& animation_name,
double elapsed_time,
const AnimationTimeDelta& elapsed_time,
const String& pseudo_element)
: Event(type, Bubbles::kYes, Cancelable::kYes),
animation_name_(animation_name),
......@@ -54,7 +55,7 @@ const String& AnimationEvent::animationName() const {
}
double AnimationEvent::elapsedTime() const {
return elapsed_time_;
return elapsed_time_.InSecondsF();
}
const String& AnimationEvent::pseudoElement() const {
......
......@@ -26,6 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_ANIMATION_EVENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_ANIMATION_EVENT_H_
#include "third_party/blink/renderer/core/animation/animation_time_delta.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/events/animation_event_init.h"
......@@ -40,7 +41,7 @@ class AnimationEvent final : public Event {
}
static AnimationEvent* Create(const AtomicString& type,
const String& animation_name,
double elapsed_time,
const AnimationTimeDelta& elapsed_time,
const String& pseudo_element) {
return MakeGarbageCollected<AnimationEvent>(type, animation_name,
elapsed_time, pseudo_element);
......@@ -53,7 +54,7 @@ class AnimationEvent final : public Event {
AnimationEvent();
AnimationEvent(const AtomicString& type,
const String& animation_name,
double elapsed_time,
const AnimationTimeDelta& elapsed_time,
const String& pseudo_element);
AnimationEvent(const AtomicString&, const AnimationEventInit*);
~AnimationEvent() override;
......@@ -68,7 +69,7 @@ class AnimationEvent final : public Event {
private:
String animation_name_;
double elapsed_time_;
AnimationTimeDelta elapsed_time_;
String pseudo_element_;
};
......
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