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 372063 1b111a0fe4e807f238e05b61602208662e9f755f
parent 372062 8c57030ba627a21380e5735edb01d8aaec85721f
child 372064 67513e7b66928878a2f4136beb6da4571c9fe241
push id19429
push userbmo:boris.chiou@gmail.com
push dateFri, 27 May 2016 10:09:46 +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);
       }
     }