1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/nsSMILValue.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 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 +#ifndef NS_SMILVALUE_H_ 1.10 +#define NS_SMILVALUE_H_ 1.11 + 1.12 +#include "nsISMILType.h" 1.13 +#include "nsSMILNullType.h" 1.14 + 1.15 +/** 1.16 + * Although objects of this type are generally only created on the stack and 1.17 + * only exist during the taking of a new time sample, that's not always the 1.18 + * case. The nsSMILValue objects obtained from attributes' base values are 1.19 + * cached so that the SMIL engine can make certain optimizations during a 1.20 + * sample if the base value has not changed since the last sample (potentially 1.21 + * avoiding recomposing). These nsSMILValue objects typically live much longer 1.22 + * than a single sample. 1.23 + */ 1.24 +class nsSMILValue 1.25 +{ 1.26 +public: 1.27 + nsSMILValue() : mU(), mType(nsSMILNullType::Singleton()) { } 1.28 + explicit nsSMILValue(const nsISMILType* aType); 1.29 + nsSMILValue(const nsSMILValue& aVal); 1.30 + 1.31 + ~nsSMILValue() 1.32 + { 1.33 + mType->Destroy(*this); 1.34 + } 1.35 + 1.36 + const nsSMILValue& operator=(const nsSMILValue& aVal); 1.37 + 1.38 + // Equality operators. These are allowed to be conservative (return false 1.39 + // more than you'd expect) - see comment above nsISMILType::IsEqual. 1.40 + bool operator==(const nsSMILValue& aVal) const; 1.41 + bool operator!=(const nsSMILValue& aVal) const { 1.42 + return !(*this == aVal); 1.43 + } 1.44 + 1.45 + bool IsNull() const 1.46 + { 1.47 + return (mType == nsSMILNullType::Singleton()); 1.48 + } 1.49 + 1.50 + // Swaps the member data (mU & mPtr) of |this| with |aOther| 1.51 + void Swap(nsSMILValue& aOther); 1.52 + 1.53 + nsresult Add(const nsSMILValue& aValueToAdd, uint32_t aCount = 1); 1.54 + nsresult SandwichAdd(const nsSMILValue& aValueToAdd); 1.55 + nsresult ComputeDistance(const nsSMILValue& aTo, double& aDistance) const; 1.56 + nsresult Interpolate(const nsSMILValue& aEndVal, 1.57 + double aUnitDistance, 1.58 + nsSMILValue& aResult) const; 1.59 + 1.60 + union { 1.61 + bool mBool; 1.62 + uint64_t mUint; 1.63 + int64_t mInt; 1.64 + double mDouble; 1.65 + struct { 1.66 + float mAngle; 1.67 + uint16_t mUnit; 1.68 + uint16_t mOrientType; 1.69 + } mOrient; 1.70 + int32_t mIntPair[2]; 1.71 + float mNumberPair[2]; 1.72 + void* mPtr; 1.73 + } mU; 1.74 + const nsISMILType* mType; 1.75 + 1.76 +protected: 1.77 + void InitAndCheckPostcondition(const nsISMILType* aNewType); 1.78 + void DestroyAndCheckPostcondition(); 1.79 + void DestroyAndReinit(const nsISMILType* aNewType); 1.80 +}; 1.81 + 1.82 +#endif // NS_SMILVALUE_H_