| 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/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
| 10 #include "wtf/HashCountedSet.h" | 10 #include "wtf/HashCountedSet.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class AddEventListenerOptions; |
| 14 class Document; | 15 class Document; |
| 15 class EventListenerOptions; | |
| 16 class EventTarget; | 16 class EventTarget; |
| 17 | 17 |
| 18 typedef HashCountedSet<UntracedMember<EventTarget>> EventTargetSet; | 18 typedef HashCountedSet<UntracedMember<EventTarget>> EventTargetSet; |
| 19 | 19 |
| 20 // Registry for keeping track of event handlers. Note that only handlers on | 20 // Registry for keeping track of event handlers. Note that only handlers on |
| 21 // documents that can be rendered or can receive input (i.e., are attached to a | 21 // documents that can be rendered or can receive input (i.e., are attached to a |
| 22 // FrameHost) are registered here. | 22 // FrameHost) are registered here. |
| 23 class CORE_EXPORT EventHandlerRegistry final : public GarbageCollectedFinalized<
EventHandlerRegistry> { | 23 class CORE_EXPORT EventHandlerRegistry final : public GarbageCollectedFinalized<
EventHandlerRegistry> { |
| 24 public: | 24 public: |
| 25 explicit EventHandlerRegistry(FrameHost&); | 25 explicit EventHandlerRegistry(FrameHost&); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 42 EventHandlerClassCount, // Must be the last entry. | 42 EventHandlerClassCount, // Must be the last entry. |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // Returns true if the FrameHost has event handlers of the specified class. | 45 // Returns true if the FrameHost has event handlers of the specified class. |
| 46 bool hasEventHandlers(EventHandlerClass) const; | 46 bool hasEventHandlers(EventHandlerClass) const; |
| 47 | 47 |
| 48 // Returns a set of EventTargets which have registered handlers of the given
class. | 48 // Returns a set of EventTargets which have registered handlers of the given
class. |
| 49 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; | 49 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; |
| 50 | 50 |
| 51 // Registration and management of event handlers attached to EventTargets. | 51 // Registration and management of event handlers attached to EventTargets. |
| 52 void didAddEventHandler(EventTarget&, const AtomicString& eventType, const E
ventListenerOptions&); | 52 void didAddEventHandler(EventTarget&, const AtomicString& eventType, const A
ddEventListenerOptions&); |
| 53 void didAddEventHandler(EventTarget&, EventHandlerClass); | 53 void didAddEventHandler(EventTarget&, EventHandlerClass); |
| 54 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType, cons
t EventListenerOptions&); | 54 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType, cons
t AddEventListenerOptions&); |
| 55 void didRemoveEventHandler(EventTarget&, EventHandlerClass); | 55 void didRemoveEventHandler(EventTarget&, EventHandlerClass); |
| 56 void didRemoveAllEventHandlers(EventTarget&); | 56 void didRemoveAllEventHandlers(EventTarget&); |
| 57 | 57 |
| 58 void didMoveIntoFrameHost(EventTarget&); | 58 void didMoveIntoFrameHost(EventTarget&); |
| 59 void didMoveOutOfFrameHost(EventTarget&); | 59 void didMoveOutOfFrameHost(EventTarget&); |
| 60 static void didMoveBetweenFrameHosts(EventTarget&, FrameHost* oldFrameHost,
FrameHost* newFrameHost); | 60 static void didMoveBetweenFrameHosts(EventTarget&, FrameHost* oldFrameHost,
FrameHost* newFrameHost); |
| 61 | 61 |
| 62 // Either |documentDetached| or |didMove{Into,OutOf,Between}FrameHosts| must | 62 // Either |documentDetached| or |didMove{Into,OutOf,Between}FrameHosts| must |
| 63 // be called whenever the FrameHost that is associated with a registered eve
nt | 63 // be called whenever the FrameHost that is associated with a registered eve
nt |
| 64 // target changes. This ensures the registry does not end up with stale | 64 // target changes. This ensures the registry does not end up with stale |
| 65 // references to handlers that are no longer related to it. | 65 // references to handlers that are no longer related to it. |
| 66 void documentDetached(Document&); | 66 void documentDetached(Document&); |
| 67 | 67 |
| 68 DECLARE_TRACE(); | 68 DECLARE_TRACE(); |
| 69 void clearWeakMembers(Visitor*); | 69 void clearWeakMembers(Visitor*); |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 enum ChangeOperation { | 72 enum ChangeOperation { |
| 73 Add, // Add a new event handler. | 73 Add, // Add a new event handler. |
| 74 Remove, // Remove an existing event handler. | 74 Remove, // Remove an existing event handler. |
| 75 RemoveAll // Remove any and all existing event handlers for a given targ
et. | 75 RemoveAll // Remove any and all existing event handlers for a given targ
et. |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 // Returns true if |eventType| belongs to a class this registry tracks. | 78 // Returns true if |eventType| belongs to a class this registry tracks. |
| 79 static bool eventTypeToClass(const AtomicString& eventType, const EventListe
nerOptions&, EventHandlerClass* result); | 79 static bool eventTypeToClass(const AtomicString& eventType, const AddEventLi
stenerOptions&, EventHandlerClass* result); |
| 80 | 80 |
| 81 // Returns true if the operation actually added a new target or completely | 81 // Returns true if the operation actually added a new target or completely |
| 82 // removed an existing one. | 82 // removed an existing one. |
| 83 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg
et*); | 83 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg
et*); |
| 84 | 84 |
| 85 // Called on the EventHandlerRegistry of the root Document to notify | 85 // Called on the EventHandlerRegistry of the root Document to notify |
| 86 // clients when we have added the first handler or removed the last one for | 86 // clients when we have added the first handler or removed the last one for |
| 87 // a given event class. |hasActiveHandlers| can be used to distinguish | 87 // a given event class. |hasActiveHandlers| can be used to distinguish |
| 88 // between the two cases. | 88 // between the two cases. |
| 89 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); | 89 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); |
| 90 | 90 |
| 91 // Called to notify clients whenever a single event handler target is | 91 // Called to notify clients whenever a single event handler target is |
| 92 // registered or unregistered. If several handlers are registered for the | 92 // registered or unregistered. If several handlers are registered for the |
| 93 // same target, only the first registration will trigger this notification. | 93 // same target, only the first registration will trigger this notification. |
| 94 void notifyDidAddOrRemoveEventHandlerTarget(EventHandlerClass); | 94 void notifyDidAddOrRemoveEventHandlerTarget(EventHandlerClass); |
| 95 | 95 |
| 96 // Record a change operation to a given event handler class and notify any | 96 // Record a change operation to a given event handler class and notify any |
| 97 // parent registry and other clients accordingly. | 97 // parent registry and other clients accordingly. |
| 98 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType
, const EventListenerOptions&, EventTarget*); | 98 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType
, const AddEventListenerOptions&, EventTarget*); |
| 99 | 99 |
| 100 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar
get*); | 100 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar
get*); |
| 101 | 101 |
| 102 void updateAllEventHandlers(ChangeOperation, EventTarget&); | 102 void updateAllEventHandlers(ChangeOperation, EventTarget&); |
| 103 | 103 |
| 104 void checkConsistency() const; | 104 void checkConsistency() const; |
| 105 | 105 |
| 106 Member<FrameHost> m_frameHost; | 106 Member<FrameHost> m_frameHost; |
| 107 EventTargetSet m_targets[EventHandlerClassCount]; | 107 EventTargetSet m_targets[EventHandlerClassCount]; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 } // namespace blink | 110 } // namespace blink |
| 111 | 111 |
| 112 #endif // EventHandlerRegistry_h | 112 #endif // EventHandlerRegistry_h |
| OLD | NEW |