mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1610670 - Add AllPhysicalHalfCorners() to support range-based for loops. r=mats
This patch is generated via: 1. Manually modify gfx/2d/Types.h 2. Run the following script and clang-format. 3. Add brackets for the for loop in nsCSSRendering.cpp. ``` function rename() { echo "Renaming $1 to $2" rg -l "$1" | xargs sed -i -E -e s/"$1"/"$2"/g } rename "NS_FOR_CSS_HALF_CORNERS\(i\)" "for (const auto i : mozilla::AllPhysicalHalfCorners())" rename "NS_FOR_CSS_HALF_CORNERS\(corner\)" "for (const auto corner : mozilla::AllPhysicalHalfCorners())" ``` Differential Revision: https://phabricator.services.mozilla.com/D61252 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
b19983c13e
commit
22ea8326d7
@ -564,23 +564,9 @@ enum HalfCorner : uint8_t {
|
||||
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 && \
|
||||
(static_cast<void>( \
|
||||
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;
|
||||
constexpr auto AllPhysicalHalfCorners() {
|
||||
return mozilla::MakeInclusiveEnumeratedRange(eCornerTopLeftX,
|
||||
eCornerBottomLeftY);
|
||||
}
|
||||
|
||||
// The result of these conversion functions are exhaustively checked in
|
||||
|
@ -7194,7 +7194,7 @@ static bool NonZeroCorner(const LengthPercentage& aLength) {
|
||||
|
||||
/* static */
|
||||
bool nsLayoutUtils::HasNonZeroCorner(const BorderRadius& aCorners) {
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) {
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
if (NonZeroCorner(aCorners.Get(corner))) return true;
|
||||
}
|
||||
return false;
|
||||
@ -7239,7 +7239,7 @@ bool nsLayoutUtils::HasNonZeroCornerOnSide(const BorderRadius& aCorners,
|
||||
static_assert(eCornerBottomLeftY / 2 == eCornerBottomLeft,
|
||||
"Check for Non Zero on side");
|
||||
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) {
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
// corner is a "half corner" value, so dividing by two gives us a
|
||||
// "full corner" value.
|
||||
if (NonZeroCorner(aCorners.Get(corner)) &&
|
||||
|
@ -1815,7 +1815,7 @@ bool nsIFrame::ComputeBorderRadii(const BorderRadius& aBorderRadius,
|
||||
const nsSize& aBorderArea, Sides aSkipSides,
|
||||
nscoord aRadii[8]) {
|
||||
// Percentages are relative to whichever side they're on.
|
||||
NS_FOR_CSS_HALF_CORNERS(i) {
|
||||
for (const auto i : mozilla::AllPhysicalHalfCorners()) {
|
||||
const LengthPercentage& c = aBorderRadius.Get(i);
|
||||
nscoord axis = HalfCornerIsX(i) ? aFrameSize.width : aFrameSize.height;
|
||||
aRadii[i] = std::max(0, c.Resolve(axis));
|
||||
@ -1868,7 +1868,9 @@ bool nsIFrame::ComputeBorderRadii(const BorderRadius& aBorderRadius,
|
||||
}
|
||||
}
|
||||
if (ratio < 1.0) {
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) { aRadii[corner] *= ratio; }
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
aRadii[corner] *= ratio;
|
||||
}
|
||||
}
|
||||
|
||||
return haveRadius;
|
||||
@ -1916,7 +1918,7 @@ void nsIFrame::OutsetBorderRadii(nscoord aRadii[8], const nsMargin& aOffsets) {
|
||||
}
|
||||
|
||||
static inline bool RadiiAreDefinitelyZero(const BorderRadius& aBorderRadius) {
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) {
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
if (!aBorderRadius.Get(corner).IsDefinitelyZero()) {
|
||||
return false;
|
||||
}
|
||||
@ -1941,7 +1943,9 @@ bool nsIFrame::GetBorderRadii(const nsSize& aFrameSize,
|
||||
// In an ideal world, we might have a way for the them to tell us an
|
||||
// border radius, but since we don't, we're better off assuming
|
||||
// zero.
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) { aRadii[corner] = 0; }
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
aRadii[corner] = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1984,7 +1988,7 @@ bool nsIFrame::GetBoxBorderRadii(nscoord aRadii[8], nsMargin aOffset,
|
||||
} else {
|
||||
InsetBorderRadii(aRadii, aOffset);
|
||||
}
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) {
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
if (aRadii[corner]) return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -57,7 +57,7 @@ class DisplayItemClip {
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) {
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
if (mRadii[corner] != aOther.mRadii[corner]) {
|
||||
return false;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class MaskLayerImageCache {
|
||||
aPresContext->AppUnitsToGfxUnits(aRRect.mRect.width),
|
||||
aPresContext->AppUnitsToGfxUnits(aRRect.mRect.height)) {
|
||||
MOZ_COUNT_CTOR(PixelRoundedRect);
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) {
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
mRadii[corner] =
|
||||
aPresContext->AppUnitsToGfxUnits(aRRect.mRadii[corner]);
|
||||
}
|
||||
@ -64,7 +64,9 @@ class MaskLayerImageCache {
|
||||
|
||||
PixelRoundedRect(const PixelRoundedRect& aPRR) : mRect(aPRR.mRect) {
|
||||
MOZ_COUNT_CTOR(PixelRoundedRect);
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) { mRadii[corner] = aPRR.mRadii[corner]; }
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
mRadii[corner] = aPRR.mRadii[corner];
|
||||
}
|
||||
}
|
||||
|
||||
~PixelRoundedRect() { MOZ_COUNT_DTOR(PixelRoundedRect); }
|
||||
@ -89,7 +91,7 @@ class MaskLayerImageCache {
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) {
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
if (mRadii[corner] != aOther.mRadii[corner]) {
|
||||
return false;
|
||||
}
|
||||
|
@ -607,8 +607,9 @@ void nsCSSRendering::ComputePixelRadii(const nscoord* aAppUnitsRadii,
|
||||
nscoord aAppUnitsPerPixel,
|
||||
RectCornerRadii* oBorderRadii) {
|
||||
Float radii[8];
|
||||
NS_FOR_CSS_HALF_CORNERS(corner)
|
||||
radii[corner] = Float(aAppUnitsRadii[corner]) / aAppUnitsPerPixel;
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
radii[corner] = Float(aAppUnitsRadii[corner]) / aAppUnitsPerPixel;
|
||||
}
|
||||
|
||||
(*oBorderRadii)[C_TL] = Size(radii[eCornerTopLeftX], radii[eCornerTopLeftY]);
|
||||
(*oBorderRadii)[C_TR] =
|
||||
|
@ -10013,7 +10013,7 @@ static Maybe<wr::WrClipId> CreateSimpleClipRegion(
|
||||
radii * 2);
|
||||
|
||||
nscoord ellipseRadii[8];
|
||||
NS_FOR_CSS_HALF_CORNERS(corner) {
|
||||
for (const auto corner : mozilla::AllPhysicalHalfCorners()) {
|
||||
ellipseRadii[corner] =
|
||||
HalfCornerIsX(corner) ? radii.width : radii.height;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user