mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 14:25:52 +00:00
string bundle utility XBL binding, implement correct Windows platform keyboard navigation for radio groups.
This commit is contained in:
parent
cbf6ecc1f7
commit
94f8efc148
@ -38,4 +38,5 @@ nsTransferable.js
|
||||
nsJSComponentManager.js
|
||||
nsUserSettings.js
|
||||
toolbarBindings.xml
|
||||
stringbundleBindings.xml
|
||||
|
||||
|
@ -71,7 +71,7 @@ CHROME_CONTENT= \
|
||||
htmlBindings.xml \
|
||||
menulistBindings.xml \
|
||||
radioBindings.xml \
|
||||
scrollbarBindings.xml \
|
||||
scrollbarBindings.xml \
|
||||
tabBindings.xml \
|
||||
treeBindings.xml \
|
||||
xulBindings.xml \
|
||||
@ -83,6 +83,7 @@ CHROME_CONTENT= \
|
||||
nsUserSettings.js \
|
||||
xul.css \
|
||||
toolbarBindings.xml \
|
||||
stringbundleBindings.xml \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
@ -63,7 +63,7 @@ CHROME_CONTENT= \
|
||||
.\htmlBindings.xml \
|
||||
.\menulistBindings.xml \
|
||||
.\radioBindings.xml \
|
||||
.\scrollbarBindings.xml \
|
||||
.\scrollbarBindings.xml \
|
||||
.\tabBindings.xml \
|
||||
.\treeBindings.xml \
|
||||
.\toolbarBindings.xml \
|
||||
@ -74,6 +74,7 @@ CHROME_CONTENT= \
|
||||
.\nsJSComponentManager.js \
|
||||
.\nsUserSettings.js \
|
||||
.\xul.css \
|
||||
.\stringbundleBindings.xml \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
@ -34,6 +34,7 @@
|
||||
<setter>
|
||||
<![CDATA[
|
||||
var aDOMElement = val;
|
||||
val.setAttribute("focused", "true");
|
||||
this.data = aDOMElement.data;
|
||||
|
||||
aDOMElement.checked = true;
|
||||
@ -45,13 +46,37 @@
|
||||
if( groupElements[i] != aDOMElement && groupElements[i].checked )
|
||||
{
|
||||
groupElements[i].checked = false;
|
||||
groupElements[i].removeAttribute( "checked" );
|
||||
groupElements[i].removeAttribute("checked");
|
||||
groupElements[i].removeAttribute("focused");
|
||||
}
|
||||
}
|
||||
return val;
|
||||
]]>
|
||||
</setter>
|
||||
</property>
|
||||
<method name="checkAdjacentElement">
|
||||
<argument name="aNextFlag"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
var radios = this.getElementsByTagName("radio");
|
||||
for (var i = 0; i < radios.length; i++ ) {
|
||||
if (radios[i] != this.selectedItem)
|
||||
continue;
|
||||
if (aNextFlag) {
|
||||
var index = i + 1 < radios.length ? i + 1 : 0;
|
||||
this.selectedItem = radios[index];
|
||||
break;
|
||||
}
|
||||
else {
|
||||
|
||||
var index = i - 1 >= 0 ? i - 1 : radios.length - 1;
|
||||
this.selectedItem = radios[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
<handlers>
|
||||
<handler event="click">
|
||||
@ -79,8 +104,39 @@
|
||||
{
|
||||
}
|
||||
]]>
|
||||
</handler>
|
||||
</handler>
|
||||
|
||||
<!-- keyboard navigation -->
|
||||
<!-- Here's how keyboard navigation works in radio groups on Windows:
|
||||
The group takes 'focus'
|
||||
The user is then free to navigate around inside the group
|
||||
using the arrow keys. Accessing previous or following radio buttons
|
||||
is done solely through the arrow keys and not the tab button. Tab
|
||||
takes you to the next widget in the tab order -->
|
||||
<handler event="keypress" keycode="VK_UP">
|
||||
this.checkAdjacentElement(false);
|
||||
</handler>
|
||||
<handler event="keypress" keycode="VK_LEFT">
|
||||
this.checkAdjacentElement(false);
|
||||
</handler>
|
||||
<handler event="keypress" keycode="VK_DOWN">
|
||||
this.checkAdjacentElement(true);
|
||||
</handler>
|
||||
<handler event="keypress" keycode="VK_RIGHT">
|
||||
this.checkAdjacentElement(true);
|
||||
</handler>
|
||||
|
||||
<!-- set a focused attribute on the selected item when the group
|
||||
receives focus so that we can style it as if it were focused even though
|
||||
it is not (Windows platform behaviour is for the group to receive focus,
|
||||
not the item -->
|
||||
<handler event="focus">
|
||||
this.selectedItem.setAttribute("focused", "true");
|
||||
</handler>
|
||||
<handler event="blur">
|
||||
this.selectedItem.removeAttribute("focused");
|
||||
</handler>
|
||||
</handlers>
|
||||
</binding>
|
||||
|
||||
|
||||
</bindings>
|
||||
|
74
xpfe/global/resources/content/stringbundleBindings.xml
Normal file
74
xpfe/global/resources/content/stringbundleBindings.xml
Normal file
@ -0,0 +1,74 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<bindings id="stringBundleBindings"
|
||||
xmlns="http://www.mozilla.org/xbl"
|
||||
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<binding id="stringbundle" extends="xul:spring">
|
||||
<implementation name="XStringBundle">
|
||||
|
||||
<method name="getString">
|
||||
<argument name="aStringKey"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
try {
|
||||
return this._bundle.GetStringFromName(aStringKey);
|
||||
}
|
||||
catch (e) {
|
||||
dump("<StringBundle> Error: Failed to get string from bundle. Are you using the right key?\n");
|
||||
dump("The key you provided was: " + aStringKey + "\n");
|
||||
dump("The exception thrown was:\n" + e + "\n");
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<property name="stringBundle">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
return this._bundle;
|
||||
]]>
|
||||
</getter>
|
||||
<setter>
|
||||
<![CDATA[
|
||||
try {
|
||||
strBundleService = Components.classes["component://netscape/intl/stringbundle"].getService();
|
||||
strBundleService = strBundleService.QueryInterface(Components.interfaces.nsIStringBundleService);
|
||||
}
|
||||
catch (ex) {
|
||||
return null;
|
||||
}
|
||||
this._bundle = strBundleService.CreateBundle(val, this.appLocale);
|
||||
]]>
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
<property name="appLocale">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
var applicationLocale = null;
|
||||
try {
|
||||
localeService = Components.classes["component://netscape/intl/nslocaleservice"].getService();
|
||||
localeService = localeService.QueryInterface(Components.interfaces.nsILocaleService);
|
||||
}
|
||||
catch (ex) {
|
||||
return null;
|
||||
}
|
||||
applicationLocale = localeService.GetApplicationLocale();
|
||||
return applicationLocale;
|
||||
]]>
|
||||
</getter>
|
||||
</property>
|
||||
|
||||
<property name="_bundle"/>
|
||||
</implementation>
|
||||
<handlers>
|
||||
<handler event="bindingattached">
|
||||
<![CDATA[
|
||||
this.stringBundle = this.getAttribute("src");
|
||||
]]>
|
||||
</handler>
|
||||
</handlers>
|
||||
</binding>
|
||||
|
||||
</bindings>
|
@ -351,11 +351,13 @@ checkbox {
|
||||
radio
|
||||
{
|
||||
behavior : url(chrome://global/content/radioBindings.xml#radio);
|
||||
user-focus : none;
|
||||
}
|
||||
|
||||
radiogroup
|
||||
{
|
||||
behavior : url(chrome://global/content/radioBindings.xml#radiogroup);
|
||||
user-focus : normal;
|
||||
}
|
||||
|
||||
button, button.left {
|
||||
@ -625,3 +627,12 @@ address {
|
||||
behavior : url("chrome://global/content/addressingBindings.xml#address");
|
||||
}
|
||||
*/
|
||||
|
||||
stringbundle
|
||||
{
|
||||
behavior : url("chrome://global/content/stringbundleBindings.xml#stringbundle");
|
||||
visibility : collapse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user