initial import
[vuplus_webkit] / Source / WebCore / page / WebKitAnimation.cpp
1 /*
2  * Copyright (C) 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #include "config.h"
27 #include "WebKitAnimation.h"
28
29 #include "Animation.h"
30 #include "AnimationBase.h"
31 #include "RenderStyle.h"
32
33 using namespace std;
34
35 namespace WebCore {
36
37 WebKitAnimation::WebKitAnimation(PassRefPtr<KeyframeAnimation> keyframeAnimation)
38     : m_keyframeAnimation(keyframeAnimation)
39 {
40 }
41
42 String WebKitAnimation::name() const
43 {
44     return m_keyframeAnimation->animation()->name();
45 }
46
47 double WebKitAnimation::duration() const
48 {
49     return m_keyframeAnimation->duration();
50 }
51
52 double WebKitAnimation::elapsedTime() const
53 {
54     return m_keyframeAnimation->getElapsedTime();
55 }
56
57 void WebKitAnimation::setElapsedTime(double time)
58 {
59     m_keyframeAnimation->setElapsedTime(time);
60 }
61
62 double WebKitAnimation::delay() const
63 {
64     return m_keyframeAnimation->animation()->delay();
65 }
66
67 int WebKitAnimation::iterationCount() const
68 {
69     return m_keyframeAnimation->animation()->iterationCount();
70 }
71
72 bool WebKitAnimation::paused() const
73 {
74     return m_keyframeAnimation->paused();
75 }
76
77 bool WebKitAnimation::ended() const
78 {
79     int iterations = iterationCount();
80     if (iterations == Animation::IterationCountInfinite)
81         return false;
82     return m_keyframeAnimation->getElapsedTime() > (m_keyframeAnimation->duration() * iterations);
83 }
84
85 WebKitAnimation::Direction WebKitAnimation::direction() const
86 {
87     if (m_keyframeAnimation->animation()->direction() == Animation::AnimationDirectionNormal)
88         return DIRECTION_NORMAL;
89     return DIRECTION_ALTERNATE;
90 }
91
92 WebKitAnimation::FillMode WebKitAnimation::fillMode() const
93 {
94     switch (m_keyframeAnimation->animation()->fillMode()) {
95     case AnimationFillModeNone:
96         return FILL_NONE;
97     case AnimationFillModeForwards:
98         return FILL_FORWARDS;
99     case AnimationFillModeBackwards:
100         return FILL_BACKWARDS;
101     case AnimationFillModeBoth:
102         return FILL_BOTH;
103     }
104     ASSERT_NOT_REACHED();
105     return FILL_BOTH;
106 }
107
108 void WebKitAnimation::pause()
109 {
110     m_keyframeAnimation->pause();
111 }
112
113 void WebKitAnimation::play()
114 {
115     m_keyframeAnimation->play();
116 }
117
118 }