Bug 1324700 - Add a function which is equivalent to ResolveStyleForFilter for servo. r?heycam
Also ResolveStyleForFilter is renamed to ResolveFilterStyle for consistency.
MozReview-Commit-ID: IEOxNexpnl5
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -2919,20 +2919,20 @@ CreateFilterDeclaration(const nsAString&
{
bool dummy;
return CreateDeclaration(aNode,
eCSSProperty_filter, aFilter, aOutFilterChanged,
eCSSProperty_UNKNOWN, EmptyString(), &dummy);
}
static already_AddRefed<nsStyleContext>
-ResolveStyleForFilter(const nsAString& aFilterString,
- nsIPresShell* aPresShell,
- nsStyleContext* aParentContext,
- ErrorResult& aError)
+ResolveFilterStyle(const nsAString& aFilterString,
+ nsIPresShell* aPresShell,
+ nsStyleContext* aParentContext,
+ ErrorResult& aError)
{
nsStyleSet* styleSet = aPresShell->StyleSet()->GetAsGecko();
if (!styleSet) {
// XXXheycam ServoStyleSets do not support resolving style from a list of
// rules yet.
NS_ERROR("stylo: cannot resolve style for canvas from a ServoStyleSet yet");
aError.Throw(NS_ERROR_FAILURE);
return nullptr;
@@ -2958,16 +2958,52 @@ ResolveStyleForFilter(const nsAString& a
rules.AppendElement(decl);
RefPtr<nsStyleContext> sc =
styleSet->ResolveStyleForRules(aParentContext, rules);
return sc.forget();
}
+static already_AddRefed<RawServoDeclarationBlock>
+CreateFilterDeclarationForServo(const nsAString& aFilter,
+ nsIDocument* aDocument)
+{
+ return CreateDeclarationForServo(eCSSProperty_filter, aFilter, aDocument);
+}
+
+static already_AddRefed<ServoComputedValues>
+ResolveFilterStyleForServo(const nsAString& aFilterString,
+ const ServoComputedValues* aParentStyle,
+ nsIPresShell* aPresShell,
+ ErrorResult& aError)
+{
+ MOZ_ASSERT(aPresShell->StyleSet()->IsServo());
+
+ RefPtr<RawServoDeclarationBlock> declarations =
+ CreateFilterDeclarationForServo(aFilterString, aPresShell->GetDocument());
+ if (!declarations) {
+ // Refuse to accept the filter, but do not throw an error.
+ return nullptr;
+ }
+
+ // In addition to unparseable values, the spec says we need to reject
+ // 'inherit' and 'initial'.
+ if (Servo_DeclarationBlock_HasCSSWideKeyword(declarations,
+ eCSSProperty_filter)) {
+ return nullptr;
+ }
+
+ ServoStyleSet* styleSet = aPresShell->StyleSet()->AsServo();
+ RefPtr<ServoComputedValues> computedValues =
+ styleSet->ResolveForDeclarations(aParentStyle, declarations);
+
+ return computedValues.forget();
+}
+
bool
CanvasRenderingContext2D::ParseFilter(const nsAString& aString,
nsTArray<nsStyleFilter>& aFilterChain,
ErrorResult& aError)
{
if (!mCanvasElement && !mDocShell) {
NS_WARNING("Canvas element must be non-null or a docshell must be provided");
aError.Throw(NS_ERROR_FAILURE);
@@ -2985,17 +3021,17 @@ CanvasRenderingContext2D::ParseFilter(co
GetFontStyleContext(mCanvasElement, GetFont(),
presShell, usedFont, aError);
if (!parentContext) {
aError.Throw(NS_ERROR_FAILURE);
return false;
}
RefPtr<nsStyleContext> sc =
- ResolveStyleForFilter(aString, presShell, parentContext, aError);
+ ResolveFilterStyle(aString, presShell, parentContext, aError);
if (!sc) {
return false;
}
aFilterChain = sc->StyleEffects()->mFilters;
return true;
}