OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2011 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 , m_animationTimer(this, &ScriptedAnimationController::animationTimerFired) | 54 , m_animationTimer(this, &ScriptedAnimationController::animationTimerFired) |
55 , m_lastAnimationFrameTime(0) | 55 , m_lastAnimationFrameTime(0) |
56 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) | 56 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
57 , m_useTimer(false) | 57 , m_useTimer(false) |
58 #endif | 58 #endif |
59 #endif | 59 #endif |
60 { | 60 { |
61 windowScreenDidChange(displayID); | 61 windowScreenDidChange(displayID); |
62 } | 62 } |
63 | 63 |
| 64 ScriptedAnimationController::~ScriptedAnimationController() |
| 65 { |
| 66 } |
| 67 |
64 void ScriptedAnimationController::suspend() | 68 void ScriptedAnimationController::suspend() |
65 { | 69 { |
66 ++m_suspendCount; | 70 ++m_suspendCount; |
67 } | 71 } |
68 | 72 |
69 void ScriptedAnimationController::resume() | 73 void ScriptedAnimationController::resume() |
70 { | 74 { |
71 --m_suspendCount; | 75 --m_suspendCount; |
72 if (!m_suspendCount && m_callbacks.size()) | 76 if (!m_suspendCount && m_callbacks.size()) |
73 scheduleAnimation(); | 77 scheduleAnimation(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // FIXME: Currently, this code doesn't do any visibility tests beyond checki
ng display: | 116 // FIXME: Currently, this code doesn't do any visibility tests beyond checki
ng display: |
113 | 117 |
114 // First, generate a list of callbacks to consider. Callbacks registered fr
om this point | 118 // First, generate a list of callbacks to consider. Callbacks registered fr
om this point |
115 // on are considered only for the "next" frame, not this one. | 119 // on are considered only for the "next" frame, not this one. |
116 CallbackList callbacks(m_callbacks); | 120 CallbackList callbacks(m_callbacks); |
117 | 121 |
118 // Firing the callback may cause the visibility of other elements to change.
To avoid | 122 // Firing the callback may cause the visibility of other elements to change.
To avoid |
119 // missing any callbacks, we keep iterating through the list of candiate cal
lbacks and firing | 123 // missing any callbacks, we keep iterating through the list of candiate cal
lbacks and firing |
120 // them until nothing new becomes visible. | 124 // them until nothing new becomes visible. |
121 bool firedCallback; | 125 bool firedCallback; |
| 126 |
| 127 // Invoking callbacks may detach elements from our document, which clear's t
he document's |
| 128 // reference to us, so take a defensive reference. |
| 129 RefPtr<ScriptedAnimationController> protector(this); |
122 do { | 130 do { |
123 firedCallback = false; | 131 firedCallback = false; |
| 132 // A previous iteration may have detached this Document from the DOM tre
e. |
| 133 // If so, then we do not need to process any more callbacks. |
| 134 if (!m_document) |
| 135 continue; |
| 136 |
124 // A previous iteration may have invalidated style (or layout). Update
styles for each iteration | 137 // A previous iteration may have invalidated style (or layout). Update
styles for each iteration |
125 // for now since all we check is the existence of a renderer. | 138 // for now since all we check is the existence of a renderer. |
126 m_document->updateStyleIfNeeded(); | 139 m_document->updateStyleIfNeeded(); |
127 for (size_t i = 0; i < callbacks.size(); ++i) { | 140 for (size_t i = 0; i < callbacks.size(); ++i) { |
128 RequestAnimationFrameCallback* callback = callbacks[i].get(); | 141 RequestAnimationFrameCallback* callback = callbacks[i].get(); |
129 if (!callback->m_firedOrCancelled && (!callback->m_element || callba
ck->m_element->renderer())) { | 142 if (!callback->m_firedOrCancelled && (!callback->m_element || callba
ck->m_element->renderer())) { |
130 callback->m_firedOrCancelled = true; | 143 callback->m_firedOrCancelled = true; |
131 InspectorInstrumentationCookie cookie = InspectorInstrumentation
::willFireAnimationFrameEvent(m_document, callback->m_id); | 144 InspectorInstrumentationCookie cookie = InspectorInstrumentation
::willFireAnimationFrameEvent(m_document, callback->m_id); |
132 callback->handleEvent(time); | 145 callback->handleEvent(time); |
133 InspectorInstrumentation::didFireAnimationFrameEvent(cookie); | 146 InspectorInstrumentation::didFireAnimationFrameEvent(cookie); |
(...skipping 20 matching lines...) Expand all Loading... |
154 { | 167 { |
155 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) | 168 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
156 DisplayRefreshMonitorManager::sharedManager()->windowScreenDidChange(display
ID, this); | 169 DisplayRefreshMonitorManager::sharedManager()->windowScreenDidChange(display
ID, this); |
157 #else | 170 #else |
158 UNUSED_PARAM(displayID); | 171 UNUSED_PARAM(displayID); |
159 #endif | 172 #endif |
160 } | 173 } |
161 | 174 |
162 void ScriptedAnimationController::scheduleAnimation() | 175 void ScriptedAnimationController::scheduleAnimation() |
163 { | 176 { |
| 177 if (!m_document) |
| 178 return; |
| 179 |
164 #if USE(REQUEST_ANIMATION_FRAME_TIMER) | 180 #if USE(REQUEST_ANIMATION_FRAME_TIMER) |
165 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) | 181 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
166 if (!m_useTimer) { | 182 if (!m_useTimer) { |
167 if (DisplayRefreshMonitorManager::sharedManager()->scheduleAnimation(thi
s)) | 183 if (DisplayRefreshMonitorManager::sharedManager()->scheduleAnimation(thi
s)) |
168 return; | 184 return; |
169 | 185 |
170 m_useTimer = true; | 186 m_useTimer = true; |
171 } | 187 } |
172 #endif | 188 #endif |
173 if (m_animationTimer.isActive()) | 189 if (m_animationTimer.isActive()) |
(...skipping 12 matching lines...) Expand all Loading... |
186 { | 202 { |
187 m_lastAnimationFrameTime = currentTime(); | 203 m_lastAnimationFrameTime = currentTime(); |
188 serviceScriptedAnimations(convertSecondsToDOMTimeStamp(m_lastAnimationFrameT
ime)); | 204 serviceScriptedAnimations(convertSecondsToDOMTimeStamp(m_lastAnimationFrameT
ime)); |
189 } | 205 } |
190 #endif | 206 #endif |
191 | 207 |
192 } | 208 } |
193 | 209 |
194 #endif | 210 #endif |
195 | 211 |
OLD | NEW |