Commit f63fad52 authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

TransitionEvent: 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 a TransitionEvent. The spec mentions it must
be a double but we can use AnimationTimeDelta as the internal representation.
This change reduces a little bit the number of required conversions between
AnimationTimeDelta and double.

Bug: 737867
Change-Id: Ide96f3906c3937c6d4af893a9677211c7f8de8f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1907247Reviewed-by: default avatarKevin Ellis <kevers@chromium.org>
Commit-Queue: Sergio Villar <svillar@igalia.com>
Cr-Commit-Position: refs/heads/master@{#714261}
parent 9dd5b45c
...@@ -218,8 +218,8 @@ std::unique_ptr<TypedInterpolationValue> SampleAnimation( ...@@ -218,8 +218,8 @@ std::unique_ptr<TypedInterpolationValue> SampleAnimation(
// Returns the start time of an animation given the start delay. A negative // Returns the start time of an animation given the start delay. A negative
// start delay results in the animation starting with non-zero progress. // start delay results in the animation starting with non-zero progress.
double StartTimeFromDelay(double start_delay) { AnimationTimeDelta StartTimeFromDelay(double start_delay) {
return start_delay < 0 ? -start_delay : 0; return AnimationTimeDelta::FromSecondsD(start_delay < 0 ? -start_delay : 0);
} }
} // namespace } // namespace
...@@ -1201,9 +1201,9 @@ void CSSAnimations::TransitionEventDelegate::OnEventCondition( ...@@ -1201,9 +1201,9 @@ void CSSAnimations::TransitionEventDelegate::OnEventCondition(
previous_phase_ == Timing::kPhaseAfter) { previous_phase_ == Timing::kPhaseAfter) {
// If the transition is progressing backwards it is considered to have // If the transition is progressing backwards it is considered to have
// started at the end position. // started at the end position.
EnqueueEvent( DCHECK(animation_node.SpecifiedTiming().iteration_duration.has_value());
event_type_names::kTransitionstart, EnqueueEvent(event_type_names::kTransitionstart,
animation_node.SpecifiedTiming().iteration_duration->InSecondsF()); animation_node.SpecifiedTiming().iteration_duration.value());
} }
} }
...@@ -1212,9 +1212,9 @@ void CSSAnimations::TransitionEventDelegate::OnEventCondition( ...@@ -1212,9 +1212,9 @@ void CSSAnimations::TransitionEventDelegate::OnEventCondition(
(previous_phase_ == Timing::kPhaseActive || (previous_phase_ == Timing::kPhaseActive ||
previous_phase_ == Timing::kPhaseBefore || previous_phase_ == Timing::kPhaseBefore ||
previous_phase_ == Timing::kPhaseNone)) { previous_phase_ == Timing::kPhaseNone)) {
EnqueueEvent( DCHECK(animation_node.SpecifiedTiming().iteration_duration.has_value());
event_type_names::kTransitionend, EnqueueEvent(event_type_names::kTransitionend,
animation_node.SpecifiedTiming().iteration_duration->InSecondsF()); animation_node.SpecifiedTiming().iteration_duration.value());
} else if (current_phase == Timing::kPhaseBefore && } else if (current_phase == Timing::kPhaseBefore &&
(previous_phase_ == Timing::kPhaseActive || (previous_phase_ == Timing::kPhaseActive ||
previous_phase_ == Timing::kPhaseAfter)) { previous_phase_ == Timing::kPhaseAfter)) {
...@@ -1242,7 +1242,7 @@ void CSSAnimations::TransitionEventDelegate::OnEventCondition( ...@@ -1242,7 +1242,7 @@ void CSSAnimations::TransitionEventDelegate::OnEventCondition(
// current_phase != previous_phase_ (see early return at the beginning). // current_phase != previous_phase_ (see early return at the beginning).
DCHECK(cancel_active_time); DCHECK(cancel_active_time);
EnqueueEvent(event_type_names::kTransitioncancel, EnqueueEvent(event_type_names::kTransitioncancel,
cancel_active_time->InSecondsF()); cancel_active_time.value());
} }
} }
...@@ -1251,7 +1251,7 @@ void CSSAnimations::TransitionEventDelegate::OnEventCondition( ...@@ -1251,7 +1251,7 @@ void CSSAnimations::TransitionEventDelegate::OnEventCondition(
void CSSAnimations::TransitionEventDelegate::EnqueueEvent( void CSSAnimations::TransitionEventDelegate::EnqueueEvent(
const WTF::AtomicString& type, const WTF::AtomicString& type,
double elapsed_time) { const AnimationTimeDelta& elapsed_time) {
String property_name = String property_name =
property_.IsCSSCustomProperty() property_.IsCSSCustomProperty()
? property_.CustomPropertyName() ? property_.CustomPropertyName()
......
...@@ -234,7 +234,8 @@ class CORE_EXPORT CSSAnimations final { ...@@ -234,7 +234,8 @@ class CORE_EXPORT CSSAnimations final {
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
private: private:
void EnqueueEvent(const WTF::AtomicString& type, double elapsed_time); void EnqueueEvent(const WTF::AtomicString& type,
const AnimationTimeDelta& elapsed_time);
const Element& TransitionTarget() const { return *transition_target_; } const Element& TransitionTarget() const { return *transition_target_; }
EventTarget* GetEventTarget() const; EventTarget* GetEventTarget() const;
......
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
namespace blink { namespace blink {
TransitionEvent::TransitionEvent() : elapsed_time_(0) {} TransitionEvent::TransitionEvent() = default;
TransitionEvent::TransitionEvent(const AtomicString& type, TransitionEvent::TransitionEvent(const AtomicString& type,
const String& property_name, const String& property_name,
double elapsed_time, const AnimationTimeDelta& elapsed_time,
const String& pseudo_element) const String& pseudo_element)
: Event(type, Bubbles::kYes, Cancelable::kYes), : Event(type, Bubbles::kYes, Cancelable::kYes),
property_name_(property_name), property_name_(property_name),
...@@ -43,11 +43,13 @@ TransitionEvent::TransitionEvent(const AtomicString& type, ...@@ -43,11 +43,13 @@ TransitionEvent::TransitionEvent(const AtomicString& type,
TransitionEvent::TransitionEvent(const AtomicString& type, TransitionEvent::TransitionEvent(const AtomicString& type,
const TransitionEventInit* initializer) const TransitionEventInit* initializer)
: Event(type, initializer), elapsed_time_(0) { : Event(type, initializer) {
if (initializer->hasPropertyName()) if (initializer->hasPropertyName())
property_name_ = initializer->propertyName(); property_name_ = initializer->propertyName();
if (initializer->hasElapsedTime()) if (initializer->hasElapsedTime()) {
elapsed_time_ = initializer->elapsedTime(); elapsed_time_ =
AnimationTimeDelta::FromSecondsD(initializer->elapsedTime());
}
if (initializer->hasPseudoElement()) if (initializer->hasPseudoElement())
pseudo_element_ = initializer->pseudoElement(); pseudo_element_ = initializer->pseudoElement();
} }
...@@ -59,7 +61,7 @@ const String& TransitionEvent::propertyName() const { ...@@ -59,7 +61,7 @@ const String& TransitionEvent::propertyName() const {
} }
double TransitionEvent::elapsedTime() const { double TransitionEvent::elapsedTime() const {
return elapsed_time_; return elapsed_time_.InSecondsF();
} }
const String& TransitionEvent::pseudoElement() const { const String& TransitionEvent::pseudoElement() const {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_TRANSITION_EVENT_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_TRANSITION_EVENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_TRANSITION_EVENT_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_TRANSITION_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/dom/events/event.h"
#include "third_party/blink/renderer/core/events/transition_event_init.h" #include "third_party/blink/renderer/core/events/transition_event_init.h"
...@@ -41,7 +42,7 @@ class TransitionEvent final : public Event { ...@@ -41,7 +42,7 @@ class TransitionEvent final : public Event {
} }
static TransitionEvent* Create(const AtomicString& type, static TransitionEvent* Create(const AtomicString& type,
const String& property_name, const String& property_name,
double elapsed_time, const AnimationTimeDelta& elapsed_time,
const String& pseudo_element) { const String& pseudo_element) {
return MakeGarbageCollected<TransitionEvent>(type, property_name, return MakeGarbageCollected<TransitionEvent>(type, property_name,
elapsed_time, pseudo_element); elapsed_time, pseudo_element);
...@@ -54,7 +55,7 @@ class TransitionEvent final : public Event { ...@@ -54,7 +55,7 @@ class TransitionEvent final : public Event {
TransitionEvent(); TransitionEvent();
TransitionEvent(const AtomicString& type, TransitionEvent(const AtomicString& type,
const String& property_name, const String& property_name,
double elapsed_time, const AnimationTimeDelta& elapsed_time,
const String& pseudo_element); const String& pseudo_element);
TransitionEvent(const AtomicString& type, TransitionEvent(const AtomicString& type,
const TransitionEventInit* initializer); const TransitionEventInit* initializer);
...@@ -70,7 +71,7 @@ class TransitionEvent final : public Event { ...@@ -70,7 +71,7 @@ class TransitionEvent final : public Event {
private: private:
String property_name_; String property_name_;
double elapsed_time_; AnimationTimeDelta elapsed_time_;
String pseudo_element_; 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