| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 bool GenericEventQueue::enqueueEvent(Event* event) | 57 bool GenericEventQueue::enqueueEvent(Event* event) |
| 58 { | 58 { |
| 59 if (m_isClosed) | 59 if (m_isClosed) |
| 60 return false; | 60 return false; |
| 61 | 61 |
| 62 if (event->target() == m_owner) | 62 if (event->target() == m_owner) |
| 63 event->setTarget(nullptr); | 63 event->setTarget(nullptr); |
| 64 | 64 |
| 65 TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event, "
type", event->type().ascii()); | 65 TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event, "
type", event->type().ascii()); |
| 66 InspectorInstrumentation::didEnqueueEvent(event->target() ? event->target()
: m_owner.get(), event); | 66 EventTarget* target = event->target() ? event->target() : m_owner.get(); |
| 67 InspectorInstrumentation::asyncTaskScheduled(target->getExecutionContext(),
event->type(), event); |
| 67 m_pendingEvents.append(event); | 68 m_pendingEvents.append(event); |
| 68 | 69 |
| 69 if (!m_timer.isActive()) | 70 if (!m_timer.isActive()) |
| 70 m_timer.startOneShot(0, BLINK_FROM_HERE); | 71 m_timer.startOneShot(0, BLINK_FROM_HERE); |
| 71 | 72 |
| 72 return true; | 73 return true; |
| 73 } | 74 } |
| 74 | 75 |
| 75 bool GenericEventQueue::cancelEvent(Event* event) | 76 bool GenericEventQueue::cancelEvent(Event* event) |
| 76 { | 77 { |
| 77 bool found = m_pendingEvents.contains(event); | 78 bool found = m_pendingEvents.contains(event); |
| 78 | 79 |
| 79 if (found) { | 80 if (found) { |
| 80 InspectorInstrumentation::didRemoveEvent(event->target() ? event->target
() : m_owner.get(), event); | 81 EventTarget* target = event->target() ? event->target() : m_owner.get(); |
| 82 InspectorInstrumentation::asyncTaskCanceled(target->getExecutionContext(
), event); |
| 81 m_pendingEvents.remove(m_pendingEvents.find(event)); | 83 m_pendingEvents.remove(m_pendingEvents.find(event)); |
| 82 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"); |
| 83 } | 85 } |
| 84 | 86 |
| 85 if (m_pendingEvents.isEmpty()) | 87 if (m_pendingEvents.isEmpty()) |
| 86 m_timer.stop(); | 88 m_timer.stop(); |
| 87 | 89 |
| 88 return found; | 90 return found; |
| 89 } | 91 } |
| 90 | 92 |
| 91 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*) | 93 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*) |
| 92 { | 94 { |
| 93 ASSERT(!m_timer.isActive()); | 95 ASSERT(!m_timer.isActive()); |
| 94 ASSERT(!m_pendingEvents.isEmpty()); | 96 ASSERT(!m_pendingEvents.isEmpty()); |
| 95 | 97 |
| 96 HeapVector<Member<Event>> pendingEvents; | 98 HeapVector<Member<Event>> pendingEvents; |
| 97 m_pendingEvents.swap(pendingEvents); | 99 m_pendingEvents.swap(pendingEvents); |
| 98 | 100 |
| 99 for (const auto& pendingEvent : pendingEvents) { | 101 for (const auto& pendingEvent : pendingEvents) { |
| 100 Event* event = pendingEvent.get(); | 102 Event* event = pendingEvent.get(); |
| 101 EventTarget* target = event->target() ? event->target() : m_owner.get(); | 103 EventTarget* target = event->target() ? event->target() : m_owner.get(); |
| 102 CString type(event->type().ascii()); | 104 CString type(event->type().ascii()); |
| 105 InspectorInstrumentation::AsyncTask asyncTask(target->getExecutionContex
t(), event); |
| 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(pendingEvent); | 107 target->dispatchEvent(pendingEvent); |
| 105 TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event,
"type", type); | 108 TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event,
"type", type); |
| 106 InspectorInstrumentation::didRemoveEvent(target, event); | |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 | 111 |
| 110 void GenericEventQueue::close() | 112 void GenericEventQueue::close() |
| 111 { | 113 { |
| 112 m_isClosed = true; | 114 m_isClosed = true; |
| 113 cancelAllEvents(); | 115 cancelAllEvents(); |
| 114 } | 116 } |
| 115 | 117 |
| 116 void GenericEventQueue::cancelAllEvents() | 118 void GenericEventQueue::cancelAllEvents() |
| 117 { | 119 { |
| 118 m_timer.stop(); | 120 m_timer.stop(); |
| 119 | 121 |
| 120 for (const auto& pendingEvent : m_pendingEvents) { | 122 for (const auto& pendingEvent : m_pendingEvents) { |
| 121 Event* event = pendingEvent.get(); | 123 Event* event = pendingEvent.get(); |
| 122 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event,
"type", event->type().ascii(), "status", "cancelled"); | 124 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event,
"type", event->type().ascii(), "status", "cancelled"); |
| 123 InspectorInstrumentation::didRemoveEvent(event->target() ? event->target
() : m_owner.get(), event); | 125 EventTarget* target = event->target() ? event->target() : m_owner.get(); |
| 126 InspectorInstrumentation::asyncTaskCanceled(target->getExecutionContext(
), event); |
| 124 } | 127 } |
| 125 m_pendingEvents.clear(); | 128 m_pendingEvents.clear(); |
| 126 } | 129 } |
| 127 | 130 |
| 128 bool GenericEventQueue::hasPendingEvents() const | 131 bool GenericEventQueue::hasPendingEvents() const |
| 129 { | 132 { |
| 130 return m_pendingEvents.size(); | 133 return m_pendingEvents.size(); |
| 131 } | 134 } |
| 132 | 135 |
| 133 } // namespace blink | 136 } // namespace blink |
| OLD | NEW |