Bug 1324700 - Add a function which is equivalent to ResolveStyleForFilter for servo. r?heycam draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Sat, 15 Apr 2017 07:37:35 +0900
changeset 563191 52090a04f6cd37a335e10d10e79b106b48b1a26d
parent 563190 97b9c7c16b78703602c97f55b030739e6fbfef67
child 563192 1b360aec27b53a0317ff788a72de031431a957c7
push id54220
push userhikezoe@mozilla.com
push dateSat, 15 Apr 2017 04:25:00 +0000
reviewersheycam
bugs1324700
milestone55.0a1
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
dom/canvas/CanvasRenderingContext2D.cpp
--- 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;
 }