<!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>[172252] branches/safari-600.1-branch/Source/WebKit2</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/172252">172252</a></dd>
<dt>Author</dt> <dd>dburkart@apple.com</dd>
<dt>Date</dt> <dd>2014-08-07 13:53:42 -0700 (Thu, 07 Aug 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merged <a href="http://trac.webkit.org/projects/webkit/changeset/172200">r172200</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6001branchSourceWebKit2ChangeLog">branches/safari-600.1-branch/Source/WebKit2/ChangeLog</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2WebProcessWebPageServicesOverlayControllerh">branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ServicesOverlayController.h</a></li>
<li><a href="#branchessafari6001branchSourceWebKit2WebProcessWebPagemacServicesOverlayControllermm">branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6001branchSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/ChangeLog (172251 => 172252)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/ChangeLog        2014-08-07 20:51:56 UTC (rev 172251)
+++ branches/safari-600.1-branch/Source/WebKit2/ChangeLog        2014-08-07 20:53:42 UTC (rev 172252)
</span><span class="lines">@@ -1,5 +1,49 @@
</span><span class="cx"> 2014-08-07  Dana Burkart &lt;dburkart@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r172200
+
+    2014-08-06  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+            Services overlay flashes a lot; should have some hysteresis before showing overlay
+            https://bugs.webkit.org/show_bug.cgi?id=135683
+            &lt;rdar://problem/16878039&gt;
+
+            Reviewed by Simon Fraser.
+
+            Don't show the highlight until it's been 200ms since the last change
+            in selection or change in which highlight is hovered, whichever was more recent.
+
+            * WebProcess/WebPage/ServicesOverlayController.h:
+            * WebProcess/WebPage/mac/ServicesOverlayController.mm:
+            (WebKit::ServicesOverlayController::ServicesOverlayController):
+            (WebKit::ServicesOverlayController::selectionRectsDidChange):
+            Keep track of when the selection last changed.
+
+            (WebKit::ServicesOverlayController::drawTelephoneNumberHighlightIfVisible):
+            Make establishHoveredTelephoneHighlight take a bool instead of Boolean.
+
+            (WebKit::ServicesOverlayController::mouseIsOverHighlight):
+            Factor mouseIsOverHighlight out of establishHoveredTelephoneHighlight and drawHighlight.
+
+            (WebKit::ServicesOverlayController::remainingTimeUntilHighlightShouldBeShown):
+            Return the amount of time until the highlight should be shown; this is
+            the maximum of (the difference between the last selection change and the timeout)
+            and (the difference between the last change in which highlight is hovered and the timeout).
+
+            Telephone number highlights are shown immediately, because they are already stable
+            by virtue of being expanded to include the entire telephone number.
+
+            (WebKit::ServicesOverlayController::repaintHighlightTimerFired):
+            (WebKit::ServicesOverlayController::drawHighlight):
+            If the highlight shouldn't be shown yet (because we haven't hit the two timeouts),
+            schedule a timer to repaint us around when we will hit the timeouts.
+
+            (WebKit::ServicesOverlayController::establishHoveredTelephoneHighlight):
+            (WebKit::ServicesOverlayController::mouseEvent):
+            Don't allow mouseUp to trigger the menu if we shouldn't be showing the overlay yet.
+
+2014-08-07  Dana Burkart &lt;dburkart@apple.com&gt;
+
</ins><span class="cx">         Merge r172193
</span><span class="cx"> 
</span><span class="cx">     2014-08-06  Brady Eidson and Jeffrey Pfau &lt;beidson@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2WebProcessWebPageServicesOverlayControllerh"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ServicesOverlayController.h (172251 => 172252)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ServicesOverlayController.h        2014-08-07 20:51:56 UTC (rev 172251)
+++ branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/ServicesOverlayController.h        2014-08-07 20:53:42 UTC (rev 172252)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;PageOverlay.h&quot;
</span><span class="cx"> #include &lt;WebCore/Range.h&gt;
</span><ins>+#include &lt;WebCore/Timer.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> typedef void* DDHighlightRef;
</span><span class="cx"> 
</span><span class="lines">@@ -79,17 +80,23 @@
</span><span class="cx">     void drawSelectionHighlight(WebCore::GraphicsContext&amp;, const WebCore::IntRect&amp; dirtyRect);
</span><span class="cx">     void drawHighlight(DDHighlightRef, WebCore::GraphicsContext&amp;);
</span><span class="cx"> 
</span><del>-    void establishHoveredTelephoneHighlight(Boolean&amp; onButton);
</del><ins>+    void establishHoveredTelephoneHighlight(bool&amp; mouseIsOverButton);
</ins><span class="cx">     void maybeCreateSelectionHighlight();
</span><span class="cx"> 
</span><span class="cx">     void clearSelectionHighlight();
</span><span class="cx">     void clearHoveredTelephoneNumberHighlight();
</span><span class="cx"> 
</span><ins>+    bool mouseIsOverHighlight(DDHighlightRef, bool&amp; mouseIsOverButton) const;
+    std::chrono::milliseconds remainingTimeUntilHighlightShouldBeShown() const;
+    void repaintHighlightTimerFired(WebCore::Timer&lt;ServicesOverlayController&gt;&amp;);
+
</ins><span class="cx">     WebPage* m_webPage;
</span><span class="cx">     PageOverlay* m_servicesOverlay;
</span><span class="cx">     
</span><span class="cx">     Vector&lt;WebCore::LayoutRect&gt; m_currentSelectionRects;
</span><span class="cx">     RetainPtr&lt;DDHighlightRef&gt; m_selectionHighlight;
</span><ins>+    std::chrono::steady_clock::time_point m_lastSelectionChangeTime;
+    std::chrono::steady_clock::time_point m_lastHoveredHighlightChangeTime;
</ins><span class="cx"> 
</span><span class="cx">     Vector&lt;RefPtr&lt;WebCore::Range&gt;&gt; m_currentTelephoneNumberRanges;
</span><span class="cx">     Vector&lt;RetainPtr&lt;DDHighlightRef&gt;&gt; m_telephoneNumberHighlights;
</span><span class="lines">@@ -98,6 +105,8 @@
</span><span class="cx">     RetainPtr&lt;DDHighlightRef&gt; m_currentHoveredHighlight;
</span><span class="cx">     RetainPtr&lt;DDHighlightRef&gt; m_currentMouseDownOnButtonHighlight;
</span><span class="cx"> 
</span><ins>+    WebCore::Timer&lt;ServicesOverlayController&gt; m_repaintHighlightTimer;
+
</ins><span class="cx">     WebCore::IntPoint m_mousePosition;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebKit2WebProcessWebPagemacServicesOverlayControllermm"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm (172251 => 172252)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm        2014-08-07 20:51:56 UTC (rev 172251)
+++ branches/safari-600.1-branch/Source/WebKit2/WebProcess/WebPage/mac/ServicesOverlayController.mm        2014-08-07 20:53:42 UTC (rev 172252)
</span><span class="lines">@@ -76,6 +76,7 @@
</span><span class="cx"> ServicesOverlayController::ServicesOverlayController(WebPage&amp; webPage)
</span><span class="cx">     : m_webPage(&amp;webPage)
</span><span class="cx">     , m_servicesOverlay(nullptr)
</span><ins>+    , m_repaintHighlightTimer(this, &amp;ServicesOverlayController::repaintHighlightTimerFired)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -216,6 +217,8 @@
</span><span class="cx">     clearSelectionHighlight();
</span><span class="cx">     m_currentSelectionRects = rects;
</span><span class="cx"> 
</span><ins>+    m_lastSelectionChangeTime = std::chrono::steady_clock::now();
+
</ins><span class="cx">     compactRectsWithGapRects(m_currentSelectionRects, gapRects);
</span><span class="cx"> 
</span><span class="cx">     // DataDetectors needs these reversed in order to place the arrow in the right location.
</span><span class="lines">@@ -306,8 +309,8 @@
</span><span class="cx"> 
</span><span class="cx">     // Found out which - if any - telephone number is hovered.
</span><span class="cx">     if (!m_hoveredTelephoneNumberData) {
</span><del>-        Boolean onButton;
-        establishHoveredTelephoneHighlight(onButton);
</del><ins>+        bool mouseIsOverButton;
+        establishHoveredTelephoneHighlight(mouseIsOverButton);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // If a telephone number is actually hovered, draw it.
</span><span class="lines">@@ -319,18 +322,52 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool ServicesOverlayController::mouseIsOverHighlight(DDHighlightRef highlight, bool&amp; mouseIsOverButton) const
+{
+    Boolean onButton;
+    bool hovered = DDHighlightPointIsOnHighlight(highlight, (CGPoint)m_mousePosition, &amp;onButton);
+    mouseIsOverButton = onButton;
+    return hovered;
+}
+
+std::chrono::milliseconds ServicesOverlayController::remainingTimeUntilHighlightShouldBeShown() const
+{
+    // 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.
+    if (m_hoveredTelephoneNumberData)
+        return std::chrono::milliseconds::zero();
+
+    std::chrono::steady_clock::duration minimumTimeUntilHighlightShouldBeShown = 200_ms;
+
+    auto now = std::chrono::steady_clock::now();
+    auto timeSinceLastSelectionChange = now - m_lastSelectionChangeTime;
+    auto timeSinceMouseOverSelection = now - m_lastHoveredHighlightChangeTime;
+
+    return std::chrono::duration_cast&lt;std::chrono::milliseconds&gt;(std::max(minimumTimeUntilHighlightShouldBeShown - timeSinceLastSelectionChange, minimumTimeUntilHighlightShouldBeShown - timeSinceMouseOverSelection));
+}
+
+void ServicesOverlayController::repaintHighlightTimerFired(WebCore::Timer&lt;ServicesOverlayController&gt;&amp;)
+{
+    if (m_servicesOverlay)
+        m_servicesOverlay-&gt;setNeedsDisplay();
+}
+
</ins><span class="cx"> void ServicesOverlayController::drawHighlight(DDHighlightRef highlight, WebCore::GraphicsContext&amp; graphicsContext)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(highlight);
</span><span class="cx"> 
</span><del>-    Boolean onButton;
-    bool mouseIsOverHighlight = DDHighlightPointIsOnHighlight(highlight, (CGPoint)m_mousePosition, &amp;onButton);
-
-    if (!mouseIsOverHighlight) {
</del><ins>+    bool mouseIsOverButton;
+    if (!mouseIsOverHighlight(highlight, mouseIsOverButton)) {
</ins><span class="cx">         LOG(Services, &quot;ServicesOverlayController::drawHighlight - Mouse is not over highlight, so drawing nothing&quot;);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    auto remainingTimeUntilHighlightShouldBeShown = this-&gt;remainingTimeUntilHighlightShouldBeShown();
+    if (remainingTimeUntilHighlightShouldBeShown &gt; std::chrono::steady_clock::duration::zero()) {
+        m_repaintHighlightTimer.startOneShot(remainingTimeUntilHighlightShouldBeShown);
+        return;
+    }
+
</ins><span class="cx">     CGContextRef cgContext = graphicsContext.platformContext();
</span><span class="cx">     
</span><span class="cx">     CGLayerRef highlightLayer = DDHighlightGetLayerWithContext(highlight, cgContext);
</span><span class="lines">@@ -371,7 +408,7 @@
</span><span class="cx">     m_hoveredTelephoneNumberData = nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ServicesOverlayController::establishHoveredTelephoneHighlight(Boolean&amp; onButton)
</del><ins>+void ServicesOverlayController::establishHoveredTelephoneHighlight(bool&amp; mouseIsOverButton)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(m_currentTelephoneNumberRanges.size() == m_telephoneNumberHighlights.size());
</span><span class="cx"> 
</span><span class="lines">@@ -395,7 +432,7 @@
</span><span class="cx">             m_telephoneNumberHighlights[i] = adoptCF(DDHighlightCreateWithRectsInVisibleRectWithStyleAndDirection(nullptr, &amp;cgRect, 1, viewForRange-&gt;boundsRect(), DDHighlightOutlineWithArrow, YES, NSWritingDirectionNatural, NO, YES));
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (!DDHighlightPointIsOnHighlight(m_telephoneNumberHighlights[i].get(), (CGPoint)m_mousePosition, &amp;onButton))
</del><ins>+        if (!mouseIsOverHighlight(m_telephoneNumberHighlights[i].get(), mouseIsOverButton))
</ins><span class="cx">             continue;
</span><span class="cx"> 
</span><span class="cx">         if (!m_hoveredTelephoneNumberData || m_hoveredTelephoneNumberData-&gt;highlight != m_telephoneNumberHighlights[i])
</span><span class="lines">@@ -406,7 +443,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     clearHoveredTelephoneNumberHighlight();
</span><del>-    onButton = false;
</del><ins>+    mouseIsOverButton = false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ServicesOverlayController::maybeCreateSelectionHighlight()
</span><span class="lines">@@ -434,8 +471,8 @@
</span><span class="cx"> 
</span><span class="cx">     DDHighlightRef oldHoveredHighlight = m_currentHoveredHighlight.get();
</span><span class="cx"> 
</span><del>-    Boolean onButton = false;
-    establishHoveredTelephoneHighlight(onButton);
</del><ins>+    bool mouseIsOverButton = false;
+    establishHoveredTelephoneHighlight(mouseIsOverButton);
</ins><span class="cx">     if (m_hoveredTelephoneNumberData) {
</span><span class="cx">         ASSERT(m_hoveredTelephoneNumberData-&gt;highlight);
</span><span class="cx">         m_currentHoveredHighlight = m_hoveredTelephoneNumberData-&gt;highlight;
</span><span class="lines">@@ -443,14 +480,16 @@
</span><span class="cx">         if (!m_selectionHighlight)
</span><span class="cx">             maybeCreateSelectionHighlight();
</span><span class="cx"> 
</span><del>-        if (m_selectionHighlight &amp;&amp; DDHighlightPointIsOnHighlight(m_selectionHighlight.get(), (CGPoint)m_mousePosition, &amp;onButton))
</del><ins>+        if (m_selectionHighlight &amp;&amp; mouseIsOverHighlight(m_selectionHighlight.get(), mouseIsOverButton))
</ins><span class="cx">             m_currentHoveredHighlight = m_selectionHighlight;
</span><span class="cx">         else
</span><span class="cx">             m_currentHoveredHighlight = nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (oldHoveredHighlight != m_currentHoveredHighlight)
</del><ins>+    if (oldHoveredHighlight != m_currentHoveredHighlight) {
+        m_lastHoveredHighlightChangeTime = std::chrono::steady_clock::now();
</ins><span class="cx">         m_servicesOverlay-&gt;setNeedsDisplay();
</span><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     // If this event has nothing to do with the left button, it clears the current mouse down tracking and we're done processing it.
</span><span class="cx">     if (event.button() != WebMouseEvent::LeftButton) {
</span><span class="lines">@@ -463,7 +502,7 @@
</span><span class="cx">         RetainPtr&lt;DDHighlightRef&gt; mouseDownHighlight = std::move(m_currentMouseDownOnButtonHighlight);
</span><span class="cx"> 
</span><span class="cx">         // If the mouse lifted while still over the highlight button that it went down on, then that is a click.
</span><del>-        if (onButton &amp;&amp; mouseDownHighlight) {
</del><ins>+        if (mouseIsOverButton &amp;&amp; mouseDownHighlight &amp;&amp; remainingTimeUntilHighlightShouldBeShown() &lt;= std::chrono::steady_clock::duration::zero()) {
</ins><span class="cx">             handleClick(m_mousePosition, mouseDownHighlight.get());
</span><span class="cx">             return true;
</span><span class="cx">         }
</span><span class="lines">@@ -474,7 +513,7 @@
</span><span class="cx">     // Check and see if the mouse moved within the confines of the DD highlight button.
</span><span class="cx">     if (event.type() == WebEvent::MouseMove) {
</span><span class="cx">         // Moving with the mouse button down is okay as long as the mouse never leaves the highlight button.
</span><del>-        if (m_currentMouseDownOnButtonHighlight &amp;&amp; onButton)
</del><ins>+        if (m_currentMouseDownOnButtonHighlight &amp;&amp; mouseIsOverButton)
</ins><span class="cx">             return true;
</span><span class="cx"> 
</span><span class="cx">         m_currentMouseDownOnButtonHighlight = nullptr;
</span><span class="lines">@@ -483,7 +522,7 @@
</span><span class="cx"> 
</span><span class="cx">     // Check and see if the mouse went down over a DD highlight button.
</span><span class="cx">     if (event.type() == WebEvent::MouseDown) {
</span><del>-        if (m_currentHoveredHighlight &amp;&amp; onButton) {
</del><ins>+        if (m_currentHoveredHighlight &amp;&amp; mouseIsOverButton) {
</ins><span class="cx">             m_currentMouseDownOnButtonHighlight = m_currentHoveredHighlight;
</span><span class="cx">             m_servicesOverlay-&gt;setNeedsDisplay();
</span><span class="cx">             return true;
</span></span></pre>
</div>
</div>

</body>
</html>