Bug 1320014 Part 8 - Move NS_FOR_CSS_HALF_CORNERS to Types.h and rewrite it. draft
authorTing-Yu Lin <tlin@mozilla.com>
Thu, 05 Jan 2017 12:03:23 +0800
changeset 456797 10110c743a6115886887c29c91c0ab4c422c9a63
parent 456796 e374ed787dbfda0e072cf7da3dbbf5c4bd8e5ead
child 456798 eca9529f16e547446250327ce1a28192982b0028
push id40602
push userbmo:tlin@mozilla.com
push dateFri, 06 Jan 2017 07:30:30 +0000
bugs1320014
milestone53.0a1
Bug 1320014 Part 8 - Move NS_FOR_CSS_HALF_CORNERS to Types.h and rewrite it. MozReview-Commit-ID: 5UkZUSe5stP
gfx/2d/Types.h
layout/style/nsStyleConsts.h
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -448,11 +448,27 @@ enum HalfCorner {
   eCornerTopRightX = 2,
   eCornerTopRightY = 3,
   eCornerBottomRightX = 4,
   eCornerBottomRightY = 5,
   eCornerBottomLeftX = 6,
   eCornerBottomLeftY = 7
 };
 
+// Creates a for loop that walks over the eight mozilla::HalfCorner values.
+// This implementation uses the same technique as NS_FOR_CSS_SIDES.
+#define NS_FOR_CSS_HALF_CORNERS(var_)                                   \
+  int32_t MOZ_CONCAT(var_,__LINE__) = mozilla::eCornerTopLeftX;         \
+  for (mozilla::HalfCorner var_;                                        \
+       MOZ_CONCAT(var_,__LINE__) <= mozilla::eCornerBottomLeftY &&      \
+         (var_ = mozilla::HalfCorner(MOZ_CONCAT(var_,__LINE__)), true); \
+       ++MOZ_CONCAT(var_,__LINE__))
+
+static inline HalfCorner operator++(HalfCorner& aHalfCorner) {
+  MOZ_ASSERT(aHalfCorner >= eCornerTopLeftX && aHalfCorner <= eCornerBottomLeftY,
+             "Out of range half corner!");
+  aHalfCorner = HalfCorner(aHalfCorner + 1);
+  return aHalfCorner;
+}
+
 } // namespace mozilla
 
 #endif /* MOZILLA_GFX_TYPES_H_ */
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -11,18 +11,16 @@
 #include "gfxRect.h"
 #include "nsFont.h"
 #include "X11UndefineNone.h"
 
 // XXX fold this into nsStyleContext and group by nsStyleXXX struct
 
 namespace mozilla {
 
-#define NS_FOR_CSS_HALF_CORNERS(var_) for (int32_t var_ = 0; var_ < 8; ++var_)
-
 // The results of these conversion macros are exhaustively checked in
 // nsStyleCoord.cpp.
 // Arguments must not have side effects.
 
 #define NS_HALF_CORNER_IS_X(var_) (!((var_)%2))
 #define NS_HALF_TO_FULL_CORNER(var_) ((var_)/2)
 #define NS_FULL_TO_HALF_CORNER(var_, vert_) ((var_)*2 + !!(vert_))