1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_ComputedTimingFunction_h
8 #define mozilla_ComputedTimingFunction_h
9 
10 #include "nsSMILKeySpline.h"  // nsSMILKeySpline
11 #include "nsStyleStruct.h"    // nsTimingFunction
12 
13 namespace mozilla {
14 
15 class ComputedTimingFunction
16 {
17 public:
18   // BeforeFlag is used in step timing function.
19   // https://w3c.github.io/web-animations/#before-flag
20   enum class BeforeFlag {
21     Unset,
22     Set
23   };
24   void Init(const nsTimingFunction &aFunction);
25   double GetValue(double aPortion, BeforeFlag aBeforeFlag) const;
GetFunction()26   const nsSMILKeySpline* GetFunction() const
27   {
28     NS_ASSERTION(HasSpline(), "Type mismatch");
29     return &mTimingFunction;
30   }
GetType()31   nsTimingFunction::Type GetType() const { return mType; }
HasSpline()32   bool HasSpline() const { return nsTimingFunction::IsSplineType(mType); }
GetSteps()33   uint32_t GetSteps() const { return mSteps; }
34   bool operator==(const ComputedTimingFunction& aOther) const
35   {
36     return mType == aOther.mType &&
37            (HasSpline() ?
38             mTimingFunction == aOther.mTimingFunction :
39             mSteps == aOther.mSteps);
40   }
41   bool operator!=(const ComputedTimingFunction& aOther) const
42   {
43     return !(*this == aOther);
44   }
45   int32_t Compare(const ComputedTimingFunction& aRhs) const;
46   void AppendToString(nsAString& aResult) const;
47 
GetPortion(const Maybe<ComputedTimingFunction> & aFunction,double aPortion,BeforeFlag aBeforeFlag)48   static double GetPortion(const Maybe<ComputedTimingFunction>& aFunction,
49                            double aPortion,
50                            BeforeFlag aBeforeFlag)
51   {
52     return aFunction ? aFunction->GetValue(aPortion, aBeforeFlag) : aPortion;
53   }
54   static int32_t Compare(const Maybe<ComputedTimingFunction>& aLhs,
55                          const Maybe<ComputedTimingFunction>& aRhs);
56 
57 private:
58   nsTimingFunction::Type mType;
59   nsSMILKeySpline mTimingFunction;
60   uint32_t mSteps;
61 };
62 
63 } // namespace mozilla
64 
65 #endif // mozilla_ComputedTimingFunction_h
66