Bug 1346052 - Part 3: Implement AnimationValue::FromString. r=birtles

AnimationValue::FromString compute the AnimationValue from a string.

MozReview-Commit-ID: CX8wairpnfN

--HG--
extra : rebase_source : 05dbaa84bf40463a0021bd538d7baba5d591f992
This commit is contained in:
Boris Chiou 2017-05-03 11:15:27 +08:00
Родитель b3ceb979ce
Коммит 7c0868e25d
5 изменённых файлов: 124 добавлений и 7 удалений

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

@ -198,6 +198,12 @@ SERVO_BINDING_FUNC(Servo_AnimationValue_DeepEqual, bool,
SERVO_BINDING_FUNC(Servo_AnimationValue_Uncompute,
RawServoDeclarationBlockStrong,
RawServoAnimationValueBorrowed value)
SERVO_BINDING_FUNC(Servo_AnimationValue_Compute,
RawServoAnimationValueStrong,
RawServoDeclarationBlockBorrowed declarations,
ServoComputedValuesBorrowed style,
ServoComputedValuesBorrowedOrNull parent_style,
RawServoStyleSetBorrowed raw_data)
// Style attribute
SERVO_BINDING_FUNC(Servo_ParseStyleAttribute, RawServoDeclarationBlockStrong,

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

@ -946,6 +946,17 @@ ServoStyleSet::GetBaseComputedValuesForElement(Element* aElement,
aPseudoTag).Consume();
}
already_AddRefed<RawServoAnimationValue>
ServoStyleSet::ComputeAnimationValue(
RawServoDeclarationBlock* aDeclarations,
const ServoComputedValuesWithParent& aComputedValues)
{
return Servo_AnimationValue_Compute(aDeclarations,
aComputedValues.mCurrentStyle,
aComputedValues.mParentStyle,
mRawSet.get()).Consume();
}
void
ServoStyleSet::RebuildData()
{

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

@ -304,6 +304,10 @@ public:
ResolveForDeclarations(ServoComputedValuesBorrowedOrNull aParentOrNull,
RawServoDeclarationBlockBorrowed aDeclarations);
already_AddRefed<RawServoAnimationValue>
ComputeAnimationValue(RawServoDeclarationBlock* aDeclaration,
const ServoComputedValuesWithParent& aComputedValues);
private:
already_AddRefed<nsStyleContext> GetContext(already_AddRefed<ServoComputedValues>,
nsStyleContext* aParentContext,

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

@ -24,11 +24,14 @@
#include "nsStyleContext.h"
#include "nsStyleSet.h"
#include "nsComputedDOMStyle.h"
#include "nsContentUtils.h"
#include "nsCSSParser.h"
#include "nsCSSPseudoElements.h"
#include "mozilla/css/Declaration.h"
#include "mozilla/dom/Element.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/ServoComputedValuesWithParent.h"
#include "mozilla/KeyframeUtils.h" // KeyframeUtils::ParseProperty
#include "mozilla/Likely.h"
#include "mozilla/ServoBindings.h" // RawServoDeclarationBlock
#include "gfxMatrix.h"
@ -5216,6 +5219,7 @@ StyleAnimationValue::operator==(const StyleAnimationValue& aOther) const
return false;
}
// AnimationValue Implementation
bool
@ -5323,3 +5327,65 @@ AnimationValue::ComputeDistance(nsCSSPropertyID aProperty,
? distance
: 0.0;
}
/* static */ AnimationValue
AnimationValue::FromString(nsCSSPropertyID aProperty,
const nsAString& aValue,
Element* aElement)
{
MOZ_ASSERT(aElement);
AnimationValue result;
nsCOMPtr<nsIDocument> doc = aElement->GetComposedDoc();
if (!doc) {
return result;
}
nsCOMPtr<nsIPresShell> shell = doc->GetShell();
if (!shell) {
return result;
}
// GetStyleContext() flushes style, so we shouldn't assume that any
// non-owning references we have are still valid.
RefPtr<nsStyleContext> styleContext =
nsComputedDOMStyle::GetStyleContext(aElement, nullptr, shell);
if (styleContext->StyleSource().IsServoComputedValues()) {
nsPresContext* presContext = shell->GetPresContext();
if (!presContext) {
return result;
}
RefPtr<RawServoDeclarationBlock> declarations =
KeyframeUtils::ParseProperty(aProperty, aValue, doc);
if (!declarations) {
return result;
}
// We use the current ServoComputeValues and its parent ServoComputeValues
// to reconstruct the Context and then compute the AnimationValue. However,
// nsStyleContext::GetParentAllowServo() is going away, so if possible, we
// should find another way to get the parent ServoComputedValues.
RefPtr<nsStyleContext> parentContext = styleContext->GetParentAllowServo();
const ServoComputedValuesWithParent styles = {
styleContext->StyleSource().AsServoComputedValues(),
parentContext ? parentContext->StyleSource().AsServoComputedValues()
: nullptr
};
result.mServo = presContext->StyleSet()
->AsServo()
->ComputeAnimationValue(declarations, styles);
return result;
}
if (!StyleAnimationValue::ComputeValue(aProperty, aElement, styleContext,
aValue, false /* |aUseSVGMode| */,
result.mGecko)) {
MOZ_ASSERT(result.IsNull());
}
return result;
}

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

@ -576,13 +576,28 @@ struct AnimationValue
: mServo(aValue) { }
AnimationValue() = default;
// mGecko and mServo are mutually exclusive: only one or the other should
// ever be set.
// FIXME: After obsoleting StyleAnimationValue, we should remove mGecko, and
// make AnimationValue a wrapper of RawServoAnimationValue to hide these
// FFIs.
StyleAnimationValue mGecko;
RefPtr<RawServoAnimationValue> mServo;
AnimationValue(const AnimationValue& aOther)
: mGecko(aOther.mGecko), mServo(aOther.mServo) { }
AnimationValue(AnimationValue&& aOther)
: mGecko(Move(aOther.mGecko)), mServo(Move(aOther.mServo)) { }
AnimationValue& operator=(const AnimationValue& aOther)
{
if (this != &aOther) {
mGecko = aOther.mGecko;
mServo = aOther.mServo;
}
return *this;
}
AnimationValue& operator=(AnimationValue&& aOther)
{
MOZ_ASSERT(this != &aOther, "Do not move itself");
if (this != &aOther) {
mGecko = Move(aOther.mGecko);
mServo = Move(aOther.mServo);
}
return *this;
}
bool operator==(const AnimationValue& aOther) const;
bool operator!=(const AnimationValue& aOther) const;
@ -609,6 +624,21 @@ struct AnimationValue
double ComputeDistance(nsCSSPropertyID aProperty,
const AnimationValue& aOther,
nsStyleContext* aStyleContext) const;
// Create an AnimaitonValue from a string. This method flushes style, so we
// should use this carefully. Now, it is only used by
// nsDOMWindowUtils::ComputeAnimationDistance.
static AnimationValue FromString(nsCSSPropertyID aProperty,
const nsAString& aValue,
dom::Element* aElement);
// mGecko and mServo are mutually exclusive: only one or the other should
// ever be set.
// FIXME: After obsoleting StyleAnimationValue, we should remove mGecko, and
// make AnimationValue a wrapper of RawServoAnimationValue to hide these
// FFIs.
StyleAnimationValue mGecko;
RefPtr<RawServoAnimationValue> mServo;
};
struct PropertyStyleAnimationValuePair