Bug 602962 - Undo close tab thumbnail dissapears when rotating screen orientation [r=mfinkle]
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -170,16 +170,17 @@ function onDebugKeyPress(ev) {
var Browser = {
_tabs: [],
_selectedTab: null,
windowUtils: window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils),
controlsScrollbox: null,
controlsScrollboxScroller: null,
+ controlsPosition: null,
pageScrollbox: null,
pageScrollboxScroller: null,
styles: {},
startup: function startup() {
var self = this;
try {
@@ -242,16 +243,25 @@ var Browser = {
for each (let style in ["window-width", "window-height", "toolbar-height"]) {
let index = stylesheet.insertRule("." + style + " {}", stylesheet.cssRules.length);
this.styles[style] = stylesheet.cssRules[index].style;
}
// Init the cache used in the resize handler
window.cachedWidth = window.innerWidth;
+ // Saved the scrolls values before the resizing of the window, to restore
+ // the scrollbox position once the resize has finished
+ window.addEventListener("MozBeforeResize", function(aEvent) {
+ let { x: x1, y: y1 } = Browser.getScrollboxPosition(Browser.controlsScrollboxScroller);
+ let { x: x2, y: y2 } = Browser.getScrollboxPosition(Browser.pageScrollboxScroller);
+
+ Browser.controlsPosition = { x: x1, y: y2, hideSidebars: Browser.controlsPosition ? Browser.controlsPosition.hideSidebars : true };
+ }, false);
+
function resizeHandler(e) {
if (e.target != window)
return;
let w = window.innerWidth;
let h = window.innerHeight;
// XXX is this code right here actually needed?
@@ -263,37 +273,40 @@ var Browser = {
Browser.styles["window-width"].width = w + "px";
Browser.styles["window-height"].height = h + "px";
Browser.styles["toolbar-height"].height = toolbarHeight + "px";
// Tell the UI to resize the browser controls
BrowserUI.sizeControls(w, h);
- // XXX this should really only happen on browser startup, not every resize
- Browser.hideSidebars();
+ // Restore the previous scroll position
+ if (Browser.controlsPosition.hideSidebars) {
+ Browser.controlsPosition.hideSidebars = false;
+ Browser.hideSidebars();
+ } else {
+ Browser.controlsScrollboxScroller.scrollTo(Browser.controlsPosition.x, 0);
+ Browser.pageScrollboxScroller.scrollTo(0, Browser.controlsPosition.y);
+ Browser.tryFloatToolbar(0, 0);
+ }
let oldWidth = window.cachedWidth || w;
window.cachedWidth = w;
for (let i = Browser.tabs.length - 1; i >= 0; i--) {
let tab = Browser.tabs[i];
let oldContentWindowWidth = tab.browser.contentWindowWidth;
tab.updateViewportSize();
// 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, w);
}
- // XXX page scrollbox jumps to a strange value on resize. Scrolling it will
- // bound it to a sane place, but not where we were when the resize began :(
- Browser.hideTitlebar();
-
// We want to keep the current focused element into view if possible
let currentElement = document.activeElement;
let [scrollbox, scrollInterface] = ScrollUtils.getScrollboxFromElement(currentElement);
if (scrollbox && scrollInterface && currentElement && currentElement != scrollbox) {
// retrieve the direct child of the scrollbox
while (currentElement.parentNode != scrollbox)
currentElement = currentElement.parentNode;