Bug 938189 - Avoid duplicate snapshot taking and compression when using history swipe animations. r=felipe
This commit is contained in:
@@ -741,9 +741,13 @@ let gHistorySwipeAnimation = {
|
||||
break;
|
||||
case "pagehide":
|
||||
if (aEvent.target == gBrowser.selectedBrowser.contentDocument) {
|
||||
// Take a snapshot of a page whenever it's about to be navigated away
|
||||
// from.
|
||||
this._takeSnapshot();
|
||||
// Take and compress a snapshot of a page whenever it's about to be
|
||||
// navigated away from. We already have a snapshot of the page if an
|
||||
// animation is running, so we're left with compressing it.
|
||||
if (!this.isAnimationRunning()) {
|
||||
this._takeSnapshot();
|
||||
}
|
||||
this._compressSnapshotAtCurrentIndex();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -935,13 +939,27 @@ let gHistorySwipeAnimation = {
|
||||
aBox.style.transform = transform;
|
||||
},
|
||||
|
||||
/**
|
||||
* Verifies that we're ready to take snapshots based on the global pref and
|
||||
* the current index in history.
|
||||
*
|
||||
* @return true if we're ready to take snapshots, false otherwise.
|
||||
*/
|
||||
_readyToTakeSnapshots: function HSA__readyToTakeSnapshots() {
|
||||
if ((this._maxSnapshots < 1) ||
|
||||
(gBrowser.webNavigation.sessionHistory.index < 0)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Takes a snapshot of the page the browser is currently on.
|
||||
*/
|
||||
_takeSnapshot: function HSA__takeSnapshot() {
|
||||
if ((this._maxSnapshots < 1) ||
|
||||
(gBrowser.webNavigation.sessionHistory.index < 0))
|
||||
if (!this._readyToTakeSnapshots()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let canvas = null;
|
||||
|
||||
@@ -1010,9 +1028,27 @@ let gHistorySwipeAnimation = {
|
||||
image: aCanvas,
|
||||
scale: window.devicePixelRatio
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Compresses the HTMLCanvasElement that's stored at the current history
|
||||
* index in the snapshot array and stores the compressed image in its place.
|
||||
*/
|
||||
_compressSnapshotAtCurrentIndex:
|
||||
function HSA__compressSnapshotAtCurrentIndex() {
|
||||
if (!this._readyToTakeSnapshots()) {
|
||||
// We didn't take a snapshot earlier because we weren't ready to, so
|
||||
// there's nothing to compress.
|
||||
return;
|
||||
}
|
||||
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
let snapshots = browser.snapshots;
|
||||
let currIndex = browser.webNavigation.sessionHistory.index;
|
||||
|
||||
// Kick off snapshot compression.
|
||||
aCanvas.toBlob(function(aBlob) {
|
||||
let canvas = snapshots[currIndex].image;
|
||||
canvas.toBlob(function(aBlob) {
|
||||
if (snapshots[currIndex]) {
|
||||
snapshots[currIndex].image = aBlob;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user