Bug 1320014 Part 8 - Move NS_FOR_CSS_HALF_CORNERS to Types.h and rewrite it.
MozReview-Commit-ID: 5UkZUSe5stP
--- 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_))