2012-06-20 21:07:51 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
/* global Components, XPCOMUtils, Services, PluralForm, Logger, Rect, Utils,
|
|
|
|
States, Relations, Roles, dump, Events, PivotContext, PrefCache */
|
|
|
|
/* exported Utils, Logger, PivotContext, PrefCache, SettingCache */
|
|
|
|
|
2012-06-20 21:07:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
const {classes: Cc, utils: Cu, interfaces: Ci} = Components;
|
2012-06-20 21:07:51 +00:00
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'Services', // jshint ignore:line
|
2013-05-24 18:57:28 +00:00
|
|
|
'resource://gre/modules/Services.jsm');
|
2014-08-06 13:38:56 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'Rect', // jshint ignore:line
|
2013-05-24 18:57:28 +00:00
|
|
|
'resource://gre/modules/Geometry.jsm');
|
2014-08-06 13:38:56 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'Roles', // jshint ignore:line
|
2013-11-19 18:17:43 +00:00
|
|
|
'resource://gre/modules/accessibility/Constants.jsm');
|
2014-08-06 13:38:56 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'Events', // jshint ignore:line
|
2013-11-19 18:17:43 +00:00
|
|
|
'resource://gre/modules/accessibility/Constants.jsm');
|
2014-08-06 13:38:56 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'Relations', // jshint ignore:line
|
2013-11-19 18:17:43 +00:00
|
|
|
'resource://gre/modules/accessibility/Constants.jsm');
|
2014-08-06 13:38:56 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'States', // jshint ignore:line
|
2014-01-28 00:35:13 +00:00
|
|
|
'resource://gre/modules/accessibility/Constants.jsm');
|
2014-08-06 13:38:56 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'PluralForm', // jshint ignore:line
|
2014-08-06 13:38:50 +00:00
|
|
|
'resource://gre/modules/PluralForm.jsm');
|
2012-06-20 21:07:51 +00:00
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
this.EXPORTED_SYMBOLS = ['Utils', 'Logger', 'PivotContext', 'PrefCache', // jshint ignore:line
|
|
|
|
'SettingCache'];
|
2012-06-20 21:07:51 +00:00
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
this.Utils = { // jshint ignore:line
|
2012-07-20 16:46:54 +00:00
|
|
|
_buildAppMap: {
|
|
|
|
'{3c2e2abc-06d4-11e1-ac3b-374f68613e61}': 'b2g',
|
|
|
|
'{ec8030f7-c20a-464f-9b0e-13a3a9e97384}': 'browser',
|
|
|
|
'{aa3c5121-dab2-40e2-81ca-7ea25febc110}': 'mobile/android',
|
|
|
|
'{a23983c0-fd0e-11dc-95ff-0800200c9a66}': 'mobile/xul'
|
|
|
|
},
|
|
|
|
|
2013-03-15 13:50:55 +00:00
|
|
|
init: function Utils_init(aWindow) {
|
2014-08-06 13:38:56 +00:00
|
|
|
if (this._win) {
|
2013-03-15 13:50:55 +00:00
|
|
|
// XXX: only supports attaching to one window now.
|
|
|
|
throw new Error('Only one top-level window could used with AccessFu');
|
2014-08-06 13:38:56 +00:00
|
|
|
}
|
2013-03-15 13:50:55 +00:00
|
|
|
this._win = Cu.getWeakReference(aWindow);
|
|
|
|
},
|
|
|
|
|
2013-04-23 17:39:15 +00:00
|
|
|
uninit: function Utils_uninit() {
|
|
|
|
if (!this._win) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
delete this._win;
|
|
|
|
},
|
|
|
|
|
2013-03-15 13:50:55 +00:00
|
|
|
get win() {
|
2013-05-21 18:16:49 +00:00
|
|
|
if (!this._win) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-03-15 13:50:55 +00:00
|
|
|
return this._win.get();
|
|
|
|
},
|
|
|
|
|
2014-05-20 21:39:09 +00:00
|
|
|
get winUtils() {
|
|
|
|
let win = this.win;
|
|
|
|
if (!win) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(
|
|
|
|
Ci.nsIDOMWindowUtils);
|
|
|
|
},
|
|
|
|
|
2012-08-27 03:14:42 +00:00
|
|
|
get AccRetrieval() {
|
|
|
|
if (!this._AccRetrieval) {
|
|
|
|
this._AccRetrieval = Cc['@mozilla.org/accessibleRetrieval;1'].
|
|
|
|
getService(Ci.nsIAccessibleRetrieval);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._AccRetrieval;
|
|
|
|
},
|
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
set MozBuildApp(value) {
|
|
|
|
this._buildApp = value;
|
|
|
|
},
|
|
|
|
|
2012-07-20 16:46:54 +00:00
|
|
|
get MozBuildApp() {
|
2014-08-06 13:38:56 +00:00
|
|
|
if (!this._buildApp) {
|
2012-07-20 16:46:54 +00:00
|
|
|
this._buildApp = this._buildAppMap[Services.appinfo.ID];
|
2014-08-06 13:38:56 +00:00
|
|
|
}
|
2012-07-20 16:46:54 +00:00
|
|
|
return this._buildApp;
|
|
|
|
},
|
|
|
|
|
2012-06-20 21:07:51 +00:00
|
|
|
get OS() {
|
2014-08-06 13:38:56 +00:00
|
|
|
if (!this._OS) {
|
2012-06-20 21:07:51 +00:00
|
|
|
this._OS = Services.appinfo.OS;
|
2014-08-06 13:38:56 +00:00
|
|
|
}
|
2012-06-20 21:07:51 +00:00
|
|
|
return this._OS;
|
|
|
|
},
|
|
|
|
|
2013-06-12 17:47:25 +00:00
|
|
|
get widgetToolkit() {
|
2014-08-06 13:38:56 +00:00
|
|
|
if (!this._widgetToolkit) {
|
2013-06-12 17:47:25 +00:00
|
|
|
this._widgetToolkit = Services.appinfo.widgetToolkit;
|
2014-08-06 13:38:56 +00:00
|
|
|
}
|
2013-06-12 17:47:25 +00:00
|
|
|
return this._widgetToolkit;
|
|
|
|
},
|
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
get ScriptName() {
|
2014-08-06 13:38:56 +00:00
|
|
|
if (!this._ScriptName) {
|
2012-10-01 20:33:26 +00:00
|
|
|
this._ScriptName =
|
|
|
|
(Services.appinfo.processType == 2) ? 'AccessFuContent' : 'AccessFu';
|
2014-08-06 13:38:56 +00:00
|
|
|
}
|
2012-10-01 20:33:26 +00:00
|
|
|
return this._ScriptName;
|
|
|
|
},
|
|
|
|
|
2012-06-20 21:07:51 +00:00
|
|
|
get AndroidSdkVersion() {
|
|
|
|
if (!this._AndroidSdkVersion) {
|
2012-10-10 15:10:39 +00:00
|
|
|
if (Services.appinfo.OS == 'Android') {
|
2014-08-06 13:38:56 +00:00
|
|
|
this._AndroidSdkVersion = Services.sysinfo.getPropertyAsInt32(
|
|
|
|
'version');
|
2012-10-10 15:10:39 +00:00
|
|
|
} else {
|
|
|
|
// Most useful in desktop debugging.
|
2014-03-19 07:38:25 +00:00
|
|
|
this._AndroidSdkVersion = 16;
|
2012-10-10 15:10:39 +00:00
|
|
|
}
|
2012-06-20 21:07:51 +00:00
|
|
|
}
|
|
|
|
return this._AndroidSdkVersion;
|
|
|
|
},
|
|
|
|
|
|
|
|
set AndroidSdkVersion(value) {
|
|
|
|
// When we want to mimic another version.
|
|
|
|
this._AndroidSdkVersion = value;
|
|
|
|
},
|
|
|
|
|
2013-03-15 13:50:55 +00:00
|
|
|
get BrowserApp() {
|
2013-05-21 18:16:49 +00:00
|
|
|
if (!this.win) {
|
|
|
|
return null;
|
|
|
|
}
|
2012-07-20 16:46:54 +00:00
|
|
|
switch (this.MozBuildApp) {
|
|
|
|
case 'mobile/android':
|
2013-03-15 13:50:55 +00:00
|
|
|
return this.win.BrowserApp;
|
2012-07-20 16:46:54 +00:00
|
|
|
case 'browser':
|
2013-03-15 13:50:55 +00:00
|
|
|
return this.win.gBrowser;
|
2012-07-20 16:46:54 +00:00
|
|
|
case 'b2g':
|
2013-03-15 13:50:55 +00:00
|
|
|
return this.win.shell;
|
2012-07-20 16:46:54 +00:00
|
|
|
default:
|
|
|
|
return null;
|
2012-06-20 21:07:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-03-15 13:50:55 +00:00
|
|
|
get CurrentBrowser() {
|
2013-05-21 18:16:49 +00:00
|
|
|
if (!this.BrowserApp) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-08-06 13:38:56 +00:00
|
|
|
if (this.MozBuildApp == 'b2g') {
|
2013-03-15 13:50:55 +00:00
|
|
|
return this.BrowserApp.contentBrowser;
|
2014-08-06 13:38:56 +00:00
|
|
|
}
|
2013-03-15 13:50:55 +00:00
|
|
|
return this.BrowserApp.selectedBrowser;
|
2012-10-01 20:33:26 +00:00
|
|
|
},
|
|
|
|
|
2013-03-15 13:50:55 +00:00
|
|
|
get CurrentContentDoc() {
|
|
|
|
let browser = this.CurrentBrowser;
|
2012-10-19 17:06:07 +00:00
|
|
|
return browser ? browser.contentDocument : null;
|
2012-10-01 20:33:26 +00:00
|
|
|
},
|
|
|
|
|
2013-03-15 13:50:55 +00:00
|
|
|
get AllMessageManagers() {
|
2012-10-01 20:33:26 +00:00
|
|
|
let messageManagers = [];
|
|
|
|
|
2014-05-23 21:39:00 +00:00
|
|
|
function collectLeafMessageManagers(mm) {
|
|
|
|
for (let i = 0; i < mm.childCount; i++) {
|
|
|
|
let childMM = mm.getChildAt(i);
|
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
if ('sendAsyncMessage' in childMM) {
|
2014-05-23 21:39:00 +00:00
|
|
|
messageManagers.push(childMM);
|
|
|
|
} else {
|
|
|
|
collectLeafMessageManagers(childMM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
collectLeafMessageManagers(this.win.messageManager);
|
2012-10-01 20:33:26 +00:00
|
|
|
|
2013-03-15 13:50:55 +00:00
|
|
|
let document = this.CurrentContentDoc;
|
2012-10-01 20:33:26 +00:00
|
|
|
|
2012-10-19 17:06:07 +00:00
|
|
|
if (document) {
|
2013-05-21 18:16:50 +00:00
|
|
|
let remoteframes = document.querySelectorAll('iframe');
|
|
|
|
|
|
|
|
for (let i = 0; i < remoteframes.length; ++i) {
|
|
|
|
let mm = this.getMessageManager(remoteframes[i]);
|
|
|
|
if (mm) {
|
|
|
|
messageManagers.push(mm);
|
|
|
|
}
|
|
|
|
}
|
2012-10-01 20:33:26 +00:00
|
|
|
|
2012-10-19 17:06:07 +00:00
|
|
|
}
|
2012-10-01 20:33:26 +00:00
|
|
|
|
|
|
|
return messageManagers;
|
2012-08-17 22:49:34 +00:00
|
|
|
},
|
|
|
|
|
2013-05-21 18:16:50 +00:00
|
|
|
get isContentProcess() {
|
|
|
|
delete this.isContentProcess;
|
|
|
|
this.isContentProcess =
|
|
|
|
Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
|
|
|
|
return this.isContentProcess;
|
|
|
|
},
|
|
|
|
|
2014-08-06 13:38:50 +00:00
|
|
|
localize: function localize(aOutput) {
|
|
|
|
let outputArray = Array.isArray(aOutput) ? aOutput : [aOutput];
|
|
|
|
let localized =
|
|
|
|
[this.stringBundle.get(details) for (details of outputArray)]; // jshint ignore:line
|
|
|
|
// Clean up the white space.
|
|
|
|
let trimmed;
|
|
|
|
return [trimmed for (word of localized) if (word && // jshint ignore:line
|
|
|
|
(trimmed = word.trim()))]; // jshint ignore:line
|
|
|
|
},
|
|
|
|
|
2014-03-04 18:10:38 +00:00
|
|
|
get stringBundle() {
|
|
|
|
delete this.stringBundle;
|
2014-08-06 13:38:50 +00:00
|
|
|
let bundle = Services.strings.createBundle(
|
2014-03-04 18:10:38 +00:00
|
|
|
'chrome://global/locale/AccessFu.properties');
|
2014-08-06 13:38:50 +00:00
|
|
|
this.stringBundle = {
|
|
|
|
get: function stringBundle_get(aDetails = {}) {
|
|
|
|
if (!aDetails || typeof aDetails === 'string') {
|
|
|
|
return aDetails;
|
|
|
|
}
|
|
|
|
let str = '';
|
|
|
|
let string = aDetails.string;
|
|
|
|
if (!string) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
let args = aDetails.args;
|
|
|
|
let count = aDetails.count;
|
|
|
|
if (args) {
|
|
|
|
str = bundle.formatStringFromName(string, args, args.length);
|
|
|
|
} else {
|
|
|
|
str = bundle.GetStringFromName(string);
|
|
|
|
}
|
|
|
|
if (count) {
|
|
|
|
str = PluralForm.get(count, str);
|
|
|
|
str = str.replace('#1', count);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
Logger.debug('Failed to get a string from a bundle for', string);
|
|
|
|
} finally {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-03-04 18:10:38 +00:00
|
|
|
return this.stringBundle;
|
|
|
|
},
|
|
|
|
|
2013-03-15 13:50:55 +00:00
|
|
|
getMessageManager: function getMessageManager(aBrowser) {
|
|
|
|
try {
|
|
|
|
return aBrowser.QueryInterface(Ci.nsIFrameLoaderOwner).
|
|
|
|
frameLoader.messageManager;
|
|
|
|
} catch (x) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-28 00:35:13 +00:00
|
|
|
getState: function getState(aAccessibleOrEvent) {
|
|
|
|
if (aAccessibleOrEvent instanceof Ci.nsIAccessibleStateChangeEvent) {
|
|
|
|
return new State(
|
|
|
|
aAccessibleOrEvent.isExtraState ? 0 : aAccessibleOrEvent.state,
|
|
|
|
aAccessibleOrEvent.isExtraState ? aAccessibleOrEvent.state : 0);
|
|
|
|
} else {
|
|
|
|
let state = {};
|
|
|
|
let extState = {};
|
|
|
|
aAccessibleOrEvent.getState(state, extState);
|
|
|
|
return new State(state.value, extState.value);
|
|
|
|
}
|
2012-07-20 16:46:54 +00:00
|
|
|
},
|
|
|
|
|
2013-05-28 17:51:44 +00:00
|
|
|
getAttributes: function getAttributes(aAccessible) {
|
|
|
|
let attributes = {};
|
|
|
|
|
2013-06-27 21:15:36 +00:00
|
|
|
if (aAccessible && aAccessible.attributes) {
|
|
|
|
let attributesEnum = aAccessible.attributes.enumerate();
|
|
|
|
|
|
|
|
// Populate |attributes| object with |aAccessible|'s attribute key-value
|
|
|
|
// pairs.
|
|
|
|
while (attributesEnum.hasMoreElements()) {
|
|
|
|
let attribute = attributesEnum.getNext().QueryInterface(
|
|
|
|
Ci.nsIPropertyElement);
|
|
|
|
attributes[attribute.key] = attribute.value;
|
|
|
|
}
|
2013-05-28 17:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return attributes;
|
|
|
|
},
|
|
|
|
|
2012-07-20 16:46:54 +00:00
|
|
|
getVirtualCursor: function getVirtualCursor(aDocument) {
|
|
|
|
let doc = (aDocument instanceof Ci.nsIAccessible) ? aDocument :
|
2012-08-27 03:14:42 +00:00
|
|
|
this.AccRetrieval.getAccessibleFor(aDocument);
|
2012-07-20 16:46:54 +00:00
|
|
|
|
2013-05-21 18:16:50 +00:00
|
|
|
return doc.QueryInterface(Ci.nsIAccessibleDocument).virtualCursor;
|
|
|
|
},
|
2012-07-20 16:46:54 +00:00
|
|
|
|
2014-08-19 19:26:02 +00:00
|
|
|
getContentResolution: function _getContentResolution(aAccessible) {
|
|
|
|
let resX = { value: 1 }, resY = { value: 1 };
|
|
|
|
aAccessible.document.window.QueryInterface(
|
|
|
|
Ci.nsIInterfaceRequestor).getInterface(
|
|
|
|
Ci.nsIDOMWindowUtils).getResolution(resX, resY);
|
|
|
|
return [resX.value, resY.value];
|
2013-07-03 22:02:44 +00:00
|
|
|
},
|
|
|
|
|
2014-08-19 19:26:02 +00:00
|
|
|
getBounds: function getBounds(aAccessible, aPreserveContentScale) {
|
|
|
|
let objX = {}, objY = {}, objW = {}, objH = {};
|
|
|
|
aAccessible.getBounds(objX, objY, objW, objH);
|
|
|
|
|
|
|
|
let [scaleX, scaleY] = aPreserveContentScale ? [1, 1] :
|
|
|
|
this.getContentResolution(aAccessible);
|
|
|
|
|
|
|
|
return new Rect(objX.value, objY.value, objW.value, objH.value).scale(
|
|
|
|
scaleX, scaleY);
|
|
|
|
},
|
|
|
|
|
|
|
|
getTextBounds: function getTextBounds(aAccessible, aStart, aEnd,
|
|
|
|
aPreserveContentScale) {
|
|
|
|
let accText = aAccessible.QueryInterface(Ci.nsIAccessibleText);
|
|
|
|
let objX = {}, objY = {}, objW = {}, objH = {};
|
|
|
|
accText.getRangeExtents(aStart, aEnd, objX, objY, objW, objH,
|
|
|
|
Ci.nsIAccessibleCoordinateType.COORDTYPE_SCREEN_RELATIVE);
|
|
|
|
|
|
|
|
let [scaleX, scaleY] = aPreserveContentScale ? [1, 1] :
|
|
|
|
this.getContentResolution(aAccessible);
|
|
|
|
|
|
|
|
return new Rect(objX.value, objY.value, objW.value, objH.value).scale(
|
|
|
|
scaleX, scaleY);
|
2013-07-24 21:52:57 +00:00
|
|
|
},
|
|
|
|
|
2014-04-11 14:30:37 +00:00
|
|
|
/**
|
|
|
|
* Get current display DPI.
|
|
|
|
*/
|
|
|
|
get dpi() {
|
|
|
|
delete this.dpi;
|
2014-05-20 21:39:09 +00:00
|
|
|
this.dpi = this.winUtils.displayDPI;
|
2014-04-11 14:30:37 +00:00
|
|
|
return this.dpi;
|
|
|
|
},
|
|
|
|
|
2014-03-05 01:49:27 +00:00
|
|
|
isInSubtree: function isInSubtree(aAccessible, aSubTreeRoot) {
|
|
|
|
let acc = aAccessible;
|
|
|
|
while (acc) {
|
|
|
|
if (acc == aSubTreeRoot) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
acc = acc.parent;
|
|
|
|
} catch (x) {
|
|
|
|
Logger.debug('Failed to get parent:', x);
|
|
|
|
acc = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2014-08-28 13:07:30 +00:00
|
|
|
isHidden: function isHidden(aAccessible) {
|
|
|
|
// Need to account for aria-hidden, so can't just check for INVISIBLE
|
|
|
|
// state.
|
|
|
|
let hidden = Utils.getAttributes(aAccessible).hidden;
|
|
|
|
return hidden && hidden === 'true';
|
|
|
|
},
|
|
|
|
|
2014-09-25 13:57:22 +00:00
|
|
|
visibleChildCount: function visibleChildCount(aAccessible) {
|
|
|
|
let count = 0;
|
|
|
|
for (let child = aAccessible.firstChild; child; child = child.nextSibling) {
|
|
|
|
if (!this.isHidden(child)) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
},
|
|
|
|
|
2013-07-03 22:02:44 +00:00
|
|
|
inHiddenSubtree: function inHiddenSubtree(aAccessible) {
|
|
|
|
for (let acc=aAccessible; acc; acc=acc.parent) {
|
2014-08-28 13:07:30 +00:00
|
|
|
if (this.isHidden(acc)) {
|
2013-07-03 22:02:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2014-01-29 23:08:53 +00:00
|
|
|
isAliveAndVisible: function isAliveAndVisible(aAccessible, aIsOnScreen) {
|
2013-07-03 22:02:44 +00:00
|
|
|
if (!aAccessible) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2014-01-28 00:35:13 +00:00
|
|
|
let state = this.getState(aAccessible);
|
|
|
|
if (state.contains(States.DEFUNCT) || state.contains(States.INVISIBLE) ||
|
2014-01-29 23:08:53 +00:00
|
|
|
(aIsOnScreen && state.contains(States.OFFSCREEN)) ||
|
2013-07-03 22:02:44 +00:00
|
|
|
Utils.inHiddenSubtree(aAccessible)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (x) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2013-07-11 20:42:11 +00:00
|
|
|
},
|
|
|
|
|
2013-08-21 16:40:06 +00:00
|
|
|
matchAttributeValue: function matchAttributeValue(aAttributeValue, values) {
|
|
|
|
let attrSet = new Set(aAttributeValue.split(' '));
|
|
|
|
for (let value of values) {
|
|
|
|
if (attrSet.has(value)) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-07-11 20:42:11 +00:00
|
|
|
getLandmarkName: function getLandmarkName(aAccessible) {
|
|
|
|
const landmarks = [
|
|
|
|
'banner',
|
|
|
|
'complementary',
|
|
|
|
'contentinfo',
|
|
|
|
'main',
|
|
|
|
'navigation',
|
|
|
|
'search'
|
|
|
|
];
|
|
|
|
let roles = this.getAttributes(aAccessible)['xml-roles'];
|
|
|
|
if (!roles) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Looking up a role that would match a landmark.
|
2013-08-21 16:40:06 +00:00
|
|
|
return this.matchAttributeValue(roles, landmarks);
|
2013-10-14 19:56:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getEmbeddedControl: function getEmbeddedControl(aLabel) {
|
|
|
|
if (aLabel) {
|
2013-11-19 18:17:43 +00:00
|
|
|
let relation = aLabel.getRelationByType(Relations.LABEL_FOR);
|
2013-10-14 19:56:19 +00:00
|
|
|
for (let i = 0; i < relation.targetsCount; i++) {
|
|
|
|
let target = relation.getTarget(i);
|
|
|
|
if (target.parent === aLabel) {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2014-05-01 04:33:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
isListItemDecorator: function isListItemDecorator(aStaticText,
|
|
|
|
aExcludeOrdered) {
|
|
|
|
let parent = aStaticText.parent;
|
|
|
|
if (aExcludeOrdered && parent.parent.DOMNode.nodeName === 'OL') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent.role === Roles.LISTITEM && parent.childCount > 1 &&
|
|
|
|
aStaticText.indexInParent === 0;
|
2014-08-11 18:27:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
dispatchChromeEvent: function dispatchChromeEvent(aType, aDetails) {
|
|
|
|
let details = {
|
|
|
|
type: aType,
|
|
|
|
details: JSON.stringify(
|
|
|
|
typeof aDetails === 'string' ? { eventType : aDetails } : aDetails)
|
|
|
|
};
|
|
|
|
let window = this.win;
|
|
|
|
if (window.shell) {
|
|
|
|
// On B2G device.
|
|
|
|
window.shell.sendChromeEvent(details);
|
|
|
|
} else {
|
|
|
|
// Dispatch custom event to have support for desktop and screen reader
|
|
|
|
// emulator add-on.
|
|
|
|
window.dispatchEvent(new window.CustomEvent(aType, {
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true,
|
|
|
|
detail: details
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2014-10-14 21:42:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
isActivatableOnFingerUp: function isActivatableOnFingerUp(aAccessible) {
|
|
|
|
if (aAccessible.role === Roles.KEY) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
let quick_activate = this.getAttributes(aAccessible)['moz-quick-activate'];
|
|
|
|
return quick_activate && JSON.parse(quick_activate);
|
2012-06-20 21:07:51 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-04 19:56:20 +00:00
|
|
|
/**
|
|
|
|
* State object used internally to process accessible's states.
|
|
|
|
* @param {Number} aBase Base state.
|
|
|
|
* @param {Number} aExtended Extended state.
|
|
|
|
*/
|
|
|
|
function State(aBase, aExtended) {
|
|
|
|
this.base = aBase;
|
|
|
|
this.extended = aExtended;
|
|
|
|
}
|
|
|
|
|
|
|
|
State.prototype = {
|
|
|
|
contains: function State_contains(other) {
|
|
|
|
return !!(this.base & other.base || this.extended & other.extended);
|
|
|
|
},
|
|
|
|
toString: function State_toString() {
|
|
|
|
let stateStrings = Utils.AccRetrieval.
|
|
|
|
getStringStates(this.base, this.extended);
|
|
|
|
let statesArray = new Array(stateStrings.length);
|
|
|
|
for (let i = 0; i < statesArray.length; i++) {
|
|
|
|
statesArray[i] = stateStrings.item(i);
|
|
|
|
}
|
|
|
|
return '[' + statesArray.join(', ') + ']';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
this.Logger = { // jshint ignore:line
|
2014-08-14 13:24:08 +00:00
|
|
|
GESTURE: -1,
|
2012-06-20 21:07:51 +00:00
|
|
|
DEBUG: 0,
|
|
|
|
INFO: 1,
|
|
|
|
WARNING: 2,
|
|
|
|
ERROR: 3,
|
2014-08-14 13:24:08 +00:00
|
|
|
_LEVEL_NAMES: ['GESTURE', 'DEBUG', 'INFO', 'WARNING', 'ERROR'],
|
2012-06-20 21:07:51 +00:00
|
|
|
|
|
|
|
logLevel: 1, // INFO;
|
|
|
|
|
2013-04-23 17:39:15 +00:00
|
|
|
test: false,
|
|
|
|
|
2012-06-20 21:07:51 +00:00
|
|
|
log: function log(aLogLevel) {
|
2014-08-06 13:38:56 +00:00
|
|
|
if (aLogLevel < this.logLevel) {
|
2012-06-20 21:07:51 +00:00
|
|
|
return;
|
2014-08-06 13:38:56 +00:00
|
|
|
}
|
2012-06-20 21:07:51 +00:00
|
|
|
|
2014-02-27 15:42:45 +00:00
|
|
|
let args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
let message = (typeof(args[0]) === 'function' ? args[0]() : args).join(' ');
|
2014-08-14 13:24:08 +00:00
|
|
|
message = '[' + Utils.ScriptName + '] ' + this._LEVEL_NAMES[aLogLevel + 1] +
|
2013-04-23 17:39:15 +00:00
|
|
|
' ' + message + '\n';
|
|
|
|
dump(message);
|
|
|
|
// Note: used for testing purposes. If |this.test| is true, also log to
|
|
|
|
// the console service.
|
|
|
|
if (this.test) {
|
|
|
|
try {
|
|
|
|
Services.console.logStringMessage(message);
|
|
|
|
} catch (ex) {
|
|
|
|
// There was an exception logging to the console service.
|
|
|
|
}
|
|
|
|
}
|
2012-06-20 21:07:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
info: function info() {
|
|
|
|
this.log.apply(
|
|
|
|
this, [this.INFO].concat(Array.prototype.slice.call(arguments)));
|
|
|
|
},
|
|
|
|
|
2014-08-14 13:24:08 +00:00
|
|
|
gesture: function gesture() {
|
|
|
|
this.log.apply(
|
|
|
|
this, [this.GESTURE].concat(Array.prototype.slice.call(arguments)));
|
|
|
|
},
|
|
|
|
|
2012-06-20 21:07:51 +00:00
|
|
|
debug: function debug() {
|
|
|
|
this.log.apply(
|
|
|
|
this, [this.DEBUG].concat(Array.prototype.slice.call(arguments)));
|
|
|
|
},
|
|
|
|
|
|
|
|
warning: function warning() {
|
|
|
|
this.log.apply(
|
|
|
|
this, [this.WARNING].concat(Array.prototype.slice.call(arguments)));
|
|
|
|
},
|
|
|
|
|
|
|
|
error: function error() {
|
|
|
|
this.log.apply(
|
|
|
|
this, [this.ERROR].concat(Array.prototype.slice.call(arguments)));
|
|
|
|
},
|
|
|
|
|
2013-06-27 21:15:36 +00:00
|
|
|
logException: function logException(
|
|
|
|
aException, aErrorMessage = 'An exception has occured') {
|
2012-10-19 20:39:36 +00:00
|
|
|
try {
|
2013-06-27 21:15:36 +00:00
|
|
|
let stackMessage = '';
|
|
|
|
if (aException.stack) {
|
|
|
|
stackMessage = ' ' + aException.stack.replace(/\n/g, '\n ');
|
|
|
|
} else if (aException.location) {
|
|
|
|
let frame = aException.location;
|
|
|
|
let stackLines = [];
|
|
|
|
while (frame && frame.lineNumber) {
|
|
|
|
stackLines.push(
|
|
|
|
' ' + frame.name + '@' + frame.filename + ':' + frame.lineNumber);
|
|
|
|
frame = frame.caller;
|
|
|
|
}
|
|
|
|
stackMessage = stackLines.join('\n');
|
|
|
|
} else {
|
2014-08-06 13:38:56 +00:00
|
|
|
stackMessage =
|
|
|
|
'(' + aException.fileName + ':' + aException.lineNumber + ')';
|
2013-06-27 21:15:36 +00:00
|
|
|
}
|
|
|
|
this.error(aErrorMessage + ':\n ' +
|
|
|
|
aException.message + '\n' +
|
|
|
|
stackMessage);
|
2012-10-19 20:39:36 +00:00
|
|
|
} catch (x) {
|
|
|
|
this.error(x);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-20 21:07:51 +00:00
|
|
|
accessibleToString: function accessibleToString(aAccessible) {
|
2014-08-14 13:24:08 +00:00
|
|
|
if (!aAccessible) {
|
|
|
|
return '[ null ]';
|
|
|
|
}
|
|
|
|
|
2012-06-20 21:07:51 +00:00
|
|
|
try {
|
2014-08-14 13:24:08 +00:00
|
|
|
return'[ ' + Utils.AccRetrieval.getStringRole(aAccessible.role) +
|
2012-06-20 21:07:51 +00:00
|
|
|
' | ' + aAccessible.name + ' ]';
|
|
|
|
} catch (x) {
|
2014-08-14 13:24:08 +00:00
|
|
|
return '[ defunct ]';
|
2012-06-20 21:07:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
eventToString: function eventToString(aEvent) {
|
2012-08-27 03:14:42 +00:00
|
|
|
let str = Utils.AccRetrieval.getStringEventType(aEvent.eventType);
|
2013-11-19 18:17:43 +00:00
|
|
|
if (aEvent.eventType == Events.STATE_CHANGE) {
|
2012-06-20 21:07:51 +00:00
|
|
|
let event = aEvent.QueryInterface(Ci.nsIAccessibleStateChangeEvent);
|
2013-01-19 15:38:01 +00:00
|
|
|
let stateStrings = event.isExtraState ?
|
2012-08-27 03:14:42 +00:00
|
|
|
Utils.AccRetrieval.getStringStates(0, event.state) :
|
|
|
|
Utils.AccRetrieval.getStringStates(event.state, 0);
|
2012-06-20 21:07:51 +00:00
|
|
|
str += ' (' + stateStrings.item(0) + ')';
|
|
|
|
}
|
|
|
|
|
2014-02-26 21:31:09 +00:00
|
|
|
if (aEvent.eventType == Events.VIRTUALCURSOR_CHANGED) {
|
|
|
|
let event = aEvent.QueryInterface(
|
|
|
|
Ci.nsIAccessibleVirtualCursorChangeEvent);
|
|
|
|
let pivot = aEvent.accessible.QueryInterface(
|
|
|
|
Ci.nsIAccessibleDocument).virtualCursor;
|
|
|
|
str += ' (' + this.accessibleToString(event.oldAccessible) + ' -> ' +
|
|
|
|
this.accessibleToString(pivot.position) + ')';
|
|
|
|
}
|
|
|
|
|
2012-06-20 21:07:51 +00:00
|
|
|
return str;
|
2012-07-20 16:46:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
statesToString: function statesToString(aAccessible) {
|
2014-01-28 00:35:13 +00:00
|
|
|
return Utils.getState(aAccessible).toString();
|
2012-07-20 16:46:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
dumpTree: function dumpTree(aLogLevel, aRootAccessible) {
|
2014-08-06 13:38:56 +00:00
|
|
|
if (aLogLevel < this.logLevel) {
|
2012-07-20 16:46:54 +00:00
|
|
|
return;
|
2014-08-06 13:38:56 +00:00
|
|
|
}
|
2012-07-20 16:46:54 +00:00
|
|
|
|
|
|
|
this._dumpTreeInternal(aLogLevel, aRootAccessible, 0);
|
|
|
|
},
|
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
_dumpTreeInternal:
|
|
|
|
function _dumpTreeInternal(aLogLevel, aAccessible, aIndent) {
|
|
|
|
let indentStr = '';
|
|
|
|
for (let i = 0; i < aIndent; i++) {
|
|
|
|
indentStr += ' ';
|
|
|
|
}
|
|
|
|
this.log(aLogLevel, indentStr,
|
|
|
|
this.accessibleToString(aAccessible),
|
|
|
|
'(' + this.statesToString(aAccessible) + ')');
|
|
|
|
for (let i = 0; i < aAccessible.childCount; i++) {
|
|
|
|
this._dumpTreeInternal(aLogLevel, aAccessible.getChildAt(i),
|
|
|
|
aIndent + 1);
|
|
|
|
}
|
2012-07-20 16:46:54 +00:00
|
|
|
}
|
2012-06-20 21:07:51 +00:00
|
|
|
};
|
2013-04-04 22:16:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* PivotContext: An object that generates and caches context information
|
|
|
|
* for a given accessible and its relationship with another accessible.
|
2013-10-14 19:56:19 +00:00
|
|
|
*
|
|
|
|
* If the given accessible is a label for a nested control, then this
|
|
|
|
* context will represent the nested control instead of the label.
|
|
|
|
* With the exception of bounds calculation, which will use the containing
|
|
|
|
* label. In this case the |accessible| field would be the embedded control,
|
|
|
|
* and the |accessibleForBounds| field would be the label.
|
2013-04-04 22:16:37 +00:00
|
|
|
*/
|
2014-08-06 13:38:56 +00:00
|
|
|
this.PivotContext = function PivotContext(aAccessible, aOldAccessible, // jshint ignore:line
|
2013-08-21 16:40:06 +00:00
|
|
|
aStartOffset, aEndOffset, aIgnoreAncestry = false,
|
|
|
|
aIncludeInvisible = false) {
|
2013-04-04 22:16:37 +00:00
|
|
|
this._accessible = aAccessible;
|
2013-10-14 19:56:19 +00:00
|
|
|
this._nestedControl = Utils.getEmbeddedControl(aAccessible);
|
2013-04-04 22:16:37 +00:00
|
|
|
this._oldAccessible =
|
|
|
|
this._isDefunct(aOldAccessible) ? null : aOldAccessible;
|
2013-07-24 21:52:57 +00:00
|
|
|
this.startOffset = aStartOffset;
|
|
|
|
this.endOffset = aEndOffset;
|
2013-08-21 16:40:06 +00:00
|
|
|
this._ignoreAncestry = aIgnoreAncestry;
|
|
|
|
this._includeInvisible = aIncludeInvisible;
|
2014-08-06 13:38:56 +00:00
|
|
|
};
|
2013-04-04 22:16:37 +00:00
|
|
|
|
|
|
|
PivotContext.prototype = {
|
|
|
|
get accessible() {
|
2013-10-14 19:56:19 +00:00
|
|
|
// If the current pivot accessible has a nested control,
|
|
|
|
// make this context use it publicly.
|
|
|
|
return this._nestedControl || this._accessible;
|
2013-04-04 22:16:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get oldAccessible() {
|
|
|
|
return this._oldAccessible;
|
|
|
|
},
|
|
|
|
|
2013-10-14 19:56:19 +00:00
|
|
|
get isNestedControl() {
|
|
|
|
return !!this._nestedControl;
|
|
|
|
},
|
|
|
|
|
|
|
|
get accessibleForBounds() {
|
|
|
|
return this._accessible;
|
|
|
|
},
|
|
|
|
|
2013-07-24 21:52:57 +00:00
|
|
|
get textAndAdjustedOffsets() {
|
|
|
|
if (this.startOffset === -1 && this.endOffset === -1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._textAndAdjustedOffsets) {
|
|
|
|
let result = {startOffset: this.startOffset,
|
|
|
|
endOffset: this.endOffset,
|
|
|
|
text: this._accessible.QueryInterface(Ci.nsIAccessibleText).
|
2014-08-06 13:38:56 +00:00
|
|
|
getText(0,
|
|
|
|
Ci.nsIAccessibleText.TEXT_OFFSET_END_OF_TEXT)};
|
|
|
|
let hypertextAcc = this._accessible.QueryInterface(
|
|
|
|
Ci.nsIAccessibleHyperText);
|
2013-07-24 21:52:57 +00:00
|
|
|
|
|
|
|
// Iterate through the links in backwards order so text replacements don't
|
|
|
|
// affect the offsets of links yet to be processed.
|
|
|
|
for (let i = hypertextAcc.linkCount - 1; i >= 0; i--) {
|
|
|
|
let link = hypertextAcc.getLinkAt(i);
|
|
|
|
let linkText = '';
|
|
|
|
if (link instanceof Ci.nsIAccessibleText) {
|
|
|
|
linkText = link.QueryInterface(Ci.nsIAccessibleText).
|
2014-08-06 13:38:56 +00:00
|
|
|
getText(0,
|
|
|
|
Ci.nsIAccessibleText.TEXT_OFFSET_END_OF_TEXT);
|
2013-07-24 21:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let start = link.startIndex;
|
|
|
|
let end = link.endIndex;
|
|
|
|
for (let offset of ['startOffset', 'endOffset']) {
|
|
|
|
if (this[offset] >= end) {
|
|
|
|
result[offset] += linkText.length - (end - start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.text = result.text.substring(0, start) + linkText +
|
|
|
|
result.text.substring(end);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._textAndAdjustedOffsets = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._textAndAdjustedOffsets;
|
|
|
|
},
|
|
|
|
|
2013-06-27 21:15:36 +00:00
|
|
|
/**
|
|
|
|
* Get a list of |aAccessible|'s ancestry up to the root.
|
|
|
|
* @param {nsIAccessible} aAccessible.
|
|
|
|
* @return {Array} Ancestry list.
|
|
|
|
*/
|
|
|
|
_getAncestry: function _getAncestry(aAccessible) {
|
|
|
|
let ancestry = [];
|
|
|
|
let parent = aAccessible;
|
2014-03-05 01:49:27 +00:00
|
|
|
try {
|
|
|
|
while (parent && (parent = parent.parent)) {
|
|
|
|
ancestry.push(parent);
|
|
|
|
}
|
2014-04-15 18:24:57 +00:00
|
|
|
} catch (x) {
|
2014-03-05 01:49:27 +00:00
|
|
|
// A defunct accessible will raise an exception geting parent.
|
|
|
|
Logger.debug('Failed to get parent:', x);
|
2013-06-27 21:15:36 +00:00
|
|
|
}
|
|
|
|
return ancestry.reverse();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of the old accessible's ancestry.
|
|
|
|
*/
|
|
|
|
get oldAncestry() {
|
|
|
|
if (!this._oldAncestry) {
|
2013-08-21 16:40:06 +00:00
|
|
|
if (!this._oldAccessible || this._ignoreAncestry) {
|
2013-06-27 21:15:36 +00:00
|
|
|
this._oldAncestry = [];
|
|
|
|
} else {
|
|
|
|
this._oldAncestry = this._getAncestry(this._oldAccessible);
|
|
|
|
this._oldAncestry.push(this._oldAccessible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this._oldAncestry;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of the current accessible's ancestry.
|
|
|
|
*/
|
|
|
|
get currentAncestry() {
|
|
|
|
if (!this._currentAncestry) {
|
2013-08-21 16:40:06 +00:00
|
|
|
this._currentAncestry = this._ignoreAncestry ? [] :
|
2013-10-14 19:56:19 +00:00
|
|
|
this._getAncestry(this.accessible);
|
2013-06-27 21:15:36 +00:00
|
|
|
}
|
|
|
|
return this._currentAncestry;
|
|
|
|
},
|
|
|
|
|
2013-04-04 22:16:37 +00:00
|
|
|
/*
|
|
|
|
* This is a list of the accessible's ancestry up to the common ancestor
|
|
|
|
* of the accessible and the old accessible. It is useful for giving the
|
|
|
|
* user context as to where they are in the heirarchy.
|
|
|
|
*/
|
|
|
|
get newAncestry() {
|
|
|
|
if (!this._newAncestry) {
|
2014-08-06 13:38:56 +00:00
|
|
|
this._newAncestry = this._ignoreAncestry ? [] : [currentAncestor for ( // jshint ignore:line
|
|
|
|
[index, currentAncestor] of Iterator(this.currentAncestry)) if ( // jshint ignore:line
|
|
|
|
currentAncestor !== this.oldAncestry[index])]; // jshint ignore:line
|
2013-04-04 22:16:37 +00:00
|
|
|
}
|
|
|
|
return this._newAncestry;
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Traverse the accessible's subtree in pre or post order.
|
|
|
|
* It only includes the accessible's visible chidren.
|
2013-06-10 20:31:17 +00:00
|
|
|
* Note: needSubtree is a function argument that can be used to determine
|
|
|
|
* whether aAccessible's subtree is required.
|
2013-04-04 22:16:37 +00:00
|
|
|
*/
|
2014-08-06 13:38:56 +00:00
|
|
|
_traverse: function* _traverse(aAccessible, aPreorder, aStop) {
|
2013-06-10 20:31:17 +00:00
|
|
|
if (aStop && aStop(aAccessible)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-04 22:16:37 +00:00
|
|
|
let child = aAccessible.firstChild;
|
|
|
|
while (child) {
|
2013-08-21 16:40:06 +00:00
|
|
|
let include;
|
|
|
|
if (this._includeInvisible) {
|
|
|
|
include = true;
|
|
|
|
} else {
|
2014-08-28 13:07:30 +00:00
|
|
|
include = !Utils.isHidden(child);
|
2013-08-21 16:40:06 +00:00
|
|
|
}
|
|
|
|
if (include) {
|
2013-06-10 20:31:17 +00:00
|
|
|
if (aPreorder) {
|
|
|
|
yield child;
|
2014-08-06 13:38:56 +00:00
|
|
|
[yield node for (node of this._traverse(child, aPreorder, aStop))]; // jshint ignore:line
|
2013-06-10 20:31:17 +00:00
|
|
|
} else {
|
2014-08-06 13:38:56 +00:00
|
|
|
[yield node for (node of this._traverse(child, aPreorder, aStop))]; // jshint ignore:line
|
2013-06-10 20:31:17 +00:00
|
|
|
yield child;
|
|
|
|
}
|
2013-04-04 22:16:37 +00:00
|
|
|
}
|
|
|
|
child = child.nextSibling;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
2013-06-10 20:31:17 +00:00
|
|
|
* A subtree generator function, used to generate a flattened
|
|
|
|
* list of the accessible's subtree in pre or post order.
|
2013-04-04 22:16:37 +00:00
|
|
|
* It only includes the accessible's visible chidren.
|
2013-06-10 20:31:17 +00:00
|
|
|
* @param {boolean} aPreorder A flag for traversal order. If true, traverse
|
|
|
|
* in preorder; if false, traverse in postorder.
|
|
|
|
* @param {function} aStop An optional function, indicating whether subtree
|
|
|
|
* traversal should stop.
|
2013-04-04 22:16:37 +00:00
|
|
|
*/
|
2013-06-10 20:31:17 +00:00
|
|
|
subtreeGenerator: function subtreeGenerator(aPreorder, aStop) {
|
2013-10-14 19:56:19 +00:00
|
|
|
return this._traverse(this.accessible, aPreorder, aStop);
|
2013-04-04 22:16:37 +00:00
|
|
|
},
|
|
|
|
|
2013-06-27 21:15:36 +00:00
|
|
|
getCellInfo: function getCellInfo(aAccessible) {
|
|
|
|
if (!this._cells) {
|
|
|
|
this._cells = new WeakMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
let domNode = aAccessible.DOMNode;
|
|
|
|
if (this._cells.has(domNode)) {
|
|
|
|
return this._cells.get(domNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
let cellInfo = {};
|
|
|
|
let getAccessibleCell = function getAccessibleCell(aAccessible) {
|
|
|
|
if (!aAccessible) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-11-19 18:17:43 +00:00
|
|
|
if ([Roles.CELL, Roles.COLUMNHEADER, Roles.ROWHEADER].indexOf(
|
2013-07-02 03:50:39 +00:00
|
|
|
aAccessible.role) < 0) {
|
|
|
|
return null;
|
2013-06-27 21:15:36 +00:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
return aAccessible.QueryInterface(Ci.nsIAccessibleTableCell);
|
|
|
|
} catch (x) {
|
|
|
|
Logger.logException(x);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
2014-08-06 13:38:56 +00:00
|
|
|
let getHeaders = function* getHeaders(aHeaderCells) {
|
2013-06-27 21:15:36 +00:00
|
|
|
let enumerator = aHeaderCells.enumerate();
|
|
|
|
while (enumerator.hasMoreElements()) {
|
|
|
|
yield enumerator.getNext().QueryInterface(Ci.nsIAccessible).name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
cellInfo.current = getAccessibleCell(aAccessible);
|
|
|
|
|
|
|
|
if (!cellInfo.current) {
|
|
|
|
Logger.warning(aAccessible,
|
|
|
|
'does not support nsIAccessibleTableCell interface.');
|
|
|
|
this._cells.set(domNode, null);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let table = cellInfo.current.table;
|
|
|
|
if (table.isProbablyForLayout()) {
|
|
|
|
this._cells.set(domNode, null);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
cellInfo.previous = null;
|
|
|
|
let oldAncestry = this.oldAncestry.reverse();
|
|
|
|
let ancestor = oldAncestry.shift();
|
|
|
|
while (!cellInfo.previous && ancestor) {
|
|
|
|
let cell = getAccessibleCell(ancestor);
|
|
|
|
if (cell && cell.table === table) {
|
|
|
|
cellInfo.previous = cell;
|
|
|
|
}
|
|
|
|
ancestor = oldAncestry.shift();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cellInfo.previous) {
|
|
|
|
cellInfo.rowChanged = cellInfo.current.rowIndex !==
|
|
|
|
cellInfo.previous.rowIndex;
|
|
|
|
cellInfo.columnChanged = cellInfo.current.columnIndex !==
|
|
|
|
cellInfo.previous.columnIndex;
|
|
|
|
} else {
|
|
|
|
cellInfo.rowChanged = true;
|
|
|
|
cellInfo.columnChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
cellInfo.rowExtent = cellInfo.current.rowExtent;
|
|
|
|
cellInfo.columnExtent = cellInfo.current.columnExtent;
|
|
|
|
cellInfo.columnIndex = cellInfo.current.columnIndex;
|
|
|
|
cellInfo.rowIndex = cellInfo.current.rowIndex;
|
|
|
|
|
|
|
|
cellInfo.columnHeaders = [];
|
|
|
|
if (cellInfo.columnChanged && cellInfo.current.role !==
|
2013-11-19 18:17:43 +00:00
|
|
|
Roles.COLUMNHEADER) {
|
2014-08-06 13:38:56 +00:00
|
|
|
cellInfo.columnHeaders = [headers for (headers of getHeaders( // jshint ignore:line
|
2013-06-27 21:15:36 +00:00
|
|
|
cellInfo.current.columnHeaderCells))];
|
|
|
|
}
|
|
|
|
cellInfo.rowHeaders = [];
|
2013-11-19 18:17:43 +00:00
|
|
|
if (cellInfo.rowChanged && cellInfo.current.role === Roles.CELL) {
|
2014-08-06 13:38:56 +00:00
|
|
|
cellInfo.rowHeaders = [headers for (headers of getHeaders( // jshint ignore:line
|
2013-06-27 21:15:36 +00:00
|
|
|
cellInfo.current.rowHeaderCells))];
|
|
|
|
}
|
|
|
|
|
|
|
|
this._cells.set(domNode, cellInfo);
|
|
|
|
return cellInfo;
|
|
|
|
},
|
|
|
|
|
2013-04-04 22:16:37 +00:00
|
|
|
get bounds() {
|
|
|
|
if (!this._bounds) {
|
2013-10-14 19:56:19 +00:00
|
|
|
this._bounds = Utils.getBounds(this.accessibleForBounds);
|
2013-04-04 22:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this._bounds.clone();
|
|
|
|
},
|
|
|
|
|
|
|
|
_isDefunct: function _isDefunct(aAccessible) {
|
|
|
|
try {
|
2014-01-28 00:35:13 +00:00
|
|
|
return Utils.getState(aAccessible).contains(States.DEFUNCT);
|
2013-04-04 22:16:37 +00:00
|
|
|
} catch (x) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-05-24 18:57:28 +00:00
|
|
|
};
|
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
this.PrefCache = function PrefCache(aName, aCallback, aRunCallbackNow) { // jshint ignore:line
|
2013-05-24 18:57:28 +00:00
|
|
|
this.name = aName;
|
|
|
|
this.callback = aCallback;
|
|
|
|
|
|
|
|
let branch = Services.prefs;
|
|
|
|
this.value = this._getValue(branch);
|
|
|
|
|
|
|
|
if (this.callback && aRunCallbackNow) {
|
|
|
|
try {
|
2014-10-14 21:42:50 +00:00
|
|
|
this.callback(this.name, this.value, true);
|
2013-05-24 18:57:28 +00:00
|
|
|
} catch (x) {
|
|
|
|
Logger.logException(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
branch.addObserver(aName, this, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
PrefCache.prototype = {
|
|
|
|
_getValue: function _getValue(aBranch) {
|
2014-03-04 18:10:38 +00:00
|
|
|
try {
|
|
|
|
if (!this.type) {
|
|
|
|
this.type = aBranch.getPrefType(this.name);
|
|
|
|
}
|
|
|
|
switch (this.type) {
|
|
|
|
case Ci.nsIPrefBranch.PREF_STRING:
|
|
|
|
return aBranch.getCharPref(this.name);
|
|
|
|
case Ci.nsIPrefBranch.PREF_INT:
|
|
|
|
return aBranch.getIntPref(this.name);
|
|
|
|
case Ci.nsIPrefBranch.PREF_BOOL:
|
|
|
|
return aBranch.getBoolPref(this.name);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (x) {
|
|
|
|
// Pref does not exist.
|
|
|
|
return null;
|
2013-05-24 18:57:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
observe: function observe(aSubject) {
|
2013-05-24 18:57:28 +00:00
|
|
|
this.value = this._getValue(aSubject.QueryInterface(Ci.nsIPrefBranch));
|
2014-10-14 21:42:50 +00:00
|
|
|
Logger.info('pref changed', this.name, this.value);
|
2013-05-24 18:57:28 +00:00
|
|
|
if (this.callback) {
|
|
|
|
try {
|
2014-10-14 21:42:50 +00:00
|
|
|
this.callback(this.name, this.value, false);
|
2013-05-24 18:57:28 +00:00
|
|
|
} catch (x) {
|
|
|
|
Logger.logException(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface : XPCOMUtils.generateQI([Ci.nsIObserver,
|
|
|
|
Ci.nsISupportsWeakReference])
|
2013-07-17 20:41:29 +00:00
|
|
|
};
|
2014-01-23 18:37:38 +00:00
|
|
|
|
2014-08-06 13:38:56 +00:00
|
|
|
this.SettingCache = function SettingCache(aName, aCallback, aOptions = {}) { // jshint ignore:line
|
2014-01-23 18:37:38 +00:00
|
|
|
this.value = aOptions.defaultValue;
|
|
|
|
let runCallback = () => {
|
2014-01-23 21:44:13 +00:00
|
|
|
if (aCallback) {
|
2014-01-23 18:37:38 +00:00
|
|
|
aCallback(aName, this.value);
|
|
|
|
if (aOptions.callbackOnce) {
|
|
|
|
runCallback = () => {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let settings = Utils.win.navigator.mozSettings;
|
|
|
|
if (!settings) {
|
2014-01-23 21:44:13 +00:00
|
|
|
if (aOptions.callbackNow) {
|
|
|
|
runCallback();
|
|
|
|
}
|
2014-01-23 18:37:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let lock = settings.createLock();
|
|
|
|
let req = lock.get(aName);
|
|
|
|
|
|
|
|
req.addEventListener('success', () => {
|
2014-08-06 13:38:56 +00:00
|
|
|
this.value = req.result[aName] === undefined ?
|
|
|
|
aOptions.defaultValue : req.result[aName];
|
2014-01-23 21:44:13 +00:00
|
|
|
if (aOptions.callbackNow) {
|
|
|
|
runCallback();
|
|
|
|
}
|
2014-01-23 18:37:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
settings.addObserver(aName,
|
|
|
|
(evt) => {
|
|
|
|
this.value = evt.settingValue;
|
|
|
|
runCallback();
|
|
|
|
});
|
|
|
|
};
|