Bug 1383650 - Add conversion utilities to get CSS counterpart of SVG unit and AttrEnum r=longsonr
☠☠ backed out by 1624c5a31917 ☠ ☠
authorviolet <violet.bugreport@gmail.com>
Thu, 16 May 2019 00:53:45 +0000
changeset 532849 e864696f6cf80910479dce91eed090a6455a4e2f
parent 532848 2b003d678c5885aa8bc388fbca2e211addcb2d93
child 532850 a7b8e6460fb8b1245507e9e15deadc1e62674102
push id11272
push userapavel@mozilla.com
push dateThu, 16 May 2019 15:28:22 +0000
treeherdermozilla-beta@2265bfc5920d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs1383650
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1383650 - Add conversion utilities to get CSS counterpart of SVG unit and AttrEnum r=longsonr We need some utilities to convert SVG unit and attrenum to CSS unit and property id. This is useful when we need to pass parsed geometry property directly to CSS. Differential Revision: https://phabricator.services.mozilla.com/D30777
dom/svg/SVGCircleElement.cpp
dom/svg/SVGCircleElement.h
dom/svg/SVGEllipseElement.cpp
dom/svg/SVGEllipseElement.h
dom/svg/SVGForeignObjectElement.cpp
dom/svg/SVGForeignObjectElement.h
dom/svg/SVGGeometryProperty.cpp
dom/svg/SVGGeometryProperty.h
dom/svg/SVGRectElement.cpp
dom/svg/SVGRectElement.h
dom/svg/moz.build
--- a/dom/svg/SVGCircleElement.cpp
+++ b/dom/svg/SVGCircleElement.cpp
@@ -145,10 +145,25 @@ bool SVGCircleElement::IsLengthChangedVi
   auto *newSVGReset = aNewStyle.StyleSVGReset(),
        *oldSVGReset = aOldStyle.StyleSVGReset();
 
   return newSVGReset->mCx != oldSVGReset->mCx ||
          newSVGReset->mCy != oldSVGReset->mCy ||
          newSVGReset->mR != oldSVGReset->mR;
 }
 
+nsCSSPropertyID SVGCircleElement::GetCSSPropertyIdForAttrEnum(
+    uint8_t aAttrEnum) {
+  switch (aAttrEnum) {
+    case ATTR_CX:
+      return eCSSProperty_cx;
+    case ATTR_CY:
+      return eCSSProperty_cy;
+    case ATTR_R:
+      return eCSSProperty_r;
+    default:
+      MOZ_ASSERT_UNREACHABLE("Unknown attr enum");
+      return eCSSProperty_UNKNOWN;
+  }
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/svg/SVGCircleElement.h
+++ b/dom/svg/SVGCircleElement.h
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGCircleElement_h
 #define mozilla_dom_SVGCircleElement_h
 
+#include "nsCSSPropertyID.h"
 #include "SVGGeometryElement.h"
 #include "SVGAnimatedLength.h"
 
 nsresult NS_NewSVGCircleElement(
     nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 class ComputedStyle;
@@ -42,16 +43,17 @@ class SVGCircleElement final : public SV
       const Matrix& aToBoundsSpace,
       const Matrix* aToNonScalingStrokeSpace = nullptr) override;
   virtual already_AddRefed<Path> BuildPath(PathBuilder* aBuilder) override;
 
   virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
 
   static bool IsLengthChangedViaCSS(const ComputedStyle& aNewStyle,
                                     const ComputedStyle& aOldStyle);
+  static nsCSSPropertyID GetCSSPropertyIdForAttrEnum(uint8_t aAttrEnum);
 
   // WebIDL
   already_AddRefed<DOMSVGAnimatedLength> Cx();
   already_AddRefed<DOMSVGAnimatedLength> Cy();
   already_AddRefed<DOMSVGAnimatedLength> R();
 
  protected:
   virtual LengthAttributesInfo GetLengthInfo() override;
--- a/dom/svg/SVGEllipseElement.cpp
+++ b/dom/svg/SVGEllipseElement.cpp
@@ -158,10 +158,27 @@ bool SVGEllipseElement::IsLengthChangedV
        *oldSVGReset = aOldStyle.StyleSVGReset();
 
   return newSVGReset->mCx != oldSVGReset->mCx ||
          newSVGReset->mCy != oldSVGReset->mCy ||
          newSVGReset->mRx != oldSVGReset->mRx ||
          newSVGReset->mRy != oldSVGReset->mRy;
 }
 
+nsCSSPropertyID SVGEllipseElement::GetCSSPropertyIdForAttrEnum(
+    uint8_t aAttrEnum) {
+  switch (aAttrEnum) {
+    case CX:
+      return eCSSProperty_cx;
+    case CY:
+      return eCSSProperty_cy;
+    case RX:
+      return eCSSProperty_rx;
+    case RY:
+      return eCSSProperty_ry;
+    default:
+      MOZ_ASSERT_UNREACHABLE("Unknown attr enum");
+      return eCSSProperty_UNKNOWN;
+  }
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/svg/SVGEllipseElement.h
+++ b/dom/svg/SVGEllipseElement.h
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGEllipseElement_h
 #define mozilla_dom_SVGEllipseElement_h
 
+#include "nsCSSPropertyID.h"
 #include "SVGAnimatedLength.h"
 #include "SVGGeometryElement.h"
 
 nsresult NS_NewSVGEllipseElement(
     nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 class ComputedStyle;
@@ -42,16 +43,17 @@ class SVGEllipseElement final : public S
       const Matrix& aToBoundsSpace,
       const Matrix* aToNonScalingStrokeSpace = nullptr) override;
   virtual already_AddRefed<Path> BuildPath(PathBuilder* aBuilder) override;
 
   virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
 
   static bool IsLengthChangedViaCSS(const ComputedStyle& aNewStyle,
                                     const ComputedStyle& aOldStyle);
+  static nsCSSPropertyID GetCSSPropertyIdForAttrEnum(uint8_t aAttrEnum);
 
   // WebIDL
   already_AddRefed<DOMSVGAnimatedLength> Cx();
   already_AddRefed<DOMSVGAnimatedLength> Cy();
   already_AddRefed<DOMSVGAnimatedLength> Rx();
   already_AddRefed<DOMSVGAnimatedLength> Ry();
 
  protected:
--- a/dom/svg/SVGForeignObjectElement.cpp
+++ b/dom/svg/SVGForeignObjectElement.cpp
@@ -130,10 +130,27 @@ SVGForeignObjectElement::IsAttributeMapp
 //----------------------------------------------------------------------
 // SVGElement methods
 
 SVGElement::LengthAttributesInfo SVGForeignObjectElement::GetLengthInfo() {
   return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
                               ArrayLength(sLengthInfo));
 }
 
+nsCSSPropertyID SVGForeignObjectElement::GetCSSPropertyIdForAttrEnum(
+    uint8_t aAttrEnum) {
+  switch (aAttrEnum) {
+    case ATTR_X:
+      return eCSSProperty_x;
+    case ATTR_Y:
+      return eCSSProperty_y;
+    case ATTR_WIDTH:
+      return eCSSProperty_width;
+    case ATTR_HEIGHT:
+      return eCSSProperty_height;
+    default:
+      MOZ_ASSERT_UNREACHABLE("Unknown attr enum");
+      return eCSSProperty_UNKNOWN;
+  }
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/svg/SVGForeignObjectElement.h
+++ b/dom/svg/SVGForeignObjectElement.h
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGForeignObjectElement_h
 #define mozilla_dom_SVGForeignObjectElement_h
 
 #include "mozilla/dom/SVGGraphicsElement.h"
+#include "nsCSSPropertyID.h"
 #include "SVGAnimatedLength.h"
 
 nsresult NS_NewSVGForeignObjectElement(
     nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
 
 class nsSVGForeignObjectFrame;
 
 namespace mozilla {
@@ -37,16 +38,18 @@ class SVGForeignObjectElement final : pu
       SVGTransformTypes aWhich = eAllTransforms) const override;
   virtual bool HasValidDimensions() const override;
 
   // nsIContent interface
   NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* name) const override;
 
   virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
 
+  static nsCSSPropertyID GetCSSPropertyIdForAttrEnum(uint8_t aAttrEnum);
+
   // WebIDL
   already_AddRefed<DOMSVGAnimatedLength> X();
   already_AddRefed<DOMSVGAnimatedLength> Y();
   already_AddRefed<DOMSVGAnimatedLength> Width();
   already_AddRefed<DOMSVGAnimatedLength> Height();
 
  protected:
   virtual LengthAttributesInfo GetLengthInfo() override;
new file mode 100644
--- /dev/null
+++ b/dom/svg/SVGGeometryProperty.cpp
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "SVGGeometryProperty.h"
+#include "SVGCircleElement.h"
+#include "SVGEllipseElement.h"
+#include "SVGForeignObjectElement.h"
+#include "SVGRectElement.h"
+
+namespace mozilla {
+namespace dom {
+namespace SVGGeometryProperty {
+
+nsCSSUnit SpecifiedUnitTypeToCSSUnit(uint8_t aSpecifiedUnit) {
+  switch (aSpecifiedUnit) {
+    case SVGLength_Binding::SVG_LENGTHTYPE_NUMBER:
+    case SVGLength_Binding::SVG_LENGTHTYPE_PX:
+      return nsCSSUnit::eCSSUnit_Pixel;
+
+    case SVGLength_Binding::SVG_LENGTHTYPE_MM:
+      return nsCSSUnit::eCSSUnit_Millimeter;
+
+    case SVGLength_Binding::SVG_LENGTHTYPE_CM:
+      return nsCSSUnit::eCSSUnit_Centimeter;
+
+    case SVGLength_Binding::SVG_LENGTHTYPE_IN:
+      return nsCSSUnit::eCSSUnit_Inch;
+
+    case SVGLength_Binding::SVG_LENGTHTYPE_PT:
+      return nsCSSUnit::eCSSUnit_Point;
+
+    case SVGLength_Binding::SVG_LENGTHTYPE_PC:
+      return nsCSSUnit::eCSSUnit_Pica;
+
+    case SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE:
+      return nsCSSUnit::eCSSUnit_Percent;
+
+    case SVGLength_Binding::SVG_LENGTHTYPE_EMS:
+      return nsCSSUnit::eCSSUnit_EM;
+
+    case SVGLength_Binding::SVG_LENGTHTYPE_EXS:
+      return nsCSSUnit::eCSSUnit_XHeight;
+
+    default:
+      MOZ_ASSERT_UNREACHABLE("Unknown unit type");
+      return nsCSSUnit::eCSSUnit_Pixel;
+  }
+}
+
+nsCSSPropertyID AttrEnumToCSSPropId(const SVGElement* aElement,
+                                    uint8_t aAttrEnum) {
+  // This is a very trivial function only applied to a few elements,
+  // so we want to avoid making it virtual.
+  if (aElement->IsSVGElement(nsGkAtoms::rect)) {
+    return SVGRectElement::GetCSSPropertyIdForAttrEnum(aAttrEnum);
+  }
+  if (aElement->IsSVGElement(nsGkAtoms::circle)) {
+    return SVGCircleElement::GetCSSPropertyIdForAttrEnum(aAttrEnum);
+  }
+  if (aElement->IsSVGElement(nsGkAtoms::ellipse)) {
+    return SVGEllipseElement::GetCSSPropertyIdForAttrEnum(aAttrEnum);
+  }
+  if (aElement->IsSVGElement(nsGkAtoms::foreignObject)) {
+    return SVGForeignObjectElement::GetCSSPropertyIdForAttrEnum(aAttrEnum);
+  }
+  return eCSSProperty_UNKNOWN;
+}
+
+}  // namespace SVGGeometryProperty
+}  // namespace dom
+}  // namespace mozilla
--- a/dom/svg/SVGGeometryProperty.h
+++ b/dom/svg/SVGGeometryProperty.h
@@ -143,13 +143,17 @@ bool ResolveAll(const SVGElement* aEleme
   if (nsIFrame const* f = aElement->GetPrimaryFrame()) {
     using dummy = int[];
     (void)dummy{0, (*aRes = ResolveWith<Tags>(*f->Style(), aElement), 0)...};
     return true;
   }
   return false;
 }
 
+nsCSSUnit SpecifiedUnitTypeToCSSUnit(uint8_t aSpecifiedUnit);
+nsCSSPropertyID AttrEnumToCSSPropId(const SVGElement* aElement,
+                                    uint8_t aAttrEnum);
+
 }  // namespace SVGGeometryProperty
 }  // namespace dom
 }  // namespace mozilla
 
 #endif
--- a/dom/svg/SVGRectElement.cpp
+++ b/dom/svg/SVGRectElement.cpp
@@ -236,10 +236,30 @@ bool SVGRectElement::IsLengthChangedViaC
   return newSVGReset->mX != oldSVGReset->mX ||
          newSVGReset->mY != oldSVGReset->mY ||
          newPosition->mWidth != oldPosition->mWidth ||
          newPosition->mHeight != oldPosition->mHeight ||
          newSVGReset->mRx != oldSVGReset->mRx ||
          newSVGReset->mRy != oldSVGReset->mRy;
 }
 
+nsCSSPropertyID SVGRectElement::GetCSSPropertyIdForAttrEnum(uint8_t aAttrEnum) {
+  switch (aAttrEnum) {
+    case ATTR_X:
+      return eCSSProperty_x;
+    case ATTR_Y:
+      return eCSSProperty_y;
+    case ATTR_WIDTH:
+      return eCSSProperty_width;
+    case ATTR_HEIGHT:
+      return eCSSProperty_height;
+    case ATTR_RX:
+      return eCSSProperty_rx;
+    case ATTR_RY:
+      return eCSSProperty_ry;
+    default:
+      MOZ_ASSERT_UNREACHABLE("Unknown attr enum");
+      return eCSSProperty_UNKNOWN;
+  }
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/svg/SVGRectElement.h
+++ b/dom/svg/SVGRectElement.h
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_SVGRectElement_h
 #define mozilla_dom_SVGRectElement_h
 
+#include "nsCSSPropertyID.h"
 #include "SVGAnimatedLength.h"
 #include "SVGGeometryElement.h"
 
 nsresult NS_NewSVGRectElement(
     nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
 
 namespace mozilla {
 class ComputedStyle;
@@ -43,16 +44,17 @@ class SVGRectElement final : public SVGR
   virtual void GetAsSimplePath(SimplePath* aSimplePath) override;
   virtual already_AddRefed<Path> BuildPath(
       PathBuilder* aBuilder = nullptr) override;
 
   virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
 
   static bool IsLengthChangedViaCSS(const ComputedStyle& aNewStyle,
                                     const ComputedStyle& aOldStyle);
+  static nsCSSPropertyID GetCSSPropertyIdForAttrEnum(uint8_t aAttrEnum);
 
   // WebIDL
   already_AddRefed<DOMSVGAnimatedLength> X();
   already_AddRefed<DOMSVGAnimatedLength> Y();
   already_AddRefed<DOMSVGAnimatedLength> Height();
   already_AddRefed<DOMSVGAnimatedLength> Width();
   already_AddRefed<DOMSVGAnimatedLength> Rx();
   already_AddRefed<DOMSVGAnimatedLength> Ry();
--- a/dom/svg/moz.build
+++ b/dom/svg/moz.build
@@ -176,16 +176,17 @@ UNIFIED_SOURCES += [
     'SVGFETileElement.cpp',
     'SVGFETurbulenceElement.cpp',
     'SVGFilterElement.cpp',
     'SVGFilters.cpp',
     'SVGForeignObjectElement.cpp',
     'SVGFragmentIdentifier.cpp',
     'SVGGElement.cpp',
     'SVGGeometryElement.cpp',
+    'SVGGeometryProperty.cpp',
     'SVGGradientElement.cpp',
     'SVGGraphicsElement.cpp',
     'SVGImageElement.cpp',
     'SVGIntegerPairSMILType.cpp',
     'SVGLength.cpp',
     'SVGLengthList.cpp',
     'SVGLengthListSMILType.cpp',
     'SVGLineElement.cpp',