12014-06-30 Peyton Randolph <prandolph@apple.com>
2
3 Add link long-press event handling using a timer.
4 https://bugs.webkit.org/show_bug.cgi?id=134262
5
6 Reviewed by NOBODY (OOPS!).
7
8 This patch adds the link long-press gesture's event handling. There are three events we care about: starting the
9 long-press [start], triggering the long-press [trigger], and cancelling the long-press before or after
10 triggering [cancel].
11
12 The general flow of the event is as follows (the event triggered at a step is placed in square brackets):
13
14 - [start] The user mouses down over a link.
15 - [trigger] The user keeps the mouse pressed on that link without moving their mouse too much for longer than
16 the specified long-press duration.
17 - The user releases their mouse press.
18 - [cancel] Without releasing their mouse press, the user moves their mouse outside the bounds of the link.
19 Doing so cancels the long press, much like pressing a button on OS X and then moving outside
20 that button's bounds cancels the button press.
21 - The user releases their mouse press.
22 - [trigger] Without releasing their mouse press, the user hovers over the original link again. Loop back
23 to the grandparent's trigger event.
24 - [cancel] The user releases their mouse press before triggering the long-press, triggering a normal mouse up.
25 - [cancel] The user moves their mouse outside a small region around the original mouse press before triggering
26 the long-press.
27
28 * page/EventHandler.h:
29 Add four members to EventHandler:
30 m_linkLongPressTimer -- timer tracking the delay between mousing down on a link and triggering a long-press.
31 m_linkLongPressSource -- the link element. Stores the source link element of the long-press as soon as the
32 mouse is pressed.
33 m_didLongPressLink -- track whether a long-press was triggered at any point.
34 m_linkLongPressMouseOutside -- track whether the mouse has moved outside the long-pressed link. Used to
35 implement OS X-style button hovering behavior, i.e. long-pressing a link and
36 then dragging the mouse outside the link will cancel the long-press.
37
38 * page/EventHandler.cpp:
39 (WebCore::EventHandler::EventHandler):
40 (WebCore::EventHandler::clear): Insert clearLinkLongPressState();
41 (WebCore::EventHandler::handleMousePressEvent): Start the long-press if the mouse press is over a link.
42 (WebCore::EventHandler::handleMouseReleaseEvent): Cancel the long-press when the mouse goes up.
43 (WebCore::EventHandler::startLinkLongPressWithSource):
44 Added. Starts the long-press timer and stores the source of the long-press.
45 (WebCore::EventHandler::triggerLinkLongPress): Added. Will send up the long-press event.
46 (WebCore::EventHandler::cancelLinkLongPress): Added. Will send up the link long-press event.
47 (WebCore::EventHandler::cancelLinkLongPressTimer):
48 Added. Cancel the long-press timer. Distinct from cancelLinkLongPress() because cancelLinkLongPress() will
49 send up a cancel event in a future patch.
50 (WebCore::EventHandler::clearLinkLongPressState): Added. Clear member variables.
51 (WebCore::EventHandler::linkLongPressTimerFired):
52 Added. Trigger the long-press and disable other actions like dragging.
53 (WebCore::EventHandler::handleLinkLongPressMouseMovedEvent):
54 Added. Cancels the long-press if the mouse moves outside a specified hysteresis before triggering. Cancel the
55 link long-press if triggered but the mouse moves outside the original URL element.
56 (WebCore::EventHandler::handleMouseMoveEvent): Call handleLinkLongPressEvent to handle the move.
57 (WebCore::EventHandler::handleDrag): Long-press and drag are mutually exclusive, so cancel long-press.
58 (WebCore::EventHandler::mouseHysteresisExceeded): Added. General hysteresis function that takes an arbitrary
59 mouse movement threshold. Factored out from dragHysteresisExceeded.
60 (WebCore::EventHandler::dragHysteresisExceeded): Factored out the hysteresis bounds check into
61 mouseHysteresisExceeded().
62