Bug 1325006 Part 2 - Convert NS_RADIUS_* to StyleShapeRadius enum class. r=heycam

The "default" case in EnumerationToLength() is not needed anymore because
StyleShapeRadius is an enum class, which cannot have other values.

MozReview-Commit-ID: GHkPAXXxqGZ

--HG--
extra : rebase_source : 8bc51d6f21cd70688d3b968bcd0a5ef12a6e3f47
This commit is contained in:
Ting-Yu Lin 2016-12-03 16:13:49 +08:00
Родитель b8e8384476
Коммит 6c29f00e11
5 изменённых файлов: 20 добавлений и 19 удалений

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

@ -2298,8 +2298,8 @@ const KTableEntry nsCSSProps::kClipPathGeometryBoxKTable[] = {
};
const KTableEntry nsCSSProps::kShapeRadiusKTable[] = {
{ eCSSKeyword_closest_side, NS_RADIUS_CLOSEST_SIDE },
{ eCSSKeyword_farthest_side, NS_RADIUS_FARTHEST_SIDE },
{ eCSSKeyword_closest_side, StyleShapeRadius::ClosestSide },
{ eCSSKeyword_farthest_side, StyleShapeRadius::FarthestSide },
{ eCSSKeyword_UNKNOWN, -1 }
};

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

@ -1023,10 +1023,10 @@ nsCSSValue::AppendCircleOrEllipseToString(nsCSSKeyword aFunctionId,
// closest-side is the default, so we don't need to
// output it if all values are closest-side.
if (array->Item(1).GetUnit() == eCSSUnit_Enumerated &&
array->Item(1).GetIntValue() == NS_RADIUS_CLOSEST_SIDE &&
StyleShapeRadius(array->Item(1).GetIntValue()) == StyleShapeRadius::ClosestSide &&
(aFunctionId == eCSSKeyword_circle ||
(array->Item(2).GetUnit() == eCSSUnit_Enumerated &&
array->Item(2).GetIntValue() == NS_RADIUS_CLOSEST_SIDE))) {
StyleShapeRadius(array->Item(2).GetIntValue()) == StyleShapeRadius::ClosestSide))) {
hasRadii = false;
} else {
AppendPositionCoordinateToString(array->Item(1), aProperty,

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

@ -9755,7 +9755,7 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
aConditions);
MOZ_ASSERT(didSetRadius, "unexpected radius unit");
} else {
radius.SetIntValue(NS_RADIUS_CLOSEST_SIDE, eStyleUnit_Enumerated);
radius.SetEnumValue(StyleShapeRadius::ClosestSide);
}
basicShape->Coordinates().AppendElement(radius);
}

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

@ -155,6 +155,12 @@ enum class StyleShapeOutsideShapeBox : uint8_t {
Margin
};
// <shape-radius> for <basic-shape>
enum class StyleShapeRadius : uint8_t {
FarthestSide,
ClosestSide
};
// Shape source type
enum class StyleShapeSourceType : uint8_t {
None,
@ -219,9 +225,6 @@ enum class StyleOrient : uint8_t {
Vertical,
};
#define NS_RADIUS_FARTHEST_SIDE 0
#define NS_RADIUS_CLOSEST_SIDE 1
// stack-sizing
#define NS_STYLE_STACK_SIZING_IGNORE 0
#define NS_STYLE_STACK_SIZING_STRETCH_TO_FIT 1

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

@ -216,21 +216,18 @@ nsCSSClipPathInstance::CreateClipPath(DrawTarget* aDrawTarget)
}
static void
EnumerationToLength(nscoord& aCoord, int32_t aType,
EnumerationToLength(nscoord& aCoord, StyleShapeRadius aType,
nscoord aCenter, nscoord aPosMin, nscoord aPosMax)
{
nscoord dist1 = abs(aPosMin - aCenter);
nscoord dist2 = abs(aPosMax - aCenter);
switch (aType) {
case NS_RADIUS_FARTHEST_SIDE:
case StyleShapeRadius::FarthestSide:
aCoord = dist1 > dist2 ? dist1 : dist2;
break;
case NS_RADIUS_CLOSEST_SIDE:
case StyleShapeRadius::ClosestSide:
aCoord = dist1 > dist2 ? dist2 : dist1;
break;
default:
NS_NOTREACHED("unknown keyword");
break;
}
}
@ -253,12 +250,13 @@ nsCSSClipPathInstance::CreateClipPathCircle(DrawTarget* aDrawTarget,
MOZ_ASSERT(coords.Length() == 1, "wrong number of arguments");
nscoord r = 0;
if (coords[0].GetUnit() == eStyleUnit_Enumerated) {
const auto styleShapeRadius = coords[0].GetEnumValue<StyleShapeRadius>();
nscoord horizontal, vertical;
EnumerationToLength(horizontal, coords[0].GetIntValue(),
EnumerationToLength(horizontal, styleShapeRadius,
center.x, aRefBox.x, aRefBox.x + aRefBox.width);
EnumerationToLength(vertical, coords[0].GetIntValue(),
EnumerationToLength(vertical, styleShapeRadius,
center.y, aRefBox.y, aRefBox.y + aRefBox.height);
if (coords[0].GetIntValue() == NS_RADIUS_FARTHEST_SIDE) {
if (styleShapeRadius == StyleShapeRadius::FarthestSide) {
r = horizontal > vertical ? horizontal : vertical;
} else {
r = horizontal < vertical ? horizontal : vertical;
@ -299,13 +297,13 @@ nsCSSClipPathInstance::CreateClipPathEllipse(DrawTarget* aDrawTarget,
MOZ_ASSERT(coords.Length() == 2, "wrong number of arguments");
nscoord rx = 0, ry = 0;
if (coords[0].GetUnit() == eStyleUnit_Enumerated) {
EnumerationToLength(rx, coords[0].GetIntValue(),
EnumerationToLength(rx, coords[0].GetEnumValue<StyleShapeRadius>(),
center.x, aRefBox.x, aRefBox.x + aRefBox.width);
} else {
rx = nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.width);
}
if (coords[1].GetUnit() == eStyleUnit_Enumerated) {
EnumerationToLength(ry, coords[1].GetIntValue(),
EnumerationToLength(ry, coords[1].GetEnumValue<StyleShapeRadius>(),
center.y, aRefBox.y, aRefBox.y + aRefBox.height);
} else {
ry = nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.height);