Bug 1346052 - Part 4: Implement ComputeAnimationDistance for Servo backend. draft
authorBoris Chiou <boris.chiou@gmail.com>
Mon, 20 Mar 2017 18:18:41 +0800
changeset 571667 43a8619c59ccf7d928b219a4332a95f1f59a9acf
parent 571666 3e2acc0717322ec6d2c4f5231cd2299da9d1c0fd
child 626845 4ef6fccf421f8363a83c2c63f82ef4819880866f
push id56881
push userbmo:boris.chiou@gmail.com
push dateWed, 03 May 2017 03:53:29 +0000
bugs1346052
milestone55.0a1
Bug 1346052 - Part 4: Implement ComputeAnimationDistance for Servo backend. Implement servo's computed values version of nsDOMWindowUtils::ComputeAnimationDistance MozReview-Commit-ID: 8fggxuUxne8
dom/base/nsDOMWindowUtils.cpp
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -2410,38 +2410,16 @@ nsDOMWindowUtils::StopFrameTimeRecording
   /* copy over the frame intervals and paint times into the arrays we just allocated */
   for (uint32_t i = 0; i < *frameCount; i++) {
     (*frameIntervals)[i] = tmpFrameIntervals[i];
   }
 
   return NS_OK;
 }
 
-static bool
-ComputeAnimationValue(nsCSSPropertyID aProperty,
-                      Element* aElement,
-                      const nsAString& aInput,
-                      StyleAnimationValue& aOutput)
-{
-  nsIDocument* doc = aElement->GetUncomposedDoc();
-  nsIPresShell* shell = doc->GetShell();
-  if (!shell) {
-    return false;
-  }
-
-  RefPtr<nsStyleContext> styleContext =
-    nsComputedDOMStyle::GetStyleContext(aElement, nullptr, shell);
-
-  if (!StyleAnimationValue::ComputeValue(aProperty, aElement, styleContext,
-                                         aInput, false, aOutput)) {
-    return false;
-  }
-  return true;
-}
-
 NS_IMETHODIMP
 nsDOMWindowUtils::AdvanceTimeAndRefresh(int64_t aMilliseconds)
 {
   // Before we advance the time, we should trigger any animations that are
   // waiting to start. This is because there are many tests that call this
   // which expect animations to start immediately. Ideally, we should make
   // all these tests do an asynchronous wait on the corresponding animation's
   // 'ready' promise before continuing. Then we could remove the special
@@ -2695,41 +2673,33 @@ nsDOMWindowUtils::ComputeAnimationDistan
                                            double* aResult)
 {
   nsresult rv;
   nsCOMPtr<nsIContent> content = do_QueryInterface(aElement, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCSSPropertyID property =
     nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eIgnoreEnabledState);
-  if (property != eCSSProperty_UNKNOWN && nsCSSProps::IsShorthand(property)) {
-    property = eCSSProperty_UNKNOWN;
-  }
-
-  MOZ_ASSERT(property == eCSSProperty_UNKNOWN ||
-             !nsCSSProps::IsShorthand(property),
-             "should not have shorthand");
-
-  StyleAnimationValue v1, v2;
-  Element* element = content->AsElement();
   if (property == eCSSProperty_UNKNOWN ||
-      !ComputeAnimationValue(property, element, aValue1, v1) ||
-      !ComputeAnimationValue(property, element, aValue2, v2)) {
+      nsCSSProps::IsShorthand(property)) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
-  nsIPresShell* shell = element->GetUncomposedDoc()->GetShell();
+  Element* element = content->AsElement();
+  AnimationValue v1 = AnimationValue::FromString(property, aValue1, element);
+  AnimationValue v2 = AnimationValue::FromString(property, aValue2, element);
+  if (v1.IsNull() || v2.IsNull()) {
+    return NS_ERROR_ILLEGAL_VALUE;
+  }
+
+  nsIPresShell* shell = element->GetComposedDoc()->GetShell();
   RefPtr<nsStyleContext> styleContext = shell
     ? nsComputedDOMStyle::GetStyleContext(element, nullptr, shell)
     : nullptr;
-  if (!StyleAnimationValue::ComputeDistance(property, v1, v2, styleContext,
-                                            *aResult)) {
-    return NS_ERROR_FAILURE;
-  }
-
+  *aResult = v1.ComputeDistance(property, v2, styleContext);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetAnimationTypeForLonghand(const nsAString& aProperty,
                                               nsAString& aResult)
 {
   nsCSSPropertyID propertyID =