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

Cleanup invalidation of SMIL timing/animation parameters

The main gist is that timing and animation should be essentially
independent - i.e the former only feeds into the latter by means of the
progress state. Based on this we can perform some cleanups:

 * Any change to the animation target will also invalidate the
   animation parameter state via WillChangeAnimationTarget(), so any
   such change (SetTargetElement, SetAttributeType and SetAttributeName)
   needn't be followed by a call to AnimationAttributeChanged(), so
   remove those.

 * Any change to timing state (such as 'dur', 'repeatDur',
   'repeatCount', 'min', 'max', 'begin' and 'end') will only influence
   the timing and not animation state, so we can drop calls to
   AnimationAttributeChanged() in those cases as well.

 * Since changing animation state should not affect timing, drop the
   call to SetInactive() from AnimationAttributeChanged() - this will be
   handled by timing updates when needed. This also means that
   SetInactive() is no longer used so it can be removed.

After the above changes AnimationAttributeChanged() no longer needs to
be virtual, and can reside in SVGAnimationElement alone.
Also fold InvalidatedValuesCache() into AnimationAttributeChanged()
since it is the only caller.
Take this opportunity to move some state updates from the
SvgAttributeChanged() override (which is for attributes which have an
SVG DOM representation - and 'href' attributes because of how the
dependency notifications work) to ParseAttribute().

Bug: 998526
Change-Id: Id50407cb5fb59601fea573e5963a7d4e1158a317
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869210Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#707366}
parent cfd97ee1
...@@ -298,7 +298,6 @@ void SVGSMILElement::RemovedFrom(ContainerNode& root_parent) { ...@@ -298,7 +298,6 @@ void SVGSMILElement::RemovedFrom(ContainerNode& root_parent) {
ClearResourceAndEventBaseReferences(); ClearResourceAndEventBaseReferences();
ClearConditions(); ClearConditions();
SetTargetElement(nullptr); SetTargetElement(nullptr);
AnimationAttributeChanged();
time_container_ = nullptr; time_container_ = nullptr;
} }
...@@ -483,7 +482,6 @@ void SVGSMILElement::ParseAttribute(const AttributeModificationParams& params) { ...@@ -483,7 +482,6 @@ void SVGSMILElement::ParseAttribute(const AttributeModificationParams& params) {
time_container_->ScheduleIntervalUpdate(); time_container_->ScheduleIntervalUpdate();
} }
} }
AnimationAttributeChanged();
} else if (name == svg_names::kEndAttr) { } else if (name == svg_names::kEndAttr) {
if (!conditions_.IsEmpty()) { if (!conditions_.IsEmpty()) {
ClearConditions(); ClearConditions();
...@@ -499,7 +497,6 @@ void SVGSMILElement::ParseAttribute(const AttributeModificationParams& params) { ...@@ -499,7 +497,6 @@ void SVGSMILElement::ParseAttribute(const AttributeModificationParams& params) {
time_container_->ScheduleIntervalUpdate(); time_container_->ScheduleIntervalUpdate();
} }
} }
AnimationAttributeChanged();
} else if (name == svg_names::kOnbeginAttr) { } else if (name == svg_names::kOnbeginAttr) {
SetAttributeEventListener(event_type_names::kBeginEvent, SetAttributeEventListener(event_type_names::kBeginEvent,
CreateAttributeEventListener(this, name, value)); CreateAttributeEventListener(this, name, value));
...@@ -518,34 +515,31 @@ void SVGSMILElement::ParseAttribute(const AttributeModificationParams& params) { ...@@ -518,34 +515,31 @@ void SVGSMILElement::ParseAttribute(const AttributeModificationParams& params) {
restart_ = kRestartAlways; restart_ = kRestartAlways;
} else if (name == svg_names::kFillAttr) { } else if (name == svg_names::kFillAttr) {
fill_ = value == "freeze" ? kFillFreeze : kFillRemove; fill_ = value == "freeze" ? kFillFreeze : kFillRemove;
} else if (name == svg_names::kDurAttr) {
cached_dur_ = kInvalidCachedTime;
} else if (name == svg_names::kRepeatDurAttr) {
cached_repeat_dur_ = kInvalidCachedTime;
} else if (name == svg_names::kRepeatCountAttr) {
cached_repeat_count_ = SMILRepeatCount::Invalid();
} else if (name == svg_names::kMinAttr) {
cached_min_ = kInvalidCachedTime;
} else if (name == svg_names::kMaxAttr) {
cached_max_ = kInvalidCachedTime;
} else { } else {
SVGElement::ParseAttribute(params); SVGElement::ParseAttribute(params);
} }
} }
void SVGSMILElement::SvgAttributeChanged(const QualifiedName& attr_name) { void SVGSMILElement::SvgAttributeChanged(const QualifiedName& attr_name) {
if (attr_name == svg_names::kDurAttr) { if (attr_name.Matches(svg_names::kHrefAttr) ||
cached_dur_ = kInvalidCachedTime; attr_name.Matches(xlink_names::kHrefAttr)) {
} else if (attr_name == svg_names::kRepeatDurAttr) {
cached_repeat_dur_ = kInvalidCachedTime;
} else if (attr_name == svg_names::kRepeatCountAttr) {
cached_repeat_count_ = SMILRepeatCount::Invalid();
} else if (attr_name == svg_names::kMinAttr) {
cached_min_ = kInvalidCachedTime;
} else if (attr_name == svg_names::kMaxAttr) {
cached_max_ = kInvalidCachedTime;
} else if (attr_name.Matches(svg_names::kHrefAttr) ||
attr_name.Matches(xlink_names::kHrefAttr)) {
// TODO(fs): Could be smarter here when 'href' is specified and 'xlink:href' // TODO(fs): Could be smarter here when 'href' is specified and 'xlink:href'
// is changed. // is changed.
SVGElement::InvalidationGuard invalidation_guard(this); SVGElement::InvalidationGuard invalidation_guard(this);
BuildPendingResource(); BuildPendingResource();
} else {
SVGElement::SvgAttributeChanged(attr_name);
return; return;
} }
SVGElement::SvgAttributeChanged(attr_name);
AnimationAttributeChanged();
} }
void SVGSMILElement::ConnectConditions() { void SVGSMILElement::ConnectConditions() {
......
...@@ -56,7 +56,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { ...@@ -56,7 +56,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
void RemovedFrom(ContainerNode&) override; void RemovedFrom(ContainerNode&) override;
virtual bool HasValidTarget() const; virtual bool HasValidTarget() const;
virtual void AnimationAttributeChanged() = 0;
SMILTimeContainer* TimeContainer() const { return time_container_.Get(); } SMILTimeContainer* TimeContainer() const { return time_container_.Get(); }
...@@ -131,8 +130,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests { ...@@ -131,8 +130,6 @@ class CORE_EXPORT SVGSMILElement : public SVGElement, public SVGTests {
void AddInstanceTimeAndUpdate(BeginOrEnd, SMILTime, SMILTimeOrigin); void AddInstanceTimeAndUpdate(BeginOrEnd, SMILTime, SMILTimeOrigin);
void SetInactive() { active_state_ = kInactive; }
void SetTargetElement(SVGElement*); void SetTargetElement(SVGElement*);
// Sub-classes may need to take action when the target is changed. // Sub-classes may need to take action when the target is changed.
......
...@@ -155,12 +155,10 @@ void SVGAnimateElement::ParseAttribute( ...@@ -155,12 +155,10 @@ void SVGAnimateElement::ParseAttribute(
const AttributeModificationParams& params) { const AttributeModificationParams& params) {
if (params.name == svg_names::kAttributeTypeAttr) { if (params.name == svg_names::kAttributeTypeAttr) {
SetAttributeType(params.new_value); SetAttributeType(params.new_value);
AnimationAttributeChanged();
return; return;
} }
if (params.name == svg_names::kAttributeNameAttr) { if (params.name == svg_names::kAttributeNameAttr) {
SetAttributeName(ConstructQualifiedName(*this, params.new_value)); SetAttributeName(ConstructQualifiedName(*this, params.new_value));
AnimationAttributeChanged();
return; return;
} }
SVGAnimationElement::ParseAttribute(params); SVGAnimationElement::ParseAttribute(params);
......
...@@ -171,6 +171,7 @@ void SVGAnimationElement::ParseAttribute( ...@@ -171,6 +171,7 @@ void SVGAnimationElement::ParseAttribute(
return; return;
} }
UpdateAnimationMode(); UpdateAnimationMode();
AnimationAttributeChanged();
return; return;
} }
...@@ -179,6 +180,7 @@ void SVGAnimationElement::ParseAttribute( ...@@ -179,6 +180,7 @@ void SVGAnimationElement::ParseAttribute(
ReportAttributeParsingError(SVGParseStatus::kParsingFailed, name, ReportAttributeParsingError(SVGParseStatus::kParsingFailed, name,
params.new_value); params.new_value);
} }
AnimationAttributeChanged();
return; return;
} }
...@@ -191,6 +193,7 @@ void SVGAnimationElement::ParseAttribute( ...@@ -191,6 +193,7 @@ void SVGAnimationElement::ParseAttribute(
params.new_value); params.new_value);
} }
} }
AnimationAttributeChanged();
return; return;
} }
...@@ -199,53 +202,36 @@ void SVGAnimationElement::ParseAttribute( ...@@ -199,53 +202,36 @@ void SVGAnimationElement::ParseAttribute(
ReportAttributeParsingError(SVGParseStatus::kParsingFailed, name, ReportAttributeParsingError(SVGParseStatus::kParsingFailed, name,
params.new_value); params.new_value);
} }
AnimationAttributeChanged();
return; return;
} }
if (name == svg_names::kCalcModeAttr) { if (name == svg_names::kCalcModeAttr) {
SetCalcMode(params.new_value); SetCalcMode(params.new_value);
AnimationAttributeChanged();
return; return;
} }
if (name == svg_names::kFromAttr || name == svg_names::kToAttr || if (name == svg_names::kFromAttr || name == svg_names::kToAttr ||
name == svg_names::kByAttr) { name == svg_names::kByAttr) {
UpdateAnimationMode(); UpdateAnimationMode();
return;
}
SVGSMILElement::ParseAttribute(params);
}
void SVGAnimationElement::SvgAttributeChanged(const QualifiedName& attr_name) {
if (attr_name == svg_names::kValuesAttr || attr_name == svg_names::kByAttr ||
attr_name == svg_names::kFromAttr || attr_name == svg_names::kToAttr ||
attr_name == svg_names::kCalcModeAttr ||
attr_name == svg_names::kKeySplinesAttr ||
attr_name == svg_names::kKeyPointsAttr ||
attr_name == svg_names::kKeyTimesAttr) {
AnimationAttributeChanged(); AnimationAttributeChanged();
return; return;
} }
SVGSMILElement::SvgAttributeChanged(attr_name); SVGSMILElement::ParseAttribute(params);
}
void SVGAnimationElement::InvalidatedValuesCache() {
last_values_animation_from_ = String();
last_values_animation_to_ = String();
} }
void SVGAnimationElement::AnimationAttributeChanged() { void SVGAnimationElement::AnimationAttributeChanged() {
// Assumptions may not hold after an attribute change. // Assumptions may not hold after an attribute change.
animation_valid_ = AnimationValidity::kUnknown; animation_valid_ = AnimationValidity::kUnknown;
InvalidatedValuesCache(); last_values_animation_from_ = String();
SetInactive(); last_values_animation_to_ = String();
} }
void SVGAnimationElement::WillChangeAnimationTarget() { void SVGAnimationElement::WillChangeAnimationTarget() {
SVGSMILElement::WillChangeAnimationTarget(); SVGSMILElement::WillChangeAnimationTarget();
animation_valid_ = AnimationValidity::kUnknown; AnimationAttributeChanged();
InvalidatedValuesCache();
} }
float SVGAnimationElement::getStartTime(ExceptionState& exception_state) const { float SVGAnimationElement::getStartTime(ExceptionState& exception_state) const {
......
...@@ -114,7 +114,6 @@ class CORE_EXPORT SVGAnimationElement : public SVGSMILElement { ...@@ -114,7 +114,6 @@ class CORE_EXPORT SVGAnimationElement : public SVGSMILElement {
SVGAnimationElement(const QualifiedName&, Document&); SVGAnimationElement(const QualifiedName&, Document&);
void ParseAttribute(const AttributeModificationParams&) override; void ParseAttribute(const AttributeModificationParams&) override;
void SvgAttributeChanged(const QualifiedName&) override;
String ToValue() const; String ToValue() const;
String ByValue() const; String ByValue() const;
...@@ -141,13 +140,12 @@ class CORE_EXPORT SVGAnimationElement : public SVGSMILElement { ...@@ -141,13 +140,12 @@ class CORE_EXPORT SVGAnimationElement : public SVGSMILElement {
// http://www.w3.org/TR/SVG/animate.html#ValuesAttribute . // http://www.w3.org/TR/SVG/animate.html#ValuesAttribute .
static bool ParseValues(const String&, Vector<String>& result); static bool ParseValues(const String&, Vector<String>& result);
void InvalidatedValuesCache();
void AnimationAttributeChanged() override;
void WillChangeAnimationTarget() override; void WillChangeAnimationTarget() override;
private: private:
bool IsValid() const final { return SVGTests::IsValid(); } bool IsValid() const final { return SVGTests::IsValid(); }
void AnimationAttributeChanged();
bool CheckAnimationParameters(); bool CheckAnimationParameters();
virtual bool CalculateToAtEndOfDurationValue( virtual bool CalculateToAtEndOfDurationValue(
const String& to_at_end_of_duration_string) = 0; const String& to_at_end_of_duration_string) = 0;
......
...@@ -47,7 +47,6 @@ class SVGDiscardElement final : public SVGSMILElement { ...@@ -47,7 +47,6 @@ class SVGDiscardElement final : public SVGSMILElement {
void ResetAnimatedType() override {} void ResetAnimatedType() override {}
void ClearAnimatedType() override {} void ClearAnimatedType() override {}
void ApplyResultsToTarget() override {} void ApplyResultsToTarget() override {}
void AnimationAttributeChanged() override {}
bool OverwritesUnderlyingAnimationValue() const override { return false; } bool OverwritesUnderlyingAnimationValue() const override { return false; }
......
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