Avoid making new active service overlay highlights while the mouse is down
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Aug 2014 19:03:56 +0000 (19:03 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Aug 2014 19:03:56 +0000 (19:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135872
<rdar://problem/17982341>

Reviewed by Enrica Casucci.

* WebProcess/WebPage/ServicesOverlayController.h:
* WebProcess/WebPage/mac/ServicesOverlayController.mm:
(WebKit::ServicesOverlayController::remainingTimeUntilHighlightShouldBeShown):
(WebKit::ServicesOverlayController::mouseEvent):
If the mouse is pressed or it's been less than 200ms since the mouse went up,
don't allow the highlight to change. We apply the mouse-is-pressed rule to telephone
number highlights as well, unlike the rest of the hysteresis logic.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172528 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/ServicesOverlayController.h
Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm

index e812dae44eb5bfafe7a7f2ffb4ef841bbc5d3b8c..fb75e21331eb8575277ab58a69ccea70c74d4f5c 100644 (file)
@@ -1,3 +1,19 @@
+2014-08-13  Tim Horton  <timothy_horton@apple.com>
+
+        Avoid making new active service overlay highlights while the mouse is down
+        https://bugs.webkit.org/show_bug.cgi?id=135872
+        <rdar://problem/17982341>
+
+        Reviewed by Enrica Casucci.
+
+        * WebProcess/WebPage/ServicesOverlayController.h:
+        * WebProcess/WebPage/mac/ServicesOverlayController.mm:
+        (WebKit::ServicesOverlayController::remainingTimeUntilHighlightShouldBeShown):
+        (WebKit::ServicesOverlayController::mouseEvent):
+        If the mouse is pressed or it's been less than 200ms since the mouse went up,
+        don't allow the highlight to change. We apply the mouse-is-pressed rule to telephone
+        number highlights as well, unlike the rest of the hysteresis logic.
+
 2014-08-13  Timothy Hatcher  <timothy@apple.com>
 
         Web Inspector: Workaround a NSWindow change to the title bar.
index 8643a3d40a237579b507378623a6323124fb5108..43b86ab0d1f6807be35f5decde94bc44a2679514 100644 (file)
@@ -151,6 +151,7 @@ private:
 
     std::chrono::steady_clock::time_point m_lastSelectionChangeTime;
     std::chrono::steady_clock::time_point m_nextActiveHighlightChangeTime;
+    std::chrono::steady_clock::time_point m_lastMouseUpTime;
 
     RefPtr<Highlight> m_currentMouseDownOnButtonHighlight;
     WebCore::IntPoint m_mousePosition;
index b1028871eb879b2b880cbb00bb593ab01936488f..e9ad9e45cb98e6cc6361fb4f41c0c63eceb996b3 100644 (file)
@@ -33,6 +33,7 @@
 #import "WebProcess.h"
 #import <QuartzCore/QuartzCore.h>
 #import <WebCore/Document.h>
+#import <WebCore/EventHandler.h>
 #import <WebCore/FloatQuad.h>
 #import <WebCore/FocusController.h>
 #import <WebCore/FrameView.h>
@@ -400,18 +401,25 @@ std::chrono::milliseconds ServicesOverlayController::remainingTimeUntilHighlight
     if (!highlight)
         return std::chrono::milliseconds::zero();
 
+    auto minimumTimeUntilHighlightShouldBeShown = 200_ms;
+
+    bool mousePressed = false;
+    if (Frame* mainFrame = m_webPage.mainFrame())
+        mousePressed = mainFrame->eventHandler().mousePressed();
+
     // Highlight hysteresis is only for selection services, because telephone number highlights are already much more stable
-    // by virtue of being expanded to include the entire telephone number.
+    // by virtue of being expanded to include the entire telephone number. However, we will still avoid highlighting
+    // telephone numbers while the mouse is down.
     if (highlight->type() == Highlight::Type::TelephoneNumber)
-        return std::chrono::milliseconds::zero();
-
-    std::chrono::steady_clock::duration minimumTimeUntilHighlightShouldBeShown = 200_ms;
+        return mousePressed ? minimumTimeUntilHighlightShouldBeShown : 0_ms;
 
     auto now = std::chrono::steady_clock::now();
     auto timeSinceLastSelectionChange = now - m_lastSelectionChangeTime;
     auto timeSinceHighlightBecameActive = now - m_nextActiveHighlightChangeTime;
+    auto timeSinceLastMouseUp = mousePressed ? 0_ms : now - m_lastMouseUpTime;
 
-    return std::chrono::duration_cast<std::chrono::milliseconds>(std::max(minimumTimeUntilHighlightShouldBeShown - timeSinceLastSelectionChange, minimumTimeUntilHighlightShouldBeShown - timeSinceHighlightBecameActive));
+    auto remainingDelay = minimumTimeUntilHighlightShouldBeShown - std::min(std::min(timeSinceLastSelectionChange, timeSinceHighlightBecameActive), timeSinceLastMouseUp);
+    return std::chrono::duration_cast<std::chrono::milliseconds>(remainingDelay);
 }
 
 void ServicesOverlayController::determineActiveHighlightTimerFired(Timer<ServicesOverlayController>&)
@@ -688,6 +696,8 @@ bool ServicesOverlayController::mouseEvent(PageOverlay*, const WebMouseEvent& ev
         RefPtr<Highlight> mouseDownHighlight = m_currentMouseDownOnButtonHighlight;
         m_currentMouseDownOnButtonHighlight = nullptr;
 
+        m_lastMouseUpTime = std::chrono::steady_clock::now();
+
         if (mouseIsOverActiveHighlightButton && mouseDownHighlight) {
             handleClick(m_mousePosition, *mouseDownHighlight);
             return true;