Bug 1365926, part 1 - Support 'context-fill-opacity'/'context-stroke-opacity' as SVG-as-an-image context properties. r=heycam

MozReview-Commit-ID: 2YHjwCB02jV
This commit is contained in:
Jonathan Watt 2017-05-18 12:47:20 +01:00
Родитель c2cc55b60e
Коммит 2642ec495c
5 изменённых файлов: 40 добавлений и 6 удалений

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

@ -9648,6 +9648,10 @@ nsRuleNode::ComputeSVGData(void* aStartStruct,
svg->mContextPropsBits |= NS_STYLE_CONTEXT_PROPERTY_FILL;
} else if (atom == nsGkAtoms::stroke) {
svg->mContextPropsBits |= NS_STYLE_CONTEXT_PROPERTY_STROKE;
} else if (atom == nsGkAtoms::fill_opacity) {
svg->mContextPropsBits |= NS_STYLE_CONTEXT_PROPERTY_FILL_OPACITY;
} else if (atom == nsGkAtoms::stroke_opacity) {
svg->mContextPropsBits |= NS_STYLE_CONTEXT_PROPERTY_STROKE_OPACITY;
}
}
break;

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

@ -1060,6 +1060,8 @@ enum class StyleGridTrackBreadth : uint8_t {
// -moz-context-properties
#define NS_STYLE_CONTEXT_PROPERTY_FILL (1 << 0)
#define NS_STYLE_CONTEXT_PROPERTY_STROKE (1 << 1)
#define NS_STYLE_CONTEXT_PROPERTY_FILL_OPACITY (1 << 2)
#define NS_STYLE_CONTEXT_PROPERTY_STROKE_OPACITY (1 << 3)
/*
* -moz-window-shadow

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

@ -395,6 +395,14 @@ SVGEmbeddingContextPaint::Hash() const
hash = HashGeneric(hash, mStroke->ToABGR());
}
if (mFillOpacity != 1.0f) {
hash = HashGeneric(hash, mFillOpacity);
}
if (mStrokeOpacity != 1.0f) {
hash = HashGeneric(hash, mStrokeOpacity);
}
return hash;
}

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

@ -251,7 +251,10 @@ class SVGEmbeddingContextPaint : public SVGContextPaint
typedef gfx::Color Color;
public:
SVGEmbeddingContextPaint() {}
SVGEmbeddingContextPaint()
: mFillOpacity(1.0f)
, mStrokeOpacity(1.0f)
{}
bool operator==(const SVGEmbeddingContextPaint& aOther) const {
MOZ_ASSERT(GetStrokeWidth() == aOther.GetStrokeWidth() &&
@ -259,7 +262,10 @@ public:
GetStrokeDashArray() == aOther.GetStrokeDashArray(),
"We don't currently include these in the context information "
"from an embedding element");
return mFill == aOther.mFill && mStroke == aOther.mStroke;
return mFill == aOther.mFill &&
mStroke == aOther.mStroke &&
mFillOpacity == aOther.mFillOpacity &&
mStrokeOpacity == aOther.mStrokeOpacity;
}
void SetFill(nscolor aFill) {
@ -283,14 +289,18 @@ public:
GetStrokePattern(const DrawTarget* aDrawTarget, float aStrokeOpacity,
const gfxMatrix& aCTM, imgDrawingParams& aImgParams) override;
void SetFillOpacity(float aOpacity) {
mFillOpacity = aOpacity;
}
float GetFillOpacity() const override {
// Always 1.0f since we don't currently allow 'context-fill-opacity'
return 1.0f;
return mFillOpacity;
};
void SetStrokeOpacity(float aOpacity) {
mStrokeOpacity = aOpacity;
}
float GetStrokeOpacity() const override {
// Always 1.0f since we don't currently allow 'context-stroke-opacity'
return 1.0f;
return mStrokeOpacity;
};
uint32_t Hash() const override;
@ -298,6 +308,8 @@ public:
private:
Maybe<Color> mFill;
Maybe<Color> mStroke;
float mFillOpacity;
float mStrokeOpacity;
};
} // namespace mozilla

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

@ -49,6 +49,14 @@ SVGImageContext::MaybeStoreContextPaint(Maybe<SVGImageContext>& aContext,
haveContextPaint = true;
contextPaint->SetStroke(style->mStroke.GetColor());
}
if (style->mContextPropsBits & NS_STYLE_CONTEXT_PROPERTY_FILL_OPACITY) {
haveContextPaint = true;
contextPaint->SetFillOpacity(style->mFillOpacity);
}
if (style->mContextPropsBits & NS_STYLE_CONTEXT_PROPERTY_STROKE_OPACITY) {
haveContextPaint = true;
contextPaint->SetStrokeOpacity(style->mStrokeOpacity);
}
if (haveContextPaint) {
if (!aContext) {