зеркало из https://github.com/mozilla/pjs.git
Bug 732564 - Add a before-first-paint event that fires before the first paint of the new document. r=Cwiiis, bz
This commit is contained in:
Родитель
bddc5e8b4f
Коммит
69b22d9e28
|
@ -506,6 +506,18 @@ public:
|
|||
nsCOMPtr<nsIDocument> mTop;
|
||||
};
|
||||
|
||||
class nsBeforeFirstPaintDispatcher : public nsRunnable
|
||||
{
|
||||
public:
|
||||
nsBeforeFirstPaintDispatcher(nsIDocument* aDocument)
|
||||
: mDocument(aDocument) {}
|
||||
|
||||
NS_IMETHOD Run();
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIDocument> mDocument;
|
||||
};
|
||||
|
||||
class nsDocumentShownDispatcher : public nsRunnable
|
||||
{
|
||||
public:
|
||||
|
@ -2047,8 +2059,13 @@ DocumentViewerImpl::Show(void)
|
|||
}
|
||||
}
|
||||
|
||||
// Notify observers that a new page has been shown. (But not right now;
|
||||
// running JS at this time is not safe.)
|
||||
// Notify observers that a new page is about to be drawn. Execute this
|
||||
// as soon as it is safe to run JS, which is guaranteed to be before we
|
||||
// go back to the event loop and actually draw the page.
|
||||
nsContentUtils::AddScriptRunner(new nsBeforeFirstPaintDispatcher(mDocument));
|
||||
|
||||
// Notify observers that a new page has been shown. This will get run
|
||||
// from the event loop after we actually draw the page.
|
||||
NS_DispatchToMainThread(new nsDocumentShownDispatcher(mDocument));
|
||||
|
||||
return NS_OK;
|
||||
|
@ -4370,9 +4387,21 @@ DocumentViewerImpl::SetPrintPreviewPresentation(nsIViewManager* aViewManager,
|
|||
mPresShell = aPresShell;
|
||||
}
|
||||
|
||||
// Fires the "document-shown" event so that interested parties (right now, the
|
||||
// Fires the "before-first-paint" event so that interested parties (right now, the
|
||||
// mobile browser) are aware of it.
|
||||
NS_IMETHODIMP
|
||||
nsBeforeFirstPaintDispatcher::Run()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
mozilla::services::GetObserverService();
|
||||
if (observerService) {
|
||||
observerService->NotifyObservers(mDocument, "before-first-paint", NULL);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Fires the "document-shown" event so that interested parties are aware of it.
|
||||
NS_IMETHODIMP
|
||||
nsDocumentShownDispatcher::Run()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
|
|
|
@ -1517,7 +1517,7 @@ Tab.prototype = {
|
|||
this.browser.addEventListener("pagehide", this, true);
|
||||
this.browser.addEventListener("pageshow", this, true);
|
||||
|
||||
Services.obs.addObserver(this, "document-shown", false);
|
||||
Services.obs.addObserver(this, "before-first-paint", false);
|
||||
|
||||
if (!aParams.delayLoad) {
|
||||
let flags = "flags" in aParams ? aParams.flags : Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
||||
|
@ -1563,7 +1563,7 @@ Tab.prototype = {
|
|||
this.browser.removeEventListener("pagehide", this, true);
|
||||
this.browser.removeEventListener("pageshow", this, true);
|
||||
|
||||
Services.obs.removeObserver(this, "document-shown");
|
||||
Services.obs.removeObserver(this, "before-first-paint");
|
||||
|
||||
// Make sure the previously selected panel remains selected. The selected panel of a deck is
|
||||
// not stable when panels are removed.
|
||||
|
@ -2238,7 +2238,7 @@ Tab.prototype = {
|
|||
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case "document-shown":
|
||||
case "before-first-paint":
|
||||
// Is it on the top level?
|
||||
let contentDocument = aSubject;
|
||||
if (contentDocument == this.browser.contentDocument) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче