dom/smil/nsSMILCSSValueType.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/nsSMILCSSValueType.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,105 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* representation of a value for a SMIL-animated CSS property */
    1.10 +
    1.11 +#ifndef NS_SMILCSSVALUETYPE_H_
    1.12 +#define NS_SMILCSSVALUETYPE_H_
    1.13 +
    1.14 +#include "nsISMILType.h"
    1.15 +#include "nsCSSProperty.h"
    1.16 +#include "mozilla/Attributes.h"
    1.17 +
    1.18 +class nsAString;
    1.19 +
    1.20 +namespace mozilla {
    1.21 +namespace dom {
    1.22 +class Element;
    1.23 +} // namespace dom
    1.24 +} // namespace mozilla
    1.25 +
    1.26 +/*
    1.27 + * nsSMILCSSValueType: Represents a SMIL-animated CSS value.
    1.28 + */
    1.29 +class nsSMILCSSValueType : public nsISMILType
    1.30 +{
    1.31 +public:
    1.32 +  typedef mozilla::dom::Element Element;
    1.33 +
    1.34 +  // Singleton for nsSMILValue objects to hold onto.
    1.35 +  static nsSMILCSSValueType sSingleton;
    1.36 +
    1.37 +protected:
    1.38 +  // nsISMILType Methods
    1.39 +  // -------------------
    1.40 +  virtual void     Init(nsSMILValue& aValue) const MOZ_OVERRIDE;
    1.41 +  virtual void     Destroy(nsSMILValue&) const MOZ_OVERRIDE;
    1.42 +  virtual nsresult Assign(nsSMILValue& aDest,
    1.43 +                          const nsSMILValue& aSrc) const MOZ_OVERRIDE;
    1.44 +  virtual bool     IsEqual(const nsSMILValue& aLeft,
    1.45 +                           const nsSMILValue& aRight) const MOZ_OVERRIDE;
    1.46 +  virtual nsresult Add(nsSMILValue& aDest,
    1.47 +                       const nsSMILValue& aValueToAdd,
    1.48 +                       uint32_t aCount) const MOZ_OVERRIDE;
    1.49 +  virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
    1.50 +                                   const nsSMILValue& aTo,
    1.51 +                                   double& aDistance) const MOZ_OVERRIDE;
    1.52 +  virtual nsresult Interpolate(const nsSMILValue& aStartVal,
    1.53 +                               const nsSMILValue& aEndVal,
    1.54 +                               double aUnitDistance,
    1.55 +                               nsSMILValue& aResult) const MOZ_OVERRIDE;
    1.56 +
    1.57 +public:
    1.58 +  // Helper Methods
    1.59 +  // --------------
    1.60 +  /**
    1.61 +   * Sets up the given nsSMILValue to represent the given string value.  The
    1.62 +   * string is interpreted as a value for the given property on the given
    1.63 +   * element.
    1.64 +   *
    1.65 +   * On failure, this method leaves aValue.mType == nsSMILNullType::sSingleton.
    1.66 +   * Otherwise, this method leaves aValue.mType == this class's singleton.
    1.67 +   *
    1.68 +   * @param       aPropID         The property for which we're parsing a value.
    1.69 +   * @param       aTargetElement  The target element to whom the property/value
    1.70 +   *                              setting applies.
    1.71 +   * @param       aString         The string to be parsed as a CSS value.
    1.72 +   * @param [out] aValue          The nsSMILValue to be populated. Should
    1.73 +   *                              initially be null-typed.
    1.74 +   * @param [out] aIsContextSensitive Set to true if |aString| may produce
    1.75 +   *                                  a different |aValue| depending on other
    1.76 +   *                                  CSS properties on |aTargetElement|
    1.77 +   *                                  or its ancestors (e.g. 'inherit).
    1.78 +   *                                  false otherwise. May be nullptr.
    1.79 +   *                                  Not set if the method fails.
    1.80 +   * @pre  aValue.IsNull()
    1.81 +   * @post aValue.IsNull() || aValue.mType == nsSMILCSSValueType::sSingleton
    1.82 +   */
    1.83 +  static void ValueFromString(nsCSSProperty aPropID,
    1.84 +                              Element* aTargetElement,
    1.85 +                              const nsAString& aString,
    1.86 +                              nsSMILValue& aValue,
    1.87 +                              bool* aIsContextSensitive);
    1.88 +
    1.89 +  /**
    1.90 +   * Creates a string representation of the given nsSMILValue.
    1.91 +   *
    1.92 +   * Note: aValue is expected to be of this type (that is, it's expected to
    1.93 +   * have been initialized by nsSMILCSSValueType::sSingleton).  If aValue is a
    1.94 +   * freshly-initialized value, this method will succeed, though the resulting
    1.95 +   * string will be empty.
    1.96 +   *
    1.97 +   * @param       aValue   The nsSMILValue to be converted into a string.
    1.98 +   * @param [out] aString  The string to be populated with the given value.
    1.99 +   * @return               true on success, false on failure.
   1.100 +   */
   1.101 +  static bool ValueToString(const nsSMILValue& aValue, nsAString& aString);
   1.102 +
   1.103 +private:
   1.104 +  // Private constructor: prevent instances beyond my singleton.
   1.105 +  MOZ_CONSTEXPR nsSMILCSSValueType() {}
   1.106 +};
   1.107 +
   1.108 +#endif // NS_SMILCSSVALUETYPE_H_

mercurial