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

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: 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
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 AbstractView* view, 172 AbstractView* view,
173 bool isFrameBoundaryTransition) 173 bool isFrameBoundaryTransition)
174 { 174 {
175 // Pointer event type does not matter as it will be overridden in the sendNo deTransitionEvents 175 // Pointer event type does not matter as it will be overridden in the sendBo undaryEvents
176 PointerEvent* pointerEvent = 176 PointerEvent* pointerEvent =
177 m_pointerEventFactory.create(EventTypeNames::mouseout, mouseEvent, 177 m_pointerEventFactory.create(EventTypeNames::mousedown, mouseEvent,
178 nullptr, view); 178 nullptr, view);
179 179
180 // TODO(crbug/545647): This state should reset with pointercancel too. 180 // TODO(crbug/545647): This state should reset with pointercancel too.
181 // This function also gets called for compat mouse events of touch at this 181 // This function also gets called for compat mouse events of touch at this
182 // stage. So if the event is not frame boundary transition it is only a 182 // stage. So if the event is not frame boundary transition it is only a
183 // compatibility mouse event and we do not need to change pointer event 183 // compatibility mouse event and we do not need to change pointer event
184 // behavior regarding preventMouseEvent state in that case. 184 // behavior regarding preventMouseEvent state in that case.
185 if (isFrameBoundaryTransition && pointerEvent->buttons() == 0 185 if (isFrameBoundaryTransition && pointerEvent->buttons() == 0
186 && pointerEvent->isPrimary()) { 186 && pointerEvent->isPrimary()) {
187 m_preventMouseEventForPointerType[toPointerTypeIndex( 187 m_preventMouseEventForPointerType[toPointerTypeIndex(
188 mouseEvent.pointerProperties().pointerType)] = false; 188 mouseEvent.pointerProperties().pointerType)] = false;
189 } 189 }
190 190
191 processCaptureAndPositionOfPointerEvent(pointerEvent, enteredNode, 191 processCaptureAndPositionOfPointerEvent(pointerEvent, enteredNode,
192 exitedNode, mouseEvent, true, isFrameBoundaryTransition); 192 exitedNode, mouseEvent, true, isFrameBoundaryTransition);
193 } 193 }
194 194
195 void PointerEventManager::sendNodeTransitionEvents( 195 void PointerEventManager::sendBoundaryEvents(
196 EventTarget* exitedTarget, 196 EventTarget* exitedTarget,
197 EventTarget* enteredTarget, 197 EventTarget* enteredTarget,
198 PointerEvent* pointerEvent, 198 PointerEvent* pointerEvent,
199 const PlatformMouseEvent& mouseEvent, bool sendMouseEvent) 199 const PlatformMouseEvent& mouseEvent, bool sendMouseEvent)
200 { 200 {
201 if (exitedTarget == enteredTarget) 201 if (exitedTarget == enteredTarget)
202 return; 202 return;
203 203
204 if (EventTarget* capturingTarget = getCapturingNode(pointerEvent->pointerId( ))) { 204 if (EventTarget* capturingTarget = getCapturingNode(pointerEvent->pointerId( ))) {
205 if (capturingTarget == exitedTarget) 205 if (capturingTarget == exitedTarget)
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 EventTargetAttributes node = m_nodeUnderPointer.get( 318 EventTargetAttributes node = m_nodeUnderPointer.get(
319 pointerEvent->pointerId()); 319 pointerEvent->pointerId());
320 if (!target) { 320 if (!target) {
321 m_nodeUnderPointer.remove(pointerEvent->pointerId()); 321 m_nodeUnderPointer.remove(pointerEvent->pointerId());
322 } else if (target 322 } else if (target
323 != m_nodeUnderPointer.get(pointerEvent->pointerId()).target) { 323 != m_nodeUnderPointer.get(pointerEvent->pointerId()).target) {
324 m_nodeUnderPointer.set(pointerEvent->pointerId(), 324 m_nodeUnderPointer.set(pointerEvent->pointerId(),
325 EventTargetAttributes(target, false)); 325 EventTargetAttributes(target, false));
326 } 326 }
327 if (sendEvent) 327 if (sendEvent)
328 sendNodeTransitionEvents(node.target, target, pointerEvent); 328 sendBoundaryEvents(node.target, target, pointerEvent);
329 } else if (target) { 329 } else if (target) {
330 m_nodeUnderPointer.add(pointerEvent->pointerId(), 330 m_nodeUnderPointer.add(pointerEvent->pointerId(),
331 EventTargetAttributes(target, false)); 331 EventTargetAttributes(target, false));
332 if (sendEvent) 332 if (sendEvent)
333 sendNodeTransitionEvents(nullptr, target, pointerEvent); 333 sendBoundaryEvents(nullptr, target, pointerEvent);
334 } 334 }
335 } 335 }
336 336
337 void PointerEventManager::blockTouchPointers() 337 void PointerEventManager::blockTouchPointers()
338 { 338 {
339 if (m_inCanceledStateForPointerTypeTouch) 339 if (m_inCanceledStateForPointerTypeTouch)
340 return; 340 return;
341 m_inCanceledStateForPointerTypeTouch = true; 341 m_inCanceledStateForPointerTypeTouch = true;
342 342
343 Vector<int> touchPointerIds 343 Vector<int> touchPointerIds
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 if (setPointerPosition) { 571 if (setPointerPosition) {
572 isCaptureChanged = processPendingPointerCapture(pointerEvent, 572 isCaptureChanged = processPendingPointerCapture(pointerEvent,
573 hitTestTarget, mouseEvent, sendMouseEvent); 573 hitTestTarget, mouseEvent, sendMouseEvent);
574 // If there was a change in capturing processPendingPointerCapture has 574 // If there was a change in capturing processPendingPointerCapture has
575 // 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
576 // transition events here. 576 // transition events here.
577 setNodeUnderPointer(pointerEvent, hitTestTarget, !isCaptureChanged); 577 setNodeUnderPointer(pointerEvent, hitTestTarget, !isCaptureChanged);
578 } 578 }
579 if (sendMouseEvent && !isCaptureChanged) { 579 if (sendMouseEvent && !isCaptureChanged) {
580 // 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.
581 sendNodeTransitionEvents(lastNodeUnderMouse, hitTestTarget, 581 sendBoundaryEvents(lastNodeUnderMouse, hitTestTarget,
582 pointerEvent, mouseEvent, true); 582 pointerEvent, mouseEvent, true);
583 } 583 }
584 } 584 }
585 585
586 bool PointerEventManager::processPendingPointerCapture( 586 bool PointerEventManager::processPendingPointerCapture(
587 PointerEvent* pointerEvent, 587 PointerEvent* pointerEvent,
588 EventTarget* hitTestTarget, 588 EventTarget* hitTestTarget,
589 const PlatformMouseEvent& mouseEvent, bool sendMouseEvent) 589 const PlatformMouseEvent& mouseEvent, bool sendMouseEvent)
590 { 590 {
591 int pointerId = pointerEvent->pointerId(); 591 int pointerId = pointerEvent->pointerId();
(...skipping 10 matching lines...) Expand all
602 pointerCaptureTarget != pendingPointerCaptureTarget; 602 pointerCaptureTarget != pendingPointerCaptureTarget;
603 603
604 if (isCaptureChanged) { 604 if (isCaptureChanged) {
605 if ((hitTestTarget != nodeUnderPointerAtt.target 605 if ((hitTestTarget != nodeUnderPointerAtt.target
606 || (pendingPointerCaptureTarget 606 || (pendingPointerCaptureTarget
607 && pendingPointerCaptureTarget != nodeUnderPointerAtt.target)) 607 && pendingPointerCaptureTarget != nodeUnderPointerAtt.target))
608 && nodeUnderPointerAtt.hasRecievedOverEvent) { 608 && nodeUnderPointerAtt.hasRecievedOverEvent) {
609 if (sendMouseEvent) { 609 if (sendMouseEvent) {
610 // Send pointer event transitions as the line after this if 610 // Send pointer event transitions as the line after this if
611 // block sends the mouse events 611 // block sends the mouse events
612 sendNodeTransitionEvents(nodeUnderPointerAtt.target, nullptr, 612 sendBoundaryEvents(nodeUnderPointerAtt.target, nullptr,
613 pointerEvent); 613 pointerEvent);
614 } 614 }
615 sendNodeTransitionEvents(nodeUnderPointerAtt.target, nullptr, 615 sendBoundaryEvents(nodeUnderPointerAtt.target, nullptr,
616 pointerEvent, mouseEvent, sendMouseEvent); 616 pointerEvent, mouseEvent, sendMouseEvent);
617 } 617 }
618 if (pointerCaptureTarget) { 618 if (pointerCaptureTarget) {
619 // Re-target lostpointercapture to the document when the element is 619 // Re-target lostpointercapture to the document when the element is
620 // no longer participating in the tree. 620 // no longer participating in the tree.
621 EventTarget* target = pointerCaptureTarget; 621 EventTarget* target = pointerCaptureTarget;
622 if (target->toNode() 622 if (target->toNode()
623 && !target->toNode()->inShadowIncludingDocument()) { 623 && !target->toNode()->inShadowIncludingDocument()) {
624 target = target->toNode()->ownerDocument(); 624 target = target->toNode()->ownerDocument();
625 } 625 }
626 dispatchPointerEvent(target, 626 dispatchPointerEvent(target,
627 m_pointerEventFactory.createPointerCaptureEvent( 627 m_pointerEventFactory.createPointerCaptureEvent(
628 pointerEvent, EventTypeNames::lostpointercapture)); 628 pointerEvent, EventTypeNames::lostpointercapture));
629 } 629 }
630 } 630 }
631 631
632 // Set pointerCaptureTarget from pendingPointerCaptureTarget. This does 632 // Set pointerCaptureTarget from pendingPointerCaptureTarget. This does
633 // affect the behavior of sendNodeTransitionEvents function. So the 633 // affect the behavior of sendBoundaryEvents function. So the
634 // ordering of the surrounding blocks of code for sending transition events 634 // ordering of the surrounding blocks of code for sending transition events
635 // are important. 635 // are important.
636 if (pendingPointerCaptureTarget) 636 if (pendingPointerCaptureTarget)
637 m_pointerCaptureTarget.set(pointerId, pendingPointerCaptureTarget); 637 m_pointerCaptureTarget.set(pointerId, pendingPointerCaptureTarget);
638 else 638 else
639 m_pointerCaptureTarget.remove(pointerId); 639 m_pointerCaptureTarget.remove(pointerId);
640 640
641 if (isCaptureChanged) { 641 if (isCaptureChanged) {
642 dispatchPointerEvent(pendingPointerCaptureTarget, 642 dispatchPointerEvent(pendingPointerCaptureTarget,
643 m_pointerEventFactory.createPointerCaptureEvent( 643 m_pointerEventFactory.createPointerCaptureEvent(
644 pointerEvent, EventTypeNames::gotpointercapture)); 644 pointerEvent, EventTypeNames::gotpointercapture));
645 if ((pendingPointerCaptureTarget == hitTestTarget 645 if ((pendingPointerCaptureTarget == hitTestTarget
646 || !pendingPointerCaptureTarget) 646 || !pendingPointerCaptureTarget)
647 && (nodeUnderPointerAtt.target != hitTestTarget 647 && (nodeUnderPointerAtt.target != hitTestTarget
648 || !nodeUnderPointerAtt.hasRecievedOverEvent)) { 648 || !nodeUnderPointerAtt.hasRecievedOverEvent)) {
649 if (sendMouseEvent) { 649 if (sendMouseEvent) {
650 // Send pointer event transitions as the line after this if 650 // Send pointer event transitions as the line after this if
651 // block sends the mouse events 651 // block sends the mouse events
652 sendNodeTransitionEvents(nullptr, hitTestTarget, pointerEvent); 652 sendBoundaryEvents(nullptr, hitTestTarget, pointerEvent);
653 } 653 }
654 sendNodeTransitionEvents(nullptr, hitTestTarget, pointerEvent, 654 sendBoundaryEvents(nullptr, hitTestTarget, pointerEvent,
655 mouseEvent, sendMouseEvent); 655 mouseEvent, sendMouseEvent);
656 } 656 }
657 } 657 }
658 return isCaptureChanged; 658 return isCaptureChanged;
659 } 659 }
660 660
661 void PointerEventManager::removeTargetFromPointerCapturingMapping( 661 void PointerEventManager::removeTargetFromPointerCapturingMapping(
662 PointerCapturingMap& map, const EventTarget* target) 662 PointerCapturingMap& map, const EventTarget* target)
663 { 663 {
664 // 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
732 { 732 {
733 visitor->trace(m_frame); 733 visitor->trace(m_frame);
734 visitor->trace(m_nodeUnderPointer); 734 visitor->trace(m_nodeUnderPointer);
735 visitor->trace(m_pointerCaptureTarget); 735 visitor->trace(m_pointerCaptureTarget);
736 visitor->trace(m_pendingPointerCaptureTarget); 736 visitor->trace(m_pendingPointerCaptureTarget);
737 visitor->trace(m_touchEventManager); 737 visitor->trace(m_touchEventManager);
738 } 738 }
739 739
740 740
741 } // namespace blink 741 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698