| 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 Document; | 14 class Document; |
| 15 class EventListenerOptions; |
| 15 class EventTarget; | 16 class EventTarget; |
| 16 | 17 |
| 17 typedef HashCountedSet<RawPtrWillBeUntracedMember<EventTarget>> EventTargetSet; | 18 typedef HashCountedSet<RawPtrWillBeUntracedMember<EventTarget>> EventTargetSet; |
| 18 | 19 |
| 19 // 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 |
| 20 // 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 |
| 21 // FrameHost) are registered here. | 22 // FrameHost) are registered here. |
| 22 class CORE_EXPORT EventHandlerRegistry final : public NoBaseWillBeGarbageCollect
edFinalized<EventHandlerRegistry> { | 23 class CORE_EXPORT EventHandlerRegistry final : public NoBaseWillBeGarbageCollect
edFinalized<EventHandlerRegistry> { |
| 23 USING_FAST_MALLOC_WILL_BE_REMOVED(EventHandlerRegistry); | 24 USING_FAST_MALLOC_WILL_BE_REMOVED(EventHandlerRegistry); |
| 24 public: | 25 public: |
| 25 explicit EventHandlerRegistry(FrameHost&); | 26 explicit EventHandlerRegistry(FrameHost&); |
| 26 virtual ~EventHandlerRegistry(); | 27 virtual ~EventHandlerRegistry(); |
| 27 | 28 |
| 28 // Supported event handler classes. Note that each one may correspond to | 29 // Supported event handler classes. Note that each one may correspond to |
| 29 // multiple event types. | 30 // multiple event types. |
| 30 enum EventHandlerClass { | 31 enum EventHandlerClass { |
| 31 ScrollEvent, | 32 ScrollEvent, |
| 32 WheelEvent, | 33 WheelEventBlocking, |
| 33 TouchEvent, | 34 WheelEventPassive, |
| 35 TouchEventBlocking, |
| 36 TouchEventPassive, |
| 34 #if ENABLE(ASSERT) | 37 #if ENABLE(ASSERT) |
| 35 // Additional event categories for verifying handler tracking logic. | 38 // Additional event categories for verifying handler tracking logic. |
| 36 EventsForTesting, | 39 EventsForTesting, |
| 37 #endif | 40 #endif |
| 38 EventHandlerClassCount, // Must be the last entry. | 41 EventHandlerClassCount, // Must be the last entry. |
| 39 }; | 42 }; |
| 40 | 43 |
| 41 // Returns true if the FrameHost has event handlers of the specified class. | 44 // Returns true if the FrameHost has event handlers of the specified class. |
| 42 bool hasEventHandlers(EventHandlerClass) const; | 45 bool hasEventHandlers(EventHandlerClass) const; |
| 43 | 46 |
| 44 // Returns a set of EventTargets which have registered handlers of the given
class. | 47 // Returns a set of EventTargets which have registered handlers of the given
class. |
| 45 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; | 48 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; |
| 46 | 49 |
| 47 // Registration and management of event handlers attached to EventTargets. | 50 // Registration and management of event handlers attached to EventTargets. |
| 48 void didAddEventHandler(EventTarget&, const AtomicString& eventType); | 51 void didAddEventHandler(EventTarget&, const AtomicString& eventType, const E
ventListenerOptions&); |
| 49 void didAddEventHandler(EventTarget&, EventHandlerClass); | 52 void didAddEventHandler(EventTarget&, EventHandlerClass); |
| 50 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); | 53 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType, cons
t EventListenerOptions&); |
| 51 void didRemoveEventHandler(EventTarget&, EventHandlerClass); | 54 void didRemoveEventHandler(EventTarget&, EventHandlerClass); |
| 52 void didRemoveAllEventHandlers(EventTarget&); | 55 void didRemoveAllEventHandlers(EventTarget&); |
| 53 | 56 |
| 54 void didMoveIntoFrameHost(EventTarget&); | 57 void didMoveIntoFrameHost(EventTarget&); |
| 55 void didMoveOutOfFrameHost(EventTarget&); | 58 void didMoveOutOfFrameHost(EventTarget&); |
| 56 static void didMoveBetweenFrameHosts(EventTarget&, FrameHost* oldFrameHost,
FrameHost* newFrameHost); | 59 static void didMoveBetweenFrameHosts(EventTarget&, FrameHost* oldFrameHost,
FrameHost* newFrameHost); |
| 57 | 60 |
| 58 // Either |documentDetached| or |didMove{Into,OutOf,Between}FrameHosts| must | 61 // Either |documentDetached| or |didMove{Into,OutOf,Between}FrameHosts| must |
| 59 // be called whenever the FrameHost that is associated with a registered eve
nt | 62 // be called whenever the FrameHost that is associated with a registered eve
nt |
| 60 // target changes. This ensures the registry does not end up with stale | 63 // target changes. This ensures the registry does not end up with stale |
| 61 // references to handlers that are no longer related to it. | 64 // references to handlers that are no longer related to it. |
| 62 void documentDetached(Document&); | 65 void documentDetached(Document&); |
| 63 | 66 |
| 64 DECLARE_TRACE(); | 67 DECLARE_TRACE(); |
| 65 void clearWeakMembers(Visitor*); | 68 void clearWeakMembers(Visitor*); |
| 66 | 69 |
| 67 private: | 70 private: |
| 68 enum ChangeOperation { | 71 enum ChangeOperation { |
| 69 Add, // Add a new event handler. | 72 Add, // Add a new event handler. |
| 70 Remove, // Remove an existing event handler. | 73 Remove, // Remove an existing event handler. |
| 71 RemoveAll // Remove any and all existing event handlers for a given targ
et. | 74 RemoveAll // Remove any and all existing event handlers for a given targ
et. |
| 72 }; | 75 }; |
| 73 | 76 |
| 74 // Returns true if |eventType| belongs to a class this registry tracks. | 77 // Returns true if |eventType| belongs to a class this registry tracks. |
| 75 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas
s* result); | 78 static bool eventTypeToClass(const AtomicString& eventType, const EventListe
nerOptions&, EventHandlerClass* result); |
| 76 | 79 |
| 77 // Returns true if the operation actually added a new target or completely | 80 // Returns true if the operation actually added a new target or completely |
| 78 // removed an existing one. | 81 // removed an existing one. |
| 79 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg
et*); | 82 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg
et*); |
| 80 | 83 |
| 81 // Called on the EventHandlerRegistry of the root Document to notify | 84 // Called on the EventHandlerRegistry of the root Document to notify |
| 82 // clients when we have added the first handler or removed the last one for | 85 // clients when we have added the first handler or removed the last one for |
| 83 // a given event class. |hasActiveHandlers| can be used to distinguish | 86 // a given event class. |hasActiveHandlers| can be used to distinguish |
| 84 // between the two cases. | 87 // between the two cases. |
| 85 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); | 88 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); |
| 86 | 89 |
| 87 // Called to notify clients whenever a single event handler target is | 90 // Called to notify clients whenever a single event handler target is |
| 88 // registered or unregistered. If several handlers are registered for the | 91 // registered or unregistered. If several handlers are registered for the |
| 89 // same target, only the first registration will trigger this notification. | 92 // same target, only the first registration will trigger this notification. |
| 90 void notifyDidAddOrRemoveEventHandlerTarget(EventHandlerClass); | 93 void notifyDidAddOrRemoveEventHandlerTarget(EventHandlerClass); |
| 91 | 94 |
| 92 // Record a change operation to a given event handler class and notify any | 95 // Record a change operation to a given event handler class and notify any |
| 93 // parent registry and other clients accordingly. | 96 // parent registry and other clients accordingly. |
| 94 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType
, EventTarget*); | 97 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType
, const EventListenerOptions&, EventTarget*); |
| 95 | 98 |
| 96 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar
get*); | 99 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar
get*); |
| 97 | 100 |
| 98 void updateAllEventHandlers(ChangeOperation, EventTarget&); | 101 void updateAllEventHandlers(ChangeOperation, EventTarget&); |
| 99 | 102 |
| 100 void checkConsistency() const; | 103 void checkConsistency() const; |
| 101 | 104 |
| 102 RawPtrWillBeMember<FrameHost> m_frameHost; | 105 RawPtrWillBeMember<FrameHost> m_frameHost; |
| 103 EventTargetSet m_targets[EventHandlerClassCount]; | 106 EventTargetSet m_targets[EventHandlerClassCount]; |
| 104 }; | 107 }; |
| 105 | 108 |
| 106 } // namespace blink | 109 } // namespace blink |
| 107 | 110 |
| 108 #endif // EventHandlerRegistry_h | 111 #endif // EventHandlerRegistry_h |
| OLD | NEW |