Bug 1879449 [wpt PR 44489] - [wptrunner] Add `infrastructure/expected-fail/` test...
[gecko.git] / layout / style / StyleAnimationValue.h
blob04dc48dd90a410d1bcb2ecc4cd2d9db4f79205ba
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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Utilities for animation of computed style values */
9 #ifndef mozilla_StyleAnimationValue_h_
10 #define mozilla_StyleAnimationValue_h_
12 #include "mozilla/gfx/MatrixFwd.h"
13 #include "mozilla/gfx/Point.h"
14 #include "mozilla/RefPtr.h"
15 #include "mozilla/ServoBindingTypes.h"
16 #include "mozilla/ServoStyleConsts.h" // Servo_AnimationValue_Dump
17 #include "mozilla/DbgMacro.h"
18 #include "mozilla/AnimatedPropertyID.h"
19 #include "nsStringFwd.h"
20 #include "nsStringBuffer.h"
21 #include "nsCoord.h"
22 #include "nsColor.h"
23 #include "nsCSSPropertyID.h"
24 #include "nsCSSValue.h"
25 #include "nsStyleConsts.h"
26 #include "nsStyleTransformMatrix.h"
28 class nsIFrame;
29 class gfx3DMatrix;
31 namespace mozilla {
33 namespace css {
34 class StyleRule;
35 } // namespace css
37 namespace dom {
38 class Element;
39 } // namespace dom
41 namespace layers {
42 class Animatable;
43 } // namespace layers
45 enum class PseudoStyleType : uint8_t;
46 struct PropertyStyleAnimationValuePair;
48 struct AnimationValue {
49 explicit AnimationValue(const RefPtr<StyleAnimationValue>& aValue)
50 : mServo(aValue) {}
51 AnimationValue() = default;
53 AnimationValue(const AnimationValue& aOther) = default;
54 AnimationValue(AnimationValue&& aOther) = default;
56 AnimationValue& operator=(const AnimationValue& aOther) = default;
57 AnimationValue& operator=(AnimationValue&& aOther) = default;
59 bool operator==(const AnimationValue& aOther) const;
60 bool operator!=(const AnimationValue& aOther) const;
62 bool IsNull() const { return !mServo; }
64 float GetOpacity() const;
66 // Returns nscolor value in this AnimationValue.
67 // Currently only background-color is supported.
68 nscolor GetColor(nscolor aForegroundColor) const;
70 // Returns true if this AnimationValue is current-color.
71 // Currently only background-color is supported.
72 bool IsCurrentColor() const;
74 // Return a transform list for the transform property.
75 const mozilla::StyleTransform& GetTransformProperty() const;
76 const mozilla::StyleScale& GetScaleProperty() const;
77 const mozilla::StyleTranslate& GetTranslateProperty() const;
78 const mozilla::StyleRotate& GetRotateProperty() const;
80 // Motion path properties.
81 // Note: This clones the StyleOffsetPath object from its AnimatedValue, so
82 // this may be expensive if the path is a complex SVG path or polygon. The
83 // caller should be aware of this performance impact.
84 void GetOffsetPathProperty(StyleOffsetPath& aOffsetPath) const;
85 const mozilla::LengthPercentage& GetOffsetDistanceProperty() const;
86 const mozilla::StyleOffsetRotate& GetOffsetRotateProperty() const;
87 const mozilla::StylePositionOrAuto& GetOffsetAnchorProperty() const;
88 const mozilla::StyleOffsetPosition& GetOffsetPositionProperty() const;
89 bool IsOffsetPathUrl() const;
91 // Return the scale for mServo, which is calculated with reference to aFrame.
92 mozilla::gfx::MatrixScales GetScaleValue(const nsIFrame* aFrame) const;
94 // Uncompute this AnimationValue and then serialize it.
95 void SerializeSpecifiedValue(const AnimatedPropertyID& aProperty,
96 const StylePerDocumentStyleData* aRawData,
97 nsACString& aString) const;
99 // Check if |*this| and |aToValue| can be interpolated.
100 bool IsInterpolableWith(const AnimatedPropertyID& aProperty,
101 const AnimationValue& aToValue) const;
103 // Compute the distance between *this and aOther.
104 double ComputeDistance(const AnimationValue& aOther) const;
106 // Create an AnimaitonValue from a string. This method flushes style, so we
107 // should use this carefully. Now, it is only used by
108 // nsDOMWindowUtils::ComputeAnimationDistance.
109 static AnimationValue FromString(AnimatedPropertyID& aProperty,
110 const nsACString& aValue,
111 dom::Element* aElement);
113 // Create an already_AddRefed<StyleAnimationValue> from a
114 // layers::Animatable. Basically, this function should return AnimationValue,
115 // but it seems the caller, AnimationHelper, only needs
116 // StyleAnimationValue, so we return its already_AddRefed<> to avoid
117 // adding/removing a redundant ref-count.
118 static already_AddRefed<StyleAnimationValue> FromAnimatable(
119 nsCSSPropertyID aProperty, const layers::Animatable& aAnimatable);
121 RefPtr<StyleAnimationValue> mServo;
124 inline std::ostream& operator<<(std::ostream& aOut,
125 const AnimationValue& aValue) {
126 MOZ_ASSERT(aValue.mServo);
127 nsAutoCString s;
128 Servo_AnimationValue_Dump(aValue.mServo, &s);
129 return aOut << s;
132 struct PropertyStyleAnimationValuePair {
133 AnimatedPropertyID mProperty;
134 AnimationValue mValue;
136 } // namespace mozilla
138 #endif