StyleAnimationValue.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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/. */
  5. /* Utilities for animation of computed style values */
  6. #ifndef mozilla_StyleAnimationValue_h_
  7. #define mozilla_StyleAnimationValue_h_
  8. #include "mozilla/gfx/MatrixFwd.h"
  9. #include "mozilla/UniquePtr.h"
  10. #include "nsStringFwd.h"
  11. #include "nsStringBuffer.h"
  12. #include "nsCoord.h"
  13. #include "nsColor.h"
  14. #include "nsCSSProps.h"
  15. #include "nsCSSValue.h"
  16. #include "nsStyleCoord.h"
  17. class nsIFrame;
  18. class nsStyleContext;
  19. class gfx3DMatrix;
  20. struct RawServoDeclarationBlock;
  21. namespace mozilla {
  22. namespace css {
  23. class StyleRule;
  24. } // namespace css
  25. namespace dom {
  26. class Element;
  27. } // namespace dom
  28. enum class CSSPseudoElementType : uint8_t;
  29. struct PropertyStyleAnimationValuePair;
  30. /**
  31. * Utility class to handle animated style values
  32. */
  33. class StyleAnimationValue {
  34. public:
  35. // Mathematical methods
  36. // --------------------
  37. /**
  38. * Adds |aCount| copies of |aValueToAdd| to |aDest|. The result of this
  39. * addition is stored in aDest.
  40. *
  41. * Note that if |aCount| is 0, then |aDest| will be unchanged. Also, if
  42. * this method fails, then |aDest| will be unchanged.
  43. *
  44. * @param aDest The value to add to.
  45. * @param aValueToAdd The value to add.
  46. * @param aCount The number of times to add aValueToAdd.
  47. * @return true on success, false on failure.
  48. */
  49. static MOZ_MUST_USE bool
  50. Add(nsCSSPropertyID aProperty, StyleAnimationValue& aDest,
  51. const StyleAnimationValue& aValueToAdd, uint32_t aCount) {
  52. return AddWeighted(aProperty, 1.0, aDest, aCount, aValueToAdd, aDest);
  53. }
  54. /**
  55. * Calculates a measure of 'distance' between two colors.
  56. *
  57. * @param aStartColor The start of the interval for which the distance
  58. * should be calculated.
  59. * @param aEndColor The end of the interval for which the distance
  60. * should be calculated.
  61. * @return the result of the calculation.
  62. */
  63. static double ComputeColorDistance(const css::RGBAColorData& aStartColor,
  64. const css::RGBAColorData& aEndColor);
  65. /**
  66. * Calculates a measure of 'distance' between two values.
  67. *
  68. * This measure of Distance is guaranteed to be proportional to
  69. * portions passed to Interpolate, Add, or AddWeighted. However, for
  70. * some types of StyleAnimationValue it may not produce sensible results
  71. * for paced animation.
  72. *
  73. * If this method succeeds, the returned distance value is guaranteed to be
  74. * non-negative.
  75. *
  76. * @param aStartValue The start of the interval for which the distance
  77. * should be calculated.
  78. * @param aEndValue The end of the interval for which the distance
  79. * should be calculated.
  80. * @param aStyleContext The style context to use for processing the
  81. * translate part of transforms.
  82. * @param aDistance The result of the calculation.
  83. * @return true on success, false on failure.
  84. */
  85. static MOZ_MUST_USE bool
  86. ComputeDistance(nsCSSPropertyID aProperty,
  87. const StyleAnimationValue& aStartValue,
  88. const StyleAnimationValue& aEndValue,
  89. nsStyleContext* aStyleContext,
  90. double& aDistance);
  91. /**
  92. * Calculates an interpolated value that is the specified |aPortion| between
  93. * the two given values.
  94. *
  95. * This really just does the following calculation:
  96. * aResultValue = (1.0 - aPortion) * aStartValue + aPortion * aEndValue
  97. *
  98. * @param aStartValue The value defining the start of the interval of
  99. * interpolation.
  100. * @param aEndValue The value defining the end of the interval of
  101. * interpolation.
  102. * @param aPortion A number in the range [0.0, 1.0] defining the
  103. * distance of the interpolated value in the interval.
  104. * @param [out] aResultValue The resulting interpolated value.
  105. * @return true on success, false on failure.
  106. */
  107. static MOZ_MUST_USE bool
  108. Interpolate(nsCSSPropertyID aProperty,
  109. const StyleAnimationValue& aStartValue,
  110. const StyleAnimationValue& aEndValue,
  111. double aPortion,
  112. StyleAnimationValue& aResultValue) {
  113. return AddWeighted(aProperty, 1.0 - aPortion, aStartValue,
  114. aPortion, aEndValue, aResultValue);
  115. }
  116. /**
  117. * Does the calculation:
  118. * aResultValue = aCoeff1 * aValue1 + aCoeff2 * aValue2
  119. *
  120. * @param [out] aResultValue The resulting interpolated value. May be
  121. * the same as aValue1 or aValue2.
  122. * @return true on success, false on failure.
  123. *
  124. * NOTE: Current callers always pass aCoeff1 and aCoeff2 >= 0. They
  125. * are currently permitted to be negative; however, if, as we add
  126. * support more value types types, we find that this causes
  127. * difficulty, we might change this to restrict them to being
  128. * positive.
  129. */
  130. static MOZ_MUST_USE bool
  131. AddWeighted(nsCSSPropertyID aProperty,
  132. double aCoeff1, const StyleAnimationValue& aValue1,
  133. double aCoeff2, const StyleAnimationValue& aValue2,
  134. StyleAnimationValue& aResultValue);
  135. /**
  136. * Accumulates |aValueToAccumulate| onto |aDest| |aCount| times.
  137. * The result is stored in |aDest| on success.
  138. *
  139. * @param aDest The base value to be accumulated.
  140. * @param aValueToAccumulate The value to accumulate.
  141. * @param aCount The number of times to accumulate
  142. * aValueToAccumulate.
  143. * @return true on success, false on failure.
  144. *
  145. * NOTE: This function will work as a wrapper of StyleAnimationValue::Add()
  146. * if |aProperty| isn't color or shadow or filter. For these properties,
  147. * this function may return a color value that at least one of its components
  148. * has a value which is outside the range [0, 1] so that we can calculate
  149. * plausible values as interpolation with the return value.
  150. */
  151. static MOZ_MUST_USE bool
  152. Accumulate(nsCSSPropertyID aProperty, StyleAnimationValue& aDest,
  153. const StyleAnimationValue& aValueToAccumulate,
  154. uint64_t aCount);
  155. // Type-conversion methods
  156. // -----------------------
  157. /**
  158. * Creates a computed value for the given specified value
  159. * (property ID + string). A style context is needed in case the
  160. * specified value depends on inherited style or on the values of other
  161. * properties.
  162. *
  163. * @param aProperty The property whose value we're computing.
  164. * @param aTargetElement The content node to which our computed value is
  165. * applicable. For pseudo-elements, this is the parent
  166. * element to which the pseudo is attached, not the
  167. * generated content node.
  168. * @param aStyleContext The style context used to compute values from the
  169. * specified value. For pseudo-elements, this should
  170. * be the style context corresponding to the pseudo
  171. * element.
  172. * @param aSpecifiedValue The specified value, from which we'll build our
  173. * computed value.
  174. * @param aUseSVGMode A flag to indicate whether we should parse
  175. * |aSpecifiedValue| in SVG mode.
  176. * @param [out] aComputedValue The resulting computed value.
  177. * @param [out] aIsContextSensitive
  178. * Set to true if |aSpecifiedValue| may produce
  179. * a different |aComputedValue| depending on other CSS
  180. * properties on |aTargetElement| or its ancestors.
  181. * false otherwise.
  182. * Note that the operation of this method is
  183. * significantly faster when |aIsContextSensitive| is
  184. * nullptr.
  185. * @return true on success, false on failure.
  186. */
  187. static MOZ_MUST_USE bool
  188. ComputeValue(nsCSSPropertyID aProperty,
  189. mozilla::dom::Element* aTargetElement,
  190. nsStyleContext* aStyleContext,
  191. const nsAString& aSpecifiedValue,
  192. bool aUseSVGMode,
  193. StyleAnimationValue& aComputedValue,
  194. bool* aIsContextSensitive = nullptr);
  195. /**
  196. * Like ComputeValue, but returns an array of StyleAnimationValues.
  197. *
  198. * On success, when aProperty is a longhand, aResult will have a single
  199. * value in it. When aProperty is a shorthand, aResult will be filled with
  200. * values for all of aProperty's longhand components. aEnabledState
  201. * is used to filter the longhand components that will be appended
  202. * to aResult. On failure, aResult might still have partial results
  203. * in it.
  204. */
  205. static MOZ_MUST_USE bool
  206. ComputeValues(nsCSSPropertyID aProperty,
  207. mozilla::CSSEnabledState aEnabledState,
  208. mozilla::dom::Element* aTargetElement,
  209. nsStyleContext* aStyleContext,
  210. const nsAString& aSpecifiedValue,
  211. bool aUseSVGMode,
  212. nsTArray<PropertyStyleAnimationValuePair>& aResult);
  213. /**
  214. * A variant on ComputeValues that takes an nsCSSValue as the specified
  215. * value. Only longhand properties are supported.
  216. */
  217. static MOZ_MUST_USE bool
  218. ComputeValues(nsCSSPropertyID aProperty,
  219. mozilla::CSSEnabledState aEnabledState,
  220. mozilla::dom::Element* aTargetElement,
  221. nsStyleContext* aStyleContext,
  222. const nsCSSValue& aSpecifiedValue,
  223. bool aUseSVGMode,
  224. nsTArray<PropertyStyleAnimationValuePair>& aResult);
  225. /**
  226. * A variant of ComputeValues that takes a RawServoDeclarationBlock
  227. * as the specified value.
  228. */
  229. static MOZ_MUST_USE bool
  230. ComputeValues(nsCSSPropertyID aProperty,
  231. mozilla::CSSEnabledState aEnabledState,
  232. nsStyleContext* aStyleContext,
  233. const RawServoDeclarationBlock& aDeclarations,
  234. nsTArray<PropertyStyleAnimationValuePair>& aValues);
  235. /**
  236. * Creates a specified value for the given computed value.
  237. *
  238. * The first two overloads fill in an nsCSSValue object; the third
  239. * produces a string. For the overload that takes a const
  240. * StyleAnimationValue& reference, the nsCSSValue result may depend on
  241. * objects owned by the |aComputedValue| object, so users of that variant
  242. * must keep |aComputedValue| alive longer than |aSpecifiedValue|.
  243. * The overload that takes an rvalue StyleAnimationValue reference
  244. * transfers ownership for some resources such that the |aComputedValue|
  245. * does not depend on the lifetime of |aSpecifiedValue|.
  246. *
  247. * @param aProperty The property whose value we're uncomputing.
  248. * @param aComputedValue The computed value to be converted.
  249. * @param [out] aSpecifiedValue The resulting specified value.
  250. * @return true on success, false on failure.
  251. *
  252. * These functions are not MOZ_MUST_USE because failing to check the return
  253. * value is common and reasonable.
  254. */
  255. static MOZ_MUST_USE bool
  256. UncomputeValue(nsCSSPropertyID aProperty,
  257. const StyleAnimationValue& aComputedValue,
  258. nsCSSValue& aSpecifiedValue);
  259. static MOZ_MUST_USE bool
  260. UncomputeValue(nsCSSPropertyID aProperty,
  261. StyleAnimationValue&& aComputedValue,
  262. nsCSSValue& aSpecifiedValue);
  263. static MOZ_MUST_USE bool
  264. UncomputeValue(nsCSSPropertyID aProperty,
  265. const StyleAnimationValue& aComputedValue,
  266. nsAString& aSpecifiedValue);
  267. /**
  268. * Gets the computed value for the given property from the given style
  269. * context.
  270. *
  271. * Obtaining the computed value allows us to animate properties when the
  272. * content author has specified a value like "inherit" or "initial" or some
  273. * other keyword that isn't directly interpolatable, but which *computes* to
  274. * something interpolatable.
  275. *
  276. * @param aProperty The property whose value we're looking up.
  277. * @param aStyleContext The style context to check for the computed value.
  278. * @param [out] aComputedValue The resulting computed value.
  279. * @return true on success, false on failure.
  280. */
  281. static MOZ_MUST_USE bool ExtractComputedValue(
  282. nsCSSPropertyID aProperty,
  283. nsStyleContext* aStyleContext,
  284. StyleAnimationValue& aComputedValue);
  285. /**
  286. * Interpolates between 2 matrices by decomposing them.
  287. *
  288. * @param aMatrix1 First matrix, using CSS pixel units.
  289. * @param aMatrix2 Second matrix, using CSS pixel units.
  290. * @param aProgress Interpolation value in the range [0.0, 1.0]
  291. */
  292. static gfx::Matrix4x4 InterpolateTransformMatrix(const gfx::Matrix4x4 &aMatrix1,
  293. const gfx::Matrix4x4 &aMatrix2,
  294. double aProgress);
  295. static already_AddRefed<nsCSSValue::Array>
  296. AppendTransformFunction(nsCSSKeyword aTransformFunction,
  297. nsCSSValueList**& aListTail);
  298. /**
  299. * The types and values for the values that we extract and animate.
  300. */
  301. enum Unit {
  302. eUnit_Null, // not initialized
  303. eUnit_Normal,
  304. eUnit_Auto,
  305. eUnit_None,
  306. eUnit_Enumerated,
  307. eUnit_Visibility, // special case for transitions (which converts
  308. // Enumerated to Visibility as needed)
  309. eUnit_Integer,
  310. eUnit_Coord,
  311. eUnit_Percent,
  312. eUnit_Float,
  313. eUnit_Color, // nsCSSValue* (never null), always with an nscolor or
  314. // an nsCSSValueFloatColor
  315. eUnit_CurrentColor,
  316. eUnit_ComplexColor, // ComplexColorValue* (never null)
  317. eUnit_Calc, // nsCSSValue* (never null), always with a single
  318. // calc() expression that's either length or length+percent
  319. eUnit_ObjectPosition, // nsCSSValue* (never null), always with a
  320. // 4-entry nsCSSValue::Array
  321. eUnit_URL, // nsCSSValue* (never null), always with a css::URLValue
  322. eUnit_DiscreteCSSValue, // nsCSSValue* (never null)
  323. eUnit_CSSValuePair, // nsCSSValuePair* (never null)
  324. eUnit_CSSValueTriplet, // nsCSSValueTriplet* (never null)
  325. eUnit_CSSRect, // nsCSSRect* (never null)
  326. eUnit_Dasharray, // nsCSSValueList* (never null)
  327. eUnit_Shadow, // nsCSSValueList* (may be null)
  328. eUnit_Shape, // nsCSSValue::Array* (never null)
  329. eUnit_Filter, // nsCSSValueList* (may be null)
  330. eUnit_Transform, // nsCSSValueList* (never null)
  331. eUnit_BackgroundPositionCoord, // nsCSSValueList* (never null)
  332. eUnit_CSSValuePairList, // nsCSSValuePairList* (never null)
  333. eUnit_UnparsedString // nsStringBuffer* (never null)
  334. };
  335. private:
  336. Unit mUnit;
  337. union {
  338. int32_t mInt;
  339. nscoord mCoord;
  340. float mFloat;
  341. nsCSSValue* mCSSValue;
  342. nsCSSValuePair* mCSSValuePair;
  343. nsCSSValueTriplet* mCSSValueTriplet;
  344. nsCSSRect* mCSSRect;
  345. nsCSSValue::Array* mCSSValueArray;
  346. nsCSSValueList* mCSSValueList;
  347. nsCSSValueSharedList* mCSSValueSharedList;
  348. nsCSSValuePairList* mCSSValuePairList;
  349. nsStringBuffer* mString;
  350. css::ComplexColorValue* mComplexColor;
  351. } mValue;
  352. public:
  353. Unit GetUnit() const {
  354. NS_ASSERTION(mUnit != eUnit_Null, "uninitialized");
  355. return mUnit;
  356. }
  357. // Accessor to let us verify assumptions about presence of null unit,
  358. // without tripping the assertion in GetUnit().
  359. bool IsNull() const {
  360. return mUnit == eUnit_Null;
  361. }
  362. int32_t GetIntValue() const {
  363. NS_ASSERTION(IsIntUnit(mUnit), "unit mismatch");
  364. return mValue.mInt;
  365. }
  366. nscoord GetCoordValue() const {
  367. NS_ASSERTION(mUnit == eUnit_Coord, "unit mismatch");
  368. return mValue.mCoord;
  369. }
  370. float GetPercentValue() const {
  371. NS_ASSERTION(mUnit == eUnit_Percent, "unit mismatch");
  372. return mValue.mFloat;
  373. }
  374. float GetFloatValue() const {
  375. NS_ASSERTION(mUnit == eUnit_Float, "unit mismatch");
  376. return mValue.mFloat;
  377. }
  378. nsCSSValue* GetCSSValueValue() const {
  379. NS_ASSERTION(IsCSSValueUnit(mUnit), "unit mismatch");
  380. return mValue.mCSSValue;
  381. }
  382. nsCSSValuePair* GetCSSValuePairValue() const {
  383. NS_ASSERTION(IsCSSValuePairUnit(mUnit), "unit mismatch");
  384. return mValue.mCSSValuePair;
  385. }
  386. nsCSSValueTriplet* GetCSSValueTripletValue() const {
  387. NS_ASSERTION(IsCSSValueTripletUnit(mUnit), "unit mismatch");
  388. return mValue.mCSSValueTriplet;
  389. }
  390. nsCSSRect* GetCSSRectValue() const {
  391. NS_ASSERTION(IsCSSRectUnit(mUnit), "unit mismatch");
  392. return mValue.mCSSRect;
  393. }
  394. nsCSSValue::Array* GetCSSValueArrayValue() const {
  395. NS_ASSERTION(IsCSSValueArrayUnit(mUnit), "unit mismatch");
  396. return mValue.mCSSValueArray;
  397. }
  398. nsCSSValueList* GetCSSValueListValue() const {
  399. NS_ASSERTION(IsCSSValueListUnit(mUnit), "unit mismatch");
  400. return mValue.mCSSValueList;
  401. }
  402. nsCSSValueSharedList* GetCSSValueSharedListValue() const {
  403. NS_ASSERTION(IsCSSValueSharedListValue(mUnit), "unit mismatch");
  404. return mValue.mCSSValueSharedList;
  405. }
  406. nsCSSValuePairList* GetCSSValuePairListValue() const {
  407. NS_ASSERTION(IsCSSValuePairListUnit(mUnit), "unit mismatch");
  408. return mValue.mCSSValuePairList;
  409. }
  410. const char16_t* GetStringBufferValue() const {
  411. NS_ASSERTION(IsStringUnit(mUnit), "unit mismatch");
  412. return GetBufferValue(mValue.mString);
  413. }
  414. void GetStringValue(nsAString& aBuffer) const {
  415. NS_ASSERTION(IsStringUnit(mUnit), "unit mismatch");
  416. aBuffer.Truncate();
  417. uint32_t len = NS_strlen(GetBufferValue(mValue.mString));
  418. mValue.mString->ToString(len, aBuffer);
  419. }
  420. /// @return the scale for this value, calculated with reference to @aForFrame.
  421. gfxSize GetScaleValue(const nsIFrame* aForFrame) const;
  422. const css::ComplexColorData& GetComplexColorData() const {
  423. MOZ_ASSERT(mUnit == eUnit_ComplexColor, "unit mismatch");
  424. return *mValue.mComplexColor;
  425. }
  426. StyleComplexColor GetStyleComplexColorValue() const {
  427. return GetComplexColorData().ToComplexColor();
  428. }
  429. UniquePtr<nsCSSValueList> TakeCSSValueListValue() {
  430. nsCSSValueList* list = GetCSSValueListValue();
  431. mValue.mCSSValueList = nullptr;
  432. mUnit = eUnit_Null;
  433. return UniquePtr<nsCSSValueList>(list);
  434. }
  435. UniquePtr<nsCSSValuePairList> TakeCSSValuePairListValue() {
  436. nsCSSValuePairList* list = GetCSSValuePairListValue();
  437. mValue.mCSSValuePairList = nullptr;
  438. mUnit = eUnit_Null;
  439. return UniquePtr<nsCSSValuePairList>(list);
  440. }
  441. explicit StyleAnimationValue(Unit aUnit = eUnit_Null) : mUnit(aUnit) {
  442. NS_ASSERTION(aUnit == eUnit_Null || aUnit == eUnit_Normal ||
  443. aUnit == eUnit_Auto || aUnit == eUnit_None,
  444. "must be valueless unit");
  445. }
  446. StyleAnimationValue(const StyleAnimationValue& aOther)
  447. : mUnit(eUnit_Null) { *this = aOther; }
  448. StyleAnimationValue(StyleAnimationValue&& aOther)
  449. : mUnit(aOther.mUnit)
  450. , mValue(aOther.mValue)
  451. {
  452. aOther.mUnit = eUnit_Null;
  453. }
  454. enum IntegerConstructorType { IntegerConstructor };
  455. StyleAnimationValue(int32_t aInt, Unit aUnit, IntegerConstructorType);
  456. enum CoordConstructorType { CoordConstructor };
  457. StyleAnimationValue(nscoord aLength, CoordConstructorType);
  458. enum PercentConstructorType { PercentConstructor };
  459. StyleAnimationValue(float aPercent, PercentConstructorType);
  460. enum FloatConstructorType { FloatConstructor };
  461. StyleAnimationValue(float aFloat, FloatConstructorType);
  462. enum ColorConstructorType { ColorConstructor };
  463. StyleAnimationValue(nscolor aColor, ColorConstructorType);
  464. ~StyleAnimationValue() { FreeValue(); }
  465. void SetNormalValue();
  466. void SetAutoValue();
  467. void SetNoneValue();
  468. void SetIntValue(int32_t aInt, Unit aUnit);
  469. template<typename T,
  470. typename = typename std::enable_if<std::is_enum<T>::value>::type>
  471. void SetIntValue(T aInt, Unit aUnit)
  472. {
  473. static_assert(mozilla::EnumTypeFitsWithin<T, int32_t>::value,
  474. "aValue must be an enum that fits within mValue.mInt");
  475. SetIntValue(static_cast<int32_t>(aInt), aUnit);
  476. }
  477. void SetCoordValue(nscoord aCoord);
  478. void SetPercentValue(float aPercent);
  479. void SetFloatValue(float aFloat);
  480. void SetColorValue(nscolor aColor);
  481. void SetCurrentColorValue();
  482. void SetComplexColorValue(const StyleComplexColor& aColor);
  483. void SetComplexColorValue(already_AddRefed<css::ComplexColorValue> aValue);
  484. void SetUnparsedStringValue(const nsString& aString);
  485. void SetCSSValueArrayValue(nsCSSValue::Array* aValue, Unit aUnit);
  486. // These setters take ownership of |aValue|, and are therefore named
  487. // "SetAndAdopt*".
  488. void SetAndAdoptCSSValueValue(nsCSSValue *aValue, Unit aUnit);
  489. void SetAndAdoptCSSValuePairValue(nsCSSValuePair *aValue, Unit aUnit);
  490. void SetAndAdoptCSSValueTripletValue(nsCSSValueTriplet *aValue, Unit aUnit);
  491. void SetAndAdoptCSSRectValue(nsCSSRect *aValue, Unit aUnit);
  492. void SetAndAdoptCSSValueListValue(nsCSSValueList *aValue, Unit aUnit);
  493. void SetAndAdoptCSSValuePairListValue(nsCSSValuePairList *aValue);
  494. void SetTransformValue(nsCSSValueSharedList* aList);
  495. StyleAnimationValue& operator=(const StyleAnimationValue& aOther);
  496. StyleAnimationValue& operator=(StyleAnimationValue&& aOther)
  497. {
  498. MOZ_ASSERT(this != &aOther, "Do not move itself");
  499. if (this != &aOther) {
  500. FreeValue();
  501. mUnit = aOther.mUnit;
  502. mValue = aOther.mValue;
  503. aOther.mUnit = eUnit_Null;
  504. }
  505. return *this;
  506. }
  507. bool operator==(const StyleAnimationValue& aOther) const;
  508. bool operator!=(const StyleAnimationValue& aOther) const
  509. { return !(*this == aOther); }
  510. private:
  511. void FreeValue();
  512. static const char16_t* GetBufferValue(nsStringBuffer* aBuffer) {
  513. return static_cast<char16_t*>(aBuffer->Data());
  514. }
  515. static bool IsIntUnit(Unit aUnit) {
  516. return aUnit == eUnit_Enumerated || aUnit == eUnit_Visibility ||
  517. aUnit == eUnit_Integer;
  518. }
  519. static bool IsCSSValueUnit(Unit aUnit) {
  520. return aUnit == eUnit_Color ||
  521. aUnit == eUnit_Calc ||
  522. aUnit == eUnit_ObjectPosition ||
  523. aUnit == eUnit_URL ||
  524. aUnit == eUnit_DiscreteCSSValue;
  525. }
  526. static bool IsCSSValuePairUnit(Unit aUnit) {
  527. return aUnit == eUnit_CSSValuePair;
  528. }
  529. static bool IsCSSValueTripletUnit(Unit aUnit) {
  530. return aUnit == eUnit_CSSValueTriplet;
  531. }
  532. static bool IsCSSRectUnit(Unit aUnit) {
  533. return aUnit == eUnit_CSSRect;
  534. }
  535. static bool IsCSSValueArrayUnit(Unit aUnit) {
  536. return aUnit == eUnit_Shape;
  537. }
  538. static bool IsCSSValueListUnit(Unit aUnit) {
  539. return aUnit == eUnit_Dasharray || aUnit == eUnit_Filter ||
  540. aUnit == eUnit_Shadow ||
  541. aUnit == eUnit_BackgroundPositionCoord;
  542. }
  543. static bool IsCSSValueSharedListValue(Unit aUnit) {
  544. return aUnit == eUnit_Transform;
  545. }
  546. static bool IsCSSValuePairListUnit(Unit aUnit) {
  547. return aUnit == eUnit_CSSValuePairList;
  548. }
  549. static bool IsStringUnit(Unit aUnit) {
  550. return aUnit == eUnit_UnparsedString;
  551. }
  552. };
  553. struct PropertyStyleAnimationValuePair
  554. {
  555. nsCSSPropertyID mProperty;
  556. StyleAnimationValue mValue;
  557. };
  558. } // namespace mozilla
  559. #endif