Bug 647518 part 1. Make requestAnimationFrame return handles for animation frame requests. r=roc

This commit is contained in:
Boris Zbarsky 2011-12-06 23:43:18 -05:00
parent 27ae7a604d
commit 83bd6bb9a4
6 changed files with 73 additions and 12 deletions

View File

@ -1529,7 +1529,8 @@ public:
*/
virtual Element* LookupImageElement(const nsAString& aElementId) = 0;
void ScheduleFrameRequestCallback(nsIFrameRequestCallback* aCallback);
nsresult ScheduleFrameRequestCallback(nsIFrameRequestCallback* aCallback,
PRInt32 *aHandle);
typedef nsTArray< nsCOMPtr<nsIFrameRequestCallback> > FrameRequestCallbackList;
/**
@ -1810,13 +1811,33 @@ protected:
*/
PRUint32 mExternalScriptsBeingEvaluated;
/**
* The current frame request callback handle
*/
PRInt32 mFrameRequestCallbackCounter;
// Weak reference to mScriptGlobalObject QI:d to nsPIDOMWindow,
// updated on every set of mSecriptGlobalObject.
nsPIDOMWindow *mWindow;
nsCOMPtr<nsIDocumentEncoder> mCachedEncoder;
FrameRequestCallbackList mFrameRequestCallbacks;
struct FrameRequest {
FrameRequest(nsIFrameRequestCallback* aCallback,
PRInt32 aHandle) :
mCallback(aCallback),
mHandle(aHandle)
{}
// Conversion operator so that we can append these to a
// FrameRequestCallbackList
operator nsIFrameRequestCallback* const () const { return mCallback; }
nsCOMPtr<nsIFrameRequestCallback> mCallback;
PRInt32 mHandle;
};
nsTArray<FrameRequest> mFrameRequestCallbacks;
// This object allows us to evict ourself from the back/forward cache. The
// pointer is non-null iff we're currently in the bfcache.

View File

@ -8041,15 +8041,27 @@ nsIDocument::CreateStaticClone(nsISupports* aCloneContainer)
return clonedDoc.forget();
}
void
nsIDocument::ScheduleFrameRequestCallback(nsIFrameRequestCallback* aCallback)
nsresult
nsIDocument::ScheduleFrameRequestCallback(nsIFrameRequestCallback* aCallback,
PRInt32 *aHandle)
{
if (mFrameRequestCallbackCounter == PR_INT32_MAX) {
// Can't increment without overflowing; bail out
return NS_ERROR_NOT_AVAILABLE;
}
PRInt32 newHandle = ++mFrameRequestCallbackCounter;
bool alreadyRegistered = !mFrameRequestCallbacks.IsEmpty();
if (mFrameRequestCallbacks.AppendElement(aCallback) &&
!alreadyRegistered && mPresShell && IsEventHandlingEnabled()) {
FrameRequest *request =
mFrameRequestCallbacks.AppendElement(FrameRequest(aCallback, newHandle));
NS_ASSERTION(request, "This is supposed to be infallible!");
if (!alreadyRegistered && mPresShell && IsEventHandlingEnabled()) {
mPresShell->GetPresContext()->RefreshDriver()->
ScheduleFrameRequestCallbacks(this);
}
*aHandle = newHandle;
return NS_OK;
}
nsresult

View File

@ -511,6 +511,7 @@ _TEST_FILES2 = \
file_html_in_xhr2.html \
file_html_in_xhr3.html \
file_html_in_xhr.sjs \
test_bug647518.html \
test_bug664916.html \
test_bug666604.html \
test_bug675121.html \

View File

@ -0,0 +1,27 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=647518
-->
<head>
<title>Test for Bug 647518</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=647518">Mozilla Bug 647518</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 647518 **/
var handle1 = window.mozRequestAnimationFrame(function() {});
ok(handle1 > 0, "Should get back a nonzero handle");
</script>
</pre>
</body>
</html>

View File

@ -3874,9 +3874,10 @@ nsGlobalWindow::GetMozPaintCount(PRUint64* aResult)
}
NS_IMETHODIMP
nsGlobalWindow::MozRequestAnimationFrame(nsIFrameRequestCallback* aCallback)
nsGlobalWindow::MozRequestAnimationFrame(nsIFrameRequestCallback* aCallback,
PRInt32 *aHandle)
{
FORWARD_TO_INNER(MozRequestAnimationFrame, (aCallback),
FORWARD_TO_INNER(MozRequestAnimationFrame, (aCallback, aHandle),
NS_ERROR_NOT_INITIALIZED);
if (!mDoc) {
@ -3887,8 +3888,7 @@ nsGlobalWindow::MozRequestAnimationFrame(nsIFrameRequestCallback* aCallback)
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
mDoc->ScheduleFrameRequestCallback(aCallback);
return NS_OK;
return mDoc->ScheduleFrameRequestCallback(aCallback, aHandle);
}
NS_IMETHODIMP

View File

@ -70,7 +70,7 @@ interface nsIDOMMozURLProperty : nsISupports
* @see <http://www.whatwg.org/html/#window>
*/
[scriptable, uuid(8f577294-d572-4473-94b1-d2c5a74a2a74)]
[scriptable, uuid(57b7ed24-c340-4994-a023-56ba578b78ab)]
interface nsIDOMWindow : nsISupports
{
// the current browsing context
@ -417,7 +417,7 @@ interface nsIDOMWindow : nsISupports
*
* @see <http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/RequestAnimationFrame/Overview.html>
*/
void
long
mozRequestAnimationFrame(in nsIFrameRequestCallback aCallback);
/**