1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_KeyframeUtils_h
8 #define mozilla_KeyframeUtils_h
10 #include "mozilla/KeyframeEffectParams.h" // For CompositeOperation
11 #include "nsCSSPropertyID.h"
12 #include "nsTArrayForwardDeclare.h" // For nsTArray
13 #include "js/RootingAPI.h" // For JS::Handle
19 struct AnimationProperty
;
22 enum class PseudoStyleType
: uint8_t;
25 struct PropertyStyleAnimationValuePair
;
31 } // namespace mozilla
35 // Represents the set of property-value pairs on a Keyframe converted to
37 using ComputedKeyframeValues
= nsTArray
<PropertyStyleAnimationValuePair
>;
40 * Utility methods for processing keyframes.
45 * Converts a JS value representing a property-indexed keyframe or a sequence
46 * of keyframes to an array of Keyframe objects.
48 * @param aCx The JSContext that corresponds to |aFrames|.
49 * @param aDocument The document to use when parsing CSS properties.
50 * @param aFrames The JS value, provided as an optional IDL |object?| value,
51 * that is the keyframe list specification.
52 * @param aContext Information about who is trying to get keyframes from the
53 * object, for use in error reporting. This must be be a non-null
54 * pointer representing a null-terminated ASCII string.
55 * @param aRv (out) Out-param to hold any error returned by this function.
56 * Must be initially empty.
57 * @return The set of processed keyframes. If an error occurs, aRv will be
58 * filled-in with the appropriate error code and an empty array will be
61 static nsTArray
<Keyframe
> GetKeyframesFromObject(
62 JSContext
* aCx
, dom::Document
* aDocument
, JS::Handle
<JSObject
*> aFrames
,
63 const char* aContext
, ErrorResult
& aRv
);
66 * Calculate the computed offset of keyframes by evenly distributing keyframes
67 * with a missing offset.
70 * https://drafts.csswg.org/web-animations/#calculating-computed-keyframes
72 * @param aKeyframes The set of keyframes to adjust.
74 static void DistributeKeyframes(nsTArray
<Keyframe
>& aKeyframes
);
77 * Converts an array of Keyframe objects into an array of AnimationProperty
78 * objects. This involves creating an array of computed values for each
79 * longhand property and determining the offset and timing function to use
82 * @param aKeyframes The input keyframes.
83 * @param aElement The context element.
84 * @param aStyle The computed style values.
85 * @param aEffectComposite The composite operation specified on the effect.
86 * For any keyframes in |aKeyframes| that do not specify a composite
87 * operation, this value will be used.
88 * @return The set of animation properties. If an error occurs, the returned
89 * array will be empty.
91 static nsTArray
<AnimationProperty
> GetAnimationPropertiesFromKeyframes(
92 const nsTArray
<Keyframe
>& aKeyframes
, dom::Element
* aElement
,
93 PseudoStyleType aPseudoType
, const ComputedStyle
* aStyle
,
94 dom::CompositeOperation aEffectComposite
);
97 * Check if the property or, for shorthands, one or more of
98 * its subproperties, is animatable.
100 * @param aProperty The property to check.
101 * @param aBackend The style backend, Servo or Gecko, that should determine
102 * if the property is animatable or not.
103 * @return true if |aProperty| is animatable.
105 static bool IsAnimatableProperty(nsCSSPropertyID aProperty
);
108 } // namespace mozilla
110 #endif // mozilla_KeyframeUtils_h