Bug 1274944 - Part 2: Implement SetSpacing(). draft
authorBoris Chiou <boris.chiou@gmail.com>
Wed, 31 Aug 2016 17:31:10 +0800
changeset 409800 f91c53dbd01c96c5d397ab9f97cbc388ea560d72
parent 409799 e20fc280635ae228ae630b23e4b28acad74a4594
child 409801 e15352783c70443a3e9a5489915369ad0211d79e
child 409870 9f26c76530ebaf8588623ba67deaee0f48e83492
push id28551
push userbmo:boris.chiou@gmail.com
push dateMon, 05 Sep 2016 07:18:07 +0000
bugs1274944
milestone51.0a1
Bug 1274944 - Part 2: Implement SetSpacing(). MozReview-Commit-ID: ASJHVK97gq6
dom/animation/KeyframeEffect.cpp
--- 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