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

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

Issue 1892653003: Extract touch handling logic from EventHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TODO 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/html/HTMLCanvasElement.h" 11 #include "core/html/HTMLCanvasElement.h"
11 #include "core/input/EventHandler.h" 12 #include "core/input/EventHandler.h"
13 #include "platform/PlatformTouchEvent.h"
12 14
13 namespace blink { 15 namespace blink {
14 16
15 namespace { 17 namespace {
16 18
17 size_t toPointerTypeIndex(WebPointerProperties::PointerType t) { return static_c ast<size_t>(t); } 19 size_t toPointerTypeIndex(WebPointerProperties::PointerType t) { return static_c ast<size_t>(t); }
18 20
19 const AtomicString& pointerEventNameForTouchPointState(PlatformTouchPoint::Touch State state) 21 const AtomicString& pointerEventNameForTouchPointState(PlatformTouchPoint::Touch State state)
20 { 22 {
21 switch (state) { 23 switch (state) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 370
369 removePointer(pointerEvent); 371 removePointer(pointerEvent);
370 } 372 }
371 } 373 }
372 374
373 void PointerEventManager::unblockTouchPointers() 375 void PointerEventManager::unblockTouchPointers()
374 { 376 {
375 m_inCanceledStateForPointerTypeTouch = false; 377 m_inCanceledStateForPointerTypeTouch = false;
376 } 378 }
377 379
380 WebInputEventResult PointerEventManager::handleTouchEvents(
381 const PlatformTouchEvent& event)
382 {
383
384 if (event.type() == PlatformEvent::TouchScrollStarted) {
385 blockTouchPointers();
386 return WebInputEventResult::HandledSystem;
387 }
388
389 bool newTouchSequence = true;
390 for (const auto &touchPoint : event.touchPoints()) {
391 if (touchPoint.state() != PlatformTouchPoint::TouchPressed) {
392 newTouchSequence = false;
393 break;
394 }
395 }
396 if (newTouchSequence)
397 unblockTouchPointers();
398 HeapVector<TouchEventManager::TouchInfo> touchInfos;
399
400 // TODO(crbug.com/606822): This will be moved after pointer events so
401 // pointer event operations will get the first shot to fill up this array.
402 if (!m_touchEventManager.generateTouchInfosAfterHittest(event, touchInfos))
403 return WebInputEventResult::NotHandled;
404
405 dispatchTouchPointerEvents(event, touchInfos);
406
407 return m_touchEventManager.handleTouchEvent(event, touchInfos);
408 }
409
410 void PointerEventManager::dispatchTouchPointerEvents(
411 const PlatformTouchEvent& event,
412 HeapVector<TouchEventManager::TouchInfo>& touchInfos)
413 {
414 if (!RuntimeEnabledFeatures::pointerEventEnabled())
415 return;
416
417 if (m_inCanceledStateForPointerTypeTouch)
418 return;
419
420 // Iterate through the touch points, sending PointerEvents to the targets as required.
421 for (auto& touchInfo: touchInfos) {
422 const PlatformTouchPoint &touchPoint = touchInfo.point;
423 WebInputEventResult result = WebInputEventResult::NotHandled;
424 // Do not send pointer events for stationary touches.
425 if (touchPoint.state() != PlatformTouchPoint::TouchStationary) {
426 // TODO(crbug.com/608394): The adjustedPagePoint should be converted
427 // to client coordinates.
428 PointerEvent* pointerEvent = m_pointerEventFactory.create(
429 pointerEventNameForTouchPointState(touchPoint.state()),
430 touchPoint, event.getModifiers(),
431 touchInfo.adjustedRadius,
432 touchInfo.adjustedPagePoint);
433
434 // Consume the touch point if its pointer event is anything but NotH andled
435 // (e.g. preventDefault is called in the listener for the pointer ev ent).
436 result = sendTouchPointerEvent(touchInfo.touchNode, pointerEvent);
437 touchInfo.consumed = result != WebInputEventResult::NotHandled;
438 }
439 }
440 }
441
378 WebInputEventResult PointerEventManager::sendTouchPointerEvent( 442 WebInputEventResult PointerEventManager::sendTouchPointerEvent(
379 EventTarget* target, 443 EventTarget* target, PointerEvent* pointerEvent)
380 const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers,
381 const double width, const double height,
382 const double clientX, const double clientY)
383 { 444 {
384 if (m_inCanceledStateForPointerTypeTouch) 445 if (m_inCanceledStateForPointerTypeTouch)
385 return WebInputEventResult::NotHandled; 446 return WebInputEventResult::NotHandled;
386 447
387 PointerEvent* pointerEvent =
388 m_pointerEventFactory.create(
389 pointerEventNameForTouchPointState(touchPoint.state()),
390 touchPoint, modifiers, width, height, clientX, clientY);
391
392 processCaptureAndPositionOfPointerEvent(pointerEvent, target); 448 processCaptureAndPositionOfPointerEvent(pointerEvent, target);
393 449
394 // TODO(nzolghadr): crbug.com/579553 dealing with implicit touch capturing v s pointer event capturing 450 // TODO(nzolghadr): crbug.com/579553 dealing with implicit touch capturing v s pointer event capturing
395 WebInputEventResult result = dispatchPointerEvent( 451 WebInputEventResult result = dispatchPointerEvent(
396 getEffectiveTargetForPointerEvent(target, pointerEvent->pointerId()), 452 getEffectiveTargetForPointerEvent(target, pointerEvent->pointerId()),
397 pointerEvent); 453 pointerEvent);
398 454
399 // Setting the implicit capture for touch 455 // Setting the implicit capture for touch
400 if (touchPoint.state() == PlatformTouchPoint::TouchPressed) 456 if (pointerEvent->type() == EventTypeNames::pointerdown)
401 setPointerCapture(pointerEvent->pointerId(), target); 457 setPointerCapture(pointerEvent->pointerId(), target);
402 458
403 if (touchPoint.state() == PlatformTouchPoint::TouchReleased 459 if (pointerEvent->type() == EventTypeNames::pointerup
404 || touchPoint.state() == PlatformTouchPoint::TouchCancelled) { 460 || pointerEvent->type() == EventTypeNames::pointercancel) {
405 releasePointerCapture(pointerEvent->pointerId()); 461 releasePointerCapture(pointerEvent->pointerId());
406 462
407 // Sending the leave/out events and lostpointercapture 463 // Sending the leave/out events and lostpointercapture
408 // because the next touch event will have a different id. So delayed 464 // because the next touch event will have a different id. So delayed
409 // sending of lostpointercapture won't work here. 465 // sending of lostpointercapture won't work here.
410 processCaptureAndPositionOfPointerEvent(pointerEvent, nullptr); 466 processCaptureAndPositionOfPointerEvent(pointerEvent, nullptr);
411 467
412 removePointer(pointerEvent); 468 removePointer(pointerEvent);
413 } 469 }
414 470
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 releasePointerCapture(pointerEvent->pointerId()); 517 releasePointerCapture(pointerEvent->pointerId());
462 if (pointerEvent->isPrimary()) { 518 if (pointerEvent->isPrimary()) {
463 m_preventMouseEventForPointerType[toPointerTypeIndex( 519 m_preventMouseEventForPointerType[toPointerTypeIndex(
464 mouseEvent.pointerProperties().pointerType)] = false; 520 mouseEvent.pointerProperties().pointerType)] = false;
465 } 521 }
466 } 522 }
467 523
468 return result; 524 return result;
469 } 525 }
470 526
471 PointerEventManager::PointerEventManager() 527 PointerEventManager::PointerEventManager(LocalFrame* frame)
528 : m_frame(frame)
529 , m_touchEventManager(frame)
472 { 530 {
473 clear(); 531 clear();
474 } 532 }
475 533
476 PointerEventManager::~PointerEventManager() 534 PointerEventManager::~PointerEventManager()
477 { 535 {
478 } 536 }
479 537
480 void PointerEventManager::clear() 538 void PointerEventManager::clear()
481 { 539 {
482 for (auto& entry : m_preventMouseEventForPointerType) 540 for (auto& entry : m_preventMouseEventForPointerType)
483 entry = false; 541 entry = false;
542 m_touchEventManager.clear();
484 m_inCanceledStateForPointerTypeTouch = false; 543 m_inCanceledStateForPointerTypeTouch = false;
485 m_pointerEventFactory.clear(); 544 m_pointerEventFactory.clear();
486 m_nodeUnderPointer.clear(); 545 m_nodeUnderPointer.clear();
487 m_pointerCaptureTarget.clear(); 546 m_pointerCaptureTarget.clear();
488 m_pendingPointerCaptureTarget.clear(); 547 m_pendingPointerCaptureTarget.clear();
489 } 548 }
490 549
491 void PointerEventManager::processCaptureAndPositionOfPointerEvent( 550 void PointerEventManager::processCaptureAndPositionOfPointerEvent(
492 PointerEvent* pointerEvent, 551 PointerEvent* pointerEvent,
493 EventTarget* hitTestTarget, 552 EventTarget* hitTestTarget,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 { 693 {
635 if (m_pointerCaptureTarget.get(pointerId) == target) 694 if (m_pointerCaptureTarget.get(pointerId) == target)
636 releasePointerCapture(pointerId); 695 releasePointerCapture(pointerId);
637 } 696 }
638 697
639 void PointerEventManager::releasePointerCapture(int pointerId) 698 void PointerEventManager::releasePointerCapture(int pointerId)
640 { 699 {
641 m_pendingPointerCaptureTarget.remove(pointerId); 700 m_pendingPointerCaptureTarget.remove(pointerId);
642 } 701 }
643 702
644 bool PointerEventManager::isActive(const int pointerId) 703 bool PointerEventManager::isActive(const int pointerId) const
645 { 704 {
646 return m_pointerEventFactory.isActive(pointerId); 705 return m_pointerEventFactory.isActive(pointerId);
647 } 706 }
648 707
649 WebPointerProperties::PointerType PointerEventManager::getPointerEventType( 708 WebPointerProperties::PointerType PointerEventManager::getPointerEventType(
650 const int pointerId) 709 const int pointerId) const
651 { 710 {
652 return m_pointerEventFactory.getPointerType(pointerId); 711 return m_pointerEventFactory.getPointerType(pointerId);
653 } 712 }
654 713
714 bool PointerEventManager::isAnyTouchActive() const
715 {
716 return m_touchEventManager.isAnyTouchActive();
717 }
718
655 DEFINE_TRACE(PointerEventManager) 719 DEFINE_TRACE(PointerEventManager)
656 { 720 {
721 visitor->trace(m_frame);
657 visitor->trace(m_nodeUnderPointer); 722 visitor->trace(m_nodeUnderPointer);
658 visitor->trace(m_pointerCaptureTarget); 723 visitor->trace(m_pointerCaptureTarget);
659 visitor->trace(m_pendingPointerCaptureTarget); 724 visitor->trace(m_pendingPointerCaptureTarget);
725 visitor->trace(m_touchEventManager);
660 } 726 }
661 727
662 728
663 } // namespace blink 729 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/PointerEventManager.h ('k') | third_party/WebKit/Source/core/input/TouchEventManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698