OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef EventHandlerRegistry_h | |
6 #define EventHandlerRegistry_h | |
7 | |
8 #include "core/dom/ActiveDOMObject.h" | |
9 #include "core/dom/DocumentLifecycleObserver.h" | |
abarth-chromium
2014/04/17 18:05:12
These two includes don't appear to be used.
Sami
2014/04/17 18:40:53
Ah, thanks for pointing that out. Done.
| |
10 #include "core/dom/DocumentSupplementable.h" | |
11 #include "core/events/Event.h" | |
12 #include "core/frame/DOMWindowLifecycleObserver.h" | |
abarth-chromium
2014/04/17 18:05:12
This include doesn't appear to be used.
| |
13 #include "wtf/HashCountedSet.h" | |
14 | |
15 namespace WebCore { | |
16 | |
17 typedef HashCountedSet<EventTarget*> EventTargetSet; | |
18 | |
19 // Registry for keeping track of event handlers. Handlers can either be | |
20 // associated with an EventTarget or be "external" handlers which live outside | |
21 // the DOM (e.g., WebViewImpl). | |
22 class EventHandlerRegistry FINAL : public DocumentSupplement { | |
23 public: | |
24 virtual ~EventHandlerRegistry(); | |
25 | |
26 // Supported event handler classes. Note that each one may correspond to | |
27 // multiple event types. | |
28 enum EventHandlerClass { | |
29 ScrollEvent, | |
30 EventHandlerClassCount, // Must be the last entry. | |
31 }; | |
32 | |
33 static const char* supplementName(); | |
34 static EventHandlerRegistry* from(Document&); | |
35 | |
36 // Returns true if the host Document or any child documents have any | |
37 // registered event handlers of the class. | |
38 bool hasEventHandlers(EventHandlerClass) const; | |
39 | |
40 // Returns a set of EventTargets which have registered handlers of the | |
41 // given class. Only contains targets directly in this document; all | |
42 // handlers in a child Document are collapsed to a single respective | |
43 // Document instance in the set. | |
44 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; | |
45 | |
46 // Registration and management of event handlers attached to EventTargets. | |
47 void didAddEventHandler(EventTarget&, const AtomicString& eventType); | |
48 void didAddEventHandler(EventTarget&, EventHandlerClass); | |
49 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); | |
50 void didRemoveEventHandler(EventTarget&, EventHandlerClass); | |
51 void didMoveFromOtherDocument(EventTarget&, Document& oldDocument); | |
52 void didRemoveAllEventHandlers(EventTarget&); | |
53 | |
54 virtual void trace(Visitor*) OVERRIDE { } | |
55 private: | |
abarth-chromium
2014/04/17 18:05:12
Please add a blank line before this line.
Sami
2014/04/17 18:40:53
Done.
| |
56 explicit EventHandlerRegistry(Document&); | |
57 | |
58 enum ChangeOperation { | |
59 Add, // Add a new event handler. | |
60 Remove, // Remove an existing event handler. | |
61 RemoveAll // Remove any and all existing event handlers for a given targ et. | |
62 }; | |
63 | |
64 // Returns true if |eventType| belongs to a class this registry tracks. | |
65 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas s* result); | |
66 | |
67 // Returns true if the operation actually added a new target or completely | |
68 // removed an existing one. | |
69 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg et*); | |
70 | |
71 // Called on the EventHandlerRegistry of the root Document to notify | |
72 // clients when we have added the first handler or removed the last one for | |
73 // a given event class. |hasActiveHandlers| can be used to distinguish | |
74 // between the two cases. | |
75 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); | |
76 | |
77 // Record a change operation to a given event handler class and notify any | |
78 // parent registry and other clients accordingly. | |
79 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType , EventTarget*); | |
80 | |
81 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar get*); | |
82 | |
83 struct HandlerState { | |
84 HandlerState(); | |
85 ~HandlerState(); | |
86 | |
87 OwnPtr<EventTargetSet> targets; | |
88 }; | |
89 | |
90 Document& m_document; | |
91 HandlerState m_eventHandlers[EventHandlerClassCount]; | |
92 }; | |
93 | |
94 } // namespace WebCore | |
95 | |
96 #endif // EventHandlerRegistry_h | |
OLD | NEW |