ComputedTimingFunction.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* -*- Mode: C++; tab-width: 8; 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 file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_ComputedTimingFunction_h
  6. #define mozilla_ComputedTimingFunction_h
  7. #include "nsSMILKeySpline.h" // nsSMILKeySpline
  8. #include "nsStyleStruct.h" // nsTimingFunction
  9. namespace mozilla {
  10. class ComputedTimingFunction
  11. {
  12. public:
  13. // BeforeFlag is used in step timing function.
  14. // https://w3c.github.io/web-animations/#before-flag
  15. enum class BeforeFlag {
  16. Unset,
  17. Set
  18. };
  19. void Init(const nsTimingFunction &aFunction);
  20. double GetValue(double aPortion, BeforeFlag aBeforeFlag) const;
  21. const nsSMILKeySpline* GetFunction() const
  22. {
  23. NS_ASSERTION(HasSpline(), "Type mismatch");
  24. return &mTimingFunction;
  25. }
  26. nsTimingFunction::Type GetType() const { return mType; }
  27. bool HasSpline() const { return nsTimingFunction::IsSplineType(mType); }
  28. uint32_t GetSteps() const { return mSteps; }
  29. bool operator==(const ComputedTimingFunction& aOther) const
  30. {
  31. return mType == aOther.mType &&
  32. (HasSpline() ?
  33. mTimingFunction == aOther.mTimingFunction :
  34. mSteps == aOther.mSteps);
  35. }
  36. bool operator!=(const ComputedTimingFunction& aOther) const
  37. {
  38. return !(*this == aOther);
  39. }
  40. int32_t Compare(const ComputedTimingFunction& aRhs) const;
  41. void AppendToString(nsAString& aResult) const;
  42. static double GetPortion(const Maybe<ComputedTimingFunction>& aFunction,
  43. double aPortion,
  44. BeforeFlag aBeforeFlag)
  45. {
  46. return aFunction ? aFunction->GetValue(aPortion, aBeforeFlag) : aPortion;
  47. }
  48. static int32_t Compare(const Maybe<ComputedTimingFunction>& aLhs,
  49. const Maybe<ComputedTimingFunction>& aRhs);
  50. private:
  51. nsTimingFunction::Type mType;
  52. nsSMILKeySpline mTimingFunction;
  53. uint32_t mSteps;
  54. };
  55. } // namespace mozilla
  56. #endif // mozilla_ComputedTimingFunction_h