Bug 1288626 Part 2 - Use basic shape enum class defined in nsStyleConsts.h. r=heycam

Rename StyleBasicShape to StyleBasicShapeType in nsStyleConsts.h, and
replace the old enum nsStyleBasicShape::Type by the enum class
StyleBasicShapeType.

Also, replace NS_ASSERTION() by MOZ_ASSERT().

MozReview-Commit-ID: EuS4ZtYKsk6

--HG--
extra : rebase_source : b6cb68f91c545cef283c97de222111d3acb64b02
This commit is contained in:
Ting-Yu Lin 2016-07-27 17:59:33 +08:00
Родитель 30bb6dcff2
Коммит d5b06eeac7
7 изменённых файлов: 40 добавлений и 45 удалений

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

@ -3503,8 +3503,8 @@ StyleClipBasicShapeToCSSArray(const nsStyleClipPath& aClipPath,
nsCSSKeyword functionName = shape->GetShapeTypeName(); nsCSSKeyword functionName = shape->GetShapeTypeName();
RefPtr<nsCSSValue::Array> functionArray; RefPtr<nsCSSValue::Array> functionArray;
switch (shape->GetShapeType()) { switch (shape->GetShapeType()) {
case nsStyleBasicShape::Type::eCircle: case StyleBasicShapeType::Circle:
case nsStyleBasicShape::Type::eEllipse: { case StyleBasicShapeType::Ellipse: {
const nsTArray<nsStyleCoord>& coords = shape->Coordinates(); const nsTArray<nsStyleCoord>& coords = shape->Coordinates();
MOZ_ASSERT(coords.Length() == ShapeArgumentCount(functionName) - 1, MOZ_ASSERT(coords.Length() == ShapeArgumentCount(functionName) - 1,
"Unexpected radii count"); "Unexpected radii count");
@ -3525,7 +3525,7 @@ StyleClipBasicShapeToCSSArray(const nsStyleClipPath& aClipPath,
functionArray->Item(functionArray->Count() - 1)); functionArray->Item(functionArray->Count() - 1));
break; break;
} }
case nsStyleBasicShape::Type::ePolygon: { case StyleBasicShapeType::Polygon: {
functionArray = functionArray =
aResult->Item(0).InitFunction(functionName, aResult->Item(0).InitFunction(functionName,
ShapeArgumentCount(functionName)); ShapeArgumentCount(functionName));
@ -3546,7 +3546,7 @@ StyleClipBasicShapeToCSSArray(const nsStyleClipPath& aClipPath,
} }
break; break;
} }
case nsStyleBasicShape::Type::eInset: { case StyleBasicShapeType::Inset: {
const nsTArray<nsStyleCoord>& coords = shape->Coordinates(); const nsTArray<nsStyleCoord>& coords = shape->Coordinates();
MOZ_ASSERT(coords.Length() == ShapeArgumentCount(functionName) - 1, MOZ_ASSERT(coords.Length() == ShapeArgumentCount(functionName) - 1,
"Unexpected offset count"); "Unexpected offset count");

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

@ -5920,7 +5920,7 @@ nsComputedDOMStyle::CreatePrimitiveValueForBasicShape(
{ {
MOZ_ASSERT(aStyleBasicShape, "Expect a valid basic shape pointer!"); MOZ_ASSERT(aStyleBasicShape, "Expect a valid basic shape pointer!");
nsStyleBasicShape::Type type = aStyleBasicShape->GetShapeType(); StyleBasicShapeType type = aStyleBasicShape->GetShapeType();
// Shape function name and opening parenthesis. // Shape function name and opening parenthesis.
nsAutoString shapeFunctionString; nsAutoString shapeFunctionString;
AppendASCIItoUTF16(nsCSSKeywords::GetStringValue( AppendASCIItoUTF16(nsCSSKeywords::GetStringValue(
@ -5928,7 +5928,7 @@ nsComputedDOMStyle::CreatePrimitiveValueForBasicShape(
shapeFunctionString); shapeFunctionString);
shapeFunctionString.Append('('); shapeFunctionString.Append('(');
switch (type) { switch (type) {
case nsStyleBasicShape::Type::ePolygon: { case StyleBasicShapeType::Polygon: {
bool hasEvenOdd = aStyleBasicShape->GetFillRule() == bool hasEvenOdd = aStyleBasicShape->GetFillRule() ==
NS_STYLE_FILL_RULE_EVENODD; NS_STYLE_FILL_RULE_EVENODD;
if (hasEvenOdd) { if (hasEvenOdd) {
@ -5950,11 +5950,11 @@ nsComputedDOMStyle::CreatePrimitiveValueForBasicShape(
} }
break; break;
} }
case nsStyleBasicShape::Type::eCircle: case StyleBasicShapeType::Circle:
case nsStyleBasicShape::Type::eEllipse: { case StyleBasicShapeType::Ellipse: {
const nsTArray<nsStyleCoord>& radii = aStyleBasicShape->Coordinates(); const nsTArray<nsStyleCoord>& radii = aStyleBasicShape->Coordinates();
MOZ_ASSERT(radii.Length() == MOZ_ASSERT(radii.Length() ==
(type == nsStyleBasicShape::Type::eCircle ? 1 : 2), (type == StyleBasicShapeType::Circle ? 1 : 2),
"wrong number of radii"); "wrong number of radii");
for (size_t i = 0; i < radii.Length(); ++i) { for (size_t i = 0; i < radii.Length(); ++i) {
nsAutoString radius; nsAutoString radius;
@ -5975,7 +5975,7 @@ nsComputedDOMStyle::CreatePrimitiveValueForBasicShape(
shapeFunctionString.Append(positionString); shapeFunctionString.Append(positionString);
break; break;
} }
case nsStyleBasicShape::Type::eInset: { case StyleBasicShapeType::Inset: {
BoxValuesToString(shapeFunctionString, aStyleBasicShape->Coordinates()); BoxValuesToString(shapeFunctionString, aStyleBasicShape->Coordinates());
if (aStyleBasicShape->HasRadius()) { if (aStyleBasicShape->HasRadius()) {
shapeFunctionString.AppendLiteral(" round "); shapeFunctionString.AppendLiteral(" round ");

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

@ -9595,7 +9595,7 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
if (functionName == eCSSKeyword_polygon) { if (functionName == eCSSKeyword_polygon) {
MOZ_ASSERT(!basicShape, "did not expect value"); MOZ_ASSERT(!basicShape, "did not expect value");
basicShape = new nsStyleBasicShape(nsStyleBasicShape::ePolygon); basicShape = new nsStyleBasicShape(StyleBasicShapeType::Polygon);
MOZ_ASSERT(shapeFunction->Count() > 1, MOZ_ASSERT(shapeFunction->Count() > 1,
"polygon has wrong number of arguments"); "polygon has wrong number of arguments");
size_t j = 1; size_t j = 1;
@ -9626,17 +9626,17 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
} }
} else if (functionName == eCSSKeyword_circle || } else if (functionName == eCSSKeyword_circle ||
functionName == eCSSKeyword_ellipse) { functionName == eCSSKeyword_ellipse) {
nsStyleBasicShape::Type type = functionName == eCSSKeyword_circle ? StyleBasicShapeType type = functionName == eCSSKeyword_circle ?
nsStyleBasicShape::eCircle : StyleBasicShapeType::Circle :
nsStyleBasicShape::eEllipse; StyleBasicShapeType::Ellipse;
MOZ_ASSERT(!basicShape, "did not expect value"); MOZ_ASSERT(!basicShape, "did not expect value");
basicShape = new nsStyleBasicShape(type); basicShape = new nsStyleBasicShape(type);
const int32_t mask = SETCOORD_PERCENT | SETCOORD_LENGTH | const int32_t mask = SETCOORD_PERCENT | SETCOORD_LENGTH |
SETCOORD_STORE_CALC | SETCOORD_ENUMERATED; SETCOORD_STORE_CALC | SETCOORD_ENUMERATED;
size_t count = type == nsStyleBasicShape::eCircle ? 2 : 3; size_t count = type == StyleBasicShapeType::Circle ? 2 : 3;
MOZ_ASSERT(shapeFunction->Count() == count + 1, MOZ_ASSERT(shapeFunction->Count() == count + 1,
"unexpected arguments count"); "unexpected arguments count");
MOZ_ASSERT(type == nsStyleBasicShape::eCircle || MOZ_ASSERT(type == StyleBasicShapeType::Circle ||
(shapeFunction->Item(1).GetUnit() == eCSSUnit_Null) == (shapeFunction->Item(1).GetUnit() == eCSSUnit_Null) ==
(shapeFunction->Item(2).GetUnit() == eCSSUnit_Null), (shapeFunction->Item(2).GetUnit() == eCSSUnit_Null),
"ellipse should have two radii or none"); "ellipse should have two radii or none");
@ -9666,7 +9666,7 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
} }
} else if (functionName == eCSSKeyword_inset) { } else if (functionName == eCSSKeyword_inset) {
MOZ_ASSERT(!basicShape, "did not expect value"); MOZ_ASSERT(!basicShape, "did not expect value");
basicShape = new nsStyleBasicShape(nsStyleBasicShape::eInset); basicShape = new nsStyleBasicShape(StyleBasicShapeType::Inset);
MOZ_ASSERT(shapeFunction->Count() == 6, MOZ_ASSERT(shapeFunction->Count() == 6,
"inset function has wrong number of arguments"); "inset function has wrong number of arguments");
MOZ_ASSERT(shapeFunction->Item(1).GetUnit() != eCSSUnit_Null, MOZ_ASSERT(shapeFunction->Item(1).GetUnit() != eCSSUnit_Null,

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

@ -54,8 +54,8 @@ static inline css::Side operator++(css::Side& side, int) {
#define NS_SIDE_TO_HALF_CORNER(side_, second_, parallel_) \ #define NS_SIDE_TO_HALF_CORNER(side_, second_, parallel_) \
((((side_) + !!(second_))*2 + ((side_) + !(parallel_))%2) % 8) ((((side_) + !!(second_))*2 + ((side_) + !(parallel_))%2) % 8)
// Basic Shapes (currently unused) // Basic shapes
enum class StyleBasicShape : uint8_t{ enum class StyleBasicShapeType : uint8_t {
Polygon, Polygon,
Circle, Circle,
Ellipse, Ellipse,

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

@ -1092,13 +1092,13 @@ nsCSSKeyword
nsStyleBasicShape::GetShapeTypeName() const nsStyleBasicShape::GetShapeTypeName() const
{ {
switch (mType) { switch (mType) {
case nsStyleBasicShape::Type::ePolygon: case StyleBasicShapeType::Polygon:
return eCSSKeyword_polygon; return eCSSKeyword_polygon;
case nsStyleBasicShape::Type::eCircle: case StyleBasicShapeType::Circle:
return eCSSKeyword_circle; return eCSSKeyword_circle;
case nsStyleBasicShape::Type::eEllipse: case StyleBasicShapeType::Ellipse:
return eCSSKeyword_ellipse; return eCSSKeyword_ellipse;
case nsStyleBasicShape::Type::eInset: case StyleBasicShapeType::Inset:
return eCSSKeyword_inset; return eCSSKeyword_inset;
} }
NS_NOTREACHED("unexpected type"); NS_NOTREACHED("unexpected type");

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

@ -3441,44 +3441,39 @@ namespace mozilla {
class nsStyleBasicShape final class nsStyleBasicShape final
{ {
public: public:
enum Type { explicit nsStyleBasicShape(StyleBasicShapeType type)
eInset,
eCircle,
eEllipse,
ePolygon
};
explicit nsStyleBasicShape(Type type)
: mType(type), : mType(type),
mFillRule(NS_STYLE_FILL_RULE_NONZERO) mFillRule(NS_STYLE_FILL_RULE_NONZERO)
{ {
mPosition.SetInitialPercentValues(0.5f); mPosition.SetInitialPercentValues(0.5f);
} }
Type GetShapeType() const { return mType; } StyleBasicShapeType GetShapeType() const { return mType; }
nsCSSKeyword GetShapeTypeName() const; nsCSSKeyword GetShapeTypeName() const;
int32_t GetFillRule() const { return mFillRule; } int32_t GetFillRule() const { return mFillRule; }
void SetFillRule(int32_t aFillRule) void SetFillRule(int32_t aFillRule)
{ {
NS_ASSERTION(mType == ePolygon, "expected polygon"); MOZ_ASSERT(mType == StyleBasicShapeType::Polygon, "expected polygon");
mFillRule = aFillRule; mFillRule = aFillRule;
} }
typedef nsStyleImageLayers::Position Position; typedef nsStyleImageLayers::Position Position;
Position& GetPosition() { Position& GetPosition() {
NS_ASSERTION(mType == eCircle || mType == eEllipse, MOZ_ASSERT(mType == StyleBasicShapeType::Circle ||
"expected circle or ellipse"); mType == StyleBasicShapeType::Ellipse,
"expected circle or ellipse");
return mPosition; return mPosition;
} }
const Position& GetPosition() const { const Position& GetPosition() const {
NS_ASSERTION(mType == eCircle || mType == eEllipse, MOZ_ASSERT(mType == StyleBasicShapeType::Circle ||
"expected circle or ellipse"); mType == StyleBasicShapeType::Ellipse,
"expected circle or ellipse");
return mPosition; return mPosition;
} }
bool HasRadius() const { bool HasRadius() const {
NS_ASSERTION(mType == eInset, "expected inset"); MOZ_ASSERT(mType == StyleBasicShapeType::Inset, "expected inset");
nsStyleCoord zero; nsStyleCoord zero;
zero.SetCoordValue(0); zero.SetCoordValue(0);
NS_FOR_CSS_HALF_CORNERS(corner) { NS_FOR_CSS_HALF_CORNERS(corner) {
@ -3489,11 +3484,11 @@ public:
return false; return false;
} }
nsStyleCorners& GetRadius() { nsStyleCorners& GetRadius() {
NS_ASSERTION(mType == eInset, "expected inset"); MOZ_ASSERT(mType == StyleBasicShapeType::Inset, "expected inset");
return mRadius; return mRadius;
} }
const nsStyleCorners& GetRadius() const { const nsStyleCorners& GetRadius() const {
NS_ASSERTION(mType == eInset, "expected inset"); MOZ_ASSERT(mType == StyleBasicShapeType::Inset, "expected inset");
return mRadius; return mRadius;
} }
@ -3526,7 +3521,7 @@ public:
private: private:
~nsStyleBasicShape() {} ~nsStyleBasicShape() {}
Type mType; StyleBasicShapeType mType;
int32_t mFillRule; int32_t mFillRule;
// mCoordinates has coordinates for polygon or radii for // mCoordinates has coordinates for polygon or radii for

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

@ -94,13 +94,13 @@ nsCSSClipPathInstance::CreateClipPath(DrawTarget* aDrawTarget)
nsStyleBasicShape* basicShape = mClipPathStyle.GetBasicShape(); nsStyleBasicShape* basicShape = mClipPathStyle.GetBasicShape();
switch (basicShape->GetShapeType()) { switch (basicShape->GetShapeType()) {
case nsStyleBasicShape::Type::eCircle: case StyleBasicShapeType::Circle:
return CreateClipPathCircle(aDrawTarget, r); return CreateClipPathCircle(aDrawTarget, r);
case nsStyleBasicShape::Type::eEllipse: case StyleBasicShapeType::Ellipse:
return CreateClipPathEllipse(aDrawTarget, r); return CreateClipPathEllipse(aDrawTarget, r);
case nsStyleBasicShape::Type::ePolygon: case StyleBasicShapeType::Polygon:
return CreateClipPathPolygon(aDrawTarget, r); return CreateClipPathPolygon(aDrawTarget, r);
case nsStyleBasicShape::Type::eInset: case StyleBasicShapeType::Inset:
// XXXkrit support all basic shapes // XXXkrit support all basic shapes
break; break;
default: default: