Bug 807315 - Load AccessFu resources on-demand. r=davidb

This commit is contained in:
Eitan Isaacson 2012-11-05 13:27:18 -05:00
parent 0d3e56e976
commit 5e54987c8a

View File

@ -12,7 +12,6 @@ const Cr = Components.results;
this.EXPORTED_SYMBOLS = ['AccessFu']; this.EXPORTED_SYMBOLS = ['AccessFu'];
Cu.import('resource://gre/modules/Services.jsm'); 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/Utils.jsm');
Cu.import('resource://gre/modules/accessibility/TouchAdapter.jsm'); Cu.import('resource://gre/modules/accessibility/TouchAdapter.jsm');
@ -32,33 +31,25 @@ this.AccessFu = {
// XXX: only supports attaching to one window now. // XXX: only supports attaching to one window now.
throw new Error('Only one window could be attached to AccessFu'); throw new Error('Only one window could be attached to AccessFu');
Logger.info('attach');
this.chromeWin = aWindow; this.chromeWin = aWindow;
this.prefsBranch = Cc['@mozilla.org/preferences-service;1'] this.prefsBranch = Cc['@mozilla.org/preferences-service;1']
.getService(Ci.nsIPrefService).getBranch('accessibility.accessfu.'); .getService(Ci.nsIPrefService).getBranch('accessibility.accessfu.');
this.prefsBranch.addObserver('activate', this, false); this.prefsBranch.addObserver('activate', this, false);
this.touchAdapter = TouchAdapter; try {
Cc['@mozilla.org/android/bridge;1'].
switch (Utils.MozBuildApp) { getService(Ci.nsIAndroidBridge).handleGeckoMessage(
case 'mobile/android': JSON.stringify({ gecko: { type: 'Accessibility:Ready' } }));
Services.obs.addObserver(this, 'Accessibility:Settings', false); Services.obs.addObserver(this, 'Accessibility:Settings', false);
Cc['@mozilla.org/android/bridge;1']. } catch (x) {
getService(Ci.nsIAndroidBridge).handleGeckoMessage( // Not on Android
JSON.stringify({ gecko: { type: 'Accessibility:Ready' } })); aWindow.addEventListener(
this.touchAdapter = AndroidTouchAdapter; 'ContentStart',
break; (function(event) {
case 'b2g': let content = aWindow.shell.contentBrowser.contentWindow;
aWindow.addEventListener( content.addEventListener('mozContentEvent', this, false, true);
'ContentStart', }).bind(this), false);
(function(event) {
let content = aWindow.shell.contentBrowser.contentWindow;
content.addEventListener('mozContentEvent', this, false, true);
}).bind(this), false);
break;
default:
break;
} }
try { try {
@ -79,8 +70,14 @@ this.AccessFu = {
return; return;
this._enabled = true; this._enabled = true;
Cu.import('resource://gre/modules/accessibility/Utils.jsm');
Cu.import('resource://gre/modules/accessibility/TouchAdapter.jsm');
Logger.info('enable'); Logger.info('enable');
this.touchAdapter = (Utils.MozBuildApp == 'mobile/android') ?
AndroidTouchAdapter : TouchAdapter;
for each (let mm in Utils.getAllMessageManagers(this.chromeWin)) for each (let mm in Utils.getAllMessageManagers(this.chromeWin))
this._loadFrameScript(mm); this._loadFrameScript(mm);
@ -137,7 +134,7 @@ this.AccessFu = {
else else
this._disable(); this._disable();
} catch (x) { } catch (x) {
Logger.logException(x); dump('Error ' + x.message + ' ' + x.fileName + ':' + x.lineNumber);
} }
}, },
@ -176,7 +173,6 @@ this.AccessFu = {
}, },
observe: function observe(aSubject, aTopic, aData) { observe: function observe(aSubject, aTopic, aData) {
Logger.debug('observe', aTopic);
switch (aTopic) { switch (aTopic) {
case 'Accessibility:Settings': case 'Accessibility:Settings':
this._systemPref = JSON.parse(aData).enabled; this._systemPref = JSON.parse(aData).enabled;
@ -253,6 +249,7 @@ this.AccessFu = {
var Output = { var Output = {
attach: function attach(aWindow) { attach: function attach(aWindow) {
this.chromeWin = aWindow; this.chromeWin = aWindow;
Cu.import('resource://gre/modules/Geometry.jsm');
}, },
Speech: function Speech(aDetails, aBrowser) { Speech: function Speech(aDetails, aBrowser) {
@ -482,36 +479,39 @@ var Input = {
mm.sendAsyncMessage('AccessFu:Scroll', {page: aPage, horizontal: aHorizontal, origin: 'top'}); mm.sendAsyncMessage('AccessFu:Scroll', {page: aPage, horizontal: aHorizontal, origin: 'top'});
}, },
keyMap: { get keyMap() {
a: ['moveNext', 'Anchor'], delete this.keyMap;
A: ['movePrevious', 'Anchor'], this.keyMap = {
b: ['moveNext', 'Button'], a: ['moveNext', 'Anchor'],
B: ['movePrevious', 'Button'], A: ['movePrevious', 'Anchor'],
c: ['moveNext', 'Combobox'], b: ['moveNext', 'Button'],
C: ['movePrevious', 'Combobox'], B: ['movePrevious', 'Button'],
e: ['moveNext', 'Entry'], c: ['moveNext', 'Combobox'],
E: ['movePrevious', 'Entry'], C: ['movePrevious', 'Combobox'],
f: ['moveNext', 'FormElement'], e: ['moveNext', 'Entry'],
F: ['movePrevious', 'FormElement'], E: ['movePrevious', 'Entry'],
g: ['moveNext', 'Graphic'], f: ['moveNext', 'FormElement'],
G: ['movePrevious', 'Graphic'], F: ['movePrevious', 'FormElement'],
h: ['moveNext', 'Heading'], g: ['moveNext', 'Graphic'],
H: ['movePrevious', 'Heading'], G: ['movePrevious', 'Graphic'],
i: ['moveNext', 'ListItem'], h: ['moveNext', 'Heading'],
I: ['movePrevious', 'ListItem'], H: ['movePrevious', 'Heading'],
k: ['moveNext', 'Link'], i: ['moveNext', 'ListItem'],
K: ['movePrevious', 'Link'], I: ['movePrevious', 'ListItem'],
l: ['moveNext', 'List'], k: ['moveNext', 'Link'],
L: ['movePrevious', 'List'], K: ['movePrevious', 'Link'],
p: ['moveNext', 'PageTab'], l: ['moveNext', 'List'],
P: ['movePrevious', 'PageTab'], L: ['movePrevious', 'List'],
r: ['moveNext', 'RadioButton'], p: ['moveNext', 'PageTab'],
R: ['movePrevious', 'RadioButton'], P: ['movePrevious', 'PageTab'],
s: ['moveNext', 'Separator'], r: ['moveNext', 'RadioButton'],
S: ['movePrevious', 'Separator'], R: ['movePrevious', 'RadioButton'],
t: ['moveNext', 'Table'], s: ['moveNext', 'Separator'],
T: ['movePrevious', 'Table'], S: ['movePrevious', 'Separator'],
x: ['moveNext', 'Checkbox'], t: ['moveNext', 'Table'],
X: ['movePrevious', 'Checkbox'] T: ['movePrevious', 'Table'],
x: ['moveNext', 'Checkbox'],
X: ['movePrevious', 'Checkbox']
};
} }
}; };