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