Bug 1610670 - Add AllPhysicalCorners() 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.

```

function rename() {
    echo "Renaming $1 to $2"
    rg -l "$1" | xargs sed -i -E -e s/"$1"/"$2"/g
}

rename "NS_FOR_CSS_FULL_CORNERS\(i\)" "for (const auto i : mozilla::AllPhysicalCorners())"
rename "NS_FOR_CSS_FULL_CORNERS\(corner\)" "for (const auto corner : mozilla::AllPhysicalCorners())"
```

Differential Revision: https://phabricator.services.mozilla.com/D61251

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ting-Yu Lin 2020-02-04 03:28:35 +00:00
Родитель c81d3e5f5f
Коммит b19983c13e
4 изменённых файлов: 16 добавлений и 22 удалений

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

@ -364,11 +364,15 @@ struct RectCornerRadii final {
RectCornerRadii() = default;
explicit RectCornerRadii(Float radius) {
NS_FOR_CSS_FULL_CORNERS(i) { radii[i].SizeTo(radius, radius); }
for (const auto i : mozilla::AllPhysicalCorners()) {
radii[i].SizeTo(radius, radius);
}
}
RectCornerRadii(Float radiusX, Float radiusY) {
NS_FOR_CSS_FULL_CORNERS(i) { radii[i].SizeTo(radiusX, radiusY); }
for (const auto i : mozilla::AllPhysicalCorners()) {
radii[i].SizeTo(radiusX, radiusY);
}
}
RectCornerRadii(Float tl, Float tr, Float br, Float bl) {
@ -402,7 +406,9 @@ struct RectCornerRadii final {
}
void Scale(Float aXScale, Float aYScale) {
NS_FOR_CSS_FULL_CORNERS(i) { radii[i].Scale(aXScale, aYScale); }
for (const auto i : mozilla::AllPhysicalCorners()) {
radii[i].Scale(aXScale, aYScale);
}
}
const Size TopLeft() const { return radii[eCornerTopLeft]; }

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

@ -546,21 +546,9 @@ enum Corner {
// 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 && \
(static_cast<void>(var_ = mozilla::Corner(MOZ_CONCAT(var_, __LINE__))), \
true); \
++MOZ_CONCAT(var_, __LINE__))
static inline Corner operator++(Corner& aCorner) {
MOZ_ASSERT(aCorner >= eCornerTopLeft && aCorner <= eCornerBottomLeft,
"Out of range corner!");
aCorner = Corner(aCorner + 1);
return aCorner;
constexpr auto AllPhysicalCorners() {
return mozilla::MakeInclusiveEnumeratedRange(eCornerTopLeft,
eCornerBottomLeft);
}
// Indices into "half corner" arrays (nsStyleCorners e.g.)

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

@ -409,7 +409,7 @@ static IntSize ComputeMinSizeForShadowShape(const RectCornerRadii* aCornerRadii,
Size cornerSize(0, 0);
if (aCornerRadii) {
const RectCornerRadii& corners = *aCornerRadii;
NS_FOR_CSS_FULL_CORNERS(i) {
for (const auto i : mozilla::AllPhysicalCorners()) {
cornerSize.width = std::max(cornerSize.width, corners[i].width);
cornerSize.height = std::max(cornerSize.height, corners[i].height);
}
@ -1115,7 +1115,7 @@ static void GetBlurMargins(const RectCornerRadii* aInnerClipRadii,
Size cornerSize(0, 0);
if (aInnerClipRadii) {
const RectCornerRadii& corners = *aInnerClipRadii;
NS_FOR_CSS_FULL_CORNERS(i) {
for (const auto i : mozilla::AllPhysicalCorners()) {
cornerSize.width = std::max(cornerSize.width, corners[i].width);
cornerSize.height = std::max(cornerSize.height, corners[i].height);
}

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

@ -3182,7 +3182,7 @@ void nsCSSBorderRenderer::DrawBorders() {
// XXX In fact is this optimization even worth the complexity it adds to
// the code? 1px wide dashed borders are not overly common, and drawing
// corners for them is not that expensive.
NS_FOR_CSS_FULL_CORNERS(corner) {
for (const auto corner : mozilla::AllPhysicalCorners()) {
const mozilla::Side sides[2] = {mozilla::Side(corner), PREV_SIDE(corner)};
if (!IsZeroSize(mBorderRadii[corner])) {
@ -3199,7 +3199,7 @@ void nsCSSBorderRenderer::DrawBorders() {
}
// First, the corners
NS_FOR_CSS_FULL_CORNERS(corner) {
for (const auto corner : mozilla::AllPhysicalCorners()) {
// if there's no corner, don't do all this work for it
if (IsZeroSize(mBorderCornerDimensions[corner])) {
continue;