dom/smil/nsISMILType.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef NS_ISMILTYPE_H_
michael@0 7 #define NS_ISMILTYPE_H_
michael@0 8
michael@0 9 #include "mozilla/Attributes.h"
michael@0 10 #include "nscore.h"
michael@0 11
michael@0 12 class nsSMILValue;
michael@0 13
michael@0 14 //////////////////////////////////////////////////////////////////////////////
michael@0 15 // nsISMILType: Interface for defining the basic operations needed for animating
michael@0 16 // a particular kind of data (e.g. lengths, colors, transformation matrices).
michael@0 17 //
michael@0 18 // This interface is never used directly but always through an nsSMILValue that
michael@0 19 // bundles together a pointer to a concrete implementation of this interface and
michael@0 20 // the data upon which it should operate.
michael@0 21 //
michael@0 22 // We keep the data and type separate rather than just providing different
michael@0 23 // subclasses of nsSMILValue. This is so that sizeof(nsSMILValue) is the same
michael@0 24 // for all value types, allowing us to have a type-agnostic nsTArray of
michael@0 25 // nsSMILValue objects (actual objects, not pointers). It also allows most
michael@0 26 // nsSMILValues (except those that need to allocate extra memory for their
michael@0 27 // data) to be allocated on the stack and directly assigned to one another
michael@0 28 // provided performance benefits for the animation code.
michael@0 29 //
michael@0 30 // Note that different types have different capabilities. Roughly speaking there
michael@0 31 // are probably three main types:
michael@0 32 //
michael@0 33 // +---------------------+---------------+-------------+------------------+
michael@0 34 // | CATEGORY: | DISCRETE | LINEAR | ADDITIVE |
michael@0 35 // +---------------------+---------------+-------------+------------------+
michael@0 36 // | Example: | strings, | path data? | lengths, |
michael@0 37 // | | color k/words?| | RGB color values |
michael@0 38 // | | | | |
michael@0 39 // | -- Assign? | X | X | X |
michael@0 40 // | -- Add? | - | X? | X |
michael@0 41 // | -- SandwichAdd? | - | -? | X |
michael@0 42 // | -- ComputeDistance? | - | - | X? |
michael@0 43 // | -- Interpolate? | - | X | X |
michael@0 44 // +---------------------+---------------+-------------+------------------+
michael@0 45 //
michael@0 46
michael@0 47 class nsISMILType
michael@0 48 {
michael@0 49 /**
michael@0 50 * Only give the nsSMILValue class access to this interface.
michael@0 51 */
michael@0 52 friend class nsSMILValue;
michael@0 53
michael@0 54 protected:
michael@0 55 /**
michael@0 56 * Initialises aValue and sets it to some identity value such that adding
michael@0 57 * aValue to another value of the same type has no effect.
michael@0 58 *
michael@0 59 * @pre aValue.IsNull()
michael@0 60 * @post aValue.mType == this
michael@0 61 */
michael@0 62 virtual void Init(nsSMILValue& aValue) const = 0;
michael@0 63
michael@0 64 /**
michael@0 65 * Destroys any data associated with a value of this type.
michael@0 66 *
michael@0 67 * @pre aValue.mType == this
michael@0 68 * @post aValue.IsNull()
michael@0 69 */
michael@0 70 virtual void Destroy(nsSMILValue& aValue) const = 0;
michael@0 71
michael@0 72 /**
michael@0 73 * Assign this object the value of another. Think of this as the assignment
michael@0 74 * operator.
michael@0 75 *
michael@0 76 * @param aDest The left-hand side of the assignment.
michael@0 77 * @param aSrc The right-hand side of the assignment.
michael@0 78 * @return NS_OK on success, an error code on failure such as when the
michael@0 79 * underlying type of the specified object differs.
michael@0 80 *
michael@0 81 * @pre aDest.mType == aSrc.mType == this
michael@0 82 */
michael@0 83 virtual nsresult Assign(nsSMILValue& aDest,
michael@0 84 const nsSMILValue& aSrc) const = 0;
michael@0 85
michael@0 86 /**
michael@0 87 * Test two nsSMILValue objects (of this nsISMILType) for equality.
michael@0 88 *
michael@0 89 * A return value of true represents a guarantee that aLeft and aRight are
michael@0 90 * equal. (That is, they would behave identically if passed to the methods
michael@0 91 * Add, SandwichAdd, ComputeDistance, and Interpolate).
michael@0 92 *
michael@0 93 * A return value of false simply indicates that we make no guarantee
michael@0 94 * about equality.
michael@0 95 *
michael@0 96 * NOTE: It's perfectly legal for implementations of this method to return
michael@0 97 * false in all cases. However, smarter implementations will make this
michael@0 98 * method more useful for optimization.
michael@0 99 *
michael@0 100 * @param aLeft The left-hand side of the equality check.
michael@0 101 * @param aRight The right-hand side of the equality check.
michael@0 102 * @return true if we're sure the values are equal, false otherwise.
michael@0 103 *
michael@0 104 * @pre aDest.mType == aSrc.mType == this
michael@0 105 */
michael@0 106 virtual bool IsEqual(const nsSMILValue& aLeft,
michael@0 107 const nsSMILValue& aRight) const = 0;
michael@0 108
michael@0 109 /**
michael@0 110 * Adds two values.
michael@0 111 *
michael@0 112 * The count parameter facilitates repetition.
michael@0 113 *
michael@0 114 * By equation,
michael@0 115 *
michael@0 116 * aDest += aValueToAdd * aCount
michael@0 117 *
michael@0 118 * Therefore, if aCount == 0, aDest will be unaltered.
michael@0 119 *
michael@0 120 * This method will fail if this data type is not additive or the value was
michael@0 121 * not specified using an additive syntax.
michael@0 122 *
michael@0 123 * See SVG 1.1, section 19.2.5. In particular,
michael@0 124 *
michael@0 125 * "If a given attribute or property can take values of keywords (which are
michael@0 126 * not additive) or numeric values (which are additive), then additive
michael@0 127 * animations are possible if the subsequent animation uses a numeric value
michael@0 128 * even if the base animation uses a keyword value; however, if the
michael@0 129 * subsequent animation uses a keyword value, additive animation is not
michael@0 130 * possible."
michael@0 131 *
michael@0 132 * If this method fails (e.g. because the data type is not additive), aDest
michael@0 133 * will be unaltered.
michael@0 134 *
michael@0 135 * @param aDest The value to add to.
michael@0 136 * @param aValueToAdd The value to add.
michael@0 137 * @param aCount The number of times to add aValueToAdd.
michael@0 138 * @return NS_OK on success, an error code on failure.
michael@0 139 *
michael@0 140 * @pre aValueToAdd.mType == aDest.mType == this
michael@0 141 */
michael@0 142 virtual nsresult Add(nsSMILValue& aDest,
michael@0 143 const nsSMILValue& aValueToAdd,
michael@0 144 uint32_t aCount) const = 0;
michael@0 145
michael@0 146 /**
michael@0 147 * Adds aValueToAdd to the underlying value in the animation sandwich, aDest.
michael@0 148 *
michael@0 149 * For most types this operation is identical to a regular Add() but for some
michael@0 150 * types (notably <animateTransform>) the operation differs. For
michael@0 151 * <animateTransform> Add() corresponds to simply adding together the
michael@0 152 * transform parameters and is used when calculating cumulative values or
michael@0 153 * by-animation values. On the other hand SandwichAdd() is used when adding to
michael@0 154 * the underlying value and requires matrix post-multiplication. (This
michael@0 155 * distinction is most clearly indicated by the SVGT1.2 test suite. It is not
michael@0 156 * obvious within the SMIL specifications.)
michael@0 157 *
michael@0 158 * @param aDest The value to add to.
michael@0 159 * @param aValueToAdd The value to add.
michael@0 160 * @return NS_OK on success, an error code on failure.
michael@0 161 *
michael@0 162 * @pre aValueToAdd.mType == aDest.mType == this
michael@0 163 */
michael@0 164 virtual nsresult SandwichAdd(nsSMILValue& aDest,
michael@0 165 const nsSMILValue& aValueToAdd) const
michael@0 166 {
michael@0 167 return Add(aDest, aValueToAdd, 1);
michael@0 168 }
michael@0 169
michael@0 170 /**
michael@0 171 * Calculates the 'distance' between two values. This is the distance used in
michael@0 172 * paced interpolation.
michael@0 173 *
michael@0 174 * @param aFrom The start of the interval for which the distance should
michael@0 175 * be calculated.
michael@0 176 * @param aTo The end of the interval for which the distance should be
michael@0 177 * calculated.
michael@0 178 * @param aDistance The result of the calculation.
michael@0 179 * @return NS_OK on success, or an appropriate error code if there is no
michael@0 180 * notion of distance for the underlying data type or the distance
michael@0 181 * could not be calculated.
michael@0 182 *
michael@0 183 * @pre aFrom.mType == aTo.mType == this
michael@0 184 */
michael@0 185 virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
michael@0 186 const nsSMILValue& aTo,
michael@0 187 double& aDistance) const = 0;
michael@0 188
michael@0 189 /**
michael@0 190 * Calculates an interpolated value between two values using the specified
michael@0 191 * proportion.
michael@0 192 *
michael@0 193 * @param aStartVal The value defining the start of the interval of
michael@0 194 * interpolation.
michael@0 195 * @param aEndVal The value defining the end of the interval of
michael@0 196 * interpolation.
michael@0 197 * @param aUnitDistance A number between 0.0 and 1.0 (inclusive) defining
michael@0 198 * the distance of the interpolated value in the
michael@0 199 * interval.
michael@0 200 * @param aResult The interpolated value.
michael@0 201 * @return NS_OK on success, NS_ERROR_FAILURE if this data type cannot be
michael@0 202 * interpolated or NS_ERROR_OUT_OF_MEMORY if insufficient memory was
michael@0 203 * available for storing the result.
michael@0 204 *
michael@0 205 * @pre aStartVal.mType == aEndVal.mType == aResult.mType == this
michael@0 206 */
michael@0 207 virtual nsresult Interpolate(const nsSMILValue& aStartVal,
michael@0 208 const nsSMILValue& aEndVal,
michael@0 209 double aUnitDistance,
michael@0 210 nsSMILValue& aResult) const = 0;
michael@0 211 };
michael@0 212
michael@0 213 #endif // NS_ISMILTYPE_H_

mercurial