Bug 906643. Part 1: Add nsRefreshDriver::Add/Remove/PostRefreshObserver so we can receive notifications when a refresh has occurred, without triggering one. r=dbaron

--HG--
extra : rebase_source : fbfdd2678f4561f421fda2eb17e9e7ae8754f8d3
This commit is contained in:
Robert O'Callahan 2013-08-20 01:08:44 +12:00
Родитель d00023d255
Коммит 9243c99ebb
2 изменённых файлов: 44 добавлений и 8 удалений

Просмотреть файл

@ -753,9 +753,7 @@ nsRefreshDriver::AddRefreshObserver(nsARefreshObserver* aObserver,
{
ObserverArray& array = ArrayFor(aFlushType);
bool success = array.AppendElement(aObserver) != nullptr;
EnsureTimerStarted(false);
return success;
}
@ -767,6 +765,18 @@ nsRefreshDriver::RemoveRefreshObserver(nsARefreshObserver* aObserver,
return array.RemoveElement(aObserver);
}
void
nsRefreshDriver::AddPostRefreshObserver(nsAPostRefreshObserver* aObserver)
{
mPostRefreshObservers.AppendElement(aObserver);
}
void
nsRefreshDriver::RemovePostRefreshObserver(nsAPostRefreshObserver* aObserver)
{
mPostRefreshObservers.RemoveElement(aObserver);
}
bool
nsRefreshDriver::AddImageRequest(imgIRequest* aRequest)
{
@ -1198,6 +1208,10 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime)
}
#endif
}
for (uint32_t i = 0; i < mPostRefreshObservers.Length(); ++i) {
mPostRefreshObservers[i]->DidRefresh();
}
}
/* static */ PLDHashOperator

Просмотреть файл

@ -26,16 +26,17 @@ class nsPresContext;
class nsIPresShell;
class nsIDocument;
class imgIRequest;
class nsIRunnable;
namespace mozilla {
class RefreshDriverTimer;
}
/**
* An abstract base class to be implemented by callers wanting to be
* notified at refresh times. When nothing needs to be painted, callers
* may not be notified.
*/
namespace mozilla {
class RefreshDriverTimer;
}
class nsARefreshObserver {
public:
// AddRef and Release signatures that match nsISupports. Implementors
@ -50,6 +51,16 @@ public:
virtual void WillRefresh(mozilla::TimeStamp aTime) = 0;
};
/**
* An abstract base class to be implemented by callers wanting to be notified
* that a refresh has occurred. Callers must ensure an observer is removed
* before it is destroyed.
*/
class nsAPostRefreshObserver {
public:
virtual void DidRefresh() = 0;
};
class nsRefreshDriver MOZ_FINAL : public nsISupports {
public:
nsRefreshDriver(nsPresContext *aPresContext);
@ -101,11 +112,21 @@ public:
*
* The refresh driver does NOT own a reference to these observers;
* they must remove themselves before they are destroyed.
*
* The observer will be called even if there is no other activity.
*/
bool AddRefreshObserver(nsARefreshObserver *aObserver,
mozFlushType aFlushType);
mozFlushType aFlushType);
bool RemoveRefreshObserver(nsARefreshObserver *aObserver,
mozFlushType aFlushType);
mozFlushType aFlushType);
/**
* Add an observer that will be called after each refresh. The caller
* must remove the observer before it is deleted. This does not trigger
* refresh driver ticks.
*/
void AddPostRefreshObserver(nsAPostRefreshObserver *aObserver);
void RemovePostRefreshObserver(nsAPostRefreshObserver *aObserver);
/**
* Add/Remove imgIRequest versions of observers.
@ -295,6 +316,7 @@ private:
nsAutoTArray<nsIPresShell*, 16> mPresShellsToInvalidateIfHidden;
// nsTArray on purpose, because we want to be able to swap.
nsTArray<nsIDocument*> mFrameRequestCallbackDocs;
nsTArray<nsAPostRefreshObserver*> mPostRefreshObservers;
// Helper struct for processing image requests
struct ImageRequestParameters {