[svg] Rename gradient units type to object bounding box units

It turns out that "userSpaceOnUse | objectBoundingBox" can be specified
as the unit type for multiple elements, such as clips, masks, filters
etc. and is not specific to gradients.

The full list:
https://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBoxUnits

Bug: skia:10842
Change-Id: I995d588862fb43b9f130f0455d7af8de47046af4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/330616
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
diff --git a/modules/svg/include/SkSVGAttributeParser.h b/modules/svg/include/SkSVGAttributeParser.h
index 57a73c8..d61d750 100644
--- a/modules/svg/include/SkSVGAttributeParser.h
+++ b/modules/svg/include/SkSVGAttributeParser.h
@@ -29,7 +29,7 @@
     bool parseIRI(SkSVGStringType*);
     bool parseSpreadMethod(SkSVGSpreadMethod*);
     bool parseStopColor(SkSVGStopColor*);
-    bool parseGradientUnits(SkSVGGradientUnits*);
+    bool parseObjectBoundingBoxUnits(SkSVGObjectBoundingBoxUnits*);
     bool parseVisibility(SkSVGVisibility*);
     bool parseDashArray(SkSVGDashArray*);
     bool parsePreserveAspectRatio(SkSVGPreserveAspectRatio*);
diff --git a/modules/svg/include/SkSVGGradient.h b/modules/svg/include/SkSVGGradient.h
index 175d2fc..8734252 100644
--- a/modules/svg/include/SkSVGGradient.h
+++ b/modules/svg/include/SkSVGGradient.h
@@ -23,7 +23,7 @@
     void setHref(const SkSVGStringType&);
     void setGradientTransform(const SkSVGTransformType&);
     void setSpreadMethod(const SkSVGSpreadMethod&);
-    void setGradientUnits(const SkSVGGradientUnits&);
+    void setGradientUnits(const SkSVGObjectBoundingBoxUnits&);
 
 protected:
     explicit SkSVGGradient(SkSVGTag t) : INHERITED(t) {}
@@ -36,7 +36,8 @@
                                          const SkColor*, const SkScalar*, int count,
                                          SkTileMode, const SkMatrix& localMatrix) const = 0;
 
-    SkSVGGradientUnits fGradientUnits = SkSVGGradientUnits(SkSVGGradientUnits::Type::kObjectBoundingBox);
+    SkSVGObjectBoundingBoxUnits fGradientUnits =
+            SkSVGObjectBoundingBoxUnits(SkSVGObjectBoundingBoxUnits::Type::kObjectBoundingBox);
 
 private:
     using StopPositionArray = SkSTArray<2, SkScalar, true>;
diff --git a/modules/svg/include/SkSVGTypes.h b/modules/svg/include/SkSVGTypes.h
index 840a378..65895dc 100644
--- a/modules/svg/include/SkSVGTypes.h
+++ b/modules/svg/include/SkSVGTypes.h
@@ -308,20 +308,22 @@
     SkSVGColorType fColor;
 };
 
-class SkSVGGradientUnits {
+class SkSVGObjectBoundingBoxUnits {
 public:
     enum class Type {
         kUserSpaceOnUse,
         kObjectBoundingBox,
     };
 
-    SkSVGGradientUnits() : fType(Type::kUserSpaceOnUse) {}
-    explicit SkSVGGradientUnits(Type t) : fType(t) {}
+    SkSVGObjectBoundingBoxUnits() : fType(Type::kUserSpaceOnUse) {}
+    explicit SkSVGObjectBoundingBoxUnits(Type t) : fType(t) {}
 
-    bool operator==(const SkSVGGradientUnits& other) const {
+    bool operator==(const SkSVGObjectBoundingBoxUnits& other) const {
         return fType == other.fType;
     }
-    bool operator!=(const SkSVGGradientUnits& other) const { return !(*this == other); }
+    bool operator!=(const SkSVGObjectBoundingBoxUnits& other) const {
+        return !(*this == other);
+    }
 
     Type type() const { return fType; }
 
diff --git a/modules/svg/include/SkSVGValue.h b/modules/svg/include/SkSVGValue.h
index aafe332..0040179 100644
--- a/modules/svg/include/SkSVGValue.h
+++ b/modules/svg/include/SkSVGValue.h
@@ -26,11 +26,11 @@
         kFontSize,
         kFontStyle,
         kFontWeight,
-        kGradientUnits,
         kLength,
         kLineCap,
         kLineJoin,
         kNumber,
+        kObjectBoundingBoxUnits,
         kPaint,
         kPath,
         kPoints,
@@ -98,8 +98,6 @@
 using SkSVGSpreadMethodValue = SkSVGWrapperValue<SkSVGSpreadMethod ,
                                                  SkSVGValue::Type::kSpreadMethod>;
 using SkSVGStopColorValue    = SkSVGWrapperValue<SkSVGStopColor    , SkSVGValue::Type::kStopColor >;
-using SkSVGGradientUnitsValue= SkSVGWrapperValue<SkSVGGradientUnits,
-                                                 SkSVGValue::Type::kGradientUnits>;
 using SkSVGVisibilityValue   = SkSVGWrapperValue<SkSVGVisibility   , SkSVGValue::Type::kVisibility>;
 using SkSVGDashArrayValue    = SkSVGWrapperValue<SkSVGDashArray    , SkSVGValue::Type::kDashArray >;
 
@@ -109,7 +107,10 @@
 using SkSVGFontWeightValue   = SkSVGWrapperValue<SkSVGFontWeight   , SkSVGValue::Type::kFontWeight>;
 using SkSVGTextAnchorValue   = SkSVGWrapperValue<SkSVGTextAnchor   , SkSVGValue::Type::kTextAnchor>;
 
-using SkSVGPreserveAspectRatioValue = SkSVGWrapperValue<SkSVGPreserveAspectRatio,
-                                                        SkSVGValue::Type::kPreserveAspectRatio>;
+using SkSVGPreserveAspectRatioValue    = SkSVGWrapperValue<SkSVGPreserveAspectRatio,
+                                                           SkSVGValue::Type::kPreserveAspectRatio>;
+
+using SkSVGObjectBoundingBoxUnitsValue = SkSVGWrapperValue<SkSVGObjectBoundingBoxUnits,
+                                                           SkSVGValue::Type::kObjectBoundingBoxUnits>;
 
 #endif // SkSVGValue_DEFINED
diff --git a/modules/svg/src/SkSVGAttributeParser.cpp b/modules/svg/src/SkSVGAttributeParser.cpp
index 05c585b..f6a6e66 100644
--- a/modules/svg/src/SkSVGAttributeParser.cpp
+++ b/modules/svg/src/SkSVGAttributeParser.cpp
@@ -597,14 +597,17 @@
     return parsedValue && this->parseEOSToken();
 }
 
-// https://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementGradientUnitsAttribute
-bool SkSVGAttributeParser::parseGradientUnits(SkSVGGradientUnits* gradientUnits) {
+// https://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBoxUnits
+bool SkSVGAttributeParser::parseObjectBoundingBoxUnits(
+        SkSVGObjectBoundingBoxUnits* objectBoundingBoxUnits) {
     bool parsedValue = false;
     if (this->parseExpectedStringToken("userSpaceOnUse")) {
-        *gradientUnits = SkSVGGradientUnits(SkSVGGradientUnits::Type::kUserSpaceOnUse);
+        *objectBoundingBoxUnits =
+                SkSVGObjectBoundingBoxUnits(SkSVGObjectBoundingBoxUnits::Type::kUserSpaceOnUse);
         parsedValue = true;
     } else if (this->parseExpectedStringToken("objectBoundingBox")) {
-        *gradientUnits = SkSVGGradientUnits(SkSVGGradientUnits::Type::kObjectBoundingBox);
+        *objectBoundingBoxUnits =
+                SkSVGObjectBoundingBoxUnits(SkSVGObjectBoundingBoxUnits::Type::kObjectBoundingBox);
         parsedValue = true;
     }
     return parsedValue && this->parseEOSToken();
diff --git a/modules/svg/src/SkSVGDOM.cpp b/modules/svg/src/SkSVGDOM.cpp
index f9327a3..37e2bbe7 100644
--- a/modules/svg/src/SkSVGDOM.cpp
+++ b/modules/svg/src/SkSVGDOM.cpp
@@ -200,15 +200,16 @@
     return true;
 }
 
-bool SetGradientUnitsAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
-                               const char* stringValue) {
-    SkSVGGradientUnits gradientUnits;
+bool SetObjectBoundingBoxUnitsAttribute(const sk_sp<SkSVGNode>& node,
+                                        SkSVGAttribute attr,
+                                        const char* stringValue) {
+    SkSVGObjectBoundingBoxUnits objectBoundingBoxUnits;
     SkSVGAttributeParser parser(stringValue);
-    if (!parser.parseGradientUnits(&gradientUnits)) {
+    if (!parser.parseObjectBoundingBoxUnits(&objectBoundingBoxUnits)) {
         return false;
     }
 
-    node->setAttribute(attr, SkSVGGradientUnitsValue(gradientUnits));
+    node->setAttribute(attr, SkSVGObjectBoundingBoxUnitsValue(objectBoundingBoxUnits));
     return true;
 }
 
@@ -428,7 +429,8 @@
     { "fx"                 , { SkSVGAttribute::kFx               , SetLengthAttribute       }},
     { "fy"                 , { SkSVGAttribute::kFy               , SetLengthAttribute       }},
     { "gradientTransform"  , { SkSVGAttribute::kGradientTransform, SetTransformAttribute    }},
-    { "gradientUnits"      , { SkSVGAttribute::kGradientUnits    , SetGradientUnitsAttribute}},
+    { "gradientUnits"      , { SkSVGAttribute::kGradientUnits    ,
+                               SetObjectBoundingBoxUnitsAttribute }},
     { "height"             , { SkSVGAttribute::kHeight           , SetLengthAttribute       }},
     { "offset"             , { SkSVGAttribute::kOffset           , SetLengthAttribute       }},
     { "opacity"            , { SkSVGAttribute::kOpacity          , SetNumberAttribute       }},
diff --git a/modules/svg/src/SkSVGGradient.cpp b/modules/svg/src/SkSVGGradient.cpp
index 9500681..3d45438 100644
--- a/modules/svg/src/SkSVGGradient.cpp
+++ b/modules/svg/src/SkSVGGradient.cpp
@@ -23,7 +23,7 @@
     fSpreadMethod = spread;
 }
 
-void SkSVGGradient::setGradientUnits(const SkSVGGradientUnits& gradientUnits) {
+void SkSVGGradient::setGradientUnits(const SkSVGObjectBoundingBoxUnits& gradientUnits) {
     fGradientUnits = gradientUnits;
 }
 
@@ -45,7 +45,7 @@
         }
         break;
     case SkSVGAttribute::kGradientUnits:
-        if (const auto* gradientUnits = v.as<SkSVGGradientUnitsValue>()) {
+        if (const auto* gradientUnits = v.as<SkSVGObjectBoundingBoxUnitsValue>()) {
             this->setGradientUnits(*gradientUnits);
         }
         break;
@@ -127,7 +127,7 @@
     const auto tileMode = static_cast<SkTileMode>(fSpreadMethod.type());
 
     SkMatrix localMatrix = SkMatrix::I();
-    if (fGradientUnits.type() == SkSVGGradientUnits::Type::kObjectBoundingBox) {
+    if (fGradientUnits.type() == SkSVGObjectBoundingBoxUnits::Type::kObjectBoundingBox) {
         SkASSERT(ctx.node());
         const SkRect objBounds = ctx.node()->objectBoundingBox(ctx);
         localMatrix.preTranslate(objBounds.fLeft, objBounds.fTop);
diff --git a/modules/svg/src/SkSVGLinearGradient.cpp b/modules/svg/src/SkSVGLinearGradient.cpp
index 1579942..54f6eff 100644
--- a/modules/svg/src/SkSVGLinearGradient.cpp
+++ b/modules/svg/src/SkSVGLinearGradient.cpp
@@ -60,7 +60,7 @@
                                                   int count, SkTileMode tm,
                                                   const SkMatrix& localMatrix) const {
     const SkSVGLengthContext lctx =
-            fGradientUnits.type() == SkSVGGradientUnits::Type::kObjectBoundingBox
+            fGradientUnits.type() == SkSVGObjectBoundingBoxUnits::Type::kObjectBoundingBox
                     ? SkSVGLengthContext({1, 1})
                     : ctx.lengthContext();
 
diff --git a/modules/svg/src/SkSVGRadialGradient.cpp b/modules/svg/src/SkSVGRadialGradient.cpp
index 0300248..7273365 100644
--- a/modules/svg/src/SkSVGRadialGradient.cpp
+++ b/modules/svg/src/SkSVGRadialGradient.cpp
@@ -69,7 +69,7 @@
                                                   int count, SkTileMode tm,
                                                   const SkMatrix& m) const {
     const SkSVGLengthContext lctx =
-            fGradientUnits.type() == SkSVGGradientUnits::Type::kObjectBoundingBox
+            fGradientUnits.type() == SkSVGObjectBoundingBoxUnits::Type::kObjectBoundingBox
                     ? SkSVGLengthContext({1, 1})
                     : ctx.lengthContext();