Modified: trunk/Source/WebCore/ChangeLog (172366 => 172367)
--- trunk/Source/WebCore/ChangeLog 2014-08-08 23:27:25 UTC (rev 172366)
+++ trunk/Source/WebCore/ChangeLog 2014-08-09 00:00:04 UTC (rev 172367)
@@ -1,3 +1,37 @@
+2014-08-08 Peyton Randolph <[email protected]>
+
+ 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 <[email protected]>
[WK2] Scrolling does not work inside nested frames
Modified: trunk/Source/WebCore/page/EventHandler.cpp (172366 => 172367)
--- trunk/Source/WebCore/page/EventHandler.cpp 2014-08-08 23:27:25 UTC (rev 172366)
+++ trunk/Source/WebCore/page/EventHandler.cpp 2014-08-09 00:00:04 UTC (rev 172367)
@@ -131,6 +131,11 @@
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
@@ -371,6 +376,10 @@
#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)
, m_mouseDownWasInSubframe(false)
@@ -447,6 +456,9 @@
#if ENABLE(CURSOR_VISIBILITY)
cancelAutoHideCursorTimer();
#endif
+#if ENABLE(LONG_MOUSE_PRESS)
+ clearLongMousePressState();
+#endif
m_resizeLayer = 0;
m_elementUnderMouse = nullptr;
m_lastElementUnderMouse = nullptr;
@@ -762,6 +774,13 @@
}
}
+#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 @@
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 @@
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,7 +1574,62 @@
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)
{
FrameView* view = frame.view();
@@ -1796,6 +1880,11 @@
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 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 @@
ASSERT_NOT_REACHED();
}
- return abs(delta.width()) >= threshold || abs(delta.height()) >= threshold;
+ return mouseMovementExceedsThreshold(dragViewportLocation, threshold);
}
void EventHandler::freeDataTransfer()
@@ -3413,6 +3496,10 @@
// 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 @@
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),
Modified: trunk/Source/WebCore/page/EventHandler.h (172366 => 172367)
--- trunk/Source/WebCore/page/EventHandler.h 2014-08-08 23:27:25 UTC (rev 172366)
+++ trunk/Source/WebCore/page/EventHandler.h 2014-08-09 00:00:04 UTC (rev 172367)
@@ -379,6 +379,10 @@
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 @@
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 @@
#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;