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 /* representation of a value for a SMIL-animated CSS property */
9 #ifndef DOM_SMIL_SMILCSSVALUETYPE_H_
10 #define DOM_SMIL_SMILCSSVALUETYPE_H_
12 #include "mozilla/Attributes.h"
13 #include "mozilla/SMILType.h"
14 #include "nsCSSPropertyID.h"
15 #include "nsStringFwd.h"
18 struct AnimationValue
;
19 class DeclarationBlock
;
25 * SMILCSSValueType: Represents a SMIL-animated CSS value.
27 class SMILCSSValueType
: public SMILType
{
29 // Singleton for SMILValue objects to hold onto.
30 static SMILCSSValueType sSingleton
;
34 // -------------------
35 void Init(SMILValue
& aValue
) const override
;
36 void Destroy(SMILValue
&) const override
;
37 nsresult
Assign(SMILValue
& aDest
, const SMILValue
& aSrc
) const override
;
38 bool IsEqual(const SMILValue
& aLeft
, const SMILValue
& aRight
) const override
;
39 nsresult
Add(SMILValue
& aDest
, const SMILValue
& aValueToAdd
,
40 uint32_t aCount
) const override
;
41 nsresult
SandwichAdd(SMILValue
& aDest
,
42 const SMILValue
& aValueToAdd
) const override
;
43 nsresult
ComputeDistance(const SMILValue
& aFrom
, const SMILValue
& aTo
,
44 double& aDistance
) const override
;
45 nsresult
Interpolate(const SMILValue
& aStartVal
, const SMILValue
& aEndVal
,
46 double aUnitDistance
, SMILValue
& aResult
) const override
;
52 * Sets up the given SMILValue to represent the given string value. The
53 * string is interpreted as a value for the given property on the given
56 * On failure, this method leaves aValue.mType == SMILNullType::sSingleton.
57 * Otherwise, this method leaves aValue.mType == this class's singleton.
59 * @param aPropID The property for which we're parsing a value.
60 * @param aTargetElement The target element to whom the property/value
62 * @param aString The string to be parsed as a CSS value.
63 * @param [out] aValue The SMILValue to be populated. Should
64 * initially be null-typed.
65 * @param [out] aIsContextSensitive Set to true if |aString| may produce
66 * a different |aValue| depending on other
67 * CSS properties on |aTargetElement|
68 * or its ancestors (e.g. 'inherit).
69 * false otherwise. May be nullptr.
70 * Not set if the method fails.
71 * @pre aValue.IsNull()
72 * @post aValue.IsNull() || aValue.mType == SMILCSSValueType::sSingleton
74 static void ValueFromString(nsCSSPropertyID aPropID
,
75 dom::Element
* aTargetElement
,
76 const nsAString
& aString
, SMILValue
& aValue
,
77 bool* aIsContextSensitive
);
80 * Creates a SMILValue to wrap the given animation value.
82 * @param aPropID The property that |aValue| corresponds to.
83 * @param aTargetElement The target element to which the animation value
85 * @param aValue The animation value to use.
86 * @return A new SMILValue. On failure, returns a
87 * SMILValue with the null type (i.e. rv.IsNull()
90 static SMILValue
ValueFromAnimationValue(nsCSSPropertyID aPropID
,
91 dom::Element
* aTargetElement
,
92 const AnimationValue
& aValue
);
95 * Sets the relevant property values in the declaration block.
97 * Returns whether the declaration changed.
99 static bool SetPropertyValues(const SMILValue
&, mozilla::DeclarationBlock
&);
102 * Return the CSS property animated by the specified value.
104 * @param aValue The SMILValue to examine.
105 * @return The nsCSSPropertyID enum value of the property animated
106 * by |aValue|, or eCSSProperty_UNKNOWN if the type of
107 * |aValue| is not SMILCSSValueType.
109 static nsCSSPropertyID
PropertyFromValue(const SMILValue
& aValue
);
112 * If |aValue| is an empty value, converts it to a suitable zero value by
113 * matching the type of value stored in |aValueToMatch|.
115 * There is no indication if this method fails. If a suitable zero value could
116 * not be created, |aValue| is simply unmodified.
118 * @param aValue The SMILValue (of type SMILCSSValueType) to
120 * @param aValueToMatch A SMILValue (of type SMILCSSValueType) for which
121 * a corresponding zero value will be created if |aValue|
124 static void FinalizeValue(SMILValue
& aValue
, const SMILValue
& aValueToMatch
);
127 // Private constructor: prevent instances beyond my singleton.
128 constexpr SMILCSSValueType() = default;
131 } // namespace mozilla
133 #endif // DOM_SMIL_SMILCSSVALUETYPE_H_