Bug 1320014 Part 15 - Replace RectCorner with Corner.
Rewrite RectCornerRadii::operator==() and RectCornerRadii::AreRadiiSame() by
explicitly expand all the comparisons, and rewrite other explicit for-loops
with NS_FOR_CSS_FULL_CORNERS.
MozReview-Commit-ID: BLBJHla8kyk
--- a/gfx/2d/BaseRect.h
+++ b/gfx/2d/BaseRect.h
@@ -314,22 +314,22 @@ struct BaseRect {
aRect.x - x);
}
// Helpers for accessing the vertices
Point TopLeft() const { return Point(x, y); }
Point TopRight() const { return Point(XMost(), y); }
Point BottomLeft() const { return Point(x, YMost()); }
Point BottomRight() const { return Point(XMost(), YMost()); }
- Point AtCorner(int aCorner) const {
+ Point AtCorner(Corner aCorner) const {
switch (aCorner) {
- case RectCorner::TopLeft: return TopLeft();
- case RectCorner::TopRight: return TopRight();
- case RectCorner::BottomRight: return BottomRight();
- case RectCorner::BottomLeft: return BottomLeft();
+ case eCornerTopLeft: return TopLeft();
+ case eCornerTopRight: return TopRight();
+ case eCornerBottomRight: return BottomRight();
+ case eCornerBottomLeft: return BottomLeft();
}
MOZ_CRASH("GFX: Incomplete switch");
}
Point CCWCorner(mozilla::Side side) const {
switch (side) {
case eSideTop: return TopLeft();
case eSideRight: return TopRight();
case eSideBottom: return BottomRight();
--- a/gfx/2d/PathHelpers.cpp
+++ b/gfx/2d/PathHelpers.cpp
@@ -120,20 +120,20 @@ AppendRoundedRectToPath(PathBuilder* aPa
twoFloats *cornerMults = aDrawClockwise ? cwCornerMults : ccwCornerMults;
Point cornerCoords[] = { aRect.TopLeft(), aRect.TopRight(),
aRect.BottomRight(), aRect.BottomLeft() };
Point pc, p0, p1, p2, p3;
if (aDrawClockwise) {
- aPathBuilder->MoveTo(Point(aRect.X() + aRadii[RectCorner::TopLeft].width,
+ aPathBuilder->MoveTo(Point(aRect.X() + aRadii[eCornerTopLeft].width,
aRect.Y()));
} else {
- aPathBuilder->MoveTo(Point(aRect.X() + aRect.Width() - aRadii[RectCorner::TopRight].width,
+ aPathBuilder->MoveTo(Point(aRect.X() + aRect.Width() - aRadii[eCornerTopRight].width,
aRect.Y()));
}
for (int i = 0; i < 4; ++i) {
// the corner index -- either 1 2 3 0 (cw) or 0 3 2 1 (ccw)
int c = aDrawClockwise ? ((i+1) % 4) : ((4-i) % 4);
// i+2 and i+3 respectively. These are used to index into the corner
--- a/gfx/2d/PathHelpers.h
+++ b/gfx/2d/PathHelpers.h
@@ -173,88 +173,85 @@ inline already_AddRefed<Path> MakePathFo
bool aDrawClockwise = true)
{
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
AppendRectToPath(builder, aRect, aDrawClockwise);
return builder->Finish();
}
struct RectCornerRadii {
- Size radii[RectCorner::Count];
+ Size radii[eCornerCount];
RectCornerRadii() {}
explicit RectCornerRadii(Float radius) {
- for (int i = 0; i < RectCorner::Count; i++) {
+ NS_FOR_CSS_FULL_CORNERS(i) {
radii[i].SizeTo(radius, radius);
}
}
explicit RectCornerRadii(Float radiusX, Float radiusY) {
- for (int i = 0; i < RectCorner::Count; i++) {
+ NS_FOR_CSS_FULL_CORNERS(i) {
radii[i].SizeTo(radiusX, radiusY);
}
}
RectCornerRadii(Float tl, Float tr, Float br, Float bl) {
- radii[RectCorner::TopLeft].SizeTo(tl, tl);
- radii[RectCorner::TopRight].SizeTo(tr, tr);
- radii[RectCorner::BottomRight].SizeTo(br, br);
- radii[RectCorner::BottomLeft].SizeTo(bl, bl);
+ radii[eCornerTopLeft].SizeTo(tl, tl);
+ radii[eCornerTopRight].SizeTo(tr, tr);
+ radii[eCornerBottomRight].SizeTo(br, br);
+ radii[eCornerBottomLeft].SizeTo(bl, bl);
}
RectCornerRadii(const Size& tl, const Size& tr,
const Size& br, const Size& bl) {
- radii[RectCorner::TopLeft] = tl;
- radii[RectCorner::TopRight] = tr;
- radii[RectCorner::BottomRight] = br;
- radii[RectCorner::BottomLeft] = bl;
+ radii[eCornerTopLeft] = tl;
+ radii[eCornerTopRight] = tr;
+ radii[eCornerBottomRight] = br;
+ radii[eCornerBottomLeft] = bl;
}
const Size& operator[](size_t aCorner) const {
return radii[aCorner];
}
Size& operator[](size_t aCorner) {
return radii[aCorner];
}
bool operator==(const RectCornerRadii& aOther) const {
- for (size_t i = 0; i < RectCorner::Count; i++) {
- if (radii[i] != aOther.radii[i]) return false;
- }
- return true;
+ return TopLeft() == aOther.TopLeft() &&
+ TopRight() == aOther.TopRight() &&
+ BottomRight() == aOther.BottomRight() &&
+ BottomLeft() == aOther.BottomLeft();
}
bool AreRadiiSame() const {
- for (size_t i = 1; i < RectCorner::Count; i++) {
- if (radii[i] != radii[0]) {
- return false;
- }
- }
- return true;
+ return TopLeft() == TopRight() &&
+ TopLeft() == BottomRight() &&
+ TopLeft() == BottomLeft();
}
void Scale(Float aXScale, Float aYScale) {
- for (int i = 0; i < RectCorner::Count; i++) {
+ NS_FOR_CSS_FULL_CORNERS(i) {
radii[i].Scale(aXScale, aYScale);
}
}
- const Size TopLeft() const { return radii[RectCorner::TopLeft]; }
- Size& TopLeft() { return radii[RectCorner::TopLeft]; }
+ const Size TopLeft() const { return radii[eCornerTopLeft]; }
+ Size& TopLeft() { return radii[eCornerTopLeft]; }
- const Size TopRight() const { return radii[RectCorner::TopRight]; }
- Size& TopRight() { return radii[RectCorner::TopRight]; }
+ const Size TopRight() const { return radii[eCornerTopRight]; }
+ Size& TopRight() { return radii[eCornerTopRight]; }
- const Size BottomRight() const { return radii[RectCorner::BottomRight]; }
- Size& BottomRight() { return radii[RectCorner::BottomRight]; }
+ const Size BottomRight() const { return radii[eCornerBottomRight]; }
+ Size& BottomRight() { return radii[eCornerBottomRight]; }
- const Size BottomLeft() const { return radii[RectCorner::BottomLeft]; }
- Size& BottomLeft() { return radii[RectCorner::BottomLeft]; }
+ const Size BottomLeft() const { return radii[eCornerBottomLeft]; }
+ Size& BottomLeft() { return radii[eCornerBottomLeft]; }
};
/**
* Appends a path represending a rounded rectangle to the path being built by
* aPathBuilder.
*
* aRect The rectangle to append.
* aCornerRadii Contains the radii of the top-left, top-right, bottom-right
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -364,31 +364,16 @@ typedef mozilla::gfx::SurfaceFormat gfxI
#define GFX2D_API __declspec(dllimport)
#endif
#else
#define GFX2D_API
#endif
namespace mozilla {
-// We can't use MOZ_BEGIN_ENUM_CLASS here because that prevents the enum
-// values from being used for indexing. Wrapping the enum in a struct does at
-// least gives us name scoping.
-struct RectCorner {
- enum {
- // This order is important since Rect::AtCorner, AppendRoundedRectToPath
- // and other code depends on it!
- TopLeft = 0,
- TopRight = 1,
- BottomRight = 2,
- BottomLeft = 3,
- Count = 4
- };
-};
-
// Side constants for use in various places.
enum Side { eSideTop, eSideRight, eSideBottom, eSideLeft };
enum SideBits {
eSideBitsNone = 0,
eSideBitsTop = 1 << eSideTop,
eSideBitsRight = 1 << eSideRight,
eSideBitsBottom = 1 << eSideBottom,
@@ -419,16 +404,21 @@ static inline Side& operator++(Side& sid
enum Corner {
// This order is important!
eCornerTopLeft = 0,
eCornerTopRight = 1,
eCornerBottomRight = 2,
eCornerBottomLeft = 3
};
+// RectCornerRadii::radii depends on this value. It is not being added to
+// Corner because we want to lift the responsibility to handle it in the
+// switch-case.
+constexpr int eCornerCount = 4;
+
// 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__))
--- a/gfx/thebes/gfxBlur.cpp
+++ b/gfx/thebes/gfxBlur.cpp
@@ -425,17 +425,17 @@ static IntSize
ComputeMinSizeForShadowShape(const RectCornerRadii* aCornerRadii,
const IntSize& aBlurRadius,
IntMargin& aOutSlice,
const IntSize& aRectSize)
{
Size cornerSize(0, 0);
if (aCornerRadii) {
const RectCornerRadii& corners = *aCornerRadii;
- for (size_t i = 0; i < RectCorner::Count; i++) {
+ NS_FOR_CSS_FULL_CORNERS(i) {
cornerSize.width = std::max(cornerSize.width, corners[i].width);
cornerSize.height = std::max(cornerSize.height, corners[i].height);
}
}
IntSize margin = IntSize::Ceil(cornerSize) + aBlurRadius;
aOutSlice = IntMargin(margin.height, margin.width,
margin.height, margin.width);
@@ -1158,17 +1158,17 @@ gfxAlphaBoxBlur::GetInsetBlur(const Rect
static void GetBlurMargins(const RectCornerRadii* aInnerClipRadii,
const IntSize& aBlurRadius,
Margin& aOutBlurMargin,
Margin& aOutInnerMargin)
{
Size cornerSize(0, 0);
if (aInnerClipRadii) {
const RectCornerRadii& corners = *aInnerClipRadii;
- for (size_t i = 0; i < RectCorner::Count; i++) {
+ NS_FOR_CSS_FULL_CORNERS(i) {
cornerSize.width = std::max(cornerSize.width, corners[i].width);
cornerSize.height = std::max(cornerSize.height, corners[i].height);
}
}
// Only the inside whitespace size cares about the border radius size.
// Outer sizes only care about blur.
IntSize margin = IntSize::Ceil(cornerSize) + aBlurRadius;