michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* representation of a value for a SMIL-animated CSS property */ michael@0: michael@0: #ifndef NS_SMILCSSVALUETYPE_H_ michael@0: #define NS_SMILCSSVALUETYPE_H_ michael@0: michael@0: #include "nsISMILType.h" michael@0: #include "nsCSSProperty.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsAString; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class Element; michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: /* michael@0: * nsSMILCSSValueType: Represents a SMIL-animated CSS value. michael@0: */ michael@0: class nsSMILCSSValueType : public nsISMILType michael@0: { michael@0: public: michael@0: typedef mozilla::dom::Element Element; michael@0: michael@0: // Singleton for nsSMILValue objects to hold onto. michael@0: static nsSMILCSSValueType sSingleton; michael@0: michael@0: protected: michael@0: // nsISMILType Methods michael@0: // ------------------- michael@0: virtual void Init(nsSMILValue& aValue) const MOZ_OVERRIDE; michael@0: virtual void Destroy(nsSMILValue&) const MOZ_OVERRIDE; michael@0: virtual nsresult Assign(nsSMILValue& aDest, michael@0: const nsSMILValue& aSrc) const MOZ_OVERRIDE; michael@0: virtual bool IsEqual(const nsSMILValue& aLeft, michael@0: const nsSMILValue& aRight) const MOZ_OVERRIDE; michael@0: virtual nsresult Add(nsSMILValue& aDest, michael@0: const nsSMILValue& aValueToAdd, michael@0: uint32_t aCount) const MOZ_OVERRIDE; michael@0: virtual nsresult ComputeDistance(const nsSMILValue& aFrom, michael@0: const nsSMILValue& aTo, michael@0: double& aDistance) const MOZ_OVERRIDE; michael@0: virtual nsresult Interpolate(const nsSMILValue& aStartVal, michael@0: const nsSMILValue& aEndVal, michael@0: double aUnitDistance, michael@0: nsSMILValue& aResult) const MOZ_OVERRIDE; michael@0: michael@0: public: michael@0: // Helper Methods michael@0: // -------------- michael@0: /** michael@0: * Sets up the given nsSMILValue to represent the given string value. The michael@0: * string is interpreted as a value for the given property on the given michael@0: * element. michael@0: * michael@0: * On failure, this method leaves aValue.mType == nsSMILNullType::sSingleton. michael@0: * Otherwise, this method leaves aValue.mType == this class's singleton. michael@0: * michael@0: * @param aPropID The property for which we're parsing a value. michael@0: * @param aTargetElement The target element to whom the property/value michael@0: * setting applies. michael@0: * @param aString The string to be parsed as a CSS value. michael@0: * @param [out] aValue The nsSMILValue to be populated. Should michael@0: * initially be null-typed. michael@0: * @param [out] aIsContextSensitive Set to true if |aString| may produce michael@0: * a different |aValue| depending on other michael@0: * CSS properties on |aTargetElement| michael@0: * or its ancestors (e.g. 'inherit). michael@0: * false otherwise. May be nullptr. michael@0: * Not set if the method fails. michael@0: * @pre aValue.IsNull() michael@0: * @post aValue.IsNull() || aValue.mType == nsSMILCSSValueType::sSingleton michael@0: */ michael@0: static void ValueFromString(nsCSSProperty aPropID, michael@0: Element* aTargetElement, michael@0: const nsAString& aString, michael@0: nsSMILValue& aValue, michael@0: bool* aIsContextSensitive); michael@0: michael@0: /** michael@0: * Creates a string representation of the given nsSMILValue. michael@0: * michael@0: * Note: aValue is expected to be of this type (that is, it's expected to michael@0: * have been initialized by nsSMILCSSValueType::sSingleton). If aValue is a michael@0: * freshly-initialized value, this method will succeed, though the resulting michael@0: * string will be empty. michael@0: * michael@0: * @param aValue The nsSMILValue to be converted into a string. michael@0: * @param [out] aString The string to be populated with the given value. michael@0: * @return true on success, false on failure. michael@0: */ michael@0: static bool ValueToString(const nsSMILValue& aValue, nsAString& aString); michael@0: michael@0: private: michael@0: // Private constructor: prevent instances beyond my singleton. michael@0: MOZ_CONSTEXPR nsSMILCSSValueType() {} michael@0: }; michael@0: michael@0: #endif // NS_SMILCSSVALUETYPE_H_