<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[172367] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/172367">172367</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2014-08-08 17:00:04 -0700 (Fri, 08 Aug 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>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:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageEventHandlercpp">trunk/Source/WebCore/page/EventHandler.cpp</a></li>
<li><a href="#trunkSourceWebCorepageEventHandlerh">trunk/Source/WebCore/page/EventHandler.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (172366 => 172367)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+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:
+
</ins><span class="cx"> 2014-08-08 Simon Fraser <simon.fraser@apple.com>
</span><span class="cx">
</span><span class="cx"> [WK2] Scrolling does not work inside nested frames
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.cpp (172366 => 172367)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -131,6 +131,11 @@
</span><span class="cx"> const int GeneralDragHysteresis = 3;
</span><span class="cx"> #endif // ENABLE(DRAG_SUPPORT)
</span><span class="cx">
</span><ins>+#if ENABLE(LONG_MOUSE_PRESS)
+const std::chrono::milliseconds longMousePressRecognitionDelay = 500_ms;
+const int maximumLongMousePressDragDistance = 5; // in points.
+#endif
+
</ins><span class="cx"> #if ENABLE(IOS_GESTURE_EVENTS)
</span><span class="cx"> const float GestureUnknown = 0;
</span><span class="cx"> #endif
</span><span class="lines">@@ -371,6 +376,10 @@
</span><span class="cx"> #if ENABLE(CURSOR_SUPPORT)
</span><span class="cx"> , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired)
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(LONG_MOUSE_PRESS)
+ , m_longMousePressTimer(this, &EventHandler::recognizeLongMousePress)
+ , m_didRecognizeLongMousePress(false)
+#endif
</ins><span class="cx"> , m_autoscrollController(std::make_unique<AutoscrollController>())
</span><span class="cx"> , m_mouseDownMayStartAutoscroll(false)
</span><span class="cx"> , m_mouseDownWasInSubframe(false)
</span><span class="lines">@@ -447,6 +456,9 @@
</span><span class="cx"> #if ENABLE(CURSOR_VISIBILITY)
</span><span class="cx"> cancelAutoHideCursorTimer();
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(LONG_MOUSE_PRESS)
+ clearLongMousePressState();
+#endif
</ins><span class="cx"> m_resizeLayer = 0;
</span><span class="cx"> m_elementUnderMouse = nullptr;
</span><span class="cx"> m_lastElementUnderMouse = nullptr;
</span><span class="lines">@@ -762,6 +774,13 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(LONG_MOUSE_PRESS)
+ if (event.event().button() == LeftButton && event.isOverLink()) {
+ // FIXME 135703: Handle long press for more than just links.
+ beginTrackingPotentialLongMousePress();
+ }
+#endif
+
</ins><span class="cx"> // We don't do this at the start of mouse down handling,
</span><span class="cx"> // because we don't want to do it until we know we didn't hit a widget.
</span><span class="cx"> if (singleClick)
</span><span class="lines">@@ -846,6 +865,11 @@
</span><span class="cx">
</span><span class="cx"> if (event.button() != LeftButton || event.clickCount() != 1)
</span><span class="cx"> return false;
</span><ins>+
+#if ENABLE(LONG_MOUSE_PRESS)
+ if (m_didRecognizeLongMousePress)
+ return false;
+#endif
</ins><span class="cx">
</span><span class="cx"> FrameView* view = m_frame.view();
</span><span class="cx"> if (!view)
</span><span class="lines">@@ -1002,6 +1026,11 @@
</span><span class="cx"> m_mouseDownWasInSubframe = false;
</span><span class="cx">
</span><span class="cx"> bool handled = false;
</span><ins>+
+#if ENABLE(LONG_MOUSE_PRESS)
+ if (event.event().button() == LeftButton)
+ clearLongMousePressState();
+#endif
</ins><span class="cx">
</span><span class="cx"> // Clear the selection if the mouse didn't move after the last mouse
</span><span class="cx"> // press and it's not a context menu click. We do this so when clicking
</span><span class="lines">@@ -1545,7 +1574,62 @@
</span><span class="cx"> view->setCursor(m_currentMouseCursor);
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><ins>+
+#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);
</ins><span class="cx">
</span><ins>+ 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)
+
</ins><span class="cx"> static LayoutPoint documentPointForWindowPoint(Frame& frame, const IntPoint& windowPoint)
</span><span class="cx"> {
</span><span class="cx"> FrameView* view = frame.view();
</span><span class="lines">@@ -1796,6 +1880,11 @@
</span><span class="cx"> return true;
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if ENABLE(LONG_MOUSE_PRESS)
+ if (handleLongMousePressMouseMovedEvent(mouseEvent))
+ return true;
+#endif
+
</ins><span class="cx"> RefPtr<FrameView> protector(m_frame.view());
</span><span class="cx">
</span><span class="cx"> setLastKnownMousePosition(mouseEvent);
</span><span class="lines">@@ -3215,12 +3304,6 @@
</span><span class="cx">
</span><span class="cx"> bool EventHandler::dragHysteresisExceeded(const FloatPoint& dragViewportLocation) const
</span><span class="cx"> {
</span><del>- FrameView* view = m_frame.view();
- if (!view)
- return false;
- IntPoint dragLocation = view->windowToContents(flooredIntPoint(dragViewportLocation));
- IntSize delta = dragLocation - m_mouseDownPos;
-
</del><span class="cx"> int threshold = GeneralDragHysteresis;
</span><span class="cx"> switch (dragState().type) {
</span><span class="cx"> case DragSourceActionSelection:
</span><span class="lines">@@ -3239,7 +3322,7 @@
</span><span class="cx"> ASSERT_NOT_REACHED();
</span><span class="cx"> }
</span><span class="cx">
</span><del>- return abs(delta.width()) >= threshold || abs(delta.height()) >= threshold;
</del><ins>+ return mouseMovementExceedsThreshold(dragViewportLocation, threshold);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void EventHandler::freeDataTransfer()
</span><span class="lines">@@ -3413,6 +3496,10 @@
</span><span class="cx"> // On OS X this causes problems with the ownership of the pasteboard and the promised types.
</span><span class="cx"> if (m_didStartDrag) {
</span><span class="cx"> m_mouseDownMayStartDrag = false;
</span><ins>+
+#if ENABLE(LONG_MOUSE_PRESS)
+ cancelTrackingPotentialLongMousePress();
+#endif
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> if (dragState().source && dragState().shouldDispatchEvents) {
</span><span class="lines">@@ -3433,7 +3520,20 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> #endif // ENABLE(DRAG_SUPPORT)
</span><del>-
</del><ins>+
+#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)
+
</ins><span class="cx"> bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEvent, TextEventInputType inputType)
</span><span class="cx"> {
</span><span class="cx"> // Platforms should differentiate real commands like selectAll from text input in disguise (like insertNewline),
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.h (172366 => 172367)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -379,6 +379,10 @@
</span><span class="cx"> bool dragHysteresisExceeded(const FloatPoint&) const;
</span><span class="cx"> bool dragHysteresisExceeded(const IntPoint&) const;
</span><span class="cx"> #endif // ENABLE(DRAG_SUPPORT)
</span><ins>+
+#if ENABLE(DRAG_SUPPORT) || ENABLE(LONG_MOUSE_PRESS)
+ bool mouseMovementExceedsThreshold(const FloatPoint&, int pointsThreshold) const;
+#endif
</ins><span class="cx">
</span><span class="cx"> bool passMousePressEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe);
</span><span class="cx"> bool passMouseMoveEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe, HitTestResult* hoveredNode = 0);
</span><span class="lines">@@ -438,6 +442,15 @@
</span><span class="cx"> void autoHideCursorTimerFired(Timer<EventHandler>&);
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if ENABLE(LONG_MOUSE_PRESS)
+ void beginTrackingPotentialLongMousePress();
+ void recognizeLongMousePress(Timer<EventHandler>&);
+ void cancelTrackingPotentialLongMousePress();
+ bool longMousePressHysteresisExceeded();
+ void clearLongMousePressState();
+ bool handleLongMousePressMouseMovedEvent(const PlatformMouseEvent&);
+#endif
+
</ins><span class="cx"> void clearLatchedState();
</span><span class="cx">
</span><span class="cx"> Frame& m_frame;
</span><span class="lines">@@ -465,6 +478,10 @@
</span><span class="cx"> #if ENABLE(CURSOR_SUPPORT)
</span><span class="cx"> Timer<EventHandler> m_cursorUpdateTimer;
</span><span class="cx"> #endif
</span><ins>+#if ENABLE(LONG_MOUSE_PRESS)
+ Timer<EventHandler> m_longMousePressTimer;
+ bool m_didRecognizeLongMousePress;
+#endif
</ins><span class="cx">
</span><span class="cx"> std::unique_ptr<AutoscrollController> m_autoscrollController;
</span><span class="cx"> bool m_mouseDownMayStartAutoscroll;
</span></span></pre>
</div>
</div>
</body>
</html>