Bug 1338927 - Part 4: Templatize BuildProperties(). r?birtles
We'd like to use template to manage functions that have almost the same functionality
both on stylo and gecko instead of branching in each functions because it will be
easier to maintain stylo and gecko for a while.
MozReview-Commit-ID: 25ukMpOeqLj
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -13,16 +13,17 @@
#include "mozilla/AnimationRule.h"
#include "mozilla/AnimationUtils.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/EffectSet.h"
#include "mozilla/FloatingPoint.h" // For IsFinite
#include "mozilla/LookAndFeel.h" // For LookAndFeel::GetInt
#include "mozilla/KeyframeUtils.h"
#include "mozilla/ServoBindings.h"
+#include "mozilla/TypeTraits.h"
#include "Layers.h" // For Layer
#include "nsComputedDOMStyle.h" // nsComputedDOMStyle::GetStyleContextForElement
#include "nsContentUtils.h" // nsContentUtils::ReportToConsole
#include "nsCSSPropertyIDSet.h"
#include "nsCSSProps.h" // For nsCSSProps::PropHasFlags
#include "nsCSSPseudoElements.h" // For CSSPseudoElementType
#include "nsIPresShell.h"
#include "nsIScriptError.h"
@@ -278,17 +279,17 @@ KeyframeEffectReadOnly::UpdateProperties
// FIXME: Bug 1324966. Drop this check once we have a function to get
// nsStyleContext without resolving animating style.
MOZ_DIAGNOSTIC_ASSERT(!mIsComposingStyle,
"Should not be called while processing ComposeStyle()");
if (mIsComposingStyle) {
return;
}
- nsTArray<AnimationProperty> properties = BuildProperties(aStyleContext);
+ nsTArray<AnimationProperty> properties = BuildProperties(Move(aStyleContext));
// We need to update base styles even if any properties are not changed at all
// since base styles might have been changed due to parent style changes, etc.
EnsureBaseStyles(aStyleContext, properties);
if (mProperties == properties) {
return;
}
@@ -848,20 +849,26 @@ KeyframeEffectReadOnly::ConstructKeyfram
// computed offsets and rebuild the animation properties.
// FIXME: Bug 1314537: We have to make sure SharedKeyframeList is handled
// properly.
effect->mKeyframes = aSource.mKeyframes;
effect->mProperties = aSource.mProperties;
return effect.forget();
}
+template<typename StyleType>
nsTArray<AnimationProperty>
-KeyframeEffectReadOnly::BuildProperties(nsStyleContext* aStyleContext)
+KeyframeEffectReadOnly::BuildProperties(StyleType&& aStyle)
{
- MOZ_ASSERT(aStyleContext);
+ static_assert(IsSame<StyleType, nsStyleContext*>::value ||
+ IsSame<StyleType, const ServoComputedStyleValues&>::value,
+ "StyleType should be nsStyleContext* or "
+ "const ServoComputedStyleValues&");
+
+ MOZ_ASSERT(aStyle);
nsTArray<AnimationProperty> result;
// If mTarget is null, return an empty property array.
if (!mTarget) {
return result;
}
// When GetComputedKeyframeValues or GetAnimationPropertiesFromKeyframes
@@ -870,25 +877,25 @@ KeyframeEffectReadOnly::BuildProperties(
// happens we could find that |mKeyframes| is overwritten while it is
// being iterated over. Normally that shouldn't happen but just in case we
// make a copy of |mKeyframes| first and iterate over that instead.
auto keyframesCopy(mKeyframes);
nsTArray<ComputedKeyframeValues> computedValues =
KeyframeUtils::GetComputedKeyframeValues(keyframesCopy,
mTarget->mElement,
- aStyleContext);
+ aStyle);
// FIXME: Bug 1332633: we have to implement ComputeDistance for
// RawServoAnimationValue.
if (mEffectOptions.mSpacingMode == SpacingMode::paced &&
- aStyleContext->PresContext()->StyleSet()->IsGecko()) {
+ !mDocument->IsStyledByServo()) {
KeyframeUtils::ApplySpacing(keyframesCopy, SpacingMode::paced,
mEffectOptions.mPacedProperty,
- computedValues, aStyleContext);
+ computedValues, aStyle);
}
result =
KeyframeUtils::GetAnimationPropertiesFromKeyframes(
keyframesCopy,
computedValues,
mEffectOptions.mComposite);
--- a/dom/animation/KeyframeEffectReadOnly.h
+++ b/dom/animation/KeyframeEffectReadOnly.h
@@ -326,17 +326,18 @@ protected:
static already_AddRefed<KeyframeEffectType>
ConstructKeyframeEffect(const GlobalObject& aGlobal,
KeyframeEffectReadOnly& aSource,
ErrorResult& aRv);
// Build properties by recalculating from |mKeyframes| using |aStyleContext|
// to resolve specified values. This function also applies paced spacing if
// needed.
- nsTArray<AnimationProperty> BuildProperties(nsStyleContext* aStyleContext);
+ template<typename StyleType>
+ nsTArray<AnimationProperty> BuildProperties(StyleType&& aStyle);
// This effect is registered with its target element so long as:
//
// (a) It has a target element, and
// (b) It is "relevant" (i.e. yet to finish but not idle, or finished but
// filling forwards)
//
// As a result, we need to make sure this gets called whenever anything
--- a/dom/animation/KeyframeUtils.h
+++ b/dom/animation/KeyframeUtils.h
@@ -108,16 +108,24 @@ public:
* @param aStyleContext The style context used for calculating paced spacing
* on transform.
*/
static void ApplySpacing(nsTArray<Keyframe>& aKeyframes,
SpacingMode aSpacingMode,
nsCSSPropertyID aProperty,
nsTArray<ComputedKeyframeValues>& aComputedValues,
nsStyleContext* aStyleContext);
+ static void ApplySpacing(nsTArray<Keyframe>& aKeyframes,
+ SpacingMode aSpacingMode,
+ nsCSSPropertyID aProperty,
+ nsTArray<ComputedKeyframeValues>& aComputedValues,
+ const ServoComputedStyleValues& aServoValues)
+ {
+ NS_WARNING("stylo: ApplySpacing not implemented yet");
+ }
/**
* Wrapper for ApplySpacing to simplify using distribute spacing.
*
* @param aKeyframes The set of keyframes to adjust.
*/
static void ApplyDistributeSpacing(nsTArray<Keyframe>& aKeyframes);