diff --git a/dom/smil/nsSMILCSSValueType.cpp b/dom/smil/nsSMILCSSValueType.cpp index 2844e2dcc785..769810cd3e98 100644 --- a/dom/smil/nsSMILCSSValueType.cpp +++ b/dom/smil/nsSMILCSSValueType.cpp @@ -16,7 +16,6 @@ #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" @@ -29,6 +28,8 @@ using namespace mozilla::dom; using mozilla::StyleAnimationValue; +typedef AutoTArray, 1> ServoAnimationValues; + /*static*/ nsSMILCSSValueType nsSMILCSSValueType::sSingleton; struct ValueWrapper { @@ -46,6 +47,8 @@ struct ValueWrapper { ValueWrapper(nsCSSPropertyID aPropID, const RefPtr& aValue) : mPropID(aPropID), mServoValues{(aValue)} {} + ValueWrapper(nsCSSPropertyID aPropID, ServoAnimationValues&& aValues) + : mPropID(aPropID), mServoValues{aValues} {} bool operator==(const ValueWrapper& aOther) const { @@ -76,7 +79,7 @@ struct ValueWrapper { } nsCSSPropertyID mPropID; - AutoTArray, 1> mServoValues; + ServoAnimationValues mServoValues; StyleAnimationValue mGeckoValue; }; @@ -621,21 +624,22 @@ ValueFromStringHelper(nsCSSPropertyID aPropID, return true; } -static already_AddRefed +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 @@ -652,7 +656,7 @@ ValueFromStringHelper(nsCSSPropertyID aPropID, ParsingMode::AllowAllNumericValues, doc->GetCompatibilityMode()).Consume(); if (!servoDeclarationBlock) { - return nullptr; + return result; } // Get a suitable style context for Servo @@ -660,27 +664,12 @@ ValueFromStringHelper(nsCSSPropertyID aPropID, aStyleContext->StyleSource().AsServoComputedValues(); // Compute value - PropertyValuePair propValuePair; - propValuePair.mProperty = aPropID; - propValuePair.mServoDeclarationBlock = servoDeclarationBlock; - AutoTArray keyframes; - keyframes.AppendElement()->mPropertyValues.AppendElement(Move(propValuePair)); - nsTArray 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) { @@ -692,8 +681,7 @@ ValueFromStringHelper(nsCSSPropertyID aPropID, } } - // Result should be already add-refed - return computedValue.mServo.forget(); + return result; } // static @@ -727,7 +715,7 @@ nsSMILCSSValueType::ValueFromString(nsCSSPropertyID aPropID, } if (aTargetElement->IsStyledByServo()) { - RefPtr parsedValue = + ServoAnimationValues parsedValues = ValueFromStringHelper(aPropID, aTargetElement, presContext, styleContext, aString); if (aIsContextSensitive) { @@ -736,9 +724,9 @@ nsSMILCSSValueType::ValueFromString(nsCSSPropertyID aPropID, *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; } diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 6ccc8a1571c9..35dfb7509803 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -1041,6 +1041,20 @@ ServoStyleSet::GetComputedKeyframeValuesFor( return result; } +void +ServoStyleSet::GetAnimationValues( + RawServoDeclarationBlock* aDeclarations, + Element* aElement, + ServoComputedValuesBorrowed aComputedValues, + nsTArray>& aAnimationValues) +{ + Servo_GetAnimationValues(aDeclarations, + aElement, + aComputedValues, + mRawSet.get(), + &aAnimationValues); +} + already_AddRefed ServoStyleSet::GetBaseComputedValuesForElement(Element* aElement, CSSPseudoElementType aPseudoType) diff --git a/layout/style/ServoStyleSet.h b/layout/style/ServoStyleSet.h index c40ea226c9f3..5a4c2bd3deec 100644 --- a/layout/style/ServoStyleSet.h +++ b/layout/style/ServoStyleSet.h @@ -362,6 +362,12 @@ public: dom::Element* aElement, ServoComputedValuesBorrowed aComputedValues); + void + GetAnimationValues(RawServoDeclarationBlock* aDeclarations, + dom::Element* aElement, + ServoComputedValuesBorrowed aComputedValues, + nsTArray>& aAnimationValues); + bool AppendFontFaceRules(nsTArray& aArray); nsCSSCounterStyleRule* CounterStyleRuleForName(nsIAtom* aName);