| 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 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 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "EventQueue.h" | 28 #include "EventQueue.h" |
| 29 | 29 |
| 30 #include "DOMWindow.h" | 30 #include "DOMWindow.h" |
| 31 #include "Document.h" | |
| 32 #include "Event.h" | 31 #include "Event.h" |
| 33 #include "EventNames.h" | 32 #include "EventNames.h" |
| 33 #include "ScriptExecutionContext.h" |
| 34 #include "SuspendableTimer.h" |
| 34 | 35 |
| 35 namespace WebCore { | 36 namespace WebCore { |
| 36 | 37 |
| 37 EventQueue::EventQueue() | 38 class EventQueueTimer : public SuspendableTimer { |
| 38 : m_pendingEventTimer(this, &EventQueue::pendingEventTimerFired) | 39 WTF_MAKE_NONCOPYABLE(EventQueueTimer); |
| 40 public: |
| 41 EventQueueTimer(EventQueue* eventQueue, ScriptExecutionContext* context) |
| 42 : SuspendableTimer(context) |
| 43 , m_eventQueue(eventQueue) { } |
| 44 |
| 45 private: |
| 46 virtual void fired() { m_eventQueue->pendingEventTimerFired(); } |
| 47 EventQueue* m_eventQueue; |
| 48 }; |
| 49 |
| 50 EventQueue::EventQueue(ScriptExecutionContext* context) |
| 51 : m_pendingEventTimer(adoptPtr(new EventQueueTimer(this, context))) |
| 52 { |
| 53 } |
| 54 |
| 55 EventQueue::~EventQueue() |
| 39 { | 56 { |
| 40 } | 57 } |
| 41 | 58 |
| 42 void EventQueue::enqueueEvent(PassRefPtr<Event> event) | 59 void EventQueue::enqueueEvent(PassRefPtr<Event> event) |
| 43 { | 60 { |
| 44 ASSERT(event->target()->toNode() || event->target()->toDOMWindow()); | 61 ASSERT(event->target()->toNode() || event->target()->toDOMWindow()); |
| 45 m_queuedEvents.append(event); | 62 m_queuedEvents.append(event); |
| 46 | 63 |
| 47 if (!m_pendingEventTimer.isActive()) | 64 if (!m_pendingEventTimer->isActive()) |
| 48 m_pendingEventTimer.startOneShot(0); | 65 m_pendingEventTimer->startOneShot(0); |
| 49 } | 66 } |
| 50 | 67 |
| 51 void EventQueue::enqueueScrollEvent(PassRefPtr<Node> target, ScrollEventTargetTy
pe targetType) | 68 void EventQueue::enqueueScrollEvent(PassRefPtr<Node> target, ScrollEventTargetTy
pe targetType) |
| 52 { | 69 { |
| 53 if (!m_nodesWithQueuedScrollEvents.add(target.get()).second) | 70 if (!m_nodesWithQueuedScrollEvents.add(target.get()).second) |
| 54 return; | 71 return; |
| 55 | 72 |
| 56 // Per the W3C CSSOM View Module, scroll events fired at the document should
bubble, others should not. | 73 // Per the W3C CSSOM View Module, scroll events fired at the document should
bubble, others should not. |
| 57 bool canBubble = targetType == ScrollEventDocumentTarget; | 74 bool canBubble = targetType == ScrollEventDocumentTarget; |
| 58 RefPtr<Event> scrollEvent = Event::create(eventNames().scrollEvent, canBubbl
e, false /* non cancelleable */); | 75 RefPtr<Event> scrollEvent = Event::create(eventNames().scrollEvent, canBubbl
e, false /* non cancelleable */); |
| 59 scrollEvent->setTarget(target); | 76 scrollEvent->setTarget(target); |
| 60 enqueueEvent(scrollEvent.release()); | 77 enqueueEvent(scrollEvent.release()); |
| 61 } | 78 } |
| 62 | 79 |
| 63 void EventQueue::pendingEventTimerFired(Timer<EventQueue>*) | 80 void EventQueue::pendingEventTimerFired() |
| 64 { | 81 { |
| 65 ASSERT(!m_pendingEventTimer.isActive()); | 82 ASSERT(!m_pendingEventTimer->isActive()); |
| 66 | 83 |
| 67 Vector<RefPtr<Event> > queuedEvents; | 84 Vector<RefPtr<Event> > queuedEvents; |
| 68 queuedEvents.swap(m_queuedEvents); | 85 queuedEvents.swap(m_queuedEvents); |
| 69 | 86 |
| 70 m_nodesWithQueuedScrollEvents.clear(); | 87 m_nodesWithQueuedScrollEvents.clear(); |
| 71 | 88 |
| 72 for (size_t i = 0; i < queuedEvents.size(); i++) | 89 for (size_t i = 0; i < queuedEvents.size(); i++) |
| 73 dispatchEvent(queuedEvents[i].release()); | 90 dispatchEvent(queuedEvents[i].release()); |
| 74 } | 91 } |
| 75 | 92 |
| 76 void EventQueue::dispatchEvent(PassRefPtr<Event> event) | 93 void EventQueue::dispatchEvent(PassRefPtr<Event> event) |
| 77 { | 94 { |
| 78 EventTarget* eventTarget = event->target(); | 95 EventTarget* eventTarget = event->target(); |
| 79 if (eventTarget->toNode()) | 96 if (eventTarget->toNode()) |
| 80 eventTarget->dispatchEvent(event); | 97 eventTarget->dispatchEvent(event); |
| 81 else if (eventTarget->toDOMWindow()) | 98 else if (eventTarget->toDOMWindow()) |
| 82 eventTarget->toDOMWindow()->dispatchEvent(event, 0); | 99 eventTarget->toDOMWindow()->dispatchEvent(event, 0); |
| 83 else | 100 else |
| 84 ASSERT_NOT_REACHED(); | 101 ASSERT_NOT_REACHED(); |
| 85 } | 102 } |
| 86 | 103 |
| 87 } | 104 } |
| OLD | NEW |