mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 13:58:49 +00:00
Issue #1925 - Convert NS_FULL_TO_HALF_CORNER to a constexpr function.
Note: Because the new function checks types, we need to change the fullCorner type in `nsComputedDOMStyle::GetEllipseRadii()` and `StyleAnimationValue::ExtractComputedValue()` to `Corner` instead of the underlying base type.
This commit is contained in:
@@ -469,6 +469,11 @@ 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_ */
|
||||
|
||||
@@ -3945,9 +3945,9 @@ StyleClipBasicShapeToCSSArray(const StyleClipPath& aClipPath,
|
||||
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;
|
||||
}
|
||||
@@ -4401,11 +4401,11 @@ StyleAnimationValue::ExtractComputedValue(nsCSSPropertyID aProperty,
|
||||
|
||||
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)) {
|
||||
|
||||
@@ -3440,10 +3440,10 @@ nsComputedDOMStyle::DoGetOutlineColor()
|
||||
|
||||
already_AddRefed<CSSValue>
|
||||
nsComputedDOMStyle::GetEllipseRadii(const nsStyleCorners& aRadius,
|
||||
uint8_t aFullCorner)
|
||||
Corner aFullCorner)
|
||||
{
|
||||
nsStyleCoord radiusX = aRadius.Get(NS_FULL_TO_HALF_CORNER(aFullCorner, false));
|
||||
nsStyleCoord radiusY = aRadius.Get(NS_FULL_TO_HALF_CORNER(aFullCorner, true));
|
||||
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) {
|
||||
@@ -6002,9 +6002,9 @@ nsComputedDOMStyle::BasicShapeRadiiToString(nsAString& aCssText,
|
||||
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);
|
||||
|
||||
@@ -158,7 +158,7 @@ private:
|
||||
#undef STYLE_STRUCT
|
||||
|
||||
already_AddRefed<CSSValue> GetEllipseRadii(const nsStyleCorners& aRadius,
|
||||
uint8_t aFullCorner);
|
||||
mozilla::Corner aFullCorner);
|
||||
|
||||
already_AddRefed<CSSValue> GetOffsetWidthFor(mozilla::Side aSide);
|
||||
|
||||
|
||||
@@ -7874,8 +7874,8 @@ nsRuleNode::ComputeBorderData(void* aStartStruct,
|
||||
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);
|
||||
@@ -8066,8 +8066,8 @@ nsRuleNode::ComputeOutlineData(void* aStartStruct,
|
||||
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);
|
||||
@@ -9915,8 +9915,8 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
|
||||
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,
|
||||
|
||||
@@ -20,8 +20,6 @@ namespace mozilla {
|
||||
// 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)
|
||||
|
||||
@@ -354,7 +354,7 @@ CASE(eCornerBottomLeftY, false);
|
||||
|
||||
// Validation of HalfToFullCorner.
|
||||
#define CASE(corner, result) \
|
||||
static_assert(HalfToFullCorner(corner) == result, \
|
||||
static_assert(HalfToFullCorner(corner) == result, \
|
||||
"HalfToFullCorner is wrong")
|
||||
CASE(eCornerTopLeftX, eCornerTopLeft);
|
||||
CASE(eCornerTopLeftY, eCornerTopLeft);
|
||||
@@ -366,10 +366,10 @@ 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);
|
||||
@@ -382,7 +382,7 @@ CASE(eCornerBottomLeft, true, eCornerBottomLeftY);
|
||||
|
||||
// Validation of NS_SIDE_TO_{FULL,HALF}_CORNER.
|
||||
#define CASE(side, second, result) \
|
||||
static_assert(NS_SIDE_TO_FULL_CORNER(side, second) == result, \
|
||||
static_assert(NS_SIDE_TO_FULL_CORNER(side, second) == result, \
|
||||
"NS_SIDE_TO_FULL_CORNER is wrong")
|
||||
CASE(eSideTop, false, eCornerTopLeft);
|
||||
CASE(eSideTop, true, eCornerTopRight);
|
||||
@@ -398,7 +398,7 @@ CASE(eSideLeft, true, eCornerTopLeft);
|
||||
#undef CASE
|
||||
|
||||
#define CASE(side, second, parallel, result) \
|
||||
static_assert(NS_SIDE_TO_HALF_CORNER(side, second, parallel) == result, \
|
||||
static_assert(NS_SIDE_TO_HALF_CORNER(side, second, parallel) == result, \
|
||||
"NS_SIDE_TO_HALF_CORNER is wrong")
|
||||
CASE(eSideTop, false, true, eCornerTopLeftX);
|
||||
CASE(eSideTop, false, false, eCornerTopLeftY);
|
||||
|
||||
Reference in New Issue
Block a user