/work/obj-fuzz/dist/include/nsTimingFunction.h
Line | Count | Source (jump to first uncovered line) |
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 |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef nsTimingFunction_h |
8 | | #define nsTimingFunction_h |
9 | | |
10 | | #include "nsStyleConsts.h" |
11 | | |
12 | | struct nsTimingFunction |
13 | | { |
14 | | enum class Type { |
15 | | Ease, // ease |
16 | | Linear, // linear |
17 | | EaseIn, // ease-in |
18 | | EaseOut, // ease-out |
19 | | EaseInOut, // ease-in-out |
20 | | StepStart, // step-start and steps(..., start) |
21 | | StepEnd, // step-end, steps(..., end) and steps(...) |
22 | | CubicBezier, // cubic-bezier() |
23 | | Frames, // frames() |
24 | | }; |
25 | | |
26 | | // Whether the timing function type is represented by a spline, |
27 | | // and thus will have mFunc filled in. |
28 | | static bool IsSplineType(Type aType) |
29 | | { |
30 | | return aType != Type::StepStart && |
31 | | aType != Type::StepEnd && |
32 | | aType != Type::Frames; |
33 | | } |
34 | | |
35 | | explicit nsTimingFunction( |
36 | | int32_t aTimingFunctionType = NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE) |
37 | | : mType(Type::Ease) |
38 | | , mFunc{} |
39 | 0 | { |
40 | 0 | AssignFromKeyword(aTimingFunctionType); |
41 | 0 | } |
42 | | |
43 | | nsTimingFunction(float x1, float y1, float x2, float y2) |
44 | | : mType(Type::CubicBezier) |
45 | 0 | { |
46 | 0 | mFunc.mX1 = x1; |
47 | 0 | mFunc.mY1 = y1; |
48 | 0 | mFunc.mX2 = x2; |
49 | 0 | mFunc.mY2 = y2; |
50 | 0 | } |
51 | | |
52 | | enum class Keyword { Implicit, Explicit }; |
53 | | |
54 | | nsTimingFunction(Type aType, uint32_t aStepsOrFrames) |
55 | | : mType(aType) |
56 | 0 | { |
57 | 0 | MOZ_ASSERT(mType == Type::StepStart || |
58 | 0 | mType == Type::StepEnd || |
59 | 0 | mType == Type::Frames, |
60 | 0 | "wrong type"); |
61 | 0 | mStepsOrFrames = aStepsOrFrames; |
62 | 0 | } |
63 | | |
64 | | nsTimingFunction(const nsTimingFunction& aOther) |
65 | | { |
66 | | *this = aOther; |
67 | | } |
68 | | |
69 | | Type mType; |
70 | | union { |
71 | | struct { |
72 | | float mX1; |
73 | | float mY1; |
74 | | float mX2; |
75 | | float mY2; |
76 | | } mFunc; |
77 | | struct { |
78 | | uint32_t mStepsOrFrames; |
79 | | }; |
80 | | }; |
81 | | |
82 | | nsTimingFunction& |
83 | | operator=(const nsTimingFunction& aOther) |
84 | | { |
85 | | if (&aOther == this) { |
86 | | return *this; |
87 | | } |
88 | | |
89 | | mType = aOther.mType; |
90 | | |
91 | | if (HasSpline()) { |
92 | | mFunc.mX1 = aOther.mFunc.mX1; |
93 | | mFunc.mY1 = aOther.mFunc.mY1; |
94 | | mFunc.mX2 = aOther.mFunc.mX2; |
95 | | mFunc.mY2 = aOther.mFunc.mY2; |
96 | | } else { |
97 | | mStepsOrFrames = aOther.mStepsOrFrames; |
98 | | } |
99 | | |
100 | | return *this; |
101 | | } |
102 | | |
103 | | bool operator==(const nsTimingFunction& aOther) const |
104 | | { |
105 | | if (mType != aOther.mType) { |
106 | | return false; |
107 | | } |
108 | | if (HasSpline()) { |
109 | | return mFunc.mX1 == aOther.mFunc.mX1 && mFunc.mY1 == aOther.mFunc.mY1 && |
110 | | mFunc.mX2 == aOther.mFunc.mX2 && mFunc.mY2 == aOther.mFunc.mY2; |
111 | | } |
112 | | return mStepsOrFrames == aOther.mStepsOrFrames; |
113 | | } |
114 | | |
115 | | bool operator!=(const nsTimingFunction& aOther) const |
116 | 0 | { |
117 | 0 | return !(*this == aOther); |
118 | 0 | } |
119 | | |
120 | | bool HasSpline() const { return IsSplineType(mType); } |
121 | | |
122 | | private: |
123 | | void AssignFromKeyword(int32_t aTimingFunctionType); |
124 | | }; |
125 | | |
126 | | #endif // nsTimingFunction_h |