<!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>[166110] trunk/Source</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/166110">166110</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2014-03-21 19:40:31 -0700 (Fri, 21 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS][WK2] Reduce the tiling coverage to the current rect and 1 tile size ahead
https://bugs.webkit.org/show_bug.cgi?id=130555

Patch by Benjamin Poulain &lt;bpoulain@apple.com&gt; on 2014-03-21
Reviewed by Simon Fraser.

Source/WebCore: 

* WebCore.exp.in:
* platform/ScrollView.h:
* platform/graphics/ca/mac/TileController.mm:
(WebCore::TileController::computeTileCoverageRect):
* platform/ios/ScrollViewIOS.mm:
(WebCore::ScrollView::setScrollVelocityInformation):
(WebCore::ScrollView::computeCoverageRect):
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::flushPendingLayerChanges):

Source/WebKit2: 

* Shared/VisibleContentRectUpdateInfo.cpp:
(WebKit::VisibleContentRectUpdateInfo::encode):
(WebKit::VisibleContentRectUpdateInfo::decode):
* Shared/VisibleContentRectUpdateInfo.h:
(WebKit::VisibleContentRectUpdateInfo::VisibleContentRectUpdateInfo):
(WebKit::operator==):
* UIProcess/ios/WKContentView.mm:
(WebKit::HistoricalKinematicData::HistoricalKinematicData):
(WebKit::HistoricalKinematicData::velocityForNewData):
(WebKit::HistoricalKinematicData::clear):
(WebKit::HistoricalKinematicData::append):
(-[WKContentView didUpdateVisibleRect:unobscuredRect:scale:inStableState:]):
* WebProcess/WebPage/ViewUpdateDispatcher.cpp:
(WebKit::ViewUpdateDispatcher::visibleContentRectUpdate):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::updateVisibleContentRects):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollViewh">trunk/Source/WebCore/platform/ScrollView.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscamacTileControllermm">trunk/Source/WebCore/platform/graphics/ca/mac/TileController.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosScrollViewIOSmm">trunk/Source/WebCore/platform/ios/ScrollViewIOS.mm</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderLayerCompositorcpp">trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedVisibleContentRectUpdateInfocpp">trunk/Source/WebKit2/Shared/VisibleContentRectUpdateInfo.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedVisibleContentRectUpdateInfoh">trunk/Source/WebKit2/Shared/VisibleContentRectUpdateInfo.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewmm">trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebCore/ChangeLog        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2014-03-21  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
+        [iOS][WK2] Reduce the tiling coverage to the current rect and 1 tile size ahead
+        https://bugs.webkit.org/show_bug.cgi?id=130555
+
+        Reviewed by Simon Fraser.
+
+        * WebCore.exp.in:
+        * platform/ScrollView.h:
+        * platform/graphics/ca/mac/TileController.mm:
+        (WebCore::TileController::computeTileCoverageRect):
+        * platform/ios/ScrollViewIOS.mm:
+        (WebCore::ScrollView::setScrollVelocityInformation):
+        (WebCore::ScrollView::computeCoverageRect):
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::flushPendingLayerChanges):
+
</ins><span class="cx"> 2014-03-21  Eric Carlson  &lt;eric.carlson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS] clean up fullscreen player controller when exiting fullscreen
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -2414,6 +2414,7 @@
</span><span class="cx"> __ZN7WebCore10ScrollView24setUnobscuredContentRectERKNS_7IntRectE
</span><span class="cx"> __ZN7WebCore10XLinkNames4initEv
</span><span class="cx"> __ZN7WebCore10inSameLineERKNS_15VisiblePositionES2_
</span><ins>+__ZN7WebCore10ScrollView17setScrollVelocityEddd
</ins><span class="cx"> __ZN7WebCore11BidiContext41copyStackRemovingUnicodeEmbeddingContextsEv
</span><span class="cx"> __ZN7WebCore11BidiContext6createEh14UCharDirectionbNS_19BidiEmbeddingSourceEPS0_
</span><span class="cx"> __ZN7WebCore11CachedImage5imageEv
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollView.h (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollView.h        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebCore/platform/ScrollView.h        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -186,6 +186,9 @@
</span><span class="cx">     void setExposedContentRect(const IntRect&amp;);
</span><span class="cx">     void setUnobscuredContentRect(const IntRect&amp;);
</span><span class="cx"> 
</span><ins>+    void setScrollVelocity(double horizontalVelocity, double verticalVelocity, double timestamp);
+    FloatRect computeCoverageRect(double horizontalMargin, double verticalMargin) const;
+
</ins><span class="cx">     void setActualScrollPosition(const IntPoint&amp;);
</span><span class="cx">     TileCache* tileCache();
</span><span class="cx"> #endif
</span><span class="lines">@@ -414,6 +417,10 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     IntRect m_exposedContentRect;
</span><span class="cx">     IntRect m_unobscuredContentRect;
</span><ins>+
+    double m_horizontalVelocity;
+    double m_verticalVelocity;
+    double m_lastVelocityUpdateTime;
</ins><span class="cx"> #else
</span><span class="cx">     IntRect m_fixedVisibleContentRect;
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscamacTileControllermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/ca/mac/TileController.mm (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/ca/mac/TileController.mm        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileController.mm        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -493,20 +493,16 @@
</span><span class="cx">     if (!m_isInWindow)
</span><span class="cx">         return visibleRect;
</span><span class="cx"> 
</span><del>-    bool largeVisibleRectChange = !previousVisibleRect.isEmpty() &amp;&amp; !visibleRect.intersects(previousVisibleRect);
-    
</del><span class="cx">     // FIXME: look at how far the document can scroll in each dimension.
</span><span class="cx">     float coverageHorizontalSize = visibleRect.width();
</span><span class="cx">     float coverageVerticalSize = visibleRect.height();
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-    // FIXME: ViewUpdateDispatcher could do an amazing job at computing this (&lt;rdar://problem/16205290&gt;).
-    // In the meantime, just default to something good enough.
-    if (!largeVisibleRectChange) {
-        coverageHorizontalSize *= 1.5;
-        coverageVerticalSize *= 1.5;
-    }
</del><ins>+    UNUSED_PARAM(previousVisibleRect);
+    return visibleRect;
</ins><span class="cx"> #else
</span><ins>+    bool largeVisibleRectChange = !previousVisibleRect.isEmpty() &amp;&amp; !visibleRect.intersects(previousVisibleRect);
+
</ins><span class="cx">     // Inflate the coverage rect so that it covers 2x of the visible width and 3x of the visible height.
</span><span class="cx">     // These values were chosen because it's more common to have tall pages and to scroll vertically,
</span><span class="cx">     // so we keep more tiles above and below the current area.
</span><span class="lines">@@ -516,10 +512,9 @@
</span><span class="cx"> 
</span><span class="cx">     if (m_tileCoverage &amp; CoverageForVerticalScrolling &amp;&amp; !largeVisibleRectChange)
</span><span class="cx">         coverageVerticalSize *= 3;
</span><del>-
</del><ins>+#endif
</ins><span class="cx">     coverageVerticalSize += topMarginHeight() + bottomMarginHeight();
</span><span class="cx">     coverageHorizontalSize += leftMarginWidth() + rightMarginWidth();
</span><del>-#endif
</del><span class="cx"> 
</span><span class="cx">     FloatRect coverageBounds = bounds();
</span><span class="cx">     float coverageLeft = visibleRect.x() - (coverageHorizontalSize - visibleRect.width()) / 2;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosScrollViewIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/ScrollViewIOS.mm (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/ScrollViewIOS.mm        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebCore/platform/ios/ScrollViewIOS.mm        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> #import &quot;WAKWindow.h&quot;
</span><span class="cx"> #import &quot;WKViewPrivate.h&quot;
</span><span class="cx"> #import &quot;WebCoreFrameView.h&quot;
</span><ins>+#import &lt;wtf/CurrentTime.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> using namespace std;
</span><span class="cx"> 
</span><span class="lines">@@ -118,6 +119,45 @@
</span><span class="cx">     m_unobscuredContentRect = rect;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ScrollView::setScrollVelocity(double horizontalVelocity, double verticalVelocity, double timestamp)
+{
+    m_horizontalVelocity = horizontalVelocity;
+    m_verticalVelocity = verticalVelocity;
+    m_lastVelocityUpdateTime = timestamp;
+}
+
+FloatRect ScrollView::computeCoverageRect(double horizontalMargin, double verticalMargin) const
+{
+    FloatRect exposedContentRect = this-&gt;exposedContentRect();
+
+    double currentTime = monotonicallyIncreasingTime();
+    double timeDelta = currentTime - m_lastVelocityUpdateTime;
+
+    FloatRect futureRect = exposedContentRect;
+    futureRect.setLocation(FloatPoint(futureRect.location().x() + timeDelta * m_horizontalVelocity, futureRect.location().y() + timeDelta * m_verticalVelocity));
+
+    if (m_horizontalVelocity) {
+        futureRect.setWidth(futureRect.width() + horizontalMargin);
+        if (m_horizontalVelocity &lt; 0)
+            futureRect.setX(std::max(futureRect.x() - horizontalMargin, 0.));
+    }
+
+    if (m_verticalVelocity) {
+        futureRect.setHeight(futureRect.height() + verticalMargin);
+        if (m_verticalVelocity &lt; 0)
+            futureRect.setY(std::max(futureRect.y() - verticalMargin, 0.));
+    }
+
+    if (!m_horizontalVelocity &amp;&amp; !m_verticalVelocity) {
+        futureRect.setWidth(futureRect.width() + horizontalMargin);
+        futureRect.setHeight(futureRect.height() + verticalMargin);
+        futureRect.setX(std::max(futureRect.x() - horizontalMargin / 2, 0.));
+        futureRect.setY(std::max(futureRect.y() - verticalMargin / 2, 0.));
+    }
+
+    return futureRect;
+}
+
</ins><span class="cx"> IntRect ScrollView::exposedContentRect() const
</span><span class="cx"> {
</span><span class="cx">     if (NSScrollView *view = static_cast&lt;NSScrollView *&gt;(platformWidget())) {
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderLayerCompositorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -420,7 +420,9 @@
</span><span class="cx"> 
</span><span class="cx">     if (GraphicsLayer* rootLayer = rootGraphicsLayer()) {
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-        rootLayer-&gt;flushCompositingState(frameView.exposedContentRect());
</del><ins>+        double horizontalMargin = defaultTileWidth / pageScaleFactor();
+        double verticalMargin = defaultTileHeight / pageScaleFactor();
+        rootLayer-&gt;flushCompositingState(frameView.computeCoverageRect(horizontalMargin, verticalMargin));
</ins><span class="cx"> #else
</span><span class="cx">         // Having a m_clipLayer indicates that we're doing scrolling via GraphicsLayers.
</span><span class="cx">         IntRect visibleRect = m_clipLayer ? IntRect(IntPoint(), frameView.contentsSize()) : frameView.visibleContentRect();
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebKit2/ChangeLog        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2014-03-21  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
+        [iOS][WK2] Reduce the tiling coverage to the current rect and 1 tile size ahead
+        https://bugs.webkit.org/show_bug.cgi?id=130555
+
+        Reviewed by Simon Fraser.
+
+        * Shared/VisibleContentRectUpdateInfo.cpp:
+        (WebKit::VisibleContentRectUpdateInfo::encode):
+        (WebKit::VisibleContentRectUpdateInfo::decode):
+        * Shared/VisibleContentRectUpdateInfo.h:
+        (WebKit::VisibleContentRectUpdateInfo::VisibleContentRectUpdateInfo):
+        (WebKit::operator==):
+        * UIProcess/ios/WKContentView.mm:
+        (WebKit::HistoricalKinematicData::HistoricalKinematicData):
+        (WebKit::HistoricalKinematicData::velocityForNewData):
+        (WebKit::HistoricalKinematicData::clear):
+        (WebKit::HistoricalKinematicData::append):
+        (-[WKContentView didUpdateVisibleRect:unobscuredRect:scale:inStableState:]):
+        * WebProcess/WebPage/ViewUpdateDispatcher.cpp:
+        (WebKit::ViewUpdateDispatcher::visibleContentRectUpdate):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::updateVisibleContentRects):
+
</ins><span class="cx"> 2014-03-21  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r165356): Predictive Chinese input is broken
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedVisibleContentRectUpdateInfocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/VisibleContentRectUpdateInfo.cpp (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/VisibleContentRectUpdateInfo.cpp        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebKit2/Shared/VisibleContentRectUpdateInfo.cpp        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -38,6 +38,9 @@
</span><span class="cx">     encoder &lt;&lt; m_scale;
</span><span class="cx">     encoder &lt;&lt; m_updateID;
</span><span class="cx">     encoder &lt;&lt; m_inStableState;
</span><ins>+    encoder &lt;&lt; m_timestamp;
+    encoder &lt;&lt; m_horizontalVelocity;
+    encoder &lt;&lt; m_verticalVelocity;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool VisibleContentRectUpdateInfo::decode(IPC::ArgumentDecoder&amp; decoder, VisibleContentRectUpdateInfo&amp; result)
</span><span class="lines">@@ -54,6 +57,13 @@
</span><span class="cx">         return false;
</span><span class="cx">     if (!decoder.decode(result.m_inStableState))
</span><span class="cx">         return false;
</span><ins>+    if (!decoder.decode(result.m_timestamp))
+        return false;
+    if (!decoder.decode(result.m_horizontalVelocity))
+        return false;
+    if (!decoder.decode(result.m_verticalVelocity))
+        return false;
+
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedVisibleContentRectUpdateInfoh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/VisibleContentRectUpdateInfo.h (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/VisibleContentRectUpdateInfo.h        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebKit2/Shared/VisibleContentRectUpdateInfo.h        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -44,13 +44,16 @@
</span><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    VisibleContentRectUpdateInfo(uint64_t updateID, const WebCore::FloatRect&amp; exposedRect, const WebCore::FloatRect&amp; unobscuredRect, const WebCore::FloatRect&amp; customFixedPositionRect, double scale, bool inStableState)
</del><ins>+    VisibleContentRectUpdateInfo(uint64_t updateID, const WebCore::FloatRect&amp; exposedRect, const WebCore::FloatRect&amp; unobscuredRect, const WebCore::FloatRect&amp; customFixedPositionRect, double scale, bool inStableState, double timestamp, double horizontalVelocity, double verticalVelocity)
</ins><span class="cx">         : m_exposedRect(exposedRect)
</span><span class="cx">         , m_unobscuredRect(unobscuredRect)
</span><span class="cx">         , m_customFixedPositionRect(customFixedPositionRect)
</span><span class="cx">         , m_scale(scale)
</span><span class="cx">         , m_updateID(updateID)
</span><span class="cx">         , m_inStableState(inStableState)
</span><ins>+        , m_timestamp(timestamp)
+        , m_horizontalVelocity(horizontalVelocity)
+        , m_verticalVelocity(verticalVelocity)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -71,11 +74,16 @@
</span><span class="cx">     double m_scale;
</span><span class="cx">     uint64_t m_updateID;
</span><span class="cx">     bool m_inStableState;
</span><ins>+public:
+    double m_timestamp;
+    double m_horizontalVelocity;
+    double m_verticalVelocity;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> inline bool operator==(const VisibleContentRectUpdateInfo&amp; a, const VisibleContentRectUpdateInfo&amp; b)
</span><span class="cx"> {
</span><span class="cx">     // Note: the comparison doesn't include updateID since we care about equality based on the other data.
</span><ins>+    // The timestamp and velocity are also irrelevant for comparing updates.
</ins><span class="cx">     return a.scale() == b.scale()
</span><span class="cx">         &amp;&amp; a.exposedRect() == b.exposedRect()
</span><span class="cx">         &amp;&amp; a.unobscuredRect() == b.unobscuredRect()
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentView.mm        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -48,6 +48,7 @@
</span><span class="cx"> #import &quot;WebKitSystemInterfaceIOS.h&quot;
</span><span class="cx"> #import &lt;WebCore/FrameView.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIWindow_Private.h&gt;
</span><ins>+#import &lt;wtf/CurrentTime.h&gt;
</ins><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if __has_include(&lt;QuartzCore/QuartzCorePrivate.h&gt;)
</span><span class="lines">@@ -61,6 +62,74 @@
</span><span class="cx"> using namespace WebCore;
</span><span class="cx"> using namespace WebKit;
</span><span class="cx"> 
</span><ins>+namespace WebKit {
+class HistoricalVelocityData {
+public:
+    HistoricalVelocityData()
+        : m_historySize(0)
+        , m_latestDataIndex(0)
+        , m_lastAppendTimestamp(0)
+    {
+    }
+
+    CGSize velocityForNewData(CGPoint newPosition, double timestamp)
+    {
+        // Due to all the source of rect update, the input is very noisy. To smooth the output, we accumulate all changes
+        // within 1 frame as a single update. No speed computation is ever done on data within the same frame.
+        const double filteringThreshold = 1 / 60.;
+
+        CGSize velocity = CGSizeZero;
+        if (m_historySize &gt; 0) {
+            unsigned oldestDataIndex;
+            unsigned distanceToLastHistoricalData = m_historySize - 1;
+            if (distanceToLastHistoricalData &lt;= m_latestDataIndex)
+                oldestDataIndex = m_latestDataIndex - distanceToLastHistoricalData;
+            else
+                oldestDataIndex = m_historySize - (distanceToLastHistoricalData - m_latestDataIndex);
+
+            double timeDelta = timestamp - m_history[oldestDataIndex].timestamp;
+            if (timeDelta &gt; filteringThreshold)
+                velocity =  CGSizeMake((newPosition.x - m_history[oldestDataIndex].position.x) / timeDelta, (newPosition.y - m_history[oldestDataIndex].position.y) / timeDelta);
+        }
+
+        double timeSinceLastAppend = timestamp - m_lastAppendTimestamp;
+        if (timeSinceLastAppend &gt; filteringThreshold)
+            append(newPosition, timestamp);
+        else
+            m_history[m_latestDataIndex] = { timestamp, newPosition };
+        return velocity;
+    }
+
+    void clear() { m_historySize = 0; }
+
+private:
+    void append(CGPoint newPosition, double timestamp)
+    {
+        m_latestDataIndex = (m_latestDataIndex + 1) % maxHistoryDepth;
+        m_history[m_latestDataIndex] = { timestamp, newPosition };
+
+        unsigned size = m_historySize + 1;
+        if (size &lt;= maxHistoryDepth)
+            m_historySize = size;
+
+        m_lastAppendTimestamp = timestamp;
+    }
+
+
+    static const unsigned maxHistoryDepth = 3;
+
+    unsigned m_historySize;
+    unsigned m_latestDataIndex;
+    double m_lastAppendTimestamp;
+
+    // FIXME: add scale information.
+    struct Data {
+        double timestamp;
+        CGPoint position;
+    } m_history[maxHistoryDepth];
+};
+} // namespace WebKit
+
</ins><span class="cx"> @implementation WKContentView {
</span><span class="cx">     std::unique_ptr&lt;PageClientImpl&gt; _pageClient;
</span><span class="cx">     RetainPtr&lt;WKBrowsingContextController&gt; _browsingContextController;
</span><span class="lines">@@ -68,6 +137,8 @@
</span><span class="cx">     RetainPtr&lt;UIView&gt; _rootContentView;
</span><span class="cx"> 
</span><span class="cx">     WKWebView *_webView;
</span><ins>+
+    HistoricalVelocityData _historicalKinematicData;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (instancetype)initWithFrame:(CGRect)frame context:(WebKit::WebContext&amp;)context configuration:(WebKit::WebPageConfiguration)webPageConfiguration webView:(WKWebView *)webView
</span><span class="lines">@@ -166,6 +237,13 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)didUpdateVisibleRect:(CGRect)visibleRect unobscuredRect:(CGRect)unobscuredRect scale:(CGFloat)zoomScale inStableState:(BOOL)isStableState
</span><span class="cx"> {
</span><ins>+    double timestamp = monotonicallyIncreasingTime();
+    CGSize velocity = CGSizeZero;
+    if (!isStableState)
+        velocity = _historicalKinematicData.velocityForNewData(visibleRect.origin, timestamp);
+    else
+        _historicalKinematicData.clear();
+
</ins><span class="cx">     double scaleNoiseThreshold = 0.0005;
</span><span class="cx">     CGFloat filteredScale = zoomScale;
</span><span class="cx">     if (!isStableState &amp;&amp; fabs(filteredScale - _page-&gt;displayedContentScale()) &lt; scaleNoiseThreshold) {
</span><span class="lines">@@ -175,7 +253,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     CGRect customFixedPositionRect = [self fixedPositionRectFromExposedRect:unobscuredRect scale:zoomScale];
</span><del>-    _page-&gt;updateVisibleContentRects(VisibleContentRectUpdateInfo(_page-&gt;nextVisibleContentRectUpdateID(), visibleRect, unobscuredRect, customFixedPositionRect, filteredScale, isStableState));
</del><ins>+    _page-&gt;updateVisibleContentRects(VisibleContentRectUpdateInfo(_page-&gt;nextVisibleContentRectUpdateID(), visibleRect, unobscuredRect, customFixedPositionRect, filteredScale, isStableState, timestamp, velocity.width, velocity.height));
</ins><span class="cx">     
</span><span class="cx">     RemoteScrollingCoordinatorProxy* scrollingCoordinator = _page-&gt;scrollingCoordinatorProxy();
</span><span class="cx">     scrollingCoordinator-&gt;viewportChangedViaDelegatedScrolling(scrollingCoordinator-&gt;rootScrollingNodeID(), unobscuredRect, zoomScale);
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (166109 => 166110)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-03-22 01:02:24 UTC (rev 166109)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-03-22 02:40:31 UTC (rev 166110)
</span><span class="lines">@@ -1666,6 +1666,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_page-&gt;mainFrame().view()-&gt;setScrollOffset(scrollPosition);
</span><span class="cx">     m_page-&gt;mainFrame().view()-&gt;setUnobscuredContentRect(roundedUnobscuredRect);
</span><ins>+    m_page-&gt;mainFrame().view()-&gt;setScrollVelocity(visibleContentRectUpdateInfo.m_horizontalVelocity, visibleContentRectUpdateInfo.m_verticalVelocity, visibleContentRectUpdateInfo.m_timestamp);
</ins><span class="cx"> 
</span><span class="cx">     if (visibleContentRectUpdateInfo.inStableState())
</span><span class="cx">         m_page-&gt;mainFrame().view()-&gt;setCustomFixedPositionLayoutRect(enclosingIntRect(visibleContentRectUpdateInfo.customFixedPositionRect()));
</span></span></pre>
</div>
</div>

</body>
</html>