Commit c6a7db13 authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Add SVGAngle::IsNumeric

When checking the 'orient' enumeration value the most common query is if
is an <angle> value. Since SVGAngle::IsAngle() sounds a bit too
tautological name it IsNumeric() instead.

Change-Id: I8b5add56dd510fe05545264dd91da9bd89527971
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207176
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770041}
parent 0096ff7d
...@@ -19,8 +19,7 @@ InterpolationValue SVGAngleInterpolationType::MaybeConvertNeutral( ...@@ -19,8 +19,7 @@ InterpolationValue SVGAngleInterpolationType::MaybeConvertNeutral(
InterpolationValue SVGAngleInterpolationType::MaybeConvertSVGValue( InterpolationValue SVGAngleInterpolationType::MaybeConvertSVGValue(
const SVGPropertyBase& svg_value) const { const SVGPropertyBase& svg_value) const {
if (To<SVGAngle>(svg_value).OrientType()->EnumValue() != if (!To<SVGAngle>(svg_value).IsNumeric())
kSVGMarkerOrientAngle)
return nullptr; return nullptr;
return InterpolationValue( return InterpolationValue(
std::make_unique<InterpolableNumber>(To<SVGAngle>(svg_value).Value())); std::make_unique<InterpolableNumber>(To<SVGAngle>(svg_value).Value()));
......
...@@ -366,21 +366,19 @@ void SVGAngle::Add(SVGPropertyBase* other, SVGElement*) { ...@@ -366,21 +366,19 @@ void SVGAngle::Add(SVGPropertyBase* other, SVGElement*) {
// Only respect by animations, if from and by are both specified in angles // Only respect by animations, if from and by are both specified in angles
// (and not, for example, 'auto'). // (and not, for example, 'auto').
if (OrientType()->EnumValue() != kSVGMarkerOrientAngle || if (!IsNumeric() || !other_angle->IsNumeric())
other_angle->OrientType()->EnumValue() != kSVGMarkerOrientAngle)
return; return;
SetValue(Value() + other_angle->Value()); SetValue(Value() + other_angle->Value());
} }
void SVGAngle::Assign(const SVGAngle& other) { void SVGAngle::Assign(const SVGAngle& other) {
SVGMarkerOrientType other_orient_type = other.OrientType()->EnumValue(); if (other.IsNumeric()) {
if (other_orient_type == kSVGMarkerOrientAngle) {
NewValueSpecifiedUnits(other.UnitType(), other.ValueInSpecifiedUnits()); NewValueSpecifiedUnits(other.UnitType(), other.ValueInSpecifiedUnits());
return; return;
} }
value_in_specified_units_ = 0; value_in_specified_units_ = 0;
orient_type_->SetEnumValue(other_orient_type); orient_type_->SetEnumValue(other.OrientType()->EnumValue());
} }
void SVGAngle::CalculateAnimatedValue( void SVGAngle::CalculateAnimatedValue(
...@@ -393,13 +391,10 @@ void SVGAngle::CalculateAnimatedValue( ...@@ -393,13 +391,10 @@ void SVGAngle::CalculateAnimatedValue(
SVGElement*) { SVGElement*) {
auto* from_angle = To<SVGAngle>(from); auto* from_angle = To<SVGAngle>(from);
auto* to_angle = To<SVGAngle>(to); auto* to_angle = To<SVGAngle>(to);
SVGMarkerOrientType from_orient_type = from_angle->OrientType()->EnumValue();
SVGMarkerOrientType to_orient_type = to_angle->OrientType()->EnumValue();
// We can only interpolate between two SVGAngles with orient-type 'angle', // We can only interpolate between two SVGAngles with orient-type 'angle',
// all other cases will use discrete animation. // all other cases will use discrete animation.
if (from_orient_type != to_orient_type || if (!from_angle->IsNumeric() || !to_angle->IsNumeric()) {
from_orient_type != kSVGMarkerOrientAngle) {
Assign(percentage < 0.5f ? *from_angle : *to_angle); Assign(percentage < 0.5f ? *from_angle : *to_angle);
return; return;
} }
...@@ -417,11 +412,14 @@ float SVGAngle::CalculateDistance(SVGPropertyBase* other, SVGElement*) { ...@@ -417,11 +412,14 @@ float SVGAngle::CalculateDistance(SVGPropertyBase* other, SVGElement*) {
} }
void SVGAngle::OrientTypeChanged() { void SVGAngle::OrientTypeChanged() {
if (OrientType()->EnumValue() == kSVGMarkerOrientAuto || if (IsNumeric())
OrientType()->EnumValue() == kSVGMarkerOrientAutoStartReverse) { return;
unit_type_ = kSvgAngletypeUnspecified; unit_type_ = kSvgAngletypeUnspecified;
value_in_specified_units_ = 0; value_in_specified_units_ = 0;
} }
bool SVGAngle::IsNumeric() const {
return orient_type_->EnumValue() == kSVGMarkerOrientAngle;
} }
} // namespace blink } // namespace blink
...@@ -109,6 +109,7 @@ class SVGAngle final : public SVGPropertyHelper<SVGAngle> { ...@@ -109,6 +109,7 @@ class SVGAngle final : public SVGPropertyHelper<SVGAngle> {
const SVGEnumeration<SVGMarkerOrientType>* OrientType() const { const SVGEnumeration<SVGMarkerOrientType>* OrientType() const {
return orient_type_.Get(); return orient_type_.Get();
} }
bool IsNumeric() const;
void OrientTypeChanged(); void OrientTypeChanged();
// SVGPropertyBase: // SVGPropertyBase:
......
...@@ -61,7 +61,7 @@ bool SVGAnimatedAngle::NeedsSynchronizeAttribute() const { ...@@ -61,7 +61,7 @@ bool SVGAnimatedAngle::NeedsSynchronizeAttribute() const {
void SVGAnimatedAngle::SynchronizeAttribute() { void SVGAnimatedAngle::SynchronizeAttribute() {
// If the value is not an <angle> we synchronize the value of the wrapped // If the value is not an <angle> we synchronize the value of the wrapped
// enumeration. // enumeration.
if (BaseValue()->OrientType()->EnumValue() != kSVGMarkerOrientAngle) { if (!BaseValue()->IsNumeric()) {
orient_type_->SynchronizeAttribute(); orient_type_->SynchronizeAttribute();
return; return;
} }
......
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