Bug 1244590 - Part 5: Make the default value of computed offsets be -1. draft
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 12 May 2016 16:00:47 +0800
changeset 371284 e031d7d4b9d9f5b6a9daebe90def5b090e80f852
parent 371283 8222b59a52d2d554b5dc61be63cf8b4df1ccd900
child 371285 f3290344ee2948b63d3ea7b9f20e3d6e4a3c6671
push id19290
push userbmo:boris.chiou@gmail.com
push dateThu, 26 May 2016 09:18:45 +0000
bugs1244590
milestone49.0a1
Bug 1244590 - Part 5: Make the default value of computed offsets be -1. When we apply paced spacing, we have to check if there are still null computed offsets after applying paced spacing to paceable Keyframes because the calculation of distance may be failed or some Keyframes are not paceable in the specific range. Therefore, using -1 would be easier to check it. Also, add a const, kComputedOffsetNotSet, to represent this invalid value. MozReview-Commit-ID: GPhj7cdiX2W
dom/animation/KeyframeEffect.cpp
dom/animation/KeyframeEffect.h
dom/animation/KeyframeUtils.cpp
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -1041,16 +1041,18 @@ KeyframeEffectReadOnly::GetKeyframes(JSC
   }
 
   for (const Keyframe& keyframe : mKeyframes) {
     // Set up a dictionary object for the explicit members
     BaseComputedKeyframe keyframeDict;
     if (keyframe.mOffset) {
       keyframeDict.mOffset.SetValue(keyframe.mOffset.value());
     }
+    MOZ_ASSERT(keyframe.mComputedOffset != Keyframe::kComputedOffsetNotSet,
+               "Invalid computed offset");
     keyframeDict.mComputedOffset.Construct(keyframe.mComputedOffset);
     if (keyframe.mTimingFunction) {
       keyframeDict.mEasing.Truncate();
       keyframe.mTimingFunction.ref().AppendToString(keyframeDict.mEasing);
     } // else if null, leave easing as its default "linear".
 
     JS::Rooted<JS::Value> keyframeJSValue(aCx);
     if (!ToJSValue(aCx, keyframeDict, &keyframeJSValue)) {
--- a/dom/animation/KeyframeEffect.h
+++ b/dom/animation/KeyframeEffect.h
@@ -101,17 +101,18 @@ struct Keyframe
     mOffset         = aOther.mOffset;
     mComputedOffset = aOther.mComputedOffset;
     mTimingFunction = Move(aOther.mTimingFunction);
     mPropertyValues = Move(aOther.mPropertyValues);
     return *this;
   }
 
   Maybe<double>                 mOffset;
-  double                        mComputedOffset = 0.0;
+  static MOZ_CONSTEXPR_VAR double kComputedOffsetNotSet = -1.0;
+  double                        mComputedOffset = kComputedOffsetNotSet;
   Maybe<ComputedTimingFunction> mTimingFunction; // Nothing() here means
                                                  // "linear"
   nsTArray<PropertyValuePair>   mPropertyValues;
 };
 
 struct AnimationPropertySegment
 {
   float mFromKey, mToKey;
--- a/dom/animation/KeyframeUtils.cpp
+++ b/dom/animation/KeyframeUtils.cpp
@@ -540,16 +540,18 @@ KeyframeUtils::GetAnimationPropertiesFro
       for (auto& value : values) {
         // If we already got a value for this property on the keyframe,
         // skip this one.
         if (propertiesOnThisKeyframe.HasProperty(value.mProperty)) {
           continue;
         }
 
         KeyframeValueEntry* entry = entries.AppendElement();
+        MOZ_ASSERT(frame.mComputedOffset != Keyframe::kComputedOffsetNotSet,
+                   "Invalid computed offset");
         entry->mOffset = frame.mComputedOffset;
         entry->mProperty = value.mProperty;
         entry->mValue = value.mValue;
         entry->mTimingFunction = frame.mTimingFunction;
 
         propertiesOnThisKeyframe.AddProperty(value.mProperty);
       }
     }