Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: Source/WebCore/dom/GenericEventQueue.cpp

Issue 9968049: Merge 112623 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1025/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/WebCore/dom/GenericEventQueue.h ('k') | Source/WebCore/html/HTMLMediaElement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 27
28 #include "GenericEventQueue.h" 28 #include "GenericEventQueue.h"
29 29
30 #include "Event.h" 30 #include "Event.h"
31 31
32 namespace WebCore { 32 namespace WebCore {
33 33
34 GenericEventQueue::GenericEventQueue() 34 PassOwnPtr<GenericEventQueue> GenericEventQueue::create(EventTarget* owner)
35 : m_timer(this, &GenericEventQueue::timerFired) 35 {
36 return adoptPtr(new GenericEventQueue(owner));
37 }
38
39 GenericEventQueue::GenericEventQueue(EventTarget* owner)
40 : m_owner(owner)
41 , m_timer(this, &GenericEventQueue::timerFired)
36 , m_isClosed(false) 42 , m_isClosed(false)
37 { 43 {
38 } 44 }
39 45
40 GenericEventQueue::~GenericEventQueue() 46 GenericEventQueue::~GenericEventQueue()
41 { 47 {
42 } 48 }
43 49
44 bool GenericEventQueue::enqueueEvent(PassRefPtr<Event> event) 50 bool GenericEventQueue::enqueueEvent(PassRefPtr<Event> event)
45 { 51 {
46 if (m_isClosed) 52 if (m_isClosed)
47 return false; 53 return false;
48 54
49 ASSERT(event->target()); 55 ASSERT(event->target());
56 if (event->target() == m_owner)
57 event->setTarget(0);
58
50 m_pendingEvents.append(event); 59 m_pendingEvents.append(event);
51 60
52 if (!m_timer.isActive()) 61 if (!m_timer.isActive())
53 m_timer.startOneShot(0); 62 m_timer.startOneShot(0);
54 63
55 return true; 64 return true;
56 } 65 }
57 66
58 bool GenericEventQueue::cancelEvent(Event* event) 67 bool GenericEventQueue::cancelEvent(Event* event)
59 { 68 {
60 bool found = m_pendingEvents.contains(event); 69 bool found = m_pendingEvents.contains(event);
61 70
62 if (found) 71 if (found)
63 m_pendingEvents.remove(m_pendingEvents.find(event)); 72 m_pendingEvents.remove(m_pendingEvents.find(event));
64 73
65 if (m_pendingEvents.isEmpty()) 74 if (m_pendingEvents.isEmpty())
66 m_timer.stop(); 75 m_timer.stop();
67 76
68 return found; 77 return found;
69 } 78 }
70 79
71 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*) 80 void GenericEventQueue::timerFired(Timer<GenericEventQueue>*)
72 { 81 {
73 ASSERT(!m_timer.isActive()); 82 ASSERT(!m_timer.isActive());
74 ASSERT(!m_pendingEvents.isEmpty()); 83 ASSERT(!m_pendingEvents.isEmpty());
75 84
76 Vector<RefPtr<Event> > pendingEvents; 85 Vector<RefPtr<Event> > pendingEvents;
77 m_pendingEvents.swap(pendingEvents); 86 m_pendingEvents.swap(pendingEvents);
78 87
79 for (unsigned i = 0; i < pendingEvents.size(); ++i) 88 for (unsigned i = 0; i < pendingEvents.size(); ++i) {
80 pendingEvents[i]->target()->dispatchEvent(pendingEvents[i].release()); 89 EventTarget* target = pendingEvents[i]->target() ? pendingEvents[i]->tar get() : m_owner;
90 target->dispatchEvent(pendingEvents[i].release());
91 }
81 } 92 }
82 93
83 void GenericEventQueue::close() 94 void GenericEventQueue::close()
84 { 95 {
85 m_isClosed = true; 96 m_isClosed = true;
86 97
87 m_timer.stop(); 98 m_timer.stop();
88 m_pendingEvents.clear(); 99 m_pendingEvents.clear();
89 } 100 }
90 101
91 void GenericEventQueue::cancelAllEvents() 102 void GenericEventQueue::cancelAllEvents()
92 { 103 {
93 m_timer.stop(); 104 m_timer.stop();
94 m_pendingEvents.clear(); 105 m_pendingEvents.clear();
95 } 106 }
96 107
97 bool GenericEventQueue::hasPendingEvents() const 108 bool GenericEventQueue::hasPendingEvents() const
98 { 109 {
99 return m_pendingEvents.size(); 110 return m_pendingEvents.size();
100 } 111 }
101 112
102 } 113 }
OLDNEW
« no previous file with comments | « Source/WebCore/dom/GenericEventQueue.h ('k') | Source/WebCore/html/HTMLMediaElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698