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

Simplify SMIL animated value calculation and application

The ResetAnimatedType, ClearAnimatedType, ApplyResultsToTarget and
CalculateAnimatedValue methods that handles calculation and application
of animation values are only called on elements that has made it into a
sandwich - this means that they have passed the "has valid target"
check. Simplify the code accordingly by assuming there is a target and
that other checks that HasValidTarget() make holds. The latter for
example means dropping the null-check for the animateMotion transform
transform.
Also remove SVGAnimateElement::ShouldApplyAnimation() and always remove
the CSS property in SVGAnimateElement::ClearAnimatedType() when
animating CSS.

Bug: 1017723
Change-Id: I9d184325671fae820c5718d3145228b7bd8d284e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895336Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#712531}
parent 75bd62b4
......@@ -228,11 +228,6 @@ bool SVGAnimateElement::HasValidTarget() const {
GetAttributeType() != kAttributeTypeCSS;
}
bool SVGAnimateElement::ShouldApplyAnimation(
const SVGElement& target_element) const {
return target_element.parentNode() && HasValidTarget();
}
SVGPropertyBase* SVGAnimateElement::CreatePropertyForAttributeAnimation(
const String& value) const {
// SVG DOM animVal animation code-path.
......@@ -437,9 +432,7 @@ bool SVGAnimateElement::CalculateFromAndByValues(const String& from_string,
}
void SVGAnimateElement::ResetAnimatedType() {
SVGElement* target_element = targetElement();
if (!ShouldApplyAnimation(*target_element))
return;
DCHECK(targetElement());
if (IsAnimatingSVGDom()) {
// SVG DOM animVal animation code-path.
animated_value_ = target_property_->CreateAnimatedValue();
......@@ -452,31 +445,23 @@ void SVGAnimateElement::ResetAnimatedType() {
DCHECK(SVGElement::IsAnimatableCSSProperty(AttributeName()));
// CSS properties animation code-path.
String base_value = ComputeCSSPropertyValue(target_element, css_property_id_);
String base_value =
ComputeCSSPropertyValue(targetElement(), css_property_id_);
animated_value_ = CreatePropertyForAnimation(base_value);
}
void SVGAnimateElement::ClearAnimatedType() {
if (!animated_value_)
return;
SVGElement* target_element = targetElement();
if (!target_element) {
animated_value_.Clear();
return;
}
DCHECK(target_element);
bool should_apply = ShouldApplyAnimation(*target_element);
// CSS properties animation code-path.
if (IsAnimatingCSSProperty()) {
if (should_apply) {
MutableCSSPropertyValueSet* property_set =
target_element->EnsureAnimatedSMILStyleProperties();
if (property_set->RemoveProperty(css_property_id_)) {
target_element->SetNeedsStyleRecalc(
kLocalStyleChange, StyleChangeReasonForTracing::Create(
style_change_reason::kAnimation));
}
MutableCSSPropertyValueSet* property_set =
target_element->EnsureAnimatedSMILStyleProperties();
if (property_set->RemoveProperty(css_property_id_)) {
target_element->SetNeedsStyleRecalc(
kLocalStyleChange,
StyleChangeReasonForTracing::Create(style_change_reason::kAnimation));
}
}
// SVG DOM animVal animation code-path.
......@@ -488,18 +473,12 @@ void SVGAnimateElement::ClearAnimatedType() {
void SVGAnimateElement::ApplyResultsToTarget() {
DCHECK_NE(GetAnimatedPropertyType(), kAnimatedUnknown);
// Early exit if our animated type got destructed by a previous
// endedActiveInterval().
if (!animated_value_)
return;
SVGElement* target_element = targetElement();
if (!ShouldApplyAnimation(*target_element))
return;
DCHECK(animated_value_);
DCHECK(targetElement());
// We do update the style and the animation property independent of each
// other.
SVGElement* target_element = targetElement();
// CSS properties animation code-path.
if (IsAnimatingCSSProperty()) {
......
......@@ -90,8 +90,6 @@ class CORE_EXPORT SVGAnimateElement : public SVGAnimationElement {
stringsShouldNotSupportAddition);
private:
bool ShouldApplyAnimation(const SVGElement& target_element) const;
void SetAttributeType(const AtomicString&);
InsertionNotificationRequest InsertedInto(ContainerNode&) final;
......
......@@ -144,21 +144,18 @@ static bool ParsePoint(const String& string, FloatPoint& point) {
void SVGAnimateMotionElement::ResetAnimatedType() {
SVGElement* target_element = targetElement();
if (!target_element || !TargetCanHaveMotionTransform(*target_element))
return;
if (AffineTransform* transform = target_element->AnimateMotionTransform())
transform->MakeIdentity();
DCHECK(target_element);
DCHECK(TargetCanHaveMotionTransform(*target_element));
AffineTransform* transform = target_element->AnimateMotionTransform();
DCHECK(transform);
transform->MakeIdentity();
}
void SVGAnimateMotionElement::ClearAnimatedType() {
SVGElement* target_element = targetElement();
if (!target_element)
return;
DCHECK(target_element);
AffineTransform* transform = target_element->AnimateMotionTransform();
if (!transform)
return;
DCHECK(transform);
transform->MakeIdentity();
if (LayoutObject* target_layout_object = target_element->GetLayoutObject())
......@@ -201,8 +198,7 @@ void SVGAnimateMotionElement::CalculateAnimatedValue(float percentage,
SVGElement* target_element = targetElement();
DCHECK(target_element);
AffineTransform* transform = target_element->AnimateMotionTransform();
if (!transform)
return;
DCHECK(transform);
if (!IsAdditive())
transform->MakeIdentity();
......@@ -257,12 +253,9 @@ void SVGAnimateMotionElement::ApplyResultsToTarget() {
// We accumulate to the target element transform list so there is not much to
// do here.
SVGElement* target_element = targetElement();
if (!target_element)
return;
DCHECK(target_element);
AffineTransform* target_transform = target_element->AnimateMotionTransform();
if (!target_transform)
return;
DCHECK(target_transform);
if (LayoutObject* target_layout_object = target_element->GetLayoutObject())
InvalidateForAnimateMotionTransformChange(*target_layout_object);
......@@ -273,8 +266,7 @@ void SVGAnimateMotionElement::ApplyResultsToTarget() {
DCHECK(shadow_tree_element);
AffineTransform* shadow_transform =
shadow_tree_element->AnimateMotionTransform();
if (!shadow_transform)
continue;
DCHECK(shadow_transform);
shadow_transform->SetTransform(*target_transform);
if (LayoutObject* layout_object = shadow_tree_element->GetLayoutObject())
InvalidateForAnimateMotionTransformChange(*layout_object);
......
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