Changeset 172367 in webkit


Ignore:
Timestamp:
Aug 8, 2014 5:00:04 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

Implement long mouse press over links. Part of 135257 - Add long mouse press gesture.
https://bugs.webkit.org/show_bug.cgi?id=135476

Patch by Peyton Randolph <prandolph@apple.com> on 2014-08-08
Reviewed by Tim Horton.

  • page/EventHandler.cpp:

(WebCore::EventHandler::EventHandler):
(WebCore::EventHandler::clear): Clear long press state.
(WebCore::EventHandler::handleMousePressEvent): Start the long-press if the mouse press is a left
mouse press over a link.
(WebCore::EventHandler::eventMayStartDrag): We cannot start a drag if we've recognized a long press.
(WebCore::EventHandler::handleMouseReleaseEvent):
If we didn't recognize a long press, cancel the long press.
(WebCore::EventHandler::beginTrackingPotentialLongMousePress):
Begin the long mouse press by kicking off a timer. If the timer fires before the long press is
cancelled, the long press is recognized.
(WebCore::EventHandler::recognizeLongMousePress): Added. Trigger the long-press and disable other
actions like dragging.
(WebCore::EventHandler::cancelTrackingPotentialLongMousePress): Added. Cancel the long press by
clearing related state.
(WebCore::EventHandler::clearLongMousePressState): Added. Clear long press state.
(WebCore::EventHandler::handleLongMousePressMouseMovedEvent): Added. Cancel the long press if
the mouse moves outside a specified hysteresis interval.
(WebCore::EventHandler::handleMouseMoveEvent): Ask handleLongMousePressMouseMovedEvent whether to
return early and not update hovers, cursors, drags, etc.
(WebCore::EventHandler::dragHysteresisExceeded): Factor out the hysteresis bounds check into
mouseHysteresisExceeded().
(WebCore::EventHandler::handleDrag): Cancel long press upon starting drag.
(WebCore::EventHandler::mouseHysteresisExceeded): Added. General hysteresis function that takes an
arbitrary mouse movement threshold. Factored out from dragHysteresisExceeded.

  • page/EventHandler.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r172365 r172367  
     12014-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
    1352014-08-08  Simon Fraser  <simon.fraser@apple.com>
    236
  • trunk/Source/WebCore/page/EventHandler.cpp

    r171862 r172367  
    132132#endif // ENABLE(DRAG_SUPPORT)
    133133
     134#if ENABLE(LONG_MOUSE_PRESS)
     135const std::chrono::milliseconds longMousePressRecognitionDelay = 500_ms;
     136const int maximumLongMousePressDragDistance = 5; // in points.
     137#endif
     138
    134139#if ENABLE(IOS_GESTURE_EVENTS)
    135140const float GestureUnknown = 0;
     
    372377    , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired)
    373378#endif
     379#if ENABLE(LONG_MOUSE_PRESS)
     380    , m_longMousePressTimer(this, &EventHandler::recognizeLongMousePress)
     381    , m_didRecognizeLongMousePress(false)
     382#endif
    374383    , m_autoscrollController(std::make_unique<AutoscrollController>())
    375384    , m_mouseDownMayStartAutoscroll(false)
     
    447456#if ENABLE(CURSOR_VISIBILITY)
    448457    cancelAutoHideCursorTimer();
     458#endif
     459#if ENABLE(LONG_MOUSE_PRESS)
     460    clearLongMousePressState();
    449461#endif
    450462    m_resizeLayer = 0;
     
    763775    }
    764776
     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
    765784    // We don't do this at the start of mouse down handling,
    766785    // because we don't want to do it until we know we didn't hit a widget.
     
    847866    if (event.button() != LeftButton || event.clickCount() != 1)
    848867        return false;
     868
     869#if ENABLE(LONG_MOUSE_PRESS)
     870    if (m_didRecognizeLongMousePress)
     871        return false;
     872#endif
    849873   
    850874    FrameView* view = m_frame.view();
     
    10031027 
    10041028    bool handled = false;
     1029   
     1030#if ENABLE(LONG_MOUSE_PRESS)
     1031    if (event.event().button() == LeftButton)
     1032        clearLongMousePressState();
     1033#endif
    10051034
    10061035    // Clear the selection if the mouse didn't move after the last mouse
     
    15461575}
    15471576#endif
     1577   
     1578#if ENABLE(LONG_MOUSE_PRESS)
     1579void 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   
     1588void 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   
     1601void 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
     1611void EventHandler::clearLongMousePressState()
     1612{
     1613    m_longMousePressTimer.stop();
     1614    m_didRecognizeLongMousePress = false;
     1615}
     1616   
     1617bool 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)
    15481632
    15491633static LayoutPoint documentPointForWindowPoint(Frame& frame, const IntPoint& windowPoint)
     
    17941878    bool defaultPrevented = dispatchSyntheticTouchEventIfEnabled(mouseEvent);
    17951879    if (defaultPrevented)
     1880        return true;
     1881#endif
     1882
     1883#if ENABLE(LONG_MOUSE_PRESS)
     1884    if (handleLongMousePressMouseMovedEvent(mouseEvent))
    17961885        return true;
    17971886#endif
     
    32163305bool EventHandler::dragHysteresisExceeded(const FloatPoint& dragViewportLocation) const
    32173306{
    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    
    32243307    int threshold = GeneralDragHysteresis;
    32253308    switch (dragState().type) {
     
    32403323    }
    32413324   
    3242     return abs(delta.width()) >= threshold || abs(delta.height()) >= threshold;
     3325    return mouseMovementExceedsThreshold(dragViewportLocation, threshold);
    32433326}
    32443327   
     
    34143497        if (m_didStartDrag) {
    34153498            m_mouseDownMayStartDrag = false;
     3499
     3500#if ENABLE(LONG_MOUSE_PRESS)
     3501            cancelTrackingPotentialLongMousePress();
     3502#endif
    34163503            return true;
    34173504        }
     
    34343521}
    34353522#endif // ENABLE(DRAG_SUPPORT)
    3436  
     3523   
     3524#if ENABLE(DRAG_SUPPORT) || ENABLE(LONG_MOUSE_PRESS)
     3525bool 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
    34373537bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEvent, TextEventInputType inputType)
    34383538{
  • trunk/Source/WebCore/page/EventHandler.h

    r171283 r172367  
    380380    bool dragHysteresisExceeded(const IntPoint&) const;
    381381#endif // ENABLE(DRAG_SUPPORT)
     382   
     383#if ENABLE(DRAG_SUPPORT) || ENABLE(LONG_MOUSE_PRESS)
     384    bool mouseMovementExceedsThreshold(const FloatPoint&, int pointsThreshold) const;
     385#endif
    382386
    383387    bool passMousePressEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe);
     
    439443#endif
    440444
     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   
    441454    void clearLatchedState();
    442455
     
    465478#if ENABLE(CURSOR_SUPPORT)
    466479    Timer<EventHandler> m_cursorUpdateTimer;
     480#endif
     481#if ENABLE(LONG_MOUSE_PRESS)
     482    Timer<EventHandler> m_longMousePressTimer;
     483    bool m_didRecognizeLongMousePress;
    467484#endif
    468485
Note: See TracChangeset for help on using the changeset viewer.