Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

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: fix typo Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
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 11 matching lines...) Expand all
50 } 51 }
51 52
52 ScriptedAnimationController::~ScriptedAnimationController() 53 ScriptedAnimationController::~ScriptedAnimationController()
53 { 54 {
54 } 55 }
55 56
56 void ScriptedAnimationController::trace(Visitor* visitor) 57 void ScriptedAnimationController::trace(Visitor* visitor)
57 { 58 {
58 visitor->trace(m_document); 59 visitor->trace(m_document);
59 visitor->trace(m_eventQueue); 60 visitor->trace(m_eventQueue);
61 visitor->trace(m_mediaQueryListListeners);
60 #if ENABLE(OILPAN) 62 #if ENABLE(OILPAN)
61 visitor->trace(m_perFrameEvents); 63 visitor->trace(m_perFrameEvents);
62 #endif 64 #endif
63 } 65 }
64 66
65 void ScriptedAnimationController::suspend() 67 void ScriptedAnimationController::suspend()
66 { 68 {
67 ++m_suspendCount; 69 ++m_suspendCount;
68 } 70 }
69 71
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 else 164 else
163 callback->handleEvent(highResNowMs); 165 callback->handleEvent(highResNowMs);
164 InspectorInstrumentation::didFireAnimationFrame(cookie); 166 InspectorInstrumentation::didFireAnimationFrame(cookie);
165 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "UpdateCounters", "data", InspectorUpdateCountersEvent::data()); 167 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "UpdateCounters", "data", InspectorUpdateCountersEvent::data());
166 } 168 }
167 } 169 }
168 170
169 m_callbacksToInvoke.clear(); 171 m_callbacksToInvoke.clear();
170 } 172 }
171 173
174 void ScriptedAnimationController::callMediaQueryListListeners()
175 {
176 MediaQueryListListeners listeners;
177 listeners.swap(m_mediaQueryListListeners);
178
179 for (MediaQueryListListeners::const_iterator it = listeners.begin(), end = l isteners.end();
180 it != end; ++it) {
181 (*it)->call();
182 }
183 }
184
172 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime Now) 185 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime Now)
173 { 186 {
174 if (!m_callbacks.size() && !m_eventQueue.size()) 187 if (!m_callbacks.size() && !m_eventQueue.size() && !m_mediaQueryListListener s.size())
175 return; 188 return;
176 189
177 if (m_suspendCount) 190 if (m_suspendCount)
178 return; 191 return;
179 192
180 RefPtrWillBeRawPtr<ScriptedAnimationController> protect(this); 193 RefPtrWillBeRawPtr<ScriptedAnimationController> protect(this);
181 194
195 callMediaQueryListListeners();
182 dispatchEvents(); 196 dispatchEvents();
183 executeCallbacks(monotonicTimeNow); 197 executeCallbacks(monotonicTimeNow);
184 198
185 scheduleAnimationIfNeeded(); 199 scheduleAnimationIfNeeded();
186 } 200 }
187 201
188 void ScriptedAnimationController::enqueueEvent(PassRefPtrWillBeRawPtr<Event> eve nt) 202 void ScriptedAnimationController::enqueueEvent(PassRefPtrWillBeRawPtr<Event> eve nt)
189 { 203 {
190 InspectorInstrumentation::didEnqueueEvent(event->target(), event.get()); 204 InspectorInstrumentation::didEnqueueEvent(event->target(), event.get());
191 m_eventQueue.append(event); 205 m_eventQueue.append(event);
192 scheduleAnimationIfNeeded(); 206 scheduleAnimationIfNeeded();
193 } 207 }
194 208
195 void ScriptedAnimationController::enqueuePerFrameEvent(PassRefPtrWillBeRawPtr<Ev ent> event) 209 void ScriptedAnimationController::enqueuePerFrameEvent(PassRefPtrWillBeRawPtr<Ev ent> event)
196 { 210 {
197 if (!m_perFrameEvents.add(eventTargetKey(event.get())).isNewEntry) 211 if (!m_perFrameEvents.add(eventTargetKey(event.get())).isNewEntry)
198 return; 212 return;
199 enqueueEvent(event); 213 enqueueEvent(event);
200 } 214 }
201 215
216 void ScriptedAnimationController::enqueueMediaQueryChangeListeners(WillBeHeapVec tor<RefPtrWillBeMember<MediaQueryListListener> >& listeners)
217 {
218 for (size_t i = 0; i < listeners.size(); ++i) {
219 m_mediaQueryListListeners.add(listeners[i]);
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

Powered by Google App Engine
This is Rietveld 408576698