[XForms] Move accesskey label into xhtml implementation. Bug 327998, r=doronr+me, patch by surkov@dc.baikal.ru

This commit is contained in:
allan%beaufour.dk 2006-02-23 11:34:01 +00:00
Родитель 32a42eb82c
Коммит 8240c1aa76
3 изменённых файлов: 84 добавлений и 84 удалений

Просмотреть файл

@ -50,11 +50,10 @@
%xformsDTD;
]>
<bindings id="xformsBindings"
<bindings id="xformsBindingsForXHTML"
xmlns="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xforms="http://www.w3.org/2002/xforms">
xmlns:xbl="http://www.mozilla.org/xbl">
<!-- OUTPUT: <DEFAULT> -->
@ -126,6 +125,79 @@
</binding>
<!-- LABEL: <ACCESKEY SUPPORT> -->
<binding id="xformswidget-label-accesskey"
extends="chrome://xforms/content/xforms.xml#xformswidget-label-base">
<content>
<html:span anonid="implicitcontent"/>
<html:span anonid="explicitcontent"><children/></html:span>
</content>
<implementation>
<method name="getControlElement">
<body>
<![CDATA[
return {
_labelControl: this,
_implicitContent: this.ownerDocument.
getAnonymousElementByAttribute(this, "anonid", 'implicitcontent'),
_explicitContent: this.ownerDocument.
getAnonymousElementByAttribute(this, 'anonid', 'explicitcontent'),
_ownerDocument: this.ownerDocument,
set value(val) {
var textnode = null;
if (val != null) {
this._implicitContent.textContent = val;
this._explicitContent.style.display = 'none';
textnode = this._implicitContent.firstChild;
} else {
this._implicitContent.textContent = '';
this._explicitContent.style.display = 'inline';
for (var node = this._labelControl.firstChild; node; node = node.nextSibling) {
// XXX: if label has element node children, we skip accesskey
// underlining.
if (node.nodeType == Node.ELEMENT_NODE)
return;
}
textnode = this._labelControl.firstChild;
}
var accesskey = this._labelControl.parentNode.getAttribute("accesskey");
if (accesskey.length == 1 && textnode) {
this.setAccesskeyOnNode(accesskey, textnode);
}
},
setAccesskeyOnNode: function(aAccesskey, aTextNode) {
var text = aTextNode.nodeValue;
var location = text.indexOf(aAccesskey);
if (location > -1) {
// we create a range around the character we want and surround
// it with an <html:u>
var range = this._ownerDocument.createRange();
range.setStart(aTextNode, location);
range.setEnd(aTextNode, location + 1);
var u = this._ownerDocument.
createElementNS("http://www.w3.org/1999/xhtml", "u");
range.surroundContents(u);
} else {
// if we didn't find the accesskey, append it to the end
aTextNode.nodeValue += "(" + aAccesskey + ")";
}
}
};
]]>
</body>
</method>
</implementation>
</binding>
<!-- TRIGGER: <DEFAULT> -->
<binding id="xformswidget-trigger"
extends="chrome://xforms/content/xforms.xml#xformswidget-trigger-base">

Просмотреть файл

@ -270,15 +270,15 @@ xul|*:root trigger[appearance="minimal"][disabled]:hover:active {
color: GrayText !important;
}
input > label,
secret > label,
textarea > label,
trigger > label,
submit > label,
select > label,
select1 > label,
upload > label {
-moz-binding: url('chrome://xforms/content/xforms.xml#xformswidget-label-accesskey');
html|*:root input > label,
html|*:root secret > label,
html|*:root textarea > label,
html|*:root trigger > label,
html|*:root submit > label,
html|*:root select > label,
html|*:root select1 > label,
html|*:root upload > label {
-moz-binding: url('chrome://xforms/content/xforms-xhtml.xml#xformswidget-label-accesskey');
}
html|*:root label {

Просмотреть файл

@ -233,78 +233,6 @@
</binding>
<!-- LABEL: <ACCESKEY SUPPORT>
XXX: The widget doesn't support interface based on getElementControl()
method (see a bug https://bugzilla.mozilla.org/show_bug.cgi?id=323845).
-->
<binding id="xformswidget-label-accesskey"
extends="chrome://xforms/content/xforms.xml#xformswidget-base">
<content>
<html:span anonid="content"></html:span>
<html:span anonid="anoncontent" style="display:none;">
<children/>
</html:span>
</content>
<implementation implements="nsIXFormsUIWidget">
<method name="refresh">
<body>
<![CDATA[
// we cannot access the <children/> content in XBL1, so we switch to
// always cloning the content into the content span.
var content =
document.getAnonymousElementByAttribute(this, "anonid", "content");
var hasElementChildren = false;
var hasBoundValue = false;
if (this.accessors.hasBoundNode() || this.accessors.getValue() != null) {
content.textContent = this.stringValue;
hasBoundValue = true;
} else {
// clone the contents child by child
var node;
for (var i = 0; i < this.childNodes.length; i++) {
if (!hasElementChildren && this.childNodes[i].nodeType == Node.ELEMENT_NODE)
hasElementChildren = true;
content.appendChild(this.childNodes[i].cloneNode(true));
}
}
// XXX: if label has element node children, we skip accesskey underlining
if (!hasElementChildren && this.parentNode.hasAttribute("accesskey")) {
var accesskey = this.parentNode.getAttribute("accesskey");
// bail if no accesskey or accesskey is longer than 1 character
if (!accesskey || accesskey.length != 1)
return true;
var str = content.textContent;
var location = str.indexOf(accesskey);
if (location > -1) {
// we create a range around the character we want and surround it
// with an <html:u>
var range = document.createRange();
range.setStart(content.firstChild, location);
range.setEnd(content.firstChild, location+1);
var u = document.createElementNS("http://www.w3.org/1999/xhtml", "u");
range.surroundContents(u);
} else {
// if we didn't find the accesskey, append it to the end
content.textContent += "(" + accesskey + ")";
}
}
return true;
]]>
</body>
</method>
</implementation>
</binding>
<!-- TRIGGER: <DEFAULT>
The trigger widget assumes successors bindings implement getElementControl()
method what returns the object: