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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Rob Wu 2018-08-29 22:00:32 +00:00
parent 23c68929d3
commit 5fec51b0d0
3 changed files with 9 additions and 2 deletions

View File

@ -838,7 +838,7 @@ 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;
@ -861,6 +861,11 @@ nsTextBoxFrame::UpdateAccessTitle()
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)) {

View File

@ -1061,7 +1061,7 @@ LoginManagerPrompter.prototype = {
// 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 =

View File

@ -137,6 +137,8 @@
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";