OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EventHandlerRegistry_h | 5 #ifndef EventHandlerRegistry_h |
6 #define EventHandlerRegistry_h | 6 #define EventHandlerRegistry_h |
7 | 7 |
8 #include "core/frame/FrameHost.h" | 8 #include "core/frame/FrameHost.h" |
9 #include "wtf/HashCountedSet.h" | 9 #include "wtf/HashCountedSet.h" |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 class EventHandlerRegistry FINAL : public NoBaseWillBeGarbageCollectedFinalized<
EventHandlerRegistry> { | 21 class EventHandlerRegistry FINAL : public NoBaseWillBeGarbageCollectedFinalized<
EventHandlerRegistry> { |
22 public: | 22 public: |
23 explicit EventHandlerRegistry(FrameHost&); | 23 explicit EventHandlerRegistry(FrameHost&); |
24 virtual ~EventHandlerRegistry(); | 24 virtual ~EventHandlerRegistry(); |
25 | 25 |
26 // Supported event handler classes. Note that each one may correspond to | 26 // Supported event handler classes. Note that each one may correspond to |
27 // multiple event types. | 27 // multiple event types. |
28 enum EventHandlerClass { | 28 enum EventHandlerClass { |
29 ScrollEvent, | 29 ScrollEvent, |
30 WheelEvent, | 30 WheelEvent, |
31 TouchEvent, | |
32 #if ASSERT_ENABLED | 31 #if ASSERT_ENABLED |
33 // Additional event categories for verifying handler tracking logic. | 32 // Additional event categories for verifying handler tracking logic. |
34 EventsForTesting, | 33 EventsForTesting, |
35 #endif | 34 #endif |
36 EventHandlerClassCount, // Must be the last entry. | 35 EventHandlerClassCount, // Must be the last entry. |
37 }; | 36 }; |
38 | 37 |
39 // Returns true if the FrameHost has event handlers of the specified class. | 38 // Returns true if the FrameHost has event handlers of the specified class. |
40 bool hasEventHandlers(EventHandlerClass) const; | 39 bool hasEventHandlers(EventHandlerClass) const; |
41 | 40 |
42 // Returns a set of EventTargets which have registered handlers of the given
class. | 41 // Returns a set of EventTargets which have registered handlers of the given
class. |
43 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; | 42 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; |
44 | 43 |
45 // Registration and management of event handlers attached to EventTargets. | 44 // Registration and management of event handlers attached to EventTargets. |
46 void didAddEventHandler(EventTarget&, const AtomicString& eventType); | 45 void didAddEventHandler(EventTarget&, const AtomicString& eventType); |
47 void didAddEventHandler(EventTarget&, EventHandlerClass); | 46 void didAddEventHandler(EventTarget&, EventHandlerClass); |
48 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); | 47 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); |
49 void didRemoveEventHandler(EventTarget&, EventHandlerClass); | 48 void didRemoveEventHandler(EventTarget&, EventHandlerClass); |
50 void didRemoveAllEventHandlers(EventTarget&); | 49 void didRemoveAllEventHandlers(EventTarget&); |
51 | |
52 void didMoveIntoFrameHost(EventTarget&); | 50 void didMoveIntoFrameHost(EventTarget&); |
53 void didMoveOutOfFrameHost(EventTarget&); | 51 void didMoveOutOfFrameHost(EventTarget&); |
54 static void didMoveBetweenFrameHosts(EventTarget&, FrameHost* oldFrameHost,
FrameHost* newFrameHost); | |
55 | 52 |
56 // Either |documentDetached| or |didMove{Into,OutOf,Between}FrameHosts| must | 53 // Either |documentDetached| or |didMoveOutOfFrameHost| must be called |
57 // be called whenever the FrameHost that is associated with a registered eve
nt | 54 // whenever the FrameHost that is associated with a registered event target |
58 // target changes. This ensures the registry does not end up with stale | 55 // changes. This ensures the registry does not end up with stale references |
59 // references to handlers that are no longer related to it. | 56 // to handlers that are no longer related to it. |
60 void documentDetached(Document&); | 57 void documentDetached(Document&); |
61 | 58 |
62 void trace(Visitor*); | 59 void trace(Visitor*); |
63 void clearWeakMembers(Visitor*); | 60 void clearWeakMembers(Visitor*); |
64 | 61 |
65 private: | 62 private: |
66 enum ChangeOperation { | 63 enum ChangeOperation { |
67 Add, // Add a new event handler. | 64 Add, // Add a new event handler. |
68 Remove, // Remove an existing event handler. | 65 Remove, // Remove an existing event handler. |
69 RemoveAll // Remove any and all existing event handlers for a given targ
et. | 66 RemoveAll // Remove any and all existing event handlers for a given targ
et. |
70 }; | 67 }; |
71 | 68 |
72 // Returns true if |eventType| belongs to a class this registry tracks. | 69 // Returns true if |eventType| belongs to a class this registry tracks. |
73 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas
s* result); | 70 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas
s* result); |
74 | 71 |
75 // Returns true if the operation actually added a new target or completely | 72 // Returns true if the operation actually added a new target or completely |
76 // removed an existing one. | 73 // removed an existing one. |
77 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg
et*); | 74 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg
et*); |
78 | 75 |
79 // Called on the EventHandlerRegistry of the root Document to notify | 76 // Called on the EventHandlerRegistry of the root Document to notify |
80 // clients when we have added the first handler or removed the last one for | 77 // clients when we have added the first handler or removed the last one for |
81 // a given event class. |hasActiveHandlers| can be used to distinguish | 78 // a given event class. |hasActiveHandlers| can be used to distinguish |
82 // between the two cases. | 79 // between the two cases. |
83 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); | 80 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); |
84 | 81 |
85 // Called to notify clients whenever a single event handler target is | |
86 // registered or unregistered. If several handlers are registered for the | |
87 // same target, only the first registration will trigger this notification. | |
88 void notifyDidAddOrRemoveEventHandlerTarget(EventHandlerClass); | |
89 | |
90 // Record a change operation to a given event handler class and notify any | 82 // Record a change operation to a given event handler class and notify any |
91 // parent registry and other clients accordingly. | 83 // parent registry and other clients accordingly. |
92 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType
, EventTarget*); | 84 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType
, EventTarget*); |
93 | 85 |
94 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar
get*); | 86 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar
get*); |
95 | 87 |
96 void updateAllEventHandlers(ChangeOperation, EventTarget&); | 88 void updateAllEventHandlers(ChangeOperation, EventTarget&); |
97 | 89 |
98 void checkConsistency() const; | 90 void checkConsistency() const; |
99 | 91 |
100 FrameHost& m_frameHost; | 92 FrameHost& m_frameHost; |
101 EventTargetSet m_targets[EventHandlerClassCount]; | 93 EventTargetSet m_targets[EventHandlerClassCount]; |
102 }; | 94 }; |
103 | 95 |
104 } // namespace WebCore | 96 } // namespace WebCore |
105 | 97 |
106 #endif // EventHandlerRegistry_h | 98 #endif // EventHandlerRegistry_h |
OLD | NEW |