Bug 764119 - Explore by touch preference. r=davidb
authorEitan Isaacson <eitan@monotonous.org>
Wed, 13 Jun 2012 12:22:52 -0700
changeset 96602 ad0775733110f642a7f61ae7332d42f406d1cea3
parent 96601 a90627b90bba1f7cd0440ea81af6015524cfa0c1
child 96603 363b6d52380cc8861c76e0934f99df2b5164138a
push id10628
push usereisaacson@mozilla.com
push dateWed, 13 Jun 2012 19:23:02 +0000
treeherdermozilla-inbound@ad0775733110 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidb
bugs764119
milestone16.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 764119 - Explore by touch preference. r=davidb
accessible/src/jsat/AccessFu.jsm
accessible/src/jsat/VirtualCursorController.jsm
mobile/android/app/mobile.js
--- a/accessible/src/jsat/AccessFu.jsm
+++ b/accessible/src/jsat/AccessFu.jsm
@@ -29,43 +29,41 @@ var AccessFu = {
    * @param {boolean} aForceEnabled Skip platform accessibility check and enable
    *  AccessFu.
    */
   attach: function attach(aWindow) {
     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');
+    dump('[AccessFu] attach\n');
     this.chromeWin = aWindow;
     this.presenters = [];
 
     this.prefsBranch = Cc['@mozilla.org/preferences-service;1']
       .getService(Ci.nsIPrefService).getBranch('accessibility.accessfu.');
     this.prefsBranch.addObserver('activate', this, false);
+    this.prefsBranch.addObserver('explorebytouch', this, false);
 
-    let accessPref = ACCESSFU_DISABLE;
-    try {
-      accessPref = this.prefsBranch.getIntPref('activate');
-    } catch (x) {
-    }
+    if (Services.appinfo.OS == 'Android')
+      Services.obs.addObserver(this, 'Accessibility:Settings', false);
 
-    this._processPreferences(accessPref);
+    this._processPreferences();
   },
 
   /**
    * Start AccessFu mode, this primarily means controlling the virtual cursor
    * with arrow keys.
    */
   _enable: function _enable() {
     if (this._enabled)
       return;
     this._enabled = true;
 
-    dump('AccessFu enable');
+    dump('[AccessFu] enable\n');
     this.addPresenter(new VisualPresenter());
 
     // Implicitly add the Android presenter on Android.
     if (Services.appinfo.OS == 'Android')
       this.addPresenter(new AndroidPresenter());
 
     VirtualCursorController.attach(this.chromeWin);
 
@@ -80,54 +78,63 @@ var AccessFu = {
   /**
    * Disable AccessFu and return to default interaction mode.
    */
   _disable: function _disable() {
     if (!this._enabled)
       return;
     this._enabled = false;
 
-    dump('AccessFu disable');
+    dump('[AccessFu] disable\n');
 
     this.presenters.forEach(function(p) { p.detach(); });
     this.presenters = [];
 
     VirtualCursorController.detach();
 
     Services.obs.removeObserver(this, 'accessible-event');
     this.chromeWin.removeEventListener('DOMActivate', this, true);
     this.chromeWin.removeEventListener('resize', this, true);
     this.chromeWin.removeEventListener('scroll', this, true);
     this.chromeWin.removeEventListener('TabOpen', this, true);
     this.chromeWin.removeEventListener('focus', this, true);
   },
 
-  _processPreferences: function _processPreferences(aPref) {
+  _processPreferences: function _processPreferences(aEnabled, aTouchEnabled) {
+    let accessPref = ACCESSFU_DISABLE;
+    try {
+      accessPref = (aEnabled == undefined) ?
+        this.prefsBranch.getIntPref('activate') : aEnabled;
+    } catch (x) {
+    }
+
+    let ebtPref = ACCESSFU_DISABLE;
+    try {
+      ebtPref = (aTouchEnabled == undefined) ?
+        this.prefsBranch.getIntPref('explorebytouch') : aTouchEnabled;
+    } catch (x) {
+    }
+
     if (Services.appinfo.OS == 'Android') {
-      if (aPref == ACCESSFU_AUTO) {
-        if (!this._observingSystemSettings) {
-          Services.obs.addObserver(this, 'Accessibility:Settings', false);
-          this._observingSystemSettings = true;
-        }
+      if (accessPref == ACCESSFU_AUTO) {
         Cc['@mozilla.org/android/bridge;1'].
           getService(Ci.nsIAndroidBridge).handleGeckoMessage(
             JSON.stringify({ gecko: { type: 'Accessibility:Ready' } }));
         return;
       }
-
-      if (this._observingSystemSettings) {
-        Services.obs.removeObserver(this, 'Accessibility:Settings');
-        this._observingSystemSettings = false;
-      }
     }
 
-    if (aPref == ACCESSFU_ENABLE)
+    if (accessPref == ACCESSFU_ENABLE)
       this._enable();
     else
       this._disable();
+
+    VirtualCursorController.exploreByTouch = ebtPref == ACCESSFU_ENABLE;
+    dump('[AccessFu] Explore by touch: ' +
+          VirtualCursorController.exploreByTouch + '\n');
   },
 
   addPresenter: function addPresenter(presenter) {
     this.presenters.push(presenter);
     presenter.attach(this.chromeWin);
   },
 
   handleEvent: function handleEvent(aEvent) {
@@ -180,32 +187,30 @@ var AccessFu = {
         break;
       }
     }
   },
 
   observe: function observe(aSubject, aTopic, aData) {
     switch (aTopic) {
       case 'Accessibility:Settings':
-        if (JSON.parse(aData).enabled)
-          this._enable();
-        else
-          this._disable();
+        this._processPreferences(JSON.parse(aData).enabled + 0,
+                                 JSON.parse(aData).exploreByTouch + 0);
         break;
       case 'nsPref:changed':
-        if (aData == 'activate')
-          this._processPreferences(this.prefsBranch.getIntPref('activate'));
+        this._processPreferences(this.prefsBranch.getIntPref('activate'),
+                                 this.prefsBranch.getIntPref('explorebytouch'));
         break;
       case 'accessible-event':
         let event;
         try {
           event = aSubject.QueryInterface(Ci.nsIAccessibleEvent);
           this._handleAccEvent(event);
         } catch (ex) {
-          dump(ex);
+          dump('[AccessFu] ' + ex + '\n');
           return;
         }
     }
   },
 
   _handleAccEvent: function _handleAccEvent(aEvent) {
     switch (aEvent.eventType) {
       case Ci.nsIAccessibleEvent.EVENT_VIRTUALCURSOR_CHANGED:
@@ -388,20 +393,17 @@ var AccessFu = {
 
     return location.protocol != "about:";
   },
 
   // A hash of documents that don't yet have an accessible tree.
   _pendingDocuments: {},
 
   // So we don't enable/disable twice
-  _enabled: false,
-
-  // Observing accessibility settings
-  _observingSystemSettings: false
+  _enabled: false
 };
 
 function getAccessible(aNode) {
   try {
     return Cc['@mozilla.org/accessibleRetrieval;1'].
       getService(Ci.nsIAccessibleRetrieval).getAccessibleFor(aNode);
   } catch (e) {
     return null;
--- a/accessible/src/jsat/VirtualCursorController.jsm
+++ b/accessible/src/jsat/VirtualCursorController.jsm
@@ -403,16 +403,18 @@ var TraversalRules = {
   }
 };
 
 var VirtualCursorController = {
   NOT_EDITABLE: 0,
   SINGLE_LINE_EDITABLE: 1,
   MULTI_LINE_EDITABLE: 2,
 
+  explorebytouch: false,
+
   attach: function attach(aWindow) {
     this.chromeWin = aWindow;
     this.chromeWin.document.addEventListener('keypress', this, true);
   },
 
   detach: function detach() {
     this.chromeWin.document.removeEventListener('keypress', this, true);
   },
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -711,14 +711,16 @@ pref("ui.scrolling.overscroll_snap_limit
 // in 1/1000ths of pixels.
 pref("ui.scrolling.min_scrollable_distance", -1);
 // A comma-separated list of float values in the range [0.0, 1.0) that are used as
 // interpolation frames for zoom animations.
 pref("ui.zooming.animation_frames", "");
 
 // Enable accessibility mode if platform accessibility is enabled.
 pref("accessibility.accessfu.activate", 2);
+// Enable explore by touch if it is enabled in the platform
+pref("accessibility.accessfu.explorebytouch", 2);
 
 // Mobile manages state by autodetection
 pref("network.manage-offline-status", true);
 
 // increase the timeout clamp for background tabs to 15 minutes
 pref("dom.min_background_timeout_value", 900000);