Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / smil / nsSMILCSSValueType.h
blobc04be8ab99e6c04cb70c74ee62ce33bba435cffe
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* representation of a value for a SMIL-animated CSS property */
8 #ifndef NS_SMILCSSVALUETYPE_H_
9 #define NS_SMILCSSVALUETYPE_H_
11 #include "nsISMILType.h"
12 #include "nsCSSProperty.h"
13 #include "mozilla/Attributes.h"
15 class nsAString;
17 namespace mozilla {
18 namespace dom {
19 class Element;
20 } // namespace dom
21 } // namespace mozilla
24 * nsSMILCSSValueType: Represents a SMIL-animated CSS value.
26 class nsSMILCSSValueType : public nsISMILType
28 public:
29 typedef mozilla::dom::Element Element;
31 // Singleton for nsSMILValue objects to hold onto.
32 static nsSMILCSSValueType sSingleton;
34 protected:
35 // nsISMILType Methods
36 // -------------------
37 virtual void Init(nsSMILValue& aValue) const MOZ_OVERRIDE;
38 virtual void Destroy(nsSMILValue&) const MOZ_OVERRIDE;
39 virtual nsresult Assign(nsSMILValue& aDest,
40 const nsSMILValue& aSrc) const MOZ_OVERRIDE;
41 virtual bool IsEqual(const nsSMILValue& aLeft,
42 const nsSMILValue& aRight) const MOZ_OVERRIDE;
43 virtual nsresult Add(nsSMILValue& aDest,
44 const nsSMILValue& aValueToAdd,
45 uint32_t aCount) const MOZ_OVERRIDE;
46 virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
47 const nsSMILValue& aTo,
48 double& aDistance) const MOZ_OVERRIDE;
49 virtual nsresult Interpolate(const nsSMILValue& aStartVal,
50 const nsSMILValue& aEndVal,
51 double aUnitDistance,
52 nsSMILValue& aResult) const MOZ_OVERRIDE;
54 public:
55 // Helper Methods
56 // --------------
57 /**
58 * Sets up the given nsSMILValue to represent the given string value. The
59 * string is interpreted as a value for the given property on the given
60 * element.
62 * On failure, this method leaves aValue.mType == nsSMILNullType::sSingleton.
63 * Otherwise, this method leaves aValue.mType == this class's singleton.
65 * @param aPropID The property for which we're parsing a value.
66 * @param aTargetElement The target element to whom the property/value
67 * setting applies.
68 * @param aString The string to be parsed as a CSS value.
69 * @param [out] aValue The nsSMILValue to be populated. Should
70 * initially be null-typed.
71 * @param [out] aIsContextSensitive Set to true if |aString| may produce
72 * a different |aValue| depending on other
73 * CSS properties on |aTargetElement|
74 * or its ancestors (e.g. 'inherit).
75 * false otherwise. May be nullptr.
76 * Not set if the method fails.
77 * @pre aValue.IsNull()
78 * @post aValue.IsNull() || aValue.mType == nsSMILCSSValueType::sSingleton
80 static void ValueFromString(nsCSSProperty aPropID,
81 Element* aTargetElement,
82 const nsAString& aString,
83 nsSMILValue& aValue,
84 bool* aIsContextSensitive);
86 /**
87 * Creates a string representation of the given nsSMILValue.
89 * Note: aValue is expected to be of this type (that is, it's expected to
90 * have been initialized by nsSMILCSSValueType::sSingleton). If aValue is a
91 * freshly-initialized value, this method will succeed, though the resulting
92 * string will be empty.
94 * @param aValue The nsSMILValue to be converted into a string.
95 * @param [out] aString The string to be populated with the given value.
96 * @return true on success, false on failure.
98 static bool ValueToString(const nsSMILValue& aValue, nsAString& aString);
100 private:
101 // Private constructor: prevent instances beyond my singleton.
102 MOZ_CONSTEXPR nsSMILCSSValueType() {}
105 #endif // NS_SMILCSSVALUETYPE_H_