From 9ce5c619b0e9e803cd01ef9f4d1eec59ebe8bf47 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Sun, 29 Jan 2017 12:58:23 +0900 Subject: [PATCH] Bug 1328787 - Part 1: Factor out Keyframe and PropertyValuePair into Keyframe.h. r=heycam KeyframeEffectReadOnly.h has lots of unnecesarry stuff for stylo for now, so is split stuff which needs for stylo into Keyframe.h. --- dom/animation/Keyframe.h | 89 ++++++++++++++++++++++++++ dom/animation/KeyframeEffectReadOnly.h | 65 +------------------ dom/animation/moz.build | 1 + 3 files changed, 91 insertions(+), 64 deletions(-) create mode 100644 dom/animation/Keyframe.h diff --git a/dom/animation/Keyframe.h b/dom/animation/Keyframe.h new file mode 100644 index 000000000000..8df3cc1e9046 --- /dev/null +++ b/dom/animation/Keyframe.h @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_Keyframe_h +#define mozilla_dom_Keyframe_h + +#include "nsCSSPropertyID.h" +#include "nsCSSValue.h" +#include "nsTArray.h" +#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. + */ +struct PropertyValuePair +{ + nsCSSPropertyID mProperty; + // The specified value for the property. For shorthand properties or invalid + // property values, we store the specified property value as a token stream + // (string). + nsCSSValue mValue; + + // The specified value when using the Servo backend. However, even when + // using the Servo backend, we still fill in |mValue| in the case where we + // fail to parse the value since we use it to store the original string. + RefPtr mServoDeclarationBlock; + + bool operator==(const PropertyValuePair&) const; +}; + +/** + * A single keyframe. + * + * This is the canonical form in which keyframe effects are stored and + * corresponds closely to the type of objects returned via the getKeyframes() + * API. + * + * Before computing an output animation value, however, we flatten these frames + * down to a series of per-property value arrays where we also resolve any + * overlapping shorthands/longhands, convert specified CSS values to computed + * values, etc. + * + * When the target element or style context changes, however, we rebuild these + * per-property arrays from the original list of keyframes objects. As a result, + * these objects represent the master definition of the effect's values. + */ +struct Keyframe +{ + Keyframe() = default; + Keyframe(const Keyframe& aOther) = default; + Keyframe(Keyframe&& aOther) + { + *this = Move(aOther); + } + + Keyframe& operator=(const Keyframe& aOther) = default; + Keyframe& operator=(Keyframe&& aOther) + { + mOffset = aOther.mOffset; + mComputedOffset = aOther.mComputedOffset; + mTimingFunction = Move(aOther.mTimingFunction); + mComposite = Move(aOther.mComposite); + mPropertyValues = Move(aOther.mPropertyValues); + return *this; + } + + Maybe mOffset; + static constexpr double kComputedOffsetNotSet = -1.0; + double mComputedOffset = kComputedOffsetNotSet; + Maybe mTimingFunction; // Nothing() here means + // "linear" + Maybe mComposite; + nsTArray mPropertyValues; +}; + +} + +#endif // mozilla_dom_Keyframe_h diff --git a/dom/animation/KeyframeEffectReadOnly.h b/dom/animation/KeyframeEffectReadOnly.h index b59e7e871cbf..bf7eb7eeaf0c 100644 --- a/dom/animation/KeyframeEffectReadOnly.h +++ b/dom/animation/KeyframeEffectReadOnly.h @@ -19,6 +19,7 @@ #include "mozilla/Attributes.h" #include "mozilla/ComputedTimingFunction.h" #include "mozilla/EffectCompositor.h" +#include "mozilla/Keyframe.h" #include "mozilla/KeyframeEffectParams.h" // RawServoDeclarationBlock and associated RefPtrTraits #include "mozilla/ServoBindingTypes.h" @@ -54,70 +55,6 @@ enum class CompositeOperation : uint8_t; struct AnimationPropertyDetails; } -/** - * A property-value pair specified on a keyframe. - */ -struct PropertyValuePair -{ - nsCSSPropertyID mProperty; - // The specified value for the property. For shorthand properties or invalid - // property values, we store the specified property value as a token stream - // (string). - nsCSSValue mValue; - - // The specified value when using the Servo backend. However, even when - // using the Servo backend, we still fill in |mValue| in the case where we - // fail to parse the value since we use it to store the original string. - RefPtr mServoDeclarationBlock; - - bool operator==(const PropertyValuePair&) const; -}; - -/** - * A single keyframe. - * - * This is the canonical form in which keyframe effects are stored and - * corresponds closely to the type of objects returned via the getKeyframes() - * API. - * - * Before computing an output animation value, however, we flatten these frames - * down to a series of per-property value arrays where we also resolve any - * overlapping shorthands/longhands, convert specified CSS values to computed - * values, etc. - * - * When the target element or style context changes, however, we rebuild these - * per-property arrays from the original list of keyframes objects. As a result, - * these objects represent the master definition of the effect's values. - */ -struct Keyframe -{ - Keyframe() = default; - Keyframe(const Keyframe& aOther) = default; - Keyframe(Keyframe&& aOther) - { - *this = Move(aOther); - } - - Keyframe& operator=(const Keyframe& aOther) = default; - Keyframe& operator=(Keyframe&& aOther) - { - mOffset = aOther.mOffset; - mComputedOffset = aOther.mComputedOffset; - mTimingFunction = Move(aOther.mTimingFunction); - mComposite = Move(aOther.mComposite); - mPropertyValues = Move(aOther.mPropertyValues); - return *this; - } - - Maybe mOffset; - static constexpr double kComputedOffsetNotSet = -1.0; - double mComputedOffset = kComputedOffsetNotSet; - Maybe mTimingFunction; // Nothing() here means - // "linear" - Maybe mComposite; - nsTArray mPropertyValues; -}; - struct AnimationPropertySegment { float mFromKey, mToKey; diff --git a/dom/animation/moz.build b/dom/animation/moz.build index 21bfc7aa0708..1d714e465cc6 100644 --- a/dom/animation/moz.build +++ b/dom/animation/moz.build @@ -30,6 +30,7 @@ EXPORTS.mozilla += [ 'ComputedTimingFunction.h', 'EffectCompositor.h', 'EffectSet.h', + 'Keyframe.h', 'KeyframeEffectParams.h', 'KeyframeUtils.h', 'PendingAnimationTracker.h',