Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Victor Carbune (victor@rosedu.org) | 2 * Copyright (C) 2012 Victor Carbune (victor@rosedu.org) |
| 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 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 | 27 |
| 28 #include "core/events/GenericEventQueue.h" | 28 #include "core/events/GenericEventQueue.h" |
| 29 | 29 |
| 30 #include "core/events/Event.h" | 30 #include "core/events/Event.h" |
| 31 #include "core/inspector/InspectorInstrumentation.h" | |
| 31 #include "platform/TraceEvent.h" | 32 #include "platform/TraceEvent.h" |
| 32 | 33 |
| 33 namespace WebCore { | 34 namespace WebCore { |
| 34 | 35 |
| 35 PassOwnPtrWillBeRawPtr<GenericEventQueue> GenericEventQueue::create(EventTarget* owner) | 36 PassOwnPtrWillBeRawPtr<GenericEventQueue> GenericEventQueue::create(EventTarget* owner) |
| 36 { | 37 { |
| 37 return adoptPtrWillBeNoop(new GenericEventQueue(owner)); | 38 return adoptPtrWillBeNoop(new GenericEventQueue(owner)); |
| 38 } | 39 } |
| 39 | 40 |
| 40 GenericEventQueue::GenericEventQueue(EventTarget* owner) | 41 GenericEventQueue::GenericEventQueue(EventTarget* owner) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 57 | 58 |
| 58 bool GenericEventQueue::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event) | 59 bool GenericEventQueue::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event) |
| 59 { | 60 { |
| 60 if (m_isClosed) | 61 if (m_isClosed) |
| 61 return false; | 62 return false; |
| 62 | 63 |
| 63 if (event->target() == m_owner) | 64 if (event->target() == m_owner) |
| 64 event->setTarget(nullptr); | 65 event->setTarget(nullptr); |
| 65 | 66 |
| 66 TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event.ge t(), "type", event->type().ascii()); | 67 TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event.ge t(), "type", event->type().ascii()); |
| 68 InspectorInstrumentation::didEnqueueEvent(event->target() ? event->target() : m_owner.get(), event.get()); | |
| 67 m_pendingEvents.append(event); | 69 m_pendingEvents.append(event); |
| 68 | 70 |
| 69 if (!m_timer.isActive()) | 71 if (!m_timer.isActive()) |
| 70 m_timer.startOneShot(0, FROM_HERE); | 72 m_timer.startOneShot(0, FROM_HERE); |
| 71 | 73 |
| 72 return true; | 74 return true; |
| 73 } | 75 } |
| 74 | 76 |
| 75 bool GenericEventQueue::cancelEvent(Event* event) | 77 bool GenericEventQueue::cancelEvent(Event* event) |
| 76 { | 78 { |
| 77 bool found = m_pendingEvents.contains(event); | 79 bool found = m_pendingEvents.contains(event); |
| 78 | 80 |
| 79 if (found) { | 81 if (found) { |
| 82 InspectorInstrumentation::didRemoveEvent(event->target() ? event->target () : m_owner.get(), event); | |
| 80 m_pendingEvents.remove(m_pendingEvents.find(event)); | 83 m_pendingEvents.remove(m_pendingEvents.find(event)); |
| 81 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled"); | 84 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled"); |
| 82 } | 85 } |
| 83 | 86 |
| 84 if (m_pendingEvents.isEmpty()) | 87 if (m_pendingEvents.isEmpty()) |
| 85 m_timer.stop(); | 88 m_timer.stop(); |
| 86 | 89 |
| 87 return found; | 90 return found; |
| 88 } | 91 } |
| 89 | 92 |
| 90 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*) | 93 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*) |
| 91 { | 94 { |
| 92 ASSERT(!m_timer.isActive()); | 95 ASSERT(!m_timer.isActive()); |
| 93 ASSERT(!m_pendingEvents.isEmpty()); | 96 ASSERT(!m_pendingEvents.isEmpty()); |
| 94 | 97 |
| 95 WillBeHeapVector<RefPtrWillBeMember<Event> > pendingEvents; | 98 WillBeHeapVector<RefPtrWillBeMember<Event> > pendingEvents; |
| 96 m_pendingEvents.swap(pendingEvents); | 99 m_pendingEvents.swap(pendingEvents); |
| 97 | 100 |
| 98 RefPtrWillBeRawPtr<EventTarget> protect(m_owner.get()); | 101 RefPtrWillBeRawPtr<EventTarget> protect(m_owner.get()); |
| 99 for (size_t i = 0; i < pendingEvents.size(); ++i) { | 102 for (size_t i = 0; i < pendingEvents.size(); ++i) { |
| 100 Event* event = pendingEvents[i].get(); | 103 Event* event = pendingEvents[i].get(); |
| 101 EventTarget* target = event->target() ? event->target() : m_owner.get(); | 104 EventTarget* target = event->target() ? event->target() : m_owner.get(); |
| 102 CString type(event->type().ascii()); | 105 CString type(event->type().ascii()); |
| 103 TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent", event, "dispatch", "type", type); | 106 TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent", event, "dispatch", "type", type); |
| 104 target->dispatchEvent(pendingEvents[i].release()); | 107 target->dispatchEvent(pendingEvents[i]); |
| 105 TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event, "type", type); | 108 TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event, "type", type); |
| 109 InspectorInstrumentation::didRemoveEvent(target, event); | |
| 106 } | 110 } |
| 107 } | 111 } |
| 108 | 112 |
| 109 void GenericEventQueue::close() | 113 void GenericEventQueue::close() |
| 110 { | 114 { |
| 111 m_isClosed = true; | 115 m_isClosed = true; |
| 112 cancelAllEvents(); | 116 cancelAllEvents(); |
| 113 } | 117 } |
| 114 | 118 |
| 115 void GenericEventQueue::cancelAllEvents() | 119 void GenericEventQueue::cancelAllEvents() |
| 116 { | 120 { |
| 117 m_timer.stop(); | 121 m_timer.stop(); |
| 118 | 122 |
| 119 for (size_t i = 0; i < m_pendingEvents.size(); ++i) { | 123 for (size_t i = 0; i < m_pendingEvents.size(); ++i) { |
| 120 Event* event = m_pendingEvents[i].get(); | 124 Event* event = m_pendingEvents[i].get(); |
| 125 EventTarget* target = event->target() ? event->target() : m_owner.get(); | |
|
yurys
2014/06/19 13:26:45
Inline this like in other places?
aandrey
2014/06/19 14:16:20
Done.
| |
| 121 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled"); | 126 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event, "type", event->type().ascii(), "status", "cancelled"); |
| 127 InspectorInstrumentation::didRemoveEvent(target, event); | |
| 122 } | 128 } |
| 123 m_pendingEvents.clear(); | 129 m_pendingEvents.clear(); |
| 124 } | 130 } |
| 125 | 131 |
| 126 bool GenericEventQueue::hasPendingEvents() const | 132 bool GenericEventQueue::hasPendingEvents() const |
| 127 { | 133 { |
| 128 return m_pendingEvents.size(); | 134 return m_pendingEvents.size(); |
| 129 } | 135 } |
| 130 | 136 |
| 131 } | 137 } |
| OLD | NEW |