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

Side by Side Diff: third_party/WebKit/Source/core/input/PointerEventManager.cpp

Issue 1968653005: Set width=height=1 of mouse like pointer events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 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
« no previous file with comments | « third_party/WebKit/Source/core/input/PointerEventManager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ElementTraversal.h"
8 #include "core/dom/shadow/FlatTreeTraversal.h" 8 #include "core/dom/shadow/FlatTreeTraversal.h"
9 #include "core/events/MouseEvent.h" 9 #include "core/events/MouseEvent.h"
10 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 158 }
159 159
160 EventTarget* PointerEventManager::getEffectiveTargetForPointerEvent( 160 EventTarget* PointerEventManager::getEffectiveTargetForPointerEvent(
161 EventTarget* target, int pointerId) 161 EventTarget* target, int pointerId)
162 { 162 {
163 if (EventTarget* capturingTarget = getCapturingNode(pointerId)) 163 if (EventTarget* capturingTarget = getCapturingNode(pointerId))
164 return capturingTarget; 164 return capturingTarget;
165 return target; 165 return target;
166 } 166 }
167 167
168 void PointerEventManager::sendMouseAndPossiblyPointerNodeTransitionEvents( 168 void PointerEventManager::sendMouseAndPossiblyPointerBoundaryEvents(
169 Node* exitedNode, 169 Node* exitedNode,
170 Node* enteredNode, 170 Node* enteredNode,
171 const PlatformMouseEvent& mouseEvent, 171 const PlatformMouseEvent& mouseEvent,
172 bool isFrameBoundaryTransition) 172 bool isFrameBoundaryTransition)
173 { 173 {
174 // Pointer event type does not matter as it will be overridden in the sendNo deTransitionEvents 174 // Mouse event type does not matter as this pointerevent will only be used
175 PointerEvent* pointerEvent = 175 // to create boundary pointer events and its type will be overridden in
176 m_pointerEventFactory.create(EventTypeNames::mouseout, mouseEvent, 176 // |sendBoundaryEvents| function.
177 PointerEvent* dummyPointerEvent =
178 m_pointerEventFactory.create(EventTypeNames::mousedown, mouseEvent,
177 nullptr, m_frame->document()->domWindow()); 179 nullptr, m_frame->document()->domWindow());
178 180
179 // TODO(crbug/545647): This state should reset with pointercancel too. 181 // TODO(crbug/545647): This state should reset with pointercancel too.
180 // This function also gets called for compat mouse events of touch at this 182 // This function also gets called for compat mouse events of touch at this
181 // stage. So if the event is not frame boundary transition it is only a 183 // stage. So if the event is not frame boundary transition it is only a
182 // compatibility mouse event and we do not need to change pointer event 184 // compatibility mouse event and we do not need to change pointer event
183 // behavior regarding preventMouseEvent state in that case. 185 // behavior regarding preventMouseEvent state in that case.
184 if (isFrameBoundaryTransition && pointerEvent->buttons() == 0 186 if (isFrameBoundaryTransition && dummyPointerEvent->buttons() == 0
185 && pointerEvent->isPrimary()) { 187 && dummyPointerEvent->isPrimary()) {
186 m_preventMouseEventForPointerType[toPointerTypeIndex( 188 m_preventMouseEventForPointerType[toPointerTypeIndex(
187 mouseEvent.pointerProperties().pointerType)] = false; 189 mouseEvent.pointerProperties().pointerType)] = false;
188 } 190 }
189 191
190 processCaptureAndPositionOfPointerEvent(pointerEvent, enteredNode, 192 processCaptureAndPositionOfPointerEvent(dummyPointerEvent, enteredNode,
191 exitedNode, mouseEvent, true, isFrameBoundaryTransition); 193 exitedNode, mouseEvent, true, isFrameBoundaryTransition);
192 } 194 }
193 195
194 void PointerEventManager::sendNodeTransitionEvents( 196 void PointerEventManager::sendBoundaryEvents(
195 EventTarget* exitedTarget, 197 EventTarget* exitedTarget,
196 EventTarget* enteredTarget, 198 EventTarget* enteredTarget,
197 PointerEvent* pointerEvent, 199 PointerEvent* pointerEvent,
198 const PlatformMouseEvent& mouseEvent, bool sendMouseEvent) 200 const PlatformMouseEvent& mouseEvent, bool sendMouseEvent)
199 { 201 {
200 if (exitedTarget == enteredTarget) 202 if (exitedTarget == enteredTarget)
201 return; 203 return;
202 204
203 if (EventTarget* capturingTarget = getCapturingNode(pointerEvent->pointerId( ))) { 205 if (EventTarget* capturingTarget = getCapturingNode(pointerEvent->pointerId( ))) {
204 if (capturingTarget == exitedTarget) 206 if (capturingTarget == exitedTarget)
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 EventTargetAttributes node = m_nodeUnderPointer.get( 319 EventTargetAttributes node = m_nodeUnderPointer.get(
318 pointerEvent->pointerId()); 320 pointerEvent->pointerId());
319 if (!target) { 321 if (!target) {
320 m_nodeUnderPointer.remove(pointerEvent->pointerId()); 322 m_nodeUnderPointer.remove(pointerEvent->pointerId());
321 } else if (target 323 } else if (target
322 != m_nodeUnderPointer.get(pointerEvent->pointerId()).target) { 324 != m_nodeUnderPointer.get(pointerEvent->pointerId()).target) {
323 m_nodeUnderPointer.set(pointerEvent->pointerId(), 325 m_nodeUnderPointer.set(pointerEvent->pointerId(),
324 EventTargetAttributes(target, false)); 326 EventTargetAttributes(target, false));
325 } 327 }
326 if (sendEvent) 328 if (sendEvent)
327 sendNodeTransitionEvents(node.target, target, pointerEvent); 329 sendBoundaryEvents(node.target, target, pointerEvent);
328 } else if (target) { 330 } else if (target) {
329 m_nodeUnderPointer.add(pointerEvent->pointerId(), 331 m_nodeUnderPointer.add(pointerEvent->pointerId(),
330 EventTargetAttributes(target, false)); 332 EventTargetAttributes(target, false));
331 if (sendEvent) 333 if (sendEvent)
332 sendNodeTransitionEvents(nullptr, target, pointerEvent); 334 sendBoundaryEvents(nullptr, target, pointerEvent);
333 } 335 }
334 } 336 }
335 337
336 void PointerEventManager::blockTouchPointers() 338 void PointerEventManager::blockTouchPointers()
337 { 339 {
338 if (m_inCanceledStateForPointerTypeTouch) 340 if (m_inCanceledStateForPointerTypeTouch)
339 return; 341 return;
340 m_inCanceledStateForPointerTypeTouch = true; 342 m_inCanceledStateForPointerTypeTouch = true;
341 343
342 Vector<int> touchPointerIds 344 Vector<int> touchPointerIds
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 if (setPointerPosition) { 571 if (setPointerPosition) {
570 isCaptureChanged = processPendingPointerCapture(pointerEvent, 572 isCaptureChanged = processPendingPointerCapture(pointerEvent,
571 hitTestTarget, mouseEvent, sendMouseEvent); 573 hitTestTarget, mouseEvent, sendMouseEvent);
572 // If there was a change in capturing processPendingPointerCapture has 574 // If there was a change in capturing processPendingPointerCapture has
573 // already taken care of transition events. So we don't need to send the 575 // already taken care of transition events. So we don't need to send the
574 // transition events here. 576 // transition events here.
575 setNodeUnderPointer(pointerEvent, hitTestTarget, !isCaptureChanged); 577 setNodeUnderPointer(pointerEvent, hitTestTarget, !isCaptureChanged);
576 } 578 }
577 if (sendMouseEvent && !isCaptureChanged) { 579 if (sendMouseEvent && !isCaptureChanged) {
578 // lastNodeUnderMouse is needed here because it is still stored in Event Handler. 580 // lastNodeUnderMouse is needed here because it is still stored in Event Handler.
579 sendNodeTransitionEvents(lastNodeUnderMouse, hitTestTarget, 581 sendBoundaryEvents(lastNodeUnderMouse, hitTestTarget,
580 pointerEvent, mouseEvent, true); 582 pointerEvent, mouseEvent, true);
581 } 583 }
582 } 584 }
583 585
584 bool PointerEventManager::processPendingPointerCapture( 586 bool PointerEventManager::processPendingPointerCapture(
585 PointerEvent* pointerEvent, 587 PointerEvent* pointerEvent,
586 EventTarget* hitTestTarget, 588 EventTarget* hitTestTarget,
587 const PlatformMouseEvent& mouseEvent, bool sendMouseEvent) 589 const PlatformMouseEvent& mouseEvent, bool sendMouseEvent)
588 { 590 {
589 int pointerId = pointerEvent->pointerId(); 591 int pointerId = pointerEvent->pointerId();
(...skipping 10 matching lines...) Expand all
600 pointerCaptureTarget != pendingPointerCaptureTarget; 602 pointerCaptureTarget != pendingPointerCaptureTarget;
601 603
602 if (isCaptureChanged) { 604 if (isCaptureChanged) {
603 if ((hitTestTarget != nodeUnderPointerAtt.target 605 if ((hitTestTarget != nodeUnderPointerAtt.target
604 || (pendingPointerCaptureTarget 606 || (pendingPointerCaptureTarget
605 && pendingPointerCaptureTarget != nodeUnderPointerAtt.target)) 607 && pendingPointerCaptureTarget != nodeUnderPointerAtt.target))
606 && nodeUnderPointerAtt.hasRecievedOverEvent) { 608 && nodeUnderPointerAtt.hasRecievedOverEvent) {
607 if (sendMouseEvent) { 609 if (sendMouseEvent) {
608 // Send pointer event transitions as the line after this if 610 // Send pointer event transitions as the line after this if
609 // block sends the mouse events 611 // block sends the mouse events
610 sendNodeTransitionEvents(nodeUnderPointerAtt.target, nullptr, 612 sendBoundaryEvents(nodeUnderPointerAtt.target, nullptr,
611 pointerEvent); 613 pointerEvent);
612 } 614 }
613 sendNodeTransitionEvents(nodeUnderPointerAtt.target, nullptr, 615 sendBoundaryEvents(nodeUnderPointerAtt.target, nullptr,
614 pointerEvent, mouseEvent, sendMouseEvent); 616 pointerEvent, mouseEvent, sendMouseEvent);
615 } 617 }
616 if (pointerCaptureTarget) { 618 if (pointerCaptureTarget) {
617 // Re-target lostpointercapture to the document when the element is 619 // Re-target lostpointercapture to the document when the element is
618 // no longer participating in the tree. 620 // no longer participating in the tree.
619 EventTarget* target = pointerCaptureTarget; 621 EventTarget* target = pointerCaptureTarget;
620 if (target->toNode() 622 if (target->toNode()
621 && !target->toNode()->inShadowIncludingDocument()) { 623 && !target->toNode()->inShadowIncludingDocument()) {
622 target = target->toNode()->ownerDocument(); 624 target = target->toNode()->ownerDocument();
623 } 625 }
624 dispatchPointerEvent(target, 626 dispatchPointerEvent(target,
625 m_pointerEventFactory.createPointerCaptureEvent( 627 m_pointerEventFactory.createPointerCaptureEvent(
626 pointerEvent, EventTypeNames::lostpointercapture)); 628 pointerEvent, EventTypeNames::lostpointercapture));
627 } 629 }
628 } 630 }
629 631
630 // Set pointerCaptureTarget from pendingPointerCaptureTarget. This does 632 // Set pointerCaptureTarget from pendingPointerCaptureTarget. This does
631 // affect the behavior of sendNodeTransitionEvents function. So the 633 // affect the behavior of sendBoundaryEvents function. So the
632 // ordering of the surrounding blocks of code for sending transition events 634 // ordering of the surrounding blocks of code for sending transition events
633 // are important. 635 // are important.
634 if (pendingPointerCaptureTarget) 636 if (pendingPointerCaptureTarget)
635 m_pointerCaptureTarget.set(pointerId, pendingPointerCaptureTarget); 637 m_pointerCaptureTarget.set(pointerId, pendingPointerCaptureTarget);
636 else 638 else
637 m_pointerCaptureTarget.remove(pointerId); 639 m_pointerCaptureTarget.remove(pointerId);
638 640
639 if (isCaptureChanged) { 641 if (isCaptureChanged) {
640 dispatchPointerEvent(pendingPointerCaptureTarget, 642 dispatchPointerEvent(pendingPointerCaptureTarget,
641 m_pointerEventFactory.createPointerCaptureEvent( 643 m_pointerEventFactory.createPointerCaptureEvent(
642 pointerEvent, EventTypeNames::gotpointercapture)); 644 pointerEvent, EventTypeNames::gotpointercapture));
643 if ((pendingPointerCaptureTarget == hitTestTarget 645 if ((pendingPointerCaptureTarget == hitTestTarget
644 || !pendingPointerCaptureTarget) 646 || !pendingPointerCaptureTarget)
645 && (nodeUnderPointerAtt.target != hitTestTarget 647 && (nodeUnderPointerAtt.target != hitTestTarget
646 || !nodeUnderPointerAtt.hasRecievedOverEvent)) { 648 || !nodeUnderPointerAtt.hasRecievedOverEvent)) {
647 if (sendMouseEvent) { 649 if (sendMouseEvent) {
648 // Send pointer event transitions as the line after this if 650 // Send pointer event transitions as the line after this if
649 // block sends the mouse events 651 // block sends the mouse events
650 sendNodeTransitionEvents(nullptr, hitTestTarget, pointerEvent); 652 sendBoundaryEvents(nullptr, hitTestTarget, pointerEvent);
651 } 653 }
652 sendNodeTransitionEvents(nullptr, hitTestTarget, pointerEvent, 654 sendBoundaryEvents(nullptr, hitTestTarget, pointerEvent,
653 mouseEvent, sendMouseEvent); 655 mouseEvent, sendMouseEvent);
654 } 656 }
655 } 657 }
656 return isCaptureChanged; 658 return isCaptureChanged;
657 } 659 }
658 660
659 void PointerEventManager::removeTargetFromPointerCapturingMapping( 661 void PointerEventManager::removeTargetFromPointerCapturingMapping(
660 PointerCapturingMap& map, const EventTarget* target) 662 PointerCapturingMap& map, const EventTarget* target)
661 { 663 {
662 // We could have kept a reverse mapping to make this deletion possibly 664 // We could have kept a reverse mapping to make this deletion possibly
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 { 732 {
731 visitor->trace(m_frame); 733 visitor->trace(m_frame);
732 visitor->trace(m_nodeUnderPointer); 734 visitor->trace(m_nodeUnderPointer);
733 visitor->trace(m_pointerCaptureTarget); 735 visitor->trace(m_pointerCaptureTarget);
734 visitor->trace(m_pendingPointerCaptureTarget); 736 visitor->trace(m_pendingPointerCaptureTarget);
735 visitor->trace(m_touchEventManager); 737 visitor->trace(m_touchEventManager);
736 } 738 }
737 739
738 740
739 } // namespace blink 741 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/PointerEventManager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698