Chromium Code Reviews

Side by Side Diff: Source/core/dom/ScriptedAnimationController.cpp

Issue 337883003: Call media query change listeners asynchronously. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: review comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/ScriptedAnimationController.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND A NY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND A NY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR A NY 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR A NY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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/dom/Document.h" 30 #include "core/dom/Document.h"
30 #include "core/dom/RequestAnimationFrameCallback.h" 31 #include "core/dom/RequestAnimationFrameCallback.h"
31 #include "core/events/Event.h" 32 #include "core/events/Event.h"
32 #include "core/frame/LocalDOMWindow.h" 33 #include "core/frame/LocalDOMWindow.h"
33 #include "core/frame/FrameView.h" 34 #include "core/frame/FrameView.h"
34 #include "core/inspector/InspectorInstrumentation.h" 35 #include "core/inspector/InspectorInstrumentation.h"
35 #include "core/inspector/InspectorTraceEvents.h" 36 #include "core/inspector/InspectorTraceEvents.h"
36 #include "core/loader/DocumentLoader.h" 37 #include "core/loader/DocumentLoader.h"
37 38
38 namespace WebCore { 39 namespace WebCore {
(...skipping 123 matching lines...)
162 else 163 else
163 callback->handleEvent(highResNowMs); 164 callback->handleEvent(highResNowMs);
164 InspectorInstrumentation::didFireAnimationFrame(cookie); 165 InspectorInstrumentation::didFireAnimationFrame(cookie);
165 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "UpdateCounters", "data", InspectorUpdateCountersEvent::data()); 166 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "UpdateCounters", "data", InspectorUpdateCountersEvent::data());
166 } 167 }
167 } 168 }
168 169
169 m_callbacksToInvoke.clear(); 170 m_callbacksToInvoke.clear();
170 } 171 }
171 172
173 void ScriptedAnimationController::callMediaQueryListListeners()
174 {
175 MediaQueryListListeners listeners;
176 listeners.swap(m_mediaQueryListListeners);
177
178 for (MediaQueryListListeners::const_iterator it = m_mediaQueryListListeners. begin(), end = m_mediaQueryListListeners.end();
179 it != end; ++it) {
180 (*it)->call();
181 }
182 }
183
172 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime Now) 184 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime Now)
173 { 185 {
174 if (!m_callbacks.size() && !m_eventQueue.size()) 186 if (!m_callbacks.size() && !m_eventQueue.size() && !m_mediaQueryListListener s.size())
175 return; 187 return;
176 188
177 if (m_suspendCount) 189 if (m_suspendCount)
178 return; 190 return;
179 191
180 RefPtrWillBeRawPtr<ScriptedAnimationController> protect(this); 192 RefPtrWillBeRawPtr<ScriptedAnimationController> protect(this);
181 193
194 callMediaQueryListListeners();
182 dispatchEvents(); 195 dispatchEvents();
183 executeCallbacks(monotonicTimeNow); 196 executeCallbacks(monotonicTimeNow);
184 197
185 scheduleAnimationIfNeeded(); 198 scheduleAnimationIfNeeded();
186 } 199 }
187 200
188 void ScriptedAnimationController::enqueueEvent(PassRefPtrWillBeRawPtr<Event> eve nt) 201 void ScriptedAnimationController::enqueueEvent(PassRefPtrWillBeRawPtr<Event> eve nt)
189 { 202 {
190 InspectorInstrumentation::didEnqueueEvent(event->target(), event.get()); 203 InspectorInstrumentation::didEnqueueEvent(event->target(), event.get());
191 m_eventQueue.append(event); 204 m_eventQueue.append(event);
192 scheduleAnimationIfNeeded(); 205 scheduleAnimationIfNeeded();
193 } 206 }
194 207
195 void ScriptedAnimationController::enqueuePerFrameEvent(PassRefPtrWillBeRawPtr<Ev ent> event) 208 void ScriptedAnimationController::enqueuePerFrameEvent(PassRefPtrWillBeRawPtr<Ev ent> event)
196 { 209 {
197 if (!m_perFrameEvents.add(eventTargetKey(event.get())).isNewEntry) 210 if (!m_perFrameEvents.add(eventTargetKey(event.get())).isNewEntry)
198 return; 211 return;
199 enqueueEvent(event); 212 enqueueEvent(event);
200 } 213 }
201 214
215 void ScriptedAnimationController::enqueueMediaQueryChangeListeners(WillBeHeapVec tor<RefPtrWillBeMember<MediaQueryListListener> >& listeners)
216 {
217 for (size_t i = 0; i < listeners.size(); ++i) {
218 if (!m_mediaQueryListListeners.contains(listeners[i]))
219 m_mediaQueryListListeners.add(listeners[i]);
esprehn 2014/07/01 01:21:26 You want a ListHashSet for this.
220 }
221 scheduleAnimationIfNeeded();
222 }
223
202 void ScriptedAnimationController::scheduleAnimationIfNeeded() 224 void ScriptedAnimationController::scheduleAnimationIfNeeded()
203 { 225 {
204 if (!m_document) 226 if (!m_document)
205 return; 227 return;
206 228
207 if (m_suspendCount) 229 if (m_suspendCount)
208 return; 230 return;
209 231
210 if (!m_callbacks.size() && !m_eventQueue.size()) 232 if (!m_callbacks.size() && !m_eventQueue.size() && !m_mediaQueryListListener s.size())
211 return; 233 return;
212 234
213 if (FrameView* frameView = m_document->view()) 235 if (FrameView* frameView = m_document->view())
214 frameView->scheduleAnimation(); 236 frameView->scheduleAnimation();
215 } 237 }
216 238
217 } 239 }
OLDNEW
« no previous file with comments | « Source/core/dom/ScriptedAnimationController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine