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, |
31 #if ENABLE(ASSERT) | 32 #if ENABLE(ASSERT) |
32 // Additional event categories for verifying handler tracking logic. | 33 // Additional event categories for verifying handler tracking logic. |
33 EventsForTesting, | 34 EventsForTesting, |
34 #endif | 35 #endif |
35 EventHandlerClassCount, // Must be the last entry. | 36 EventHandlerClassCount, // Must be the last entry. |
36 }; | 37 }; |
37 | 38 |
38 // Returns true if the FrameHost has event handlers of the specified class. | 39 // Returns true if the FrameHost has event handlers of the specified class. |
39 bool hasEventHandlers(EventHandlerClass) const; | 40 bool hasEventHandlers(EventHandlerClass) const; |
40 | 41 |
41 // Returns a set of EventTargets which have registered handlers of the given
class. | 42 // Returns a set of EventTargets which have registered handlers of the given
class. |
42 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; | 43 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; |
43 | 44 |
44 // Registration and management of event handlers attached to EventTargets. | 45 // Registration and management of event handlers attached to EventTargets. |
45 void didAddEventHandler(EventTarget&, const AtomicString& eventType); | 46 void didAddEventHandler(EventTarget&, const AtomicString& eventType); |
46 void didAddEventHandler(EventTarget&, EventHandlerClass); | 47 void didAddEventHandler(EventTarget&, EventHandlerClass); |
47 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); | 48 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); |
48 void didRemoveEventHandler(EventTarget&, EventHandlerClass); | 49 void didRemoveEventHandler(EventTarget&, EventHandlerClass); |
49 void didRemoveAllEventHandlers(EventTarget&); | 50 void didRemoveAllEventHandlers(EventTarget&); |
| 51 |
50 void didMoveIntoFrameHost(EventTarget&); | 52 void didMoveIntoFrameHost(EventTarget&); |
51 void didMoveOutOfFrameHost(EventTarget&); | 53 void didMoveOutOfFrameHost(EventTarget&); |
| 54 static void didMoveBetweenFrameHosts(EventTarget&, FrameHost* oldFrameHost,
FrameHost* newFrameHost); |
52 | 55 |
53 // Either |documentDetached| or |didMoveOutOfFrameHost| must be called | 56 // Either |documentDetached| or |didMove{Into,OutOf,Between}FrameHosts| must |
54 // whenever the FrameHost that is associated with a registered event target | 57 // be called whenever the FrameHost that is associated with a registered eve
nt |
55 // changes. This ensures the registry does not end up with stale references | 58 // target changes. This ensures the registry does not end up with stale |
56 // to handlers that are no longer related to it. | 59 // references to handlers that are no longer related to it. |
57 void documentDetached(Document&); | 60 void documentDetached(Document&); |
58 | 61 |
59 void trace(Visitor*); | 62 void trace(Visitor*); |
60 void clearWeakMembers(Visitor*); | 63 void clearWeakMembers(Visitor*); |
61 | 64 |
62 private: | 65 private: |
63 enum ChangeOperation { | 66 enum ChangeOperation { |
64 Add, // Add a new event handler. | 67 Add, // Add a new event handler. |
65 Remove, // Remove an existing event handler. | 68 Remove, // Remove an existing event handler. |
66 RemoveAll // Remove any and all existing event handlers for a given targ
et. | 69 RemoveAll // Remove any and all existing event handlers for a given targ
et. |
67 }; | 70 }; |
68 | 71 |
69 // Returns true if |eventType| belongs to a class this registry tracks. | 72 // Returns true if |eventType| belongs to a class this registry tracks. |
70 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas
s* result); | 73 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas
s* result); |
71 | 74 |
72 // Returns true if the operation actually added a new target or completely | 75 // Returns true if the operation actually added a new target or completely |
73 // removed an existing one. | 76 // removed an existing one. |
74 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg
et*); | 77 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg
et*); |
75 | 78 |
76 // Called on the EventHandlerRegistry of the root Document to notify | 79 // Called on the EventHandlerRegistry of the root Document to notify |
77 // clients when we have added the first handler or removed the last one for | 80 // clients when we have added the first handler or removed the last one for |
78 // a given event class. |hasActiveHandlers| can be used to distinguish | 81 // a given event class. |hasActiveHandlers| can be used to distinguish |
79 // between the two cases. | 82 // between the two cases. |
80 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); | 83 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); |
81 | 84 |
| 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 |
82 // Record a change operation to a given event handler class and notify any | 90 // Record a change operation to a given event handler class and notify any |
83 // parent registry and other clients accordingly. | 91 // parent registry and other clients accordingly. |
84 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType
, EventTarget*); | 92 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType
, EventTarget*); |
85 | 93 |
86 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar
get*); | 94 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar
get*); |
87 | 95 |
88 void updateAllEventHandlers(ChangeOperation, EventTarget&); | 96 void updateAllEventHandlers(ChangeOperation, EventTarget&); |
89 | 97 |
90 void checkConsistency() const; | 98 void checkConsistency() const; |
91 | 99 |
92 FrameHost& m_frameHost; | 100 FrameHost& m_frameHost; |
93 EventTargetSet m_targets[EventHandlerClassCount]; | 101 EventTargetSet m_targets[EventHandlerClassCount]; |
94 }; | 102 }; |
95 | 103 |
96 } // namespace blink | 104 } // namespace blink |
97 | 105 |
98 #endif // EventHandlerRegistry_h | 106 #endif // EventHandlerRegistry_h |
OLD | NEW |