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

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

Issue 225903009: Migrate touch 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 WheelEvent,
29 TouchEvent,
29 #if ASSERT_ENABLED 30 #if ASSERT_ENABLED
30 // Additional event categories for verifying handler tracking logic. 31 // Additional event categories for verifying handler tracking logic.
31 EventsForTesting, 32 EventsForTesting,
32 #endif 33 #endif
33 EventHandlerClassCount, // Must be the last entry. 34 EventHandlerClassCount, // Must be the last entry.
34 }; 35 };
35 36
36 // Returns true if the FrameHost has event handlers of the specified class. 37 // Returns true if the FrameHost has event handlers of the specified class.
37 bool hasEventHandlers(EventHandlerClass) const; 38 bool hasEventHandlers(EventHandlerClass) const;
38 39
39 // Returns a set of EventTargets which have registered handlers of the given class. 40 // Returns a set of EventTargets which have registered handlers of the given class.
40 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; 41 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const;
41 42
42 // Registration and management of event handlers attached to EventTargets. 43 // Registration and management of event handlers attached to EventTargets.
43 void didAddEventHandler(EventTarget&, const AtomicString& eventType); 44 void didAddEventHandler(EventTarget&, const AtomicString& eventType);
44 void didAddEventHandler(EventTarget&, EventHandlerClass); 45 void didAddEventHandler(EventTarget&, EventHandlerClass);
45 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); 46 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType);
46 void didRemoveEventHandler(EventTarget&, EventHandlerClass); 47 void didRemoveEventHandler(EventTarget&, EventHandlerClass);
47 void didRemoveAllEventHandlers(EventTarget&); 48 void didRemoveAllEventHandlers(EventTarget&);
48 void didMoveIntoFrameHost(EventTarget&);
49 void didMoveOutOfFrameHost(EventTarget&);
50 49
51 // Either |documentDetached| or |didMoveOutOfFrameHost| must be called 50 static void didMoveBetweenFrameHosts(EventTarget&, FrameHost* oldFrameHost, FrameHost* newFrameHost);
51
52 // Either |documentDetached| or |didMoveBetweenFrameHosts| must be called
52 // whenever the FrameHost that is associated with a registered event target 53 // whenever the FrameHost that is associated with a registered event target
53 // changes. This ensures the registry does not end up with stale references 54 // changes. This ensures the registry does not end up with stale references
54 // to handlers that are no longer related to it. 55 // to handlers that are no longer related to it.
55 void documentDetached(Document&); 56 void documentDetached(Document&);
56 57
57 void trace(Visitor*); 58 void trace(Visitor*);
58 void clearWeakMembers(Visitor*); 59 void clearWeakMembers(Visitor*);
59 60
60 private: 61 private:
61 enum ChangeOperation { 62 enum ChangeOperation {
62 Add, // Add a new event handler. 63 Add, // Add a new event handler.
63 Remove, // Remove an existing event handler. 64 Remove, // Remove an existing event handler.
64 RemoveAll // Remove any and all existing event handlers for a given targ et. 65 RemoveAll // Remove any and all existing event handlers for a given targ et.
65 }; 66 };
66 67
67 // Returns true if |eventType| belongs to a class this registry tracks. 68 // Returns true if |eventType| belongs to a class this registry tracks.
68 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas s* result); 69 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas s* result);
69 70
70 // Returns true if the operation actually added a new target or completely 71 // Returns true if the operation actually added a new target or completely
71 // removed an existing one. 72 // removed an existing one.
72 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg et*); 73 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg et*);
73 74
74 // Called on the EventHandlerRegistry of the root Document to notify 75 // Called on the EventHandlerRegistry of the root Document to notify
75 // clients when we have added the first handler or removed the last one for 76 // clients when we have added the first handler or removed the last one for
76 // a given event class. |hasActiveHandlers| can be used to distinguish 77 // a given event class. |hasActiveHandlers| can be used to distinguish
77 // between the two cases. 78 // between the two cases.
78 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); 79 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers);
79 80
81 // Called to notify clients whenever a single event handler target is
82 // registered or unregistered. If several handlers are registered for the
83 // same target, only the first registration will trigger this notification.
84 void notifyDidAddOrRemoveEventHandlerTarget(EventHandlerClass);
85
80 // Record a change operation to a given event handler class and notify any 86 // Record a change operation to a given event handler class and notify any
81 // parent registry and other clients accordingly. 87 // parent registry and other clients accordingly.
82 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType , EventTarget*); 88 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType , EventTarget*);
83 89
84 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar get*); 90 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar get*);
85 91
86 void updateAllEventHandlers(ChangeOperation, EventTarget&); 92 void updateAllEventHandlers(ChangeOperation, EventTarget&);
87 93
88 void checkConsistency() const; 94 void checkConsistency() const;
89 95
90 FrameHost& m_frameHost; 96 FrameHost& m_frameHost;
91 EventTargetSet m_targets[EventHandlerClassCount]; 97 EventTargetSet m_targets[EventHandlerClassCount];
92 }; 98 };
93 99
94 } // namespace WebCore 100 } // namespace WebCore
95 101
96 #endif // EventHandlerRegistry_h 102 #endif // EventHandlerRegistry_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698