Bug 1320014 Part 4 - Remove eNumCorners and rewrite NS_FOR_CSS_CORNERS. draft
authorTing-Yu Lin <tlin@mozilla.com>
Wed, 04 Jan 2017 17:41:49 +0800
changeset 456793 592e4eda357b7c524dbd8463395bd0a268c220df
parent 456792 f7f3d14892fde60e9f1e03d4df7590f7edf085fb
child 456794 f61867c3a933e7acd0f7d20856d934aeb96697db
push id40602
push userbmo:tlin@mozilla.com
push dateFri, 06 Jan 2017 07:30:30 +0000
bugs1320014
milestone53.0a1
Bug 1320014 Part 4 - Remove eNumCorners and rewrite NS_FOR_CSS_CORNERS. Also, change Corner's operator++ from postfix to prefix version. MozReview-Commit-ID: CpBXOZmQtJ9
gfx/2d/Types.h
gfx/thebes/gfxRect.h
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -416,33 +416,35 @@ static inline Side& operator++(Side& sid
   return side;
 }
 
 enum Corner {
   // This order is important!
   eCornerTopLeft = 0,
   eCornerTopRight = 1,
   eCornerBottomRight = 2,
-  eCornerBottomLeft = 3,
-  eNumCorners = 4
+  eCornerBottomLeft = 3
 };
 
 #define NS_CORNER_TOP_LEFT mozilla::eCornerTopLeft
 #define NS_CORNER_TOP_RIGHT mozilla::eCornerTopRight
 #define NS_CORNER_BOTTOM_RIGHT mozilla::eCornerBottomRight
 #define NS_CORNER_BOTTOM_LEFT mozilla::eCornerBottomLeft
-#define NS_NUM_CORNERS mozilla::eNumCorners
 
-#define NS_FOR_CSS_CORNERS(var_)                       \
-  for (mozilla::Corner var_ = NS_CORNER_TOP_LEFT;      \
-       var_ <= NS_CORNER_BOTTOM_LEFT;                  \
-       var_++)
+// Creates a for loop that walks over the four mozilla::Corner values. This
+// implementation uses the same technique as NS_FOR_CSS_SIDES.
+#define NS_FOR_CSS_CORNERS(var_)                                        \
+  int32_t MOZ_CONCAT(var_,__LINE__) = mozilla::eCornerTopLeft;          \
+  for (mozilla::Corner var_;                                            \
+       MOZ_CONCAT(var_,__LINE__) <= mozilla::eCornerBottomLeft &&       \
+         (var_ = mozilla::Corner(MOZ_CONCAT(var_,__LINE__)), true);     \
+       ++MOZ_CONCAT(var_,__LINE__))
 
-static inline Corner operator++(Corner& corner, int) {
-  MOZ_ASSERT(corner >= NS_CORNER_TOP_LEFT &&
-             corner < NS_NUM_CORNERS, "Out of range corner");
-  corner = Corner(corner + 1);
-  return corner;
+static inline Corner operator++(Corner& aCorner) {
+  MOZ_ASSERT(aCorner >= eCornerTopLeft && aCorner <= eCornerBottomLeft,
+             "Out of range corner!");
+  aCorner = Corner(aCorner + 1);
+  return aCorner;
 }
 
 } // namespace mozilla
 
 #endif /* MOZILLA_GFX_TYPES_H_ */
--- a/gfx/thebes/gfxRect.h
+++ b/gfx/thebes/gfxRect.h
@@ -46,19 +46,16 @@ struct gfxRect :
     bool WithinEpsilonOfIntegerPixels(gfxFloat aEpsilon) const;
 
     gfxPoint AtCorner(mozilla::Corner corner) const {
         switch (corner) {
             case NS_CORNER_TOP_LEFT: return TopLeft();
             case NS_CORNER_TOP_RIGHT: return TopRight();
             case NS_CORNER_BOTTOM_RIGHT: return BottomRight();
             case NS_CORNER_BOTTOM_LEFT: return BottomLeft();
-            default:
-                NS_ERROR("Invalid corner!");
-                break;
         }
         return gfxPoint(0.0, 0.0);
     }
 
     gfxPoint CCWCorner(mozilla::Side side) const {
         switch (side) {
             case mozilla::eSideTop: return TopLeft();
             case mozilla::eSideRight: return TopRight();