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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef EventSender_h | 26 #ifndef EventSender_h |
27 #define EventSender_h | 27 #define EventSender_h |
28 | 28 |
29 #include "platform/Timer.h" | 29 #include "platform/Timer.h" |
| 30 #include "platform/heap/Handle.h" |
30 #include "wtf/Vector.h" | 31 #include "wtf/Vector.h" |
31 #include "wtf/text/AtomicString.h" | 32 #include "wtf/text/AtomicString.h" |
32 | 33 |
33 namespace blink { | 34 namespace blink { |
34 | 35 |
35 template<typename T> class EventSender { | 36 template<typename T> |
36 WTF_MAKE_NONCOPYABLE(EventSender); USING_FAST_MALLOC(EventSender); | 37 class EventSender final : public NoBaseWillBeGarbageCollectedFinalized<EventSend
er<T>> { |
| 38 WTF_MAKE_NONCOPYABLE(EventSender); |
| 39 USING_FAST_MALLOC_WILL_BE_REMOVED(EventSender); |
37 public: | 40 public: |
38 explicit EventSender(const AtomicString& eventType); | 41 static PassOwnPtrWillBeRawPtr<EventSender> create(const AtomicString& eventT
ype) |
| 42 { |
| 43 return adoptPtrWillBeNoop(new EventSender(eventType)); |
| 44 } |
39 | 45 |
40 const AtomicString& eventType() const { return m_eventType; } | 46 const AtomicString& eventType() const { return m_eventType; } |
41 void dispatchEventSoon(T*); | 47 void dispatchEventSoon(T*); |
42 void cancelEvent(T*); | 48 void cancelEvent(T*); |
43 void dispatchPendingEvents(); | 49 void dispatchPendingEvents(); |
44 | 50 |
45 #if ENABLE(ASSERT) | 51 #if ENABLE(ASSERT) |
46 bool hasPendingEvents(T* sender) const | 52 bool hasPendingEvents(T* sender) const |
47 { | 53 { |
48 return m_dispatchSoonList.find(sender) != kNotFound || m_dispatchingList
.find(sender) != kNotFound; | 54 return m_dispatchSoonList.find(sender) != kNotFound || m_dispatchingList
.find(sender) != kNotFound; |
49 } | 55 } |
50 #endif | 56 #endif |
51 | 57 |
| 58 DEFINE_INLINE_TRACE() |
| 59 { |
| 60 visitor->trace(m_dispatchSoonList); |
| 61 visitor->trace(m_dispatchingList); |
| 62 } |
| 63 |
52 private: | 64 private: |
| 65 explicit EventSender(const AtomicString& eventType); |
| 66 |
53 void timerFired(Timer<EventSender<T>>*) { dispatchPendingEvents(); } | 67 void timerFired(Timer<EventSender<T>>*) { dispatchPendingEvents(); } |
54 | 68 |
55 AtomicString m_eventType; | 69 AtomicString m_eventType; |
56 Timer<EventSender<T>> m_timer; | 70 Timer<EventSender<T>> m_timer; |
57 WillBePersistentHeapVector<RawPtrWillBeMember<T>> m_dispatchSoonList; | 71 WillBeHeapVector<RawPtrWillBeMember<T>> m_dispatchSoonList; |
58 WillBePersistentHeapVector<RawPtrWillBeMember<T>> m_dispatchingList; | 72 WillBeHeapVector<RawPtrWillBeMember<T>> m_dispatchingList; |
59 }; | 73 }; |
60 | 74 |
61 template<typename T> EventSender<T>::EventSender(const AtomicString& eventType) | 75 template<typename T> EventSender<T>::EventSender(const AtomicString& eventType) |
62 : m_eventType(eventType) | 76 : m_eventType(eventType) |
63 , m_timer(this, &EventSender::timerFired) | 77 , m_timer(this, &EventSender::timerFired) |
64 { | 78 { |
65 } | 79 } |
66 | 80 |
67 template<typename T> void EventSender<T>::dispatchEventSoon(T* sender) | 81 template<typename T> void EventSender<T>::dispatchEventSoon(T* sender) |
68 { | 82 { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 m_dispatchingList[i] = nullptr; | 118 m_dispatchingList[i] = nullptr; |
105 sender->dispatchPendingEvent(this); | 119 sender->dispatchPendingEvent(this); |
106 } | 120 } |
107 } | 121 } |
108 m_dispatchingList.clear(); | 122 m_dispatchingList.clear(); |
109 } | 123 } |
110 | 124 |
111 } // namespace blink | 125 } // namespace blink |
112 | 126 |
113 #endif // EventSender_h | 127 #endif // EventSender_h |
OLD | NEW |