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/dom/ActiveDOMObject.h" |
8 #include "core/dom/DocumentSupplementable.h" | 9 #include "core/dom/DocumentSupplementable.h" |
9 #include "core/events/Event.h" | 10 #include "core/events/Event.h" |
10 #include "wtf/HashCountedSet.h" | 11 #include "wtf/HashCountedSet.h" |
11 | 12 |
12 namespace WebCore { | 13 namespace WebCore { |
13 | 14 |
14 typedef HashCountedSet<EventTarget*> EventTargetSet; | 15 typedef HashCountedSet<EventTarget*> EventTargetSet; |
15 | 16 |
16 // Registry for keeping track of event handlers. Handlers can either be | 17 // Registry for keeping track of event handlers. Handlers can either be |
17 // associated with an EventTarget or be "external" handlers which live outside | 18 // associated with an EventTarget or be "external" handlers which live outside |
18 // the DOM (e.g., WebViewImpl). | 19 // the DOM (e.g., WebViewImpl). |
19 class EventHandlerRegistry FINAL : public DocumentSupplement { | 20 class EventHandlerRegistry FINAL : public DocumentSupplement, private ActiveDOMO
bject { |
20 public: | 21 public: |
21 virtual ~EventHandlerRegistry(); | 22 virtual ~EventHandlerRegistry(); |
22 | 23 |
23 // Supported event handler classes. Note that each one may correspond to | 24 // Supported event handler classes. Note that each one may correspond to |
24 // multiple event types. | 25 // multiple event types. |
25 enum EventHandlerClass { | 26 enum EventHandlerClass { |
26 ScrollEvent, | 27 ScrollEvent, |
27 EventHandlerClassCount, // Must be the last entry. | 28 EventHandlerClassCount, // Must be the last entry. |
28 }; | 29 }; |
29 | 30 |
(...skipping 15 matching lines...) Expand all Loading... |
45 void didAddEventHandler(EventTarget&, EventHandlerClass); | 46 void didAddEventHandler(EventTarget&, EventHandlerClass); |
46 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); | 47 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); |
47 void didRemoveEventHandler(EventTarget&, EventHandlerClass); | 48 void didRemoveEventHandler(EventTarget&, EventHandlerClass); |
48 void didMoveFromOtherDocument(EventTarget&, Document& oldDocument); | 49 void didMoveFromOtherDocument(EventTarget&, Document& oldDocument); |
49 void didRemoveAllEventHandlers(EventTarget&); | 50 void didRemoveAllEventHandlers(EventTarget&); |
50 | 51 |
51 virtual void trace(Visitor*) OVERRIDE { } | 52 virtual void trace(Visitor*) OVERRIDE { } |
52 | 53 |
53 private: | 54 private: |
54 explicit EventHandlerRegistry(Document&); | 55 explicit EventHandlerRegistry(Document&); |
| 56 static EventHandlerRegistry* create(Document&); |
55 | 57 |
56 enum ChangeOperation { | 58 enum ChangeOperation { |
57 Add, // Add a new event handler. | 59 Add, // Add a new event handler. |
58 Remove, // Remove an existing event handler. | 60 Remove, // Remove an existing event handler. |
59 RemoveAll // Remove any and all existing event handlers for a given targ
et. | 61 RemoveAll // Remove any and all existing event handlers for a given targ
et. |
60 }; | 62 }; |
61 | 63 |
| 64 Document* document() const; |
| 65 |
| 66 // Inherited from ActiveDOMObject |
| 67 virtual void stop() OVERRIDE; |
| 68 |
62 // Returns true if |eventType| belongs to a class this registry tracks. | 69 // Returns true if |eventType| belongs to a class this registry tracks. |
63 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas
s* result); | 70 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas
s* result); |
64 | 71 |
65 // 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 |
66 // removed an existing one. | 73 // removed an existing one. |
67 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg
et*); | 74 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg
et*); |
68 | 75 |
69 // Called on the EventHandlerRegistry of the root Document to notify | 76 // Called on the EventHandlerRegistry of the root Document to notify |
70 // 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 |
71 // a given event class. |hasActiveHandlers| can be used to distinguish | 78 // a given event class. |hasActiveHandlers| can be used to distinguish |
72 // between the two cases. | 79 // between the two cases. |
73 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); | 80 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); |
74 | 81 |
75 // 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 |
76 // parent registry and other clients accordingly. | 83 // parent registry and other clients accordingly. |
77 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType
, EventTarget*); | 84 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType
, EventTarget*); |
78 | 85 |
79 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar
get*); | 86 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar
get*); |
80 | 87 |
81 struct HandlerState { | 88 struct HandlerState { |
82 HandlerState(); | 89 HandlerState(); |
83 ~HandlerState(); | 90 ~HandlerState(); |
84 | 91 |
85 OwnPtr<EventTargetSet> targets; | 92 OwnPtr<EventTargetSet> targets; |
86 }; | 93 }; |
87 | 94 |
88 Document& m_document; | |
89 HandlerState m_eventHandlers[EventHandlerClassCount]; | 95 HandlerState m_eventHandlers[EventHandlerClassCount]; |
90 }; | 96 }; |
91 | 97 |
92 } // namespace WebCore | 98 } // namespace WebCore |
93 | 99 |
94 #endif // EventHandlerRegistry_h | 100 #endif // EventHandlerRegistry_h |
OLD | NEW |