2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 #ifndef TimingFunction_h
26 #define TimingFunction_h
28 #include <wtf/RefCounted.h>
32 class TimingFunction : public RefCounted<TimingFunction> {
35 enum TimingFunctionType {
36 LinearFunction, CubicBezierFunction, StepsFunction
39 virtual ~TimingFunction() { }
41 TimingFunctionType type() const { return m_type; }
43 bool isLinearTimingFunction() const { return m_type == LinearFunction; }
44 bool isCubicBezierTimingFunction() const { return m_type == CubicBezierFunction; }
45 bool isStepsTimingFunction() const { return m_type == StepsFunction; }
47 virtual bool operator==(const TimingFunction& other) = 0;
50 TimingFunction(TimingFunctionType type)
55 TimingFunctionType m_type;
58 class LinearTimingFunction : public TimingFunction {
60 static PassRefPtr<LinearTimingFunction> create()
62 return adoptRef(new LinearTimingFunction);
65 ~LinearTimingFunction() { }
67 virtual bool operator==(const TimingFunction& other)
69 return other.isLinearTimingFunction();
73 LinearTimingFunction()
74 : TimingFunction(LinearFunction)
79 class CubicBezierTimingFunction : public TimingFunction {
81 static PassRefPtr<CubicBezierTimingFunction> create(double x1, double y1, double x2, double y2)
83 return adoptRef(new CubicBezierTimingFunction(x1, y1, x2, y2));
86 static PassRefPtr<CubicBezierTimingFunction> create()
88 return adoptRef(new CubicBezierTimingFunction());
91 ~CubicBezierTimingFunction() { }
93 virtual bool operator==(const TimingFunction& other)
95 if (other.isCubicBezierTimingFunction()) {
96 const CubicBezierTimingFunction* ctf = static_cast<const CubicBezierTimingFunction*>(&other);
97 return m_x1 == ctf->m_x1 && m_y1 == ctf->m_y1 && m_x2 == ctf->m_x2 && m_y2 == ctf->m_y2;
102 double x1() const { return m_x1; }
103 double y1() const { return m_y1; }
104 double x2() const { return m_x2; }
105 double y2() const { return m_y2; }
107 static const CubicBezierTimingFunction* defaultTimingFunction()
109 static const CubicBezierTimingFunction* dtf = create().leakRef();
114 CubicBezierTimingFunction(double x1 = 0.25, double y1 = 0.1, double x2 = 0.25, double y2 = 1.0)
115 : TimingFunction(CubicBezierFunction)
129 class StepsTimingFunction : public TimingFunction {
131 static PassRefPtr<StepsTimingFunction> create(int steps, bool stepAtStart)
133 return adoptRef(new StepsTimingFunction(steps, stepAtStart));
136 ~StepsTimingFunction() { }
138 virtual bool operator==(const TimingFunction& other)
140 if (other.isStepsTimingFunction()) {
141 const StepsTimingFunction* stf = static_cast<const StepsTimingFunction*>(&other);
142 return m_steps == stf->m_steps && m_stepAtStart == stf->m_stepAtStart;
147 int numberOfSteps() const { return m_steps; }
148 bool stepAtStart() const { return m_stepAtStart; }
151 StepsTimingFunction(int steps, bool stepAtStart)
152 : TimingFunction(StepsFunction)
154 , m_stepAtStart(stepAtStart)
162 } // namespace WebCore
164 #endif // TimingFunction_h