gecko-dev/toolkit/content/widgets/text.xml

208 lines
7.8 KiB
XML

<?xml version="1.0"?>
<bindings id="textBindings"
xmlns="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml">
<!-- bound to <description>s -->
<binding id="text-base">
<implementation implements="nsIDOMXULDescriptionElement, nsIAccessibleProvider">
<property name="accessible">
<getter>
<![CDATA[
var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
return accService.createXULTextAccessible(this);
]]>
</getter>
</property>
<property name="disabled" onget="return this.hasAttribute('disabled');"
onset="if (val) this.setAttribute('disabled', 'true');
else this.removeAttribute('disabled');
return val;"/>
<property name="value" onget="return this.getAttribute('value');"
onset="this.setAttribute('value', val); return val;"/>
<property name="crop" onget="return this.getAttribute('crop');"
onset="this.setAttribute('crop', val); return val;"/>
</implementation>
</binding>
<binding id="text-label" extends="chrome://global/content/bindings/text.xml#text-base">
<implementation implements="nsIDOMXULLabelElement">
<property name="accessKey">
<getter>
<![CDATA[
var accessKey = this.getAttribute('accesskey');
return accessKey ? accessKey[0] : null;
]]>
</getter>
<setter>
<![CDATA[
this.setAttribute('accesskey', val);
return val;
]]>
</setter>
</property>
<property name="control" onget="return getAttribute('control');">
<setter>
<![CDATA[
// After this gets set, the label will use the binding #label-control
this.setAttribute('control', val);
return val;
]]>
</setter>
</property>
</implementation>
</binding>
<binding id="label-control" extends="chrome://global/content/bindings/text.xml#text-label">
<content>
<html:span anonid="accessKeyParens"><children/></html:span>
</content>
<implementation implements="nsIDOMXULLabelElement">
<constructor>
<![CDATA[
this.formatAccessKey();
]]>
</constructor>
<method name="formatAccessKey">
<body>
<![CDATA[
var control = this.labeledControlElement;
if (!control) {
var bindingParent = document.getBindingParent(this);
if (bindingParent instanceof Components.interfaces.nsIDOMXULLabeledControlElement) {
control = bindingParent; // For controls that make the <label> an anon child
}
}
if (control) {
control.labelElement = this;
}
var afterLabel = document.getAnonymousElementByAttribute(this, "anonid", "accessKeyParens");
afterLabel.textContent = ""; // This does not clear real nodes!
var oldAccessKey = this.getElementsByAttribute('class', 'accesskey').item(0);
if (oldAccessKey) { // Clear old accesskey
if (oldAccessKey.previousSibling instanceof Text) {
oldAccessKey.previousSibling.appendData(oldAccessKey.textContent)
}
else {
oldAccessKey.parentNode.insertBefore(oldAccessKey.firstChild, oldAccessKey);
}
oldAccessKey.parentNode.removeChild(oldAccessKey);
}
var accessKey = this.accessKey;
var labelText = this.textContent;
if (!accessKey || !labelText || !control) {
return;
}
var accessKeyIndex = labelText.indexOf(accessKey);
if (accessKeyIndex < 0) { // Try again in upper case
accessKeyIndex = labelText.toUpperCase().indexOf(accessKey.toUpperCase());
}
var span = document.createElementNS("http://www.w3.org/1999/xhtml", "span");
span.className = "accesskey";
if (accessKeyIndex < 0) {
// If accesskey is not in string, append in parentheses
afterLabel.textContent = " (";
span.textContent = accessKey.toUpperCase();
afterLabel.appendChild(span);
afterLabel.appendChild(document.createTextNode(")"));
return;
}
var treeWalker = document.createTreeWalker(this, NodeFilter.SHOW_TEXT, null, true);
var accessKeyNode = treeWalker.nextNode();
while (accessKeyIndex >= accessKeyNode.length) {
accessKeyIndex -= accessKeyNode.length;
accessKeyNode = treeWalker.nextNode();
}
// Now wrap the access key in a <span class="accesskey"/>
if (accessKeyIndex) {
accessKeyNode = accessKeyNode.splitText(accessKeyIndex); // returns 2nd node from split
}
accessKeyNode.parentNode.insertBefore(span, accessKeyNode);
if (accessKeyNode.length > 1) {
accessKeyNode.splitText(1);
}
span.appendChild(accessKeyNode);
]]>
</body>
</method>
<property name="accessKey">
<getter>
<![CDATA[
var accessKey = null;
var labeledEl = this.labeledControlElement;
if (labeledEl) {
accessKey = labeledEl.getAttribute('accesskey');
}
if (!accessKey) {
accessKey = this.getAttribute('accesskey');
}
return accessKey ? accessKey[0] : null;
]]>
</getter>
<setter>
<![CDATA[
// If this label already has an accesskey attribute store it here as well
if (this.hasAttribute('accesskey')) {
this.setAttribute('accesskey', val);
}
var control = this.labeledControlElement;
if (control) {
control.setAttribute('accesskey', val);
}
this.formatAccessKey();
return val;
]]>
</setter>
</property>
<property name="labeledControlElement" readonly="true"
onget="var control = this.control; return control ? document.getElementById(control) : null;" />
<property name="control" onget="return this.getAttribute('control');">
<setter>
<![CDATA[
var control = this.labeledControlElement;
if (control) {
control.labelElement = null; // No longer pointed to be this label
}
this.setAttribute('control', val);
this.formatAccessKey();
return val;
]]>
</setter>
</property>
</implementation>
<handlers>
<handler event="click" action="if (this.disabled) return;
var controlElementID = this.getAttribute('control');
var controlElement;
if (controlElementID)
controlElement = document.getElementById(controlElementID);
if(controlElement)
controlElement.focus();
"/>
</handlers>
</binding>
<binding id="text-link" extends="chrome://global/content/bindings/text.xml#text-label">
<handlers>
<handler event="keypress" keycode="VK_ENTER" action="this.click()" />
<handler event="keypress" keycode="VK_RETURN" action="this.click()" />
</handlers>
</binding>
</bindings>