зеркало из 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;
|
nsCOMPtr<nsIDocument> mTop;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class nsBeforeFirstPaintDispatcher : public nsRunnable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsBeforeFirstPaintDispatcher(nsIDocument* aDocument)
|
||||||
|
: mDocument(aDocument) {}
|
||||||
|
|
||||||
|
NS_IMETHOD Run();
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsCOMPtr<nsIDocument> mDocument;
|
||||||
|
};
|
||||||
|
|
||||||
class nsDocumentShownDispatcher : public nsRunnable
|
class nsDocumentShownDispatcher : public nsRunnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -2047,8 +2059,13 @@ DocumentViewerImpl::Show(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify observers that a new page has been shown. (But not right now;
|
// Notify observers that a new page is about to be drawn. Execute this
|
||||||
// running JS at this time is not safe.)
|
// 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));
|
NS_DispatchToMainThread(new nsDocumentShownDispatcher(mDocument));
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -4370,9 +4387,21 @@ DocumentViewerImpl::SetPrintPreviewPresentation(nsIViewManager* aViewManager,
|
||||||
mPresShell = aPresShell;
|
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.
|
// mobile browser) are aware of it.
|
||||||
NS_IMETHODIMP
|
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()
|
nsDocumentShownDispatcher::Run()
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIObserverService> observerService =
|
nsCOMPtr<nsIObserverService> observerService =
|
||||||
|
|
|
@ -1517,7 +1517,7 @@ Tab.prototype = {
|
||||||
this.browser.addEventListener("pagehide", this, true);
|
this.browser.addEventListener("pagehide", this, true);
|
||||||
this.browser.addEventListener("pageshow", 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) {
|
if (!aParams.delayLoad) {
|
||||||
let flags = "flags" in aParams ? aParams.flags : Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
|
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("pagehide", this, true);
|
||||||
this.browser.removeEventListener("pageshow", 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
|
// Make sure the previously selected panel remains selected. The selected panel of a deck is
|
||||||
// not stable when panels are removed.
|
// not stable when panels are removed.
|
||||||
|
@ -2238,7 +2238,7 @@ Tab.prototype = {
|
||||||
|
|
||||||
observe: function(aSubject, aTopic, aData) {
|
observe: function(aSubject, aTopic, aData) {
|
||||||
switch (aTopic) {
|
switch (aTopic) {
|
||||||
case "document-shown":
|
case "before-first-paint":
|
||||||
// Is it on the top level?
|
// Is it on the top level?
|
||||||
let contentDocument = aSubject;
|
let contentDocument = aSubject;
|
||||||
if (contentDocument == this.browser.contentDocument) {
|
if (contentDocument == this.browser.contentDocument) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче