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 16 matching lines...) Expand all Loading... |
27 #include "config.h" | 27 #include "config.h" |
28 #include "core/events/DOMWindowEventQueue.h" | 28 #include "core/events/DOMWindowEventQueue.h" |
29 | 29 |
30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.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/SuspendableTimer.h" | 33 #include "core/frame/SuspendableTimer.h" |
34 | 34 |
35 namespace WebCore { | 35 namespace WebCore { |
36 | 36 |
37 class DOMWindowEventQueueTimer : public SuspendableTimer { | 37 class DOMWindowEventQueueTimer : public NoBaseWillBeGarbageCollectedFinalized<DO
MWindowEventQueueTimer>, public SuspendableTimer { |
38 WTF_MAKE_NONCOPYABLE(DOMWindowEventQueueTimer); | 38 WTF_MAKE_NONCOPYABLE(DOMWindowEventQueueTimer); |
39 public: | 39 public: |
40 DOMWindowEventQueueTimer(DOMWindowEventQueue* eventQueue, ExecutionContext*
context) | 40 DOMWindowEventQueueTimer(DOMWindowEventQueue* eventQueue, ExecutionContext*
context) |
41 : SuspendableTimer(context) | 41 : SuspendableTimer(context) |
42 , m_eventQueue(eventQueue) { } | 42 , m_eventQueue(eventQueue) { } |
| 43 void trace(Visitor* visitor) { visitor->trace(m_eventQueue); } |
43 | 44 |
44 private: | 45 private: |
45 virtual void fired() { m_eventQueue->pendingEventTimerFired(); } | 46 virtual void fired() { m_eventQueue->pendingEventTimerFired(); } |
46 DOMWindowEventQueue* m_eventQueue; | 47 |
| 48 RawPtrWillBeMember<DOMWindowEventQueue> m_eventQueue; |
47 }; | 49 }; |
48 | 50 |
49 PassRefPtr<DOMWindowEventQueue> DOMWindowEventQueue::create(ExecutionContext* co
ntext) | 51 PassRefPtrWillBeRawPtr<DOMWindowEventQueue> DOMWindowEventQueue::create(Executio
nContext* context) |
50 { | 52 { |
51 return adoptRef(new DOMWindowEventQueue(context)); | 53 return adoptRefWillBeNoop(new DOMWindowEventQueue(context)); |
52 } | 54 } |
53 | 55 |
54 DOMWindowEventQueue::DOMWindowEventQueue(ExecutionContext* context) | 56 DOMWindowEventQueue::DOMWindowEventQueue(ExecutionContext* context) |
55 : m_pendingEventTimer(adoptPtr(new DOMWindowEventQueueTimer(this, context))) | 57 : m_pendingEventTimer(adoptPtrWillBeNoop(new DOMWindowEventQueueTimer(this,
context))) |
56 , m_isClosed(false) | 58 , m_isClosed(false) |
57 { | 59 { |
58 m_pendingEventTimer->suspendIfNeeded(); | 60 m_pendingEventTimer->suspendIfNeeded(); |
59 } | 61 } |
60 | 62 |
61 DOMWindowEventQueue::~DOMWindowEventQueue() | 63 DOMWindowEventQueue::~DOMWindowEventQueue() |
62 { | 64 { |
63 } | 65 } |
64 | 66 |
| 67 void DOMWindowEventQueue::trace(Visitor* visitor) |
| 68 { |
| 69 visitor->trace(m_pendingEventTimer); |
| 70 visitor->trace(m_queuedEvents); |
| 71 EventQueue::trace(visitor); |
| 72 } |
| 73 |
65 bool DOMWindowEventQueue::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event) | 74 bool DOMWindowEventQueue::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event) |
66 { | 75 { |
67 if (m_isClosed) | 76 if (m_isClosed) |
68 return false; | 77 return false; |
69 | 78 |
70 ASSERT(event->target()); | 79 ASSERT(event->target()); |
71 bool wasAdded = m_queuedEvents.add(event).isNewEntry; | 80 bool wasAdded = m_queuedEvents.add(event).isNewEntry; |
72 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. | 81 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. |
73 | 82 |
74 if (!m_pendingEventTimer->isActive()) | 83 if (!m_pendingEventTimer->isActive()) |
75 m_pendingEventTimer->startOneShot(0, FROM_HERE); | 84 m_pendingEventTimer->startOneShot(0, FROM_HERE); |
76 | 85 |
77 return true; | 86 return true; |
78 } | 87 } |
79 | 88 |
80 bool DOMWindowEventQueue::cancelEvent(Event* event) | 89 bool DOMWindowEventQueue::cancelEvent(Event* event) |
81 { | 90 { |
82 ListHashSet<RefPtrWillBePersistent<Event>, 16>::iterator it = m_queuedEvents
.find(event); | 91 WillBeHeapListHashSet<RefPtrWillBeMember<Event>, 16>::iterator it = m_queued
Events.find(event); |
83 bool found = it != m_queuedEvents.end(); | 92 bool found = it != m_queuedEvents.end(); |
84 if (found) | 93 if (found) |
85 m_queuedEvents.remove(it); | 94 m_queuedEvents.remove(it); |
86 if (m_queuedEvents.isEmpty()) | 95 if (m_queuedEvents.isEmpty()) |
87 m_pendingEventTimer->stop(); | 96 m_pendingEventTimer->stop(); |
88 return found; | 97 return found; |
89 } | 98 } |
90 | 99 |
91 void DOMWindowEventQueue::close() | 100 void DOMWindowEventQueue::close() |
92 { | 101 { |
93 m_isClosed = true; | 102 m_isClosed = true; |
94 m_pendingEventTimer->stop(); | 103 m_pendingEventTimer->stop(); |
95 m_queuedEvents.clear(); | 104 m_queuedEvents.clear(); |
96 } | 105 } |
97 | 106 |
98 void DOMWindowEventQueue::pendingEventTimerFired() | 107 void DOMWindowEventQueue::pendingEventTimerFired() |
99 { | 108 { |
100 ASSERT(!m_pendingEventTimer->isActive()); | 109 ASSERT(!m_pendingEventTimer->isActive()); |
101 ASSERT(!m_queuedEvents.isEmpty()); | 110 ASSERT(!m_queuedEvents.isEmpty()); |
102 | 111 |
103 // Insert a marker for where we should stop. | 112 // Insert a marker for where we should stop. |
104 ASSERT(!m_queuedEvents.contains(nullptr)); | 113 ASSERT(!m_queuedEvents.contains(nullptr)); |
105 bool wasAdded = m_queuedEvents.add(nullptr).isNewEntry; | 114 bool wasAdded = m_queuedEvents.add(nullptr).isNewEntry; |
106 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. | 115 ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the
list. |
107 | 116 |
108 RefPtr<DOMWindowEventQueue> protector(this); | 117 RefPtrWillBeRawPtr<DOMWindowEventQueue> protector(this); |
109 | 118 |
110 while (!m_queuedEvents.isEmpty()) { | 119 while (!m_queuedEvents.isEmpty()) { |
111 ListHashSet<RefPtrWillBePersistent<Event>, 16>::iterator iter = m_queued
Events.begin(); | 120 WillBeHeapListHashSet<RefPtrWillBeMember<Event>, 16>::iterator iter = m_
queuedEvents.begin(); |
112 RefPtrWillBeRawPtr<Event> event = *iter; | 121 RefPtrWillBeRawPtr<Event> event = *iter; |
113 m_queuedEvents.remove(iter); | 122 m_queuedEvents.remove(iter); |
114 if (!event) | 123 if (!event) |
115 break; | 124 break; |
116 dispatchEvent(event.get()); | 125 dispatchEvent(event.get()); |
117 } | 126 } |
118 } | 127 } |
119 | 128 |
120 void DOMWindowEventQueue::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event) | 129 void DOMWindowEventQueue::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event) |
121 { | 130 { |
122 EventTarget* eventTarget = event->target(); | 131 EventTarget* eventTarget = event->target(); |
123 if (eventTarget->toDOMWindow()) | 132 if (eventTarget->toDOMWindow()) |
124 eventTarget->toDOMWindow()->dispatchEvent(event, nullptr); | 133 eventTarget->toDOMWindow()->dispatchEvent(event, nullptr); |
125 else | 134 else |
126 eventTarget->dispatchEvent(event); | 135 eventTarget->dispatchEvent(event); |
127 } | 136 } |
128 | 137 |
129 } | 138 } |
OLD | NEW |