Changeset 143145 in webkit
- Timestamp:
- Feb 17, 2013 9:51:49 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r143144 r143145 1 2013-02-17 Hayato Ito <hayato@chromium.org> 2 3 Make EventDispatcher take an Event object in its constructor. 4 https://bugs.webkit.org/show_bug.cgi?id=109898 5 6 Reviewed by Dimitri Glazkov. 7 8 That makes EventDispatcher more RAII-like so that we can calculate 9 an EventPath in its constructor. I'll remove 10 EventDispatcher::ensureEventPath() in a following patch. 11 12 No tests. No change in behavior. 13 14 * dom/EventDispatchMediator.cpp: 15 (WebCore::EventDispatchMediator::dispatchEvent): 16 * dom/EventDispatcher.cpp: 17 (WebCore::EventDispatcher::dispatchEvent): 18 (WebCore::EventDispatcher::EventDispatcher): 19 (WebCore::EventDispatcher::ensureEventPath): 20 (WebCore::EventDispatcher::dispatchSimulatedClick): 21 (WebCore::EventDispatcher::dispatch): 22 (WebCore::EventDispatcher::dispatchEventPreProcess): 23 (WebCore::EventDispatcher::dispatchEventAtCapturing): 24 (WebCore::EventDispatcher::dispatchEventAtTarget): 25 (WebCore::EventDispatcher::dispatchEventAtBubbling): 26 (WebCore::EventDispatcher::dispatchEventPostProcess): 27 * dom/EventDispatcher.h: 28 (EventDispatcher): 29 (WebCore::EventDispatcher::node): 30 (WebCore::EventDispatcher::event): 31 * dom/FocusEvent.cpp: 32 (WebCore::FocusEventDispatchMediator::dispatchEvent): 33 (WebCore::BlurEventDispatchMediator::dispatchEvent): 34 (WebCore::FocusInEventDispatchMediator::dispatchEvent): 35 (WebCore::FocusOutEventDispatchMediator::dispatchEvent): 36 * dom/GestureEvent.cpp: 37 (WebCore::GestureEventDispatchMediator::dispatchEvent): 38 * dom/MouseEvent.cpp: 39 (WebCore::MouseEventDispatchMediator::dispatchEvent): 40 1 41 2013-02-17 Philip Rogers <pdr@google.com> 2 42 -
trunk/Source/WebCore/dom/EventDispatchMediator.cpp
r142957 r143145 51 51 bool EventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const 52 52 { 53 return dispatcher->dispatchEvent(m_event.get()); 53 ASSERT(m_event.get() == dispatcher->event()); 54 return dispatcher->dispatch(); 54 55 } 55 56 -
trunk/Source/WebCore/dom/EventDispatcher.cpp
r142957 r143145 52 52 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); 53 53 54 EventDispatcher dispatcher(node );54 EventDispatcher dispatcher(node, mediator->event()); 55 55 return mediator->dispatchEvent(&dispatcher); 56 56 } 57 57 58 EventDispatcher::EventDispatcher(Node* node )58 EventDispatcher::EventDispatcher(Node* node, PassRefPtr<Event> event) 59 59 : m_node(node) 60 , m_event(event) 60 61 , m_eventPathInitialized(false) 61 62 #ifndef NDEBUG … … 64 65 { 65 66 ASSERT(node); 67 ASSERT(m_event.get()); 68 ASSERT(!m_event->type().isNull()); // JavaScript code can create an event with an empty name, but not null. 66 69 m_view = node->document()->view(); 67 70 } 68 71 69 EventPath& EventDispatcher::ensureEventPath( Event* event)72 EventPath& EventDispatcher::ensureEventPath() 70 73 { 71 74 if (m_eventPathInitialized) 72 75 return m_eventPath; 73 76 m_eventPathInitialized = true; 74 EventRetargeter::calculateEventPath(m_node.get(), event, m_eventPath);77 EventRetargeter::calculateEventPath(m_node.get(), m_event.get(), m_eventPath); 75 78 return m_eventPath; 76 79 } … … 96 99 97 100 if (mouseEventOptions == SendMouseOverUpDownEvents) 98 EventDispatcher(node ).dispatchEvent(SimulatedMouseEvent::create(eventNames().mouseoverEvent, node->document()->defaultView(), underlyingEvent));101 EventDispatcher(node, SimulatedMouseEvent::create(eventNames().mouseoverEvent, node->document()->defaultView(), underlyingEvent)).dispatch(); 99 102 100 103 if (mouseEventOptions != SendNoEvents) 101 EventDispatcher(node ).dispatchEvent(SimulatedMouseEvent::create(eventNames().mousedownEvent, node->document()->defaultView(), underlyingEvent));104 EventDispatcher(node, SimulatedMouseEvent::create(eventNames().mousedownEvent, node->document()->defaultView(), underlyingEvent)).dispatch(); 102 105 node->setActive(true, visualOptions == ShowPressedLook); 103 106 if (mouseEventOptions != SendNoEvents) 104 EventDispatcher(node ).dispatchEvent(SimulatedMouseEvent::create(eventNames().mouseupEvent, node->document()->defaultView(), underlyingEvent));107 EventDispatcher(node, SimulatedMouseEvent::create(eventNames().mouseupEvent, node->document()->defaultView(), underlyingEvent)).dispatch(); 105 108 node->setActive(false); 106 109 107 110 // always send click 108 EventDispatcher(node ).dispatchEvent(SimulatedMouseEvent::create(eventNames().clickEvent, node->document()->defaultView(), underlyingEvent));111 EventDispatcher(node, SimulatedMouseEvent::create(eventNames().clickEvent, node->document()->defaultView(), underlyingEvent)).dispatch(); 109 112 110 113 gNodesDispatchingSimulatedClicks->remove(node); 111 114 } 112 115 113 bool EventDispatcher::dispatch Event(PassRefPtr<Event> prpEvent)116 bool EventDispatcher::dispatch() 114 117 { 115 118 #ifndef NDEBUG … … 117 120 m_eventDispatched = true; 118 121 #endif 119 RefPtr<Event> event = prpEvent;120 122 ChildNodesLazySnapshot::takeChildNodesLazySnapshot(); 121 123 122 event->setTarget(EventRetargeter::eventTargetRespectingTargetRules(m_node.get()));124 m_event->setTarget(EventRetargeter::eventTargetRespectingTargetRules(m_node.get())); 123 125 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); 124 ASSERT(event->target()); 125 ASSERT(!event->type().isNull()); // JavaScript code can create an event with an empty name, but not null. 126 ensureEventPath(event.get()); 127 WindowEventContext windowEventContext(event.get(), m_node.get(), topEventContext()); 128 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchEvent(m_node->document(), *event, windowEventContext.window(), m_node.get(), m_eventPath); 126 ASSERT(m_event->target()); 127 ensureEventPath(); 128 WindowEventContext windowEventContext(m_event.get(), m_node.get(), topEventContext()); 129 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDispatchEvent(m_node->document(), *m_event, windowEventContext.window(), m_node.get(), m_eventPath); 129 130 130 131 void* preDispatchEventHandlerResult; 131 if (dispatchEventPreProcess( event,preDispatchEventHandlerResult) == ContinueDispatching)132 if (dispatchEventAtCapturing( event,windowEventContext) == ContinueDispatching)133 if (dispatchEventAtTarget( event) == ContinueDispatching)134 dispatchEventAtBubbling( event,windowEventContext);135 dispatchEventPostProcess( event,preDispatchEventHandlerResult);132 if (dispatchEventPreProcess(preDispatchEventHandlerResult) == ContinueDispatching) 133 if (dispatchEventAtCapturing(windowEventContext) == ContinueDispatching) 134 if (dispatchEventAtTarget() == ContinueDispatching) 135 dispatchEventAtBubbling(windowEventContext); 136 dispatchEventPostProcess(preDispatchEventHandlerResult); 136 137 137 138 // Ensure that after event dispatch, the event's target object is the 138 139 // outermost shadow DOM boundary. 139 event->setTarget(windowEventContext.target());140 event->setCurrentTarget(0);140 m_event->setTarget(windowEventContext.target()); 141 m_event->setCurrentTarget(0); 141 142 InspectorInstrumentation::didDispatchEvent(cookie); 142 143 143 return ! event->defaultPrevented();144 } 145 146 inline EventDispatchContinuation EventDispatcher::dispatchEventPreProcess( PassRefPtr<Event> event,void*& preDispatchEventHandlerResult)144 return !m_event->defaultPrevented(); 145 } 146 147 inline EventDispatchContinuation EventDispatcher::dispatchEventPreProcess(void*& preDispatchEventHandlerResult) 147 148 { 148 149 // Give the target node a chance to do some work before DOM event handlers get a crack. 149 preDispatchEventHandlerResult = m_node->preDispatchEventHandler( event.get());150 return (m_eventPath.isEmpty() || event->propagationStopped()) ? DoneDispatching : ContinueDispatching;151 } 152 153 inline EventDispatchContinuation EventDispatcher::dispatchEventAtCapturing( PassRefPtr<Event> event,WindowEventContext& windowEventContext)150 preDispatchEventHandlerResult = m_node->preDispatchEventHandler(m_event.get()); 151 return (m_eventPath.isEmpty() || m_event->propagationStopped()) ? DoneDispatching : ContinueDispatching; 152 } 153 154 inline EventDispatchContinuation EventDispatcher::dispatchEventAtCapturing(WindowEventContext& windowEventContext) 154 155 { 155 156 // Trigger capturing event handlers, starting at the top and working our way down. 156 event->setEventPhase(Event::CAPTURING_PHASE);157 158 if (windowEventContext.handleLocalEvents( event.get()) &&event->propagationStopped())157 m_event->setEventPhase(Event::CAPTURING_PHASE); 158 159 if (windowEventContext.handleLocalEvents(m_event.get()) && m_event->propagationStopped()) 159 160 return DoneDispatching; 160 161 … … 162 163 const EventContext& eventContext = *m_eventPath[i]; 163 164 if (eventContext.currentTargetSameAsTarget()) { 164 if ( event->bubbles())165 if (m_event->bubbles()) 165 166 continue; 166 event->setEventPhase(Event::AT_TARGET);167 m_event->setEventPhase(Event::AT_TARGET); 167 168 } else 168 event->setEventPhase(Event::CAPTURING_PHASE);169 eventContext.handleLocalEvents( event.get());170 if ( event->propagationStopped())169 m_event->setEventPhase(Event::CAPTURING_PHASE); 170 eventContext.handleLocalEvents(m_event.get()); 171 if (m_event->propagationStopped()) 171 172 return DoneDispatching; 172 173 } … … 175 176 } 176 177 177 inline EventDispatchContinuation EventDispatcher::dispatchEventAtTarget( PassRefPtr<Event> event)178 { 179 event->setEventPhase(Event::AT_TARGET);180 m_eventPath[0]->handleLocalEvents( event.get());181 return event->propagationStopped() ? DoneDispatching : ContinueDispatching;182 } 183 184 inline EventDispatchContinuation EventDispatcher::dispatchEventAtBubbling( PassRefPtr<Event> event,WindowEventContext& windowContext)185 { 186 if ( event->bubbles() && !event->cancelBubble()) {178 inline EventDispatchContinuation EventDispatcher::dispatchEventAtTarget() 179 { 180 m_event->setEventPhase(Event::AT_TARGET); 181 m_eventPath[0]->handleLocalEvents(m_event.get()); 182 return m_event->propagationStopped() ? DoneDispatching : ContinueDispatching; 183 } 184 185 inline EventDispatchContinuation EventDispatcher::dispatchEventAtBubbling(WindowEventContext& windowContext) 186 { 187 if (m_event->bubbles() && !m_event->cancelBubble()) { 187 188 // Trigger bubbling event handlers, starting at the bottom and working our way up. 188 event->setEventPhase(Event::BUBBLING_PHASE);189 m_event->setEventPhase(Event::BUBBLING_PHASE); 189 190 190 191 size_t size = m_eventPath.size(); … … 192 193 const EventContext& eventContext = *m_eventPath[i]; 193 194 if (eventContext.currentTargetSameAsTarget()) 194 event->setEventPhase(Event::AT_TARGET);195 m_event->setEventPhase(Event::AT_TARGET); 195 196 else 196 event->setEventPhase(Event::BUBBLING_PHASE);197 eventContext.handleLocalEvents( event.get());198 if ( event->propagationStopped() ||event->cancelBubble())197 m_event->setEventPhase(Event::BUBBLING_PHASE); 198 eventContext.handleLocalEvents(m_event.get()); 199 if (m_event->propagationStopped() || m_event->cancelBubble()) 199 200 return DoneDispatching; 200 201 } 201 windowContext.handleLocalEvents( event.get());202 windowContext.handleLocalEvents(m_event.get()); 202 203 } 203 204 return ContinueDispatching; 204 205 } 205 206 206 inline void EventDispatcher::dispatchEventPostProcess( PassRefPtr<Event> event,void* preDispatchEventHandlerResult)207 { 208 event->setTarget(EventRetargeter::eventTargetRespectingTargetRules(m_node.get()));209 event->setCurrentTarget(0);210 event->setEventPhase(0);207 inline void EventDispatcher::dispatchEventPostProcess(void* preDispatchEventHandlerResult) 208 { 209 m_event->setTarget(EventRetargeter::eventTargetRespectingTargetRules(m_node.get())); 210 m_event->setCurrentTarget(0); 211 m_event->setEventPhase(0); 211 212 212 213 // Pass the data from the preDispatchEventHandler to the postDispatchEventHandler. 213 m_node->postDispatchEventHandler( event.get(), preDispatchEventHandlerResult);214 m_node->postDispatchEventHandler(m_event.get(), preDispatchEventHandlerResult); 214 215 215 216 // Call default event handlers. While the DOM does have a concept of preventing 216 217 // default handling, the detail of which handlers are called is an internal 217 218 // implementation detail and not part of the DOM. 218 if (! event->defaultPrevented() && !event->defaultHandled()) {219 if (!m_event->defaultPrevented() && !m_event->defaultHandled()) { 219 220 // Non-bubbling events call only one default event handler, the one for the target. 220 m_node->defaultEventHandler( event.get());221 ASSERT(! event->defaultPrevented());222 if ( event->defaultHandled())221 m_node->defaultEventHandler(m_event.get()); 222 ASSERT(!m_event->defaultPrevented()); 223 if (m_event->defaultHandled()) 223 224 return; 224 225 // For bubbling events, call default event handlers on the same targets in the 225 226 // same order as the bubbling phase. 226 if ( event->bubbles()) {227 if (m_event->bubbles()) { 227 228 size_t size = m_eventPath.size(); 228 229 for (size_t i = 1; i < size; ++i) { 229 m_eventPath[i]->node()->defaultEventHandler( event.get());230 ASSERT(! event->defaultPrevented());231 if ( event->defaultHandled())230 m_eventPath[i]->node()->defaultEventHandler(m_event.get()); 231 ASSERT(!m_event->defaultPrevented()); 232 if (m_event->defaultHandled()) 232 233 return; 233 234 } -
trunk/Source/WebCore/dom/EventDispatcher.h
r142957 r143145 31 31 #include <wtf/Forward.h> 32 32 #include <wtf/HashMap.h> 33 #include <wtf/PassRefPtr.h> 33 34 #include <wtf/Vector.h> 34 35 … … 58 59 static void dispatchSimulatedClick(Node*, Event* underlyingEvent, SimulatedClickMouseEventOptions, SimulatedClickVisualOptions); 59 60 60 bool dispatchEvent(PassRefPtr<Event>); 61 Node* node() const; 62 EventPath& ensureEventPath(Event*); 61 bool dispatch(); 62 Node* node() const { return m_node.get(); } 63 Event* event() const { return m_event.get(); } 64 EventPath& ensureEventPath(); 63 65 64 66 private: 65 EventDispatcher(Node* );67 EventDispatcher(Node*, PassRefPtr<Event>); 66 68 const EventContext* topEventContext(); 67 69 68 EventDispatchContinuation dispatchEventPreProcess( PassRefPtr<Event>,void*& preDispatchEventHandlerResult);69 EventDispatchContinuation dispatchEventAtCapturing( PassRefPtr<Event>,WindowEventContext&);70 EventDispatchContinuation dispatchEventAtTarget( PassRefPtr<Event>);71 EventDispatchContinuation dispatchEventAtBubbling( PassRefPtr<Event>,WindowEventContext&);72 void dispatchEventPostProcess( PassRefPtr<Event>,void* preDispatchEventHandlerResult);70 EventDispatchContinuation dispatchEventPreProcess(void*& preDispatchEventHandlerResult); 71 EventDispatchContinuation dispatchEventAtCapturing(WindowEventContext&); 72 EventDispatchContinuation dispatchEventAtTarget(); 73 EventDispatchContinuation dispatchEventAtBubbling(WindowEventContext&); 74 void dispatchEventPostProcess(void* preDispatchEventHandlerResult); 73 75 74 76 EventPath m_eventPath; 75 77 RefPtr<Node> m_node; 78 RefPtr<Event> m_event; 76 79 RefPtr<FrameView> m_view; 77 80 bool m_eventPathInitialized; … … 81 84 }; 82 85 83 inline Node* EventDispatcher::node() const84 {85 return m_node.get();86 }87 88 86 } 89 87 -
trunk/Source/WebCore/dom/FocusEvent.cpp
r142957 r143145 78 78 bool FocusEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const 79 79 { 80 EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath( event()));80 EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath()); 81 81 return EventDispatchMediator::dispatchEvent(dispatcher); 82 82 } … … 94 94 bool BlurEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const 95 95 { 96 EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath( event()));96 EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath()); 97 97 return EventDispatchMediator::dispatchEvent(dispatcher); 98 98 } … … 110 110 bool FocusInEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const 111 111 { 112 EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath( event()));112 EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath()); 113 113 return EventDispatchMediator::dispatchEvent(dispatcher); 114 114 } … … 126 126 bool FocusOutEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const 127 127 { 128 EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath( event()));128 EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath()); 129 129 return EventDispatchMediator::dispatchEvent(dispatcher); 130 130 } -
trunk/Source/WebCore/dom/GestureEvent.cpp
r142057 r143145 123 123 return true; 124 124 125 dispatcher->dispatch Event(event());125 dispatcher->dispatch(); 126 126 ASSERT(!event()->defaultPrevented()); 127 127 return event()->defaultHandled() || event()->defaultPrevented(); -
trunk/Source/WebCore/dom/MouseEvent.cpp
r142957 r143145 263 263 { 264 264 if (isSyntheticMouseEvent()) { 265 EventRetargeter::adjustForMouseEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath( event()));266 return dispatcher->dispatch Event(event());265 EventRetargeter::adjustForMouseEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath()); 266 return dispatcher->dispatch(); 267 267 } 268 268 … … 276 276 277 277 EventTarget* relatedTarget = event()->relatedTarget(); 278 EventRetargeter::adjustForMouseEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath( event()));279 280 dispatcher->dispatch Event(event());278 EventRetargeter::adjustForMouseEvent(dispatcher->node(), *event(), dispatcher->ensureEventPath()); 279 280 dispatcher->dispatch(); 281 281 bool swallowEvent = event()->defaultHandled() || event()->defaultPrevented(); 282 282
Note: See TracChangeset
for help on using the changeset viewer.