From 0686b4ca6ca5d038490f50405c0401320b216ba2 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Thu, 3 May 2012 19:28:35 -0700 Subject: [PATCH] Bug 750528 - Use accessibility.accessfu to enable or disable accessfu. r=davidb --- accessible/src/jsat/AccessFu.jsm | 58 +++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/accessible/src/jsat/AccessFu.jsm b/accessible/src/jsat/AccessFu.jsm index 1d29f5db0bb6..bfe451ff1f80 100644 --- a/accessible/src/jsat/AccessFu.jsm +++ b/accessible/src/jsat/AccessFu.jsm @@ -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 {