Bug 807315 - Load AccessFu resources on-demand. r=davidb
authorEitan Isaacson <eitan@monotonous.org>
Mon, 05 Nov 2012 13:27:18 -0500
changeset 112337 0dea4f9a91330ce98542cb2d131e385e39d3c878
parent 112336 c87fcf6ed0a77d0f532b41217b584a806879c5b9
child 112338 0a6cb7947e07189eb4d4673c0b15bd584e79e2db
push id23812
push useremorley@mozilla.com
push dateTue, 06 Nov 2012 14:01:34 +0000
treeherdermozilla-central@f4aeed115e54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidb
bugs807315
milestone19.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 807315 - Load AccessFu resources on-demand. r=davidb
accessible/src/jsat/AccessFu.jsm
--- a/accessible/src/jsat/AccessFu.jsm
+++ b/accessible/src/jsat/AccessFu.jsm
@@ -7,17 +7,16 @@
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 const Cr = Components.results;
 
 this.EXPORTED_SYMBOLS = ['AccessFu'];
 
 Cu.import('resource://gre/modules/Services.jsm');
-Cu.import('resource://gre/modules/Geometry.jsm');
 
 Cu.import('resource://gre/modules/accessibility/Utils.jsm');
 Cu.import('resource://gre/modules/accessibility/TouchAdapter.jsm');
 
 const ACCESSFU_DISABLE = 0;
 const ACCESSFU_ENABLE = 1;
 const ACCESSFU_AUTO = 2;
 
@@ -27,43 +26,35 @@ this.AccessFu = {
    * If accessibility is enabled on the platform, then a special accessibility
    * mode is started.
    */
   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');
 
-    Logger.info('attach');
     this.chromeWin = aWindow;
 
     this.prefsBranch = Cc['@mozilla.org/preferences-service;1']
       .getService(Ci.nsIPrefService).getBranch('accessibility.accessfu.');
     this.prefsBranch.addObserver('activate', this, false);
 
-    this.touchAdapter = TouchAdapter;
-
-    switch (Utils.MozBuildApp) {
-      case 'mobile/android':
-        Services.obs.addObserver(this, 'Accessibility:Settings', false);
-        Cc['@mozilla.org/android/bridge;1'].
-          getService(Ci.nsIAndroidBridge).handleGeckoMessage(
-            JSON.stringify({ gecko: { type: 'Accessibility:Ready' } }));
-        this.touchAdapter = AndroidTouchAdapter;
-        break;
-      case 'b2g':
-        aWindow.addEventListener(
-          'ContentStart',
-          (function(event) {
-             let content = aWindow.shell.contentBrowser.contentWindow;
-             content.addEventListener('mozContentEvent', this, false, true);
-           }).bind(this), false);
-        break;
-      default:
-        break;
+    try {
+      Cc['@mozilla.org/android/bridge;1'].
+        getService(Ci.nsIAndroidBridge).handleGeckoMessage(
+          JSON.stringify({ gecko: { type: 'Accessibility:Ready' } }));
+      Services.obs.addObserver(this, 'Accessibility:Settings', false);
+    } catch (x) {
+      // Not on Android
+      aWindow.addEventListener(
+        'ContentStart',
+        (function(event) {
+           let content = aWindow.shell.contentBrowser.contentWindow;
+           content.addEventListener('mozContentEvent', this, false, true);
+         }).bind(this), false);
     }
 
     try {
       this._activatePref = this.prefsBranch.getIntPref('activate');
     } catch (x) {
       this._activatePref = ACCESSFU_DISABLE;
     }
 
@@ -74,18 +65,24 @@ this.AccessFu = {
    * Start AccessFu mode, this primarily means controlling the virtual cursor
    * with arrow keys.
    */
   _enable: function _enable() {
     if (this._enabled)
       return;
     this._enabled = true;
 
+    Cu.import('resource://gre/modules/accessibility/Utils.jsm');
+    Cu.import('resource://gre/modules/accessibility/TouchAdapter.jsm');
+
     Logger.info('enable');
 
+    this.touchAdapter = (Utils.MozBuildApp == 'mobile/android') ?
+      AndroidTouchAdapter : TouchAdapter;
+
     for each (let mm in Utils.getAllMessageManagers(this.chromeWin))
       this._loadFrameScript(mm);
 
     // Add stylesheet
     let stylesheetURL = 'chrome://global/content/accessibility/AccessFu.css';
     this.stylesheet = this.chromeWin.document.createProcessingInstruction(
       'xml-stylesheet', 'href="' + stylesheetURL + '" type="text/css"');
     this.chromeWin.document.insertBefore(this.stylesheet,
@@ -132,17 +129,17 @@ this.AccessFu = {
   _enableOrDisable: function _enableOrDisable() {
     try {
       if (this._activatePref == ACCESSFU_ENABLE ||
           this._systemPref && this._activatePref == ACCESSFU_AUTO)
         this._enable();
       else
         this._disable();
     } catch (x) {
-      Logger.logException(x);
+      dump('Error ' + x.message + ' ' + x.fileName + ':' + x.lineNumber);
     }
   },
 
   receiveMessage: function receiveMessage(aMessage) {
     if (Logger.logLevel >= Logger.DEBUG)
       Logger.debug('Recieved', aMessage.name, JSON.stringify(aMessage.json));
 
     switch (aMessage.name) {
@@ -171,17 +168,16 @@ this.AccessFu = {
     aMessageManager.addMessageListener('AccessFu:Input', this);
     aMessageManager.addMessageListener('AccessFu:Ready', this);
     aMessageManager.
       loadFrameScript(
         'chrome://global/content/accessibility/content-script.js', true);
   },
 
   observe: function observe(aSubject, aTopic, aData) {
-    Logger.debug('observe', aTopic);
     switch (aTopic) {
       case 'Accessibility:Settings':
         this._systemPref = JSON.parse(aData).enabled;
         this._enableOrDisable();
         break;
       case 'Accessibility:NextObject':
         Input.moveCursor('moveNext', 'Simple', 'gesture');
         break;
@@ -248,16 +244,17 @@ this.AccessFu = {
 
   // Layerview is focused
   _focused: false
 };
 
 var Output = {
   attach: function attach(aWindow) {
     this.chromeWin = aWindow;
+    Cu.import('resource://gre/modules/Geometry.jsm');
   },
 
   Speech: function Speech(aDetails, aBrowser) {
     for each (let action in aDetails.actions)
       Logger.info('tts.' + action.method, '"' + action.data + '"', JSON.stringify(action.options));
   },
 
   Visual: function Visual(aDetails, aBrowser) {
@@ -477,41 +474,44 @@ var Input = {
     this.editState = aEditState;
   },
 
   scroll: function scroll(aPage, aHorizontal) {
     let mm = Utils.getMessageManager(Utils.getCurrentBrowser(this.chromeWin));
     mm.sendAsyncMessage('AccessFu:Scroll', {page: aPage, horizontal: aHorizontal, origin: 'top'});
   },
 
-  keyMap: {
-    a: ['moveNext', 'Anchor'],
-    A: ['movePrevious', 'Anchor'],
-    b: ['moveNext', 'Button'],
-    B: ['movePrevious', 'Button'],
-    c: ['moveNext', 'Combobox'],
-    C: ['movePrevious', 'Combobox'],
-    e: ['moveNext', 'Entry'],
-    E: ['movePrevious', 'Entry'],
-    f: ['moveNext', 'FormElement'],
-    F: ['movePrevious', 'FormElement'],
-    g: ['moveNext', 'Graphic'],
-    G: ['movePrevious', 'Graphic'],
-    h: ['moveNext', 'Heading'],
-    H: ['movePrevious', 'Heading'],
-    i: ['moveNext', 'ListItem'],
-    I: ['movePrevious', 'ListItem'],
-    k: ['moveNext', 'Link'],
-    K: ['movePrevious', 'Link'],
-    l: ['moveNext', 'List'],
-    L: ['movePrevious', 'List'],
-    p: ['moveNext', 'PageTab'],
-    P: ['movePrevious', 'PageTab'],
-    r: ['moveNext', 'RadioButton'],
-    R: ['movePrevious', 'RadioButton'],
-    s: ['moveNext', 'Separator'],
-    S: ['movePrevious', 'Separator'],
-    t: ['moveNext', 'Table'],
-    T: ['movePrevious', 'Table'],
-    x: ['moveNext', 'Checkbox'],
-    X: ['movePrevious', 'Checkbox']
+  get keyMap() {
+    delete this.keyMap;
+    this.keyMap = {
+      a: ['moveNext', 'Anchor'],
+      A: ['movePrevious', 'Anchor'],
+      b: ['moveNext', 'Button'],
+      B: ['movePrevious', 'Button'],
+      c: ['moveNext', 'Combobox'],
+      C: ['movePrevious', 'Combobox'],
+      e: ['moveNext', 'Entry'],
+      E: ['movePrevious', 'Entry'],
+      f: ['moveNext', 'FormElement'],
+      F: ['movePrevious', 'FormElement'],
+      g: ['moveNext', 'Graphic'],
+      G: ['movePrevious', 'Graphic'],
+      h: ['moveNext', 'Heading'],
+      H: ['movePrevious', 'Heading'],
+      i: ['moveNext', 'ListItem'],
+      I: ['movePrevious', 'ListItem'],
+      k: ['moveNext', 'Link'],
+      K: ['movePrevious', 'Link'],
+      l: ['moveNext', 'List'],
+      L: ['movePrevious', 'List'],
+      p: ['moveNext', 'PageTab'],
+      P: ['movePrevious', 'PageTab'],
+      r: ['moveNext', 'RadioButton'],
+      R: ['movePrevious', 'RadioButton'],
+      s: ['moveNext', 'Separator'],
+      S: ['movePrevious', 'Separator'],
+      t: ['moveNext', 'Table'],
+      T: ['movePrevious', 'Table'],
+      x: ['moveNext', 'Checkbox'],
+      X: ['movePrevious', 'Checkbox']
+    };
   }
 };