Bug 1358966 - Use Servo_GetAnimationValues. r=birtles

MozReview-Commit-ID: 7ag2IFUViDX

--HG--
extra : rebase_source : d545bf833a4bc428bf9141ff4cdfac05f4c453e1
This commit is contained in:
Hiroyuki Ikezoe 2017-06-09 06:19:37 +09:00
Родитель 263593c1fa
Коммит 9af90ec795
3 изменённых файлов: 40 добавлений и 32 удалений

Просмотреть файл

@ -16,7 +16,6 @@
#include "nsCSSValue.h" #include "nsCSSValue.h"
#include "nsColor.h" #include "nsColor.h"
#include "nsPresContext.h" #include "nsPresContext.h"
#include "mozilla/Keyframe.h" // For PropertyValuePair
#include "mozilla/ServoBindings.h" #include "mozilla/ServoBindings.h"
#include "mozilla/StyleAnimationValue.h" // For AnimationValue #include "mozilla/StyleAnimationValue.h" // For AnimationValue
#include "mozilla/StyleSetHandleInlines.h" #include "mozilla/StyleSetHandleInlines.h"
@ -29,6 +28,8 @@
using namespace mozilla::dom; using namespace mozilla::dom;
using mozilla::StyleAnimationValue; using mozilla::StyleAnimationValue;
typedef AutoTArray<RefPtr<RawServoAnimationValue>, 1> ServoAnimationValues;
/*static*/ nsSMILCSSValueType nsSMILCSSValueType::sSingleton; /*static*/ nsSMILCSSValueType nsSMILCSSValueType::sSingleton;
struct ValueWrapper { struct ValueWrapper {
@ -46,6 +47,8 @@ struct ValueWrapper {
ValueWrapper(nsCSSPropertyID aPropID, ValueWrapper(nsCSSPropertyID aPropID,
const RefPtr<RawServoAnimationValue>& aValue) const RefPtr<RawServoAnimationValue>& aValue)
: mPropID(aPropID), mServoValues{(aValue)} {} : mPropID(aPropID), mServoValues{(aValue)} {}
ValueWrapper(nsCSSPropertyID aPropID, ServoAnimationValues&& aValues)
: mPropID(aPropID), mServoValues{aValues} {}
bool operator==(const ValueWrapper& aOther) const bool operator==(const ValueWrapper& aOther) const
{ {
@ -76,7 +79,7 @@ struct ValueWrapper {
} }
nsCSSPropertyID mPropID; nsCSSPropertyID mPropID;
AutoTArray<RefPtr<RawServoAnimationValue>, 1> mServoValues; ServoAnimationValues mServoValues;
StyleAnimationValue mGeckoValue; StyleAnimationValue mGeckoValue;
}; };
@ -621,21 +624,22 @@ ValueFromStringHelper(nsCSSPropertyID aPropID,
return true; return true;
} }
static already_AddRefed<RawServoAnimationValue> static ServoAnimationValues
ValueFromStringHelper(nsCSSPropertyID aPropID, ValueFromStringHelper(nsCSSPropertyID aPropID,
Element* aTargetElement, Element* aTargetElement,
nsPresContext* aPresContext, nsPresContext* aPresContext,
nsStyleContext* aStyleContext, nsStyleContext* aStyleContext,
const nsAString& aString) const nsAString& aString)
{ {
ServoAnimationValues result;
// FIXME (bug 1358966): Support shorthand properties // FIXME (bug 1358966): Support shorthand properties
if (nsCSSProps::IsShorthand(aPropID)) { if (nsCSSProps::IsShorthand(aPropID)) {
return nullptr; return result;
} }
nsIDocument* doc = aTargetElement->GetUncomposedDoc(); nsIDocument* doc = aTargetElement->GetUncomposedDoc();
if (!doc) { if (!doc) {
return nullptr; return result;
} }
// Parse property // Parse property
@ -652,7 +656,7 @@ ValueFromStringHelper(nsCSSPropertyID aPropID,
ParsingMode::AllowAllNumericValues, ParsingMode::AllowAllNumericValues,
doc->GetCompatibilityMode()).Consume(); doc->GetCompatibilityMode()).Consume();
if (!servoDeclarationBlock) { if (!servoDeclarationBlock) {
return nullptr; return result;
} }
// Get a suitable style context for Servo // Get a suitable style context for Servo
@ -660,27 +664,12 @@ ValueFromStringHelper(nsCSSPropertyID aPropID,
aStyleContext->StyleSource().AsServoComputedValues(); aStyleContext->StyleSource().AsServoComputedValues();
// Compute value // Compute value
PropertyValuePair propValuePair; aPresContext->StyleSet()->AsServo()->GetAnimationValues(servoDeclarationBlock,
propValuePair.mProperty = aPropID; aTargetElement,
propValuePair.mServoDeclarationBlock = servoDeclarationBlock; currentStyle,
AutoTArray<Keyframe, 1> keyframes; result);
keyframes.AppendElement()->mPropertyValues.AppendElement(Move(propValuePair)); if (result.IsEmpty()) {
nsTArray<ComputedKeyframeValues> computedValues = return result;
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;
} }
if (aPropID == eCSSProperty_font_size) { if (aPropID == eCSSProperty_font_size) {
@ -692,8 +681,7 @@ ValueFromStringHelper(nsCSSPropertyID aPropID,
} }
} }
// Result should be already add-refed return result;
return computedValue.mServo.forget();
} }
// static // static
@ -727,7 +715,7 @@ nsSMILCSSValueType::ValueFromString(nsCSSPropertyID aPropID,
} }
if (aTargetElement->IsStyledByServo()) { if (aTargetElement->IsStyledByServo()) {
RefPtr<RawServoAnimationValue> parsedValue = ServoAnimationValues parsedValues =
ValueFromStringHelper(aPropID, aTargetElement, presContext, ValueFromStringHelper(aPropID, aTargetElement, presContext,
styleContext, aString); styleContext, aString);
if (aIsContextSensitive) { if (aIsContextSensitive) {
@ -736,9 +724,9 @@ nsSMILCSSValueType::ValueFromString(nsCSSPropertyID aPropID,
*aIsContextSensitive = false; *aIsContextSensitive = false;
} }
if (parsedValue) { if (!parsedValues.IsEmpty()) {
sSingleton.Init(aValue); sSingleton.Init(aValue);
aValue.mU.mPtr = new ValueWrapper(aPropID, parsedValue); aValue.mU.mPtr = new ValueWrapper(aPropID, Move(parsedValues));
} }
return; return;
} }

Просмотреть файл

@ -1041,6 +1041,20 @@ ServoStyleSet::GetComputedKeyframeValuesFor(
return 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> already_AddRefed<ServoComputedValues>
ServoStyleSet::GetBaseComputedValuesForElement(Element* aElement, ServoStyleSet::GetBaseComputedValuesForElement(Element* aElement,
CSSPseudoElementType aPseudoType) CSSPseudoElementType aPseudoType)

Просмотреть файл

@ -362,6 +362,12 @@ public:
dom::Element* aElement, dom::Element* aElement,
ServoComputedValuesBorrowed aComputedValues); ServoComputedValuesBorrowed aComputedValues);
void
GetAnimationValues(RawServoDeclarationBlock* aDeclarations,
dom::Element* aElement,
ServoComputedValuesBorrowed aComputedValues,
nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues);
bool AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray); bool AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
nsCSSCounterStyleRule* CounterStyleRuleForName(nsIAtom* aName); nsCSSCounterStyleRule* CounterStyleRuleForName(nsIAtom* aName);