Chromium Code Reviews| 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 #ifndef EventHandlerRegistry_h | |
| 5 #define EventHandlerRegistry_h | |
| 6 | |
| 7 #include "core/dom/DocumentLifecycleObserver.h" | |
| 8 #include "core/dom/DocumentSupplementable.h" | |
| 9 #include "core/events/Event.h" | |
| 10 #include "core/frame/DOMWindowLifecycleObserver.h" | |
| 11 #include "wtf/HashCountedSet.h" | |
| 12 | |
| 13 namespace WebCore { | |
| 14 | |
| 15 typedef HashCountedSet<EventTarget*> EventTargetSet; | |
| 16 | |
| 17 // Registry for keeping track of event handlers. Handlers can either be | |
| 18 // associated with an EventTarget or be "external" handlers which live outside | |
| 19 // the DOM (e.g., WebViewImpl). | |
| 20 class EventHandlerRegistry FINAL : public DocumentSupplement { | |
| 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 WheelEvent, | |
| 28 ScrollEvent, | |
| 29 TouchEvent, | |
| 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 // Returns the number of external event handlers for a given class. | |
| 47 // External handlers are not included in |eventHandlerTargets|. | |
| 48 unsigned externalEventHandlerCount(EventHandlerClass) const; | |
| 49 | |
| 50 // Registration and management of event handlers attached to EventTargets. | |
| 51 void didAddEventHandler(EventTarget&, const AtomicString& eventType); | |
| 52 void didAddEventHandler(EventTarget&, EventHandlerClass); | |
| 53 void didRemoveEventHandler(EventTarget&, const AtomicString& eventType); | |
| 54 void didRemoveEventHandler(EventTarget&, EventHandlerClass); | |
| 55 void didMoveToNewDocument(EventTarget&, Document& oldDocument); | |
|
Rick Byers
2014/04/03 15:33:19
Nit: A call like "doc1.didMoveToNewDocument(t, doc
Sami
2014/04/04 19:53:57
Agreed, it reads a little badly. "didMoveFromOther
| |
| 56 void didRemoveAllEventHandlers(EventTarget&); | |
| 57 | |
| 58 // Registration of event handlers attached to non-DOM objects. | |
| 59 void didAddExternalEventHandler(const AtomicString& eventType); | |
| 60 void didRemoveExternalEventHandler(const AtomicString& eventType); | |
| 61 private: | |
| 62 explicit EventHandlerRegistry(Document&); | |
| 63 | |
| 64 enum ChangeOperation { | |
| 65 Add, // Add a new event handler. | |
| 66 Remove, // Remove an existing event handler. | |
| 67 RemoveAll // Remove any and all existing event handlers for a given targ et. | |
| 68 }; | |
| 69 | |
| 70 // Returns true if |eventType| belongs to a class this registry tracks. | |
| 71 static bool eventTypeToClass(const AtomicString& eventType, EventHandlerClas s* result); | |
| 72 | |
| 73 // Returns true if the operation actually added a new target or completely | |
| 74 // removed an existing one. | |
| 75 bool updateEventHandlerTargets(ChangeOperation, EventHandlerClass, EventTarg et*); | |
| 76 | |
| 77 // Called to notify clients whenever a single event handler target is | |
| 78 // registered or unregistered. If several handlers are registered for the | |
| 79 // same target, only the first registration will trigger this notification. | |
| 80 void notifyDidAddOrRemoveEventHandlerTarget(EventHandlerClass); | |
| 81 | |
| 82 // Called on the EventHandlerRegistry of the root Document to notify | |
| 83 // clients when we have added the first handler or removed the last one for | |
| 84 // a given event class. |hasActiveHandlers| can be used to distinguish | |
| 85 // between the two cases. | |
| 86 void notifyHasHandlersChanged(EventHandlerClass, bool hasActiveHandlers); | |
| 87 | |
| 88 // Record a change operation to a given event handler class and notify any | |
| 89 // parent registry and other clients accordingly. | |
| 90 void updateEventHandlerOfType(ChangeOperation, const AtomicString& eventType , EventTarget*); | |
| 91 | |
| 92 void updateExternalHandlerCount(ChangeOperation, EventHandlerClass); | |
| 93 void updateEventHandlerInternal(ChangeOperation, EventHandlerClass, EventTar get*); | |
| 94 | |
| 95 class DocumentObserver; | |
| 96 class WindowObserver; | |
| 97 friend class DocumentObserver; | |
|
Rick Byers
2014/04/03 15:33:19
I thought nested class members were friends automa
Sami
2014/04/04 19:53:57
I was thinking that was only the case for Java, bu
| |
| 98 | |
| 99 struct HandlerState { | |
| 100 HandlerState(); | |
| 101 ~HandlerState(); | |
| 102 | |
| 103 OwnPtr<EventTargetSet> targets; | |
| 104 // External handlers are not included in |targets|. | |
| 105 unsigned externalHandlerCount; | |
|
Rick Byers
2014/04/03 15:33:19
Now that you don't have handlerCount, it's temptin
Sami
2014/04/04 19:53:57
I see where you're going and it would simplify thi
Rick Byers
2014/04/04 20:12:27
Yeah I wouldn't want to expose this to clients eit
| |
| 106 }; | |
| 107 | |
| 108 Document& m_document; | |
| 109 | |
| 110 OwnPtr<DocumentObserver> m_documentObserver; | |
|
Rick Byers
2014/04/03 15:33:19
Is there any value to the indirection via a pointe
Sami
2014/04/04 19:53:57
I picked this way just to reduce the number of imp
Rick Byers
2014/04/04 20:12:27
Ok. Did you want to update m_windowObserver too?
| |
| 111 OwnPtr<WindowObserver> m_windowObserver; | |
| 112 | |
| 113 HandlerState m_eventHandlers[EventHandlerClassCount]; | |
| 114 }; | |
| 115 | |
| 116 } // namespace WebCore | |
| 117 | |
| 118 #endif // EventHandlerRegistry_h | |
| OLD | NEW |