Bug 941300 - Make circle radial-gradient invalid if two radii values are given. r=dbaron

This commit is contained in:
Masatoshi Kimura 2013-12-14 13:22:48 +09:00
parent 4458b855ed
commit 77986a212e
3 changed files with 70 additions and 13 deletions

View File

@ -6896,10 +6896,26 @@ CSSParserImpl::ParseRadialGradient(nsCSSValue& aValue, bool aIsRepeating,
nsCSSProps::kRadialGradientShapeKTable);
}
} else if (!aIsLegacy) {
// Save RadialShape before parsing RadiusX because RadialShape and
// RadiusX share the storage.
int32_t shape =
cssGradient->GetRadialShape().GetUnit() == eCSSUnit_Enumerated ?
cssGradient->GetRadialShape().GetIntValue() : -1;
// <length> | [<length> | <percentage>]{2}
cssGradient->mIsExplicitSize = true;
haveSize =
ParseNonNegativeVariant(cssGradient->GetRadiusX(), VARIANT_LP, nullptr);
if (haveSize) {
if (!haveSize) {
// It was not an explicit size after all.
// Note that ParseNonNegativeVariant may have put something
// invalid into our storage, but only in the case where it was
// rejected only for being negative. Since this means the token
// was a length or a percentage, we know it's not valid syntax
// (which must be a comma, the 'at' keyword, or a color), so we
// know this value will be dropped. This means it doesn't matter
// that we have something invalid in our storage.
cssGradient->mIsExplicitSize = false;
} else {
// vertical extent is optional
bool haveYSize =
ParseNonNegativeVariant(cssGradient->GetRadiusY(), VARIANT_LP, nullptr);
@ -6907,10 +6923,10 @@ CSSParserImpl::ParseRadialGradient(nsCSSValue& aValue, bool aIsRepeating,
nsCSSValue shapeValue;
haveShape = ParseVariant(shapeValue, VARIANT_KEYWORD,
nsCSSProps::kRadialGradientShapeKTable);
if (haveShape) {
shape = shapeValue.GetIntValue();
}
}
int32_t shape =
cssGradient->GetRadialShape().GetUnit() == eCSSUnit_Enumerated ?
cssGradient->GetRadialShape().GetIntValue() : -1;
if (haveYSize
? shape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR
: cssGradient->GetRadiusX().GetUnit() == eCSSUnit_Percent ||
@ -6918,7 +6934,6 @@ CSSParserImpl::ParseRadialGradient(nsCSSValue& aValue, bool aIsRepeating,
SkipUntil(')');
return false;
}
cssGradient->mIsExplicitSize = true;
}
}

View File

@ -1142,14 +1142,46 @@ struct nsCSSValueGradient {
private:
nsCSSValue mRadialValues[2];
public:
nsCSSValue& GetRadialShape() { return mRadialValues[0]; }
const nsCSSValue& GetRadialShape() const { return mRadialValues[0]; }
nsCSSValue& GetRadialSize() { return mRadialValues[1]; }
const nsCSSValue& GetRadialSize() const { return mRadialValues[1]; }
nsCSSValue& GetRadiusX() { return mRadialValues[0]; }
const nsCSSValue& GetRadiusX() const { return mRadialValues[0]; }
nsCSSValue& GetRadiusY() { return mRadialValues[1]; }
const nsCSSValue& GetRadiusY() const { return mRadialValues[1]; }
nsCSSValue& GetRadialShape()
{
MOZ_ASSERT(!mIsExplicitSize);
return mRadialValues[0];
}
const nsCSSValue& GetRadialShape() const
{
MOZ_ASSERT(!mIsExplicitSize);
return mRadialValues[0];
}
nsCSSValue& GetRadialSize()
{
MOZ_ASSERT(!mIsExplicitSize);
return mRadialValues[1];
}
const nsCSSValue& GetRadialSize() const
{
MOZ_ASSERT(!mIsExplicitSize);
return mRadialValues[1];
}
nsCSSValue& GetRadiusX()
{
MOZ_ASSERT(mIsExplicitSize);
return mRadialValues[0];
}
const nsCSSValue& GetRadiusX() const
{
MOZ_ASSERT(mIsExplicitSize);
return mRadialValues[0];
}
nsCSSValue& GetRadiusY()
{
MOZ_ASSERT(mIsExplicitSize);
return mRadialValues[1];
}
const nsCSSValue& GetRadiusY() const
{
MOZ_ASSERT(mIsExplicitSize);
return mRadialValues[1];
}
InfallibleTArray<nsCSSValueGradientStop> mStops;

View File

@ -1513,10 +1513,12 @@ var gCSSProperties = {
"radial-gradient(43px 50%, red, blue)",
"radial-gradient(50% 43px, red, blue)",
"radial-gradient(circle 43px, red, blue)",
"radial-gradient(43px circle, red, blue)",
"radial-gradient(ellipse 43px 43px, red, blue)",
"radial-gradient(ellipse 50% 50%, red, blue)",
"radial-gradient(ellipse 43px 50%, red, blue)",
"radial-gradient(ellipse 50% 43px, red, blue)",
"radial-gradient(50% 43px ellipse, red, blue)",
"radial-gradient(farthest-corner at top left, red, blue)",
"radial-gradient(ellipse closest-corner at 45px, red, blue)",
@ -1818,6 +1820,14 @@ var gCSSProperties = {
"-moz-repeating-radial-gradient(ellipse at 45px closest-corner, red, blue)",
"-moz-repeating-radial-gradient(circle at 45px farthest-side, red, blue)",
"radial-gradient(circle 175px 20px, black, white)",
"radial-gradient(175px 20px circle, black, white)",
"radial-gradient(ellipse 175px, black, white)",
"radial-gradient(175px ellipse, black, white)",
"radial-gradient(50%, red, blue)",
"radial-gradient(circle 50%, red, blue)",
"radial-gradient(50% circle, red, blue)",
/* Valid only when prefixed */
"linear-gradient(top left, red, blue)",
"linear-gradient(0 0, red, blue)",