OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 { | 47 { |
48 return m_dispatchSoonList.find(sender) != kNotFound || m_dispatchingList
.find(sender) != kNotFound; | 48 return m_dispatchSoonList.find(sender) != kNotFound || m_dispatchingList
.find(sender) != kNotFound; |
49 } | 49 } |
50 #endif | 50 #endif |
51 | 51 |
52 private: | 52 private: |
53 void timerFired(Timer<EventSender<T> >*) { dispatchPendingEvents(); } | 53 void timerFired(Timer<EventSender<T> >*) { dispatchPendingEvents(); } |
54 | 54 |
55 AtomicString m_eventType; | 55 AtomicString m_eventType; |
56 Timer<EventSender<T> > m_timer; | 56 Timer<EventSender<T> > m_timer; |
57 Vector<T*> m_dispatchSoonList; | 57 WillBePersistentHeapVector<RawPtrWillBeMember<T> > m_dispatchSoonList; |
58 Vector<T*> m_dispatchingList; | 58 WillBePersistentHeapVector<RawPtrWillBeMember<T> > m_dispatchingList; |
59 }; | 59 }; |
60 | 60 |
61 template<typename T> EventSender<T>::EventSender(const AtomicString& eventType) | 61 template<typename T> EventSender<T>::EventSender(const AtomicString& eventType) |
62 : m_eventType(eventType) | 62 : m_eventType(eventType) |
63 , m_timer(this, &EventSender::timerFired) | 63 , m_timer(this, &EventSender::timerFired) |
64 { | 64 { |
65 } | 65 } |
66 | 66 |
67 template<typename T> void EventSender<T>::dispatchEventSoon(T* sender) | 67 template<typename T> void EventSender<T>::dispatchEventSoon(T* sender) |
68 { | 68 { |
69 m_dispatchSoonList.append(sender); | 69 m_dispatchSoonList.append(sender); |
70 if (!m_timer.isActive()) | 70 if (!m_timer.isActive()) |
71 m_timer.startOneShot(0, FROM_HERE); | 71 m_timer.startOneShot(0, FROM_HERE); |
72 } | 72 } |
73 | 73 |
74 template<typename T> void EventSender<T>::cancelEvent(T* sender) | 74 template<typename T> void EventSender<T>::cancelEvent(T* sender) |
75 { | 75 { |
76 // Remove instances of this sender from both lists. | 76 // Remove instances of this sender from both lists. |
77 // Use loops because we allow multiple instances to get into the lists. | 77 // Use loops because we allow multiple instances to get into the lists. |
78 size_t size = m_dispatchSoonList.size(); | 78 size_t size = m_dispatchSoonList.size(); |
79 for (size_t i = 0; i < size; ++i) { | 79 for (size_t i = 0; i < size; ++i) { |
80 if (m_dispatchSoonList[i] == sender) | 80 if (m_dispatchSoonList[i] == sender) |
81 m_dispatchSoonList[i] = 0; | 81 m_dispatchSoonList[i] = nullptr; |
82 } | 82 } |
83 size = m_dispatchingList.size(); | 83 size = m_dispatchingList.size(); |
84 for (size_t i = 0; i < size; ++i) { | 84 for (size_t i = 0; i < size; ++i) { |
85 if (m_dispatchingList[i] == sender) | 85 if (m_dispatchingList[i] == sender) |
86 m_dispatchingList[i] = 0; | 86 m_dispatchingList[i] = nullptr; |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 template<typename T> void EventSender<T>::dispatchPendingEvents() | 90 template<typename T> void EventSender<T>::dispatchPendingEvents() |
91 { | 91 { |
92 // Need to avoid re-entering this function; if new dispatches are | 92 // Need to avoid re-entering this function; if new dispatches are |
93 // scheduled before the parent finishes processing the list, they | 93 // scheduled before the parent finishes processing the list, they |
94 // will set a timer and eventually be processed. | 94 // will set a timer and eventually be processed. |
95 if (!m_dispatchingList.isEmpty()) | 95 if (!m_dispatchingList.isEmpty()) |
96 return; | 96 return; |
97 | 97 |
98 m_timer.stop(); | 98 m_timer.stop(); |
99 | 99 |
100 m_dispatchingList.swap(m_dispatchSoonList); | 100 m_dispatchingList.swap(m_dispatchSoonList); |
101 size_t size = m_dispatchingList.size(); | 101 size_t size = m_dispatchingList.size(); |
102 for (size_t i = 0; i < size; ++i) { | 102 for (size_t i = 0; i < size; ++i) { |
103 if (T* sender = m_dispatchingList[i]) { | 103 if (T* sender = m_dispatchingList[i]) { |
104 m_dispatchingList[i] = 0; | 104 m_dispatchingList[i] = nullptr; |
105 sender->dispatchPendingEvent(this); | 105 sender->dispatchPendingEvent(this); |
106 } | 106 } |
107 } | 107 } |
108 m_dispatchingList.clear(); | 108 m_dispatchingList.clear(); |
109 } | 109 } |
110 | 110 |
111 } // namespace WebCore | 111 } // namespace WebCore |
112 | 112 |
113 #endif // EventSender_h | 113 #endif // EventSender_h |
OLD | NEW |