From 5b0921df6ed71a788787128b3abed67c028aff80 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 1 Aug 2024 16:11:48 +0200 Subject: [PATCH] Issue #1925 - Move NS_FOR_CSS_SIDES and operator++ to gfx/2d/Types.h --- gfx/2d/Types.h | 28 ++++++++++++++++++++++++++-- layout/style/nsStyleConsts.h | 22 ---------------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/gfx/2d/Types.h b/gfx/2d/Types.h index 3cdf077b11..6dfd2b4054 100644 --- a/gfx/2d/Types.h +++ b/gfx/2d/Types.h @@ -7,6 +7,8 @@ #define MOZILLA_GFX_TYPES_H_ #include "mozilla/EndianUtils.h" +#include "mozilla/MacroArgs.h" // for MOZ_CONCAT +#include "nsDebug.h" #include #include @@ -387,11 +389,33 @@ enum SideBits { eSideBitsAll = eSideBitsTopBottom | eSideBitsLeftRight }; -} // namespace mozilla - #define NS_SIDE_TOP mozilla::eSideTop #define NS_SIDE_RIGHT mozilla::eSideRight #define NS_SIDE_BOTTOM mozilla::eSideBottom #define NS_SIDE_LEFT mozilla::eSideLeft +namespace css { +typedef mozilla::Side Side; +} // namespace css + +// Creates a for loop that walks over the four mozilla::css::Side values. +// We use an int32_t helper variable (instead of a Side) for our loop counter, +// to avoid triggering undefined behavior just before we exit the loop (at +// which point the counter is incremented beyond the largest valid Side value). +#define NS_FOR_CSS_SIDES(var_) \ + int32_t MOZ_CONCAT(var_,__LINE__) = NS_SIDE_TOP; \ + for (mozilla::css::Side var_; \ + MOZ_CONCAT(var_,__LINE__) <= NS_SIDE_LEFT && \ + ((var_ = mozilla::css::Side(MOZ_CONCAT(var_,__LINE__))), true); \ + MOZ_CONCAT(var_,__LINE__)++) + +static inline css::Side operator++(css::Side& side, int) { + NS_PRECONDITION(side >= NS_SIDE_TOP && + side <= NS_SIDE_LEFT, "Out of range side"); + side = css::Side(side + 1); + return side; +} + +} // namespace mozilla + #endif /* MOZILLA_GFX_TYPES_H_ */ diff --git a/layout/style/nsStyleConsts.h b/layout/style/nsStyleConsts.h index e9063b595e..90ead02e67 100644 --- a/layout/style/nsStyleConsts.h +++ b/layout/style/nsStyleConsts.h @@ -10,33 +10,11 @@ #include "gfxRect.h" #include "nsFont.h" -#include "mozilla/MacroArgs.h" // for MOZ_CONCAT #include "X11UndefineNone.h" // XXX fold this into nsStyleContext and group by nsStyleXXX struct namespace mozilla { -namespace css { -typedef mozilla::Side Side; -} // namespace css - -// Creates a for loop that walks over the four mozilla::css::Side values. -// We use an int32_t helper variable (instead of a Side) for our loop counter, -// to avoid triggering undefined behavior just before we exit the loop (at -// which point the counter is incremented beyond the largest valid Side value). -#define NS_FOR_CSS_SIDES(var_) \ - int32_t MOZ_CONCAT(var_,__LINE__) = NS_SIDE_TOP; \ - for (mozilla::css::Side var_; \ - MOZ_CONCAT(var_,__LINE__) <= NS_SIDE_LEFT && \ - ((var_ = mozilla::css::Side(MOZ_CONCAT(var_,__LINE__))), true); \ - MOZ_CONCAT(var_,__LINE__)++) - -static inline css::Side operator++(css::Side& side, int) { - NS_PRECONDITION(side >= NS_SIDE_TOP && - side <= NS_SIDE_LEFT, "Out of range side"); - side = css::Side(side + 1); - return side; -} #define NS_FOR_CSS_FULL_CORNERS(var_) for (int32_t var_ = 0; var_ < 4; ++var_)