diff --git a/mobile/chrome/content/BrowserView.js b/mobile/chrome/content/BrowserView.js index 2b34cfa1ce9a..2824e21c0c0d 100644 --- a/mobile/chrome/content/BrowserView.js +++ b/mobile/chrome/content/BrowserView.js @@ -271,6 +271,9 @@ BrowserView.prototype = { this._idleServiceObserver = new BrowserView.IdleServiceObserver(this); this._idleService = Cc["@mozilla.org/widget/idleservice;1"].getService(Ci.nsIIdleService); this._idleService.addIdleObserver(this._idleServiceObserver, kBrowserViewPrefetchBeginIdleWait); + + let browsers = document.getElementById("browsers"); + browsers.addEventListener("MozScrolledAreaChanged", this.handleMozScrolledAreaChanged, false); }, uninit: function uninit() { @@ -282,31 +285,6 @@ BrowserView.prototype = { return this._visibleRectFactory(); }, - setViewportDimensions: function setViewportDimensions(width, height, causedByZoom) { - let bvs = this._browserViewportState; - if (!bvs) - return; - - if (!causedByZoom) - this._suppressZoomToPage = false; - - let oldwidth = bvs.viewportRect.right; - let oldheight = bvs.viewportRect.bottom; - bvs.viewportRect.right = width; - bvs.viewportRect.bottom = height; - - let sizeChanged = (oldwidth != width || oldheight != height); - - // XXX we might not want the user's page to disappear from under them - // at this point, which could happen if the container gets resized such - // that visible rect becomes entirely outside of viewport rect. might - // be wise to define what UX should be in this case, like a move occurs. - // then again, we could also argue this is the responsibility of the - // caller who would do such a thing... - - this._viewportChanged(sizeChanged, sizeChanged && !!causedByZoom); - }, - /** * @return [width, height] */ @@ -328,9 +306,9 @@ BrowserView.prototype = { let browserW = this.viewportToBrowser(bvs.viewportRect.right); let browserH = this.viewportToBrowser(bvs.viewportRect.bottom); bvs.zoomLevel = newZoomLevel; // side-effect: now scale factor in transformations is newZoomLevel - this.setViewportDimensions(this.browserToViewport(browserW), - this.browserToViewport(browserH), - true); + bvs.viewportRect.right = this.browserToViewport(browserW); + bvs.viewportRect.bottom = this.browserToViewport(browserH); + this._viewportChanged(true, true); if (this._browser) { let event = document.createEvent("Events"); @@ -487,8 +465,6 @@ BrowserView.prototype = { if (oldBrowser) { oldBrowser.removeEventListener("MozAfterPaint", this.handleMozAfterPaint, false); oldBrowser.removeEventListener("scroll", this.handlePageScroll, false); - oldBrowser.removeEventListener("MozScrolledAreaChanged", this.handleMozScrolledAreaChanged, false); - oldBrowser.setAttribute("type", "content"); oldBrowser.docShell.isOffScreenBrowser = false; } @@ -504,13 +480,13 @@ BrowserView.prototype = { browser.addEventListener("MozAfterPaint", this.handleMozAfterPaint, false); browser.addEventListener("scroll", this.handlePageScroll, false); - browser.addEventListener("MozScrolledAreaChanged", this.handleMozScrolledAreaChanged, false); browser.docShell.isOffScreenBrowser = true; if (doZoom) this.zoomToPage(); - this._viewportChanged(browserChanged, browserChanged); + if (browserChanged) + this._viewportChanged(true, true); this.commitBatchOperation(); } @@ -562,11 +538,13 @@ BrowserView.prototype = { }, handleMozScrolledAreaChanged: function handleMozScrolledAreaChanged(ev) { - if (ev.target != this._browser.contentDocument) + let tab = Browser.getTabForDocument(ev.originalTarget); + if (!tab) return; - let { x: scrollX, y: scrollY } = BrowserView.Util.getContentScrollOffset(this._browser); - + let browser = tab.browser; + let bvs = tab.browserViewportState; + let { x: scrollX, y: scrollY } = BrowserView.Util.getContentScrollOffset(browser); let x = ev.x + scrollX; let y = ev.y + scrollY; let w = ev.width; @@ -578,8 +556,18 @@ BrowserView.prototype = { if (x < 0) w += x; if (y < 0) h += y; - this.setViewportDimensions(this.browserToViewport(w), - this.browserToViewport(h)); + let viewport = bvs.viewportRect; + let oldRight = viewport.right; + let oldBottom = viewport.bottom; + viewport.right = bvs.zoomLevel * w; + viewport.bottom = bvs.zoomLevel * h; + + if (browser == this._browser) { + // Page has now loaded enough to allow zooming. + let sizeChanged = oldRight != viewport.right || oldBottom != viewport.bottom; + this._suppressZoomToPage = false; + this._viewportChanged(sizeChanged, false); + } }, zoomToPage: function zoomToPage() { @@ -651,10 +639,8 @@ BrowserView.prototype = { // Since calling this method means "everything is wrong and the // is about to start giving you new data via MozAfterPaint // and MozScrolledAreaChanged", we also supress any zoomToPage() - // that might be called until the next time setViewportDimensions() - // is called (which will probably be caused by an incoming - // MozScrolledAreaChanged event, or via someone very eagerly setting - // it manually so that they can zoom to that manual "page" width). + // that might be called until the next time a MozScrolledAreaChanged + // event. // /** * Invalidates the entire page by throwing away any cached graphical @@ -666,7 +652,7 @@ BrowserView.prototype = { */ invalidateEntireView: function invalidateEntireView() { if (this._browserViewportState) { - this._viewportChanged(false, true, true); + this._viewportChanged(false, true); this._suppressZoomToPage = true; } }, @@ -764,7 +750,6 @@ BrowserView.prototype = { if (viewportSizeChanged) opState.viewportSizeChanged = viewportSizeChanged; - if (dirtyAll) opState.dirtyAll = dirtyAll; diff --git a/mobile/chrome/content/TileManager.js.in b/mobile/chrome/content/TileManager.js.in index d83b519682a5..739b8d611501 100644 --- a/mobile/chrome/content/TileManager.js.in +++ b/mobile/chrome/content/TileManager.js.in @@ -108,8 +108,6 @@ const kTileCrawlComeAgain = 0; // millis * @param removeTile The function the tile manager should call in order to * "undisplay" a tile (e.g. remove it from the DOM). The argument to this * function is a TileManager.Tile object. - * @param fakeWidth The width of the widest possible visible rectangle, e.g. - * the width of the screen. This is used in setting the zoomLevel. */ function TileManager(appendTile, removeTile, browserView, cacheSize) { /* backref to the BrowserView object that owns us */ @@ -161,12 +159,9 @@ TileManager.prototype = { this.endCriticalMove(criticalRect, !(dirtyAll || boundsSizeChanged)); } - if (dirtyAll) { this.dirtyRects([viewportRect.clone()], true); } else if (boundsSizeChanged) { - - // // This is a special case. The bounds size changed, but we are // told that not everything is dirty (so mayhap content grew or // shrank vertically or horizontally). We might have old tiles @@ -239,7 +234,6 @@ TileManager.prototype = { this.dirtyRects(rects, true); } - }, dirtyRects: function dirtyRects(rects, doCriticalRender) { diff --git a/mobile/chrome/content/Util.js b/mobile/chrome/content/Util.js index ff4ab6235f4c..25e93a056b0f 100644 --- a/mobile/chrome/content/Util.js +++ b/mobile/chrome/content/Util.js @@ -324,7 +324,8 @@ Rect.prototype = { }, equals: function equals(other) { - return (other != null && + return other != null && + (this.isEmpty() && other.isEmpty() || this.top == other.top && this.left == other.left && this.bottom == other.bottom && diff --git a/mobile/chrome/content/browser.js b/mobile/chrome/content/browser.js index 5961e6e1c122..f7cc412208df 100644 --- a/mobile/chrome/content/browser.js +++ b/mobile/chrome/content/browser.js @@ -2499,7 +2499,7 @@ Tab.prototype = { }, /** - * Throttles redraws to once every second while loading the page, zooming to fit page if + * Throttles redraws to once every 2 seconds while loading the page, zooming to fit page if * user hasn't started zooming. */ _resizeAndPaint: function() {