Bug 680126 Reduce checkerboarding during load r=mbrubeck

This commit is contained in:
Benjamin Stover 2011-08-24 14:01:18 -07:00
Родитель b39a106b62
Коммит 07e38ba86e
3 изменённых файлов: 48 добавлений и 26 удалений

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

@ -72,6 +72,7 @@ pref("toolkit.zoomManager.zoomValues", ".2,.3,.5,.67,.8,.9,1,1.1,1.2,1.33,1.5,1.
// Device pixel to CSS px ratio, in percent. Set to -1 to calculate based on display density.
pref("browser.viewport.scaleRatio", -1);
pref("browser.viewport.desktopWidth", 980);
/* allow scrollbars to float above chrome ui */
pref("ui.scrollbarsCanOverlapContent", 1);

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

@ -31,6 +31,8 @@ let WebProgressListener = {
onProgressChange: function onProgressChange(aWebProgress, aRequest, aCurSelf, aMaxSelf, aCurTotal, aMaxTotal) {
},
_firstPaint: false,
onLocationChange: function onLocationChange(aWebProgress, aRequest, aLocationURI) {
if (content != aWebProgress.DOMWindow)
return;
@ -51,10 +53,14 @@ let WebProgressListener = {
sendAsyncMessage("Content:LocationChange", json);
this._firstPaint = false;
let self = this;
// When a new page is loaded fire a message for the first paint
addEventListener("MozAfterPaint", function(aEvent) {
removeEventListener("MozAfterPaint", arguments.callee, true);
self._firstPaint = true;
let scrollOffset = ContentScroll.getScrollOffset(content);
sendAsyncMessage("Browser:FirstPaint", scrollOffset);
}, true);
@ -542,8 +548,11 @@ let ContentScroll = {
case "Content:SetCacheViewport": {
// Set resolution for root view
let rootCwu = content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
if (json.id == 1)
if (json.id == 1) {
rootCwu.setResolution(json.scale, json.scale);
if (!WebProgressListener._firstPaint)
break;
}
let displayport = new Rect(json.x, json.y, json.w, json.h);
if (displayport.isEmpty())
@ -586,7 +595,6 @@ let ContentScroll = {
let win = element.ownerDocument.defaultView;
let winCwu = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
winCwu.setDisplayPortForElement(x, y, displayport.width, displayport.height, element);
break;
}

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

@ -59,9 +59,6 @@ function getBrowser() {
const kBrowserViewZoomLevelPrecision = 10000;
const kDefaultBrowserWidth = 800;
const kFallbackBrowserWidth = 980;
// allow panning after this timeout on pages with registered touch listeners
const kTouchTimeout = 300;
@ -158,6 +155,13 @@ var Browser = {
pageScrollboxScroller: null,
styles: {},
get defaultBrowserWidth() {
delete this.defaultBrowserWidth;
var width = Services.prefs.getIntPref("browser.viewport.desktopWidth");
this.defaultBrowserWidth = width;
return width;
},
startup: function startup() {
var self = this;
@ -378,6 +382,7 @@ var Browser = {
this.addTab(commandURL || this.getHomePage(), true);
}
messageManager.addMessageListener("MozScrolledAreaChanged", this);
messageManager.addMessageListener("Browser:ViewportMetadata", this);
messageManager.addMessageListener("Browser:CanCaptureMouse:Return", this);
messageManager.addMessageListener("Browser:FormSubmit", this);
@ -477,6 +482,7 @@ var Browser = {
shutdown: function shutdown() {
BrowserUI.uninit();
messageManager.removeMessageListener("MozScrolledAreaChanged", this);
messageManager.removeMessageListener("Browser:ViewportMetadata", this);
messageManager.removeMessageListener("Browser:FormSubmit", this);
messageManager.removeMessageListener("Browser:KeyPress", this);
@ -1179,6 +1185,12 @@ var Browser = {
let browser = aMessage.target;
switch (aMessage.name) {
case "MozScrolledAreaChanged": {
let tab = this.getTabForBrowser(browser);
if (tab)
tab.scrolledAreaChanged();
break;
}
case "Browser:ViewportMetadata": {
let tab = this.getTabForBrowser(browser);
// Some browser such as iframes loaded dynamically into the chrome UI
@ -1529,7 +1541,6 @@ Browser.WebProgress.prototype = {
CrashReporter.annotateCrashReport("URL", spec);
#endif
this._waitForLoad(tab);
tab.useFallbackWidth = false;
}
let event = document.createEvent("UIEvents");
@ -1581,10 +1592,12 @@ Browser.WebProgress.prototype = {
_waitForLoad: function _waitForLoad(aTab) {
let browser = aTab.browser;
browser.messageManager.removeMessageListener("MozScrolledAreaChanged", aTab.scrolledAreaChanged);
aTab._firstPaint = false;
browser.messageManager.addMessageListener("Browser:FirstPaint", function firstPaintListener(aMessage) {
browser.messageManager.removeMessageListener(aMessage.name, arguments.callee);
aTab._firstPaint = true;
// We're about to have new page content, so scroll the content area
// so the new paints will draw correctly.
@ -1595,12 +1608,13 @@ Browser.WebProgress.prototype = {
Math.floor(json.y * browser.scale));
if (json.x == 0 && json.y == 0)
Browser.pageScrollboxScroller.scrollTo(0, 0);
else
Browser.pageScrollboxScroller.scrollTo(0, Number.MAX_VALUE);
}
aTab.scrolledAreaChanged();
aTab.scrolledAreaChanged(true);
aTab.updateThumbnail();
browser.messageManager.addMessageListener("MozScrolledAreaChanged", aTab.scrolledAreaChanged);
aTab.updateContentCapture();
});
}
@ -2686,7 +2700,6 @@ function Tab(aURI, aParams) {
this._metadata = null;
this.contentMightCaptureMouse = false;
this.useFallbackWidth = false;
this.owner = null;
this.hostChanged = false;
@ -2702,8 +2715,6 @@ function Tab(aURI, aParams) {
// default tabs to inactive (i.e. no display port)
this.active = false;
this.scrolledAreaChanged = this.scrolledAreaChanged.bind(this);
}
Tab.prototype = {
@ -2783,8 +2794,8 @@ Tab.prototype = {
} else if (!validW && validH) {
viewportW = viewportH * (screenW / screenH);
} else if (!validW && !validH) {
viewportW = this.useFallbackWidth ? kFallbackBrowserWidth : kDefaultBrowserWidth;
viewportH = kDefaultBrowserWidth * (screenH / screenW);
viewportW = Browser.defaultBrowserWidth;
viewportH = Browser.defaultBrowserWidth * (screenH / screenW);
}
}
@ -2944,16 +2955,16 @@ Tab.prototype = {
this._defaultZoomLevel = this._browser.scale;
},
scrolledAreaChanged: function scrolledAreaChanged() {
scrolledAreaChanged: function scrolledAreaChanged(firstPaint) {
if (!this._browser)
return;
if (firstPaint) {
// You only get one shot, do not miss your chance to reflow.
this.updateViewportSize();
}
this.updateDefaultZoomLevel();
if (!this.useFallbackWidth && this._browser.contentDocumentWidth > kDefaultBrowserWidth)
this.useFallbackWidth = true;
this.updateViewportSize();
},
/**
@ -2962,7 +2973,7 @@ Tab.prototype = {
*/
updateDefaultZoomLevel: function updateDefaultZoomLevel() {
let browser = this._browser;
if (!browser)
if (!browser || !this._firstPaint)
return;
let isDefault = this.isDefaultZoomLevel();
@ -3194,7 +3205,6 @@ var ViewableAreaObserver = {
return;
// Guess if the window has been resize to handle a virtual keyboard
let isDueToKeyboard = (newHeight != oldHeight && newWidth == oldWidth);
this.isKeyboardOpened = (newHeight < oldHeight && newWidth == oldWidth);
Browser.styles["viewable-height"].height = newHeight + "px";
@ -3203,20 +3213,23 @@ var ViewableAreaObserver = {
Browser.styles["viewable-width"].width = newWidth + "px";
Browser.styles["viewable-width"].maxWidth = newWidth + "px";
let startup = !oldHeight && !oldWidth;
if (!isDueToKeyboard) {
// Don't update the viewport if screen height is shrinking, which typically
// means the keyboard appeared. This helps smooth out the experience of our
// form filler.
if (newHeight > oldHeight || newWidth != oldWidth) {
let startup = !oldHeight && !oldWidth;
for (let i = Browser.tabs.length - 1; i >= 0; i--) {
let tab = Browser.tabs[i];
let oldContentWindowWidth = tab.browser.contentWindowWidth;
tab.updateViewportSize(); // contentWindowWidth may change here.
// Don't bother updating the zoom level on startup
if (!startup) {
// If the viewport width is still the same, the page layout has not
// changed, so we can keep keep the same content on-screen.
if (tab.browser.contentWindowWidth == oldContentWindowWidth)
tab.restoreViewportPosition(oldWidth, newWidth);
tab.updateDefaultZoomLevel();
}
}