From 0a7f42b4524b4cdfb4f8aa64c9a3d04167c9d5ca Mon Sep 17 00:00:00 2001 From: Moonchild Date: Fri, 2 Aug 2024 04:50:01 +0200 Subject: [PATCH] Issue #1925 - Rewrite NS_FOR_CSS_CORNERS to be similar to *_SIDES - Renames it to NS_CSS_FULL_CORNERS and uses the one macro for all full corners. In preparation for giving half corners the same treatment. - Swaps to prefix operator++ --- gfx/2d/Types.h | 26 ++++++++++++++------------ gfx/thebes/gfxRect.h | 3 --- layout/base/nsCSSRenderingBorders.cpp | 4 ++-- layout/style/nsStyleConsts.h | 2 -- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/gfx/2d/Types.h b/gfx/2d/Types.h index 882b8991f6..211577e7ab 100644 --- a/gfx/2d/Types.h +++ b/gfx/2d/Types.h @@ -411,26 +411,28 @@ enum Corner { 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_FULL_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 mozilla::Corner operator++(mozilla::Corner& corner, int) { - MOZ_ASSERT(corner >= NS_CORNER_TOP_LEFT && - corner < NS_NUM_CORNERS, "Out of range corner"); - corner = mozilla::Corner(corner + 1); - return corner; +static inline mozilla::Corner operator++(mozilla::Corner& aCorner) { + MOZ_ASSERT(aCorner >= eCornerTopLeft && aCorner <= eCornerBottomLeft, + "Out of range corner!"); + aCorner = mozilla::Corner(aCorner + 1); + return aCorner; } } // namespace mozilla diff --git a/gfx/thebes/gfxRect.h b/gfx/thebes/gfxRect.h index 780b91f22c..dd0e500119 100644 --- a/gfx/thebes/gfxRect.h +++ b/gfx/thebes/gfxRect.h @@ -51,9 +51,6 @@ struct gfxRect : 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); } diff --git a/layout/base/nsCSSRenderingBorders.cpp b/layout/base/nsCSSRenderingBorders.cpp index e786cc5e0d..27758bcc0c 100644 --- a/layout/base/nsCSSRenderingBorders.cpp +++ b/layout/base/nsCSSRenderingBorders.cpp @@ -3385,7 +3385,7 @@ nsCSSBorderRenderer::DrawBorders() * a 1.0 unit border all around and no border radius. */ - NS_FOR_CSS_CORNERS(corner) { + NS_FOR_CSS_FULL_CORNERS(corner) { const mozilla::Side sides[2] = { mozilla::Side(corner), PREV_SIDE(corner) }; if (!IsZeroSize(mBorderRadii[corner])) @@ -3400,7 +3400,7 @@ nsCSSBorderRenderer::DrawBorders() } // First, the corners - NS_FOR_CSS_CORNERS(corner) { + NS_FOR_CSS_FULL_CORNERS(corner) { // if there's no corner, don't do all this work for it if (IsZeroSize(mBorderCornerDimensions[corner])) continue; diff --git a/layout/style/nsStyleConsts.h b/layout/style/nsStyleConsts.h index 90ead02e67..9465052321 100644 --- a/layout/style/nsStyleConsts.h +++ b/layout/style/nsStyleConsts.h @@ -16,8 +16,6 @@ namespace mozilla { -#define NS_FOR_CSS_FULL_CORNERS(var_) for (int32_t var_ = 0; var_ < 4; ++var_) - // Indices into "half corner" arrays (nsStyleCorners e.g.) #define NS_CORNER_TOP_LEFT_X 0 #define NS_CORNER_TOP_LEFT_Y 1