Chromium Code Reviews| 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/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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 | 348 |
| 347 removePointer(pointerEvent); | 349 removePointer(pointerEvent); |
| 348 } | 350 } |
| 349 } | 351 } |
| 350 | 352 |
| 351 void PointerEventManager::unblockTouchPointers() | 353 void PointerEventManager::unblockTouchPointers() |
| 352 { | 354 { |
| 353 m_inCanceledStateForPointerTypeTouch = false; | 355 m_inCanceledStateForPointerTypeTouch = false; |
| 354 } | 356 } |
| 355 | 357 |
| 358 WebInputEventResult PointerEventManager::handleTouchEvents( | |
| 359 const PlatformTouchEvent& event) | |
| 360 { | |
| 361 | |
| 362 if (event.type() == PlatformEvent::TouchScrollStarted) { | |
| 363 blockTouchPointers(); | |
| 364 return WebInputEventResult::HandledSystem; | |
| 365 } | |
| 366 | |
| 367 bool newTouchSequence = true; | |
| 368 for (const auto &touchPoint : event.touchPoints()) { | |
| 369 if (touchPoint.state() != PlatformTouchPoint::TouchPressed) | |
| 370 newTouchSequence = false; | |
|
dtapuska
2016/04/27 17:07:04
break; ?
Navid Zolghadr
2016/04/28 15:13:11
Done.
| |
| 371 } | |
| 372 if (newTouchSequence) | |
| 373 unblockTouchPointers(); | |
| 374 HeapVector<TouchEventManager::TouchInfo> touchInfos; | |
| 375 | |
| 376 // TODO(crbug.com/606822): This will be moved after pointer events so | |
| 377 // pointer event operations will get the first shot to fill up this array. | |
| 378 if (!m_touchEventManager.generateTouchInfos(event, touchInfos)) | |
| 379 return WebInputEventResult::NotHandled; | |
| 380 | |
| 381 dispatchTouchPointerEvents(event, touchInfos); | |
| 382 | |
| 383 return m_touchEventManager.handleTouchEvent(event, touchInfos); | |
| 384 } | |
| 385 | |
| 386 void PointerEventManager::dispatchTouchPointerEvents( | |
| 387 const PlatformTouchEvent& event, | |
| 388 HeapVector<TouchEventManager::TouchInfo>& touchInfos) | |
| 389 { | |
| 390 if (!RuntimeEnabledFeatures::pointerEventEnabled()) | |
| 391 return; | |
| 392 | |
| 393 if (m_inCanceledStateForPointerTypeTouch) | |
| 394 return; | |
| 395 | |
| 396 // Iterate through the touch points, sending PointerEvents to the targets as required. | |
| 397 for (auto& touchInfo: touchInfos) { | |
| 398 const PlatformTouchPoint &touchPoint = touchInfo.point; | |
| 399 WebInputEventResult result = WebInputEventResult::NotHandled; | |
| 400 // Do not send pointer events for stationary touches. | |
| 401 if (touchPoint.state() != PlatformTouchPoint::TouchStationary) { | |
| 402 PointerEvent* pointerEvent = m_pointerEventFactory.create( | |
| 403 pointerEventNameForTouchPointState(touchPoint.state()), | |
| 404 touchPoint, event.getModifiers(), | |
| 405 touchInfo.adjustedRadius, | |
| 406 touchInfo.adjustedPagePoint); | |
| 407 | |
| 408 // Consume the touch point if its pointer event is anything but NotH andled | |
| 409 // (e.g. preventDefault is called in the listener for the pointer ev ent). | |
| 410 result = sendTouchPointerEvent(touchInfo.touchNode, pointerEvent); | |
| 411 touchInfo.consumed = result != WebInputEventResult::NotHandled; | |
| 412 } | |
| 413 } | |
| 414 } | |
| 415 | |
| 356 WebInputEventResult PointerEventManager::sendTouchPointerEvent( | 416 WebInputEventResult PointerEventManager::sendTouchPointerEvent( |
| 357 EventTarget* target, | 417 EventTarget* target, PointerEvent* pointerEvent) |
| 358 const PlatformTouchPoint& touchPoint, PlatformEvent::Modifiers modifiers, | |
| 359 const double width, const double height, | |
| 360 const double clientX, const double clientY) | |
| 361 { | 418 { |
| 362 if (m_inCanceledStateForPointerTypeTouch) | 419 if (m_inCanceledStateForPointerTypeTouch) |
| 363 return WebInputEventResult::NotHandled; | 420 return WebInputEventResult::NotHandled; |
| 364 | 421 |
| 365 PointerEvent* pointerEvent = | |
| 366 m_pointerEventFactory.create( | |
| 367 pointerEventNameForTouchPointState(touchPoint.state()), | |
| 368 touchPoint, modifiers, width, height, clientX, clientY); | |
| 369 | |
| 370 processCaptureAndPositionOfPointerEvent(pointerEvent, target); | 422 processCaptureAndPositionOfPointerEvent(pointerEvent, target); |
| 371 | 423 |
| 372 // TODO(nzolghadr): crbug.com/579553 dealing with implicit touch capturing v s pointer event capturing | 424 // TODO(nzolghadr): crbug.com/579553 dealing with implicit touch capturing v s pointer event capturing |
| 373 WebInputEventResult result = dispatchPointerEvent( | 425 WebInputEventResult result = dispatchPointerEvent( |
| 374 getEffectiveTargetForPointerEvent(target, pointerEvent->pointerId()), | 426 getEffectiveTargetForPointerEvent(target, pointerEvent->pointerId()), |
| 375 pointerEvent); | 427 pointerEvent); |
| 376 | 428 |
| 377 // Setting the implicit capture for touch | 429 // Setting the implicit capture for touch |
| 378 if (touchPoint.state() == PlatformTouchPoint::TouchPressed) | 430 if (pointerEvent->type() == EventTypeNames::pointerdown) |
| 379 setPointerCapture(pointerEvent->pointerId(), target); | 431 setPointerCapture(pointerEvent->pointerId(), target); |
| 380 | 432 |
| 381 if (touchPoint.state() == PlatformTouchPoint::TouchReleased | 433 if (pointerEvent->type() == EventTypeNames::pointerup |
| 382 || touchPoint.state() == PlatformTouchPoint::TouchCancelled) { | 434 || pointerEvent->type() == EventTypeNames::pointercancel) { |
| 383 releasePointerCapture(pointerEvent->pointerId()); | 435 releasePointerCapture(pointerEvent->pointerId()); |
| 384 | 436 |
| 385 // Sending the leave/out events and lostpointercapture | 437 // Sending the leave/out events and lostpointercapture |
| 386 // because the next touch event will have a different id. So delayed | 438 // because the next touch event will have a different id. So delayed |
| 387 // sending of lostpointercapture won't work here. | 439 // sending of lostpointercapture won't work here. |
| 388 processCaptureAndPositionOfPointerEvent(pointerEvent, nullptr); | 440 processCaptureAndPositionOfPointerEvent(pointerEvent, nullptr); |
| 389 | 441 |
| 390 removePointer(pointerEvent); | 442 removePointer(pointerEvent); |
| 391 } | 443 } |
| 392 | 444 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 releasePointerCapture(pointerEvent->pointerId()); | 491 releasePointerCapture(pointerEvent->pointerId()); |
| 440 if (pointerEvent->isPrimary()) { | 492 if (pointerEvent->isPrimary()) { |
| 441 m_preventMouseEventForPointerType[toPointerTypeIndex( | 493 m_preventMouseEventForPointerType[toPointerTypeIndex( |
| 442 mouseEvent.pointerProperties().pointerType)] = false; | 494 mouseEvent.pointerProperties().pointerType)] = false; |
| 443 } | 495 } |
| 444 } | 496 } |
| 445 | 497 |
| 446 return result; | 498 return result; |
| 447 } | 499 } |
| 448 | 500 |
| 449 PointerEventManager::PointerEventManager() | 501 PointerEventManager::PointerEventManager(LocalFrame* frame) |
| 502 : m_frame(frame) | |
| 503 , m_touchEventManager(frame) | |
| 450 { | 504 { |
| 451 clear(); | 505 clear(); |
| 452 } | 506 } |
| 453 | 507 |
| 454 PointerEventManager::~PointerEventManager() | 508 PointerEventManager::~PointerEventManager() |
| 455 { | 509 { |
| 456 } | 510 } |
| 457 | 511 |
| 458 void PointerEventManager::clear() | 512 void PointerEventManager::clear() |
| 459 { | 513 { |
| 460 for (auto& entry : m_preventMouseEventForPointerType) | 514 for (auto& entry : m_preventMouseEventForPointerType) |
| 461 entry = false; | 515 entry = false; |
| 516 m_touchEventManager.clear(); | |
| 462 m_inCanceledStateForPointerTypeTouch = false; | 517 m_inCanceledStateForPointerTypeTouch = false; |
| 463 m_pointerEventFactory.clear(); | 518 m_pointerEventFactory.clear(); |
| 464 m_nodeUnderPointer.clear(); | 519 m_nodeUnderPointer.clear(); |
| 465 m_pointerCaptureTarget.clear(); | 520 m_pointerCaptureTarget.clear(); |
| 466 m_pendingPointerCaptureTarget.clear(); | 521 m_pendingPointerCaptureTarget.clear(); |
| 467 } | 522 } |
| 468 | 523 |
| 469 void PointerEventManager::processCaptureAndPositionOfPointerEvent( | 524 void PointerEventManager::processCaptureAndPositionOfPointerEvent( |
| 470 PointerEvent* pointerEvent, | 525 PointerEvent* pointerEvent, |
| 471 EventTarget* hitTestTarget, | 526 EventTarget* hitTestTarget, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 { | 667 { |
| 613 if (m_pointerCaptureTarget.get(pointerId) == target) | 668 if (m_pointerCaptureTarget.get(pointerId) == target) |
| 614 releasePointerCapture(pointerId); | 669 releasePointerCapture(pointerId); |
| 615 } | 670 } |
| 616 | 671 |
| 617 void PointerEventManager::releasePointerCapture(int pointerId) | 672 void PointerEventManager::releasePointerCapture(int pointerId) |
| 618 { | 673 { |
| 619 m_pendingPointerCaptureTarget.remove(pointerId); | 674 m_pendingPointerCaptureTarget.remove(pointerId); |
| 620 } | 675 } |
| 621 | 676 |
| 622 bool PointerEventManager::isActive(const int pointerId) | 677 bool PointerEventManager::isActive(const int pointerId) const |
| 623 { | 678 { |
| 624 return m_pointerEventFactory.isActive(pointerId); | 679 return m_pointerEventFactory.isActive(pointerId); |
| 625 } | 680 } |
| 626 | 681 |
| 627 WebPointerProperties::PointerType PointerEventManager::getPointerEventType( | 682 WebPointerProperties::PointerType PointerEventManager::getPointerEventType( |
| 628 const int pointerId) | 683 const int pointerId) const |
| 629 { | 684 { |
| 630 return m_pointerEventFactory.getPointerType(pointerId); | 685 return m_pointerEventFactory.getPointerType(pointerId); |
| 631 } | 686 } |
| 632 | 687 |
| 688 bool PointerEventManager::isAnyTouchActive() const | |
| 689 { | |
| 690 return m_touchEventManager.isAnyTouchActive(); | |
| 691 } | |
| 692 | |
| 633 DEFINE_TRACE(PointerEventManager) | 693 DEFINE_TRACE(PointerEventManager) |
| 634 { | 694 { |
| 695 visitor->trace(m_frame); | |
| 635 visitor->trace(m_nodeUnderPointer); | 696 visitor->trace(m_nodeUnderPointer); |
| 636 visitor->trace(m_pointerCaptureTarget); | 697 visitor->trace(m_pointerCaptureTarget); |
| 637 visitor->trace(m_pendingPointerCaptureTarget); | 698 visitor->trace(m_pendingPointerCaptureTarget); |
| 699 visitor->trace(m_touchEventManager); | |
| 638 } | 700 } |
| 639 | 701 |
| 640 | 702 |
| 641 } // namespace blink | 703 } // namespace blink |
| OLD | NEW |