OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 CCActiveAnimation::CCActiveAnimation(PassOwnPtr<CCAnimationCurve> curve, int ani
mationId, int groupId, TargetProperty targetProperty) | 40 CCActiveAnimation::CCActiveAnimation(PassOwnPtr<CCAnimationCurve> curve, int ani
mationId, int groupId, TargetProperty targetProperty) |
41 : m_curve(curve) | 41 : m_curve(curve) |
42 , m_id(animationId) | 42 , m_id(animationId) |
43 , m_group(groupId) | 43 , m_group(groupId) |
44 , m_targetProperty(targetProperty) | 44 , m_targetProperty(targetProperty) |
45 , m_runState(WaitingForTargetAvailability) | 45 , m_runState(WaitingForTargetAvailability) |
46 , m_iterations(1) | 46 , m_iterations(1) |
47 , m_startTime(0) | 47 , m_startTime(0) |
| 48 , m_alternatesDirection(false) |
48 , m_timeOffset(0) | 49 , m_timeOffset(0) |
49 , m_needsSynchronizedStartTime(false) | 50 , m_needsSynchronizedStartTime(false) |
50 , m_suspended(false) | 51 , m_suspended(false) |
51 , m_pauseTime(0) | 52 , m_pauseTime(0) |
52 , m_totalPausedTime(0) | 53 , m_totalPausedTime(0) |
53 { | 54 { |
54 } | 55 } |
55 | 56 |
56 CCActiveAnimation::~CCActiveAnimation() | 57 CCActiveAnimation::~CCActiveAnimation() |
57 { | 58 { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 113 |
113 // Always return zero if we have no iterations. | 114 // Always return zero if we have no iterations. |
114 if (!m_iterations) | 115 if (!m_iterations) |
115 return 0; | 116 return 0; |
116 | 117 |
117 // If less than an iteration duration, just return trimmed. | 118 // If less than an iteration duration, just return trimmed. |
118 if (trimmed < m_curve->duration()) | 119 if (trimmed < m_curve->duration()) |
119 return trimmed; | 120 return trimmed; |
120 | 121 |
121 // If greater than or equal to the total duration, return iteration duration
. | 122 // If greater than or equal to the total duration, return iteration duration
. |
122 if (m_iterations >= 0 && trimmed >= m_curve->duration() * m_iterations) | 123 if (m_iterations >= 0 && trimmed >= m_curve->duration() * m_iterations) { |
| 124 if (m_alternatesDirection && !(m_iterations % 2)) |
| 125 return 0; |
123 return m_curve->duration(); | 126 return m_curve->duration(); |
| 127 } |
124 | 128 |
125 // Finally, return x where trimmed = x + n * m_animation->duration() for som
e positive integer n. | 129 // We need to know the current iteration if we're alternating. |
126 return fmod(trimmed, m_curve->duration()); | 130 int iteration = static_cast<int>(trimmed / m_curve->duration()); |
| 131 |
| 132 // Calculate x where trimmed = x + n * m_curve->duration() for some positive
integer n. |
| 133 trimmed = fmod(trimmed, m_curve->duration()); |
| 134 |
| 135 // If we're alternating and on an odd iteration, reverse the direction. |
| 136 if (m_alternatesDirection && iteration % 2 == 1) |
| 137 return m_curve->duration() - trimmed; |
| 138 |
| 139 return trimmed; |
127 } | 140 } |
128 | 141 |
129 PassOwnPtr<CCActiveAnimation> CCActiveAnimation::cloneForImplThread() const | 142 PassOwnPtr<CCActiveAnimation> CCActiveAnimation::cloneForImplThread() const |
130 { | 143 { |
131 OwnPtr<CCActiveAnimation> toReturn(adoptPtr(new CCActiveAnimation(m_curve->c
lone(), m_id, m_group, m_targetProperty))); | 144 OwnPtr<CCActiveAnimation> toReturn(adoptPtr(new CCActiveAnimation(m_curve->c
lone(), m_id, m_group, m_targetProperty))); |
132 toReturn->m_runState = m_runState; | 145 toReturn->m_runState = m_runState; |
133 toReturn->m_iterations = m_iterations; | 146 toReturn->m_iterations = m_iterations; |
134 toReturn->m_startTime = m_startTime; | 147 toReturn->m_startTime = m_startTime; |
135 toReturn->m_pauseTime = m_pauseTime; | 148 toReturn->m_pauseTime = m_pauseTime; |
136 toReturn->m_totalPausedTime = m_totalPausedTime; | 149 toReturn->m_totalPausedTime = m_totalPausedTime; |
137 toReturn->m_timeOffset = m_timeOffset; | 150 toReturn->m_timeOffset = m_timeOffset; |
| 151 toReturn->m_alternatesDirection = m_alternatesDirection; |
138 return toReturn.release(); | 152 return toReturn.release(); |
139 } | 153 } |
140 | 154 |
141 void CCActiveAnimation::pushPropertiesTo(CCActiveAnimation* other) const | 155 void CCActiveAnimation::pushPropertiesTo(CCActiveAnimation* other) const |
142 { | 156 { |
143 // Currently, we only push changes due to pausing and resuming animations on
the main thread. | 157 // Currently, we only push changes due to pausing and resuming animations on
the main thread. |
144 if (m_runState == CCActiveAnimation::Paused || other->m_runState == CCActive
Animation::Paused) { | 158 if (m_runState == CCActiveAnimation::Paused || other->m_runState == CCActive
Animation::Paused) { |
145 other->m_runState = m_runState; | 159 other->m_runState = m_runState; |
146 other->m_pauseTime = m_pauseTime; | 160 other->m_pauseTime = m_pauseTime; |
147 other->m_totalPausedTime = m_totalPausedTime; | 161 other->m_totalPausedTime = m_totalPausedTime; |
148 } | 162 } |
149 } | 163 } |
150 | 164 |
151 } // namespace WebCore | 165 } // namespace WebCore |
OLD | NEW |