| 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 #include "core/css/MediaQueryListListener.h" | 29 #include "core/css/MediaQueryListListener.h" |
| 30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/dom/RequestAnimationFrameCallback.h" | 31 #include "core/dom/RequestAnimationFrameCallback.h" |
| 32 #include "core/events/Event.h" | 32 #include "core/events/Event.h" |
| 33 #include "core/frame/LocalDOMWindow.h" | 33 #include "core/frame/LocalDOMWindow.h" |
| 34 #include "core/frame/FrameView.h" | 34 #include "core/frame/FrameView.h" |
| 35 #include "core/inspector/InspectorInstrumentation.h" | 35 #include "core/inspector/InspectorInstrumentation.h" |
| 36 #include "core/inspector/InspectorTraceEvents.h" | 36 #include "core/inspector/InspectorTraceEvents.h" |
| 37 #include "core/loader/DocumentLoader.h" | 37 #include "core/loader/DocumentLoader.h" |
| 38 #include "platform/Logging.h" |
| 38 | 39 |
| 39 namespace blink { | 40 namespace blink { |
| 40 | 41 |
| 41 std::pair<EventTarget*, StringImpl*> eventTargetKey(const Event* event) | 42 std::pair<EventTarget*, StringImpl*> eventTargetKey(const Event* event) |
| 42 { | 43 { |
| 43 return std::make_pair(event->target(), event->type().impl()); | 44 return std::make_pair(event->target(), event->type().impl()); |
| 44 } | 45 } |
| 45 | 46 |
| 46 ScriptedAnimationController::ScriptedAnimationController(Document* document) | 47 ScriptedAnimationController::ScriptedAnimationController(Document* document) |
| 47 : m_document(document) | 48 : m_document(document) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 visitor->trace(m_document); | 61 visitor->trace(m_document); |
| 61 visitor->trace(m_eventQueue); | 62 visitor->trace(m_eventQueue); |
| 62 visitor->trace(m_mediaQueryListListeners); | 63 visitor->trace(m_mediaQueryListListeners); |
| 63 visitor->trace(m_perFrameEvents); | 64 visitor->trace(m_perFrameEvents); |
| 64 #endif | 65 #endif |
| 65 } | 66 } |
| 66 | 67 |
| 67 void ScriptedAnimationController::suspend() | 68 void ScriptedAnimationController::suspend() |
| 68 { | 69 { |
| 69 ++m_suspendCount; | 70 ++m_suspendCount; |
| 71 WTF_LOG(ScriptedAnimationController, "suspend: count = %d", m_suspendCount); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void ScriptedAnimationController::resume() | 74 void ScriptedAnimationController::resume() |
| 73 { | 75 { |
| 74 // It would be nice to put an ASSERT(m_suspendCount > 0) here, but in WK1 re
sume() can be called | 76 // It would be nice to put an ASSERT(m_suspendCount > 0) here, but in WK1 re
sume() can be called |
| 75 // even when suspend hasn't (if a tab was created in the background). | 77 // even when suspend hasn't (if a tab was created in the background). |
| 76 if (m_suspendCount > 0) | 78 if (m_suspendCount > 0) |
| 77 --m_suspendCount; | 79 --m_suspendCount; |
| 80 WTF_LOG(ScriptedAnimationController, "resume: count = %d", m_suspendCount); |
| 78 scheduleAnimationIfNeeded(); | 81 scheduleAnimationIfNeeded(); |
| 79 } | 82 } |
| 80 | 83 |
| 81 ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCal
lback(PassOwnPtr<RequestAnimationFrameCallback> callback) | 84 ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCal
lback(PassOwnPtr<RequestAnimationFrameCallback> callback) |
| 82 { | 85 { |
| 83 ScriptedAnimationController::CallbackId id = ++m_nextCallbackId; | 86 ScriptedAnimationController::CallbackId id = ++m_nextCallbackId; |
| 87 WTF_LOG(ScriptedAnimationController, "registerCallback: id = %d", id); |
| 84 callback->m_cancelled = false; | 88 callback->m_cancelled = false; |
| 85 callback->m_id = id; | 89 callback->m_id = id; |
| 86 m_callbacks.append(callback); | 90 m_callbacks.append(callback); |
| 87 scheduleAnimationIfNeeded(); | 91 scheduleAnimationIfNeeded(); |
| 88 | 92 |
| 89 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Reques
tAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_document, id)); | 93 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Reques
tAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_document, id)); |
| 90 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "
CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 94 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "
CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
| 91 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. | 95 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. |
| 92 InspectorInstrumentation::didRequestAnimationFrame(m_document, id); | 96 InspectorInstrumentation::didRequestAnimationFrame(m_document, id); |
| 93 | 97 |
| 94 return id; | 98 return id; |
| 95 } | 99 } |
| 96 | 100 |
| 97 void ScriptedAnimationController::cancelCallback(CallbackId id) | 101 void ScriptedAnimationController::cancelCallback(CallbackId id) |
| 98 { | 102 { |
| 103 WTF_LOG(ScriptedAnimationController, "cancelCallback: id = %d", id); |
| 99 for (size_t i = 0; i < m_callbacks.size(); ++i) { | 104 for (size_t i = 0; i < m_callbacks.size(); ++i) { |
| 100 if (m_callbacks[i]->m_id == id) { | 105 if (m_callbacks[i]->m_id == id) { |
| 101 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
"CancelAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_document,
id)); | 106 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
"CancelAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_document,
id)); |
| 102 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.st
ack"), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 107 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.st
ack"), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
| 103 // FIXME(361045): remove InspectorInstrumentation calls once DevTool
s Timeline migrates to tracing. | 108 // FIXME(361045): remove InspectorInstrumentation calls once DevTool
s Timeline migrates to tracing. |
| 104 InspectorInstrumentation::didCancelAnimationFrame(m_document, id); | 109 InspectorInstrumentation::didCancelAnimationFrame(m_document, id); |
| 105 m_callbacks.remove(i); | 110 m_callbacks.remove(i); |
| 106 return; | 111 return; |
| 107 } | 112 } |
| 108 } | 113 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 listeners.swap(m_mediaQueryListListeners); | 182 listeners.swap(m_mediaQueryListListeners); |
| 178 | 183 |
| 179 for (MediaQueryListListeners::const_iterator it = listeners.begin(), end = l
isteners.end(); | 184 for (MediaQueryListListeners::const_iterator it = listeners.begin(), end = l
isteners.end(); |
| 180 it != end; ++it) { | 185 it != end; ++it) { |
| 181 (*it)->call(); | 186 (*it)->call(); |
| 182 } | 187 } |
| 183 } | 188 } |
| 184 | 189 |
| 185 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime
Now) | 190 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime
Now) |
| 186 { | 191 { |
| 192 WTF_LOG(ScriptedAnimationController, "serviceScriptedAnimations: #callbacks
= %d, #events = %d, #mediaQueryListListeners = %d, count = %d", |
| 193 static_cast<int>(m_callbacks.size()), |
| 194 static_cast<int>(m_eventQueue.size()), |
| 195 static_cast<int>(m_mediaQueryListListeners.size()), |
| 196 m_suspendCount); |
| 187 if (!m_callbacks.size() && !m_eventQueue.size() && !m_mediaQueryListListener
s.size()) | 197 if (!m_callbacks.size() && !m_eventQueue.size() && !m_mediaQueryListListener
s.size()) |
| 188 return; | 198 return; |
| 189 | 199 |
| 190 if (m_suspendCount) | 200 if (m_suspendCount) |
| 191 return; | 201 return; |
| 192 | 202 |
| 193 RefPtrWillBeRawPtr<ScriptedAnimationController> protect(this); | 203 RefPtrWillBeRawPtr<ScriptedAnimationController> protect(this); |
| 194 | 204 |
| 195 callMediaQueryListListeners(); | 205 callMediaQueryListListeners(); |
| 196 dispatchEvents(); | 206 dispatchEvents(); |
| 197 executeCallbacks(monotonicTimeNow); | 207 executeCallbacks(monotonicTimeNow); |
| 198 | 208 |
| 199 scheduleAnimationIfNeeded(); | 209 scheduleAnimationIfNeeded(); |
| 200 } | 210 } |
| 201 | 211 |
| 202 void ScriptedAnimationController::enqueueEvent(PassRefPtrWillBeRawPtr<Event> eve
nt) | 212 void ScriptedAnimationController::enqueueEvent(PassRefPtrWillBeRawPtr<Event> eve
nt) |
| 203 { | 213 { |
| 214 WTF_LOG(ScriptedAnimationController, "enqueueEvent"); |
| 204 InspectorInstrumentation::didEnqueueEvent(event->target(), event.get()); | 215 InspectorInstrumentation::didEnqueueEvent(event->target(), event.get()); |
| 205 m_eventQueue.append(event); | 216 m_eventQueue.append(event); |
| 206 scheduleAnimationIfNeeded(); | 217 scheduleAnimationIfNeeded(); |
| 207 } | 218 } |
| 208 | 219 |
| 209 void ScriptedAnimationController::enqueuePerFrameEvent(PassRefPtrWillBeRawPtr<Ev
ent> event) | 220 void ScriptedAnimationController::enqueuePerFrameEvent(PassRefPtrWillBeRawPtr<Ev
ent> event) |
| 210 { | 221 { |
| 211 if (!m_perFrameEvents.add(eventTargetKey(event.get())).isNewEntry) | 222 if (!m_perFrameEvents.add(eventTargetKey(event.get())).isNewEntry) |
| 212 return; | 223 return; |
| 213 enqueueEvent(event); | 224 enqueueEvent(event); |
| 214 } | 225 } |
| 215 | 226 |
| 216 void ScriptedAnimationController::enqueueMediaQueryChangeListeners(WillBeHeapVec
tor<RefPtrWillBeMember<MediaQueryListListener> >& listeners) | 227 void ScriptedAnimationController::enqueueMediaQueryChangeListeners(WillBeHeapVec
tor<RefPtrWillBeMember<MediaQueryListListener> >& listeners) |
| 217 { | 228 { |
| 229 WTF_LOG(ScriptedAnimationController, "enqueueMediaQueryChangeListeners"); |
| 218 for (size_t i = 0; i < listeners.size(); ++i) { | 230 for (size_t i = 0; i < listeners.size(); ++i) { |
| 219 m_mediaQueryListListeners.add(listeners[i]); | 231 m_mediaQueryListListeners.add(listeners[i]); |
| 220 } | 232 } |
| 221 scheduleAnimationIfNeeded(); | 233 scheduleAnimationIfNeeded(); |
| 222 } | 234 } |
| 223 | 235 |
| 224 void ScriptedAnimationController::scheduleAnimationIfNeeded() | 236 void ScriptedAnimationController::scheduleAnimationIfNeeded() |
| 225 { | 237 { |
| 238 WTF_LOG(ScriptedAnimationController, "scheduleAnimationIfNeeded: document =
%d, count = %d, #callbacks = %d, #events = %d, #mediaQueryListListeners =%d, fra
meView = %d", |
| 239 m_document ? 1 : 0, m_suspendCount, |
| 240 static_cast<int>(m_callbacks.size()), |
| 241 static_cast<int>(m_eventQueue.size()), |
| 242 static_cast<int>(m_mediaQueryListListeners.size()), |
| 243 m_document && m_document->view() ? 1 : 0); |
| 226 if (!m_document) | 244 if (!m_document) |
| 227 return; | 245 return; |
| 228 | 246 |
| 229 if (m_suspendCount) | 247 if (m_suspendCount) |
| 230 return; | 248 return; |
| 231 | 249 |
| 232 if (!m_callbacks.size() && !m_eventQueue.size() && !m_mediaQueryListListener
s.size()) | 250 if (!m_callbacks.size() && !m_eventQueue.size() && !m_mediaQueryListListener
s.size()) |
| 233 return; | 251 return; |
| 234 | 252 |
| 235 if (FrameView* frameView = m_document->view()) | 253 if (FrameView* frameView = m_document->view()) |
| 236 frameView->scheduleAnimation(); | 254 frameView->scheduleAnimation(); |
| 237 } | 255 } |
| 238 | 256 |
| 239 } | 257 } |
| OLD | NEW |