Bug 750528 - Use accessibility.accessfu to enable or disable accessfu. r=davidb
authorEitan Isaacson <eitan@monotonous.org>
Thu, 03 May 2012 19:28:35 -0700
changeset 93101 7972b92116b081674c57e8a1b3cd72a86cffc6d0
parent 93100 2b95bc1a64a7b15f2951b7998e07ade758c6d19d
child 93102 e2f1d7d2a01170da1ee0b9469a9a9aa50e715824
push id8973
push usereisaacson@mozilla.com
push dateFri, 04 May 2012 02:28:44 +0000
treeherdermozilla-inbound@7972b92116b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidb
bugs750528
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 750528 - Use accessibility.accessfu to enable or disable accessfu. r=davidb
accessible/src/jsat/AccessFu.jsm
--- a/accessible/src/jsat/AccessFu.jsm
+++ b/accessible/src/jsat/AccessFu.jsm
@@ -11,16 +11,20 @@ const Cr = Components.results;
 
 var EXPORTED_SYMBOLS = ['AccessFu'];
 
 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.
    * If accessibility is enabled on the platform (currently Android-only), then
    * a special accessibility mode is started (see startup()).
    * @param {ChromeWindow} aWindow Chrome window to attach to.
    * @param {boolean} aForceEnabled Skip platform accessibility check and enable
    *  AccessFu.
@@ -29,33 +33,27 @@ var AccessFu = {
     if (this.chromeWin)
       // XXX: only supports attaching to one window now.
       throw new Error('Only one window could be attached to AccessFu');
 
     dump('AccessFu attach!! ' + Services.appinfo.OS + '\n');
     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();
   },
 
   /**
    * Start the special AccessFu mode, this primarily means controlling the virtual
    * cursor with arrow keys. Currently, on platforms other than Android this needs
    * to be called explicitly.
    */
@@ -93,16 +91,38 @@ var AccessFu = {
     this.chromeWin.removeEventListener('DOMActivate', this);
     this.chromeWin.removeEventListener('resize', this);
     this.chromeWin.removeEventListener('scroll', this);
     this.chromeWin.removeEventListener('TabOpen', this);
     this.chromeWin.removeEventListener('TabSelect', this);
     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);
   },
 
   handleEvent: function handleEvent(aEvent) {
     switch (aEvent.type) {
       case 'TabSelect':
@@ -149,16 +169,24 @@ var AccessFu = {
       this._pendingDocuments[browserApp.selectedBrowser] = aCallback;
     } else {
       aCallback.apply(this, [docAcc]);
     }
   },
 
   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 {
           event = aSubject.QueryInterface(Ci.nsIAccessibleEvent);
           this.handleAccEvent(event);
         } catch (ex) {
           dump(ex);
           return;