<!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>[183998] trunk</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/183998">183998</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2015-05-08 11:15:57 -0700 (Fri, 08 May 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Throttle RequestAnimationFrame in subframes that are outside the viewport
https://bugs.webkit.org/show_bug.cgi?id=144718
<rdar://problem/20688782>
Reviewed by Simon Fraser.
Source/WebCore:
Throttle RequestAnimationFrame in subframes that are outside the
viewport or have "display: none" for performance and power.
Tests: fast/animation/request-animation-frame-throttle-subframe-display-none.html
fast/animation/request-animation-frame-throttle-subframe.html
* dom/Document.h:
(WebCore::Document::scriptedAnimationController):
* dom/ScriptedAnimationController.cpp:
(WebCore::ScriptedAnimationController::setThrottled):
(WebCore::ScriptedAnimationController::isThrottled):
* dom/ScriptedAnimationController.h:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::open):
Call FrameView::setFrameRect() only *after* the view has been
set on the Frame. Otherwise, setFrameRect() ends up calling
viewportContentsChanged() and we hit the
ASSERT(frame().view() == this) assertion in windowClipRect()
because the Frame still has its old FrameView. This is covered
by loader/go-back-to-different-window-size.html layout test.
* page/FrameView.cpp:
(WebCore::FrameView::viewportContentsChanged):
(WebCore::FrameView::applyRecursivelyWithVisibleRect):
(WebCore::FrameView::resumeVisibleImageAnimations):
(WebCore::FrameView::updateScriptedAnimationsThrottlingState):
(WebCore::FrameView::resumeVisibleImageAnimationsIncludingSubframes):
(WebCore::FrameView::updateThrottledDOMTimersState):
(WebCore::FrameView::scrollPositionChanged): Deleted.
(WebCore::FrameView::sendResizeEventIfNeeded): Deleted.
* page/FrameView.h:
* testing/Internals.cpp:
(WebCore::Internals::isRequestAnimationFrameThrottled):
(WebCore::Internals::isTimerThrottled): Deleted.
* testing/Internals.h:
* testing/Internals.idl:
LayoutTests:
* fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt: Added.
* fast/animation/request-animation-frame-throttle-subframe-display-none.html: Added.
Add layout test to test that RequestAnimationFrame is properly throttled
in "display: none" subframes.
* fast/animation/request-animation-frame-throttle-subframe-expected.txt: Added.
* fast/animation/request-animation-frame-throttle-subframe.html: Added.
Add layout test to test that RequestAnimationFrame is properly throttled
in frames that are outside the viewport.
* fast/animation/resources/requestAnimationFrame-frame-2.html: Added.
* fast/animation/resources/requestAnimationFrame-frame.html: Added.
* platform/win/TestExpectations:
Skip the 2 new tests on Windows as requestAnimationFrame throttling is
only supported on Cocoa.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformwinTestExpectations">trunk/LayoutTests/platform/win/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</a></li>
<li><a href="#trunkSourceWebCoredomScriptedAnimationControllercpp">trunk/Source/WebCore/dom/ScriptedAnimationController.cpp</a></li>
<li><a href="#trunkSourceWebCoredomScriptedAnimationControllerh">trunk/Source/WebCore/dom/ScriptedAnimationController.h</a></li>
<li><a href="#trunkSourceWebCoreloaderFrameLoadercpp">trunk/Source/WebCore/loader/FrameLoader.cpp</a></li>
<li><a href="#trunkSourceWebCorepageFrameViewcpp">trunk/Source/WebCore/page/FrameView.cpp</a></li>
<li><a href="#trunkSourceWebCorepageFrameViewh">trunk/Source/WebCore/page/FrameView.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsh">trunk/Source/WebCore/testing/Internals.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsidl">trunk/Source/WebCore/testing/Internals.idl</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastanimationrequestanimationframethrottlesubframedisplaynoneexpectedtxt">trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastanimationrequestanimationframethrottlesubframedisplaynonehtml">trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none.html</a></li>
<li><a href="#trunkLayoutTestsfastanimationrequestanimationframethrottlesubframeexpectedtxt">trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastanimationrequestanimationframethrottlesubframehtml">trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html</a></li>
<li>trunk/LayoutTests/fast/animation/resources/</li>
<li><a href="#trunkLayoutTestsfastanimationresourcesrequestAnimationFrameframe2html">trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame-2.html</a></li>
<li><a href="#trunkLayoutTestsfastanimationresourcesrequestAnimationFrameframehtml">trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/LayoutTests/ChangeLog        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2015-05-08 Chris Dumez <cdumez@apple.com>
+
+ Throttle RequestAnimationFrame in subframes that are outside the viewport
+ https://bugs.webkit.org/show_bug.cgi?id=144718
+ <rdar://problem/20688782>
+
+ Reviewed by Simon Fraser.
+
+ * fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt: Added.
+ * fast/animation/request-animation-frame-throttle-subframe-display-none.html: Added.
+ Add layout test to test that RequestAnimationFrame is properly throttled
+ in "display: none" subframes.
+
+ * fast/animation/request-animation-frame-throttle-subframe-expected.txt: Added.
+ * fast/animation/request-animation-frame-throttle-subframe.html: Added.
+ Add layout test to test that RequestAnimationFrame is properly throttled
+ in frames that are outside the viewport.
+
+ * fast/animation/resources/requestAnimationFrame-frame-2.html: Added.
+ * fast/animation/resources/requestAnimationFrame-frame.html: Added.
+
+ * platform/win/TestExpectations:
+ Skip the 2 new tests on Windows as requestAnimationFrame throttling is
+ only supported on Cocoa.
+
</ins><span class="cx"> 2015-05-08 Carlos Garcia Campos <cgarcia@igalia.com>
</span><span class="cx">
</span><span class="cx"> [GTK] WTR doesn't correctly handle the Escape key
</span></span></pre></div>
<a id="trunkLayoutTestsfastanimationrequestanimationframethrottlesubframedisplaynoneexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none-expected.txt        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+Tests that requestAnimationFrame is throttled in subframes that are display:none
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Frame is initially visibile so requestAnimationFrame should not be throttled
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() became false
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is false
+Hiding subframe.
+testFrame.style.display = 'none';
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() became true
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is true
+Show subframe again
+testFrame.style.display = 'block';
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() became false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastanimationrequestanimationframethrottlesubframedisplaynonehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none.html (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none.html         (rev 0)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-display-none.html        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,44 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../resources/js-test-pre.js"></script>
+<script>
+description("Tests that requestAnimationFrame is throttled in subframes that are display:none");
+window.jsTestIsAsync = true;
+
+function checkSubframeThrottled()
+{
+ shouldBeTrue("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
+
+ debug("Show subframe again");
+ evalAndLog("testFrame.style.display = 'block';");
+
+ shouldBecomeEqual("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()", "false", finishJSTest);
+}
+
+function hideFrame()
+{
+ shouldBeFalse("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
+
+ debug("Hiding subframe.");
+ evalAndLog("testFrame.style.display = 'none';");
+
+ shouldBecomeEqual("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()", "true", checkSubframeThrottled);
+}
+
+function runTest()
+{
+ testFrame = document.getElementById("testFrame");
+ debug("Frame is initially visibile so requestAnimationFrame should not be throttled");
+ shouldBecomeEqual("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()", "false", hideFrame);
+}
+
+var i = 0;
+requestAnimationFrame(function() {
+ i++;
+});
+</script>
+<iframe id="testFrame" src="resources/requestAnimationFrame-frame.html" onload="runTest()"></iframe>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsfastanimationrequestanimationframethrottlesubframeexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-expected.txt (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe-expected.txt        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,24 @@
</span><ins>+Tests that requestAnimationFrame is throttled in subframes that are outside the viewport
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Frame is initially outside the viewport so requestAnimationFrame should be throttled
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() became true
+PASS internals.isRequestAnimationFrameThrottled() is false
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is true
+PASS grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is true
+Scrolling frame into view.
+RequestAnimationFrame should no longer be throttled
+PASS internals.isRequestAnimationFrameThrottled() is false
+PASS grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is false
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is false
+Scrolling frame out of view again.
+PASS internals.isRequestAnimationFrameThrottled() is false
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() became true
+PASS testFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is true
+PASS grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled() is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastanimationrequestanimationframethrottlesubframehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html         (rev 0)
+++ trunk/LayoutTests/fast/animation/request-animation-frame-throttle-subframe.html        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,61 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../resources/js-test-pre.js"></script>
+<script>
+description("Tests that requestAnimationFrame is throttled in subframes that are outside the viewport");
+window.jsTestIsAsync = true;
+
+function checkSubframesThrottled()
+{
+ shouldBeTrue("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
+ shouldBeTrue("grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
+
+ finishJSTest();
+}
+
+function scrollFrameOutOfView()
+{
+ debug("Scrolling frame out of view again.");
+ window.scroll(0, 0);
+
+ shouldBeFalse("internals.isRequestAnimationFrameThrottled()");
+ shouldBecomeEqual("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()", "true", checkSubframesThrottled);
+}
+
+function scrollFrameIntoView()
+{
+ shouldBeFalse("internals.isRequestAnimationFrameThrottled()");
+ shouldBeTrue("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
+ shouldBeTrue("grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
+
+ debug("Scrolling frame into view.");
+ window.internals.scrollElementToRect(testFrame, 0, 0, 300, 300);
+
+ debug("RequestAnimationFrame should no longer be throttled");
+ shouldBeFalse("internals.isRequestAnimationFrameThrottled()");
+ shouldBeFalse("grandChildFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
+ shouldBeFalse("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()");
+
+ scrollFrameOutOfView();
+}
+
+function runTest()
+{
+ testFrame = document.getElementById("testFrame");
+ grandChildFrame = testFrame.contentDocument.getElementById("grandChildFrame");
+ debug("Frame is initially outside the viewport so requestAnimationFrame should be throttled");
+ shouldBecomeEqual("testFrame.contentWindow.internals.isRequestAnimationFrameThrottled()", "true", scrollFrameIntoView);
+}
+
+var i = 0;
+requestAnimationFrame(function() {
+ i++;
+});
+</script>
+<div style="position: relative; width: 1600px; height: 2400px; background-color: green;">
+ <iframe id="testFrame" src="resources/requestAnimationFrame-frame.html" style="position:absolute; left: 600px; top: 800px;" onload="runTest()"></iframe>
+</div>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsfastanimationresourcesrequestAnimationFrameframe2html"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame-2.html (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame-2.html         (rev 0)
+++ trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame-2.html        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<body>
+<script>
+var i = 0;
+requestAnimationFrame(function() {
+ i++;
+});
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsfastanimationresourcesrequestAnimationFrameframehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame.html (0 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame.html         (rev 0)
+++ trunk/LayoutTests/fast/animation/resources/requestAnimationFrame-frame.html        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<body>
+<iframe id="grandChildFrame" src="requestAnimationFrame-frame-2.html"></iframe>
+<script>
+var i = 0;
+requestAnimationFrame(function() {
+ i++;
+});
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformwinTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/win/TestExpectations (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/win/TestExpectations        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/LayoutTests/platform/win/TestExpectations        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -2496,6 +2496,10 @@
</span><span class="cx"> webkit.org/b/138676 imported/w3c/canvas/2d.line.join.parallel.html [ Failure ]
</span><span class="cx"> webkit.org/b/138676 imported/w3c/canvas/2d.strokeRect.zero.5.html [ Failure ]
</span><span class="cx">
</span><ins>+# requestAnimationFrame throttling does not work on Windows because USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) is disabled.
+webkit.org/b/144718 fast/animation/request-animation-frame-throttle-subframe-display-none.html [ Skip ]
+webkit.org/b/144718 fast/animation/request-animation-frame-throttle-subframe.html [ Skip ]
+
</ins><span class="cx"> ################################################################################
</span><span class="cx"> ######################### Start list of UNREVIEWED failures ########################
</span><span class="cx"> ################################################################################
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/ChangeLog        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -1,3 +1,48 @@
</span><ins>+2015-05-08 Chris Dumez <cdumez@apple.com>
+
+ Throttle RequestAnimationFrame in subframes that are outside the viewport
+ https://bugs.webkit.org/show_bug.cgi?id=144718
+ <rdar://problem/20688782>
+
+ Reviewed by Simon Fraser.
+
+ Throttle RequestAnimationFrame in subframes that are outside the
+ viewport or have "display: none" for performance and power.
+
+ Tests: fast/animation/request-animation-frame-throttle-subframe-display-none.html
+ fast/animation/request-animation-frame-throttle-subframe.html
+
+ * dom/Document.h:
+ (WebCore::Document::scriptedAnimationController):
+ * dom/ScriptedAnimationController.cpp:
+ (WebCore::ScriptedAnimationController::setThrottled):
+ (WebCore::ScriptedAnimationController::isThrottled):
+ * dom/ScriptedAnimationController.h:
+ * loader/FrameLoader.cpp:
+ (WebCore::FrameLoader::open):
+ Call FrameView::setFrameRect() only *after* the view has been
+ set on the Frame. Otherwise, setFrameRect() ends up calling
+ viewportContentsChanged() and we hit the
+ ASSERT(frame().view() == this) assertion in windowClipRect()
+ because the Frame still has its old FrameView. This is covered
+ by loader/go-back-to-different-window-size.html layout test.
+
+ * page/FrameView.cpp:
+ (WebCore::FrameView::viewportContentsChanged):
+ (WebCore::FrameView::applyRecursivelyWithVisibleRect):
+ (WebCore::FrameView::resumeVisibleImageAnimations):
+ (WebCore::FrameView::updateScriptedAnimationsThrottlingState):
+ (WebCore::FrameView::resumeVisibleImageAnimationsIncludingSubframes):
+ (WebCore::FrameView::updateThrottledDOMTimersState):
+ (WebCore::FrameView::scrollPositionChanged): Deleted.
+ (WebCore::FrameView::sendResizeEventIfNeeded): Deleted.
+ * page/FrameView.h:
+ * testing/Internals.cpp:
+ (WebCore::Internals::isRequestAnimationFrameThrottled):
+ (WebCore::Internals::isTimerThrottled): Deleted.
+ * testing/Internals.h:
+ * testing/Internals.idl:
+
</ins><span class="cx"> 2015-05-08 Daniel Bates <dabates@apple.com>
</span><span class="cx">
</span><span class="cx"> Fix the iOS Simulator external SDK build following <http://trac.webkit.org/changeset/181918>
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/dom/Document.h        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -948,6 +948,9 @@
</span><span class="cx">
</span><span class="cx"> virtual void postTask(Task) override final; // Executes the task on context's thread asynchronously.
</span><span class="cx">
</span><ins>+#if ENABLE(REQUEST_ANIMATION_FRAME)
+ ScriptedAnimationController* scriptedAnimationController() { return m_scriptedAnimationController.get(); }
+#endif
</ins><span class="cx"> void suspendScriptedAnimationControllerCallbacks();
</span><span class="cx"> void resumeScriptedAnimationControllerCallbacks();
</span><span class="cx"> void scriptedAnimationControllerSetThrottled(bool);
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptedAnimationControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptedAnimationController.cpp (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptedAnimationController.cpp        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/dom/ScriptedAnimationController.cpp        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -34,6 +34,8 @@
</span><span class="cx"> #include "DocumentLoader.h"
</span><span class="cx"> #include "FrameView.h"
</span><span class="cx"> #include "InspectorInstrumentation.h"
</span><ins>+#include "Logging.h"
+#include "MainFrame.h"
</ins><span class="cx"> #include "RequestAnimationFrameCallback.h"
</span><span class="cx"> #include "Settings.h"
</span><span class="cx"> #include <wtf/Ref.h>
</span><span class="lines">@@ -84,6 +86,8 @@
</span><span class="cx"> if (m_isThrottled == isThrottled)
</span><span class="cx"> return;
</span><span class="cx">
</span><ins>+ LOG(Animations, "%p - Setting RequestAnimationFrame throttling state to %d in frame %p (isMainFrame: %d)", this, isThrottled, m_document->frame(), m_document->frame() ? m_document->frame()->isMainFrame() : 0);
+
</ins><span class="cx"> m_isThrottled = isThrottled;
</span><span class="cx"> if (m_animationTimer.isActive()) {
</span><span class="cx"> m_animationTimer.stop();
</span><span class="lines">@@ -94,6 +98,15 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+bool ScriptedAnimationController::isThrottled() const
+{
+#if USE(REQUEST_ANIMATION_FRAME_TIMER) && USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
+ return m_isThrottled;
+#else
+ return false;
+#endif
+}
+
</ins><span class="cx"> ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCallback(PassRefPtr<RequestAnimationFrameCallback> callback)
</span><span class="cx"> {
</span><span class="cx"> ScriptedAnimationController::CallbackId id = ++m_nextCallbackId;
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptedAnimationControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptedAnimationController.h (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptedAnimationController.h        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/dom/ScriptedAnimationController.h        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -68,6 +68,7 @@
</span><span class="cx"> void suspend();
</span><span class="cx"> void resume();
</span><span class="cx"> void setThrottled(bool);
</span><ins>+ WEBCORE_EXPORT bool isThrottled() const;
</ins><span class="cx">
</span><span class="cx"> void windowScreenDidChange(PlatformDisplayID);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderFrameLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/FrameLoader.cpp        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -2068,10 +2068,12 @@
</span><span class="cx"> ASSERT(view);
</span><span class="cx"> view->setWasScrolledByUser(false);
</span><span class="cx">
</span><del>- // Use the current ScrollView's frame rect.
- if (m_frame.view())
- view->setFrameRect(m_frame.view()->frameRect());
</del><ins>+ Optional<IntRect> previousViewFrameRect = m_frame.view() ? m_frame.view()->frameRect() : Optional<IntRect>(Nullopt);
</ins><span class="cx"> m_frame.setView(view);
</span><ins>+
+ // Use the previous ScrollView's frame rect.
+ if (previousViewFrameRect)
+ view->setFrameRect(previousViewFrameRect.value());
</ins><span class="cx">
</span><span class="cx"> m_frame.setDocument(document);
</span><span class="cx"> document->domWindow()->resumeFromPageCache();
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.cpp (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.cpp        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/page/FrameView.cpp        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -80,6 +80,7 @@
</span><span class="cx"> #include "RenderWidget.h"
</span><span class="cx"> #include "SVGDocument.h"
</span><span class="cx"> #include "SVGSVGElement.h"
</span><ins>+#include "ScriptedAnimationController.h"
</ins><span class="cx"> #include "ScrollAnimator.h"
</span><span class="cx"> #include "ScrollingCoordinator.h"
</span><span class="cx"> #include "Settings.h"
</span><span class="lines">@@ -1755,10 +1756,18 @@
</span><span class="cx">
</span><span class="cx"> void FrameView::viewportContentsChanged()
</span><span class="cx"> {
</span><ins>+ if (!frame().view()) {
+ // The frame is being destroyed.
+ return;
+ }
+
</ins><span class="cx"> // When the viewport contents changes (scroll, resize, style recalc, layout, ...),
</span><span class="cx"> // check if we should resume animated images or unthrottle DOM timers.
</span><del>- resumeVisibleImageAnimationsIncludingSubframes();
- updateThrottledDOMTimersState();
</del><ins>+ applyRecursivelyWithVisibleRect([] (FrameView& frameView, const IntRect& visibleRect) {
+ frameView.resumeVisibleImageAnimations(visibleRect);
+ frameView.updateThrottledDOMTimersState(visibleRect);
+ frameView.updateScriptedAnimationsThrottlingState(visibleRect);
+ });
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool FrameView::fixedElementsLayoutRelativeToFrame() const
</span><span class="lines">@@ -2095,28 +2104,60 @@
</span><span class="cx"> viewportContentsChanged();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void FrameView::resumeVisibleImageAnimationsIncludingSubframes()
</del><ins>+void FrameView::applyRecursivelyWithVisibleRect(const std::function<void (FrameView& frameView, const IntRect& visibleRect)>& apply)
</ins><span class="cx"> {
</span><del>- auto* renderView = frame().contentRenderer();
- if (!renderView)
- return;
-
</del><span class="cx"> IntRect windowClipRect = this->windowClipRect();
</span><span class="cx"> auto visibleRect = windowToContents(windowClipRect);
</span><del>- if (visibleRect.isEmpty())
- return;
</del><ins>+ apply(*this, visibleRect);
</ins><span class="cx">
</span><del>- // Resume paused image animations in this frame.
- renderView->resumePausedImageAnimationsIfNeeded(visibleRect);
-
</del><span class="cx"> // Recursive call for subframes. We cache the current FrameView's windowClipRect to avoid recomputing it for every subframe.
</span><span class="cx"> TemporaryChange<IntRect*> windowClipRectCache(m_cachedWindowClipRect, &windowClipRect);
</span><span class="cx"> for (Frame* childFrame = frame().tree().firstChild(); childFrame; childFrame = childFrame->tree().nextSibling()) {
</span><span class="cx"> if (auto* childView = childFrame->view())
</span><del>- childView->resumeVisibleImageAnimationsIncludingSubframes();
</del><ins>+ childView->applyRecursivelyWithVisibleRect(apply);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void FrameView::resumeVisibleImageAnimations(const IntRect& visibleRect)
+{
+ if (visibleRect.isEmpty())
+ return;
+
+ if (auto* renderView = frame().contentRenderer())
+ renderView->resumePausedImageAnimationsIfNeeded(visibleRect);
+}
+
+void FrameView::updateScriptedAnimationsThrottlingState(const IntRect& visibleRect)
+{
+#if ENABLE(REQUEST_ANIMATION_FRAME)
+ if (frame().isMainFrame())
+ return;
+
+ auto* document = frame().document();
+ if (!document)
+ return;
+
+ auto* scriptedAnimationController = document->scriptedAnimationController();
+ if (!scriptedAnimationController)
+ return;
+
+ // FIXME: This doesn't work for subframes of a "display: none" frame because
+ // they have a non-null ownerRenderer.
+ bool shouldThrottle = !frame().ownerRenderer() || visibleRect.isEmpty();
+ scriptedAnimationController->setThrottled(shouldThrottle);
+#else
+ UNUSED_PARAM(visibleRect);
+#endif
+}
+
+
+void FrameView::resumeVisibleImageAnimationsIncludingSubframes()
+{
+ applyRecursivelyWithVisibleRect([] (FrameView& frameView, const IntRect& visibleRect) {
+ frameView.resumeVisibleImageAnimations(visibleRect);
+ });
+}
+
</ins><span class="cx"> void FrameView::updateLayerPositionsAfterScrolling()
</span><span class="cx"> {
</span><span class="cx"> // If we're scrolling as a result of updating the view size after layout, we'll update widgets and layer positions soon anyway.
</span><span class="lines">@@ -3059,13 +3100,11 @@
</span><span class="cx"> m_throttledTimers.remove(timer);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void FrameView::updateThrottledDOMTimersState()
</del><ins>+void FrameView::updateThrottledDOMTimersState(const IntRect& visibleRect)
</ins><span class="cx"> {
</span><span class="cx"> if (m_throttledTimers.isEmpty())
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- IntRect visibleRect = windowToContents(windowClipRect());
-
</del><span class="cx"> // Do not iterate over the HashSet because calling DOMTimer::updateThrottlingStateAfterViewportChange()
</span><span class="cx"> // may cause timers to remove themselves from it while we are iterating.
</span><span class="cx"> Vector<DOMTimer*> timers;
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.h (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.h        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/page/FrameView.h        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -596,8 +596,12 @@
</span><span class="cx"> void forceLayoutParentViewIfNeeded();
</span><span class="cx"> void performPostLayoutTasks();
</span><span class="cx"> void autoSizeIfEnabled();
</span><del>- void updateThrottledDOMTimersState();
</del><span class="cx">
</span><ins>+ void applyRecursivelyWithVisibleRect(const std::function<void (FrameView& frameView, const IntRect& visibleRect)>&);
+ void updateThrottledDOMTimersState(const IntRect& visibleRect);
+ void resumeVisibleImageAnimations(const IntRect& visibleRect);
+ void updateScriptedAnimationsThrottlingState(const IntRect& visibleRect);
+
</ins><span class="cx"> void updateLayerFlushThrottling();
</span><span class="cx"> WEBCORE_EXPORT void adjustTiledBackingCoverage();
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/testing/Internals.cpp        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -98,6 +98,7 @@
</span><span class="cx"> #include "RenderedDocumentMarker.h"
</span><span class="cx"> #include "RuntimeEnabledFeatures.h"
</span><span class="cx"> #include "SchemeRegistry.h"
</span><ins>+#include "ScriptedAnimationController.h"
</ins><span class="cx"> #include "ScrollingCoordinator.h"
</span><span class="cx"> #include "SerializedScriptValue.h"
</span><span class="cx"> #include "Settings.h"
</span><span class="lines">@@ -766,6 +767,18 @@
</span><span class="cx"> return timer->m_throttleState == DOMTimer::ShouldThrottle;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+bool Internals::isRequestAnimationFrameThrottled() const
+{
+#if ENABLE(REQUEST_ANIMATION_FRAME)
+ auto* scriptedAnimationController = contextDocument()->scriptedAnimationController();
+ if (!scriptedAnimationController)
+ return false;
+ return scriptedAnimationController->isThrottled();
+#else
+ return false;
+#endif
+}
+
</ins><span class="cx"> String Internals::visiblePlaceholder(Element* element)
</span><span class="cx"> {
</span><span class="cx"> if (is<HTMLTextFormControlElement>(element)) {
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/testing/Internals.h        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -113,6 +113,7 @@
</span><span class="cx">
</span><span class="cx"> // DOMTimers throttling testing.
</span><span class="cx"> bool isTimerThrottled(int timeoutId, ExceptionCode&);
</span><ins>+ bool isRequestAnimationFrameThrottled() const;
</ins><span class="cx">
</span><span class="cx"> // Spatial Navigation testing.
</span><span class="cx"> unsigned lastSpatialNavigationCandidateCount(ExceptionCode&) const;
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (183997 => 183998)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.idl        2015-05-08 17:56:25 UTC (rev 183997)
+++ trunk/Source/WebCore/testing/Internals.idl        2015-05-08 18:15:57 UTC (rev 183998)
</span><span class="lines">@@ -279,6 +279,8 @@
</span><span class="cx"> // Query if a timer is currently throttled, to debug timer throttling.
</span><span class="cx"> [RaisesException] boolean isTimerThrottled(long timerHandle);
</span><span class="cx">
</span><ins>+ boolean isRequestAnimationFrameThrottled();
+
</ins><span class="cx"> [RaisesException] void startTrackingStyleRecalcs();
</span><span class="cx"> [RaisesException] unsigned long styleRecalcCount();
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>