Bug 1597062 - Port |Bug 581932 - Keyboard shortcuts are disabled after deleting a message and next is a thread when message pane has focus|. r=frg a=frg CLOSED TREE
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sun, 24 Nov 2019 14:23:37 +0100
changeset 32381 d1bf768379071baecf3f20f9bb7149f3a33724f1
parent 32380 dc3f8cba758d04fb1274a333ddc680b00ddf322f
child 32382 fddcb5bd203c2f4bb0c85225231efd7ae10ec8e5
push id231
push userfrgrahl@gmx.net
push dateSun, 24 Nov 2019 13:24:21 +0000
treeherdercomm-esr60@fddcb5bd203c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1597062, 581932
Bug 1597062 - Port |Bug 581932 - Keyboard shortcuts are disabled after deleting a message and next is a thread when message pane has focus|. r=frg a=frg CLOSED TREE
suite/mailnews/content/folderDisplay.js
suite/mailnews/content/mail3PaneWindowCommands.js
--- a/suite/mailnews/content/folderDisplay.js
+++ b/suite/mailnews/content/folderDisplay.js
@@ -79,17 +79,42 @@ var gFolderDisplay =
       let identity = GetIdentityForHeader(aMsg);
       return identity && identity.archiveEnabled;
     });
   },
 
   get displayedFolder()
   {
     return gMsgFolderSelected;
-  }
+  },
+
+   /**
+   * Determine which pane currently has focus (one of the folder pane, thread
+   * pane, or message pane). When changing focus to the message pane, be sure
+   * to focus the appropriate content window in addition to the messagepanebox
+   * (doing both is required in order to blur the previously-focused chrome
+   * element).
+   *
+   * @return the focused pane
+   */
+  get focusedPane() {
+    let panes = ["threadTree", "folderTree", "messagepanebox"].map(id =>
+        document.getElementById(id));
+
+    let currentNode = top.document.activeElement;
+
+    while (currentNode) {
+      if (panes.includes(currentNode)) {
+        return currentNode;
+      }
+
+      currentNode = currentNode.parentNode;
+    }
+    return null;
+  },
 
 }
 
 var gMessageDisplay =
 {
   get displayedMessage()
   {
     if (!gDBView)
--- a/suite/mailnews/content/mail3PaneWindowCommands.js
+++ b/suite/mailnews/content/mail3PaneWindowCommands.js
@@ -764,24 +764,22 @@ function GetNumSelectedMessages()
     return 0;
   }
 }
 
 var gLastFocusedElement=null;
 
 function FocusRingUpdate_Mail()
 {
-  // WhichPaneHasFocus() uses on top.document.commandDispatcher.focusedElement
-  // to determine which pane has focus
-  // if the focusedElement is null, we're here on a blur.
+  // If the focusedElement is null, we're here on a blur.
   // nsFocusController::Blur() calls nsFocusController::SetFocusedElement(null),
   // which will update any commands listening for "focus".
   // we really only care about nsFocusController::Focus() happens,
   // which calls nsFocusController::SetFocusedElement(element)
-  var currentFocusedElement = WhichPaneHasFocus();
+  var currentFocusedElement = gFolderDisplay.focusedPane;
 
   if (currentFocusedElement != gLastFocusedElement) {
     if (currentFocusedElement)
       currentFocusedElement.setAttribute("focusring", "true");
 
     if (gLastFocusedElement)
       gLastFocusedElement.removeAttribute("focusring");
 
@@ -790,38 +788,16 @@ function FocusRingUpdate_Mail()
     // since we just changed the pane with focus we need to update the toolbar to reflect this
     // XXX TODO
     // can we optimize
     // and just update cmd_delete and button_delete?
     UpdateMailToolbar("focus");
   }
 }
 
-function WhichPaneHasFocus()
-{
-  var threadTree = GetThreadTree();
-  var folderTree = GetFolderTree();
-  var messagePane = GetMessagePane();
-
-  if (top.document.commandDispatcher.focusedWindow == GetMessagePaneFrame())
-    return messagePane;
-
-  var currentNode = top.document.commandDispatcher.focusedElement;
-  while (currentNode) {
-    if (currentNode === threadTree ||
-        currentNode === folderTree ||
-        currentNode === messagePane)
-      return currentNode;
-
-    currentNode = currentNode.parentNode;
-  }
-
-  return null;
-}
-
 function SetupCommandUpdateHandlers()
 {
   // folder pane
   var widget = GetFolderTree();
   if (widget)
     widget.controllers.appendController(FolderPaneController);
 }
 
@@ -990,34 +966,34 @@ function MsgDeleteFolder()
         }
       }
     }
   }
 }
 
 function SetFocusThreadPaneIfNotOnMessagePane()
 {
-  var focusedElement = WhichPaneHasFocus();
+  var focusedElement = gFolderDisplay.focusedPane;
 
   if((focusedElement != GetThreadTree()) &&
      (focusedElement != GetMessagePane()))
      SetFocusThreadPane();
 }
 
 function SwitchPaneFocus(event)
 {
   var folderTree = GetFolderTree();
   var threadTree = GetThreadTree();
   var messagePane = GetMessagePane();
 
   // Although internally this is actually a four-pane window, it is presented as
   // a three-pane -- the search pane is more of a toolbar.  So, shift among the
   // three main panes.
 
-  var focusedElement = WhichPaneHasFocus();
+  var focusedElement = gFolderDisplay.focusedPane;
   if (focusedElement == null)       // focus not on one of the main three panes?
     focusedElement = threadTree;    // treat as if on thread tree
 
   if (event && event.shiftKey)
   {
     // Reverse traversal: Message -> Thread -> Folder -> Message
     if (focusedElement == threadTree && !IsFolderPaneCollapsed())
       folderTree.focus();