Bug 1320014 Part 15 - Replace RectCorner with Corner. r=mats

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

--HG--
extra : rebase_source : 464d8973eae6fa58e6931cc65d61900605926b85
This commit is contained in:
Ting-Yu Lin 2017-01-05 17:07:07 +08:00
Родитель 53633b1c42
Коммит e857e2115f
5 изменённых файлов: 41 добавлений и 54 удалений

Просмотреть файл

@ -319,12 +319,12 @@ struct BaseRect {
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");
}

Просмотреть файл

@ -125,10 +125,10 @@ AppendRoundedRectToPath(PathBuilder* aPathBuilder,
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()));
}

Просмотреть файл

@ -178,35 +178,35 @@ inline already_AddRefed<Path> MakePathForRect(const DrawTarget& aDrawTarget,
}
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 {
@ -218,38 +218,35 @@ struct RectCornerRadii {
}
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]; }
};
/**

Просмотреть файл

@ -369,21 +369,6 @@ typedef mozilla::gfx::SurfaceFormat gfxImageFormat;
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 };
@ -424,6 +409,11 @@ enum Corner {
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_) \

Просмотреть файл

@ -430,7 +430,7 @@ ComputeMinSizeForShadowShape(const RectCornerRadii* aCornerRadii,
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);
}
@ -1163,7 +1163,7 @@ static void GetBlurMargins(const RectCornerRadii* aInnerClipRadii,
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);
}