OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "core/input/PointerEventManager.h" | 5 #include "core/input/PointerEventManager.h" |
6 | 6 |
| 7 #include "core/dom/ElementTraversal.h" |
7 #include "core/dom/shadow/FlatTreeTraversal.h" | 8 #include "core/dom/shadow/FlatTreeTraversal.h" |
8 #include "core/events/MouseEvent.h" | 9 #include "core/events/MouseEvent.h" |
| 10 #include "core/html/HTMLCanvasElement.h" |
9 #include "core/input/EventHandler.h" | 11 #include "core/input/EventHandler.h" |
10 | 12 |
11 namespace blink { | 13 namespace blink { |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 const AtomicString& pointerEventNameForTouchPointState(PlatformTouchPoint::Touch
State state) | 17 const AtomicString& pointerEventNameForTouchPointState(PlatformTouchPoint::Touch
State state) |
16 { | 18 { |
17 switch (state) { | 19 switch (state) { |
18 case PlatformTouchPoint::TouchReleased: | 20 case PlatformTouchPoint::TouchReleased: |
(...skipping 30 matching lines...) Expand all Loading... |
49 Node* targetNode = target->toNode(); | 51 Node* targetNode = target->toNode(); |
50 MouseEvent* event = MouseEvent::create(mouseEventType, | 52 MouseEvent* event = MouseEvent::create(mouseEventType, |
51 targetNode->document().domWindow(), mouseEvent, detail, | 53 targetNode->document().domWindow(), mouseEvent, detail, |
52 relatedTarget ? relatedTarget->toNode() : nullptr); | 54 relatedTarget ? relatedTarget->toNode() : nullptr); |
53 DispatchEventResult dispatchResult = target->dispatchEvent(event); | 55 DispatchEventResult dispatchResult = target->dispatchEvent(event); |
54 return EventHandler::toWebInputEventResult(dispatchResult); | 56 return EventHandler::toWebInputEventResult(dispatchResult); |
55 } | 57 } |
56 return WebInputEventResult::NotHandled; | 58 return WebInputEventResult::NotHandled; |
57 } | 59 } |
58 | 60 |
| 61 PlatformMouseEvent mouseEventWithRegion(Node* node, const PlatformMouseEvent& mo
useEvent) |
| 62 { |
| 63 if (!node->isElementNode()) |
| 64 return mouseEvent; |
| 65 |
| 66 Element* element = toElement(node); |
| 67 if (!element->isInCanvasSubtree()) |
| 68 return mouseEvent; |
| 69 |
| 70 HTMLCanvasElement* canvas = Traversal<HTMLCanvasElement>::firstAncestorOrSel
f(*element); |
| 71 // In this case, the event target is canvas and mouse rerouting doesn't happ
en. |
| 72 if (canvas == element) |
| 73 return mouseEvent; |
| 74 String region = canvas->getIdFromControl(element); |
| 75 PlatformMouseEvent newMouseEvent = mouseEvent; |
| 76 newMouseEvent.setRegion(region); |
| 77 return newMouseEvent; |
| 78 } |
| 79 |
59 } // namespace | 80 } // namespace |
60 | 81 |
61 WebInputEventResult PointerEventManager::dispatchPointerEvent( | 82 WebInputEventResult PointerEventManager::dispatchPointerEvent( |
62 EventTarget* target, | 83 EventTarget* target, |
63 PointerEvent* pointerEvent, | 84 PointerEvent* pointerEvent, |
64 bool checkForListener) | 85 bool checkForListener) |
65 { | 86 { |
66 if (!target) | 87 if (!target) |
67 return WebInputEventResult::NotHandled; | 88 return WebInputEventResult::NotHandled; |
68 | 89 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 return; | 162 return; |
142 } | 163 } |
143 | 164 |
144 // Dispatch pointerout/mouseout events | 165 // Dispatch pointerout/mouseout events |
145 if (isInDocument(exitedTarget)) { | 166 if (isInDocument(exitedTarget)) { |
146 if (!sendMouseEvent) { | 167 if (!sendMouseEvent) { |
147 dispatchPointerEvent(exitedTarget, m_pointerEventFactory.createPoint
erTransitionEvent( | 168 dispatchPointerEvent(exitedTarget, m_pointerEventFactory.createPoint
erTransitionEvent( |
148 pointerEvent, EventTypeNames::pointerout, enteredTarget)); | 169 pointerEvent, EventTypeNames::pointerout, enteredTarget)); |
149 } else { | 170 } else { |
150 dispatchMouseEvent(exitedTarget, | 171 dispatchMouseEvent(exitedTarget, |
151 EventTypeNames::mouseout, mouseEvent, enteredTarget); | 172 EventTypeNames::mouseout, |
| 173 mouseEventWithRegion(exitedTarget->toNode(), mouseEvent), |
| 174 enteredTarget); |
152 } | 175 } |
153 } | 176 } |
154 | 177 |
155 // Create lists of all exited/entered ancestors, locate the common ancestor | 178 // Create lists of all exited/entered ancestors, locate the common ancestor |
156 HeapVector<Member<Node>, 32> exitedAncestors; | 179 HeapVector<Member<Node>, 32> exitedAncestors; |
157 HeapVector<Member<Node>, 32> enteredAncestors; | 180 HeapVector<Member<Node>, 32> enteredAncestors; |
158 if (isInDocument(exitedTarget)) { | 181 if (isInDocument(exitedTarget)) { |
159 Node* exitedNode = exitedTarget->toNode(); | 182 Node* exitedNode = exitedTarget->toNode(); |
160 exitedNode->updateDistribution(); | 183 exitedNode->updateDistribution(); |
161 for (Node* node = exitedNode; node; node = FlatTreeTraversal::parent(*no
de)) | 184 for (Node* node = exitedNode; node; node = FlatTreeTraversal::parent(*no
de)) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 233 |
211 // Dispatch pointerleave/mouseleave events, in child-to-parent order. | 234 // Dispatch pointerleave/mouseleave events, in child-to-parent order. |
212 for (size_t j = 0; j < exitedAncestorIndex; j++) { | 235 for (size_t j = 0; j < exitedAncestorIndex; j++) { |
213 if (!sendMouseEvent) { | 236 if (!sendMouseEvent) { |
214 dispatchPointerEvent(exitedAncestors[j].get(), | 237 dispatchPointerEvent(exitedAncestors[j].get(), |
215 m_pointerEventFactory.createPointerTransitionEvent( | 238 m_pointerEventFactory.createPointerTransitionEvent( |
216 pointerEvent, EventTypeNames::pointerleave, enteredTarget), | 239 pointerEvent, EventTypeNames::pointerleave, enteredTarget), |
217 !exitedNodeHasCapturingAncestor); | 240 !exitedNodeHasCapturingAncestor); |
218 } else { | 241 } else { |
219 dispatchMouseEvent(exitedAncestors[j].get(), | 242 dispatchMouseEvent(exitedAncestors[j].get(), |
220 EventTypeNames::mouseleave, mouseEvent, enteredTarget, | 243 EventTypeNames::mouseleave, |
221 0, !exitedNodeHasCapturingAncestor); | 244 mouseEventWithRegion(exitedTarget->toNode(), mouseEvent), |
| 245 enteredTarget, 0, !exitedNodeHasCapturingAncestor); |
222 } | 246 } |
223 } | 247 } |
224 | 248 |
225 // Dispatch pointerover/mouseover. | 249 // Dispatch pointerover/mouseover. |
226 if (isInDocument(enteredTarget)) { | 250 if (isInDocument(enteredTarget)) { |
227 if (!sendMouseEvent) { | 251 if (!sendMouseEvent) { |
228 dispatchPointerEvent(enteredTarget, m_pointerEventFactory.createPoin
terTransitionEvent( | 252 dispatchPointerEvent(enteredTarget, m_pointerEventFactory.createPoin
terTransitionEvent( |
229 pointerEvent, EventTypeNames::pointerover, exitedTarget)); | 253 pointerEvent, EventTypeNames::pointerover, exitedTarget)); |
230 } else { | 254 } else { |
231 dispatchMouseEvent(enteredTarget, | 255 dispatchMouseEvent(enteredTarget, |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 | 594 |
571 DEFINE_TRACE(PointerEventManager) | 595 DEFINE_TRACE(PointerEventManager) |
572 { | 596 { |
573 visitor->trace(m_nodeUnderPointer); | 597 visitor->trace(m_nodeUnderPointer); |
574 visitor->trace(m_pointerCaptureTarget); | 598 visitor->trace(m_pointerCaptureTarget); |
575 visitor->trace(m_pendingPointerCaptureTarget); | 599 visitor->trace(m_pendingPointerCaptureTarget); |
576 } | 600 } |
577 | 601 |
578 | 602 |
579 } // namespace blink | 603 } // namespace blink |
OLD | NEW |