Bug 826961 - Revise SVGPreserveAspectRatio so that the silly cast is not needed. r=longsonr
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sun, 06 Jan 2013 02:28:00 +0900
changeset 117742 0b4ce0db7ecbc3ded6700ce9204fb4bc94896d67
parent 117741 9958b17acc012ffa71cfe1740389269a01fd94ba
child 117743 08a616b1e4f4b24d72ba731afc40521974246094
push id24110
push userphilringnalda@gmail.com
push dateSat, 05 Jan 2013 23:57:49 +0000
treeherdermozilla-central@20d1a5916ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslongsonr
bugs826961
milestone20.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 826961 - Revise SVGPreserveAspectRatio so that the silly cast is not needed. r=longsonr
content/svg/content/src/SVGAnimatedPreserveAspectRatio.h
content/svg/content/src/SVGContentUtils.cpp
content/svg/content/src/SVGPreserveAspectRatio.h
--- a/content/svg/content/src/SVGAnimatedPreserveAspectRatio.h
+++ b/content/svg/content/src/SVGAnimatedPreserveAspectRatio.h
@@ -14,17 +14,17 @@
 #include "SVGPreserveAspectRatio.h"
 #include "mozilla/Attributes.h"
 
 class nsISMILAnimationElement;
 class nsSMILValue;
 
 namespace mozilla {
 
-class SVGAnimatedPreserveAspectRatio
+class SVGAnimatedPreserveAspectRatio MOZ_FINAL
 {
 public:
   void Init() {
     mBaseVal.mAlign = SVG_PRESERVEASPECTRATIO_XMIDYMID;
     mBaseVal.mMeetOrSlice = SVG_MEETORSLICE_MEET;
     mBaseVal.mDefer = false;
     mAnimVal = mBaseVal;
     mIsAnimated = false;
@@ -39,27 +39,29 @@ public:
   void SetBaseValue(const SVGPreserveAspectRatio &aValue,
                     nsSVGElement *aSVGElement);
   nsresult SetBaseAlign(uint16_t aAlign, nsSVGElement *aSVGElement) {
     if (aAlign < SVG_PRESERVEASPECTRATIO_NONE ||
         aAlign > SVG_PRESERVEASPECTRATIO_XMAXYMAX) {
       return NS_ERROR_FAILURE;
     }
     SetBaseValue(SVGPreserveAspectRatio(
-                   aAlign, mBaseVal.GetMeetOrSlice(), mBaseVal.GetDefer()),
+                   static_cast<SVGAlign>(aAlign), mBaseVal.GetMeetOrSlice(),
+                   mBaseVal.GetDefer()),
                  aSVGElement);
     return NS_OK;
   }
   nsresult SetBaseMeetOrSlice(uint16_t aMeetOrSlice, nsSVGElement *aSVGElement) {
     if (aMeetOrSlice < SVG_MEETORSLICE_MEET ||
         aMeetOrSlice > SVG_MEETORSLICE_SLICE) {
       return NS_ERROR_FAILURE;
     }
     SetBaseValue(SVGPreserveAspectRatio(
-                   mBaseVal.GetAlign(), aMeetOrSlice, mBaseVal.GetDefer()),
+                   mBaseVal.GetAlign(), static_cast<SVGMeetOrSlice>(aMeetOrSlice),
+                   mBaseVal.GetDefer()),
                  aSVGElement);
     return NS_OK;
   }
   void SetAnimValue(uint64_t aPackedValue, nsSVGElement *aSVGElement);
 
   const SVGPreserveAspectRatio &GetBaseValue() const
     { return mBaseVal; }
   const SVGPreserveAspectRatio &GetAnimValue() const
--- a/content/svg/content/src/SVGContentUtils.cpp
+++ b/content/svg/content/src/SVGContentUtils.cpp
@@ -298,18 +298,18 @@ SVGContentUtils::GetViewBoxTransform(con
                                      float aViewboxWidth, float aViewboxHeight,
                                      const SVGPreserveAspectRatio &aPreserveAspectRatio)
 {
   NS_ASSERTION(aViewportWidth  >= 0, "viewport width must be nonnegative!");
   NS_ASSERTION(aViewportHeight >= 0, "viewport height must be nonnegative!");
   NS_ASSERTION(aViewboxWidth  > 0, "viewBox width must be greater than zero!");
   NS_ASSERTION(aViewboxHeight > 0, "viewBox height must be greater than zero!");
 
-  uint16_t align = aPreserveAspectRatio.GetAlign();
-  uint16_t meetOrSlice = aPreserveAspectRatio.GetMeetOrSlice();
+  SVGAlign align = aPreserveAspectRatio.GetAlign();
+  SVGMeetOrSlice meetOrSlice = aPreserveAspectRatio.GetMeetOrSlice();
 
   // default to the defaults
   if (align == SVG_PRESERVEASPECTRATIO_UNKNOWN)
     align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
   if (meetOrSlice == SVG_MEETORSLICE_UNKNOWN)
     meetOrSlice = SVG_MEETORSLICE_MEET;
 
   float a, d, e, f;
--- a/content/svg/content/src/SVGPreserveAspectRatio.h
+++ b/content/svg/content/src/SVGPreserveAspectRatio.h
@@ -7,93 +7,102 @@
 
 #include "nsWrapperCache.h"
 #include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/ErrorResult.h"
 
 class nsSVGElement;
 
+namespace mozilla {
 // Alignment Types
-static const unsigned short SVG_PRESERVEASPECTRATIO_UNKNOWN = 0;
-static const unsigned short SVG_PRESERVEASPECTRATIO_NONE = 1;
-static const unsigned short SVG_PRESERVEASPECTRATIO_XMINYMIN = 2;
-static const unsigned short SVG_PRESERVEASPECTRATIO_XMIDYMIN = 3;
-static const unsigned short SVG_PRESERVEASPECTRATIO_XMAXYMIN = 4;
-static const unsigned short SVG_PRESERVEASPECTRATIO_XMINYMID = 5;
-static const unsigned short SVG_PRESERVEASPECTRATIO_XMIDYMID = 6;
-static const unsigned short SVG_PRESERVEASPECTRATIO_XMAXYMID = 7;
-static const unsigned short SVG_PRESERVEASPECTRATIO_XMINYMAX = 8;
-static const unsigned short SVG_PRESERVEASPECTRATIO_XMIDYMAX = 9;
-static const unsigned short SVG_PRESERVEASPECTRATIO_XMAXYMAX = 10;
+enum SVGAlign MOZ_ENUM_TYPE(uint8_t) {
+  SVG_PRESERVEASPECTRATIO_UNKNOWN = 0,
+  SVG_PRESERVEASPECTRATIO_NONE = 1,
+  SVG_PRESERVEASPECTRATIO_XMINYMIN = 2,
+  SVG_PRESERVEASPECTRATIO_XMIDYMIN = 3,
+  SVG_PRESERVEASPECTRATIO_XMAXYMIN = 4,
+  SVG_PRESERVEASPECTRATIO_XMINYMID = 5,
+  SVG_PRESERVEASPECTRATIO_XMIDYMID = 6,
+  SVG_PRESERVEASPECTRATIO_XMAXYMID = 7,
+  SVG_PRESERVEASPECTRATIO_XMINYMAX = 8,
+  SVG_PRESERVEASPECTRATIO_XMIDYMAX = 9,
+  SVG_PRESERVEASPECTRATIO_XMAXYMAX = 10
+};
 
 // Meet-or-slice Types
-static const unsigned short SVG_MEETORSLICE_UNKNOWN = 0;
-static const unsigned short SVG_MEETORSLICE_MEET = 1;
-static const unsigned short SVG_MEETORSLICE_SLICE = 2;
+enum SVGMeetOrSlice MOZ_ENUM_TYPE(uint8_t) {
+  SVG_MEETORSLICE_UNKNOWN = 0,
+  SVG_MEETORSLICE_MEET = 1,
+  SVG_MEETORSLICE_SLICE = 2
+};
 
-namespace mozilla {
 class SVGAnimatedPreserveAspectRatio;
 
-class SVGPreserveAspectRatio
+class SVGPreserveAspectRatio MOZ_FINAL
 {
   friend class SVGAnimatedPreserveAspectRatio;
 public:
-  SVGPreserveAspectRatio(uint16_t aAlign, uint16_t aMeetOrSlice, bool aDefer = false)
-    : mAlign(static_cast<uint8_t>(aAlign))
-    , mMeetOrSlice(static_cast<uint8_t>(aMeetOrSlice))
+  SVGPreserveAspectRatio(SVGAlign aAlign, SVGMeetOrSlice aMeetOrSlice,
+                         bool aDefer = false)
+    : mAlign(aAlign)
+    , mMeetOrSlice(aMeetOrSlice)
     , mDefer(aDefer)
   {}
 
   bool operator==(const SVGPreserveAspectRatio& aOther) const;
 
   explicit SVGPreserveAspectRatio()
-    : mAlign(0)
-    , mMeetOrSlice(0)
+    : mAlign(SVG_PRESERVEASPECTRATIO_UNKNOWN)
+    , mMeetOrSlice(SVG_MEETORSLICE_UNKNOWN)
     , mDefer(false)
   {}
 
   nsresult SetAlign(uint16_t aAlign) {
     if (aAlign < SVG_PRESERVEASPECTRATIO_NONE ||
         aAlign > SVG_PRESERVEASPECTRATIO_XMAXYMAX)
       return NS_ERROR_FAILURE;
     mAlign = static_cast<uint8_t>(aAlign);
     return NS_OK;
   }
 
-  uint16_t GetAlign() const {
-    return mAlign;
+  SVGAlign GetAlign() const {
+    return static_cast<SVGAlign>(mAlign);
   }
 
   nsresult SetMeetOrSlice(uint16_t aMeetOrSlice) {
     if (aMeetOrSlice < SVG_MEETORSLICE_MEET ||
         aMeetOrSlice > SVG_MEETORSLICE_SLICE)
       return NS_ERROR_FAILURE;
     mMeetOrSlice = static_cast<uint8_t>(aMeetOrSlice);
     return NS_OK;
   }
 
-  uint16_t GetMeetOrSlice() const {
-    return mMeetOrSlice;
+  SVGMeetOrSlice GetMeetOrSlice() const {
+    return static_cast<SVGMeetOrSlice>(mMeetOrSlice);
   }
 
   void SetDefer(bool aDefer) {
     mDefer = aDefer;
   }
 
   bool GetDefer() const {
     return mDefer;
   }
 
 private:
+  // We can't use enum types here because some compilers fail to pack them.
   uint8_t mAlign;
   uint8_t mMeetOrSlice;
   bool mDefer;
 };
 
+MOZ_STATIC_ASSERT(sizeof(SVGPreserveAspectRatio) <= 4,
+                  "The compiler didn't pack SVGPreserveAspectRatio well");
+
 namespace dom {
 
 class DOMSVGPreserveAspectRatio MOZ_FINAL : public nsISupports,
                                             public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGPreserveAspectRatio)