Bug 1509847 - only move minimized windows behind unminimized ones, r=dao a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 18 Feb 2019 07:04:43 +0000
changeset 516106 f7afc2589d2cd268558ac274c2d6aa51caf209d3
parent 516105 3c75057cd305fabb2a722960a429f9098a017954
child 516107 9d3241ed6cc5a21adfa97431541565cf1f26c275
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao, lizzard
bugs1509847
milestone66.0
Bug 1509847 - only move minimized windows behind unminimized ones, r=dao a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D19181
browser/modules/BrowserWindowTracker.jsm
--- a/browser/modules/BrowserWindowTracker.jsm
+++ b/browser/modules/BrowserWindowTracker.jsm
@@ -77,18 +77,25 @@ function _handleMessage(message) {
   let browser = message.target;
   if (message.name === "Browser:Init" &&
       browser === browser.ownerGlobal.gBrowser.selectedBrowser) {
     _updateCurrentContentOuterWindowID(browser);
   }
 }
 
 function _trackWindowOrder(window) {
-  _trackedWindows.splice(window.windowState == window.STATE_MINIMIZED ?
-    _trackedWindows.length - 1 : 0, 0, window);
+  if (window.windowState == window.STATE_MINIMIZED) {
+    let firstMinimizedWindow = _trackedWindows.findIndex(w => w.windowState == w.STATE_MINIMIZED);
+    if (firstMinimizedWindow == -1) {
+      firstMinimizedWindow = _trackedWindows.length;
+    }
+    _trackedWindows.splice(firstMinimizedWindow, 0, window);
+  } else {
+    _trackedWindows.unshift(window);
+  }
 }
 
 function _untrackWindowOrder(window) {
   let idx = _trackedWindows.indexOf(window);
   if (idx >= 0)
     _trackedWindows.splice(idx, 1);
 }
 
@@ -135,19 +142,19 @@ var WindowHelper = {
     _untrackWindowOrder(window);
     _trackWindowOrder(window);
 
     _updateCurrentContentOuterWindowID(window.gBrowser.selectedBrowser);
   },
 
   onSizemodeChange(window) {
     if (window.windowState == window.STATE_MINIMIZED) {
-      // Make sure to have the minimized window at the end of the list.
+      // Make sure to have the minimized window behind unminimized windows.
       _untrackWindowOrder(window);
-      _trackedWindows.push(window);
+      _trackWindowOrder(window);
     }
   },
 };
 
 this.BrowserWindowTracker = {
   /**
    * Get the most recent browser window.
    *