Bug 750528 - Use accessibility.accessfu to enable or disable accessfu. r=davidb

This commit is contained in:
Eitan Isaacson 2012-05-03 19:28:35 -07:00
Родитель 046551ffe6
Коммит 4ff1a41d96
1 изменённых файлов: 43 добавлений и 15 удалений

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

@ -16,6 +16,10 @@ Cu.import('resource://gre/modules/Services.jsm');
Cu.import('resource://gre/modules/accessibility/Presenters.jsm');
Cu.import('resource://gre/modules/accessibility/VirtualCursorController.jsm');
const ACCESSFU_DISABLE = 0;
const ACCESSFU_ENABLE = 1;
const ACCESSFU_AUTO = 2;
var AccessFu = {
/**
* Attach chrome-layer accessibility functionality to the given chrome window.
@ -34,23 +38,17 @@ var AccessFu = {
this.chromeWin = aWindow;
this.presenters = [];
function checkA11y() {
if (Services.appinfo.OS == 'Android') {
let msg = Cc['@mozilla.org/android/bridge;1'].
getService(Ci.nsIAndroidBridge).handleGeckoMessage(
JSON.stringify(
{ gecko: {
type: 'Accessibility:IsEnabled',
eventType: 1,
text: []
}
}));
return JSON.parse(msg).enabled;
}
return false;
this.prefsBranch = Cc['@mozilla.org/preferences-service;1']
.getService(Ci.nsIPrefService).getBranch('accessibility.');
this.prefsBranch.addObserver('accessfu', this, false);
let accessPref = ACCESSFU_DISABLE;
try {
accessPref = this.prefsBranch.getIntPref('accessfu');
} catch (x) {
}
if (checkA11y())
if (this.amINeeded(accessPref))
this.enable();
},
@ -98,6 +96,28 @@ var AccessFu = {
this.chromeWin.removeEventListener('TabClose', this);
},
amINeeded: function(aPref) {
switch (aPref) {
case ACCESSFU_ENABLE:
return true;
case ACCESSFU_AUTO:
if (Services.appinfo.OS == 'Android') {
let msg = Cc['@mozilla.org/android/bridge;1'].
getService(Ci.nsIAndroidBridge).handleGeckoMessage(
JSON.stringify(
{ gecko: {
type: 'Accessibility:IsEnabled',
eventType: 1,
text: []
}
}));
return JSON.parse(msg).enabled;
}
default:
return false;
}
},
addPresenter: function addPresenter(presenter) {
this.presenters.push(presenter);
presenter.attach(this.chromeWin);
@ -154,6 +174,14 @@ var AccessFu = {
observe: function observe(aSubject, aTopic, aData) {
switch (aTopic) {
case 'nsPref:changed':
if (aData == 'accessfu') {
if (this.amINeeded(this.prefsBranch.getIntPref('accessfu')))
this.enable();
else
this.disable();
}
break;
case 'accessible-event':
let event;
try {