Commit ab46a4f0 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Extend the range of SMILTime "origins"

This extends the current set of possible origins from kParserOrigin and
kScriptOrigin to kAttribute, kScript, kSyncBase, kRepeat, kEvent and
kLinkActivation. The enumeration is renamed to SMILTimeOrigin and
defined outside of the SMILTimeWithOrigin scope.
This should allow future changes like clearing out sync-base instances
when rewinding the timeline and similar "cleanup" (currently we
accumulate these instance times which means there's a possibility of the
instance list growing indefinitely).

Bug: 998526
Change-Id: I2cbc910dccb2d48d32a3316239969b93a63a4907
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1816550Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#698744}
parent e68eac59
...@@ -137,26 +137,35 @@ class SMILTime { ...@@ -137,26 +137,35 @@ class SMILTime {
std::ostream& operator<<(std::ostream& os, SMILTime time); std::ostream& operator<<(std::ostream& os, SMILTime time);
// What generated a SMILTime.
enum class SMILTimeOrigin {
kAttribute, // 'begin' / 'end' attribute
kScript, // beginElementAt / endElementAt
kSyncBase, // Sync-base
kRepeat, // Repeat event
kEvent, // DOM event
kLinkActivation, // Link activation (Click on link referring to timed
// element.)
};
class SMILTimeWithOrigin { class SMILTimeWithOrigin {
DISALLOW_NEW(); DISALLOW_NEW();
public: public:
enum Origin { kParserOrigin, kScriptOrigin }; SMILTimeWithOrigin() : origin_(SMILTimeOrigin::kAttribute) {}
SMILTimeWithOrigin() : origin_(kParserOrigin) {}
SMILTimeWithOrigin(const SMILTime& time, Origin origin) SMILTimeWithOrigin(const SMILTime& time, SMILTimeOrigin origin)
: time_(time), origin_(origin) {} : time_(time), origin_(origin) {}
const SMILTime& Time() const { return time_; } const SMILTime& Time() const { return time_; }
bool OriginIsScript() const { return origin_ == kScriptOrigin; } bool OriginIsScript() const { return origin_ == SMILTimeOrigin::kScript; }
bool HasSameOrigin(SMILTimeWithOrigin other) const { bool HasSameOrigin(SMILTimeWithOrigin other) const {
return origin_ == other.origin_; return origin_ == other.origin_;
} }
private: private:
SMILTime time_; SMILTime time_;
Origin origin_; SMILTimeOrigin origin_;
}; };
inline bool operator<(const SMILTimeWithOrigin& a, inline bool operator<(const SMILTimeWithOrigin& a,
......
...@@ -117,7 +117,8 @@ void ConditionEventListener::Invoke(ExecutionContext*, Event* event) { ...@@ -117,7 +117,8 @@ void ConditionEventListener::Invoke(ExecutionContext*, Event* event) {
return; return;
animation_->IntervalIsDirty(); animation_->IntervalIsDirty();
animation_->AddInstanceTime(condition_->GetBeginOrEnd(), animation_->AddInstanceTime(condition_->GetBeginOrEnd(),
animation_->Elapsed() + condition_->Offset()); animation_->Elapsed() + condition_->Offset(),
SMILTimeOrigin::kEvent);
} }
SVGSMILElement::Condition::Condition(Type type, SVGSMILElement::Condition::Condition(Type type,
...@@ -487,7 +488,7 @@ void SVGSMILElement::ParseBeginOrEnd(const String& parse_string, ...@@ -487,7 +488,7 @@ void SVGSMILElement::ParseBeginOrEnd(const String& parse_string,
ParseCondition(item, begin_or_end); ParseCondition(item, begin_or_end);
} else if (!existing.Contains(value)) { } else if (!existing.Contains(value)) {
time_list.push_back( time_list.push_back(
SMILTimeWithOrigin(value, SMILTimeWithOrigin::kParserOrigin)); SMILTimeWithOrigin(value, SMILTimeOrigin::kAttribute));
} }
} }
std::sort(time_list.begin(), time_list.end()); std::sort(time_list.begin(), time_list.end());
...@@ -712,7 +713,7 @@ static void InsertSortedAndUnique(Vector<SMILTimeWithOrigin>& list, ...@@ -712,7 +713,7 @@ static void InsertSortedAndUnique(Vector<SMILTimeWithOrigin>& list,
void SVGSMILElement::AddInstanceTime(BeginOrEnd begin_or_end, void SVGSMILElement::AddInstanceTime(BeginOrEnd begin_or_end,
SMILTime time, SMILTime time,
SMILTimeWithOrigin::Origin origin) { SMILTimeOrigin origin) {
SMILTime current_presentation_time = SMILTime current_presentation_time =
time_container_ ? time_container_->CurrentDocumentTime() : SMILTime(); time_container_ ? time_container_->CurrentDocumentTime() : SMILTime();
DCHECK(!current_presentation_time.IsUnresolved()); DCHECK(!current_presentation_time.IsUnresolved());
...@@ -1171,6 +1172,7 @@ void SVGSMILElement::CreateInstanceTimesFromSyncBase( ...@@ -1171,6 +1172,7 @@ void SVGSMILElement::CreateInstanceTimesFromSyncBase(
// No nested time containers in SVG, no need for crazy time space // No nested time containers in SVG, no need for crazy time space
// conversions. Phew! // conversions. Phew!
SMILTime time = SMILTime::Unresolved(); SMILTime time = SMILTime::Unresolved();
SMILTimeOrigin origin = SMILTimeOrigin::kSyncBase;
if (condition->GetName() == "begin") { if (condition->GetName() == "begin") {
time = new_interval.begin + condition->Offset(); time = new_interval.begin + condition->Offset();
} else if (condition->GetName() == "end") { } else if (condition->GetName() == "end") {
...@@ -1184,11 +1186,12 @@ void SVGSMILElement::CreateInstanceTimesFromSyncBase( ...@@ -1184,11 +1186,12 @@ void SVGSMILElement::CreateInstanceTimesFromSyncBase(
? time_container_->CurrentDocumentTime() ? time_container_->CurrentDocumentTime()
: SMILTime(); : SMILTime();
time = base_time + condition->Offset(); time = base_time + condition->Offset();
origin = SMILTimeOrigin::kRepeat;
} }
} }
if (!time.IsFinite()) if (!time.IsFinite())
continue; continue;
AddInstanceTime(condition->GetBeginOrEnd(), time); AddInstanceTime(condition->GetBeginOrEnd(), time, origin);
} }
} }
} }
...@@ -1204,7 +1207,7 @@ void SVGSMILElement::RemoveSyncBaseDependent(SVGSMILElement& animation) { ...@@ -1204,7 +1207,7 @@ void SVGSMILElement::RemoveSyncBaseDependent(SVGSMILElement& animation) {
} }
void SVGSMILElement::BeginByLinkActivation() { void SVGSMILElement::BeginByLinkActivation() {
AddInstanceTime(kBegin, Elapsed()); AddInstanceTime(kBegin, Elapsed(), SMILTimeOrigin::kLinkActivation);
} }
void SVGSMILElement::EndedActiveInterval() { void SVGSMILElement::EndedActiveInterval() {
......
...@@ -145,10 +145,7 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { ...@@ -145,10 +145,7 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
interval_.end = SMILTime(); interval_.end = SMILTime();
} }
void AddInstanceTime( void AddInstanceTime(BeginOrEnd, SMILTime, SMILTimeOrigin);
BeginOrEnd,
SMILTime,
SMILTimeWithOrigin::Origin = SMILTimeWithOrigin::kParserOrigin);
void SetInactive() { active_state_ = kInactive; } void SetInactive() { active_state_ = kInactive; }
......
...@@ -262,13 +262,13 @@ float SVGAnimationElement::getSimpleDuration( ...@@ -262,13 +262,13 @@ float SVGAnimationElement::getSimpleDuration(
void SVGAnimationElement::beginElementAt(float offset) { void SVGAnimationElement::beginElementAt(float offset) {
DCHECK(std::isfinite(offset)); DCHECK(std::isfinite(offset));
AddInstanceTime(kBegin, Elapsed() + SMILTime::FromSecondsD(offset), AddInstanceTime(kBegin, Elapsed() + SMILTime::FromSecondsD(offset),
SMILTimeWithOrigin::kScriptOrigin); SMILTimeOrigin::kScript);
} }
void SVGAnimationElement::endElementAt(float offset) { void SVGAnimationElement::endElementAt(float offset) {
DCHECK(std::isfinite(offset)); DCHECK(std::isfinite(offset));
AddInstanceTime(kEnd, Elapsed() + SMILTime::FromSecondsD(offset), AddInstanceTime(kEnd, Elapsed() + SMILTime::FromSecondsD(offset),
SMILTimeWithOrigin::kScriptOrigin); SMILTimeOrigin::kScript);
} }
void SVGAnimationElement::UpdateAnimationMode() { void SVGAnimationElement::UpdateAnimationMode() {
......
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