Bug 1484914 - Never append duplicate access key hints r=bzbarsky
authorRob Wu <rob@robwu.nl>
Wed, 29 Aug 2018 22:00:32 +0000
changeset 434042 964610ef7e3f6f715a0422879a5da67765233407
parent 434041 9de4c7559795d4d6d89c3d223dfa73297af3934a
child 434043 7d47dca5962e1dc0b3426814885f9a5bd27afb07
push id68521
push userrob@robwu.nl
push dateThu, 30 Aug 2018 09:22:17 +0000
treeherderautoland@964610ef7e3f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1484914
milestone63.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 1484914 - Never append duplicate access key hints r=bzbarsky On macOS, access keys are not visually observable. On Linux and Windows, access keys are underlined. Moreover, if intl.menuitems.alwaysappendaccesskeys is set, the access key is always appended as "(X)", optionally preceded by a space, where X is the uppercased version of the access key. This commit updates the logic to not append a new "(X)" if this expected suffix is already present at the end of the label. Differential Revision: https://phabricator.services.mozilla.com/D3996
layout/xul/nsTextBoxFrame.cpp
toolkit/components/passwordmgr/nsLoginManagerPrompter.js
toolkit/content/widgets/text.xml
--- a/layout/xul/nsTextBoxFrame.cpp
+++ b/layout/xul/nsTextBoxFrame.cpp
@@ -833,17 +833,17 @@ nsTextBoxFrame::CalculateTitleForWidth(g
 // the following block is to append the accesskey to mTitle if there is an accesskey
 // but the mTitle doesn't have the character
 void
 nsTextBoxFrame::UpdateAccessTitle()
 {
     /*
      * Note that if you change appending access key label spec,
      * you need to maintain same logic in following methods. See bug 324159.
-     * toolkit/content/commonDialog.js (setLabelForNode)
+     * toolkit/components/prompts/src/CommonDialog.jsm (setLabelForNode)
      * toolkit/content/widgets/text.xml (formatAccessKey)
      */
     int32_t menuAccessKey;
     nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
     if (!menuAccessKey || mAccessKey.IsEmpty())
         return;
 
     if (!AlwaysAppendAccessKey() &&
@@ -856,16 +856,21 @@ nsTextBoxFrame::UpdateAccessTitle()
     ToUpperCase(accessKeyLabel);
     accessKeyLabel += ')';
 
     if (mTitle.IsEmpty()) {
         mTitle = accessKeyLabel;
         return;
     }
 
+    if (StringEndsWith(mTitle, accessKeyLabel)) {
+      // Never append another "(X)" if the title already ends with "(X)".
+      return;
+    }
+
     const nsDependentString& kEllipsis = nsContentUtils::GetLocalizedEllipsis();
     uint32_t offset = mTitle.Length();
     if (StringEndsWith(mTitle, kEllipsis)) {
         offset -= kEllipsis.Length();
     } else if (StringEndsWith(mTitle, OLD_ELLIPSIS)) {
         // Try to check with our old ellipsis (for old addons)
         offset -= OLD_ELLIPSIS.Length();
     } else {
--- a/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
+++ b/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
@@ -1056,17 +1056,17 @@ LoginManagerPrompter.prototype = {
    *        A notification box or a popup notification.
    * @param aLogin
    *        The login captured from the form.
    */
   _showSaveLoginNotification(aNotifyObj, aLogin) {
     // Ugh. We can't use the strings from the popup window, because they
     // have the access key marked in the string (eg "Mo&zilla"), along
     // with some weird rules for handling access keys that do not occur
-    // in the string, for L10N. See commonDialog.js's setLabelForNode().
+    // in the string, for L10N. See CommonDialog.jsm's setLabelForNode().
     var neverButtonText =
           this._getLocalizedString("notifyBarNeverRememberButtonText2");
     var neverButtonAccessKey =
           this._getLocalizedString("notifyBarNeverRememberButtonAccessKey2");
     var rememberButtonText =
           this._getLocalizedString("notifyBarRememberPasswordButtonText");
     var rememberButtonAccessKey =
           this._getLocalizedString("notifyBarRememberPasswordButtonAccessKey");
--- a/toolkit/content/widgets/text.xml
+++ b/toolkit/content/widgets/text.xml
@@ -132,16 +132,18 @@
             }
             var accessKeyIndex = -1;
             if (!this.mAlwaysAppendAccessKey) {
               accessKeyIndex = labelText.indexOf(accessKey);
               if (accessKeyIndex < 0) { // Try again in upper case
                 accessKeyIndex =
                   labelText.toUpperCase().indexOf(accessKey.toUpperCase());
               }
+            } else if (labelText.endsWith(`(${accessKey.toUpperCase()})`)) {
+              accessKeyIndex = labelText.length - (1 + accessKey.length); // = index of accessKey.
             }
 
             const HTML_NS = "http://www.w3.org/1999/xhtml";
             var span = document.createElementNS(HTML_NS, "span");
             span.className = "accesskey";
 
             // Note that if you change the following code, see the comment of
             // nsTextBoxFrame::UpdateAccessTitle.