Bug 1320014 Part 12 - Convert NS_SIDE_IS_VERTICAL to a constexpr function.
MozReview-Commit-ID: GFdigJKppuR
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -479,11 +479,16 @@ constexpr Corner HalfToFullCorner(HalfCo
return Corner(aHalfCorner / 2);
}
constexpr HalfCorner FullToHalfCorner(Corner aCorner, bool aIsVertical)
{
return HalfCorner(aCorner * 2 + aIsVertical);
}
+constexpr bool SideIsVertical(Side aSide)
+{
+ return aSide % 2;
+}
+
} // namespace mozilla
#endif /* MOZILLA_GFX_TYPES_H_ */
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -1301,17 +1301,17 @@ nsIFrame::ComputeBorderRadii(const nsSty
// css3-background specifies this algorithm for reducing
// corner radii when they are too big.
bool haveRadius = false;
double ratio = 1.0f;
NS_FOR_CSS_SIDES(side) {
uint32_t hc1 = NS_SIDE_TO_HALF_CORNER(side, false, true);
uint32_t hc2 = NS_SIDE_TO_HALF_CORNER(side, true, true);
nscoord length =
- NS_SIDE_IS_VERTICAL(side) ? aBorderArea.height : aBorderArea.width;
+ SideIsVertical(side) ? aBorderArea.height : aBorderArea.width;
nscoord sum = aRadii[hc1] + aRadii[hc2];
if (sum)
haveRadius = true;
// avoid floating point division in the normal case
if (length < sum)
ratio = std::min(ratio, double(length)/sum);
}
--- a/layout/painting/nsCSSRendering.cpp
+++ b/layout/painting/nsCSSRendering.cpp
@@ -4059,19 +4059,19 @@ DrawBorderImage(nsPresContext* aPr
renderer.SetPreferredSize(intrinsicSize, imageSize);
// Compute the used values of 'border-image-slice' and 'border-image-width';
// we do them together because the latter can depend on the former.
nsMargin slice;
nsMargin border;
NS_FOR_CSS_SIDES(s) {
nsStyleCoord coord = aStyleBorder.mBorderImageSlice.Get(s);
- int32_t imgDimension = NS_SIDE_IS_VERTICAL(s)
+ int32_t imgDimension = SideIsVertical(s)
? imageSize.width : imageSize.height;
- nscoord borderDimension = NS_SIDE_IS_VERTICAL(s)
+ nscoord borderDimension = SideIsVertical(s)
? borderImgArea.width : borderImgArea.height;
double value;
switch (coord.GetUnit()) {
case eStyleUnit_Percent:
value = coord.GetPercentValue() * imgDimension;
break;
case eStyleUnit_Factor:
value = nsPresContext::CSSPixelsToAppUnits(
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -15,17 +15,16 @@
// XXX fold this into nsStyleContext and group by nsStyleXXX struct
namespace mozilla {
// The results of these conversion macros are exhaustively checked in
// nsStyleCoord.cpp.
// Arguments must not have side effects.
-#define NS_SIDE_IS_VERTICAL(side_) ((side_) % 2)
#define NS_SIDE_TO_FULL_CORNER(side_, second_) \
(((side_) + !!(second_)) % 4)
#define NS_SIDE_TO_HALF_CORNER(side_, second_, parallel_) \
((((side_) + !!(second_))*2 + ((side_) + !(parallel_))%2) % 8)
// Basic shapes
enum class StyleBasicShapeType : uint8_t {
Polygon,
--- a/layout/style/nsStyleCoord.cpp
+++ b/layout/style/nsStyleCoord.cpp
@@ -325,20 +325,20 @@ nsStyleCorners::operator==(const nsStyle
void nsStyleCorners::Reset()
{
NS_FOR_CSS_HALF_CORNERS(i) {
nsStyleCoord::Reset(mUnits[i], mValues[i]);
}
}
-// Validation of NS_SIDE_IS_VERTICAL and NS_HALF_CORNER_IS_X.
+// Validation of SideIsVertical.
#define CASE(side, result) \
- static_assert(NS_SIDE_IS_VERTICAL(side) == result, \
- "NS_SIDE_IS_VERTICAL is wrong")
+ static_assert(SideIsVertical(side) == result, \
+ "SideIsVertical is wrong")
CASE(eSideTop, false);
CASE(eSideRight, true);
CASE(eSideBottom, false);
CASE(eSideLeft, true);
#undef CASE
// Validation of HalfCornerIsX.
#define CASE(corner, result) \