Bug 1274944 - Part 2: Implement SetSpacing().
MozReview-Commit-ID: ASJHVK97gq6
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -7,16 +7,17 @@
#include "mozilla/dom/KeyframeEffect.h"
#include "mozilla/dom/AnimatableBinding.h"
// For UnrestrictedDoubleOrKeyframeAnimationOptions
#include "mozilla/dom/AnimationEffectTiming.h"
#include "mozilla/dom/KeyframeEffectBinding.h"
#include "mozilla/KeyframeUtils.h"
#include "nsDOMMutationObserver.h" // For nsAutoAnimationMutationBatch
+#include "nsIScriptError.h"
namespace mozilla {
namespace dom {
KeyframeEffect::KeyframeEffect(nsIDocument* aDocument,
const Maybe<OwningAnimationTarget>& aTarget,
const TimingParams& aTiming,
const KeyframeEffectParams& aOptions)
@@ -125,13 +126,55 @@ KeyframeEffect::SetTarget(const Nullable
}
}
void
KeyframeEffect::SetSpacing(JSContext* aCx,
const nsAString& aSpacing,
ErrorResult& aRv)
{
- // TODO: Implement this in the next patch.
+ SpacingMode spacingMode = SpacingMode::distribute;
+ nsCSSPropertyID pacedProperty = eCSSProperty_UNKNOWN;
+ nsAutoString invalidPacedProperty;
+ KeyframeEffectParams::ParseSpacing(aSpacing,
+ spacingMode,
+ pacedProperty,
+ invalidPacedProperty,
+ aRv);
+ if (aRv.Failed()) {
+ return;
+ }
+
+ if (!invalidPacedProperty.IsEmpty()) {
+ const char16_t* params[] = { invalidPacedProperty.get() };
+ nsIDocument* doc = AnimationUtils::GetCurrentRealmDocument(aCx);
+ nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
+ NS_LITERAL_CSTRING("Animation"),
+ doc,
+ nsContentUtils::eDOM_PROPERTIES,
+ "UnanimatablePacedProperty",
+ params, ArrayLength(params));
+ }
+
+ if (mEffectOptions.mSpacingMode == spacingMode &&
+ mEffectOptions.mPacedProperty == pacedProperty) {
+ return;
+ }
+
+ mEffectOptions.mSpacingMode = spacingMode;
+ mEffectOptions.mPacedProperty = pacedProperty;
+
+ // Apply spacing. We apply distribute here. If the new spacing is paced,
+ // UpdateProperties() will apply it.
+ if (mEffectOptions.mSpacingMode == SpacingMode::distribute) {
+ KeyframeUtils::ApplyDistributeSpacing(mKeyframes);
+ }
+
+ if (mTarget) {
+ RefPtr<nsStyleContext> styleContext = GetTargetStyleContext();
+ if (styleContext) {
+ UpdateProperties(styleContext);
+ }
+ }
}
} // namespace dom
} // namespace mozilla