Skip to content
Permalink
Browse files
Implement long mouse press over links. Part of 135257 - Add long mous…
…e 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:

Canonical link: https://commits.webkit.org/153648@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172367 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Peyton Randolph authored and webkit-commit-queue committed Aug 9, 2014
1 parent 6d9f18b commit a5124a036c566b39ecf7491ddbc9ce1f85d765d0
Showing 3 changed files with 159 additions and 8 deletions.
@@ -1,3 +1,37 @@
2014-08-08 Peyton Randolph <prandolph@apple.com>

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

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:

2014-08-08 Simon Fraser <simon.fraser@apple.com>

[WK2] Scrolling does not work inside nested frames
@@ -131,6 +131,11 @@ const int TextDragHysteresis = 3;
const int GeneralDragHysteresis = 3;
#endif // ENABLE(DRAG_SUPPORT)

#if ENABLE(LONG_MOUSE_PRESS)
const std::chrono::milliseconds longMousePressRecognitionDelay = 500_ms;
const int maximumLongMousePressDragDistance = 5; // in points.
#endif

#if ENABLE(IOS_GESTURE_EVENTS)
const float GestureUnknown = 0;
#endif
@@ -370,6 +375,10 @@ EventHandler::EventHandler(Frame& frame)
, m_hoverTimer(this, &EventHandler::hoverTimerFired)
#if ENABLE(CURSOR_SUPPORT)
, m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired)
#endif
#if ENABLE(LONG_MOUSE_PRESS)
, m_longMousePressTimer(this, &EventHandler::recognizeLongMousePress)
, m_didRecognizeLongMousePress(false)
#endif
, m_autoscrollController(std::make_unique<AutoscrollController>())
, m_mouseDownMayStartAutoscroll(false)
@@ -446,6 +455,9 @@ void EventHandler::clear()
#endif
#if ENABLE(CURSOR_VISIBILITY)
cancelAutoHideCursorTimer();
#endif
#if ENABLE(LONG_MOUSE_PRESS)
clearLongMousePressState();
#endif
m_resizeLayer = 0;
m_elementUnderMouse = nullptr;
@@ -762,6 +774,13 @@ bool EventHandler::handleMousePressEvent(const MouseEventWithHitTestResults& eve
}
}

#if ENABLE(LONG_MOUSE_PRESS)
if (event.event().button() == LeftButton && event.isOverLink()) {
// FIXME 135703: Handle long press for more than just links.
beginTrackingPotentialLongMousePress();
}
#endif

// We don't do this at the start of mouse down handling,
// because we don't want to do it until we know we didn't hit a widget.
if (singleClick)
@@ -846,6 +865,11 @@ bool EventHandler::eventMayStartDrag(const PlatformMouseEvent& event) const

if (event.button() != LeftButton || event.clickCount() != 1)
return false;

#if ENABLE(LONG_MOUSE_PRESS)
if (m_didRecognizeLongMousePress)
return false;
#endif

FrameView* view = m_frame.view();
if (!view)
@@ -1002,6 +1026,11 @@ bool EventHandler::handleMouseReleaseEvent(const MouseEventWithHitTestResults& e
m_mouseDownWasInSubframe = false;

bool handled = false;

#if ENABLE(LONG_MOUSE_PRESS)
if (event.event().button() == LeftButton)
clearLongMousePressState();
#endif

// Clear the selection if the mouse didn't move after the last mouse
// press and it's not a context menu click. We do this so when clicking
@@ -1545,6 +1574,61 @@ void EventHandler::autoHideCursorTimerFired(Timer<EventHandler>& timer)
view->setCursor(m_currentMouseCursor);
}
#endif

#if ENABLE(LONG_MOUSE_PRESS)
void EventHandler::beginTrackingPotentialLongMousePress()
{
clearLongMousePressState();

m_longMousePressTimer.startOneShot(longMousePressRecognitionDelay);

// FIXME 135580: Bubble long mouse press up to the client.
}

void EventHandler::recognizeLongMousePress(Timer<EventHandler>& timer)
{
ASSERT_UNUSED(timer, &timer == &m_longMousePressTimer);

m_didRecognizeLongMousePress = true;

// Clear mouse state to avoid initiating a drag.
m_mousePressed = false;
invalidateClick();

// FIXME 135580: Bubble long mouse press up to the client.
}

void EventHandler::cancelTrackingPotentialLongMousePress()
{
if (!m_longMousePressTimer.isActive())
return;

clearLongMousePressState();

// FIXME 135580: Bubble long mouse press up to the client.
}

void EventHandler::clearLongMousePressState()
{
m_longMousePressTimer.stop();
m_didRecognizeLongMousePress = false;
}

bool EventHandler::handleLongMousePressMouseMovedEvent(const PlatformMouseEvent& mouseEvent)
{
if (mouseEvent.button() != LeftButton || mouseEvent.type() != PlatformEvent::MouseMoved)
return false;

if (m_didRecognizeLongMousePress)
return true;

if (!mouseMovementExceedsThreshold(mouseEvent.position(), maximumLongMousePressDragDistance))
cancelTrackingPotentialLongMousePress();

return false;
}

#endif // ENABLE(LONG_MOUSE_PRESS)

static LayoutPoint documentPointForWindowPoint(Frame& frame, const IntPoint& windowPoint)
{
@@ -1796,6 +1880,11 @@ bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& mouseEvent, Hi
return true;
#endif

#if ENABLE(LONG_MOUSE_PRESS)
if (handleLongMousePressMouseMovedEvent(mouseEvent))
return true;
#endif

RefPtr<FrameView> protector(m_frame.view());

setLastKnownMousePosition(mouseEvent);
@@ -3215,12 +3304,6 @@ bool EventHandler::dragHysteresisExceeded(const IntPoint& floatDragViewportLocat

bool EventHandler::dragHysteresisExceeded(const FloatPoint& dragViewportLocation) const
{
FrameView* view = m_frame.view();
if (!view)
return false;
IntPoint dragLocation = view->windowToContents(flooredIntPoint(dragViewportLocation));
IntSize delta = dragLocation - m_mouseDownPos;

int threshold = GeneralDragHysteresis;
switch (dragState().type) {
case DragSourceActionSelection:
@@ -3239,7 +3322,7 @@ bool EventHandler::dragHysteresisExceeded(const FloatPoint& dragViewportLocation
ASSERT_NOT_REACHED();
}

return abs(delta.width()) >= threshold || abs(delta.height()) >= threshold;
return mouseMovementExceedsThreshold(dragViewportLocation, threshold);
}

void EventHandler::freeDataTransfer()
@@ -3413,6 +3496,10 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, CheckDr
// On OS X this causes problems with the ownership of the pasteboard and the promised types.
if (m_didStartDrag) {
m_mouseDownMayStartDrag = false;

#if ENABLE(LONG_MOUSE_PRESS)
cancelTrackingPotentialLongMousePress();
#endif
return true;
}
if (dragState().source && dragState().shouldDispatchEvents) {
@@ -3433,7 +3520,20 @@ bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, CheckDr
return true;
}
#endif // ENABLE(DRAG_SUPPORT)


#if ENABLE(DRAG_SUPPORT) || ENABLE(LONG_MOUSE_PRESS)
bool EventHandler::mouseMovementExceedsThreshold(const FloatPoint& viewportLocation, int pointsThreshold) const
{
FrameView* view = m_frame.view();
if (!view)
return false;
IntPoint location = view->windowToContents(flooredIntPoint(viewportLocation));
IntSize delta = location - m_mouseDownPos;

return abs(delta.width()) >= pointsThreshold || abs(delta.height()) >= pointsThreshold;
}
#endif // ENABLE(DRAG_SUPPORT) || ENABLE(LONG_MOUSE_PRESS)

bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEvent, TextEventInputType inputType)
{
// Platforms should differentiate real commands like selectAll from text input in disguise (like insertNewline),
@@ -379,6 +379,10 @@ class EventHandler {
bool dragHysteresisExceeded(const FloatPoint&) const;
bool dragHysteresisExceeded(const IntPoint&) const;
#endif // ENABLE(DRAG_SUPPORT)

#if ENABLE(DRAG_SUPPORT) || ENABLE(LONG_MOUSE_PRESS)
bool mouseMovementExceedsThreshold(const FloatPoint&, int pointsThreshold) const;
#endif

bool passMousePressEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe);
bool passMouseMoveEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe, HitTestResult* hoveredNode = 0);
@@ -438,6 +442,15 @@ class EventHandler {
void autoHideCursorTimerFired(Timer<EventHandler>&);
#endif

#if ENABLE(LONG_MOUSE_PRESS)
void beginTrackingPotentialLongMousePress();
void recognizeLongMousePress(Timer<EventHandler>&);
void cancelTrackingPotentialLongMousePress();
bool longMousePressHysteresisExceeded();
void clearLongMousePressState();
bool handleLongMousePressMouseMovedEvent(const PlatformMouseEvent&);
#endif

void clearLatchedState();

Frame& m_frame;
@@ -465,6 +478,10 @@ class EventHandler {
#if ENABLE(CURSOR_SUPPORT)
Timer<EventHandler> m_cursorUpdateTimer;
#endif
#if ENABLE(LONG_MOUSE_PRESS)
Timer<EventHandler> m_longMousePressTimer;
bool m_didRecognizeLongMousePress;
#endif

std::unique_ptr<AutoscrollController> m_autoscrollController;
bool m_mouseDownMayStartAutoscroll;

0 comments on commit a5124a0

Please sign in to comment.