Bug 836568: Add a delay between when the user finishes a pinch gesture and when the reflow happens for reflow-on-zoom to prevent buildup of successive reflow events. [r=kats]

This commit is contained in:
Scott Johnson 2013-04-23 12:29:22 -05:00
parent a442d16579
commit 1c425e6276
2 changed files with 35 additions and 19 deletions

View File

@ -150,6 +150,24 @@ function sendMessageToJava(aMessage) {
return getBridge().handleGeckoMessage(JSON.stringify(aMessage));
}
function doChangeMaxLineBoxWidth(aWidth) {
gReflowPending = null;
let webNav = BrowserApp.selectedTab.window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation);
let docShell = webNav.QueryInterface(Ci.nsIDocShell);
let docViewer = docShell.contentViewer.QueryInterface(Ci.nsIMarkupDocumentViewer);
let range = null;
if (BrowserApp.selectedTab._mReflozPoint) {
range = BrowserApp.selectedTab._mReflozPoint.range;
}
docViewer.changeMaxLineBoxWidth(aWidth);
if (range) {
BrowserEventHandler._zoomInAndSnapToRange(range);
}
}
function fuzzyEquals(a, b) {
return (Math.abs(a - b) < 1e-6);
}
@ -2301,6 +2319,7 @@ nsBrowserAccess.prototype = {
// get created with the right size rather than being 1x1
let gScreenWidth = 1;
let gScreenHeight = 1;
let gReflowPending = null;
// The margins that should be applied to the viewport for fixed position
// children. This is used to avoid browser chrome permanently obscuring
@ -2480,14 +2499,18 @@ Tab.prototype = {
},
performReflowOnZoom: function(aViewport) {
let webNav = this.window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation);
let docShell = webNav.QueryInterface(Ci.nsIDocShell);
let docViewer = docShell.contentViewer.QueryInterface(Ci.nsIMarkupDocumentViewer);
let viewportWidth = gScreenWidth / aViewport.zoom;
let reflozTimeout = Services.prefs.getIntPref("browser.zoom.reflowZoom.reflowTimeout");
if (gReflowPending) {
clearTimeout(gReflowPending);
}
// We add in a bit of fudge just so that the end characters don't accidentally
// get clipped. 15px is an arbitrary choice.
docViewer.changeMaxLineBoxWidth(viewportWidth - 15);
gReflowPending = setTimeout(doChangeMaxLineBoxWidth,
reflozTimeout,
viewportWidth - 15);
},
/**
@ -3890,12 +3913,6 @@ var BrowserEventHandler = {
this.onPinch(aData);
break;
case "MozMagnifyGesture":
if (BrowserEventHandler.mReflozPref) {
this.onPinchFinish(aData, BrowserApp.selectedTab._mReflozPoint.x, BrowserApp.selectedTab._mReflozPoint.y);
}
break;
default:
dump('BrowserEventHandler.handleUserEvent: unexpected topic "' + aTopic + '"');
break;
@ -4039,6 +4056,7 @@ var BrowserEventHandler = {
rect.h = viewport.cssHeight;
sendMessageToJava(rect);
BrowserApp.selectedTab._mReflozPoint = null;
},
onPinch: function(aData) {
@ -4055,15 +4073,6 @@ var BrowserEventHandler = {
}
},
onPinchFinish: function(aData, aX, aY) {
// We only want to do this if reflow-on-zoom is enabled.
if (BrowserEventHandler.mReflozPref) {
let range = BrowserApp.selectedTab._mReflozPoint.range;
this._zoomInAndSnapToRange(range);
BrowserApp.selectedTab._mReflozPoint = null;
}
},
_shouldZoomToElement: function(aElement) {
let win = aElement.ownerDocument.defaultView;
if (win.getComputedStyle(aElement, null).display == "inline")

View File

@ -3836,6 +3836,13 @@ pref("toolkit.zoomManager.zoomValues", ".3,.5,.67,.8,.9,1,1.1,1.2,1.33,1.5,1.7,2
*/
pref("browser.zoom.reflowOnZoom", false);
/**
* Specifies the number of milliseconds to wait after a given reflow-on-zoom
* operation has completed before allowing another one to be triggered. This
* is to prevent a buildup of reflow-zoom events.
*/
pref("browser.zoom.reflowZoom.reflowTimeout", 500);
/**
* Controls whether or not the reflow-on-zoom behavior happens on page load.
* This can be enabled in conjunction with the above preference (reflowOnZoom),