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

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

Issue 237963014: Track scroll event handlers in nested documents (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Expanded test to move child doc from attached doc to unattached one (reverse not possible AFAICT). Created 6 years, 7 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/dom/DocumentSupplementable.h"
9 #include "core/events/Event.h" 8 #include "core/events/Event.h"
9 #include "core/page/Page.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. Handlers can either be 16 // Registry for keeping track of event handlers.
17 // associated with an EventTarget or be "external" handlers which live outside 17 class EventHandlerRegistry FINAL : public Supplement<Page> {
18 // the DOM (e.g., WebViewImpl).
19 class EventHandlerRegistry FINAL : public DocumentSupplement {
20 public: 18 public:
21 virtual ~EventHandlerRegistry(); 19 virtual ~EventHandlerRegistry();
22 20
23 // Supported event handler classes. Note that each one may correspond to 21 // Supported event handler classes. Note that each one may correspond to
24 // multiple event types. 22 // multiple event types.
25 enum EventHandlerClass { 23 enum EventHandlerClass {
26 ScrollEvent, 24 ScrollEvent,
25 #if ASSERT_ENABLED
26 // Additional event categories for verifying handler tracking logic.
27 EventsForTesting,
28 #endif
27 EventHandlerClassCount, // Must be the last entry. 29 EventHandlerClassCount, // Must be the last entry.
28 }; 30 };
29 31
30 static const char* supplementName(); 32 static const char* supplementName();
31 static EventHandlerRegistry* from(Document&); 33 static EventHandlerRegistry* from(Page&);
32 34
33 // Returns true if the host Document or any child documents have any 35 // Returns true if the page has event handlers of the specified class.
34 // registered event handlers of the class.
35 bool hasEventHandlers(EventHandlerClass) const; 36 bool hasEventHandlers(EventHandlerClass) const;
36 37
37 // Returns a set of EventTargets which have registered handlers of the 38 // Returns a set of EventTargets which have registered handlers of the given class.
38 // given class. Only contains targets directly in this document; all
39 // handlers in a child Document are collapsed to a single respective
40 // Document instance in the set.
41 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const; 39 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const;
42 40
43 // Registration and management of event handlers attached to EventTargets. 41 // Registration and management of event handlers attached to EventTargets.
44 void didAddEventHandler(EventTarget&, const AtomicString& eventType); 42 void didAddEventHandler(EventTarget&, const AtomicString& eventType);
45 void didAddEventHandler(EventTarget&, EventHandlerClass); 43 void didAddEventHandler(EventTarget&, EventHandlerClass);
46 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); 44 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType);
47 void didRemoveEventHandler(EventTarget&, EventHandlerClass); 45 void didRemoveEventHandler(EventTarget&, EventHandlerClass);
48 void didMoveFromOtherDocument(EventTarget&, Document& oldDocument);
49 void didRemoveAllEventHandlers(EventTarget&); 46 void didRemoveAllEventHandlers(EventTarget&);
47 void didMoveIntoPage(EventTarget&);
48 void didMoveOutOfPage(EventTarget&);
49
50 void documentDetached(Document&);
50 51
51 virtual void trace(Visitor*) OVERRIDE { } 52 virtual void trace(Visitor*) OVERRIDE { }
52 void clearWeakMembers(Visitor*); 53 void clearWeakMembers(Visitor*);
53 54
54 private: 55 private:
55 explicit EventHandlerRegistry(Document&); 56 explicit EventHandlerRegistry(Page&);
56 57
57 enum ChangeOperation { 58 enum ChangeOperation {
58 Add, // Add a new event handler. 59 Add, // Add a new event handler.
59 Remove, // Remove an existing event handler. 60 Remove, // Remove an existing event handler.
60 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.
61 }; 62 };
62 63
63 // Returns true if |eventType| belongs to a class this registry tracks. 64 // Returns true if |eventType| belongs to a class this registry tracks.
64 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas s* result); 65 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas s* result);
65 66
66 // Returns true if the operation actually added a new target or completely 67 // Returns true if the operation actually added a new target or completely
67 // removed an existing one. 68 // removed an existing one.
68 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg et*); 69 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg et*);
69 70
70 // Called on the EventHandlerRegistry of the root Document to notify 71 // Called on the EventHandlerRegistry of the root Document to notify
71 // clients when we have added the first handler or removed the last one for 72 // clients when we have added the first handler or removed the last one for
72 // a given event class. |hasActiveHandlers| can be used to distinguish 73 // a given event class. |hasActiveHandlers| can be used to distinguish
73 // between the two cases. 74 // between the two cases.
74 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); 75 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers);
75 76
76 // Record a change operation to a given event handler class and notify any 77 // Record a change operation to a given event handler class and notify any
77 // parent registry and other clients accordingly. 78 // parent registry and other clients accordingly.
78 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType , EventTarget*); 79 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType , EventTarget*);
79 80
80 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar get*); 81 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar get*);
81 82
82 struct HandlerState { 83 void updateAllEventHandlers(ChangeOperation, EventTarget&);
83 HandlerState();
84 ~HandlerState();
85 84
86 OwnPtr<EventTargetSet> targets; 85 void checkConsistency() const;
87 };
88 86
89 Document& m_document; 87 Page& m_page;
90 HandlerState m_eventHandlers[EventHandlerClassCount]; 88 EventTargetSet m_targets[EventHandlerClassCount];
91 }; 89 };
92 90
93 } // namespace WebCore 91 } // namespace WebCore
94 92
95 #endif // EventHandlerRegistry_h 93 #endif // EventHandlerRegistry_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698