Changeset 172367 in webkit
- Timestamp:
- Aug 8, 2014 5:00:04 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r172365 r172367 1 2014-08-08 Peyton Randolph <prandolph@apple.com> 2 3 Implement long mouse press over links. Part of 135257 - Add long mouse press gesture. 4 https://bugs.webkit.org/show_bug.cgi?id=135476 5 6 Reviewed by Tim Horton. 7 8 * page/EventHandler.cpp: 9 (WebCore::EventHandler::EventHandler): 10 (WebCore::EventHandler::clear): Clear long press state. 11 (WebCore::EventHandler::handleMousePressEvent): Start the long-press if the mouse press is a left 12 mouse press over a link. 13 (WebCore::EventHandler::eventMayStartDrag): We cannot start a drag if we've recognized a long press. 14 (WebCore::EventHandler::handleMouseReleaseEvent): 15 If we didn't recognize a long press, cancel the long press. 16 (WebCore::EventHandler::beginTrackingPotentialLongMousePress): 17 Begin the long mouse press by kicking off a timer. If the timer fires before the long press is 18 cancelled, the long press is recognized. 19 (WebCore::EventHandler::recognizeLongMousePress): Added. Trigger the long-press and disable other 20 actions like dragging. 21 (WebCore::EventHandler::cancelTrackingPotentialLongMousePress): Added. Cancel the long press by 22 clearing related state. 23 (WebCore::EventHandler::clearLongMousePressState): Added. Clear long press state. 24 (WebCore::EventHandler::handleLongMousePressMouseMovedEvent): Added. Cancel the long press if 25 the mouse moves outside a specified hysteresis interval. 26 (WebCore::EventHandler::handleMouseMoveEvent): Ask handleLongMousePressMouseMovedEvent whether to 27 return early and not update hovers, cursors, drags, etc. 28 (WebCore::EventHandler::dragHysteresisExceeded): Factor out the hysteresis bounds check into 29 mouseHysteresisExceeded(). 30 (WebCore::EventHandler::handleDrag): Cancel long press upon starting drag. 31 (WebCore::EventHandler::mouseHysteresisExceeded): Added. General hysteresis function that takes an 32 arbitrary mouse movement threshold. Factored out from dragHysteresisExceeded. 33 * page/EventHandler.h: 34 1 35 2014-08-08 Simon Fraser <simon.fraser@apple.com> 2 36 -
trunk/Source/WebCore/page/EventHandler.cpp
r171862 r172367 132 132 #endif // ENABLE(DRAG_SUPPORT) 133 133 134 #if ENABLE(LONG_MOUSE_PRESS) 135 const std::chrono::milliseconds longMousePressRecognitionDelay = 500_ms; 136 const int maximumLongMousePressDragDistance = 5; // in points. 137 #endif 138 134 139 #if ENABLE(IOS_GESTURE_EVENTS) 135 140 const float GestureUnknown = 0; … … 372 377 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired) 373 378 #endif 379 #if ENABLE(LONG_MOUSE_PRESS) 380 , m_longMousePressTimer(this, &EventHandler::recognizeLongMousePress) 381 , m_didRecognizeLongMousePress(false) 382 #endif 374 383 , m_autoscrollController(std::make_unique<AutoscrollController>()) 375 384 , m_mouseDownMayStartAutoscroll(false) … … 447 456 #if ENABLE(CURSOR_VISIBILITY) 448 457 cancelAutoHideCursorTimer(); 458 #endif 459 #if ENABLE(LONG_MOUSE_PRESS) 460 clearLongMousePressState(); 449 461 #endif 450 462 m_resizeLayer = 0; … … 763 775 } 764 776 777 #if ENABLE(LONG_MOUSE_PRESS) 778 if (event.event().button() == LeftButton && event.isOverLink()) { 779 // FIXME 135703: Handle long press for more than just links. 780 beginTrackingPotentialLongMousePress(); 781 } 782 #endif 783 765 784 // We don't do this at the start of mouse down handling, 766 785 // because we don't want to do it until we know we didn't hit a widget. … … 847 866 if (event.button() != LeftButton || event.clickCount() != 1) 848 867 return false; 868 869 #if ENABLE(LONG_MOUSE_PRESS) 870 if (m_didRecognizeLongMousePress) 871 return false; 872 #endif 849 873 850 874 FrameView* view = m_frame.view(); … … 1003 1027 1004 1028 bool handled = false; 1029 1030 #if ENABLE(LONG_MOUSE_PRESS) 1031 if (event.event().button() == LeftButton) 1032 clearLongMousePressState(); 1033 #endif 1005 1034 1006 1035 // Clear the selection if the mouse didn't move after the last mouse … … 1546 1575 } 1547 1576 #endif 1577 1578 #if ENABLE(LONG_MOUSE_PRESS) 1579 void EventHandler::beginTrackingPotentialLongMousePress() 1580 { 1581 clearLongMousePressState(); 1582 1583 m_longMousePressTimer.startOneShot(longMousePressRecognitionDelay); 1584 1585 // FIXME 135580: Bubble long mouse press up to the client. 1586 } 1587 1588 void EventHandler::recognizeLongMousePress(Timer<EventHandler>& timer) 1589 { 1590 ASSERT_UNUSED(timer, &timer == &m_longMousePressTimer); 1591 1592 m_didRecognizeLongMousePress = true; 1593 1594 // Clear mouse state to avoid initiating a drag. 1595 m_mousePressed = false; 1596 invalidateClick(); 1597 1598 // FIXME 135580: Bubble long mouse press up to the client. 1599 } 1600 1601 void EventHandler::cancelTrackingPotentialLongMousePress() 1602 { 1603 if (!m_longMousePressTimer.isActive()) 1604 return; 1605 1606 clearLongMousePressState(); 1607 1608 // FIXME 135580: Bubble long mouse press up to the client. 1609 } 1610 1611 void EventHandler::clearLongMousePressState() 1612 { 1613 m_longMousePressTimer.stop(); 1614 m_didRecognizeLongMousePress = false; 1615 } 1616 1617 bool EventHandler::handleLongMousePressMouseMovedEvent(const PlatformMouseEvent& mouseEvent) 1618 { 1619 if (mouseEvent.button() != LeftButton || mouseEvent.type() != PlatformEvent::MouseMoved) 1620 return false; 1621 1622 if (m_didRecognizeLongMousePress) 1623 return true; 1624 1625 if (!mouseMovementExceedsThreshold(mouseEvent.position(), maximumLongMousePressDragDistance)) 1626 cancelTrackingPotentialLongMousePress(); 1627 1628 return false; 1629 } 1630 1631 #endif // ENABLE(LONG_MOUSE_PRESS) 1548 1632 1549 1633 static LayoutPoint documentPointForWindowPoint(Frame& frame, const IntPoint& windowPoint) … … 1794 1878 bool defaultPrevented = dispatchSyntheticTouchEventIfEnabled(mouseEvent); 1795 1879 if (defaultPrevented) 1880 return true; 1881 #endif 1882 1883 #if ENABLE(LONG_MOUSE_PRESS) 1884 if (handleLongMousePressMouseMovedEvent(mouseEvent)) 1796 1885 return true; 1797 1886 #endif … … 3216 3305 bool EventHandler::dragHysteresisExceeded(const FloatPoint& dragViewportLocation) const 3217 3306 { 3218 FrameView* view = m_frame.view();3219 if (!view)3220 return false;3221 IntPoint dragLocation = view->windowToContents(flooredIntPoint(dragViewportLocation));3222 IntSize delta = dragLocation - m_mouseDownPos;3223 3224 3307 int threshold = GeneralDragHysteresis; 3225 3308 switch (dragState().type) { … … 3240 3323 } 3241 3324 3242 return abs(delta.width()) >= threshold || abs(delta.height()) >= threshold;3325 return mouseMovementExceedsThreshold(dragViewportLocation, threshold); 3243 3326 } 3244 3327 … … 3414 3497 if (m_didStartDrag) { 3415 3498 m_mouseDownMayStartDrag = false; 3499 3500 #if ENABLE(LONG_MOUSE_PRESS) 3501 cancelTrackingPotentialLongMousePress(); 3502 #endif 3416 3503 return true; 3417 3504 } … … 3434 3521 } 3435 3522 #endif // ENABLE(DRAG_SUPPORT) 3436 3523 3524 #if ENABLE(DRAG_SUPPORT) || ENABLE(LONG_MOUSE_PRESS) 3525 bool EventHandler::mouseMovementExceedsThreshold(const FloatPoint& viewportLocation, int pointsThreshold) const 3526 { 3527 FrameView* view = m_frame.view(); 3528 if (!view) 3529 return false; 3530 IntPoint location = view->windowToContents(flooredIntPoint(viewportLocation)); 3531 IntSize delta = location - m_mouseDownPos; 3532 3533 return abs(delta.width()) >= pointsThreshold || abs(delta.height()) >= pointsThreshold; 3534 } 3535 #endif // ENABLE(DRAG_SUPPORT) || ENABLE(LONG_MOUSE_PRESS) 3536 3437 3537 bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEvent, TextEventInputType inputType) 3438 3538 { -
trunk/Source/WebCore/page/EventHandler.h
r171283 r172367 380 380 bool dragHysteresisExceeded(const IntPoint&) const; 381 381 #endif // ENABLE(DRAG_SUPPORT) 382 383 #if ENABLE(DRAG_SUPPORT) || ENABLE(LONG_MOUSE_PRESS) 384 bool mouseMovementExceedsThreshold(const FloatPoint&, int pointsThreshold) const; 385 #endif 382 386 383 387 bool passMousePressEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe); … … 439 443 #endif 440 444 445 #if ENABLE(LONG_MOUSE_PRESS) 446 void beginTrackingPotentialLongMousePress(); 447 void recognizeLongMousePress(Timer<EventHandler>&); 448 void cancelTrackingPotentialLongMousePress(); 449 bool longMousePressHysteresisExceeded(); 450 void clearLongMousePressState(); 451 bool handleLongMousePressMouseMovedEvent(const PlatformMouseEvent&); 452 #endif 453 441 454 void clearLatchedState(); 442 455 … … 465 478 #if ENABLE(CURSOR_SUPPORT) 466 479 Timer<EventHandler> m_cursorUpdateTimer; 480 #endif 481 #if ENABLE(LONG_MOUSE_PRESS) 482 Timer<EventHandler> m_longMousePressTimer; 483 bool m_didRecognizeLongMousePress; 467 484 #endif 468 485
Note: See TracChangeset
for help on using the changeset viewer.