From 16a3baa743a14c0422a577a86d2be305de3514c3 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Fri, 26 Apr 2013 12:41:29 +0100 Subject: [PATCH] bug 864107 - constrain restored window dimensions to available screen area. r=ttaubert --- .../sessionstore/src/SessionStore.jsm | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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);