Bug 1691109 [wpt PR 27513] - Increase timeout duration for wpt/fetch/api/basic/keepal...
[gecko.git] / dom / animation / KeyframeUtils.h
blobe96a28f3635a09a38bea3ef9ce67a4fe98efcfe7
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
15 struct JSContext;
16 class JSObject;
17 struct RawServoDeclarationBlock;
19 namespace mozilla {
20 struct AnimationProperty;
21 class ComputedStyle;
23 enum class PseudoStyleType : uint8_t;
24 class ErrorResult;
25 struct Keyframe;
26 struct PropertyStyleAnimationValuePair;
28 namespace dom {
29 class Document;
30 class Element;
31 } // namespace dom
32 } // namespace mozilla
34 namespace mozilla {
36 // Represents the set of property-value pairs on a Keyframe converted to
37 // computed values.
38 using ComputedKeyframeValues = nsTArray<PropertyStyleAnimationValuePair>;
40 /**
41 * Utility methods for processing keyframes.
43 class KeyframeUtils {
44 public:
45 /**
46 * Converts a JS value representing a property-indexed keyframe or a sequence
47 * of keyframes to an array of Keyframe objects.
49 * @param aCx The JSContext that corresponds to |aFrames|.
50 * @param aDocument The document to use when parsing CSS properties.
51 * @param aFrames The JS value, provided as an optional IDL |object?| value,
52 * that is the keyframe list specification.
53 * @param aContext Information about who is trying to get keyframes from the
54 * object, for use in error reporting. This must be be a non-null
55 * pointer representing a null-terminated ASCII string.
56 * @param aRv (out) Out-param to hold any error returned by this function.
57 * Must be initially empty.
58 * @return The set of processed keyframes. If an error occurs, aRv will be
59 * filled-in with the appropriate error code and an empty array will be
60 * returned.
62 static nsTArray<Keyframe> GetKeyframesFromObject(
63 JSContext* aCx, dom::Document* aDocument, JS::Handle<JSObject*> aFrames,
64 const char* aContext, ErrorResult& aRv);
66 /**
67 * Calculate the computed offset of keyframes by evenly distributing keyframes
68 * with a missing offset.
70 * @see
71 * https://drafts.csswg.org/web-animations/#calculating-computed-keyframes
73 * @param aKeyframes The set of keyframes to adjust.
75 static void DistributeKeyframes(nsTArray<Keyframe>& aKeyframes);
77 /**
78 * Converts an array of Keyframe objects into an array of AnimationProperty
79 * objects. This involves creating an array of computed values for each
80 * longhand property and determining the offset and timing function to use
81 * for each value.
83 * @param aKeyframes The input keyframes.
84 * @param aElement The context element.
85 * @param aStyle The computed style values.
86 * @param aEffectComposite The composite operation specified on the effect.
87 * For any keyframes in |aKeyframes| that do not specify a composite
88 * operation, this value will be used.
89 * @return The set of animation properties. If an error occurs, the returned
90 * array will be empty.
92 static nsTArray<AnimationProperty> GetAnimationPropertiesFromKeyframes(
93 const nsTArray<Keyframe>& aKeyframes, dom::Element* aElement,
94 PseudoStyleType aPseudoType, const ComputedStyle* aStyle,
95 dom::CompositeOperation aEffectComposite);
97 /**
98 * Check if the property or, for shorthands, one or more of
99 * its subproperties, is animatable.
101 * @param aProperty The property to check.
102 * @param aBackend The style backend, Servo or Gecko, that should determine
103 * if the property is animatable or not.
104 * @return true if |aProperty| is animatable.
106 static bool IsAnimatableProperty(nsCSSPropertyID aProperty);
109 } // namespace mozilla
111 #endif // mozilla_KeyframeUtils_h