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

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

Issue 237963014: Track scroll event handlers in nested documents (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Oilpan build fix. 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
« no previous file with comments | « Source/core/dom/Document.cpp ('k') | Source/core/dom/EventHandlerRegistry.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/DocumentSupplementable.h"
9 #include "core/events/Event.h"
10 #include "wtf/HashCountedSet.h"
11
12 namespace WebCore {
13
14 typedef HashCountedSet<EventTarget*> EventTargetSet;
15
16 // Registry for keeping track of event handlers. Handlers can either be
17 // associated with an EventTarget or be "external" handlers which live outside
18 // the DOM (e.g., WebViewImpl).
19 class EventHandlerRegistry FINAL : public NoBaseWillBeGarbageCollectedFinalized< EventHandlerRegistry>, public DocumentSupplement {
20 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(EventHandlerRegistry);
21 public:
22 virtual ~EventHandlerRegistry();
23
24 // Supported event handler classes. Note that each one may correspond to
25 // multiple event types.
26 enum EventHandlerClass {
27 ScrollEvent,
28 EventHandlerClassCount, // Must be the last entry.
29 };
30
31 static const char* supplementName();
32 static EventHandlerRegistry* from(Document&);
33
34 // Returns true if the host Document or any child documents have any
35 // registered event handlers of the class.
36 bool hasEventHandlers(EventHandlerClass) const;
37
38 // Returns a set of EventTargets which have registered handlers of the
39 // given class. Only contains targets directly in this document; all
40 // handlers in a child Document are collapsed to a single respective
41 // Document instance in the set.
42 const EventTargetSet* eventHandlerTargets(EventHandlerClass) const;
43
44 // Registration and management of event handlers attached to EventTargets.
45 void didAddEventHandler(EventTarget&, const AtomicString& eventType);
46 void didAddEventHandler(EventTarget&, EventHandlerClass);
47 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType);
48 void didRemoveEventHandler(EventTarget&, EventHandlerClass);
49 void didMoveFromOtherDocument(EventTarget&, Document& oldDocument);
50 void didRemoveAllEventHandlers(EventTarget&);
51
52 virtual void trace(Visitor*) OVERRIDE;
53 void clearWeakMembers(Visitor*);
54
55 private:
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
OLDNEW
« no previous file with comments | « Source/core/dom/Document.cpp ('k') | Source/core/dom/EventHandlerRegistry.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698