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

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

Issue 2202493002: NOT FOR REVIEW: Fullscreen WIP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 1 month 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
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
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 ScriptedAnimationController::registerCallback(FrameRequestCallback* callback) { 74 ScriptedAnimationController::registerCallback(FrameRequestCallback* callback) {
75 CallbackId id = m_callbackCollection.registerCallback(callback); 75 CallbackId id = m_callbackCollection.registerCallback(callback);
76 scheduleAnimationIfNeeded(); 76 scheduleAnimationIfNeeded();
77 return id; 77 return id;
78 } 78 }
79 79
80 void ScriptedAnimationController::cancelCallback(CallbackId id) { 80 void ScriptedAnimationController::cancelCallback(CallbackId id) {
81 m_callbackCollection.cancelCallback(id); 81 m_callbackCollection.cancelCallback(id);
82 } 82 }
83 83
84 void ScriptedAnimationController::runTasks() {
85 // TODO(foolip): can running a task append to the task queue?
86 for (std::unique_ptr<WTF::Closure>& task : m_taskQueue)
87 (*task)();
88 m_taskQueue.clear();
89 }
90
84 void ScriptedAnimationController::dispatchEvents( 91 void ScriptedAnimationController::dispatchEvents(
85 const AtomicString& eventInterfaceFilter) { 92 const AtomicString& eventInterfaceFilter) {
86 HeapVector<Member<Event>> events; 93 HeapVector<Member<Event>> events;
87 if (eventInterfaceFilter.isEmpty()) { 94 if (eventInterfaceFilter.isEmpty()) {
88 events.swap(m_eventQueue); 95 events.swap(m_eventQueue);
89 m_perFrameEvents.clear(); 96 m_perFrameEvents.clear();
90 } else { 97 } else {
91 HeapVector<Member<Event>> remaining; 98 HeapVector<Member<Event>> remaining;
92 for (auto& event : m_eventQueue) { 99 for (auto& event : m_eventQueue) {
93 if (event && event->interfaceName() == eventInterfaceFilter) { 100 if (event && event->interfaceName() == eventInterfaceFilter) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 144
138 for (const auto& listener : listeners) { 145 for (const auto& listener : listeners) {
139 listener->notifyMediaQueryChanged(); 146 listener->notifyMediaQueryChanged();
140 } 147 }
141 } 148 }
142 149
143 bool ScriptedAnimationController::hasScheduledItems() const { 150 bool ScriptedAnimationController::hasScheduledItems() const {
144 if (m_suspendCount) 151 if (m_suspendCount)
145 return false; 152 return false;
146 153
147 return !m_callbackCollection.isEmpty() || !m_eventQueue.isEmpty() || 154 return !m_callbackCollection.isEmpty() || !m_taskQueue.isEmpty() ||
148 !m_mediaQueryListListeners.isEmpty(); 155 !m_eventQueue.isEmpty() || !m_mediaQueryListListeners.isEmpty();
149 } 156 }
150 157
151 void ScriptedAnimationController::serviceScriptedAnimations( 158 void ScriptedAnimationController::serviceScriptedAnimations(
152 double monotonicTimeNow) { 159 double monotonicTimeNow) {
153 if (!hasScheduledItems()) 160 if (!hasScheduledItems())
154 return; 161 return;
155 162
156 callMediaQueryListListeners(); 163 callMediaQueryListListeners();
157 dispatchEvents(); 164 dispatchEvents();
165 runTasks(); // must be after resize event per spec
158 executeCallbacks(monotonicTimeNow); 166 executeCallbacks(monotonicTimeNow);
159 167
160 scheduleAnimationIfNeeded(); 168 scheduleAnimationIfNeeded();
161 } 169 }
162 170
171 void ScriptedAnimationController::enqueueTask(
172 std::unique_ptr<WTF::Closure> task) {
173 m_taskQueue.append(std::move(task));
174 scheduleAnimationIfNeeded();
175 }
176
163 void ScriptedAnimationController::enqueueEvent(Event* event) { 177 void ScriptedAnimationController::enqueueEvent(Event* event) {
164 InspectorInstrumentation::asyncTaskScheduled( 178 InspectorInstrumentation::asyncTaskScheduled(
165 event->target()->getExecutionContext(), event->type(), event); 179 event->target()->getExecutionContext(), event->type(), event);
166 m_eventQueue.append(event); 180 m_eventQueue.append(event);
167 scheduleAnimationIfNeeded(); 181 scheduleAnimationIfNeeded();
168 } 182 }
169 183
170 void ScriptedAnimationController::enqueuePerFrameEvent(Event* event) { 184 void ScriptedAnimationController::enqueuePerFrameEvent(Event* event) {
171 if (!m_perFrameEvents.add(eventTargetKey(event)).isNewEntry) 185 if (!m_perFrameEvents.add(eventTargetKey(event)).isNewEntry)
172 return; 186 return;
(...skipping 13 matching lines...) Expand all
186 return; 200 return;
187 201
188 if (!m_document) 202 if (!m_document)
189 return; 203 return;
190 204
191 if (FrameView* frameView = m_document->view()) 205 if (FrameView* frameView = m_document->view())
192 frameView->scheduleAnimation(); 206 frameView->scheduleAnimation();
193 } 207 }
194 208
195 } // namespace blink 209 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698