Bug 1320014 Part 11 - Convert NS_FULL_TO_HALF_CORNER to a constexpr function.
Because the new function checks types, we need to change the fullCorner type
in nsComputedDOMStyle::GetEllipseRadii() and
StyleAnimationValue::ExtractComputedValue() from uint8_t to |Corner| to fix
build error.
MozReview-Commit-ID: 5NuFE3yA2QD
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -474,11 +474,16 @@ constexpr bool HalfCornerIsX(HalfCorner
return !(aHalfCorner % 2);
}
constexpr Corner HalfToFullCorner(HalfCorner aHalfCorner)
{
return Corner(aHalfCorner / 2);
}
+constexpr HalfCorner FullToHalfCorner(Corner aCorner, bool aIsVertical)
+{
+ return HalfCorner(aCorner * 2 + aIsVertical);
+}
+
} // namespace mozilla
#endif /* MOZILLA_GFX_TYPES_H_ */
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -4205,19 +4205,19 @@ StyleClipBasicShapeToCSSArray(const Styl
if (!StyleCoordToCSSValue(coords[i], functionArray->Item(i + 1))) {
return false;
}
}
RefPtr<nsCSSValue::Array> radiusArray = nsCSSValue::Array::Create(4);
const nsStyleCorners& radii = shape->GetRadius();
NS_FOR_CSS_FULL_CORNERS(corner) {
auto pair = MakeUnique<nsCSSValuePair>();
- if (!StyleCoordToCSSValue(radii.Get(NS_FULL_TO_HALF_CORNER(corner, false)),
+ if (!StyleCoordToCSSValue(radii.Get(FullToHalfCorner(corner, false)),
pair->mXValue) ||
- !StyleCoordToCSSValue(radii.Get(NS_FULL_TO_HALF_CORNER(corner, true)),
+ !StyleCoordToCSSValue(radii.Get(FullToHalfCorner(corner, true)),
pair->mYValue)) {
return false;
}
radiusArray->Item(corner).SetPairValue(pair.get());
}
// Set the last item in functionArray to the radius array:
functionArray->Item(functionArray->Count() - 1).
SetArrayValue(radiusArray, eCSSUnit_Array);
@@ -4687,21 +4687,21 @@ StyleAnimationValue::ExtractComputedValu
eCornerBottomRight == eStyleAnimType_Corner_BottomRight -
eStyleAnimType_Corner_TopLeft &&
eCornerBottomLeft == eStyleAnimType_Corner_BottomLeft -
eStyleAnimType_Corner_TopLeft,
"box corner constants out of sync with animation corner constants");
const nsStyleCorners& corners =
StyleDataAtOffset<nsStyleCorners>(styleStruct, ssOffset);
- uint8_t fullCorner = animType - eStyleAnimType_Corner_TopLeft;
+ Corner fullCorner = Corner(animType - eStyleAnimType_Corner_TopLeft);
const nsStyleCoord &horiz =
- corners.Get(NS_FULL_TO_HALF_CORNER(fullCorner, false));
+ corners.Get(FullToHalfCorner(fullCorner, false));
const nsStyleCoord &vert =
- corners.Get(NS_FULL_TO_HALF_CORNER(fullCorner, true));
+ corners.Get(FullToHalfCorner(fullCorner, true));
nsAutoPtr<nsCSSValuePair> pair(new nsCSSValuePair);
if (!StyleCoordToCSSValue(horiz, pair->mXValue) ||
!StyleCoordToCSSValue(vert, pair->mYValue)) {
return false;
}
aComputedValue.SetAndAdoptCSSValuePairValue(pair.forget(),
eUnit_CSSValuePair);
return true;
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -3408,20 +3408,20 @@ nsComputedDOMStyle::DoGetOutlineColor()
{
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
SetValueFromComplexColor(val, StyleOutline()->mOutlineColor);
return val.forget();
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::GetEllipseRadii(const nsStyleCorners& aRadius,
- uint8_t aFullCorner)
-{
- nsStyleCoord radiusX = aRadius.Get(NS_FULL_TO_HALF_CORNER(aFullCorner, false));
- nsStyleCoord radiusY = aRadius.Get(NS_FULL_TO_HALF_CORNER(aFullCorner, true));
+ Corner aFullCorner)
+{
+ nsStyleCoord radiusX = aRadius.Get(FullToHalfCorner(aFullCorner, false));
+ nsStyleCoord radiusY = aRadius.Get(FullToHalfCorner(aFullCorner, true));
// for compatibility, return a single value if X and Y are equal
if (radiusX == radiusY) {
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
SetValueToCoord(val, radiusX, true);
return val.forget();
}
@@ -5955,19 +5955,19 @@ nsComputedDOMStyle::BoxValuesToString(ns
void
nsComputedDOMStyle::BasicShapeRadiiToString(nsAString& aCssText,
const nsStyleCorners& aCorners)
{
nsTArray<nsStyleCoord> horizontal, vertical;
nsAutoString horizontalString, verticalString;
NS_FOR_CSS_FULL_CORNERS(corner) {
horizontal.AppendElement(
- aCorners.Get(NS_FULL_TO_HALF_CORNER(corner, false)));
+ aCorners.Get(FullToHalfCorner(corner, false)));
vertical.AppendElement(
- aCorners.Get(NS_FULL_TO_HALF_CORNER(corner, true)));
+ aCorners.Get(FullToHalfCorner(corner, true)));
}
BoxValuesToString(horizontalString, horizontal);
BoxValuesToString(verticalString, vertical);
aCssText.Append(horizontalString);
if (horizontalString == verticalString) {
return;
}
aCssText.AppendLiteral(" / ");
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -147,17 +147,17 @@ private:
#define STYLE_STRUCT(name_, checkdata_cb_) \
const nsStyle##name_ * Style##name_() { \
return mStyleContext->Style##name_(); \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
already_AddRefed<CSSValue> GetEllipseRadii(const nsStyleCorners& aRadius,
- uint8_t aFullCorner);
+ mozilla::Corner aFullCorner);
already_AddRefed<CSSValue> GetOffsetWidthFor(mozilla::Side aSide);
already_AddRefed<CSSValue> GetAbsoluteOffset(mozilla::Side aSide);
already_AddRefed<CSSValue> GetRelativeOffset(mozilla::Side aSide);
already_AddRefed<CSSValue> GetStickyOffset(mozilla::Side aSide);
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -7774,18 +7774,18 @@ nsRuleNode::ComputeBorderData(void* aSta
}
}
// border-radius: length, percent, inherit
{
const nsCSSPropertyID* subprops =
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_radius);
NS_FOR_CSS_FULL_CORNERS(corner) {
- int cx = NS_FULL_TO_HALF_CORNER(corner, false);
- int cy = NS_FULL_TO_HALF_CORNER(corner, true);
+ int cx = FullToHalfCorner(corner, false);
+ int cy = FullToHalfCorner(corner, true);
const nsCSSValue& radius = *aRuleData->ValueFor(subprops[corner]);
nsStyleCoord parentX = parentBorder->mBorderRadius.Get(cx);
nsStyleCoord parentY = parentBorder->mBorderRadius.Get(cy);
nsStyleCoord coordX, coordY;
if (SetPairCoords(radius, coordX, coordY, parentX, parentY,
SETCOORD_LPH | SETCOORD_INITIAL_ZERO |
SETCOORD_STORE_CALC | SETCOORD_UNSET_INITIAL,
@@ -7963,18 +7963,18 @@ nsRuleNode::ComputeOutlineData(void* aSt
mPresContext,
outline->mOutlineColor, conditions);
// -moz-outline-radius: length, percent, inherit
{
const nsCSSPropertyID* subprops =
nsCSSProps::SubpropertyEntryFor(eCSSProperty__moz_outline_radius);
NS_FOR_CSS_FULL_CORNERS(corner) {
- int cx = NS_FULL_TO_HALF_CORNER(corner, false);
- int cy = NS_FULL_TO_HALF_CORNER(corner, true);
+ int cx = FullToHalfCorner(corner, false);
+ int cy = FullToHalfCorner(corner, true);
const nsCSSValue& radius = *aRuleData->ValueFor(subprops[corner]);
nsStyleCoord parentX = parentOutline->mOutlineRadius.Get(cx);
nsStyleCoord parentY = parentOutline->mOutlineRadius.Get(cy);
nsStyleCoord coordX, coordY;
if (SetPairCoords(radius, coordX, coordY, parentX, parentY,
SETCOORD_LPH | SETCOORD_INITIAL_ZERO |
SETCOORD_STORE_CALC | SETCOORD_UNSET_INITIAL,
@@ -9825,18 +9825,18 @@ GetStyleBasicShapeFromCSSValue(const nsC
}
coords.AppendElement(inset);
}
nsStyleCorners& insetRadius = basicShape->GetRadius();
if (shapeFunction->Item(5).GetUnit() == eCSSUnit_Array) {
nsCSSValue::Array* radiiArray = shapeFunction->Item(5).GetArrayValue();
NS_FOR_CSS_FULL_CORNERS(corner) {
- int cx = NS_FULL_TO_HALF_CORNER(corner, false);
- int cy = NS_FULL_TO_HALF_CORNER(corner, true);
+ int cx = FullToHalfCorner(corner, false);
+ int cy = FullToHalfCorner(corner, true);
const nsCSSValue& radius = radiiArray->Item(corner);
nsStyleCoord coordX, coordY;
DebugOnly<bool> didSetRadii = SetPairCoords(radius, coordX, coordY,
nsStyleCoord(),
nsStyleCoord(), mask,
aStyleContext,
aPresContext,
aConditions);
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -15,18 +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_FULL_TO_HALF_CORNER(var_, vert_) ((var_)*2 + !!(vert_))
-
#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 {
--- a/layout/style/nsStyleCoord.cpp
+++ b/layout/style/nsStyleCoord.cpp
@@ -363,20 +363,20 @@ CASE(eCornerTopLeftY, eCornerTopLeft
CASE(eCornerTopRightX, eCornerTopRight);
CASE(eCornerTopRightY, eCornerTopRight);
CASE(eCornerBottomRightX, eCornerBottomRight);
CASE(eCornerBottomRightY, eCornerBottomRight);
CASE(eCornerBottomLeftX, eCornerBottomLeft);
CASE(eCornerBottomLeftY, eCornerBottomLeft);
#undef CASE
-// Validation of NS_FULL_TO_HALF_CORNER.
+// Validation of FullToHalfCorner.
#define CASE(corner, vert, result) \
- static_assert(NS_FULL_TO_HALF_CORNER(corner, vert) == result, \
- "NS_FULL_TO_HALF_CORNER is wrong")
+ static_assert(FullToHalfCorner(corner, vert) == result, \
+ "FullToHalfCorner is wrong")
CASE(eCornerTopLeft, false, eCornerTopLeftX);
CASE(eCornerTopLeft, true, eCornerTopLeftY);
CASE(eCornerTopRight, false, eCornerTopRightX);
CASE(eCornerTopRight, true, eCornerTopRightY);
CASE(eCornerBottomRight, false, eCornerBottomRightX);
CASE(eCornerBottomRight, true, eCornerBottomRightY);
CASE(eCornerBottomLeft, false, eCornerBottomLeftX);
CASE(eCornerBottomLeft, true, eCornerBottomLeftY);