| 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 18 matching lines...) Expand all Loading... |
| 29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
| 30 #include "core/dom/RequestAnimationFrameCallback.h" | 30 #include "core/dom/RequestAnimationFrameCallback.h" |
| 31 #include "core/events/Event.h" | 31 #include "core/events/Event.h" |
| 32 #include "core/frame/DOMWindow.h" | 32 #include "core/frame/DOMWindow.h" |
| 33 #include "core/frame/FrameView.h" | 33 #include "core/frame/FrameView.h" |
| 34 #include "core/inspector/InspectorInstrumentation.h" | 34 #include "core/inspector/InspectorInstrumentation.h" |
| 35 #include "core/loader/DocumentLoader.h" | 35 #include "core/loader/DocumentLoader.h" |
| 36 | 36 |
| 37 namespace WebCore { | 37 namespace WebCore { |
| 38 | 38 |
| 39 std::pair<EventTarget*, StringImpl*> scheduledEventTargetKey(const Event* event) | 39 std::pair<EventTarget*, StringImpl*> eventTargetKey(const Event* event) |
| 40 { | 40 { |
| 41 return std::make_pair(event->target(), event->type().impl()); | 41 return std::make_pair(event->target(), event->type().impl()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 ScriptedAnimationController::ScriptedAnimationController(Document* document) | 44 ScriptedAnimationController::ScriptedAnimationController(Document* document) |
| 45 : m_document(document) | 45 : m_document(document) |
| 46 , m_nextCallbackId(0) | 46 , m_nextCallbackId(0) |
| 47 , m_suspendCount(0) | 47 , m_suspendCount(0) |
| 48 { | 48 { |
| 49 } | 49 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 m_callbacks.remove(i); | 88 m_callbacks.remove(i); |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 void ScriptedAnimationController::dispatchEvents() | 94 void ScriptedAnimationController::dispatchEvents() |
| 95 { | 95 { |
| 96 Vector<RefPtr<Event> > events; | 96 Vector<RefPtr<Event> > events; |
| 97 events.swap(m_eventQueue); | 97 events.swap(m_eventQueue); |
| 98 m_scheduledEventTargets.clear(); | 98 m_perFrameEvents.clear(); |
| 99 | 99 |
| 100 for (size_t i = 0; i < events.size(); ++i) { | 100 for (size_t i = 0; i < events.size(); ++i) { |
| 101 EventTarget* eventTarget = events[i]->target(); | 101 EventTarget* eventTarget = events[i]->target(); |
| 102 // FIXME: we should figure out how to make dispatchEvent properly virtua
l to avoid this. | 102 // FIXME: we should figure out how to make dispatchEvent properly virtua
l to avoid |
| 103 // special casting window. |
| 104 // FIXME: We should not fire events for nodes that are no longer in the
tree. |
| 103 if (DOMWindow* window = eventTarget->toDOMWindow()) | 105 if (DOMWindow* window = eventTarget->toDOMWindow()) |
| 104 window->dispatchEvent(events[i], 0); | 106 window->dispatchEvent(events[i], 0); |
| 105 else | 107 else |
| 106 eventTarget->dispatchEvent(events[i]); | 108 eventTarget->dispatchEvent(events[i]); |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 | 111 |
| 110 void ScriptedAnimationController::executeCallbacks(double monotonicTimeNow) | 112 void ScriptedAnimationController::executeCallbacks(double monotonicTimeNow) |
| 111 { | 113 { |
| 112 // dispatchEvents() runs script which can cause the document to be destroyed
. | 114 // dispatchEvents() runs script which can cause the document to be destroyed
. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return; | 153 return; |
| 152 | 154 |
| 153 RefPtr<ScriptedAnimationController> protect(this); | 155 RefPtr<ScriptedAnimationController> protect(this); |
| 154 | 156 |
| 155 dispatchEvents(); | 157 dispatchEvents(); |
| 156 executeCallbacks(monotonicTimeNow); | 158 executeCallbacks(monotonicTimeNow); |
| 157 | 159 |
| 158 scheduleAnimationIfNeeded(); | 160 scheduleAnimationIfNeeded(); |
| 159 } | 161 } |
| 160 | 162 |
| 161 void ScriptedAnimationController::scheduleEvent(PassRefPtr<Event> event) | 163 void ScriptedAnimationController::enqueueEvent(PassRefPtr<Event> event) |
| 162 { | 164 { |
| 163 if (!m_scheduledEventTargets.add(scheduledEventTargetKey(event.get())).isNew
Entry) | |
| 164 return; | |
| 165 m_eventQueue.append(event); | 165 m_eventQueue.append(event); |
| 166 scheduleAnimationIfNeeded(); | 166 scheduleAnimationIfNeeded(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void ScriptedAnimationController::enqueuePerFrameEvent(PassRefPtr<Event> event) |
| 170 { |
| 171 if (!m_perFrameEvents.add(eventTargetKey(event.get())).isNewEntry) |
| 172 return; |
| 173 enqueueEvent(event); |
| 174 } |
| 175 |
| 169 void ScriptedAnimationController::scheduleAnimationIfNeeded() | 176 void ScriptedAnimationController::scheduleAnimationIfNeeded() |
| 170 { | 177 { |
| 171 if (!m_document) | 178 if (!m_document) |
| 172 return; | 179 return; |
| 173 | 180 |
| 174 if (m_suspendCount) | 181 if (m_suspendCount) |
| 175 return; | 182 return; |
| 176 | 183 |
| 177 if (!m_callbacks.size() && !m_eventQueue.size()) | 184 if (!m_callbacks.size() && !m_eventQueue.size()) |
| 178 return; | 185 return; |
| 179 | 186 |
| 180 if (FrameView* frameView = m_document->view()) | 187 if (FrameView* frameView = m_document->view()) |
| 181 frameView->scheduleAnimation(); | 188 frameView->scheduleAnimation(); |
| 182 } | 189 } |
| 183 | 190 |
| 184 } | 191 } |
| OLD | NEW |