| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2010 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 #endif | 82 #endif |
| 83 EventQueue::trace(visitor); | 83 EventQueue::trace(visitor); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool DOMWindowEventQueue::enqueueEvent(Event* event) | 86 bool DOMWindowEventQueue::enqueueEvent(Event* event) |
| 87 { | 87 { |
| 88 if (m_isClosed) | 88 if (m_isClosed) |
| 89 return false; | 89 return false; |
| 90 | 90 |
| 91 ASSERT(event->target()); | 91 ASSERT(event->target()); |
| 92 InspectorInstrumentation::didEnqueueEvent(event->target(), event); | 92 InspectorInstrumentation::scheduleAsyncTask(event->target()->getExecutionCon
text(), "Event", event); |
| 93 | 93 |
| 94 bool wasAdded = m_queuedEvents.add(event).isNewEntry; | 94 bool wasAdded = m_queuedEvents.add(event).isNewEntry; |
| 95 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. | 95 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. |
| 96 | 96 |
| 97 if (!m_pendingEventTimer->isActive()) | 97 if (!m_pendingEventTimer->isActive()) |
| 98 m_pendingEventTimer->startOneShot(0, BLINK_FROM_HERE); | 98 m_pendingEventTimer->startOneShot(0, BLINK_FROM_HERE); |
| 99 | 99 |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool DOMWindowEventQueue::cancelEvent(Event* event) | 103 bool DOMWindowEventQueue::cancelEvent(Event* event) |
| 104 { | 104 { |
| 105 HeapListHashSet<Member<Event>, 16>::iterator it = m_queuedEvents.find(event)
; | 105 HeapListHashSet<Member<Event>, 16>::iterator it = m_queuedEvents.find(event)
; |
| 106 bool found = it != m_queuedEvents.end(); | 106 bool found = it != m_queuedEvents.end(); |
| 107 if (found) { | 107 if (found) { |
| 108 InspectorInstrumentation::didRemoveEvent(event->target(), event); | 108 InspectorInstrumentation::cancelAsyncTask(event->target()->getExecutionC
ontext(), event); |
| 109 m_queuedEvents.remove(it); | 109 m_queuedEvents.remove(it); |
| 110 } | 110 } |
| 111 if (m_queuedEvents.isEmpty()) | 111 if (m_queuedEvents.isEmpty()) |
| 112 m_pendingEventTimer->stop(); | 112 m_pendingEventTimer->stop(); |
| 113 return found; | 113 return found; |
| 114 } | 114 } |
| 115 | 115 |
| 116 void DOMWindowEventQueue::close() | 116 void DOMWindowEventQueue::close() |
| 117 { | 117 { |
| 118 m_isClosed = true; | 118 m_isClosed = true; |
| 119 m_pendingEventTimer->stop(); | 119 m_pendingEventTimer->stop(); |
| 120 if (InspectorInstrumentation::hasFrontends()) { | 120 if (InspectorInstrumentation::hasFrontends()) { |
| 121 for (const auto& queuedEvent : m_queuedEvents) { | 121 for (const auto& queuedEvent : m_queuedEvents) { |
| 122 Event* event = queuedEvent; | 122 if (queuedEvent) |
| 123 if (event) | 123 InspectorInstrumentation::cancelAsyncTask(queuedEvent->target()-
>getExecutionContext(), queuedEvent); |
| 124 InspectorInstrumentation::didRemoveEvent(event->target(), event)
; | |
| 125 } | 124 } |
| 126 } | 125 } |
| 127 m_queuedEvents.clear(); | 126 m_queuedEvents.clear(); |
| 128 } | 127 } |
| 129 | 128 |
| 130 void DOMWindowEventQueue::pendingEventTimerFired() | 129 void DOMWindowEventQueue::pendingEventTimerFired() |
| 131 { | 130 { |
| 132 ASSERT(!m_pendingEventTimer->isActive()); | 131 ASSERT(!m_pendingEventTimer->isActive()); |
| 133 ASSERT(!m_queuedEvents.isEmpty()); | 132 ASSERT(!m_queuedEvents.isEmpty()); |
| 134 | 133 |
| 135 // Insert a marker for where we should stop. | 134 // Insert a marker for where we should stop. |
| 136 ASSERT(!m_queuedEvents.contains(nullptr)); | 135 ASSERT(!m_queuedEvents.contains(nullptr)); |
| 137 bool wasAdded = m_queuedEvents.add(nullptr).isNewEntry; | 136 bool wasAdded = m_queuedEvents.add(nullptr).isNewEntry; |
| 138 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. | 137 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. |
| 139 | 138 |
| 140 while (!m_queuedEvents.isEmpty()) { | 139 while (!m_queuedEvents.isEmpty()) { |
| 141 HeapListHashSet<Member<Event>, 16>::iterator iter = m_queuedEvents.begin
(); | 140 HeapListHashSet<Member<Event>, 16>::iterator iter = m_queuedEvents.begin
(); |
| 142 Event* event = *iter; | 141 Event* event = *iter; |
| 143 m_queuedEvents.remove(iter); | 142 m_queuedEvents.remove(iter); |
| 144 if (!event) | 143 if (!event) |
| 145 break; | 144 break; |
| 146 dispatchEvent(event); | 145 dispatchEvent(event); |
| 147 InspectorInstrumentation::didRemoveEvent(event->target(), event); | |
| 148 } | 146 } |
| 149 } | 147 } |
| 150 | 148 |
| 151 void DOMWindowEventQueue::dispatchEvent(Event* event) | 149 void DOMWindowEventQueue::dispatchEvent(Event* event) |
| 152 { | 150 { |
| 153 EventTarget* eventTarget = event->target(); | 151 EventTarget* eventTarget = event->target(); |
| 152 InspectorInstrumentation::AsyncTask asyncTask(eventTarget->getExecutionConte
xt(), event); |
| 154 if (eventTarget->toDOMWindow()) | 153 if (eventTarget->toDOMWindow()) |
| 155 eventTarget->toDOMWindow()->dispatchEvent(event, nullptr); | 154 eventTarget->toDOMWindow()->dispatchEvent(event, nullptr); |
| 156 else | 155 else |
| 157 eventTarget->dispatchEvent(event); | 156 eventTarget->dispatchEvent(event); |
| 158 } | 157 } |
| 159 | 158 |
| 160 } // namespace blink | 159 } // namespace blink |
| OLD | NEW |