Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: Source/core/frame/EventHandlerRegistry.h

Issue 225823007: Migrate wheel events to EventHandlerRegistry (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/events/Event.h" 8 #include "core/events/Event.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 WebCore { 12 namespace WebCore {
13 13
14 typedef HashCountedSet<EventTarget*> EventTargetSet; 14 typedef HashCountedSet<EventTarget*> EventTargetSet;
15 15
16 // Registry for keeping track of event handlers. Note that only handlers on 16 // Registry for keeping track of event handlers. Note that only handlers on
17 // documents that can be rendered or can receive input (i.e., are attached to a 17 // documents that can be rendered or can receive input (i.e., are attached to a
18 // FrameHost) are registered here. 18 // FrameHost) are registered here.
19 class EventHandlerRegistry FINAL : public NoBaseWillBeGarbageCollectedFinalized< EventHandlerRegistry> { 19 class EventHandlerRegistry FINAL : public NoBaseWillBeGarbageCollectedFinalized< EventHandlerRegistry> {
20 public: 20 public:
21 explicit EventHandlerRegistry(FrameHost&); 21 explicit EventHandlerRegistry(FrameHost&);
22 virtual ~EventHandlerRegistry(); 22 virtual ~EventHandlerRegistry();
23 23
24 // Supported event handler classes. Note that each one may correspond to 24 // Supported event handler classes. Note that each one may correspond to
25 // multiple event types. 25 // multiple event types.
26 enum EventHandlerClass { 26 enum EventHandlerClass {
27 ScrollEvent, 27 ScrollEvent,
28 WheelEvent,
28 #if ASSERT_ENABLED 29 #if ASSERT_ENABLED
29 // Additional event categories for verifying handler tracking logic. 30 // Additional event categories for verifying handler tracking logic.
30 EventsForTesting, 31 EventsForTesting,
31 #endif 32 #endif
32 EventHandlerClassCount, // Must be the last entry. 33 EventHandlerClassCount, // Must be the last entry.
33 }; 34 };
34 35
35 // Returns true if the FrameHost has event handlers of the specified class. 36 // Returns true if the FrameHost has event handlers of the specified class.
36 bool hasEventHandlers(EventHandlerClass) const; 37 bool hasEventHandlers(EventHandlerClass) const;
37 38
38 // Returns a set of EventTargets which have registered handlers of the given class. 39 // Returns a set of EventTargets which have registered handlers of the given class.
39 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; 40 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const;
40 41
42 // Returns the number of external event handlers for a given class.
43 // External handlers are not included in |eventHandlerTargets|.
44 unsigned externalEventHandlerCount(EventHandlerClass) const;
45
41 // Registration and management of event handlers attached to EventTargets. 46 // Registration and management of event handlers attached to EventTargets.
42 void didAddEventHandler(EventTarget&, const AtomicString& eventType); 47 void didAddEventHandler(EventTarget&, const AtomicString& eventType);
43 void didAddEventHandler(EventTarget&, EventHandlerClass); 48 void didAddEventHandler(EventTarget&, EventHandlerClass);
44 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); 49 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType);
45 void didRemoveEventHandler(EventTarget&, EventHandlerClass); 50 void didRemoveEventHandler(EventTarget&, EventHandlerClass);
46 void didRemoveAllEventHandlers(EventTarget&); 51 void didRemoveAllEventHandlers(EventTarget&);
47 void didMoveIntoFrameHost(EventTarget&); 52 void didMoveIntoFrameHost(EventTarget&);
48 void didMoveOutOfFrameHost(EventTarget&); 53 void didMoveOutOfFrameHost(EventTarget&);
49 54
50 // Either |documentDetached| or |didMoveOutOfFrameHost| must be called 55 // Either |documentDetached| or |didMoveOutOfFrameHost| must be called
51 // whenever the FrameHost that is associated with a registered event target 56 // whenever the FrameHost that is associated with a registered event target
52 // changes. This ensures the registry does not end up with stale references 57 // changes. This ensures the registry does not end up with stale references
53 // to handlers that are no longer related to it. 58 // to handlers that are no longer related to it.
54 void documentDetached(Document&); 59 void documentDetached(Document&);
55 60
61 // Registration of event handlers attached to non-DOM objects.
62 void didAddExternalEventHandler(const AtomicString& eventType);
63 void didRemoveExternalEventHandler(const AtomicString& eventType);
64
56 void trace(Visitor*); 65 void trace(Visitor*);
57 void clearWeakMembers(Visitor*); 66 void clearWeakMembers(Visitor*);
58 67
59 private: 68 private:
60 enum ChangeOperation { 69 enum ChangeOperation {
61 Add, // Add a new event handler. 70 Add, // Add a new event handler.
62 Remove, // Remove an existing event handler. 71 Remove, // Remove an existing event handler.
63 RemoveAll // Remove any and all existing event handlers for a given targ et. 72 RemoveAll // Remove any and all existing event handlers for a given targ et.
64 }; 73 };
65 74
66 // Returns true if |eventType| belongs to a class this registry tracks. 75 // Returns true if |eventType| belongs to a class this registry tracks.
67 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas s* result); 76 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas s* result);
68 77
69 // Returns true if the operation actually added a new target or completely 78 // Returns true if the operation actually added a new target or completely
70 // removed an existing one. 79 // removed an existing one.
71 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg et*); 80 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg et*);
72 81
73 // Called on the EventHandlerRegistry of the root Document to notify 82 // Called on the EventHandlerRegistry of the root Document to notify
74 // clients when we have added the first handler or removed the last one for 83 // clients when we have added the first handler or removed the last one for
75 // a given event class. |hasActiveHandlers| can be used to distinguish 84 // a given event class. |hasActiveHandlers| can be used to distinguish
76 // between the two cases. 85 // between the two cases.
77 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); 86 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers);
78 87
79 // Record a change operation to a given event handler class and notify any 88 // Record a change operation to a given event handler class and notify any
80 // parent registry and other clients accordingly. 89 // parent registry and other clients accordingly.
81 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType , EventTarget*); 90 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType , EventTarget*);
82 91
92 void updateExternalHandlerCount(ChangeOperation, EventHandlerClass);
83 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar get*); 93 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar get*);
84 94
85 void updateAllEventHandlers(ChangeOperation, EventTarget&); 95 void updateAllEventHandlers(ChangeOperation, EventTarget&);
86 96
87 void checkConsistency() const; 97 void checkConsistency() const;
88 98
89 FrameHost& m_frameHost; 99 FrameHost& m_frameHost;
90 EventTargetSet m_targets[EventHandlerClassCount]; 100
101 struct HandlerState {
102 HandlerState();
103 ~HandlerState();
104
105 EventTargetSet targets;
106 // External handlers are not included in |targets|.
107 unsigned externalHandlerCount;
108 };
109
110 HandlerState m_handlers[EventHandlerClassCount];
91 }; 111 };
92 112
93 } // namespace WebCore 113 } // namespace WebCore
94 114
95 #endif // EventHandlerRegistry_h 115 #endif // EventHandlerRegistry_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698