Commit abf9460b authored by fs's avatar fs Committed by Commit bot

Reduce 'iterate self and instances' helper-count in SVGElement.cpp

Generalizing updateInstancesAnimatedAttribute{,NoInvalidate} to one
higher-level helper to get rid of the subtle differences brought on
by the differences in invalidation semantics.

BUG=640676

Review-Url: https://codereview.chromium.org/2280923002
Cr-Commit-Position: refs/heads/master@{#414845}
parent dbd71521
...@@ -237,16 +237,6 @@ void SVGElement::applyActiveWebAnimations() ...@@ -237,16 +237,6 @@ void SVGElement::applyActiveWebAnimations()
svgRareData()->setWebAnimatedAttributesDirty(false); svgRareData()->setWebAnimatedAttributesDirty(false);
} }
template<typename T>
static void updateInstancesAnimatedAttributeNoInvalidate(SVGElement* element, const QualifiedName& attribute, T callback)
{
SVGElement::InstanceUpdateBlocker blocker(element);
for (SVGElement* instance : SVGAnimateElement::findElementInstances(element)) {
if (SVGAnimatedPropertyBase* animatedProperty = instance->propertyFromAttribute(attribute))
callback(*animatedProperty);
}
}
static inline void notifyAnimValChanged(SVGElement* targetElement, const QualifiedName& attributeName) static inline void notifyAnimValChanged(SVGElement* targetElement, const QualifiedName& attributeName)
{ {
targetElement->invalidateSVGAttributes(); targetElement->invalidateSVGAttributes();
...@@ -254,21 +244,20 @@ static inline void notifyAnimValChanged(SVGElement* targetElement, const Qualifi ...@@ -254,21 +244,20 @@ static inline void notifyAnimValChanged(SVGElement* targetElement, const Qualifi
} }
template<typename T> template<typename T>
static void updateInstancesAnimatedAttribute(SVGElement* element, const QualifiedName& attribute, T callback) static void forSelfAndInstances(SVGElement* element, T callback)
{ {
SVGElement::InstanceUpdateBlocker blocker(element); SVGElement::InstanceUpdateBlocker blocker(element);
for (SVGElement* instance : SVGAnimateElement::findElementInstances(element)) { for (SVGElement* instance : SVGAnimateElement::findElementInstances(element))
if (SVGAnimatedPropertyBase* animatedProperty = instance->propertyFromAttribute(attribute)) { callback(instance);
callback(*animatedProperty);
notifyAnimValChanged(instance, attribute);
}
}
} }
void SVGElement::setWebAnimatedAttribute(const QualifiedName& attribute, SVGPropertyBase* value) void SVGElement::setWebAnimatedAttribute(const QualifiedName& attribute, SVGPropertyBase* value)
{ {
updateInstancesAnimatedAttribute(this, attribute, [&value](SVGAnimatedPropertyBase& animatedProperty) { forSelfAndInstances(this, [&attribute, &value](SVGElement* element) {
animatedProperty.setAnimatedValue(value); if (SVGAnimatedPropertyBase* animatedProperty = element->propertyFromAttribute(attribute)) {
animatedProperty->setAnimatedValue(value);
notifyAnimValChanged(element, attribute);
}
}); });
ensureSVGRareData()->webAnimatedAttributes().add(&attribute); ensureSVGRareData()->webAnimatedAttributes().add(&attribute);
} }
...@@ -278,8 +267,11 @@ void SVGElement::clearWebAnimatedAttributes() ...@@ -278,8 +267,11 @@ void SVGElement::clearWebAnimatedAttributes()
if (!hasSVGRareData()) if (!hasSVGRareData())
return; return;
for (const QualifiedName* attribute : svgRareData()->webAnimatedAttributes()) { for (const QualifiedName* attribute : svgRareData()->webAnimatedAttributes()) {
updateInstancesAnimatedAttribute(this, *attribute, [](SVGAnimatedPropertyBase& animatedProperty) { forSelfAndInstances(this, [&attribute](SVGElement* element) {
animatedProperty.animationEnded(); if (SVGAnimatedPropertyBase* animatedProperty = element->propertyFromAttribute(*attribute)) {
animatedProperty->animationEnded();
notifyAnimValChanged(element, *attribute);
}
}); });
} }
svgRareData()->webAnimatedAttributes().clear(); svgRareData()->webAnimatedAttributes().clear();
...@@ -287,24 +279,24 @@ void SVGElement::clearWebAnimatedAttributes() ...@@ -287,24 +279,24 @@ void SVGElement::clearWebAnimatedAttributes()
void SVGElement::setAnimatedAttribute(const QualifiedName& attribute, SVGPropertyBase* value) void SVGElement::setAnimatedAttribute(const QualifiedName& attribute, SVGPropertyBase* value)
{ {
updateInstancesAnimatedAttributeNoInvalidate(this, attribute, [&value](SVGAnimatedPropertyBase& animatedProperty) { forSelfAndInstances(this, [&attribute, &value](SVGElement* element) {
animatedProperty.setAnimatedValue(value); if (SVGAnimatedPropertyBase* animatedProperty = element->propertyFromAttribute(attribute))
animatedProperty->setAnimatedValue(value);
}); });
} }
void SVGElement::invalidateAnimatedAttribute(const QualifiedName& attribute) void SVGElement::invalidateAnimatedAttribute(const QualifiedName& attribute)
{ {
InstanceUpdateBlocker blocker(this); forSelfAndInstances(this, [&attribute](SVGElement* element) {
notifyAnimValChanged(this, attribute);
for (SVGElement* element : instancesForElement())
notifyAnimValChanged(element, attribute); notifyAnimValChanged(element, attribute);
});
} }
void SVGElement::clearAnimatedAttribute(const QualifiedName& attribute) void SVGElement::clearAnimatedAttribute(const QualifiedName& attribute)
{ {
updateInstancesAnimatedAttributeNoInvalidate(this, attribute, [](SVGAnimatedPropertyBase& animatedProperty) { forSelfAndInstances(this, [&attribute](SVGElement* element) {
animatedProperty.animationEnded(); if (SVGAnimatedPropertyBase* animatedProperty = element->propertyFromAttribute(attribute))
animatedProperty->animationEnded();
}); });
} }
......
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