| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 void ScriptedAnimationController::resume() | 60 void ScriptedAnimationController::resume() |
| 61 { | 61 { |
| 62 // It would be nice to put an ASSERT(m_suspendCount > 0) here, but in WK1 re
sume() can be called | 62 // It would be nice to put an ASSERT(m_suspendCount > 0) here, but in WK1 re
sume() can be called |
| 63 // even when suspend hasn't (if a tab was created in the background). | 63 // even when suspend hasn't (if a tab was created in the background). |
| 64 if (m_suspendCount > 0) | 64 if (m_suspendCount > 0) |
| 65 --m_suspendCount; | 65 --m_suspendCount; |
| 66 scheduleAnimationIfNeeded(); | 66 scheduleAnimationIfNeeded(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCal
lback(PassRefPtr<RequestAnimationFrameCallback> callback) | 69 ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCal
lback(PassOwnPtr<RequestAnimationFrameCallback> callback) |
| 70 { | 70 { |
| 71 ScriptedAnimationController::CallbackId id = ++m_nextCallbackId; | 71 ScriptedAnimationController::CallbackId id = ++m_nextCallbackId; |
| 72 callback->m_firedOrCancelled = false; | 72 callback->m_cancelled = false; |
| 73 callback->m_id = id; | 73 callback->m_id = id; |
| 74 m_callbacks.append(callback); | 74 m_callbacks.append(callback); |
| 75 scheduleAnimationIfNeeded(); | 75 scheduleAnimationIfNeeded(); |
| 76 | 76 |
| 77 InspectorInstrumentation::didRequestAnimationFrame(m_document, id); | 77 InspectorInstrumentation::didRequestAnimationFrame(m_document, id); |
| 78 | 78 |
| 79 return id; | 79 return id; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ScriptedAnimationController::cancelCallback(CallbackId id) | 82 void ScriptedAnimationController::cancelCallback(CallbackId id) |
| 83 { | 83 { |
| 84 for (size_t i = 0; i < m_callbacks.size(); ++i) { | 84 for (size_t i = 0; i < m_callbacks.size(); ++i) { |
| 85 if (m_callbacks[i]->m_id == id) { | 85 if (m_callbacks[i]->m_id == id) { |
| 86 m_callbacks[i]->m_firedOrCancelled = true; | |
| 87 InspectorInstrumentation::didCancelAnimationFrame(m_document, id); | 86 InspectorInstrumentation::didCancelAnimationFrame(m_document, id); |
| 88 m_callbacks.remove(i); | 87 m_callbacks.remove(i); |
| 89 return; | 88 return; |
| 90 } | 89 } |
| 91 } | 90 } |
| 91 for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) { |
| 92 if (m_callbacksToInvoke[i]->m_id == id) { |
| 93 InspectorInstrumentation::didCancelAnimationFrame(m_document, id); |
| 94 m_callbacksToInvoke[i]->m_cancelled = true; |
| 95 // will be removed at the end of executeCallbacks() |
| 96 return; |
| 97 } |
| 98 } |
| 92 } | 99 } |
| 93 | 100 |
| 94 void ScriptedAnimationController::dispatchEvents() | 101 void ScriptedAnimationController::dispatchEvents() |
| 95 { | 102 { |
| 96 Vector<RefPtr<Event> > events; | 103 Vector<RefPtr<Event> > events; |
| 97 events.swap(m_eventQueue); | 104 events.swap(m_eventQueue); |
| 98 m_perFrameEvents.clear(); | 105 m_perFrameEvents.clear(); |
| 99 | 106 |
| 100 for (size_t i = 0; i < events.size(); ++i) { | 107 for (size_t i = 0; i < events.size(); ++i) { |
| 101 EventTarget* eventTarget = events[i]->target(); | 108 EventTarget* eventTarget = events[i]->target(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 113 { | 120 { |
| 114 // dispatchEvents() runs script which can cause the document to be destroyed
. | 121 // dispatchEvents() runs script which can cause the document to be destroyed
. |
| 115 if (!m_document) | 122 if (!m_document) |
| 116 return; | 123 return; |
| 117 | 124 |
| 118 double highResNowMs = 1000.0 * m_document->loader()->timing()->monotonicTime
ToZeroBasedDocumentTime(monotonicTimeNow); | 125 double highResNowMs = 1000.0 * m_document->loader()->timing()->monotonicTime
ToZeroBasedDocumentTime(monotonicTimeNow); |
| 119 double legacyHighResNowMs = 1000.0 * m_document->loader()->timing()->monoton
icTimeToPseudoWallTime(monotonicTimeNow); | 126 double legacyHighResNowMs = 1000.0 * m_document->loader()->timing()->monoton
icTimeToPseudoWallTime(monotonicTimeNow); |
| 120 | 127 |
| 121 // First, generate a list of callbacks to consider. Callbacks registered fr
om this point | 128 // First, generate a list of callbacks to consider. Callbacks registered fr
om this point |
| 122 // on are considered only for the "next" frame, not this one. | 129 // on are considered only for the "next" frame, not this one. |
| 123 CallbackList callbacks(m_callbacks); | 130 ASSERT(m_callbacksToInvoke.isEmpty()); |
| 131 m_callbacksToInvoke.swap(m_callbacks); |
| 124 | 132 |
| 125 for (size_t i = 0; i < callbacks.size(); ++i) { | 133 for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) { |
| 126 RequestAnimationFrameCallback* callback = callbacks[i].get(); | 134 RequestAnimationFrameCallback* callback = m_callbacksToInvoke[i].get(); |
| 127 if (!callback->m_firedOrCancelled) { | 135 if (!callback->m_cancelled) { |
| 128 callback->m_firedOrCancelled = true; | |
| 129 InspectorInstrumentationCookie cookie = InspectorInstrumentation::wi
llFireAnimationFrame(m_document, callback->m_id); | 136 InspectorInstrumentationCookie cookie = InspectorInstrumentation::wi
llFireAnimationFrame(m_document, callback->m_id); |
| 130 if (callback->m_useLegacyTimeBase) | 137 if (callback->m_useLegacyTimeBase) |
| 131 callback->handleEvent(legacyHighResNowMs); | 138 callback->handleEvent(legacyHighResNowMs); |
| 132 else | 139 else |
| 133 callback->handleEvent(highResNowMs); | 140 callback->handleEvent(highResNowMs); |
| 134 InspectorInstrumentation::didFireAnimationFrame(cookie); | 141 InspectorInstrumentation::didFireAnimationFrame(cookie); |
| 135 } | 142 } |
| 136 } | 143 } |
| 137 | 144 |
| 138 // Remove any callbacks we fired from the list of pending callbacks. | 145 m_callbacksToInvoke.clear(); |
| 139 for (size_t i = 0; i < m_callbacks.size();) { | |
| 140 if (m_callbacks[i]->m_firedOrCancelled) | |
| 141 m_callbacks.remove(i); | |
| 142 else | |
| 143 ++i; | |
| 144 } | |
| 145 } | 146 } |
| 146 | 147 |
| 147 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime
Now) | 148 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime
Now) |
| 148 { | 149 { |
| 149 if (!m_callbacks.size() && !m_eventQueue.size()) | 150 if (!m_callbacks.size() && !m_eventQueue.size()) |
| 150 return; | 151 return; |
| 151 | 152 |
| 152 if (m_suspendCount) | 153 if (m_suspendCount) |
| 153 return; | 154 return; |
| 154 | 155 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 182 return; | 183 return; |
| 183 | 184 |
| 184 if (!m_callbacks.size() && !m_eventQueue.size()) | 185 if (!m_callbacks.size() && !m_eventQueue.size()) |
| 185 return; | 186 return; |
| 186 | 187 |
| 187 if (FrameView* frameView = m_document->view()) | 188 if (FrameView* frameView = m_document->view()) |
| 188 frameView->scheduleAnimation(); | 189 frameView->scheduleAnimation(); |
| 189 } | 190 } |
| 190 | 191 |
| 191 } | 192 } |
| OLD | NEW |