Bug 1302949 - Parse animation values with Servo backend; r=manishearth, r=heycam draft
authorBrian Birtles <birtles@gmail.com>
Fri, 16 Sep 2016 10:24:05 +0900
changeset 421000 edeaec568446897c5005640d63390ec5bf3751d2
parent 420999 83e415febf10cf90631fd7a1b447921822a44bc0
child 421001 d2dc5162ff6331dd4613e00ddb0bca9ed5f54ff0
push id31345
push userbbirtles@mozilla.com
push dateWed, 05 Oct 2016 02:47:30 +0000
reviewersmanishearth, heycam
bugs1302949
milestone52.0a1
Bug 1302949 - Parse animation values with Servo backend; r=manishearth, r=heycam MozReview-Commit-ID: 4UW1fIIjvdi
dom/animation/KeyframeUtils.cpp
layout/style/ServoBindingList.h
--- a/dom/animation/KeyframeUtils.cpp
+++ b/dom/animation/KeyframeUtils.cpp
@@ -975,16 +975,46 @@ AppendValueAsString(JSContext* aCx,
  * @param aDocument The document to use when parsing.
  * @return The constructed PropertyValuePair object.
  */
 static PropertyValuePair
 MakePropertyValuePair(nsCSSPropertyID aProperty, const nsAString& aStringValue,
                       nsCSSParser& aParser, nsIDocument* aDocument)
 {
   MOZ_ASSERT(aDocument);
+  PropertyValuePair result;
+
+  result.mProperty = aProperty;
+
+  if (aDocument->GetStyleBackendType() == StyleBackendType::Servo) {
+    nsCString name = nsCSSProps::GetStringValue(aProperty);
+
+    NS_ConvertUTF16toUTF8 value(aStringValue);
+    RefPtr<ThreadSafeURIHolder> base =
+      new ThreadSafeURIHolder(aDocument->GetDocumentURI());
+    RefPtr<ThreadSafeURIHolder> referrer =
+      new ThreadSafeURIHolder(aDocument->GetDocumentURI());
+    RefPtr<ThreadSafePrincipalHolder> principal =
+      new ThreadSafePrincipalHolder(aDocument->NodePrincipal());
+
+    nsCString baseString;
+    aDocument->GetDocumentURI()->GetSpec(baseString);
+
+    RefPtr<ServoDeclarationBlock> servoDeclarationBlock =
+      Servo_ParseProperty(
+        reinterpret_cast<const uint8_t*>(name.get()), name.Length(),
+        reinterpret_cast<const uint8_t*>(value.get()), value.Length(),
+        reinterpret_cast<const uint8_t*>(baseString.get()), baseString.Length(),
+        base, referrer, principal).Consume();
+
+    if (servoDeclarationBlock) {
+      result.mServoDeclarationBlock = servoDeclarationBlock.forget();
+      return result;
+    }
+  }
 
   nsCSSValue value;
   if (!nsCSSProps::IsShorthand(aProperty)) {
     aParser.ParseLonghandProperty(aProperty,
                                   aStringValue,
                                   aDocument->GetDocumentURI(),
                                   aDocument->GetDocumentURI(),
                                   aDocument->NodePrincipal(),
@@ -1007,19 +1037,28 @@ MakePropertyValuePair(nsCSSPropertyID aP
 
     // By leaving mShorthandPropertyID as unknown, we ensure that when
     // we call nsCSSValue::AppendToString we get back the string stored
     // in mTokenStream.
     MOZ_ASSERT(tokenStream->mShorthandPropertyID == eCSSProperty_UNKNOWN,
                "The shorthand property of a token stream should be initialized"
                " to unknown");
     value.SetTokenStreamValue(tokenStream);
+  } else {
+    // If we succeeded in parsing with Gecko, but not Servo the animation is
+    // not going to work since, for the purposes of animation, we're going to
+    // ignore |mValue| when the backend is Servo.
+    NS_WARNING_ASSERTION(aDocument->GetStyleBackendType() !=
+                           StyleBackendType::Servo,
+                         "Gecko succeeded in parsing where Servo failed");
   }
 
-  return { aProperty, value };
+  result.mValue = value;
+
+  return result;
 }
 
 /**
  * Checks that the given keyframes are loosely ordered (each keyframe's
  * offset that is not null is greater than or equal to the previous
  * non-null offset) and that all values are within the range [0.0, 1.0].
  *
  * @return true if the keyframes' offsets are correctly ordered and
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -42,16 +42,29 @@ SERVO_BINDING_FUNC(Servo_StyleSet_Append
 SERVO_BINDING_FUNC(Servo_StyleSet_PrependStyleSheet, void,
                    RawServoStyleSetBorrowedMut set, RawServoStyleSheetBorrowed sheet)
 SERVO_BINDING_FUNC(Servo_StyleSet_RemoveStyleSheet, void,
                    RawServoStyleSetBorrowedMut set, RawServoStyleSheetBorrowed sheet)
 SERVO_BINDING_FUNC(Servo_StyleSet_InsertStyleSheetBefore, void,
                    RawServoStyleSetBorrowedMut set, RawServoStyleSheetBorrowed sheet,
                    RawServoStyleSheetBorrowed reference)
 
+// Animations API
+SERVO_BINDING_FUNC(Servo_ParseProperty,
+                   ServoDeclarationBlockStrong,
+                   const uint8_t* property_bytes,
+                   uint32_t property_length,
+                   const uint8_t* value_bytes,
+                   uint32_t value_length,
+                   const uint8_t* base_bytes,
+                   uint32_t base_length,
+                   ThreadSafeURIHolder* base,
+                   ThreadSafeURIHolder* referrer,
+                   ThreadSafePrincipalHolder* principal)
+
 // Style attribute
 SERVO_BINDING_FUNC(Servo_ParseStyleAttribute, ServoDeclarationBlockStrong,
                    const uint8_t* bytes, uint32_t length,
                    nsHTMLCSSStyleSheet* cache)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_AddRef, void,
                    ServoDeclarationBlockBorrowed declarations)
 SERVO_BINDING_FUNC(Servo_DeclarationBlock_Release, void,
                    ServoDeclarationBlockBorrowed declarations)