<!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>[198692] 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/198692">198692</a></dd>
<dt>Author</dt> <dd>bdakin@apple.com</dd>
<dt>Date</dt> <dd>2016-03-25 15:01:30 -0700 (Fri, 25 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Autoscrolling from a drag selection does not work in full screen, or when the 
window is against the screen edge
https://bugs.webkit.org/show_bug.cgi?id=155858
-and corresponding-
rdar://problem/9338465

Reviewed by Simon Fraser.

WebKit2 has always had this bug. Since WebKit1 scrolling in handled largely 
by AppKit, we did not have this bug because AppKit adjusts the autoscroll 
amount whenever the window is at the edge of the screen and the user is 
trying to autoscroll in that direction. This patch employs the same technique 
in WebCore.

Instead of using EventHandler::lastKnownMousePosition() as the autoscroll 
amount, use EventHandler::effectiveMousePositionForSelectionAutoscroll() 
which will adjust the lastKnownMousePosition if the window is at the edge of 
the screen.
* page/AutoscrollController.cpp:
(WebCore::AutoscrollController::autoscrollTimerFired):

For most ports, effectiveMousePositionForSelectionAutoscroll() will just 
return m_lastKnownMousePosition. We override it in EventHandlerMac to return 
an adjusted amount.
* page/EventHandler.cpp:
(WebCore::EventHandler::effectiveMousePositionForSelectionAutoscroll):
* page/EventHandler.h:
* page/mac/EventHandlerMac.mm:
(WebCore::autoscrollAdjustmentFactorForScreenBoundaries):
(WebCore::EventHandler::effectiveMousePositionForSelectionAutoscroll):

Make screenForDisplayID available as on PlatformScreen.h instead of just 
being a static function in the implementation file.
* platform/PlatformScreen.h:
* platform/mac/PlatformScreenMac.mm:
(WebCore::screenForDisplayID):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageAutoscrollControllercpp">trunk/Source/WebCore/page/AutoscrollController.cpp</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>
<li><a href="#trunkSourceWebCorepagemacEventHandlerMacmm">trunk/Source/WebCore/page/mac/EventHandlerMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformPlatformScreenh">trunk/Source/WebCore/platform/PlatformScreen.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacPlatformScreenMacmm">trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (198691 => 198692)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-25 21:55:34 UTC (rev 198691)
+++ trunk/Source/WebCore/ChangeLog        2016-03-25 22:01:30 UTC (rev 198692)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2016-03-25  Beth Dakin  &lt;bdakin@apple.com&gt;
+
+        Autoscrolling from a drag selection does not work in full screen, or when the 
+        window is against the screen edge
+        https://bugs.webkit.org/show_bug.cgi?id=155858
+        -and corresponding-
+        rdar://problem/9338465
+
+        Reviewed by Simon Fraser.
+
+        WebKit2 has always had this bug. Since WebKit1 scrolling in handled largely 
+        by AppKit, we did not have this bug because AppKit adjusts the autoscroll 
+        amount whenever the window is at the edge of the screen and the user is 
+        trying to autoscroll in that direction. This patch employs the same technique 
+        in WebCore.
+
+        Instead of using EventHandler::lastKnownMousePosition() as the autoscroll 
+        amount, use EventHandler::effectiveMousePositionForSelectionAutoscroll() 
+        which will adjust the lastKnownMousePosition if the window is at the edge of 
+        the screen.
+        * page/AutoscrollController.cpp:
+        (WebCore::AutoscrollController::autoscrollTimerFired):
+
+        For most ports, effectiveMousePositionForSelectionAutoscroll() will just 
+        return m_lastKnownMousePosition. We override it in EventHandlerMac to return 
+        an adjusted amount.
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::effectiveMousePositionForSelectionAutoscroll):
+        * page/EventHandler.h:
+        * page/mac/EventHandlerMac.mm:
+        (WebCore::autoscrollAdjustmentFactorForScreenBoundaries):
+        (WebCore::EventHandler::effectiveMousePositionForSelectionAutoscroll):
+
+        Make screenForDisplayID available as on PlatformScreen.h instead of just 
+        being a static function in the implementation file.
+        * platform/PlatformScreen.h:
+        * platform/mac/PlatformScreenMac.mm:
+        (WebCore::screenForDisplayID):
+
</ins><span class="cx"> 2016-03-25  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Soften push/replaceState frequency restrictions.
</span></span></pre></div>
<a id="trunkSourceWebCorepageAutoscrollControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/AutoscrollController.cpp (198691 => 198692)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/AutoscrollController.cpp        2016-03-25 21:55:34 UTC (rev 198691)
+++ trunk/Source/WebCore/page/AutoscrollController.cpp        2016-03-25 22:01:30 UTC (rev 198692)
</span><span class="lines">@@ -252,7 +252,7 @@
</span><span class="cx"> #if ENABLE(DRAG_SUPPORT)
</span><span class="cx">         frame.eventHandler().updateSelectionForMouseDrag();
</span><span class="cx"> #endif
</span><del>-        m_autoscrollRenderer-&gt;autoscroll(frame.eventHandler().lastKnownMousePosition());
</del><ins>+        m_autoscrollRenderer-&gt;autoscroll(frame.eventHandler().effectiveMousePositionForSelectionAutoscroll());
</ins><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx">     case NoAutoscroll:
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.cpp (198691 => 198692)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EventHandler.cpp        2016-03-25 21:55:34 UTC (rev 198691)
+++ trunk/Source/WebCore/page/EventHandler.cpp        2016-03-25 22:01:30 UTC (rev 198692)
</span><span class="lines">@@ -2586,6 +2586,11 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+IntPoint EventHandler::effectiveMousePositionForSelectionAutoscroll() const
+{
+    return m_lastKnownMousePosition;
+}
+
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> bool EventHandler::handleWheelEvent(const PlatformWheelEvent&amp; event)
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.h (198691 => 198692)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EventHandler.h        2016-03-25 21:55:34 UTC (rev 198691)
+++ trunk/Source/WebCore/page/EventHandler.h        2016-03-25 22:01:30 UTC (rev 198692)
</span><span class="lines">@@ -179,6 +179,8 @@
</span><span class="cx">     IntPoint lastKnownMouseGlobalPosition() const { return m_lastKnownMouseGlobalPosition; }
</span><span class="cx">     Cursor currentMouseCursor() const { return m_currentMouseCursor; }
</span><span class="cx"> 
</span><ins>+    IntPoint effectiveMousePositionForSelectionAutoscroll() const;
+
</ins><span class="cx">     static Frame* subframeForTargetNode(Node*);
</span><span class="cx">     static Frame* subframeForHitTestResult(const MouseEventWithHitTestResults&amp;);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepagemacEventHandlerMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/mac/EventHandlerMac.mm (198691 => 198692)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/mac/EventHandlerMac.mm        2016-03-25 21:55:34 UTC (rev 198691)
+++ trunk/Source/WebCore/page/mac/EventHandlerMac.mm        2016-03-25 22:01:30 UTC (rev 198692)
</span><span class="lines">@@ -1106,4 +1106,61 @@
</span><span class="cx">     return VisibleSelection();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static IntSize autoscrollAdjustmentFactorForScreenBoundaries(const IntPoint&amp; screenPoint, const FloatRect&amp; screenRect)
+{
+    // If the window is at the edge of the screen, and the mouse position is also at that edge of the screen,
+    // we need to adjust the autoscroll amount in order for the user to be able to autoscroll in that direction.
+    // We can pretend that the mouse position is slightly beyond the edge of the screen, and then autoscrolling
+    // will occur as excpected. This function figures out just how much to adjust the autoscroll amount by
+    // in order to get autoscrolling to feel natural in this situation.
+
+    IntSize adjustmentFactor;
+    
+#define EDGE_DISTANCE_THRESHOLD 50
+#define PIXELS_MULTIPLIER 20
+
+    float screenLeftEdge = screenRect.x();
+    float insetScreenLeftEdge = screenLeftEdge + EDGE_DISTANCE_THRESHOLD;
+    float screenRightEdge = screenRect.maxX();
+    float insetScreenRightEdge = screenRightEdge - EDGE_DISTANCE_THRESHOLD;
+    if (screenPoint.x() &gt;= screenLeftEdge &amp;&amp; screenPoint.x() &lt; insetScreenLeftEdge) {
+        float distanceFromEdge = screenPoint.x() - screenLeftEdge - EDGE_DISTANCE_THRESHOLD;
+        if (distanceFromEdge &lt; 0)
+            adjustmentFactor.setWidth((distanceFromEdge / EDGE_DISTANCE_THRESHOLD) * PIXELS_MULTIPLIER);
+    } else if (screenPoint.x() &gt;= insetScreenRightEdge &amp;&amp; screenPoint.x() &lt; screenRightEdge) {
+        float distanceFromEdge = EDGE_DISTANCE_THRESHOLD - (screenRightEdge - screenPoint.x());
+        if (distanceFromEdge &gt; 0)
+            adjustmentFactor.setWidth((distanceFromEdge / EDGE_DISTANCE_THRESHOLD) * PIXELS_MULTIPLIER);
+    }
+
+    float screenTopEdge = screenRect.y();
+    float insetScreenTopEdge = screenTopEdge + EDGE_DISTANCE_THRESHOLD;
+    float screenBottomEdge = screenRect.maxY();
+    float insetScreenBottomEdge = screenBottomEdge - EDGE_DISTANCE_THRESHOLD;
+
+    if (screenPoint.y() &gt;= screenTopEdge &amp;&amp; screenPoint.y() &lt; insetScreenTopEdge) {
+        float distanceFromEdge = screenPoint.y() - screenTopEdge - EDGE_DISTANCE_THRESHOLD;
+        if (distanceFromEdge &lt; 0)
+            adjustmentFactor.setHeight((distanceFromEdge / EDGE_DISTANCE_THRESHOLD) * PIXELS_MULTIPLIER);
+    } else if (screenPoint.y() &gt;= insetScreenBottomEdge &amp;&amp; screenPoint.y() &lt; screenBottomEdge) {
+        float distanceFromEdge = EDGE_DISTANCE_THRESHOLD - (screenBottomEdge - screenPoint.y());
+        if (distanceFromEdge &gt; 0)
+            adjustmentFactor.setHeight((distanceFromEdge / EDGE_DISTANCE_THRESHOLD) * PIXELS_MULTIPLIER);
+    }
+
+    return adjustmentFactor;
</ins><span class="cx"> }
</span><ins>+
+IntPoint EventHandler::effectiveMousePositionForSelectionAutoscroll() const
+{
+    Page* page = m_frame.page();
+    if (!page)
+        return m_lastKnownMousePosition;
+
+    NSScreen *screen = screenForDisplayID(page-&gt;chrome().displayID());
+    IntSize autoscrollAdjustmentFactor = autoscrollAdjustmentFactorForScreenBoundaries(m_lastKnownMouseGlobalPosition, toUserSpace(screen.frame, nil));
+
+    return m_lastKnownMousePosition + autoscrollAdjustmentFactor;
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformPlatformScreenh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/PlatformScreen.h (198691 => 198692)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/PlatformScreen.h        2016-03-25 21:55:34 UTC (rev 198691)
+++ trunk/Source/WebCore/platform/PlatformScreen.h        2016-03-25 22:01:30 UTC (rev 198692)
</span><span class="lines">@@ -65,6 +65,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     NSScreen *screenForWindow(NSWindow *);
</span><ins>+    NSScreen *screenForDisplayID(PlatformDisplayID);
</ins><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT FloatRect toUserSpace(const NSRect&amp;, NSWindow *destination);
</span><span class="cx">     WEBCORE_EXPORT NSRect toDeviceSpace(const FloatRect&amp;, NSWindow *source);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacPlatformScreenMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm (198691 => 198692)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm        2016-03-25 21:55:34 UTC (rev 198691)
+++ trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm        2016-03-25 22:01:30 UTC (rev 198692)
</span><span class="lines">@@ -42,15 +42,6 @@
</span><span class="cx">     return (PlatformDisplayID)[[[screen deviceDescription] objectForKey:@&quot;NSScreenNumber&quot;] intValue];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static NSScreen *screenForDisplayID(PlatformDisplayID displayID)
-{
-    for (NSScreen *screen in [NSScreen screens]) {
-        if (displayIDFromScreen(screen) == displayID)
-            return screen;
-    }
-    return nil;
-}
-
</del><span class="cx"> // These functions scale between screen and page coordinates because JavaScript/DOM operations
</span><span class="cx"> // assume that the screen and the page share the same coordinate system.
</span><span class="cx"> 
</span><span class="lines">@@ -135,6 +126,15 @@
</span><span class="cx">     return nil;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+NSScreen *screenForDisplayID(PlatformDisplayID displayID)
+{
+    for (NSScreen *screen in [NSScreen screens]) {
+        if (displayIDFromScreen(screen) == displayID)
+            return screen;
+    }
+    return nil;
+}
+
</ins><span class="cx"> FloatRect toUserSpace(const NSRect&amp; rect, NSWindow *destination)
</span><span class="cx"> {
</span><span class="cx">     FloatRect userRect = rect;
</span></span></pre>
</div>
</div>

</body>
</html>