2016-03-22 10:20:37 +03:00
|
|
|
/* -*- 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_KeyframeUtils_h
|
|
|
|
#define mozilla_KeyframeUtils_h
|
|
|
|
|
2017-06-13 10:09:19 +03:00
|
|
|
#include "mozilla/KeyframeEffectParams.h" // For CompositeOperation
|
|
|
|
#include "nsCSSPropertyID.h"
|
2016-03-22 10:20:37 +03:00
|
|
|
#include "nsTArrayForwardDeclare.h" // For nsTArray
|
|
|
|
#include "js/RootingAPI.h" // For JS::Handle
|
|
|
|
|
|
|
|
struct JSContext;
|
|
|
|
class JSObject;
|
2016-09-04 10:33:38 +03:00
|
|
|
class nsIDocument;
|
|
|
|
class nsStyleContext;
|
2017-02-23 03:52:43 +03:00
|
|
|
struct ServoComputedValues;
|
2017-03-24 12:35:27 +03:00
|
|
|
struct RawServoDeclarationBlock;
|
2016-03-22 10:20:37 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
struct AnimationProperty;
|
|
|
|
enum class CSSPseudoElementType : uint8_t;
|
2016-03-22 10:25:38 +03:00
|
|
|
class ErrorResult;
|
|
|
|
struct Keyframe;
|
2016-05-25 12:10:53 +03:00
|
|
|
struct PropertyStyleAnimationValuePair;
|
2016-03-22 10:20:37 +03:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-05-25 12:10:53 +03:00
|
|
|
// Represents the set of property-value pairs on a Keyframe converted to
|
|
|
|
// computed values.
|
|
|
|
using ComputedKeyframeValues = nsTArray<PropertyStyleAnimationValuePair>;
|
|
|
|
|
2016-03-22 10:20:37 +03:00
|
|
|
/**
|
|
|
|
* Utility methods for processing keyframes.
|
|
|
|
*/
|
|
|
|
class KeyframeUtils
|
|
|
|
{
|
|
|
|
public:
|
2016-03-22 10:25:38 +03:00
|
|
|
/**
|
|
|
|
* Converts a JS value representing a property-indexed keyframe or a sequence
|
|
|
|
* of keyframes to an array of Keyframe objects.
|
|
|
|
*
|
|
|
|
* @param aCx The JSContext that corresponds to |aFrames|.
|
2016-07-13 07:22:25 +03:00
|
|
|
* @param aDocument The document to use when parsing CSS properties.
|
2016-03-22 10:25:38 +03:00
|
|
|
* @param aFrames The JS value, provided as an optional IDL |object?| value,
|
|
|
|
* that is the keyframe list specification.
|
|
|
|
* @param aRv (out) Out-param to hold any error returned by this function.
|
|
|
|
* Must be initially empty.
|
|
|
|
* @return The set of processed keyframes. If an error occurs, aRv will be
|
|
|
|
* filled-in with the appropriate error code and an empty array will be
|
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
static nsTArray<Keyframe>
|
|
|
|
GetKeyframesFromObject(JSContext* aCx,
|
2016-07-13 07:22:25 +03:00
|
|
|
nsIDocument* aDocument,
|
2016-03-22 10:25:38 +03:00
|
|
|
JS::Handle<JSObject*> aFrames,
|
|
|
|
ErrorResult& aRv);
|
2016-03-22 10:34:14 +03:00
|
|
|
|
2016-05-25 12:10:53 +03:00
|
|
|
/**
|
|
|
|
* Calculate the StyleAnimationValues of properties of each keyframe.
|
|
|
|
* This involves expanding shorthand properties into longhand properties,
|
|
|
|
* removing the duplicated properties for each keyframe, and creating an
|
|
|
|
* array of |property:computed value| pairs for each keyframe.
|
|
|
|
*
|
|
|
|
* These computed values are used *both* when computing the final set of
|
|
|
|
* per-property animation values (see GetAnimationPropertiesFromKeyframes) as
|
|
|
|
* well when applying paced spacing. By returning these values here, we allow
|
|
|
|
* the result to be re-used in both operations.
|
|
|
|
*
|
|
|
|
* @param aKeyframes The input keyframes.
|
|
|
|
* @param aElement The context element.
|
|
|
|
* @param aStyleContext The style context to use when computing values.
|
|
|
|
* @return The set of ComputedKeyframeValues. The length will be the same as
|
|
|
|
* aFrames.
|
|
|
|
*/
|
|
|
|
static nsTArray<ComputedKeyframeValues>
|
|
|
|
GetComputedKeyframeValues(const nsTArray<Keyframe>& aKeyframes,
|
|
|
|
dom::Element* aElement,
|
|
|
|
nsStyleContext* aStyleContext);
|
|
|
|
|
2017-02-23 03:52:43 +03:00
|
|
|
static nsTArray<ComputedKeyframeValues>
|
|
|
|
GetComputedKeyframeValues(const nsTArray<Keyframe>& aKeyframes,
|
|
|
|
dom::Element* aElement,
|
2017-06-02 03:38:54 +03:00
|
|
|
const ServoComputedValues* aComputedValues);
|
2017-02-23 03:52:43 +03:00
|
|
|
|
2016-03-22 10:35:53 +03:00
|
|
|
/**
|
2017-06-13 10:09:19 +03:00
|
|
|
* Calculate the computed offset of keyframes by evenly distributing keyframes
|
|
|
|
* with a missing offset.
|
2016-03-22 10:35:53 +03:00
|
|
|
*
|
2017-06-13 10:09:19 +03:00
|
|
|
* @see https://w3c.github.io/web-animations/#calculating-computed-keyframes
|
2016-05-27 13:09:06 +03:00
|
|
|
*
|
|
|
|
* @param aKeyframes The set of keyframes to adjust.
|
|
|
|
*/
|
2017-06-15 05:47:32 +03:00
|
|
|
static void DistributeKeyframes(nsTArray<Keyframe>& aKeyframes);
|
2016-03-22 10:35:53 +03:00
|
|
|
|
2016-03-22 10:34:14 +03:00
|
|
|
/**
|
|
|
|
* Converts an array of Keyframe objects into an array of AnimationProperty
|
2016-05-25 12:10:53 +03:00
|
|
|
* objects. This involves creating an array of computed values for each
|
|
|
|
* longhand property and determining the offset and timing function to use
|
|
|
|
* for each value.
|
2016-03-22 10:34:14 +03:00
|
|
|
*
|
2016-05-25 12:10:53 +03:00
|
|
|
* @param aKeyframes The input keyframes.
|
|
|
|
* @param aComputedValues The computed keyframe values (as returned by
|
|
|
|
* GetComputedKeyframeValues) used to fill in the individual
|
|
|
|
* AnimationPropertySegment objects. Although these values could be
|
|
|
|
* calculated from |aKeyframes|, passing them in as a separate parameter
|
2017-06-13 10:09:19 +03:00
|
|
|
* allows the result of GetComputedKeyframeValues to be re-used here.
|
2016-12-04 02:07:40 +03:00
|
|
|
* @param aEffectComposite The composite operation specified on the effect.
|
|
|
|
* For any keyframes in |aKeyframes| that do not specify a composite
|
|
|
|
* operation, this value will be used.
|
2016-03-22 10:34:14 +03:00
|
|
|
* @return The set of animation properties. If an error occurs, the returned
|
|
|
|
* array will be empty.
|
|
|
|
*/
|
2016-05-25 12:10:53 +03:00
|
|
|
static nsTArray<AnimationProperty> GetAnimationPropertiesFromKeyframes(
|
|
|
|
const nsTArray<Keyframe>& aKeyframes,
|
|
|
|
const nsTArray<ComputedKeyframeValues>& aComputedValues,
|
2017-02-23 03:52:43 +03:00
|
|
|
dom::CompositeOperation aEffectComposite);
|
2016-05-13 11:38:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the property or, for shorthands, one or more of
|
|
|
|
* its subproperties, is animatable.
|
|
|
|
*
|
|
|
|
* @param aProperty The property to check.
|
2017-06-14 09:23:45 +03:00
|
|
|
* @param aBackend The style backend, Servo or Gecko, that should determine
|
|
|
|
* if the property is animatable or not.
|
2016-05-13 11:38:25 +03:00
|
|
|
* @return true if |aProperty| is animatable.
|
|
|
|
*/
|
2017-06-14 09:23:45 +03:00
|
|
|
static bool IsAnimatableProperty(nsCSSPropertyID aProperty,
|
|
|
|
StyleBackendType aBackend);
|
2017-03-24 12:35:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a string representing a CSS property value into a
|
|
|
|
* RawServoDeclarationBlock.
|
|
|
|
*
|
|
|
|
* @param aProperty The property to be parsed.
|
|
|
|
* @param aValue The specified value.
|
|
|
|
* @param aDocument The current document.
|
|
|
|
* @return The parsed value as a RawServoDeclarationBlock. We put the value
|
|
|
|
* in a declaration block since that is how we represent specified values
|
|
|
|
* in Servo.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<RawServoDeclarationBlock> ParseProperty(
|
|
|
|
nsCSSPropertyID aProperty,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIDocument* aDocument);
|
2016-03-22 10:20:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_KeyframeUtils_h
|