2010-02-03 13:17:55 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2009-10-07 20:22:42 -07:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is nsRefreshDriver.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is the Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation (original author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Code to notify things that animate before a refresh, at an appropriate
|
|
|
|
* refresh rate. (Perhaps temporary, until replaced by compositor.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "prlog.h"
|
2009-12-21 13:46:25 -08:00
|
|
|
#include "nsAutoPtr.h"
|
2010-08-11 14:05:27 -07:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2010-08-11 14:05:28 -07:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
#include "jsapi.h"
|
2010-08-23 02:30:08 -07:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
|
|
|
using mozilla::TimeStamp;
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2010-08-23 02:30:08 -07:00
|
|
|
#define DEFAULT_FRAME_RATE 60
|
2010-08-26 21:26:23 -07:00
|
|
|
#define DEFAULT_THROTTLED_FRAME_RATE 1
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2011-03-07 08:58:48 -08:00
|
|
|
static PRBool sPrecisePref;
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsRefreshDriver::InitializeStatics()
|
|
|
|
{
|
|
|
|
nsContentUtils::AddBoolPrefVarCache("layout.frame_rate.precise",
|
|
|
|
&sPrecisePref,
|
|
|
|
PR_FALSE);
|
|
|
|
}
|
2010-08-23 02:30:08 -07:00
|
|
|
// Compute the interval to use for the refresh driver timer, in
|
|
|
|
// milliseconds
|
2011-03-04 07:27:02 -08:00
|
|
|
PRInt32
|
|
|
|
nsRefreshDriver::GetRefreshTimerInterval() const
|
2010-08-23 02:30:08 -07:00
|
|
|
{
|
2010-08-26 21:26:23 -07:00
|
|
|
const char* prefName =
|
2011-03-04 07:27:02 -08:00
|
|
|
mThrottled ? "layout.throttled_frame_rate" : "layout.frame_rate";
|
2010-08-26 21:26:23 -07:00
|
|
|
PRInt32 rate = nsContentUtils::GetIntPref(prefName, -1);
|
2010-08-23 02:30:08 -07:00
|
|
|
if (rate <= 0) {
|
|
|
|
// TODO: get the rate from the platform
|
2011-03-04 07:27:02 -08:00
|
|
|
rate = mThrottled ? DEFAULT_THROTTLED_FRAME_RATE : DEFAULT_FRAME_RATE;
|
2010-08-23 02:30:08 -07:00
|
|
|
}
|
|
|
|
NS_ASSERTION(rate > 0, "Must have positive rate here");
|
2011-03-04 07:27:02 -08:00
|
|
|
PRInt32 interval = NSToIntRound(1000.0/rate);
|
|
|
|
if (mThrottled) {
|
|
|
|
interval = NS_MAX(interval, mLastTimerInterval * 2);
|
|
|
|
}
|
|
|
|
mLastTimerInterval = interval;
|
|
|
|
return interval;
|
2010-08-23 02:30:08 -07:00
|
|
|
}
|
|
|
|
|
2011-03-04 07:27:02 -08:00
|
|
|
PRInt32
|
|
|
|
nsRefreshDriver::GetRefreshTimerType() const
|
2010-08-23 02:30:08 -07:00
|
|
|
{
|
2011-03-04 07:27:02 -08:00
|
|
|
if (mThrottled) {
|
|
|
|
return nsITimer::TYPE_ONE_SHOT;
|
|
|
|
}
|
2011-03-07 08:58:48 -08:00
|
|
|
if (HaveAnimationFrameListeners() || sPrecisePref) {
|
|
|
|
return nsITimer::TYPE_REPEATING_PRECISE;
|
|
|
|
}
|
|
|
|
return nsITimer::TYPE_REPEATING_SLACK;
|
2010-08-23 02:30:08 -07:00
|
|
|
}
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2009-12-21 13:46:24 -08:00
|
|
|
nsRefreshDriver::nsRefreshDriver(nsPresContext *aPresContext)
|
2010-02-03 13:17:55 -08:00
|
|
|
: mPresContext(aPresContext),
|
2010-08-26 21:26:23 -07:00
|
|
|
mFrozen(false),
|
2011-03-07 08:58:48 -08:00
|
|
|
mThrottled(false),
|
2011-03-28 21:41:01 -07:00
|
|
|
mTimerIsPrecise(false),
|
|
|
|
mLastTimerInterval(0)
|
2009-10-07 20:22:42 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefreshDriver::~nsRefreshDriver()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(ObserverCount() == 0,
|
|
|
|
"observers should have unregistered");
|
|
|
|
NS_ABORT_IF_FALSE(!mTimer, "timer should be gone");
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeStamp
|
|
|
|
nsRefreshDriver::MostRecentRefresh() const
|
|
|
|
{
|
|
|
|
const_cast<nsRefreshDriver*>(this)->EnsureTimerStarted();
|
|
|
|
|
|
|
|
return mMostRecentRefresh;
|
|
|
|
}
|
|
|
|
|
2010-08-11 14:05:28 -07:00
|
|
|
PRInt64
|
|
|
|
nsRefreshDriver::MostRecentRefreshEpochTime() const
|
|
|
|
{
|
|
|
|
const_cast<nsRefreshDriver*>(this)->EnsureTimerStarted();
|
|
|
|
|
|
|
|
return mMostRecentRefreshEpochTime;
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
PRBool
|
|
|
|
nsRefreshDriver::AddRefreshObserver(nsARefreshObserver *aObserver,
|
|
|
|
mozFlushType aFlushType)
|
|
|
|
{
|
|
|
|
ObserverArray& array = ArrayFor(aFlushType);
|
|
|
|
PRBool success = array.AppendElement(aObserver) != nsnull;
|
|
|
|
|
|
|
|
EnsureTimerStarted();
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsRefreshDriver::RemoveRefreshObserver(nsARefreshObserver *aObserver,
|
|
|
|
mozFlushType aFlushType)
|
|
|
|
{
|
|
|
|
ObserverArray& array = ArrayFor(aFlushType);
|
2009-12-31 11:07:57 -08:00
|
|
|
return array.RemoveElement(aObserver);
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRefreshDriver::EnsureTimerStarted()
|
|
|
|
{
|
2010-02-03 13:17:55 -08:00
|
|
|
if (mTimer || mFrozen || !mPresContext) {
|
|
|
|
// It's already been started, or we don't want to start it now or
|
|
|
|
// we've been disconnected.
|
2009-10-07 20:22:42 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateMostRecentRefresh();
|
|
|
|
|
|
|
|
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
|
|
|
if (!mTimer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:58:48 -08:00
|
|
|
PRInt32 timerType = GetRefreshTimerType();
|
|
|
|
mTimerIsPrecise = (timerType == nsITimer::TYPE_REPEATING_PRECISE);
|
|
|
|
|
2010-08-26 21:26:23 -07:00
|
|
|
nsresult rv = mTimer->InitWithCallback(this,
|
2011-03-04 07:27:02 -08:00
|
|
|
GetRefreshTimerInterval(),
|
2011-03-07 08:58:48 -08:00
|
|
|
timerType);
|
2009-10-07 20:22:42 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mTimer = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRefreshDriver::StopTimer()
|
|
|
|
{
|
|
|
|
if (!mTimer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimer->Cancel();
|
|
|
|
mTimer = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsRefreshDriver::ObserverCount() const
|
|
|
|
{
|
|
|
|
PRUint32 sum = 0;
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(mObservers); ++i) {
|
|
|
|
sum += mObservers[i].Length();
|
|
|
|
}
|
2010-08-26 21:26:23 -07:00
|
|
|
// Even while throttled, we need to process layout and style changes. Style
|
|
|
|
// changes can trigger transitions which fire events when they complete, and
|
|
|
|
// layout changes can affect media queries on child documents, triggering
|
|
|
|
// style changes, etc.
|
2010-08-11 14:05:27 -07:00
|
|
|
sum += mStyleFlushObservers.Length();
|
|
|
|
sum += mLayoutFlushObservers.Length();
|
2010-08-11 14:05:28 -07:00
|
|
|
sum += mBeforePaintTargets.Length();
|
2010-09-08 22:38:04 -07:00
|
|
|
sum += mAnimationFrameListenerDocs.Length();
|
2009-10-07 20:22:42 -07:00
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRefreshDriver::UpdateMostRecentRefresh()
|
|
|
|
{
|
2010-08-11 14:05:28 -07:00
|
|
|
// Call JS_Now first, since that can have nonzero latency in some rare cases.
|
|
|
|
mMostRecentRefreshEpochTime = JS_Now();
|
2009-10-07 20:22:42 -07:00
|
|
|
mMostRecentRefresh = TimeStamp::Now();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefreshDriver::ObserverArray&
|
|
|
|
nsRefreshDriver::ArrayFor(mozFlushType aFlushType)
|
|
|
|
{
|
|
|
|
switch (aFlushType) {
|
|
|
|
case Flush_Style:
|
|
|
|
return mObservers[0];
|
|
|
|
case Flush_Layout:
|
|
|
|
return mObservers[1];
|
|
|
|
case Flush_Display:
|
|
|
|
return mObservers[2];
|
|
|
|
default:
|
|
|
|
NS_ABORT_IF_FALSE(PR_FALSE, "bad flush type");
|
|
|
|
return *static_cast<ObserverArray*>(nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsISupports implementation
|
|
|
|
*/
|
|
|
|
|
2009-12-21 13:46:24 -08:00
|
|
|
NS_IMPL_ISUPPORTS1(nsRefreshDriver, nsITimerCallback)
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsITimerCallback implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-02-03 13:17:55 -08:00
|
|
|
nsRefreshDriver::Notify(nsITimer * /* unused */)
|
2009-10-07 20:22:42 -07:00
|
|
|
{
|
2010-02-03 13:17:55 -08:00
|
|
|
NS_PRECONDITION(!mFrozen, "Why are we notified while frozen?");
|
|
|
|
NS_PRECONDITION(mPresContext, "Why are we notified after disconnection?");
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
UpdateMostRecentRefresh();
|
|
|
|
|
2009-12-21 13:46:24 -08:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
|
2009-12-31 11:07:57 -08:00
|
|
|
if (!presShell || ObserverCount() == 0) {
|
|
|
|
// Things are being destroyed, or we no longer have any observers.
|
|
|
|
// We don't want to stop the timer when observers are initially
|
|
|
|
// removed, because sometimes observers can be added and removed
|
|
|
|
// often depending on what other things are going on and in that
|
|
|
|
// situation we don't want to thrash our timer. So instead we
|
|
|
|
// wait until we get a Notify() call when we have no observers
|
|
|
|
// before stopping the timer.
|
2009-10-07 20:22:42 -07:00
|
|
|
StopTimer();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-21 13:46:25 -08:00
|
|
|
/*
|
|
|
|
* The timer holds a reference to |this| while calling |Notify|.
|
|
|
|
* However, implementations of |WillRefresh| are permitted to destroy
|
|
|
|
* the pres context, which will cause our |mPresContext| to become
|
|
|
|
* null. If this happens, we must stop notifying observers.
|
|
|
|
*/
|
2009-10-07 20:22:42 -07:00
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(mObservers); ++i) {
|
|
|
|
ObserverArray::EndLimitedIterator etor(mObservers[i]);
|
|
|
|
while (etor.HasMore()) {
|
2009-12-21 13:46:25 -08:00
|
|
|
nsRefPtr<nsARefreshObserver> obs = etor.GetNext();
|
|
|
|
obs->WillRefresh(mMostRecentRefresh);
|
|
|
|
|
|
|
|
if (!mPresContext || !mPresContext->GetPresShell()) {
|
|
|
|
StopTimer();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
if (i == 0) {
|
2010-08-11 14:05:28 -07:00
|
|
|
// Don't just loop while we have things in mBeforePaintTargets,
|
|
|
|
// the whole point is that event handlers should readd the
|
|
|
|
// target as needed.
|
2011-03-28 07:49:48 -07:00
|
|
|
nsTArray< nsCOMPtr<nsIDocument> > targets;
|
2010-08-11 14:05:28 -07:00
|
|
|
targets.SwapElements(mBeforePaintTargets);
|
|
|
|
for (PRUint32 i = 0; i < targets.Length(); ++i) {
|
|
|
|
targets[i]->BeforePaintEventFiring();
|
|
|
|
}
|
2010-09-08 22:38:04 -07:00
|
|
|
|
|
|
|
// Also grab all of our animation frame listeners up front.
|
|
|
|
nsIDocument::AnimationListenerList animationListeners;
|
|
|
|
for (PRUint32 i = 0; i < mAnimationFrameListenerDocs.Length(); ++i) {
|
|
|
|
mAnimationFrameListenerDocs[i]->
|
|
|
|
TakeAnimationFrameListeners(animationListeners);
|
|
|
|
}
|
|
|
|
// OK, now reset mAnimationFrameListenerDocs so they can be
|
|
|
|
// readded as needed.
|
|
|
|
mAnimationFrameListenerDocs.Clear();
|
|
|
|
|
|
|
|
PRInt64 eventTime = mMostRecentRefreshEpochTime / PR_USEC_PER_MSEC;
|
2010-08-11 14:05:28 -07:00
|
|
|
for (PRUint32 i = 0; i < targets.Length(); ++i) {
|
|
|
|
nsEvent ev(PR_TRUE, NS_BEFOREPAINT);
|
|
|
|
ev.time = eventTime;
|
|
|
|
nsEventDispatcher::Dispatch(targets[i], nsnull, &ev);
|
|
|
|
}
|
|
|
|
|
2010-09-08 22:38:04 -07:00
|
|
|
for (PRUint32 i = 0; i < animationListeners.Length(); ++i) {
|
|
|
|
animationListeners[i]->OnBeforePaint(eventTime);
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
// This is the Flush_Style case.
|
2011-01-14 12:03:06 -08:00
|
|
|
if (mPresContext && mPresContext->GetPresShell()) {
|
|
|
|
nsAutoTArray<nsIPresShell*, 16> observers;
|
|
|
|
observers.AppendElements(mStyleFlushObservers);
|
|
|
|
for (PRUint32 j = observers.Length();
|
|
|
|
j && mPresContext && mPresContext->GetPresShell(); --j) {
|
|
|
|
// Make sure to not process observers which might have been removed
|
|
|
|
// during previous iterations.
|
|
|
|
nsIPresShell* shell = observers[j - 1];
|
|
|
|
if (!mStyleFlushObservers.Contains(shell))
|
|
|
|
continue;
|
|
|
|
NS_ADDREF(shell);
|
|
|
|
mStyleFlushObservers.RemoveElement(shell);
|
|
|
|
shell->FrameConstructor()->mObservingRefreshDriver = PR_FALSE;
|
|
|
|
shell->FlushPendingNotifications(Flush_Style);
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
2010-08-11 14:05:27 -07:00
|
|
|
}
|
2010-02-19 09:11:40 -08:00
|
|
|
} else if (i == 1) {
|
|
|
|
// This is the Flush_Layout case.
|
2011-01-14 12:03:06 -08:00
|
|
|
if (mPresContext && mPresContext->GetPresShell()) {
|
|
|
|
nsAutoTArray<nsIPresShell*, 16> observers;
|
|
|
|
observers.AppendElements(mLayoutFlushObservers);
|
|
|
|
for (PRUint32 j = observers.Length();
|
|
|
|
j && mPresContext && mPresContext->GetPresShell(); --j) {
|
|
|
|
// Make sure to not process observers which might have been removed
|
|
|
|
// during previous iterations.
|
|
|
|
nsIPresShell* shell = observers[j - 1];
|
|
|
|
if (!mLayoutFlushObservers.Contains(shell))
|
|
|
|
continue;
|
|
|
|
NS_ADDREF(shell);
|
|
|
|
mLayoutFlushObservers.RemoveElement(shell);
|
|
|
|
shell->mReflowScheduled = PR_FALSE;
|
|
|
|
shell->mSuppressInterruptibleReflows = PR_FALSE;
|
|
|
|
shell->FlushPendingNotifications(Flush_InterruptibleLayout);
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
2010-08-11 14:05:27 -07:00
|
|
|
}
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:58:48 -08:00
|
|
|
if (mThrottled ||
|
|
|
|
(mTimerIsPrecise !=
|
|
|
|
(GetRefreshTimerType() == nsITimer::TYPE_REPEATING_PRECISE))) {
|
|
|
|
// Stop the timer now and restart it here. Stopping is in the mThrottled
|
|
|
|
// case ok because either it's already one-shot, and it just fired, and all
|
|
|
|
// we need to do is null it out, or it's repeating and we need to reset it
|
|
|
|
// to be one-shot. Stopping and restarting in the case when we need to
|
|
|
|
// switch from precise to slack timers or vice versa is unfortunately
|
|
|
|
// required.
|
|
|
|
|
|
|
|
// Note that the EnsureTimerStarted() call here is ok because
|
|
|
|
// EnsureTimerStarted makes sure to not start the timer if it shouldn't be
|
|
|
|
// started.
|
2011-03-04 07:27:02 -08:00
|
|
|
StopTimer();
|
|
|
|
EnsureTimerStarted();
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-02-03 13:17:55 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
nsRefreshDriver::Freeze()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mFrozen, "Freeze called on already-frozen refresh driver");
|
|
|
|
StopTimer();
|
2010-08-26 21:26:23 -07:00
|
|
|
mFrozen = true;
|
2010-02-03 13:17:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsRefreshDriver::Thaw()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mFrozen, "Thaw called on an unfrozen refresh driver");
|
2010-08-26 21:26:23 -07:00
|
|
|
mFrozen = false;
|
2010-02-03 13:17:55 -08:00
|
|
|
if (ObserverCount()) {
|
2010-04-20 16:21:35 -07:00
|
|
|
NS_DispatchToCurrentThread(NS_NewRunnableMethod(this, &nsRefreshDriver::DoRefresh));
|
2010-02-03 13:17:55 -08:00
|
|
|
EnsureTimerStarted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-26 21:26:23 -07:00
|
|
|
void
|
|
|
|
nsRefreshDriver::SetThrottled(bool aThrottled)
|
|
|
|
{
|
|
|
|
if (aThrottled != mThrottled) {
|
|
|
|
mThrottled = aThrottled;
|
|
|
|
if (mTimer) {
|
2011-03-04 07:27:02 -08:00
|
|
|
// We want to switch our timer type here, so just stop and
|
|
|
|
// restart the timer.
|
|
|
|
StopTimer();
|
|
|
|
EnsureTimerStarted();
|
2010-08-26 21:26:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-03 13:17:55 -08:00
|
|
|
void
|
|
|
|
nsRefreshDriver::DoRefresh()
|
|
|
|
{
|
|
|
|
// Don't do a refresh unless we're in a state where we should be refreshing.
|
|
|
|
if (!mFrozen && mPresContext && mTimer) {
|
|
|
|
Notify(nsnull);
|
|
|
|
}
|
|
|
|
}
|
2010-02-19 09:11:40 -08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool
|
|
|
|
nsRefreshDriver::IsRefreshObserver(nsARefreshObserver *aObserver,
|
|
|
|
mozFlushType aFlushType)
|
|
|
|
{
|
|
|
|
ObserverArray& array = ArrayFor(aFlushType);
|
|
|
|
return array.Contains(aObserver);
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-11 14:05:28 -07:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsRefreshDriver::ScheduleBeforePaintEvent(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mBeforePaintTargets.IndexOf(aDocument) ==
|
|
|
|
mBeforePaintTargets.NoIndex,
|
|
|
|
"Shouldn't have a paint event posted for this document");
|
|
|
|
PRBool appended = mBeforePaintTargets.AppendElement(aDocument) != nsnull;
|
|
|
|
EnsureTimerStarted();
|
|
|
|
return appended;
|
|
|
|
}
|
|
|
|
|
2010-09-08 22:38:04 -07:00
|
|
|
void
|
|
|
|
nsRefreshDriver::ScheduleAnimationFrameListeners(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mAnimationFrameListenerDocs.IndexOf(aDocument) ==
|
|
|
|
mAnimationFrameListenerDocs.NoIndex,
|
|
|
|
"Don't schedule the same document multiple times");
|
|
|
|
mAnimationFrameListenerDocs.AppendElement(aDocument);
|
2011-03-07 08:58:48 -08:00
|
|
|
// No need to worry about restarting our timer in precise mode if it's
|
|
|
|
// already running; that will happen automatically when it fires.
|
2010-09-08 22:38:04 -07:00
|
|
|
EnsureTimerStarted();
|
|
|
|
}
|
|
|
|
|
2010-08-11 14:05:28 -07:00
|
|
|
void
|
|
|
|
nsRefreshDriver::RevokeBeforePaintEvent(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
mBeforePaintTargets.RemoveElement(aDocument);
|
|
|
|
}
|
2010-09-08 22:38:04 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
nsRefreshDriver::RevokeAnimationFrameListeners(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
mAnimationFrameListenerDocs.RemoveElement(aDocument);
|
2011-03-07 08:58:48 -08:00
|
|
|
// No need to worry about restarting our timer in slack mode if it's already
|
|
|
|
// running; that will happen automatically when it fires.
|
2010-09-08 22:38:04 -07:00
|
|
|
}
|