Backed out changeset d8ad92570434 (bug 1625263) because it broke tests. rs=backout
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 28 May 2020 20:40:39 +1200
changeset 39250 7fc15b13b7eef6b459ead9200ec8c228fe4f4925
parent 39249 d8ad92570434f84f790e5ce1f160c7c07f692006
child 39251 dba64c20e3a8b91ef4750893e6b3f694fbefefc2
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersbackout
bugs1625263
backs outd8ad92570434f84f790e5ce1f160c7c07f692006
Backed out changeset d8ad92570434 (bug 1625263) because it broke tests. rs=backout
mail/base/content/mailWidgets.js
mail/components/compose/content/MsgComposeCommands.js
mail/components/compose/content/messengercompose.xhtml
mail/locales/en-US/chrome/messenger/messengercompose/composeMsgs.properties
mail/locales/en-US/chrome/messenger/messengercompose/messengercompose.dtd
mail/locales/en-US/messenger/messengercompose/messengercompose.ftl
--- a/mail/base/content/mailWidgets.js
+++ b/mail/base/content/mailWidgets.js
@@ -1272,45 +1272,39 @@
     constructor() {
       super();
 
       this.messenger = Cc["@mozilla.org/messenger;1"].createInstance(
         Ci.nsIMessenger
       );
 
       this.addEventListener("keypress", event => {
-        switch (event.key) {
-          case " ":
-            // Allow plain spacebar to select the focused item.
-            if (!event.shiftKey && !event.ctrlKey) {
-              this.addItemToSelection(this.currentItem);
-            }
-            // Prevent inbuilt scrolling.
-            event.preventDefault();
-            break;
-
-          case "Enter":
-            if (this.currentItem && !event.ctrlKey && !event.shiftKey) {
-              this.addItemToSelection(this.currentItem);
-              let evt = document.createEvent("XULCommandEvent");
-              evt.initCommandEvent(
-                "command",
-                true,
-                true,
-                window,
-                0,
-                event.ctrlKey,
-                event.altKey,
-                event.shiftKey,
-                event.metaKey,
-                null
-              );
-              this.currentItem.dispatchEvent(evt);
-            }
-            break;
+        // The spacebar should work just like the arrow keys, except that the
+        // focused element doesn't change, so use moveByOffset here.
+        if (event.keyCode == KeyEvent.DOM_VK_SPACE) {
+          this.moveByOffset(0, !event.ctrlKey, event.shiftKey);
+          event.preventDefault();
+        } else if (event.keyCode == KeyEvent.DOM_VK_RETURN) {
+          if (this.currentItem && !event.ctrlKey && !event.shiftKey) {
+            this.addItemToSelection(this.currentItem);
+            let evt = document.createEvent("XULCommandEvent");
+            evt.initCommandEvent(
+              "command",
+              true,
+              true,
+              window,
+              0,
+              event.ctrlKey,
+              event.altKey,
+              event.shiftKey,
+              event.metaKey,
+              null
+            );
+            this.currentItem.dispatchEvent(evt);
+          }
         }
       });
 
       this.addEventListener("click", event => {
         if (
           event.button != 0 ||
           event.target.classList.contains("attachmentItem")
         ) {
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -808,20 +808,17 @@ var defaultController = {
       },
     },
 
     cmd_toggleAttachmentPane: {
       isEnabled() {
         return !gWindowLocked;
       },
       doCommand() {
-        // Here we pick up the inbuilt command event, to check modifiers later.
-        // Note: We cannot pass event along the call chain: Bug 461578 / 959494.
-        // eslint-disable-next-line no-restricted-globals
-        toggleAttachmentPane("toggle", event);
+        toggleAttachmentPane();
       },
     },
 
     cmd_reorderAttachments: {
       isEnabled() {
         if (attachmentsCount() == 0) {
           let reorderAttachmentsPanel = document.getElementById(
             "reorderAttachmentsPanel"
@@ -5906,33 +5903,30 @@ function UpdateAttachmentBucket(aShowBuc
  * and tooltip of attachment pane, then (optionally) show or hide the pane.
  *
  * @param aShowPane {string} "show":  show the attachment pane
  *                           "hide":  hide the attachment pane
  *                           omitted: just update without changing pane visibility
  */
 function updateAttachmentPane(aShowPane) {
   let bucket = GetMsgAttachmentElement();
+  let bucketCountLabel = document.getElementById("attachmentBucketCount");
+  let words = getComposeBundle().getString("attachmentCount");
   let count = bucket.itemCount;
-
-  document.l10n.setAttributes(
-    document.getElementById("attachmentBucketCount"),
-    "attachment-bucket-count",
-    { count }
-  );
-
+  let countStr = PluralForm.get(count, words).replace("#1", count);
+
+  bucketCountLabel.value = countStr;
   document.getElementById("attachmentBucketSize").value =
     count > 0 ? gMessenger.formatFileSize(gAttachmentsSize) : "";
   document.getElementById("attachmentBucketCloseButton").collapsed = count > 0;
 
-  document.l10n.setAttributes(
-    document.getElementById("attachments-placeholder-box"),
-    "attachments-placeholder-tooltip",
-    { count }
-  );
+  let placeholderTooltip = count > 0 ? countStr : "";
+  document
+    .getElementById("attachments-placeholder-box")
+    .setAttribute("tooltiptext", placeholderTooltip);
 
   attachmentBucketUpdateTooltips();
 
   // If aShowPane argument is omitted, it's just updating, so we're done.
   if (aShowPane === undefined) {
     return;
   }
 
@@ -6046,16 +6040,23 @@ function RenameSelectedAttachment() {
 
     gContentChanged = true;
 
     let event = document.createEvent("CustomEvent");
     event.initCustomEvent("attachment-renamed", true, true, originalName);
     item.dispatchEvent(event);
   }
 
+  let reorderAttachmentsPanel = document.getElementById(
+    "reorderAttachmentsPanel"
+  );
+  if (reorderAttachmentsPanel.state == "open") {
+    // Hack to ensure that reorderAttachmentsPanel does not get closed as we exit.
+    bucket.setAttribute("data-ignorenextblur", "true");
+  }
   // Update cmd_sortAttachmentsToggle because renaming may change the current
   // sort order.
   goUpdateCommand("cmd_sortAttachmentsToggle");
 }
 
 /* eslint-disable complexity */
 /**
  * Move selected attachment(s) within the attachment list.
@@ -6305,78 +6306,54 @@ function moveSelectedAttachments(aDirect
   updateReorderAttachmentsItems();
 }
 /* eslint-enable complexity */
 
 /**
  * Toggle attachment pane view state: show or hide it.
  * If aAction parameter is omitted, toggle current view state.
  *
- * @param {string} [aAction = "toggle"] - "show":   show attachment pane
- *                                        "hide":   hide attachment pane
- *                                        "toggle": toggle attachment pane
- * @param {Event} [event] - The command event (cmd_toggleAttachmentPane)
+ * @param aAction {string} "show":   show attachment pane
+ *                         "hide":   hide attachment pane
+ *                         "toggle": toggle attachment pane visibility
  */
-function toggleAttachmentPane(aAction = "toggle", event) {
+function toggleAttachmentPane(aAction = "toggle") {
   let bucket = GetMsgAttachmentElement();
   let attachmentsBox = document.getElementById("attachments-box");
   let attachmentBucketSizer = document.getElementById("attachmentbucket-sizer");
-  let bucketHasFocus = document.activeElement == bucket;
 
   if (aAction == "toggle") {
-    let shown = !attachmentsBox.collapsed;
-
-    if (shown && !bucketHasFocus && event && event.altKey) {
-      // If attachment pane is shown but not focused, and we're here via
-      // key_toggleAttachmentPane, handle access key here: Focus bucket.
-      bucket.focus();
-      if (bucket.currentItem) {
-        bucket.ensureElementIsVisible(bucket.currentItem);
-      }
-      return;
-    }
-
-    // Toggle attachment pane.
-    aAction = shown ? "hide" : "show";
+    aAction = attachmentsBox.collapsed ? "show" : "hide";
   }
 
   switch (aAction) {
     case "show": {
+      let shown = !attachmentsBox.collapsed;
       attachmentsBox.collapsed = false;
       attachmentBucketSizer.collapsed = false;
       attachmentBucketSizer.setAttribute("state", "");
-      if (!bucketHasFocus) {
+      if (shown) {
         bucket.focus();
       }
-      if (bucket.currentItem) {
-        bucket.ensureElementIsVisible(bucket.currentItem);
-      }
       break;
     }
 
     case "hide": {
-      if (bucketHasFocus) {
+      if (document.activeElement == bucket) {
         SetMsgBodyFrameFocus();
       }
       attachmentsBox.collapsed = true;
       attachmentBucketSizer.setAttribute("state", "collapsed");
       break;
     }
   }
-
-  // Update the checkmark on menuitems hooked up with cmd_toggleAttachmentPane.
-  // Menuitem does not have .checked property nor .toggleAttribute(), sigh.
   for (let menuitem of document.querySelectorAll(
     'menuitem[command="cmd_toggleAttachmentPane"]'
   )) {
-    if (aAction == "show") {
-      menuitem.setAttribute("checked", "true");
-    } else {
-      menuitem.removeAttribute("checked");
-    }
+    menuitem.checked = aAction == "show";
   }
 }
 
 function showReorderAttachmentsPanel() {
   // Ensure attachment pane visibility as it might be collapsed.
   toggleAttachmentPane("show");
   showPopupById(
     "reorderAttachmentsPanel",
@@ -6511,34 +6488,32 @@ function attachmentHeaderContextOnPopupS
 
 function toggleInitiallyShowAttachmentPane(aMenuItem) {
   Services.prefs.setBoolPref(
     "mail.compose.show_attachment_pane",
     aMenuItem.getAttribute("checked")
   );
 }
 
-/**
- * Handle blur event on attachment pane. Deselect all attachments if appropriate
- * and control visibility of reorderAttachmentsPanel.
- */
 function attachmentBucketOnBlur() {
+  // Ensure that reorderAttachmentsPanel remains open while we're focused
+  // on attachmentBucket or the panel, otherwise hide it.
   let attachmentBucket = document.getElementById("attachmentBucket");
+  if (attachmentBucket.getAttribute("data-ignorenextblur") == "true") {
+    // Hack to prevent the panel from hiding after RenameSelectedAttachment()
+    attachmentBucket.setAttribute("data-ignorenextblur", "false");
+    return;
+  }
   let reorderAttachmentsPanel = document.getElementById(
     "reorderAttachmentsPanel"
   );
-  // If attachment pane has really lost focus, and if reorderAttachmentsPanel is
-  // not currently in the process of showing up, deselect attachments and hide
-  // reorderAttachmentsPanel. Otherwise, keep attachments selected and the
-  // reorderAttachmentsPanel open when reordering and after renaming via dialog.
   if (
-    document.activeElement.id != "attachmentBucket" &&
-    reorderAttachmentsPanel.state != "showing"
+    document.activeElement.id != "attachmentBucket" ||
+    document.activeElement.id != "reorderAttachmentsPanel"
   ) {
-    attachmentBucket.clearSelection();
     reorderAttachmentsPanel.hidePopup();
   }
 }
 
 function attachmentBucketOnKeyPress(aEvent) {
   let bucket = GetMsgAttachmentElement();
 
   // When ESC is pressed ...
--- a/mail/components/compose/content/messengercompose.xhtml
+++ b/mail/components/compose/content/messengercompose.xhtml
@@ -414,24 +414,27 @@
   <key id="pastequotationkb" key="&pasteAsQuotationCmd.key;"
        observes="cmd_pasteQuote" modifiers="accel, shift"/>
   <key id="pastenoformattingkb" key="&pasteNoFormattingCmd.key;"
        modifiers="accel, shift" observes="cmd_pasteNoFormatting"/>
   <key id="key_rewrap" key="&editRewrapCmd.key;" command="cmd_rewrap" modifiers="accel"/>
 #ifdef XP_MACOSX
   <key id="key_delete" keycode="VK_BACK" command="cmd_delete"/>
   <key id="key_delete2" keycode="VK_DELETE" command="cmd_delete"/>
+  <key id="key_toggleAttachmentPane"
+       key="&toggleAttachmentPaneCmd.key;" modifiers="control"
+       command="cmd_toggleAttachmentPane"/>
 #else
   <key id="key_delete" keycode="VK_DELETE" command="cmd_delete"/>
   <key id="key_renameAttachment" keycode="VK_F2"
        command="cmd_renameAttachment"/>
+  <key id="key_toggleAttachmentPane"
+       key="&toggleAttachmentPaneCmd.key;" modifiers="alt"
+       command="cmd_toggleAttachmentPane"/>
 #endif
-  <key id="key_toggleAttachmentPane"
-       data-l10n-id="key-toggle-attachment-pane" modifiers="alt"
-       command="cmd_toggleAttachmentPane"/>
   <key id="key_reorderAttachments"
        key="&reorderAttachmentsCmd.key;" modifiers="accel,shift"
        command="cmd_reorderAttachments"/>
   <key id="key_selectAll" data-l10n-id="text-action-select-all-shortcut" modifiers="accel"/>
   <key id="key_find" key="&findBarCmd.key;" command="cmd_find" modifiers="accel"/>
 #ifndef XP_MACOSX
   <key id="key_findReplace" key="&findReplaceCmd.key;" command="cmd_findReplace" modifiers="accel"/>
 #endif
@@ -2450,16 +2453,21 @@
                        role="listbox"
                        context="msgComposeAttachmentListContext"
                        itemcontext="msgComposeAttachmentItemContext"
                        onclick="attachmentBucketOnClick(event);"
                        onkeypress="attachmentBucketOnKeyPress(event);"
                        onselect="attachmentBucketOnSelect();"
                        ondragstart="attachmentBucketDNDObserver.onDragStart(event);"
                        onblur="attachmentBucketOnBlur();"/>
+          <hbox pack="end">
+            <button label="&attachFile.label;"
+                    accesskey="&attachFile.accesskey;"
+                    command="cmd_attachFile"/>
+          </hbox>
         </vbox>
         <vbox id="attachments-placeholder-box"
               hidden="true"
               tooltiptext=""
               onclick="goDoCommand('cmd_toggleAttachmentPane')"/>
       </hbox>
     </toolbar>
 
--- a/mail/locales/en-US/chrome/messenger/messengercompose/composeMsgs.properties
+++ b/mail/locales/en-US/chrome/messenger/messengercompose/composeMsgs.properties
@@ -180,16 +180,21 @@ attachPageDlogTitle=Please specify a loc
 attachPageDlogMessage=Web Page (URL):
 
 ## String used for attachment pretty name, when the attachment is a message
 messageAttachmentSafeName=Attached Message
 
 ## String used for attachment pretty name, when the attachment is a message part
 partAttachmentSafeName=Attached Message Part
 
+# LOCALIZATION NOTE (attachmentCount): Semi-colon list of plural forms.
+# See: https://developer.mozilla.org/en/Localization_and_Plurals
+# #1 number of attachments
+attachmentCount=#1 attachment;#1 attachments
+
 # LOCALIZATION NOTE (attachmentBucketAttachFilesTooltip):
 # This tooltip should be same as attachFile.label in messengercompose.dtd,
 # but without ellipsis (…).
 attachmentBucketAttachFilesTooltip=Attach File(s)
 attachmentBucketClearSelectionTooltip=Clear Selection
 attachmentBucketHeaderShowTooltip=Show attachment pane
 attachmentBucketHeaderMinimizeTooltip=Minimize attachment pane
 attachmentBucketHeaderRestoreTooltip=Restore attachment pane
--- a/mail/locales/en-US/chrome/messenger/messengercompose/messengercompose.dtd
+++ b/mail/locales/en-US/chrome/messenger/messengercompose/messengercompose.dtd
@@ -79,16 +79,17 @@
 <!ENTITY editRewrapCmd.key "R">
 <!ENTITY renameAttachmentCmd.label "Rename Attachment…">
 <!ENTITY renameAttachmentCmd.accesskey "e">
 <!ENTITY reorderAttachmentsCmd.label "Reorder Attachments…">
 <!ENTITY reorderAttachmentsCmd.accesskey "s">
 <!ENTITY reorderAttachmentsCmd.key "x">
 <!ENTITY toggleAttachmentPaneCmd.label "Attachment Pane">
 <!ENTITY toggleAttachmentPaneCmd.accesskey "m">
+<!ENTITY toggleAttachmentPaneCmd.key "M">
 <!ENTITY selectAllCmd.accesskey "a">
 <!ENTITY findBarCmd.label "Find…">
 <!ENTITY findBarCmd.accesskey "F">
 <!ENTITY findBarCmd.key "F">
 <!ENTITY findReplaceCmd.label "Find and Replace…">
 <!ENTITY findReplaceCmd.accesskey "l">
 <!ENTITY findReplaceCmd.key "H">
 <!ENTITY findAgainCmd.label "Find Again">
@@ -248,16 +249,17 @@
 <!ENTITY toAddr2.label "To">
 <!ENTITY ccAddr2.label "Cc">
 <!ENTITY bccAddr2.label "Bcc">
 <!ENTITY replyAddr2.label "Reply-To">
 <!ENTITY newsgroupsAddr2.label "Newsgroup">
 <!ENTITY followupAddr2.label "Followup-To">
 <!ENTITY subject2.label "Subject">
 <!ENTITY subject.accesskey "S">
+<!ENTITY attachmentBucketHeader.tooltip "Attachment Pane">
 <!ENTITY attachmentBucketCloseButton.tooltip "Hide the attachment pane">
 
 <!-- Format Toolbar, imported from editorAppShell.xhtml -->
 <!ENTITY SmileButton.tooltip "Insert a smiley face">
 <!ENTITY smiley1Cmd.label "Smile">
 <!ENTITY smiley2Cmd.label "Frown">
 <!ENTITY smiley3Cmd.label "Wink">
 <!ENTITY smiley4Cmd.label "Tongue-out">
--- a/mail/locales/en-US/messenger/messengercompose/messengercompose.ftl
+++ b/mail/locales/en-US/messenger/messengercompose/messengercompose.ftl
@@ -32,27 +32,8 @@ pill-action-move-to =
 
 pill-action-move-cc =
     .label = Move to Cc
     .accesskey = C
 
 pill-action-move-bcc =
     .label = Move to Bcc
     .accesskey = B
-
-#   $count (Number) - the number of attachments in the attachment bucket
-attachment-bucket-count =
-    .value = { $count ->
-        [1]      { $count } Attachment
-        *[other] { $count } Attachments
-    }
-    .accesskey = m
-
-#   $count (Number) - the number of attachments in the attachment bucket
-attachments-placeholder-tooltip =
-    .tooltiptext = { $count ->
-        [1]      { $count } Attachment
-        *[other] { $count } Attachments
-    }
-
-#   { attachment-bucket-count.accesskey } - Do not localize this message.
-key-toggle-attachment-pane =
-    .key = { attachment-bucket-count.accesskey }