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
This commit is contained in:
Ting-Yu Lin 2016-08-09 00:15:04 +08:00
Родитель 9eec95b855
Коммит 829dd22e89
7 изменённых файлов: 40 добавлений и 45 удалений

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

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

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

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

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

@ -9595,7 +9595,7 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
if (functionName == eCSSKeyword_polygon) {
MOZ_ASSERT(!basicShape, "did not expect value");
basicShape = new nsStyleBasicShape(nsStyleBasicShape::ePolygon);
basicShape = new nsStyleBasicShape(StyleBasicShapeType::Polygon);
MOZ_ASSERT(shapeFunction->Count() > 1,
"polygon has wrong number of arguments");
size_t j = 1;
@ -9626,17 +9626,17 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
}
} else if (functionName == eCSSKeyword_circle ||
functionName == eCSSKeyword_ellipse) {
nsStyleBasicShape::Type type = functionName == eCSSKeyword_circle ?
nsStyleBasicShape::eCircle :
nsStyleBasicShape::eEllipse;
StyleBasicShapeType type = functionName == eCSSKeyword_circle ?
StyleBasicShapeType::Circle :
StyleBasicShapeType::Ellipse;
MOZ_ASSERT(!basicShape, "did not expect value");
basicShape = new nsStyleBasicShape(type);
const int32_t mask = SETCOORD_PERCENT | SETCOORD_LENGTH |
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,
"unexpected arguments count");
MOZ_ASSERT(type == nsStyleBasicShape::eCircle ||
MOZ_ASSERT(type == StyleBasicShapeType::Circle ||
(shapeFunction->Item(1).GetUnit() == eCSSUnit_Null) ==
(shapeFunction->Item(2).GetUnit() == eCSSUnit_Null),
"ellipse should have two radii or none");
@ -9666,7 +9666,7 @@ GetStyleBasicShapeFromCSSValue(const nsCSSValue& aValue,
}
} else if (functionName == eCSSKeyword_inset) {
MOZ_ASSERT(!basicShape, "did not expect value");
basicShape = new nsStyleBasicShape(nsStyleBasicShape::eInset);
basicShape = new nsStyleBasicShape(StyleBasicShapeType::Inset);
MOZ_ASSERT(shapeFunction->Count() == 6,
"inset function has wrong number of arguments");
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_) \
((((side_) + !!(second_))*2 + ((side_) + !(parallel_))%2) % 8)
// Basic Shapes (currently unused)
enum class StyleBasicShape : uint8_t{
// Basic shapes
enum class StyleBasicShapeType : uint8_t {
Polygon,
Circle,
Ellipse,

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

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

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

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

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

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