Bug 709492 - Part 4: Hide the page when navigating, and expose it when the new page appears. r=kats

This commit is contained in:
Patrick Walton 2011-12-29 15:10:30 -08:00
Родитель 8864e85b2c
Коммит d02d8fac81
4 изменённых файлов: 64 добавлений и 19 удалений

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

@ -616,7 +616,10 @@ abstract public class GeckoApp
mLastTitle == lastHistoryEntry.mTitle) mLastTitle == lastHistoryEntry.mTitle)
return; return;
mLastViewport = mSoftwareLayerClient.getGeckoViewportMetrics().toJSON(); ViewportMetrics viewportMetrics = mSoftwareLayerClient.getGeckoViewportMetrics();
if (viewportMetrics != null)
mLastViewport = viewportMetrics.toJSON();
mLastUri = lastHistoryEntry.mUri; mLastUri = lastHistoryEntry.mUri;
mLastTitle = lastHistoryEntry.mTitle; mLastTitle = lastHistoryEntry.mTitle;
Bitmap bitmap = mSoftwareLayerClient.getBitmap(); Bitmap bitmap = mSoftwareLayerClient.getBitmap();

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

@ -140,7 +140,8 @@ public class GeckoSoftwareLayerClient extends LayerClient implements GeckoEventL
layerController.setViewportMetrics(mGeckoViewport); layerController.setViewportMetrics(mGeckoViewport);
} }
GeckoAppShell.registerGeckoEventListener("Viewport:Update", this); GeckoAppShell.registerGeckoEventListener("Viewport:Expose", this);
GeckoAppShell.registerGeckoEventListener("Viewport:UpdateAndDraw", this);
GeckoAppShell.registerGeckoEventListener("Viewport:UpdateLater", this); GeckoAppShell.registerGeckoEventListener("Viewport:UpdateLater", this);
} }
@ -340,19 +341,15 @@ public class GeckoSoftwareLayerClient extends LayerClient implements GeckoEventL
} }
public void handleMessage(String event, JSONObject message) { public void handleMessage(String event, JSONObject message) {
if ("Viewport:Update".equals(event)) { if ("Viewport:Expose".equals(event)) {
beginTransaction(mTileLayer); GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.EXPOSE));
try { } else if ("Viewport:UpdateAndDraw".equals(event)) {
updateViewport(message.getString("viewport"), false); mUpdateViewportOnEndDraw = true;
} catch (JSONException e) {
Log.e(LOGTAG, "Unable to update viewport", e); // Redraw everything.
} finally { Rect rect = new Rect(0, 0, mBufferSize.width, mBufferSize.height);
endTransaction(mTileLayer); GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.DRAW, rect));
}
} else if ("Viewport:UpdateLater".equals(event)) { } else if ("Viewport:UpdateLater".equals(event)) {
if (!mTileLayer.inTransaction()) {
Log.e(LOGTAG, "Viewport:UpdateLater called while not in transaction. You should be using Viewport:Update instead!");
}
mUpdateViewportOnEndDraw = true; mUpdateViewportOnEndDraw = true;
} }
} }

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

@ -264,7 +264,10 @@ public class PanZoomController
// the screen orientation changed) so abort it and start a new one to // the screen orientation changed) so abort it and start a new one to
// ensure the viewport doesn't contain out-of-bounds areas // ensure the viewport doesn't contain out-of-bounds areas
case NOTHING: case NOTHING:
bounce(); // Don't do animations here; they're distracting and can cause flashes on page
// transitions.
mController.setViewportMetrics(getValidViewportMetrics());
mController.notifyLayerClientOfGeometryChange();
break; break;
} }
} }

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

@ -200,6 +200,7 @@ var BrowserApp = {
Services.obs.addObserver(this, "Viewport:Change", false); Services.obs.addObserver(this, "Viewport:Change", false);
Services.obs.addObserver(this, "AgentMode:Change", false); Services.obs.addObserver(this, "AgentMode:Change", false);
Services.obs.addObserver(this, "SearchEngines:Get", false); Services.obs.addObserver(this, "SearchEngines:Get", false);
Services.obs.addObserver(this, "document-shown", false);
function showFullScreenWarning() { function showFullScreenWarning() {
NativeWindow.toast.show(Strings.browser.GetStringFromName("alertFullScreenToast"), "short"); NativeWindow.toast.show(Strings.browser.GetStringFromName("alertFullScreenToast"), "short");
@ -715,6 +716,20 @@ var BrowserApp = {
ViewportHandler.onResize(); ViewportHandler.onResize();
} else if (aTopic == "SearchEngines:Get") { } else if (aTopic == "SearchEngines:Get") {
this.getSearchEngines(); this.getSearchEngines();
} else if (aTopic == "document-shown") {
let tab = this.selectedTab;
if (tab.browser.contentDocument != aSubject) {
return;
}
ViewportHandler.updateMetadata(tab);
// Unsuppress drawing unless the page was being thawed from the bfcache (which is an atomic
// operation, so there is no drawing to suppress).
if (tab.suppressDrawing) {
tab.sendExposeEvent();
tab.suppressDrawing = false;
}
} }
}, },
@ -1194,6 +1209,12 @@ Tab.prototype = {
this.browser.addEventListener("PluginClickToPlay", this, true); this.browser.addEventListener("PluginClickToPlay", this, true);
this.browser.addEventListener("pagehide", this, true); this.browser.addEventListener("pagehide", this, true);
let chromeEventHandler = this.browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler;
chromeEventHandler.addEventListener("DOMWindowCreated", this, false);
Services.obs.addObserver(this, "http-on-modify-request", false); Services.obs.addObserver(this, "http-on-modify-request", false);
if (!aParams.delayLoad) { if (!aParams.delayLoad) {
@ -1403,8 +1424,7 @@ Tab.prototype = {
return; return;
sendMessageToJava({ sendMessageToJava({
gecko: { gecko: {
type: "Viewport:Update", type: "Viewport:UpdateAndDraw"
viewport: JSON.stringify(this.viewport)
} }
}); });
}, },
@ -1547,6 +1567,18 @@ Tab.prototype = {
} }
break; break;
} }
case "DOMWindowCreated": {
// Conveniently, this call to getBrowserForDocument() will return null if the document is
// not the top-level content document of the browser.
let browser = BrowserApp.getBrowserForDocument(aEvent.originalTarget);
if (!browser)
break;
let tab = BrowserApp.getTabForBrowser(browser);
tab.suppressDrawing = true;
break;
}
} }
}, },
@ -1806,6 +1838,16 @@ Tab.prototype = {
} }
}, },
sendExposeEvent: function() {
// Now that the document is actually on the screen, send an expose event.
this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
sendMessageToJava({
gecko: {
type: "Viewport:Expose"
}
});
},
QueryInterface: XPCOMUtils.generateQI([ QueryInterface: XPCOMUtils.generateQI([
Ci.nsIWebProgressListener, Ci.nsIWebProgressListener,
Ci.nsISHistoryListener, Ci.nsISHistoryListener,