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 10 matching lines...) Expand all Loading... |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THI
S | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THI
S |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 * | 23 * |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/dom/ScriptedAnimationController.h" | 27 #include "core/dom/ScriptedAnimationController.h" |
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/FrameRequestCallback.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 #include "platform/Logging.h" |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 std::pair<EventTarget*, StringImpl*> eventTargetKey(const Event* event) | 42 std::pair<EventTarget*, StringImpl*> eventTargetKey(const Event* event) |
43 { | 43 { |
44 return std::make_pair(event->target(), event->type().impl()); | 44 return std::make_pair(event->target(), event->type().impl()); |
45 } | 45 } |
46 | 46 |
47 ScriptedAnimationController::ScriptedAnimationController(Document* document) | 47 ScriptedAnimationController::ScriptedAnimationController(Document* document) |
48 : m_document(document) | 48 : m_document(document) |
49 , m_nextCallbackId(0) | 49 , m_callbackCollection(document) |
50 , m_suspendCount(0) | 50 , m_suspendCount(0) |
51 { | 51 { |
52 } | 52 } |
53 | 53 |
54 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(ScriptedAnimationController); | 54 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(ScriptedAnimationController); |
55 | 55 |
56 DEFINE_TRACE(ScriptedAnimationController) | 56 DEFINE_TRACE(ScriptedAnimationController) |
57 { | 57 { |
58 #if ENABLE(OILPAN) | 58 #if ENABLE(OILPAN) |
59 visitor->trace(m_callbacks); | |
60 visitor->trace(m_callbacksToInvoke); | |
61 visitor->trace(m_document); | 59 visitor->trace(m_document); |
| 60 visitor->trace(m_callbackCollection); |
62 visitor->trace(m_eventQueue); | 61 visitor->trace(m_eventQueue); |
63 visitor->trace(m_mediaQueryListListeners); | 62 visitor->trace(m_mediaQueryListListeners); |
64 visitor->trace(m_perFrameEvents); | 63 visitor->trace(m_perFrameEvents); |
65 #endif | 64 #endif |
66 } | 65 } |
67 | 66 |
68 void ScriptedAnimationController::suspend() | 67 void ScriptedAnimationController::suspend() |
69 { | 68 { |
70 ++m_suspendCount; | 69 ++m_suspendCount; |
71 } | 70 } |
72 | 71 |
73 void ScriptedAnimationController::resume() | 72 void ScriptedAnimationController::resume() |
74 { | 73 { |
75 // It would be nice to put an ASSERT(m_suspendCount > 0) here, but in WK1 re
sume() can be called | 74 // It would be nice to put an ASSERT(m_suspendCount > 0) here, but in WK1 re
sume() can be called |
76 // even when suspend hasn't (if a tab was created in the background). | 75 // even when suspend hasn't (if a tab was created in the background). |
77 if (m_suspendCount > 0) | 76 if (m_suspendCount > 0) |
78 --m_suspendCount; | 77 --m_suspendCount; |
79 scheduleAnimationIfNeeded(); | 78 scheduleAnimationIfNeeded(); |
80 } | 79 } |
81 | 80 |
82 void ScriptedAnimationController::dispatchEventsAndCallbacksForPrinting() | 81 void ScriptedAnimationController::dispatchEventsAndCallbacksForPrinting() |
83 { | 82 { |
84 dispatchEvents(EventNames::MediaQueryListEvent); | 83 dispatchEvents(EventNames::MediaQueryListEvent); |
85 callMediaQueryListListeners(); | 84 callMediaQueryListListeners(); |
86 } | 85 } |
87 | 86 |
88 ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCal
lback(RequestAnimationFrameCallback* callback) | 87 ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCal
lback(FrameRequestCallback* callback) |
89 { | 88 { |
90 ScriptedAnimationController::CallbackId id = ++m_nextCallbackId; | 89 CallbackId id = m_callbackCollection.registerCallback(callback); |
91 callback->m_cancelled = false; | |
92 callback->m_id = id; | |
93 m_callbacks.append(callback); | |
94 scheduleAnimationIfNeeded(); | 90 scheduleAnimationIfNeeded(); |
95 | |
96 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Reques
tAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_document, id)); | |
97 InspectorInstrumentation::didRequestAnimationFrame(m_document, id); | |
98 | |
99 return id; | 91 return id; |
100 } | 92 } |
101 | 93 |
102 void ScriptedAnimationController::cancelCallback(CallbackId id) | 94 void ScriptedAnimationController::cancelCallback(CallbackId id) |
103 { | 95 { |
104 for (size_t i = 0; i < m_callbacks.size(); ++i) { | 96 m_callbackCollection.cancelCallback(id); |
105 if (m_callbacks[i]->m_id == id) { | |
106 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
"CancelAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_document,
id)); | |
107 InspectorInstrumentation::didCancelAnimationFrame(m_document, id); | |
108 m_callbacks.remove(i); | |
109 return; | |
110 } | |
111 } | |
112 for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) { | |
113 if (m_callbacksToInvoke[i]->m_id == id) { | |
114 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
"CancelAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_document,
id)); | |
115 InspectorInstrumentation::didCancelAnimationFrame(m_document, id); | |
116 m_callbacksToInvoke[i]->m_cancelled = true; | |
117 // will be removed at the end of executeCallbacks() | |
118 return; | |
119 } | |
120 } | |
121 } | 97 } |
122 | 98 |
123 void ScriptedAnimationController::dispatchEvents(const AtomicString& eventInterf
aceFilter) | 99 void ScriptedAnimationController::dispatchEvents(const AtomicString& eventInterf
aceFilter) |
124 { | 100 { |
125 WillBeHeapVector<RefPtrWillBeMember<Event>> events; | 101 WillBeHeapVector<RefPtrWillBeMember<Event>> events; |
126 if (eventInterfaceFilter.isEmpty()) { | 102 if (eventInterfaceFilter.isEmpty()) { |
127 events.swap(m_eventQueue); | 103 events.swap(m_eventQueue); |
128 m_perFrameEvents.clear(); | 104 m_perFrameEvents.clear(); |
129 } else { | 105 } else { |
130 WillBeHeapVector<RefPtrWillBeMember<Event>> remaining; | 106 WillBeHeapVector<RefPtrWillBeMember<Event>> remaining; |
(...skipping 24 matching lines...) Expand all Loading... |
155 } | 131 } |
156 | 132 |
157 void ScriptedAnimationController::executeCallbacks(double monotonicTimeNow) | 133 void ScriptedAnimationController::executeCallbacks(double monotonicTimeNow) |
158 { | 134 { |
159 // dispatchEvents() runs script which can cause the document to be destroyed
. | 135 // dispatchEvents() runs script which can cause the document to be destroyed
. |
160 if (!m_document) | 136 if (!m_document) |
161 return; | 137 return; |
162 | 138 |
163 double highResNowMs = 1000.0 * m_document->loader()->timing().monotonicTimeT
oZeroBasedDocumentTime(monotonicTimeNow); | 139 double highResNowMs = 1000.0 * m_document->loader()->timing().monotonicTimeT
oZeroBasedDocumentTime(monotonicTimeNow); |
164 double legacyHighResNowMs = 1000.0 * m_document->loader()->timing().monotoni
cTimeToPseudoWallTime(monotonicTimeNow); | 140 double legacyHighResNowMs = 1000.0 * m_document->loader()->timing().monotoni
cTimeToPseudoWallTime(monotonicTimeNow); |
165 | 141 m_callbackCollection.executeCallbacks(highResNowMs, legacyHighResNowMs); |
166 // First, generate a list of callbacks to consider. Callbacks registered fr
om this point | |
167 // on are considered only for the "next" frame, not this one. | |
168 ASSERT(m_callbacksToInvoke.isEmpty()); | |
169 m_callbacksToInvoke.swap(m_callbacks); | |
170 | |
171 for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) { | |
172 RequestAnimationFrameCallback* callback = m_callbacksToInvoke[i].get(); | |
173 if (!callback->m_cancelled) { | |
174 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FireAn
imationFrame", "data", InspectorAnimationFrameEvent::data(m_document, callback->
m_id)); | |
175 InspectorInstrumentationCookie cookie = InspectorInstrumentation::wi
llFireAnimationFrame(m_document, callback->m_id); | |
176 if (callback->m_useLegacyTimeBase) | |
177 callback->handleEvent(legacyHighResNowMs); | |
178 else | |
179 callback->handleEvent(highResNowMs); | |
180 InspectorInstrumentation::didFireAnimationFrame(cookie); | |
181 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
"UpdateCounters", "data", InspectorUpdateCountersEvent::data()); | |
182 } | |
183 } | |
184 | |
185 m_callbacksToInvoke.clear(); | |
186 } | 142 } |
187 | 143 |
188 void ScriptedAnimationController::callMediaQueryListListeners() | 144 void ScriptedAnimationController::callMediaQueryListListeners() |
189 { | 145 { |
190 MediaQueryListListeners listeners; | 146 MediaQueryListListeners listeners; |
191 listeners.swap(m_mediaQueryListListeners); | 147 listeners.swap(m_mediaQueryListListeners); |
192 | 148 |
193 for (const auto& listener : listeners) { | 149 for (const auto& listener : listeners) { |
194 listener->notifyMediaQueryChanged(); | 150 listener->notifyMediaQueryChanged(); |
195 } | 151 } |
196 } | 152 } |
197 | 153 |
198 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime
Now) | 154 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime
Now) |
199 { | 155 { |
200 if (!m_callbacks.size() && !m_eventQueue.size() && !m_mediaQueryListListener
s.size()) | 156 if (m_callbackCollection.empty() && !m_eventQueue.size() && !m_mediaQueryLis
tListeners.size()) |
201 return; | 157 return; |
202 | 158 |
203 if (m_suspendCount) | 159 if (m_suspendCount) |
204 return; | 160 return; |
205 | 161 |
206 RefPtrWillBeRawPtr<ScriptedAnimationController> protect(this); | 162 RefPtrWillBeRawPtr<ScriptedAnimationController> protect(this); |
207 | 163 |
208 callMediaQueryListListeners(); | 164 callMediaQueryListListeners(); |
209 dispatchEvents(); | 165 dispatchEvents(); |
210 executeCallbacks(monotonicTimeNow); | 166 executeCallbacks(monotonicTimeNow); |
(...skipping 24 matching lines...) Expand all Loading... |
235 } | 191 } |
236 | 192 |
237 void ScriptedAnimationController::scheduleAnimationIfNeeded() | 193 void ScriptedAnimationController::scheduleAnimationIfNeeded() |
238 { | 194 { |
239 if (!m_document) | 195 if (!m_document) |
240 return; | 196 return; |
241 | 197 |
242 if (m_suspendCount) | 198 if (m_suspendCount) |
243 return; | 199 return; |
244 | 200 |
245 if (!m_callbacks.size() && !m_eventQueue.size() && !m_mediaQueryListListener
s.size()) | 201 if (m_callbackCollection.empty() && !m_eventQueue.size() && !m_mediaQueryLis
tListeners.size()) |
246 return; | 202 return; |
247 | 203 |
248 if (FrameView* frameView = m_document->view()) | 204 if (FrameView* frameView = m_document->view()) |
249 frameView->scheduleAnimation(); | 205 frameView->scheduleAnimation(); |
250 } | 206 } |
251 | 207 |
252 } | 208 } |
OLD | NEW |