| 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 | 57 |
| 58 bool GenericEventQueue::enqueueEvent(PassRefPtr<Event> event) | 58 bool GenericEventQueue::enqueueEvent(PassRefPtr<Event> event) |
| 59 { | 59 { |
| 60 if (m_isClosed) | 60 if (m_isClosed) |
| 61 return false; | 61 return false; |
| 62 | 62 |
| 63 if (event->target() == m_owner) | 63 if (event->target() == m_owner) |
| 64 event->setTarget(nullptr); | 64 event->setTarget(nullptr); |
| 65 | 65 |
| 66 TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event.ge
t(), "type", event->type().ascii()); | 66 TRACE_EVENT_ASYNC_BEGIN1("event", "GenericEventQueue:enqueueEvent", event.ge
t(), "type", event->type().ascii().data()); |
| 67 m_pendingEvents.append(event); | 67 m_pendingEvents.append(event); |
| 68 | 68 |
| 69 if (!m_timer.isActive()) | 69 if (!m_timer.isActive()) |
| 70 m_timer.startOneShot(0, FROM_HERE); | 70 m_timer.startOneShot(0, FROM_HERE); |
| 71 | 71 |
| 72 return true; | 72 return true; |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool GenericEventQueue::cancelEvent(Event* event) | 75 bool GenericEventQueue::cancelEvent(Event* event) |
| 76 { | 76 { |
| 77 bool found = m_pendingEvents.contains(event); | 77 bool found = m_pendingEvents.contains(event); |
| 78 | 78 |
| 79 if (found) { | 79 if (found) { |
| 80 m_pendingEvents.remove(m_pendingEvents.find(event)); | 80 m_pendingEvents.remove(m_pendingEvents.find(event)); |
| 81 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event,
"type", event->type().ascii(), "status", "cancelled"); | 81 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event,
"type", event->type().ascii().data(), "status", "cancelled"); |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (m_pendingEvents.isEmpty()) | 84 if (m_pendingEvents.isEmpty()) |
| 85 m_timer.stop(); | 85 m_timer.stop(); |
| 86 | 86 |
| 87 return found; | 87 return found; |
| 88 } | 88 } |
| 89 | 89 |
| 90 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*) | 90 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*) |
| 91 { | 91 { |
| 92 ASSERT(!m_timer.isActive()); | 92 ASSERT(!m_timer.isActive()); |
| 93 ASSERT(!m_pendingEvents.isEmpty()); | 93 ASSERT(!m_pendingEvents.isEmpty()); |
| 94 | 94 |
| 95 Vector<RefPtr<Event> > pendingEvents; | 95 Vector<RefPtr<Event> > pendingEvents; |
| 96 m_pendingEvents.swap(pendingEvents); | 96 m_pendingEvents.swap(pendingEvents); |
| 97 | 97 |
| 98 RefPtr<EventTarget> protect(m_owner.get()); | 98 RefPtr<EventTarget> protect(m_owner.get()); |
| 99 for (size_t i = 0; i < pendingEvents.size(); ++i) { | 99 for (size_t i = 0; i < pendingEvents.size(); ++i) { |
| 100 Event* event = pendingEvents[i].get(); | 100 Event* event = pendingEvents[i].get(); |
| 101 EventTarget* target = event->target() ? event->target() : m_owner.get(); | 101 EventTarget* target = event->target() ? event->target() : m_owner.get(); |
| 102 CString type(event->type().ascii()); | 102 CString type(event->type().ascii()); |
| 103 TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent",
event, "dispatch", "type", type); | 103 TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent",
event, "dispatch", "type", type.data()); |
| 104 target->dispatchEvent(pendingEvents[i]); | 104 target->dispatchEvent(pendingEvents[i]); |
| 105 TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event,
"type", type); | 105 TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event,
"type", type.data()); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 void GenericEventQueue::close() | 109 void GenericEventQueue::close() |
| 110 { | 110 { |
| 111 m_isClosed = true; | 111 m_isClosed = true; |
| 112 cancelAllEvents(); | 112 cancelAllEvents(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void GenericEventQueue::cancelAllEvents() | 115 void GenericEventQueue::cancelAllEvents() |
| 116 { | 116 { |
| 117 m_timer.stop(); | 117 m_timer.stop(); |
| 118 | 118 |
| 119 for (size_t i = 0; i < m_pendingEvents.size(); ++i) { | 119 for (size_t i = 0; i < m_pendingEvents.size(); ++i) { |
| 120 Event* event = m_pendingEvents[i].get(); | 120 Event* event = m_pendingEvents[i].get(); |
| 121 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event,
"type", event->type().ascii(), "status", "cancelled"); | 121 TRACE_EVENT_ASYNC_END2("event", "GenericEventQueue:enqueueEvent", event,
"type", event->type().ascii().data(), "status", "cancelled"); |
| 122 } | 122 } |
| 123 m_pendingEvents.clear(); | 123 m_pendingEvents.clear(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 bool GenericEventQueue::hasPendingEvents() const | 126 bool GenericEventQueue::hasPendingEvents() const |
| 127 { | 127 { |
| 128 return m_pendingEvents.size(); | 128 return m_pendingEvents.size(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 } | 131 } |
| OLD | NEW |