Bug 384278 - Added additional state variable to store window state before window minimization. r=mikedeboer
☠☠ backed out by be2f62a541cb ☠ ☠
authorOrangelynx <orangelynx@outlook.de>
Sun, 03 Feb 2019 14:29:29 +0000
changeset 456588 a1f9a3e18986242af272c6d61099c64c19e16d1a
parent 456587 8d612e0b0258f31a836bb163457605e0b4edd198
child 456589 be2f62a541cb4e5c0472878f3370092d1a2bbcae
push id35492
push usercbrindusan@mozilla.com
push dateSun, 03 Feb 2019 21:40:38 +0000
treeherdermozilla-central@be2f62a541cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs384278
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 384278 - Added additional state variable to store window state before window minimization. r=mikedeboer Current window state in the sessionstore system includes `sizeMode` which can be "normal", "minimized", "maximized". However, the OS also remembers whether the window was "normal" or "maximized" before minimization to restore it appropriately. With this fix, sessionstore does likewise. Differential Revision: https://phabricator.services.mozilla.com/D13234
browser/components/sessionstore/SessionStore.jsm
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_sizemodeBeforeMinimized.js
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -3328,16 +3328,19 @@ var SessionStoreInternal = {
    */
   _updateWindowFeatures: function ssi_updateWindowFeatures(aWindow) {
     var winData = this._windows[aWindow.__SSi];
 
     WINDOW_ATTRIBUTES.forEach(function(aAttr) {
       winData[aAttr] = this._getWindowDimension(aWindow, aAttr);
     }, this);
 
+    if (winData.sizemode != "minimized")
+      winData.sizemodeBeforeMinimized = winData.sizemode;
+
     var hidden = WINDOW_HIDEABLE_FEATURES.filter(function(aItem) {
       return aWindow[aItem] && !aWindow[aItem].visible;
     });
     if (hidden.length != 0)
       winData.hidden = hidden.join(",");
     else if (winData.hidden)
       delete winData.hidden;
 
@@ -4286,36 +4289,39 @@ var SessionStoreInternal = {
     }
 
     aWindow.setTimeout(() => {
       this.restoreDimensions(aWindow,
         +(aWinData.width || 0),
         +(aWinData.height || 0),
         "screenX" in aWinData ? +aWinData.screenX : NaN,
         "screenY" in aWinData ? +aWinData.screenY : NaN,
-        aWinData.sizemode || "", aWinData.sidebar || "");
+        aWinData.sizemode || "", aWinData.sizemodeBeforeMinimized || "",
+        aWinData.sidebar || "");
     }, 0);
   },
 
   /**
    * Restore a window's dimensions
    * @param aWidth
    *        Window width
    * @param aHeight
    *        Window height
    * @param aLeft
    *        Window left
    * @param aTop
    *        Window top
    * @param aSizeMode
    *        Window size mode (eg: maximized)
+   * @param aSizeModeBeforeMinimized
+   *        Window size mode before window got minimized (eg: maximized)
    * @param aSidebar
    *        Sidebar command
    */
-  restoreDimensions: function ssi_restoreDimensions(aWindow, aWidth, aHeight, aLeft, aTop, aSizeMode, aSidebar) {
+  restoreDimensions: function ssi_restoreDimensions(aWindow, aWidth, aHeight, aLeft, aTop, aSizeMode, aSizeModeBeforeMinimized, aSidebar) {
     var win = aWindow;
     var _this = this;
     function win_(aName) { return _this._getWindowDimension(win, aName); }
 
     const dwu = win.windowUtils;
     // find available space on the screen where this window is being placed
     let screen = gScreenManager.screenForRect(aLeft, aTop, aWidth, aHeight);
     if (screen) {
@@ -4374,22 +4380,25 @@ var SessionStoreInternal = {
       }
       if (aWidth && aHeight && (aWidth != win_("width") || aHeight != win_("height")) && !gResistFingerprintingEnabled) {
         // Don't resize the window if it's currently maximized and we would
         // maximize it again shortly after.
         if (aSizeMode != "maximized" || win_("sizemode") != "maximized") {
           aWindow.resizeTo(aWidth, aHeight);
         }
       }
+      this._windows[aWindow.__SSi].sizemodeBeforeMinimized = aSizeModeBeforeMinimized;
       if (aSizeMode && win_("sizemode") != aSizeMode && !gResistFingerprintingEnabled) {
         switch (aSizeMode) {
         case "maximized":
           aWindow.maximize();
           break;
         case "minimized":
+          if (aSizeModeBeforeMinimized == "maximized")
+            aWindow.maximize();
           aWindow.minimize();
           break;
         case "normal":
           aWindow.restore();
           break;
         }
       }
       let sidebarBox = aWindow.document.getElementById("sidebar-box");
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -121,16 +121,17 @@ skip-if = e10s # Bug 1271024
 [browser_restore_cookies_noOriginAttributes.js]
 [browser_scrollPositions.js]
 [browser_scrollPositionsReaderMode.js]
 [browser_sessionHistory.js]
 support-files =
   file_sessionHistory_hashchange.html
 [browser_sessionStorage.js]
 [browser_sessionStorage_size.js]
+[browser_sizemodeBeforeMinimized.js]
 [browser_tab_label_during_restore.js]
 [browser_swapDocShells.js]
 [browser_switch_remoteness.js]
 run-if = e10s
 [browser_upgrade_backup.js]
 skip-if = (os == 'linux' && (asan || debug)) || (verify && debug && (os == 'mac')) || (os == 'win' && bits == 64) # Bug 1435394 disabled on Linux and Windows
 [browser_windowRestore_perwindowpb.js]
 [browser_248970_b_perwindowpb.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_sizemodeBeforeMinimized.js
@@ -0,0 +1,31 @@
+add_task(async function test() {
+  // Test for bugfix 384278. Confirms that sizemodeBeforeMinimized is set properly when window state is saved.
+  const win = await BrowserTestUtils.openNewBrowserWindow();
+
+  async function changeSizeMode(mode) {
+    let promise = BrowserTestUtils.waitForEvent(win, "sizemodechange");
+    win[mode]();
+    await promise;
+  }
+
+  function checkCurrentState(sizemodeBeforeMinimized) {
+    let state = JSON.parse(ss.getWindowState(win));
+    let winState = state.windows[0];
+    is(winState.sizemodeBeforeMinimized, sizemodeBeforeMinimized, "sizemodeBeforeMinimized should match");
+  }
+
+  if (win.windowState != win.STATE_NORMAL) {
+    await changeSizeMode("restore");
+  }
+  await forceSaveState();
+  await changeSizeMode("minimize");
+  checkCurrentState("normal");
+
+  await changeSizeMode("maximize");
+  await forceSaveState();
+  await changeSizeMode("minimize");
+  checkCurrentState("maximized");
+
+  // Clean up.
+  await BrowserTestUtils.closeWindow(win);
+});