diff --git a/browser/components/sessionstore/src/SessionStore.jsm b/browser/components/sessionstore/src/SessionStore.jsm index 793ab128607..1257cf274fb 100644 --- a/browser/components/sessionstore/src/SessionStore.jsm +++ b/browser/components/sessionstore/src/SessionStore.jsm @@ -83,6 +83,8 @@ Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", this); XPCOMUtils.defineLazyServiceGetter(this, "gSessionStartup", "@mozilla.org/browser/sessionstartup;1", "nsISessionStartup"); +XPCOMUtils.defineLazyServiceGetter(this, "gScreenManager", + "@mozilla.org/gfx/screenmanager;1", "nsIScreenManager"); // List of docShell capabilities to (re)store. These are automatically // retrieved from a given docShell if not already collected before. @@ -3579,6 +3581,31 @@ let SessionStoreInternal = { var _this = this; function win_(aName) { return _this._getWindowDimension(win, aName); } + // find available space on the screen where this window is being placed + let screen = gScreenManager.screenForRect(aLeft, aTop, aWidth, aHeight); + if (screen) { + let screenLeft = {}, screenTop = {}, screenWidth = {}, screenHeight = {}; + screen.GetAvailRectDisplayPix(screenLeft, screenTop, screenWidth, screenHeight); + // constrain the dimensions to the actual space available + if (aWidth > screenWidth.value) { + aWidth = screenWidth.value; + } + if (aHeight > screenHeight.value) { + aHeight = screenHeight.value; + } + // and then pull the window within the screen's bounds + if (aLeft < screenLeft.value) { + aLeft = screenLeft.value; + } else if (aLeft + aWidth > screenLeft.value + screenWidth.value) { + aLeft = screenLeft.value + screenWidth.value - aWidth; + } + if (aTop < screenTop.value) { + aTop = screenTop.value; + } else if (aTop + aHeight > screenTop.value + screenHeight.value) { + aTop = screenTop.value + screenHeight.value - aHeight; + } + } + // only modify those aspects which aren't correct yet if (aWidth && aHeight && (aWidth != win_("width") || aHeight != win_("height"))) { aWindow.resizeTo(aWidth, aHeight);