Bug 719286 - Add support for objectfill and objectstroke values to CSS parser r=dbaron

This commit is contained in:
Edwin Flores 2012-09-06 16:58:46 +12:00
parent 251aabceb4
commit 4e81980066
12 changed files with 64 additions and 17 deletions

View File

@ -206,6 +206,9 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
#define NS_COLOR_MOZ_HYPERLINKTEXT -4
#define NS_COLOR_MOZ_VISITEDHYPERLINKTEXT -5
#define NS_COLOR_MOZ_ACTIVEHYPERLINKTEXT -6
// Only valid as paints in SVG glyphs
#define NS_COLOR_OBJECTFILL -7
#define NS_COLOR_OBJECTSTROKE -8
// See nsStyleDisplay
#define NS_STYLE_ANIMATION_DIRECTION_NORMAL 0

View File

@ -130,6 +130,8 @@ CSS_KEY(-moz-min-content, _moz_min_content)
CSS_KEY(-moz-myanmar, _moz_myanmar)
CSS_KEY(-moz-nativehyperlinktext, _moz_nativehyperlinktext)
CSS_KEY(-moz-none, _moz_none)
CSS_KEY(-moz-objectfill, _moz_objectfill)
CSS_KEY(-moz-objectstroke, _moz_objectstroke)
CSS_KEY(-moz-oddtreerow, _moz_oddtreerow)
CSS_KEY(-moz-oriya, _moz_oriya)
CSS_KEY(-moz-persian, _moz_persian)

View File

@ -9821,16 +9821,21 @@ bool
CSSParserImpl::ParsePaint(nsCSSProperty aPropID)
{
nsCSSValue x, y;
if (!ParseVariant(x, VARIANT_HC | VARIANT_NONE | VARIANT_URL, nullptr))
if (!ParseVariant(x, VARIANT_HCK | VARIANT_NONE | VARIANT_URL,
nsCSSProps::kObjectPatternKTable)) {
return false;
if (x.GetUnit() == eCSSUnit_URL) {
}
bool canHaveFallback = x.GetUnit() == eCSSUnit_URL ||
x.GetUnit() == eCSSUnit_Enumerated;
if (canHaveFallback) {
if (!ParseVariant(y, VARIANT_COLOR | VARIANT_NONE, nullptr))
y.SetNoneValue();
}
if (!ExpectEndProperty())
return false;
if (x.GetUnit() != eCSSUnit_URL) {
if (!canHaveFallback) {
AppendValue(aPropID, x);
} else {
nsCSSValue val;

View File

@ -3094,7 +3094,7 @@ CSS_PROP_SVG(
CSS_PROPERTY_PARSE_FUNCTION,
"",
0,
nullptr,
kObjectPatternKTable,
offsetof(nsStyleSVG, mFill),
eStyleAnimType_PaintServer)
CSS_PROP_SVG(
@ -3250,7 +3250,7 @@ CSS_PROP_SVG(
CSS_PROPERTY_PARSE_FUNCTION,
"",
0,
nullptr,
kObjectPatternKTable,
offsetof(nsStyleSVG, mStroke),
eStyleAnimType_PaintServer)
CSS_PROP_SVG(

View File

@ -773,6 +773,7 @@ const int32_t nsCSSProps::kClearKTable[] = {
eCSSKeyword_UNKNOWN,-1
};
// See also kObjectPatternKTable for SVG paint-specific values
const int32_t nsCSSProps::kColorKTable[] = {
eCSSKeyword_activeborder, LookAndFeel::eColorID_activeborder,
eCSSKeyword_activecaption, LookAndFeel::eColorID_activecaption,
@ -1147,6 +1148,12 @@ const int32_t nsCSSProps::kListStyleKTable[] = {
eCSSKeyword_UNKNOWN,-1
};
const int32_t nsCSSProps::kObjectPatternKTable[] = {
eCSSKeyword__moz_objectfill, NS_COLOR_OBJECTFILL,
eCSSKeyword__moz_objectstroke, NS_COLOR_OBJECTSTROKE,
eCSSKeyword_UNKNOWN,-1
};
const int32_t nsCSSProps::kOrientKTable[] = {
eCSSKeyword_horizontal, NS_STYLE_ORIENT_HORIZONTAL,
eCSSKeyword_vertical, NS_STYLE_ORIENT_VERTICAL,

View File

@ -390,6 +390,7 @@ public:
static const int32_t kLineHeightKTable[];
static const int32_t kListStylePositionKTable[];
static const int32_t kListStyleKTable[];
static const int32_t kObjectPatternKTable[];
static const int32_t kOrientKTable[];
static const int32_t kOutlineStyleKTable[];
static const int32_t kOutlineColorKTable[];

View File

@ -3947,6 +3947,16 @@ nsComputedDOMStyle::GetSVGPaintFor(bool aFill)
SetToRGBAColor(fallback, paint->mFallbackColor);
return valueList;
}
case eStyleSVGPaintType_ObjectFill:
{
val->SetIdent(eCSSKeyword__moz_objectfill);
break;
}
case eStyleSVGPaintType_ObjectStroke:
{
val->SetIdent(eCSSKeyword__moz_objectstroke);
break;
}
}
return val;

View File

@ -7132,12 +7132,27 @@ SetSVGPaint(const nsCSSValue& aValue, const nsStyleSVGPaint& parentPaint,
aResult.mPaint.mColor = color;
} else if (aValue.GetUnit() == eCSSUnit_Pair) {
const nsCSSValuePair& pair = aValue.GetPairValue();
NS_ABORT_IF_FALSE(pair.mXValue.GetUnit() == eCSSUnit_URL,
"malformed paint server value");
aResult.SetType(eStyleSVGPaintType_Server);
aResult.mPaint.mPaintServer = pair.mXValue.GetURLValue();
NS_IF_ADDREF(aResult.mPaint.mPaintServer);
if (pair.mXValue.GetUnit() == eCSSUnit_URL) {
aResult.SetType(eStyleSVGPaintType_Server);
aResult.mPaint.mPaintServer = pair.mXValue.GetURLValue();
NS_IF_ADDREF(aResult.mPaint.mPaintServer);
} else if (pair.mXValue.GetUnit() == eCSSUnit_Enumerated) {
switch (pair.mXValue.GetIntValue()) {
case NS_COLOR_OBJECTFILL:
aResult.SetType(eStyleSVGPaintType_ObjectFill);
break;
case NS_COLOR_OBJECTSTROKE:
aResult.SetType(eStyleSVGPaintType_ObjectStroke);
break;
default:
NS_NOTREACHED("unknown keyword as paint server value");
}
} else {
NS_NOTREACHED("malformed paint server value");
}
if (pair.mYValue.GetUnit() == eCSSUnit_None) {
aResult.mFallbackColor = NS_RGBA(0, 0, 0, 0);

View File

@ -1111,9 +1111,9 @@ bool nsStyleSVGPaint::operator==(const nsStyleSVGPaint& aOther) const
if (mType == eStyleSVGPaintType_Server)
return EqualURIs(mPaint.mPaintServer, aOther.mPaint.mPaintServer) &&
mFallbackColor == aOther.mFallbackColor;
if (mType == eStyleSVGPaintType_None)
return true;
return mPaint.mColor == aOther.mPaint.mColor;
if (mType == eStyleSVGPaintType_Color)
return mPaint.mColor == aOther.mPaint.mColor;
return true;
}

View File

@ -2163,7 +2163,9 @@ protected:
enum nsStyleSVGPaintType {
eStyleSVGPaintType_None = 1,
eStyleSVGPaintType_Color,
eStyleSVGPaintType_Server
eStyleSVGPaintType_Server,
eStyleSVGPaintType_ObjectFill,
eStyleSVGPaintType_ObjectStroke
};
struct nsStyleSVGPaint

View File

@ -3627,7 +3627,7 @@ var gCSSProperties = {
type: CSS_TYPE_LONGHAND,
prerequisites: { "color": "blue" },
initial_values: [ "black", "#000", "#000000", "rgb(0,0,0)", "rgba(0,0,0,1)" ],
other_values: [ "green", "#fc3", "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green', "none", "currentColor" ],
other_values: [ "green", "#fc3", "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green', "none", "currentColor", "-moz-objectFill", "-moz-objectStroke" ],
invalid_values: [ "000000", "ff00ff" ]
},
"fill-opacity": {
@ -3759,7 +3759,7 @@ var gCSSProperties = {
inherited: true,
type: CSS_TYPE_LONGHAND,
initial_values: [ "none" ],
other_values: [ "black", "#000", "#000000", "rgb(0,0,0)", "rgba(0,0,0,1)", "green", "#fc3", "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green', "currentColor" ],
other_values: [ "black", "#000", "#000000", "rgb(0,0,0)", "rgba(0,0,0,1)", "green", "#fc3", "url('#myserver')", "url(foo.svg#myserver)", 'url("#myserver") green', "currentColor", "-moz-objectFill", "-moz-objectStroke" ],
invalid_values: [ "000000", "ff00ff" ]
},
"stroke-dasharray": {

View File

@ -1842,7 +1842,9 @@ nsSVGUtils::GetFallbackOrPaintColor(gfxContext *aContext, nsStyleContext *aStyle
{
const nsStyleSVGPaint &paint = aStyleContext->GetStyleSVG()->*aFillOrStroke;
nsStyleContext *styleIfVisited = aStyleContext->GetStyleIfVisited();
bool isServer = paint.mType == eStyleSVGPaintType_Server;
bool isServer = paint.mType == eStyleSVGPaintType_Server ||
paint.mType == eStyleSVGPaintType_ObjectFill ||
paint.mType == eStyleSVGPaintType_ObjectStroke;
nscolor color = isServer ? paint.mFallbackColor : paint.mPaint.mColor;
if (styleIfVisited) {
const nsStyleSVGPaint &paintIfVisited =