Bug 1358966 - Use Servo_GetAnimationValues. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 09 Jun 2017 06:19:37 +0900
changeset 591337 0504ba616c2a5af1457894da0696cde9991573f2
parent 591336 e07ff82736467d7064eda86a05fb4c07708ad960
child 591338 1d71ecdb6d00e24902ae1443daccc5fe1b390594
push id63021
push userhikezoe@mozilla.com
push dateThu, 08 Jun 2017 22:52:23 +0000
reviewersbirtles
bugs1358966
milestone55.0a1
Bug 1358966 - Use Servo_GetAnimationValues. r?birtles MozReview-Commit-ID: 7ag2IFUViDX
dom/smil/nsSMILCSSValueType.cpp
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
--- a/dom/smil/nsSMILCSSValueType.cpp
+++ b/dom/smil/nsSMILCSSValueType.cpp
@@ -11,29 +11,30 @@
 #include "nsComputedDOMStyle.h"
 #include "nsString.h"
 #include "nsSMILParserUtils.h"
 #include "nsSMILValue.h"
 #include "nsCSSProps.h"
 #include "nsCSSValue.h"
 #include "nsColor.h"
 #include "nsPresContext.h"
-#include "mozilla/Keyframe.h" // For PropertyValuePair
 #include "mozilla/ServoBindings.h"
 #include "mozilla/StyleAnimationValue.h" // For AnimationValue
 #include "mozilla/StyleSetHandleInlines.h"
 #include "mozilla/dom/BaseKeyframeTypesBinding.h" // For CompositeOperation
 #include "mozilla/dom/Element.h"
 #include "nsDebug.h"
 #include "nsStyleUtil.h"
 #include "nsIDocument.h"
 
 using namespace mozilla::dom;
 using mozilla::StyleAnimationValue;
 
+typedef AutoTArray<RefPtr<RawServoAnimationValue>, 1> ServoAnimationValues;
+
 /*static*/ nsSMILCSSValueType nsSMILCSSValueType::sSingleton;
 
 struct ValueWrapper {
   ValueWrapper(nsCSSPropertyID aPropID, const AnimationValue& aValue)
     : mPropID(aPropID)
   {
     if (aValue.mServo) {
       mServoValues.AppendElement(aValue.mServo);
@@ -41,16 +42,18 @@ struct ValueWrapper {
     }
     mGeckoValue = aValue.mGecko;
   }
   ValueWrapper(nsCSSPropertyID aPropID, const StyleAnimationValue& aValue)
     : mPropID(aPropID), mGeckoValue(aValue) {}
   ValueWrapper(nsCSSPropertyID aPropID,
                const RefPtr<RawServoAnimationValue>& aValue)
     : mPropID(aPropID), mServoValues{(aValue)} {}
+  ValueWrapper(nsCSSPropertyID aPropID, ServoAnimationValues&& aValues)
+    : mPropID(aPropID), mServoValues{aValues} {}
 
   bool operator==(const ValueWrapper& aOther) const
   {
     if (mPropID != aOther.mPropID) {
       return false;
     }
 
     if (!mServoValues.IsEmpty()) {
@@ -71,17 +74,17 @@ struct ValueWrapper {
   }
 
   bool operator!=(const ValueWrapper& aOther) const
   {
     return !(*this == aOther);
   }
 
   nsCSSPropertyID mPropID;
-  AutoTArray<RefPtr<RawServoAnimationValue>, 1> mServoValues;
+  ServoAnimationValues mServoValues;
   StyleAnimationValue mGeckoValue;
 
 };
 
 // Helper Methods
 // --------------
 static const StyleAnimationValue*
 GetZeroValueForUnit(StyleAnimationValue::Unit aUnit)
@@ -616,89 +619,74 @@ ValueFromStringHelper(nsCSSPropertyID aP
     MOZ_ASSERT(aStyleAnimValue.GetUnit() == StyleAnimationValue::eUnit_Coord,
                "'font-size' value with unexpected style unit");
     aStyleAnimValue.SetCoordValue(aStyleAnimValue.GetCoordValue() /
                                   aPresContext->EffectiveTextZoom());
   }
   return true;
 }
 
-static already_AddRefed<RawServoAnimationValue>
+static ServoAnimationValues
 ValueFromStringHelper(nsCSSPropertyID aPropID,
                       Element* aTargetElement,
                       nsPresContext* aPresContext,
                       nsStyleContext* aStyleContext,
                       const nsAString& aString)
 {
+  ServoAnimationValues result;
   // FIXME (bug 1358966): Support shorthand properties
   if (nsCSSProps::IsShorthand(aPropID)) {
-    return nullptr;
+    return result;
   }
 
   nsIDocument* doc = aTargetElement->GetUncomposedDoc();
   if (!doc) {
-    return nullptr;
+    return result;
   }
 
   // Parse property
   // FIXME this is using the wrong base uri (bug 1343919)
   RefPtr<URLExtraData> data = new URLExtraData(doc->GetDocumentURI(),
                                                doc->GetDocumentURI(),
                                                doc->NodePrincipal());
   NS_ConvertUTF16toUTF8 value(aString);
   RefPtr<RawServoDeclarationBlock> servoDeclarationBlock =
     Servo_ParseProperty(aPropID,
                         &value,
                         data,
                         ParsingMode::AllowUnitlessLength |
                         ParsingMode::AllowAllNumericValues,
                         doc->GetCompatibilityMode()).Consume();
   if (!servoDeclarationBlock) {
-    return nullptr;
+    return result;
   }
 
   // Get a suitable style context for Servo
   const ServoComputedValues* currentStyle =
     aStyleContext->StyleSource().AsServoComputedValues();
 
   // Compute value
-  PropertyValuePair propValuePair;
-  propValuePair.mProperty = aPropID;
-  propValuePair.mServoDeclarationBlock = servoDeclarationBlock;
-  AutoTArray<Keyframe, 1> keyframes;
-  keyframes.AppendElement()->mPropertyValues.AppendElement(Move(propValuePair));
-  nsTArray<ComputedKeyframeValues> computedValues =
-    aPresContext->StyleSet()->AsServo()
-      ->GetComputedKeyframeValuesFor(keyframes, aTargetElement, currentStyle);
-
-  // Pull out the appropriate value
-  if (computedValues.IsEmpty() || computedValues[0].IsEmpty()) {
-    return nullptr;
-  }
-  // So long as we don't support shorthands (bug 1358966) the following
-  // assertion should hold.
-  MOZ_ASSERT(computedValues.Length() == 1 &&
-             computedValues[0].Length() == 1,
-             "Should only have a single property with a single value");
-  AnimationValue computedValue = computedValues[0][0].mValue;
-  if (!computedValue.mServo) {
-    return nullptr;
+  aPresContext->StyleSet()->AsServo()->GetAnimationValues(servoDeclarationBlock,
+                                                          aTargetElement,
+                                                          currentStyle,
+                                                          result);
+  if (result.IsEmpty()) {
+    return result;
   }
 
   if (aPropID == eCSSProperty_font_size) {
     // FIXME (bug 1357296): Divide out text-zoom, since SVG is supposed to
     // ignore it.
     if (aPresContext->EffectiveTextZoom() != 1.0) {
       NS_WARNING("stylo: Dividing out text-zoom not yet supported"
                  " (bug 1357296)");
     }
   }
 
-  // Result should be already add-refed
-  return computedValue.mServo.forget();
+  return result;
 }
 
 // static
 void
 nsSMILCSSValueType::ValueFromString(nsCSSPropertyID aPropID,
                                     Element* aTargetElement,
                                     const nsAString& aString,
                                     nsSMILValue& aValue,
@@ -722,28 +710,28 @@ nsSMILCSSValueType::ValueFromString(nsCS
   RefPtr<nsStyleContext> styleContext =
     nsComputedDOMStyle::GetStyleContext(aTargetElement, nullptr,
                                         presContext->PresShell());
   if (!styleContext) {
     return;
   }
 
   if (aTargetElement->IsStyledByServo()) {
-    RefPtr<RawServoAnimationValue> parsedValue =
+    ServoAnimationValues parsedValues =
       ValueFromStringHelper(aPropID, aTargetElement, presContext,
                             styleContext, aString);
     if (aIsContextSensitive) {
       // FIXME: Bug 1358955 - detect context-sensitive values and set this value
       // appropriately.
       *aIsContextSensitive = false;
     }
 
-    if (parsedValue) {
+    if (!parsedValues.IsEmpty()) {
       sSingleton.Init(aValue);
-      aValue.mU.mPtr = new ValueWrapper(aPropID, parsedValue);
+      aValue.mU.mPtr = new ValueWrapper(aPropID, Move(parsedValues));
     }
     return;
   }
 
   StyleAnimationValue parsedValue;
   if (ValueFromStringHelper(aPropID, aTargetElement, presContext, styleContext,
                             aString, parsedValue, aIsContextSensitive)) {
     sSingleton.Init(aValue);
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -1036,16 +1036,30 @@ ServoStyleSet::GetComputedKeyframeValues
   Servo_GetComputedKeyframeValues(&aKeyframes,
                                   aElement,
                                   aComputedValues,
                                   mRawSet.get(),
                                   &result);
   return result;
 }
 
+void
+ServoStyleSet::GetAnimationValues(
+  RawServoDeclarationBlock* aDeclarations,
+  Element* aElement,
+  ServoComputedValuesBorrowed aComputedValues,
+  nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues)
+{
+  Servo_GetAnimationValues(aDeclarations,
+                           aElement,
+                           aComputedValues,
+                           mRawSet.get(),
+                           &aAnimationValues);
+}
+
 already_AddRefed<ServoComputedValues>
 ServoStyleSet::GetBaseComputedValuesForElement(Element* aElement,
                                                CSSPseudoElementType aPseudoType)
 {
   return Servo_StyleSet_GetBaseComputedValuesForElement(mRawSet.get(),
                                                         aElement,
                                                         &Snapshots(),
                                                         aPseudoType).Consume();
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -357,16 +357,22 @@ public:
                            const ServoComputedValues* aComputedValues,
                            nsTArray<Keyframe>& aKeyframes);
 
   nsTArray<ComputedKeyframeValues>
   GetComputedKeyframeValuesFor(const nsTArray<Keyframe>& aKeyframes,
                                dom::Element* aElement,
                                ServoComputedValuesBorrowed aComputedValues);
 
+  void
+  GetAnimationValues(RawServoDeclarationBlock* aDeclarations,
+                     dom::Element* aElement,
+                     ServoComputedValuesBorrowed aComputedValues,
+                     nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues);
+
   bool AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
 
   nsCSSCounterStyleRule* CounterStyleRuleForName(nsIAtom* aName);
 
   already_AddRefed<ServoComputedValues>
   GetBaseComputedValuesForElement(dom::Element* aElement,
                                   CSSPseudoElementType aPseudoType);