Bug 1007344 - Ignore inactive windows when moving alerts. r=MattN
authorMichał Sobkiewicz <perceptron8@gmail.com>
Sun, 15 Mar 2020 22:30:03 +0000
changeset 518880 a0a22903ead2159fa58985684158462de0a62891
parent 518879 f14f678590b7b71de62740c3ea540b48eb17397b
child 518881 4c0c09659c77558c85f0539544b8e860b17bb500
push id37218
push userrmaries@mozilla.com
push dateMon, 16 Mar 2020 09:28:04 +0000
treeherdermozilla-central@6199f7b91e8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1007344
milestone76.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 1007344 - Ignore inactive windows when moving alerts. r=MattN Differential Revision: https://phabricator.services.mozilla.com/D66605
toolkit/components/alerts/resources/content/alert.js
--- a/toolkit/components/alerts/resources/content/alert.js
+++ b/toolkit/components/alerts/resources/content/alert.js
@@ -16,16 +16,17 @@ const WINDOW_MARGIN = AppConstants.platf
 const BODY_TEXT_LIMIT = 200;
 const WINDOW_SHADOW_SPREAD = AppConstants.platform == "win" ? 10 : 0;
 
 var gOrigin = 0; // Default value: alert from bottom right.
 var gReplacedWindow = null;
 var gAlertListener = null;
 var gAlertTextClickable = false;
 var gAlertCookie = "";
+var gIsActive = false;
 var gIsReplaced = false;
 var gRequireInteraction = false;
 
 function prefillAlertInfo() {
   // unwrap all the args....
   // arguments[0] --> the image src url
   // arguments[1] --> the alert title
   // arguments[2] --> the alert text
@@ -229,30 +230,35 @@ function onAlertLoad() {
       alertBox.setAttribute("animate", true);
     }
   }
 
   let alertSettings = document.getElementById("alertSettings");
   alertSettings.addEventListener("focus", onAlertSettingsFocus);
   alertSettings.addEventListener("click", onAlertSettingsClick);
 
+  gIsActive = true;
+
   let ev = new CustomEvent("AlertActive", { bubbles: true, cancelable: true });
   document.documentElement.dispatchEvent(ev);
 
   if (gAlertListener) {
     gAlertListener.observe(null, "alertshow", gAlertCookie);
   }
 }
 
 function moveWindowToReplace(aReplacedAlert) {
   let heightDelta = window.outerHeight - aReplacedAlert.outerHeight;
 
   // Move windows that come after the replaced alert if the height is different.
   if (heightDelta != 0) {
     for (let alertWindow of Services.wm.getEnumerator("alert:alert")) {
+      if (!alertWindow.gIsActive) {
+        continue;
+      }
       // boolean to determine if the alert window is after the replaced alert.
       let alertIsAfter =
         gOrigin & NS_ALERT_TOP
           ? alertWindow.screenY > aReplacedAlert.screenY
           : aReplacedAlert.screenY > alertWindow.screenY;
       if (alertIsAfter) {
         // The new Y position of the window.
         let adjustedY =
@@ -279,17 +285,17 @@ function moveWindowToEnd() {
       : screen.availLeft + screen.availWidth - window.outerWidth;
   let y =
     gOrigin & NS_ALERT_TOP
       ? screen.availTop
       : screen.availTop + screen.availHeight - window.outerHeight;
 
   // Position the window at the end of all alerts.
   for (let alertWindow of Services.wm.getEnumerator("alert:alert")) {
-    if (alertWindow != window) {
+    if (alertWindow != window && alertWindow.gIsActive) {
       if (gOrigin & NS_ALERT_TOP) {
         y = Math.max(
           y,
           alertWindow.screenY + alertWindow.outerHeight - WINDOW_SHADOW_SPREAD
         );
       } else {
         y = Math.min(
           y,
@@ -306,17 +312,17 @@ function moveWindowToEnd() {
   window.moveTo(x, y);
 }
 
 function onAlertBeforeUnload() {
   if (!gIsReplaced) {
     // Move other alert windows to fill the gap left by closing alert.
     let heightDelta = window.outerHeight + WINDOW_MARGIN - WINDOW_SHADOW_SPREAD;
     for (let alertWindow of Services.wm.getEnumerator("alert:alert")) {
-      if (alertWindow != window) {
+      if (alertWindow != window && alertWindow.gIsActive) {
         if (gOrigin & NS_ALERT_TOP) {
           if (alertWindow.screenY > window.screenY) {
             alertWindow.moveTo(
               alertWindow.screenX,
               alertWindow.screenY - heightDelta
             );
           }
         } else if (window.screenY > alertWindow.screenY) {