Bug 1483404 - Move conversion of CompositeOperation enum types to KeyframeUtils::GetAnimationPropertiesFromKeyframes; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D3457
This commit is contained in:
Brian Birtles
2018-08-16 16:24:52 +00:00
parent 8c57b30cbf
commit c82f9c9d10
5 changed files with 12 additions and 41 deletions

View File

@@ -10,15 +10,13 @@
#include "nsCSSPropertyID.h"
#include "nsCSSValue.h"
#include "nsTArray.h"
#include "mozilla/dom/BaseKeyframeTypesBinding.h" // CompositeOperationOrAuto
#include "mozilla/ComputedTimingFunction.h"
#include "mozilla/Maybe.h"
#include "mozilla/RefPtr.h"
struct RawServoDeclarationBlock;
namespace mozilla {
namespace dom {
enum class CompositeOperation : uint8_t;
}
/**
* A property-value pair specified on a keyframe.
@@ -89,7 +87,8 @@ struct Keyframe
double mComputedOffset = kComputedOffsetNotSet;
Maybe<ComputedTimingFunction> mTimingFunction; // Nothing() here means
// "linear"
Maybe<dom::CompositeOperation> mComposite;
dom::CompositeOperationOrAuto mComposite =
dom::CompositeOperationOrAuto::Auto;
nsTArray<PropertyValuePair> mPropertyValues;
};

View File

@@ -1099,8 +1099,7 @@ KeyframeEffect::GetKeyframes(JSContext*& aCx,
keyframe.mTimingFunction.ref().AppendToString(keyframeDict.mEasing);
} // else if null, leave easing as its default "linear".
keyframeDict.mComposite =
KeyframeUtils::ToCompositeOperationOrAuto(keyframe.mComposite);
keyframeDict.mComposite = keyframe.mComposite;
JS::Rooted<JS::Value> keyframeJSValue(aCx);
if (!ToJSValue(aCx, keyframeDict, &keyframeJSValue)) {

View File

@@ -334,8 +334,12 @@ KeyframeUtils::GetAnimationPropertiesFromKeyframes(
entry->mProperty = value.mProperty;
entry->mValue = value.mValue;
entry->mTimingFunction = frame.mTimingFunction;
// The following assumes that CompositeOperation is a strict subset of
// CompositeOperationOrAuto.
entry->mComposite =
frame.mComposite ? frame.mComposite.value() : aEffectComposite;
frame.mComposite == dom::CompositeOperationOrAuto::Auto
? aEffectComposite
: static_cast<dom::CompositeOperation>(frame.mComposite);
}
}
@@ -452,8 +456,7 @@ ConvertKeyframeSequence(JSContext* aCx,
}
if (StaticPrefs::dom_animations_api_compositing_enabled()) {
keyframe->mComposite =
KeyframeUtils::ToCompositeOperation(keyframeDict.mComposite);
keyframe->mComposite = keyframeDict.mComposite;
}
// Look for additional property-values pairs on the object.
@@ -1205,8 +1208,7 @@ GetKeyframeListFromPropertyIndexedKeyframe(JSContext* aCx,
if (compositeOps && !compositeOps->IsEmpty()) {
size_t length = compositeOps->Length();
for (size_t i = 0; i < aResult.Length(); i++) {
dom::CompositeOperationOrAuto op = compositeOps->ElementAt(i % length);
aResult[i].mComposite = KeyframeUtils::ToCompositeOperation(op);
aResult[i].mComposite = compositeOps->ElementAt(i % length);
}
}
}

View File

@@ -104,35 +104,6 @@ public:
* @return true if |aProperty| is animatable.
*/
static bool IsAnimatableProperty(nsCSSPropertyID aProperty);
/*
* The spec defines two enums: CompositeOperation and
* CompositeOperationOrAuto.
*
* Internally, however, it's more convenient to always deal with
* CompositeOperation, represent the 'auto' case as a Nothing() value, and
* convert to and from CompositeOperationOrAuto at the API boundary.
*
* The following methods convert between these two representations and allow
* us to encapsulate the assumption that CompositeOperation is a strict subset
* of CompositeOperationOrAuto, in one location.
*/
static dom::CompositeOperationOrAuto
ToCompositeOperationOrAuto(const Maybe<dom::CompositeOperation>& aComposite)
{
return aComposite
? static_cast<dom::CompositeOperationOrAuto>(aComposite.value())
: dom::CompositeOperationOrAuto::Auto;
}
static Maybe<dom::CompositeOperation>
ToCompositeOperation(dom::CompositeOperationOrAuto aComposite)
{
return aComposite == dom::CompositeOperationOrAuto::Auto
? Nothing()
: Some(static_cast<dom::CompositeOperation>(aComposite));
}
};
} // namespace mozilla

View File

@@ -21,7 +21,7 @@ enum CompositeOperation { "replace", "add", "accumulate" };
// that we can cast between the two types (provided the value is not "auto").
//
// If that assumption ceases to hold we will need to update the conversion
// routines in KeyframeUtils.
// in KeyframeUtils::GetAnimationPropertiesFromKeyframes.
enum CompositeOperationOrAuto { "replace", "add", "accumulate", "auto" };
// The following dictionary types are not referred to by other .webidl files,