<!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>[168084] trunk/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/168084">168084</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2014-04-30 21:48:35 -0700 (Wed, 30 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Only reveal selection service UI after a short delay.
&lt;rdar://problem/16777346&gt; and https://bugs.webkit.org/show_bug.cgi?id=132418

Reviewed by Sam Weinig.

* WebProcess/WebPage/SelectionOverlayController.cpp:
(WebKit::SelectionOverlayController::SelectionOverlayController):
(WebKit::SelectionOverlayController::destroyOverlay): Also stop the hover timer.
(WebKit::SelectionOverlayController::selectionRectsDidChange): Mark the highlight as dirty.
(WebKit::SelectionOverlayController::hoverTimerFired): If the mouse is still over the highlight,
  set the visible flag and setNeedsDisplay().
* WebProcess/WebPage/SelectionOverlayController.h:

* WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm:
(WebKit::SelectionOverlayController::drawRect): Recreate the highlight if it exists but
  is marked as dirty. After doing that, possibly reset the hover timer.
  Also, only performing the actual drawing if the visible flag is set.
(WebKit::SelectionOverlayController::mouseEvent): If the mouse moves on or off the highlight,
  start or stop the hover timer accordingly.
(WebKit::SelectionOverlayController::mouseHoverStateChanged): Handle starting/stopping the
  hover timer.
(WebKit::SelectionOverlayController::clearHighlight): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageSelectionOverlayControllercpp">trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageSelectionOverlayControllerh">trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPagemacSelectionOverlayControllerMacmm">trunk/Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (168083 => 168084)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-05-01 04:20:16 UTC (rev 168083)
+++ trunk/Source/WebKit2/ChangeLog        2014-05-01 04:48:35 UTC (rev 168084)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2014-04-30  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Only reveal selection service UI after a short delay.
+        &lt;rdar://problem/16777346&gt; and https://bugs.webkit.org/show_bug.cgi?id=132418
+
+        Reviewed by Sam Weinig.
+
+        * WebProcess/WebPage/SelectionOverlayController.cpp:
+        (WebKit::SelectionOverlayController::SelectionOverlayController):
+        (WebKit::SelectionOverlayController::destroyOverlay): Also stop the hover timer.
+        (WebKit::SelectionOverlayController::selectionRectsDidChange): Mark the highlight as dirty.
+        (WebKit::SelectionOverlayController::hoverTimerFired): If the mouse is still over the highlight,
+          set the visible flag and setNeedsDisplay().
+        * WebProcess/WebPage/SelectionOverlayController.h:
+
+        * WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm:
+        (WebKit::SelectionOverlayController::drawRect): Recreate the highlight if it exists but
+          is marked as dirty. After doing that, possibly reset the hover timer.
+          Also, only performing the actual drawing if the visible flag is set.
+        (WebKit::SelectionOverlayController::mouseEvent): If the mouse moves on or off the highlight,
+          start or stop the hover timer accordingly.
+        (WebKit::SelectionOverlayController::mouseHoverStateChanged): Handle starting/stopping the
+          hover timer.
+        (WebKit::SelectionOverlayController::clearHighlight): Deleted.
+
</ins><span class="cx"> 2014-04-30  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS][WK2] Animated resize incorrectly assumes the layout width is the same as the view width
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageSelectionOverlayControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp (168083 => 168084)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp        2014-05-01 04:20:16 UTC (rev 168083)
+++ trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.cpp        2014-05-01 04:48:35 UTC (rev 168084)
</span><span class="lines">@@ -41,6 +41,9 @@
</span><span class="cx">     , m_selectionOverlay(nullptr)
</span><span class="cx">     , m_mouseIsDownOnButton(false)
</span><span class="cx">     , m_mouseIsOverHighlight(false)
</span><ins>+    , m_visible(false)
+    , m_hoverTimer(RunLoop::main(), this, &amp;SelectionOverlayController::hoverTimerFired)
+    , m_currentHighlightIsDirty(false)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -62,6 +65,9 @@
</span><span class="cx">     if (!m_selectionOverlay)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    m_mouseIsOverHighlight = false;
+    mouseHoverStateChanged();
+
</ins><span class="cx">     m_webPage-&gt;uninstallPageOverlay(m_selectionOverlay, PageOverlay::FadeMode::DoNotFade);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -88,8 +94,7 @@
</span><span class="cx"> void SelectionOverlayController::selectionRectsDidChange(const Vector&lt;LayoutRect&gt;&amp; rects)
</span><span class="cx"> {
</span><span class="cx"> #if __MAC_OS_X_VERSION_MIN_REQUIRED &gt; 1090
</span><del>-    clearHighlight();
-
</del><ins>+    m_currentHighlightIsDirty = true;
</ins><span class="cx">     m_currentSelectionRects = rects;
</span><span class="cx"> 
</span><span class="cx">     if (WebProcess::shared().hasSelectionServices() &amp;&amp; !m_currentSelectionRects.isEmpty())
</span><span class="lines">@@ -102,6 +107,17 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SelectionOverlayController::hoverTimerFired()
+{
+    if (!m_mouseIsOverHighlight)
+        return;
+
+    m_visible = true;
+
+    ASSERT(m_selectionOverlay);
+    m_selectionOverlay-&gt;setNeedsDisplay();
+}
+
</ins><span class="cx"> #if !PLATFORM(MAC)
</span><span class="cx"> void SelectionOverlayController::drawRect(PageOverlay*, WebCore::GraphicsContext&amp;, const WebCore::IntRect&amp;)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageSelectionOverlayControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h (168083 => 168084)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h        2014-05-01 04:20:16 UTC (rev 168083)
+++ trunk/Source/WebKit2/WebProcess/WebPage/SelectionOverlayController.h        2014-05-01 04:48:35 UTC (rev 168084)
</span><span class="lines">@@ -30,10 +30,9 @@
</span><span class="cx"> #include &quot;PageOverlay.h&quot;
</span><span class="cx"> #include &quot;WebPage.h&quot;
</span><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><ins>+#include &lt;wtf/RunLoop.h&gt;
</ins><span class="cx"> 
</span><del>-#if PLATFORM(MAC)
</del><span class="cx"> typedef void* DDHighlightRef;
</span><del>-#endif
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> class LayoutRect;
</span><span class="lines">@@ -68,7 +67,8 @@
</span><span class="cx">     virtual void drawRect(PageOverlay*, WebCore::GraphicsContext&amp;, const WebCore::IntRect&amp; dirtyRect) override;
</span><span class="cx">     virtual bool mouseEvent(PageOverlay*, const WebMouseEvent&amp;) override;
</span><span class="cx"> 
</span><del>-    void clearHighlight();
</del><ins>+    void mouseHoverStateChanged();
+    void hoverTimerFired();
</ins><span class="cx"> 
</span><span class="cx">     RefPtr&lt;WebPage&gt; m_webPage;
</span><span class="cx">     PageOverlay* m_selectionOverlay;
</span><span class="lines">@@ -77,10 +77,12 @@
</span><span class="cx">     WebCore::IntPoint m_mousePosition;
</span><span class="cx">     bool m_mouseIsDownOnButton;
</span><span class="cx">     bool m_mouseIsOverHighlight;
</span><ins>+    bool m_visible;
</ins><span class="cx"> 
</span><del>-#if PLATFORM(MAC)
</del><ins>+    RunLoop::Timer&lt;SelectionOverlayController&gt; m_hoverTimer;
+
</ins><span class="cx">     RetainPtr&lt;DDHighlightRef&gt; m_currentHighlight;
</span><del>-#endif
</del><ins>+    bool m_currentHighlightIsDirty;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagemacSelectionOverlayControllerMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm (168083 => 168084)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm        2014-05-01 04:20:16 UTC (rev 168083)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/SelectionOverlayControllerMac.mm        2014-05-01 04:48:35 UTC (rev 168084)
</span><span class="lines">@@ -55,6 +55,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><ins>+static double hoverTimerInterval = 2.0;
+
</ins><span class="cx"> void SelectionOverlayController::drawRect(PageOverlay* overlay, WebCore::GraphicsContext&amp; graphicsContext, const WebCore::IntRect&amp; dirtyRect)
</span><span class="cx"> {
</span><span class="cx">     if (m_currentSelectionRects.isEmpty())
</span><span class="lines">@@ -65,7 +67,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (!m_currentHighlight) {
</del><ins>+    if (!m_currentHighlight || m_currentHighlightIsDirty) {
</ins><span class="cx">         Vector&lt;CGRect&gt; cgRects;
</span><span class="cx">         cgRects.reserveCapacity(m_currentSelectionRects.size());
</span><span class="cx"> 
</span><span class="lines">@@ -73,13 +75,16 @@
</span><span class="cx">             cgRects.append((CGRect)pixelSnappedIntRect(rect));
</span><span class="cx"> 
</span><span class="cx">         m_currentHighlight = adoptCF(DDHighlightCreateWithRectsInVisibleRect(nullptr, cgRects.begin(), cgRects.size(), (CGRect)dirtyRect, true));
</span><ins>+        m_currentHighlightIsDirty = false;
</ins><span class="cx"> 
</span><span class="cx">         Boolean onButton;
</span><span class="cx">         m_mouseIsOverHighlight = DDHighlightPointIsOnHighlight(m_currentHighlight.get(), (CGPoint)m_mousePosition, &amp;onButton);
</span><ins>+
+        mouseHoverStateChanged();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // If the mouse is not over the DDHighlight we have no drawing to do.
-    if (!m_mouseIsOverHighlight)
</del><ins>+    // If the UI is not visibile or if the mouse is not over the DDHighlight we have no drawing to do.
+    if (!m_mouseIsOverHighlight || !m_visible)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     CGContextRef cgContext = graphicsContext.platformContext();
</span><span class="lines">@@ -108,8 +113,10 @@
</span><span class="cx">     Boolean onButton = false;
</span><span class="cx">     m_mouseIsOverHighlight = m_currentHighlight ? DDHighlightPointIsOnHighlight(m_currentHighlight.get(), (CGPoint)m_mousePosition, &amp;onButton) : false;
</span><span class="cx"> 
</span><del>-    if (mouseWasOverHighlight != m_mouseIsOverHighlight)
</del><ins>+    if (mouseWasOverHighlight != m_mouseIsOverHighlight) {
</ins><span class="cx">         m_selectionOverlay-&gt;setNeedsDisplay();
</span><ins>+        mouseHoverStateChanged();
+    }
</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">@@ -167,11 +174,16 @@
</span><span class="cx"> {
</span><span class="cx">     m_webPage-&gt;handleSelectionServiceClick(m_webPage-&gt;corePage()-&gt;mainFrame().selection(), point);
</span><span class="cx"> }
</span><del>-    
-void SelectionOverlayController::clearHighlight()
</del><ins>+
+void SelectionOverlayController::mouseHoverStateChanged()
</ins><span class="cx"> {
</span><del>-    m_currentHighlight.clear();
-    m_mouseIsOverHighlight = false;
</del><ins>+    if (m_mouseIsOverHighlight) {
+        if (!m_hoverTimer.isActive())
+            m_hoverTimer.startOneShot(hoverTimerInterval);
+    } else {
+        m_visible = false;
+        m_hoverTimer.stop();
+    }
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> } // namespace WebKit
</span></span></pre>
</div>
</div>

</body>
</html>