michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: an anon child michael@0: } michael@0: } michael@0: if (control) { michael@0: control.labelElement = this; michael@0: } michael@0: michael@0: var accessKey = this.accessKey; michael@0: // No need to remove existing formatting the first time. michael@0: if (firstTime && !accessKey) michael@0: return; michael@0: michael@0: if (this.mInsertSeparator === undefined) { michael@0: try { michael@0: var prefs = Components.classes["@mozilla.org/preferences-service;1"]. michael@0: getService(Components.interfaces.nsIPrefBranch); michael@0: this.mUnderlineAccesskey = (prefs.getIntPref("ui.key.menuAccessKey") != 0); michael@0: michael@0: const nsIPrefLocalizedString = michael@0: Components.interfaces.nsIPrefLocalizedString; michael@0: michael@0: const prefNameInsertSeparator = michael@0: "intl.menuitems.insertseparatorbeforeaccesskeys"; michael@0: const prefNameAlwaysAppendAccessKey = michael@0: "intl.menuitems.alwaysappendaccesskeys"; michael@0: michael@0: var val = prefs.getComplexValue(prefNameInsertSeparator, michael@0: nsIPrefLocalizedString).data; michael@0: this.mInsertSeparator = (val == "true"); michael@0: michael@0: val = prefs.getComplexValue(prefNameAlwaysAppendAccessKey, michael@0: nsIPrefLocalizedString).data; michael@0: this.mAlwaysAppendAccessKey = (val == "true"); michael@0: } michael@0: catch (e) { michael@0: this.mInsertSeparator = true; michael@0: } michael@0: } michael@0: michael@0: if (!this.mUnderlineAccesskey) michael@0: return; michael@0: michael@0: var afterLabel = document.getAnonymousElementByAttribute(this, "anonid", "accessKeyParens"); michael@0: afterLabel.textContent = ""; michael@0: michael@0: var oldAccessKey = this.getElementsByAttribute('class', 'accesskey').item(0); michael@0: if (oldAccessKey) { // Clear old accesskey michael@0: this.mergeElement(oldAccessKey); michael@0: } michael@0: michael@0: var oldHiddenSpan = michael@0: this.getElementsByAttribute('class', 'hiddenColon').item(0); michael@0: if (oldHiddenSpan) { michael@0: this.mergeElement(oldHiddenSpan); michael@0: } michael@0: michael@0: var labelText = this.textContent; michael@0: if (!accessKey || !labelText || !control) { michael@0: return; michael@0: } michael@0: var accessKeyIndex = -1; michael@0: if (!this.mAlwaysAppendAccessKey) { michael@0: accessKeyIndex = labelText.indexOf(accessKey); michael@0: if (accessKeyIndex < 0) { // Try again in upper case michael@0: accessKeyIndex = michael@0: labelText.toUpperCase().indexOf(accessKey.toUpperCase()); michael@0: } michael@0: } michael@0: michael@0: const HTML_NS = "http://www.w3.org/1999/xhtml"; michael@0: var span = document.createElementNS(HTML_NS, "span"); michael@0: span.className = "accesskey"; michael@0: michael@0: // Note that if you change the following code, see the comment of michael@0: // nsTextBoxFrame::UpdateAccessTitle. michael@0: michael@0: // If accesskey is not in string, append in parentheses michael@0: if (accessKeyIndex < 0) { michael@0: // If end is colon, we should insert before colon. michael@0: // i.e., "label:" -> "label(X):" michael@0: var colonHidden = false; michael@0: if (/:$/.test(labelText)) { michael@0: labelText = labelText.slice(0, -1); michael@0: var hiddenSpan = document.createElementNS(HTML_NS, "span"); michael@0: hiddenSpan.className = "hiddenColon"; michael@0: hiddenSpan.style.display = "none"; michael@0: // Hide the last colon by using span element. michael@0: // I.e., label: michael@0: this.wrapChar(hiddenSpan, labelText.length); michael@0: colonHidden = true; michael@0: } michael@0: // If end is space(U+20), michael@0: // we should not add space before parentheses. michael@0: var endIsSpace = false; michael@0: if (/ $/.test(labelText)) { michael@0: endIsSpace = true; michael@0: } michael@0: if (this.mInsertSeparator && !endIsSpace) michael@0: afterLabel.textContent = " ("; michael@0: else michael@0: afterLabel.textContent = "("; michael@0: span.textContent = accessKey.toUpperCase(); michael@0: afterLabel.appendChild(span); michael@0: if (!colonHidden) michael@0: afterLabel.appendChild(document.createTextNode(")")); michael@0: else michael@0: afterLabel.appendChild(document.createTextNode("):")); michael@0: return; michael@0: } michael@0: this.wrapChar(span, accessKeyIndex); michael@0: ]]> michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: = node.length) { michael@0: index -= node.length; michael@0: node = treeWalker.nextNode(); michael@0: } michael@0: if (index) { michael@0: node = node.splitText(index); michael@0: } michael@0: node.parentNode.insertBefore(element, node); michael@0: if (node.length > 1) { michael@0: node.splitText(1); michael@0: } michael@0: element.appendChild(node); michael@0: ]]> michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: !/Mac/.test(navigator.platform) michael@0: michael@0: michael@0: false michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: