Bug 1288383 - Replace NS_STYLE_CLIP_PATH_* with an enum class draft
authorManish Goregaokar <manishearth@gmail.com>
Thu, 21 Jul 2016 19:31:55 +0530
changeset 390611 9c9444e6c32364bc8bca3aa305eb42195980c1c4
parent 390029 d224fc999cb6accb208af0a105f14433375e2e77
child 390612 fa0a48c26e966dfdb63e80707088cccb20ec5974
push id23712
push usermanishearth@gmail.com
push dateThu, 21 Jul 2016 14:21:10 +0000
bugs1288383
milestone50.0a1
Bug 1288383 - Replace NS_STYLE_CLIP_PATH_* with an enum class MozReview-Commit-ID: DELnXwqF4b5
layout/style/StyleAnimationValue.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsStyleConsts.h
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
layout/svg/nsCSSClipPathInstance.cpp
layout/svg/nsSVGEffects.cpp
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -3944,42 +3944,42 @@ StyleAnimationValue::ExtractComputedValu
           break;
         }
 #endif
 
         case eCSSProperty_clip_path: {
           const nsStyleSVGReset* svgReset =
             static_cast<const nsStyleSVGReset*>(styleStruct);
           const nsStyleClipPath& clipPath = svgReset->mClipPath;
-          const int32_t type = clipPath.GetType();
-
-          if (type == NS_STYLE_CLIP_PATH_URL) {
+          const mozilla::StyleClipPathType type = clipPath.GetType();
+
+          if (type == mozilla::StyleClipPathType::Url) {
             nsIDocument* doc = aStyleContext->PresContext()->Document();
             RefPtr<nsStringBuffer> uriAsStringBuffer =
               GetURIAsUtf16StringBuffer(clipPath.GetURL());
             RefPtr<mozilla::css::URLValue> url =
               new mozilla::css::URLValue(clipPath.GetURL(),
                                          uriAsStringBuffer,
                                          doc->GetDocumentURI(),
                                          doc->NodePrincipal());
             auto result = MakeUnique<nsCSSValue>();
             result->SetURLValue(url);
             aComputedValue.SetAndAdoptCSSValueValue(result.release(), eUnit_URL);
-          } else if (type == NS_STYLE_CLIP_PATH_BOX) {
+          } else if (type == mozilla::StyleClipPathType::Box) {
             aComputedValue.SetIntValue(uint8_t(clipPath.GetSizingBox()),
                                        eUnit_Enumerated);
-          } else if (type == NS_STYLE_CLIP_PATH_SHAPE) {
+          } else if (type == mozilla::StyleClipPathType::Shape) {
             RefPtr<nsCSSValue::Array> result = nsCSSValue::Array::Create(2);
             if (!StyleClipBasicShapeToCSSArray(clipPath, result)) {
               return false;
             }
             aComputedValue.SetCSSValueArrayValue(result, eUnit_Shape);
 
           } else {
-            MOZ_ASSERT(type == NS_STYLE_CLIP_PATH_NONE, "unknown type");
+            MOZ_ASSERT(type == mozilla::StyleClipPathType::None, "unknown type");
             aComputedValue.SetNoneValue();
           }
           break;
         }
 
         case eCSSProperty_filter: {
           const nsStyleEffects* effects =
             static_cast<const nsStyleEffects*>(styleStruct);
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -6000,28 +6000,28 @@ nsComputedDOMStyle::CreatePrimitiveValue
   return valueList.forget();
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetClipPath()
 {
   const nsStyleSVGReset* svg = StyleSVGReset();
   switch (svg->mClipPath.GetType()) {
-    case NS_STYLE_CLIP_PATH_SHAPE:
+    case mozilla::StyleClipPathType::Shape:
       return CreatePrimitiveValueForClipPath(svg->mClipPath.GetBasicShape(),
                                              svg->mClipPath.GetSizingBox());
-    case NS_STYLE_CLIP_PATH_BOX:
+    case mozilla::StyleClipPathType::Box:
       return CreatePrimitiveValueForClipPath(nullptr,
                                              svg->mClipPath.GetSizingBox());
-    case NS_STYLE_CLIP_PATH_URL: {
+    case mozilla::StyleClipPathType::Url: {
       RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
       val->SetURI(svg->mClipPath.GetURL());
       return val.forget();
     }
-    case NS_STYLE_CLIP_PATH_NONE: {
+    case mozilla::StyleClipPathType::None: {
       RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
       val->SetIdent(eCSSKeyword_none);
       return val.forget();
     }
     default:
       NS_NOTREACHED("unexpected type");
   }
   return nullptr;
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -67,16 +67,24 @@ enum class StyleClipShapeSizing : uint8_
     Padding,
     Border,
     Margin,
     Fill,
     Stroke,
     View,
 };
 
+// clip-path type
+enum class StyleClipPathType : uint8_t {
+  None,
+  Url,
+  Shape,
+  Box,
+};
+
 // Basic Shapes
 #define NS_STYLE_BASIC_SHAPE_POLYGON       0
 #define NS_STYLE_BASIC_SHAPE_CIRCLE        1
 #define NS_STYLE_BASIC_SHAPE_ELLIPSE       2
 #define NS_STYLE_BASIC_SHAPE_INSET         3
 
 // box-shadow
 #define NS_STYLE_BOX_SHADOW_INSET         0
@@ -558,22 +566,16 @@ enum class FillMode : uint32_t;
 
 // See nsStyleDisplay
 #define NS_STYLE_FLOAT_NONE                     0
 #define NS_STYLE_FLOAT_LEFT                     1
 #define NS_STYLE_FLOAT_RIGHT                    2
 #define NS_STYLE_FLOAT_INLINE_START             3
 #define NS_STYLE_FLOAT_INLINE_END               4
 
-// See nsStyleClipPath
-#define NS_STYLE_CLIP_PATH_NONE                 0
-#define NS_STYLE_CLIP_PATH_URL                  1
-#define NS_STYLE_CLIP_PATH_SHAPE                2
-#define NS_STYLE_CLIP_PATH_BOX                  3
-
 // See nsStyleFilter
 #define NS_STYLE_FILTER_NONE                    0
 #define NS_STYLE_FILTER_URL                     1
 #define NS_STYLE_FILTER_BLUR                    2
 #define NS_STYLE_FILTER_BRIGHTNESS              3
 #define NS_STYLE_FILTER_CONTRAST                4
 #define NS_STYLE_FILTER_GRAYSCALE               5
 #define NS_STYLE_FILTER_INVERT                  6
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -1000,124 +1000,124 @@ nsStyleBasicShape::GetShapeTypeName() co
   NS_NOTREACHED("unexpected type");
   return eCSSKeyword_UNKNOWN;
 }
 
 // --------------------
 // nsStyleClipPath
 //
 nsStyleClipPath::nsStyleClipPath()
-  : mType(NS_STYLE_CLIP_PATH_NONE)
+  : mType(mozilla::StyleClipPathType::None)
   , mURL(nullptr)
   , mSizingBox(mozilla::StyleClipShapeSizing::NoBox)
 {
 }
 
 nsStyleClipPath::nsStyleClipPath(const nsStyleClipPath& aSource)
-  : mType(NS_STYLE_CLIP_PATH_NONE)
+  : mType(mozilla::StyleClipPathType::None)
   , mURL(nullptr)
   , mSizingBox(mozilla::StyleClipShapeSizing::NoBox)
 {
-  if (aSource.mType == NS_STYLE_CLIP_PATH_URL) {
+  if (aSource.mType == mozilla::StyleClipPathType::Url) {
     SetURL(aSource.mURL);
-  } else if (aSource.mType == NS_STYLE_CLIP_PATH_SHAPE) {
+  } else if (aSource.mType == mozilla::StyleClipPathType::Shape) {
     SetBasicShape(aSource.mBasicShape, aSource.mSizingBox);
-  } else if (aSource.mType == NS_STYLE_CLIP_PATH_BOX) {
+  } else if (aSource.mType == mozilla::StyleClipPathType::Box) {
     SetSizingBox(aSource.mSizingBox);
   }
 }
 
 nsStyleClipPath::~nsStyleClipPath()
 {
   ReleaseRef();
 }
 
 nsStyleClipPath&
 nsStyleClipPath::operator=(const nsStyleClipPath& aOther)
 {
   if (this == &aOther) {
     return *this;
   }
 
-  if (aOther.mType == NS_STYLE_CLIP_PATH_URL) {
+  if (aOther.mType == mozilla::StyleClipPathType::Url) {
     SetURL(aOther.mURL);
-  } else if (aOther.mType == NS_STYLE_CLIP_PATH_SHAPE) {
+  } else if (aOther.mType == mozilla::StyleClipPathType::Shape) {
     SetBasicShape(aOther.mBasicShape, aOther.mSizingBox);
-  } else if (aOther.mType == NS_STYLE_CLIP_PATH_BOX) {
+  } else if (aOther.mType == mozilla::StyleClipPathType::Box) {
     SetSizingBox(aOther.mSizingBox);
   } else {
     ReleaseRef();
     mSizingBox = mozilla::StyleClipShapeSizing::NoBox;
-    mType = NS_STYLE_CLIP_PATH_NONE;
+    mType = mozilla::StyleClipPathType::None;
   }
   return *this;
 }
 
 bool
 nsStyleClipPath::operator==(const nsStyleClipPath& aOther) const
 {
   if (mType != aOther.mType) {
     return false;
   }
 
-  if (mType == NS_STYLE_CLIP_PATH_URL) {
+  if (mType == mozilla::StyleClipPathType::Url) {
     return EqualURIs(mURL, aOther.mURL);
-  } else if (mType == NS_STYLE_CLIP_PATH_SHAPE) {
+  } else if (mType == mozilla::StyleClipPathType::Shape) {
     return *mBasicShape == *aOther.mBasicShape &&
            mSizingBox == aOther.mSizingBox;
-  } else if (mType == NS_STYLE_CLIP_PATH_BOX) {
+  } else if (mType == mozilla::StyleClipPathType::Box) {
     return mSizingBox == aOther.mSizingBox;
   }
 
   return true;
 }
 
 void
 nsStyleClipPath::ReleaseRef()
 {
-  if (mType == NS_STYLE_CLIP_PATH_SHAPE) {
+  if (mType == mozilla::StyleClipPathType::Shape) {
     NS_ASSERTION(mBasicShape, "expected pointer");
     mBasicShape->Release();
-  } else if (mType == NS_STYLE_CLIP_PATH_URL) {
+  } else if (mType == mozilla::StyleClipPathType::Url) {
     NS_ASSERTION(mURL, "expected pointer");
     mURL->Release();
   }
   // mBasicShap, mURL, etc. are all pointers in a union of pointers. Nulling
   // one of them nulls all of them:
   mURL = nullptr;
 }
 
 void
 nsStyleClipPath::SetURL(nsIURI* aURL)
 {
   NS_ASSERTION(aURL, "expected pointer");
   ReleaseRef();
   mURL = aURL;
   mURL->AddRef();
-  mType = NS_STYLE_CLIP_PATH_URL;
+  mType = mozilla::StyleClipPathType::Url;
 }
 
 void
 nsStyleClipPath::SetBasicShape(nsStyleBasicShape* aBasicShape,
                                mozilla::StyleClipShapeSizing aSizingBox)
 {
   NS_ASSERTION(aBasicShape, "expected pointer");
   ReleaseRef();
   mBasicShape = aBasicShape;
   mBasicShape->AddRef();
   mSizingBox = aSizingBox;
-  mType = NS_STYLE_CLIP_PATH_SHAPE;
+  mType = mozilla::StyleClipPathType::Shape;
 }
 
 void
 nsStyleClipPath::SetSizingBox(mozilla::StyleClipShapeSizing aSizingBox)
 {
   ReleaseRef();
   mSizingBox = aSizingBox;
-  mType = NS_STYLE_CLIP_PATH_BOX;
+  mType = mozilla::StyleClipPathType::Box;
 }
 
 // --------------------
 // nsStyleFilter
 //
 nsStyleFilter::nsStyleFilter()
   : mType(NS_STYLE_FILTER_NONE)
   , mDropShadow(nullptr)
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -3501,43 +3501,43 @@ struct nsStyleClipPath
 
   nsStyleClipPath& operator=(const nsStyleClipPath& aOther);
 
   bool operator==(const nsStyleClipPath& aOther) const;
   bool operator!=(const nsStyleClipPath& aOther) const {
     return !(*this == aOther);
   }
 
-  int32_t GetType() const {
+  mozilla::StyleClipPathType GetType() const {
     return mType;
   }
 
   nsIURI* GetURL() const {
-    NS_ASSERTION(mType == NS_STYLE_CLIP_PATH_URL, "wrong clip-path type");
+    NS_ASSERTION(mType == mozilla::StyleClipPathType::Url, "wrong clip-path type");
     return mURL;
   }
   void SetURL(nsIURI* aURL);
 
   nsStyleBasicShape* GetBasicShape() const {
-    NS_ASSERTION(mType == NS_STYLE_CLIP_PATH_SHAPE, "wrong clip-path type");
+    NS_ASSERTION(mType == mozilla::StyleClipPathType::Shape, "wrong clip-path type");
     return mBasicShape;
   }
 
   void SetBasicShape(nsStyleBasicShape* mBasicShape,
                      mozilla::StyleClipShapeSizing aSizingBox =
                      mozilla::StyleClipShapeSizing::NoBox);
 
   mozilla::StyleClipShapeSizing GetSizingBox() const { return mSizingBox; }
   void SetSizingBox(mozilla::StyleClipShapeSizing aSizingBox);
 
 private:
   void ReleaseRef();
   void* operator new(size_t) = delete;
 
-  int32_t mType; // see NS_STYLE_CLIP_PATH_* constants in nsStyleConsts.h
+  mozilla::StyleClipPathType mType;
   union {
     nsStyleBasicShape* mBasicShape;
     nsIURI* mURL;
   };
   mozilla::StyleClipShapeSizing mSizingBox;
 };
 
 struct nsStyleFilter
@@ -3620,17 +3620,17 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
     // CalcDifference never returns the reflow hints that are sometimes
     // handled for descendants as hints not handled for descendants.
     return nsChangeHint_NeedReflow |
            nsChangeHint_ReflowChangesSizeOrPosition |
            nsChangeHint_ClearAncestorIntrinsics;
   }
 
   bool HasClipPath() const {
-    return mClipPath.GetType() != NS_STYLE_CLIP_PATH_NONE;
+    return mClipPath.GetType() != mozilla::StyleClipPathType::None;
   }
 
   bool HasNonScalingStroke() const {
     return mVectorEffect == NS_STYLE_VECTOR_EFFECT_NON_SCALING_STROKE;
   }
 
   nsStyleImageLayers    mMask;
   nsStyleClipPath  mClipPath;         // [reset]
--- a/layout/svg/nsCSSClipPathInstance.cpp
+++ b/layout/svg/nsCSSClipPathInstance.cpp
@@ -19,20 +19,20 @@ using namespace mozilla;
 using namespace mozilla::gfx;
 
 /* static*/ void
 nsCSSClipPathInstance::ApplyBasicShapeClip(gfxContext& aContext,
                                            nsIFrame* aFrame)
 {
   auto& clipPathStyle = aFrame->StyleSVGReset()->mClipPath;
   int32_t type = clipPathStyle.GetType();
-  MOZ_ASSERT(type != NS_STYLE_CLIP_PATH_NONE, "unexpected none value");
+  MOZ_ASSERT(type != mozilla::StyleClipPathType::None, "unexpected none value");
   // In the future nsCSSClipPathInstance may handle <clipPath> references as
   // well. For the time being return early.
-  if (type == NS_STYLE_CLIP_PATH_URL) {
+  if (type == mozilla::StyleClipPathType::Url) {
     return;
   }
 
   nsCSSClipPathInstance instance(aFrame, clipPathStyle);
 
   aContext.NewPath();
   RefPtr<Path> path = instance.CreateClipPath(aContext.GetDrawTarget());
   aContext.SetPath(path);
@@ -40,20 +40,20 @@ nsCSSClipPathInstance::ApplyBasicShapeCl
 }
 
 /* static*/ bool
 nsCSSClipPathInstance::HitTestBasicShapeClip(nsIFrame* aFrame,
                                              const gfxPoint& aPoint)
 {
   auto& clipPathStyle = aFrame->StyleSVGReset()->mClipPath;
   int32_t type = clipPathStyle.GetType();
-  MOZ_ASSERT(type != NS_STYLE_CLIP_PATH_NONE, "unexpected none value");
+  MOZ_ASSERT(type != mozilla::StyleClipPathType::None, "unexpected none value");
   // In the future nsCSSClipPathInstance may handle <clipPath> references as
   // well. For the time being return early.
-  if (type == NS_STYLE_CLIP_PATH_URL) {
+  if (type == mozilla::StyleClipPathType::Url) {
     return false;
   }
 
   nsCSSClipPathInstance instance(aFrame, clipPathStyle);
 
   RefPtr<DrawTarget> drawTarget =
     gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
   RefPtr<Path> path = instance.CreateClipPath(drawTarget);
@@ -76,17 +76,17 @@ nsCSSClipPathInstance::CreateClipPath(Dr
       break;
     case StyleClipShapeSizing::Margin:
       r = mTargetFrame->GetMarginRectRelativeToSelf();
       break;
     default: // Use the border box
       r = mTargetFrame->GetRectRelativeToSelf();
   }
 
-  if (mClipPathStyle.GetType() != NS_STYLE_CLIP_PATH_SHAPE) {
+  if (mClipPathStyle.GetType() != mozilla::StyleClipPathType::Shape) {
     // TODO Clip to border-radius/reference box if no shape
     // was specified.
     RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
     return builder->Finish();
   }
 
   nscoord appUnitsPerDevPixel =
     mTargetFrame->PresContext()->AppUnitsPerDevPixel();
--- a/layout/svg/nsSVGEffects.cpp
+++ b/layout/svg/nsSVGEffects.cpp
@@ -566,17 +566,17 @@ nsSVGEffects::GetEffectProperties(nsIFra
 {
   NS_ASSERTION(!aFrame->GetPrevContinuation(), "aFrame should be first continuation");
 
   EffectProperties result;
   const nsStyleSVGReset *style = aFrame->StyleSVGReset();
 
   result.mFilter = GetOrCreateFilterProperty(aFrame);
 
-  if (style->mClipPath.GetType() == NS_STYLE_CLIP_PATH_URL) {
+  if (style->mClipPath.GetType() == mozilla::StyleClipPathType::Url) {
     result.mClipPath =
       GetPaintingProperty(style->mClipPath.GetURL(), aFrame, ClipPathProperty());
   } else {
     result.mClipPath = nullptr;
   }
 
   MOZ_ASSERT(style->mMask.mImageCount > 0);
   result.mMask = style->mMask.HasLayerWithImage()