2012-04-13 23:18:57 +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/. */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
2013-06-17 14:36:41 +00:00
|
|
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'Utils',
|
|
|
|
'resource://gre/modules/accessibility/Utils.jsm');
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'Logger',
|
|
|
|
'resource://gre/modules/accessibility/Utils.jsm');
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'PivotContext',
|
|
|
|
'resource://gre/modules/accessibility/Utils.jsm');
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'UtteranceGenerator',
|
|
|
|
'resource://gre/modules/accessibility/OutputGenerator.jsm');
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'BrailleGenerator',
|
|
|
|
'resource://gre/modules/accessibility/OutputGenerator.jsm');
|
2013-11-27 00:53:45 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'Roles',
|
|
|
|
'resource://gre/modules/accessibility/Constants.jsm');
|
2014-01-28 00:35:13 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, 'States',
|
|
|
|
'resource://gre/modules/accessibility/Constants.jsm');
|
2012-04-13 23:18:57 +00:00
|
|
|
|
2012-12-07 18:39:17 +00:00
|
|
|
this.EXPORTED_SYMBOLS = ['Presentation'];
|
2012-04-13 23:18:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The interface for all presenter classes. A presenter could be, for example,
|
|
|
|
* a speech output module, or a visual cursor indicator.
|
|
|
|
*/
|
|
|
|
function Presenter() {}
|
|
|
|
|
|
|
|
Presenter.prototype = {
|
2012-10-01 20:33:26 +00:00
|
|
|
/**
|
|
|
|
* The type of presenter. Used for matching it with the appropriate output method.
|
|
|
|
*/
|
|
|
|
type: 'Base',
|
|
|
|
|
2012-04-13 23:18:57 +00:00
|
|
|
/**
|
|
|
|
* The virtual cursor's position changed.
|
2013-04-04 22:16:37 +00:00
|
|
|
* @param {PivotContext} aContext the context object for the new pivot
|
2012-05-18 18:56:38 +00:00
|
|
|
* position.
|
2012-06-25 17:34:52 +00:00
|
|
|
* @param {int} aReason the reason for the pivot change.
|
|
|
|
* See nsIAccessiblePivot.
|
2012-04-13 23:18:57 +00:00
|
|
|
*/
|
2012-06-25 17:34:52 +00:00
|
|
|
pivotChanged: function pivotChanged(aContext, aReason) {},
|
2012-04-13 23:18:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An object's action has been invoked.
|
|
|
|
* @param {nsIAccessible} aObject the object that has been invoked.
|
|
|
|
* @param {string} aActionName the name of the action.
|
|
|
|
*/
|
|
|
|
actionInvoked: function actionInvoked(aObject, aActionName) {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text has changed, either by the user or by the system. TODO.
|
|
|
|
*/
|
2012-05-14 21:21:59 +00:00
|
|
|
textChanged: function textChanged(aIsInserted, aStartOffset,
|
|
|
|
aLength, aText,
|
|
|
|
aModifiedText) {},
|
2012-04-13 23:18:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Text selection has changed. TODO.
|
|
|
|
*/
|
2013-07-11 19:55:40 +00:00
|
|
|
textSelectionChanged: function textSelectionChanged(aText, aStart, aEnd, aOldStart, aOldEnd, aIsFromUser) {},
|
2012-04-13 23:18:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Selection has changed. TODO.
|
|
|
|
* @param {nsIAccessible} aObject the object that has been selected.
|
|
|
|
*/
|
|
|
|
selectionChanged: function selectionChanged(aObject) {},
|
|
|
|
|
2014-03-19 17:08:54 +00:00
|
|
|
/**
|
|
|
|
* Value has changed.
|
|
|
|
* @param {nsIAccessible} aAccessible the object whose value has changed.
|
|
|
|
*/
|
|
|
|
valueChanged: function valueChanged(aAccessible) {},
|
|
|
|
|
2012-04-13 23:18:57 +00:00
|
|
|
/**
|
2012-05-07 16:44:44 +00:00
|
|
|
* The tab, or the tab's document state has changed.
|
|
|
|
* @param {nsIAccessible} aDocObj the tab document accessible that has had its
|
|
|
|
* state changed, or null if the tab has no associated document yet.
|
|
|
|
* @param {string} aPageState the state name for the tab, valid states are:
|
|
|
|
* 'newtab', 'loading', 'newdoc', 'loaded', 'stopped', and 'reload'.
|
2012-04-13 23:18:57 +00:00
|
|
|
*/
|
2012-05-07 16:44:44 +00:00
|
|
|
tabStateChanged: function tabStateChanged(aDocObj, aPageState) {},
|
2012-04-13 23:18:57 +00:00
|
|
|
|
|
|
|
/**
|
2012-05-07 16:44:44 +00:00
|
|
|
* The current tab has changed.
|
2013-04-04 22:16:37 +00:00
|
|
|
* @param {PivotContext} aDocContext context object for tab's
|
2012-05-18 18:56:38 +00:00
|
|
|
* document.
|
2013-04-04 22:16:37 +00:00
|
|
|
* @param {PivotContext} aVCContext context object for tab's current
|
2012-05-18 18:56:38 +00:00
|
|
|
* virtual cursor position.
|
2012-04-13 23:18:57 +00:00
|
|
|
*/
|
2012-05-18 18:56:38 +00:00
|
|
|
tabSelected: function tabSelected(aDocContext, aVCContext) {},
|
2012-04-13 23:18:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The viewport has changed, either a scroll, pan, zoom, or
|
|
|
|
* landscape/portrait toggle.
|
2012-10-01 20:33:26 +00:00
|
|
|
* @param {Window} aWindow window of viewport that changed.
|
2012-04-13 23:18:57 +00:00
|
|
|
*/
|
2012-10-01 20:33:26 +00:00
|
|
|
viewportChanged: function viewportChanged(aWindow) {},
|
2012-07-10 23:10:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We have entered or left text editing mode.
|
|
|
|
*/
|
2012-12-07 18:39:17 +00:00
|
|
|
editingModeChanged: function editingModeChanged(aIsEditing) {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Announce something. Typically an app state change.
|
|
|
|
*/
|
2013-08-21 16:40:06 +00:00
|
|
|
announce: function announce(aAnnouncement) {},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Announce a live region.
|
|
|
|
* @param {PivotContext} aContext context object for an accessible.
|
|
|
|
* @param {boolean} aIsPolite A politeness level for a live region.
|
|
|
|
* @param {boolean} aIsHide An indicator of hide/remove event.
|
|
|
|
* @param {string} aModifiedText Optional modified text.
|
|
|
|
*/
|
|
|
|
liveRegion: function liveRegionShown(aContext, aIsPolite, aIsHide,
|
|
|
|
aModifiedText) {}
|
2012-04-13 23:18:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Visual presenter. Draws a box around the virtual cursor's position.
|
|
|
|
*/
|
|
|
|
|
2013-07-03 22:02:44 +00:00
|
|
|
this.VisualPresenter = function VisualPresenter() {
|
|
|
|
this._displayedAccessibles = new WeakMap();
|
|
|
|
};
|
2012-04-13 23:18:57 +00:00
|
|
|
|
2012-05-14 21:21:59 +00:00
|
|
|
VisualPresenter.prototype = {
|
|
|
|
__proto__: Presenter.prototype,
|
2012-04-13 23:18:57 +00:00
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
type: 'Visual',
|
|
|
|
|
2012-05-14 21:21:59 +00:00
|
|
|
/**
|
|
|
|
* The padding in pixels between the object and the highlight border.
|
|
|
|
*/
|
|
|
|
BORDER_PADDING: 2,
|
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
viewportChanged: function VisualPresenter_viewportChanged(aWindow) {
|
2013-07-24 21:52:57 +00:00
|
|
|
let currentDisplay = this._displayedAccessibles.get(aWindow);
|
|
|
|
if (!currentDisplay) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let currentAcc = currentDisplay.accessible;
|
|
|
|
let start = currentDisplay.startOffset;
|
|
|
|
let end = currentDisplay.endOffset;
|
2013-07-03 22:02:44 +00:00
|
|
|
if (Utils.isAliveAndVisible(currentAcc)) {
|
2013-07-24 21:52:57 +00:00
|
|
|
let bounds = (start === -1 && end === -1) ? Utils.getBounds(currentAcc) :
|
|
|
|
Utils.getTextBounds(currentAcc, start, end);
|
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: {
|
2012-12-07 18:39:17 +00:00
|
|
|
method: 'showBounds',
|
2013-07-03 22:02:44 +00:00
|
|
|
bounds: bounds,
|
2012-10-01 20:33:26 +00:00
|
|
|
padding: this.BORDER_PADDING
|
|
|
|
}
|
|
|
|
};
|
2012-10-17 17:23:26 +00:00
|
|
|
}
|
2012-10-01 20:33:26 +00:00
|
|
|
|
|
|
|
return null;
|
2012-05-14 21:21:59 +00:00
|
|
|
},
|
|
|
|
|
2012-06-25 17:34:52 +00:00
|
|
|
pivotChanged: function VisualPresenter_pivotChanged(aContext, aReason) {
|
2014-02-18 18:19:50 +00:00
|
|
|
if (!aContext.accessible) {
|
|
|
|
// XXX: Don't hide because another vc may be using the highlight.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-07-03 22:02:44 +00:00
|
|
|
this._displayedAccessibles.set(aContext.accessible.document.window,
|
2013-10-14 19:56:19 +00:00
|
|
|
{ accessible: aContext.accessibleForBounds,
|
2013-07-24 21:52:57 +00:00
|
|
|
startOffset: aContext.startOffset,
|
|
|
|
endOffset: aContext.endOffset });
|
2012-05-14 21:21:59 +00:00
|
|
|
|
|
|
|
try {
|
2013-10-14 19:56:19 +00:00
|
|
|
aContext.accessibleForBounds.scrollTo(
|
2012-05-18 18:56:38 +00:00
|
|
|
Ci.nsIAccessibleScrollType.SCROLL_TYPE_ANYWHERE);
|
2013-07-24 21:52:57 +00:00
|
|
|
|
|
|
|
let bounds = (aContext.startOffset === -1 && aContext.endOffset === -1) ?
|
2013-10-14 19:56:19 +00:00
|
|
|
aContext.bounds : Utils.getTextBounds(aContext.accessibleForBounds,
|
|
|
|
aContext.startOffset,
|
|
|
|
aContext.endOffset);
|
2013-07-24 21:52:57 +00:00
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: {
|
2012-12-07 18:39:17 +00:00
|
|
|
method: 'showBounds',
|
2013-07-24 21:52:57 +00:00
|
|
|
bounds: bounds,
|
2012-10-01 20:33:26 +00:00
|
|
|
padding: this.BORDER_PADDING
|
|
|
|
}
|
|
|
|
};
|
2012-05-14 21:21:59 +00:00
|
|
|
} catch (e) {
|
2013-06-27 21:15:36 +00:00
|
|
|
Logger.logException(e, 'Failed to get bounds');
|
2012-10-01 20:33:26 +00:00
|
|
|
return null;
|
2012-05-14 21:21:59 +00:00
|
|
|
}
|
|
|
|
},
|
2012-04-13 23:18:57 +00:00
|
|
|
|
2012-05-18 18:56:38 +00:00
|
|
|
tabSelected: function VisualPresenter_tabSelected(aDocContext, aVCContext) {
|
2012-10-01 20:33:26 +00:00
|
|
|
return this.pivotChanged(aVCContext, Ci.nsIAccessiblePivot.REASON_NONE);
|
2012-05-14 21:21:59 +00:00
|
|
|
},
|
2012-04-13 23:18:57 +00:00
|
|
|
|
2012-05-14 21:21:59 +00:00
|
|
|
tabStateChanged: function VisualPresenter_tabStateChanged(aDocObj,
|
|
|
|
aPageState) {
|
|
|
|
if (aPageState == 'newdoc')
|
2012-12-07 18:39:17 +00:00
|
|
|
return {type: this.type, details: {method: 'hideBounds'}};
|
2012-05-07 16:44:44 +00:00
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
return null;
|
2012-12-07 18:39:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
announce: function VisualPresenter_announce(aAnnouncement) {
|
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: {
|
|
|
|
method: 'showAnnouncement',
|
|
|
|
text: aAnnouncement,
|
|
|
|
duration: 1000
|
|
|
|
}
|
|
|
|
};
|
2012-04-13 23:18:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Android presenter. Fires Android a11y events.
|
|
|
|
*/
|
|
|
|
|
2012-11-12 23:46:09 +00:00
|
|
|
this.AndroidPresenter = function AndroidPresenter() {};
|
2012-04-13 23:18:57 +00:00
|
|
|
|
2012-05-14 21:21:59 +00:00
|
|
|
AndroidPresenter.prototype = {
|
|
|
|
__proto__: Presenter.prototype,
|
2012-04-13 23:18:57 +00:00
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
type: 'Android',
|
|
|
|
|
2012-05-14 21:21:59 +00:00
|
|
|
// Android AccessibilityEvent type constants.
|
|
|
|
ANDROID_VIEW_CLICKED: 0x01,
|
|
|
|
ANDROID_VIEW_LONG_CLICKED: 0x02,
|
|
|
|
ANDROID_VIEW_SELECTED: 0x04,
|
|
|
|
ANDROID_VIEW_FOCUSED: 0x08,
|
|
|
|
ANDROID_VIEW_TEXT_CHANGED: 0x10,
|
|
|
|
ANDROID_WINDOW_STATE_CHANGED: 0x20,
|
2012-06-25 17:34:52 +00:00
|
|
|
ANDROID_VIEW_HOVER_ENTER: 0x80,
|
|
|
|
ANDROID_VIEW_HOVER_EXIT: 0x100,
|
2012-06-25 17:34:52 +00:00
|
|
|
ANDROID_VIEW_SCROLLED: 0x1000,
|
2013-06-19 20:11:46 +00:00
|
|
|
ANDROID_VIEW_TEXT_SELECTION_CHANGED: 0x2000,
|
2012-08-20 22:29:22 +00:00
|
|
|
ANDROID_ANNOUNCEMENT: 0x4000,
|
|
|
|
ANDROID_VIEW_ACCESSIBILITY_FOCUSED: 0x8000,
|
2013-06-19 20:11:46 +00:00
|
|
|
ANDROID_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY: 0x20000,
|
2012-06-25 17:34:52 +00:00
|
|
|
|
2012-06-25 17:34:52 +00:00
|
|
|
pivotChanged: function AndroidPresenter_pivotChanged(aContext, aReason) {
|
2012-05-22 18:01:39 +00:00
|
|
|
if (!aContext.accessible)
|
2012-10-01 20:33:26 +00:00
|
|
|
return null;
|
2012-05-22 18:01:39 +00:00
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
let androidEvents = [];
|
|
|
|
|
2012-06-25 17:34:52 +00:00
|
|
|
let isExploreByTouch = (aReason == Ci.nsIAccessiblePivot.REASON_POINT &&
|
|
|
|
Utils.AndroidSdkVersion >= 14);
|
2012-08-20 22:29:22 +00:00
|
|
|
let focusEventType = (Utils.AndroidSdkVersion >= 16) ?
|
|
|
|
this.ANDROID_VIEW_ACCESSIBILITY_FOCUSED :
|
|
|
|
this.ANDROID_VIEW_FOCUSED;
|
2012-06-25 17:34:52 +00:00
|
|
|
|
|
|
|
if (isExploreByTouch) {
|
|
|
|
// This isn't really used by TalkBack so this is a half-hearted attempt
|
|
|
|
// for now.
|
2012-10-01 20:33:26 +00:00
|
|
|
androidEvents.push({eventType: this.ANDROID_VIEW_HOVER_EXIT, text: []});
|
2012-06-25 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 19:55:40 +00:00
|
|
|
let brailleOutput = {};
|
2013-06-17 14:36:41 +00:00
|
|
|
if (Utils.AndroidSdkVersion >= 16) {
|
|
|
|
if (!this._braillePresenter) {
|
|
|
|
this._braillePresenter = new BraillePresenter();
|
|
|
|
}
|
2013-07-11 19:55:40 +00:00
|
|
|
brailleOutput = this._braillePresenter.pivotChanged(aContext, aReason).
|
2013-07-03 22:20:11 +00:00
|
|
|
details;
|
2013-06-17 14:36:41 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 21:52:57 +00:00
|
|
|
if (aReason === Ci.nsIAccessiblePivot.REASON_TEXT) {
|
|
|
|
if (Utils.AndroidSdkVersion >= 16) {
|
|
|
|
let adjustedText = aContext.textAndAdjustedOffsets;
|
|
|
|
|
|
|
|
androidEvents.push({
|
|
|
|
eventType: this.ANDROID_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY,
|
|
|
|
text: [adjustedText.text],
|
|
|
|
fromIndex: adjustedText.startOffset,
|
|
|
|
toIndex: adjustedText.endOffset
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2014-01-28 00:35:13 +00:00
|
|
|
let state = Utils.getState(aContext.accessible);
|
2013-07-24 21:52:57 +00:00
|
|
|
androidEvents.push({eventType: (isExploreByTouch) ?
|
|
|
|
this.ANDROID_VIEW_HOVER_ENTER : focusEventType,
|
|
|
|
text: UtteranceGenerator.genForContext(aContext).output,
|
|
|
|
bounds: aContext.bounds,
|
|
|
|
clickable: aContext.accessible.actionCount > 0,
|
2014-01-28 00:35:13 +00:00
|
|
|
checkable: state.contains(States.CHECKABLE),
|
|
|
|
checked: state.contains(States.CHECKED),
|
2013-07-24 21:52:57 +00:00
|
|
|
brailleOutput: brailleOutput});
|
|
|
|
}
|
2013-05-23 14:06:27 +00:00
|
|
|
|
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: androidEvents
|
|
|
|
};
|
2012-05-14 21:21:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
actionInvoked: function AndroidPresenter_actionInvoked(aObject, aActionName) {
|
2014-01-28 00:35:13 +00:00
|
|
|
let state = Utils.getState(aObject);
|
2013-11-27 00:53:45 +00:00
|
|
|
|
|
|
|
// Checkable objects will have a state changed event we will use instead.
|
2014-01-28 00:35:13 +00:00
|
|
|
if (state.contains(States.CHECKABLE))
|
2013-11-27 00:53:45 +00:00
|
|
|
return null;
|
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: [{
|
2012-05-14 21:21:59 +00:00
|
|
|
eventType: this.ANDROID_VIEW_CLICKED,
|
2013-05-23 14:06:27 +00:00
|
|
|
text: UtteranceGenerator.genForAction(aObject, aActionName),
|
2014-01-28 00:35:13 +00:00
|
|
|
checked: state.contains(States.CHECKED)
|
2012-10-01 20:33:26 +00:00
|
|
|
}]
|
|
|
|
};
|
2012-05-14 21:21:59 +00:00
|
|
|
},
|
|
|
|
|
2012-05-18 18:56:38 +00:00
|
|
|
tabSelected: function AndroidPresenter_tabSelected(aDocContext, aVCContext) {
|
2012-05-14 21:21:59 +00:00
|
|
|
// Send a pivot change message with the full context utterance for this doc.
|
2012-10-01 20:33:26 +00:00
|
|
|
return this.pivotChanged(aVCContext, Ci.nsIAccessiblePivot.REASON_NONE);
|
2012-05-14 21:21:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
tabStateChanged: function AndroidPresenter_tabStateChanged(aDocObj,
|
|
|
|
aPageState) {
|
2012-12-07 18:39:17 +00:00
|
|
|
return this.announce(
|
|
|
|
UtteranceGenerator.genForTabStateChange(aDocObj, aPageState).join(' '));
|
2012-05-14 21:21:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
textChanged: function AndroidPresenter_textChanged(aIsInserted, aStart,
|
|
|
|
aLength, aText,
|
|
|
|
aModifiedText) {
|
2012-10-19 20:39:37 +00:00
|
|
|
let eventDetails = {
|
|
|
|
eventType: this.ANDROID_VIEW_TEXT_CHANGED,
|
|
|
|
text: [aText],
|
|
|
|
fromIndex: aStart,
|
|
|
|
removedCount: 0,
|
|
|
|
addedCount: 0
|
2012-05-14 21:21:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (aIsInserted) {
|
2012-10-19 20:39:37 +00:00
|
|
|
eventDetails.addedCount = aLength;
|
|
|
|
eventDetails.beforeText =
|
2012-05-14 21:21:59 +00:00
|
|
|
aText.substring(0, aStart) + aText.substring(aStart + aLength);
|
|
|
|
} else {
|
2012-10-19 20:39:37 +00:00
|
|
|
eventDetails.removedCount = aLength;
|
|
|
|
eventDetails.beforeText =
|
2012-05-14 21:21:59 +00:00
|
|
|
aText.substring(0, aStart) + aModifiedText + aText.substring(aStart);
|
2012-04-13 23:18:57 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 20:39:37 +00:00
|
|
|
return {type: this.type, details: [eventDetails]};
|
2012-05-14 21:21:59 +00:00
|
|
|
},
|
2012-04-13 23:18:57 +00:00
|
|
|
|
2013-06-19 20:11:46 +00:00
|
|
|
textSelectionChanged: function AndroidPresenter_textSelectionChanged(aText, aStart,
|
|
|
|
aEnd, aOldStart,
|
2013-07-11 19:55:40 +00:00
|
|
|
aOldEnd, aIsFromUser) {
|
2013-06-19 20:11:46 +00:00
|
|
|
let androidEvents = [];
|
|
|
|
|
2013-07-11 19:55:40 +00:00
|
|
|
if (Utils.AndroidSdkVersion >= 14 && !aIsFromUser) {
|
|
|
|
if (!this._braillePresenter) {
|
|
|
|
this._braillePresenter = new BraillePresenter();
|
|
|
|
}
|
|
|
|
let brailleOutput = this._braillePresenter.textSelectionChanged(aText, aStart, aEnd,
|
|
|
|
aOldStart, aOldEnd,
|
|
|
|
aIsFromUser).details;
|
|
|
|
|
2013-06-19 20:11:46 +00:00
|
|
|
androidEvents.push({
|
|
|
|
eventType: this.ANDROID_VIEW_TEXT_SELECTION_CHANGED,
|
|
|
|
text: [aText],
|
|
|
|
fromIndex: aStart,
|
|
|
|
toIndex: aEnd,
|
2013-07-11 19:55:40 +00:00
|
|
|
itemCount: aText.length,
|
|
|
|
brailleOutput: brailleOutput
|
2013-06-19 20:11:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-07-11 19:55:40 +00:00
|
|
|
if (Utils.AndroidSdkVersion >= 16 && aIsFromUser) {
|
2013-06-19 20:11:46 +00:00
|
|
|
let [from, to] = aOldStart < aStart ? [aOldStart, aStart] : [aStart, aOldStart];
|
|
|
|
androidEvents.push({
|
|
|
|
eventType: this.ANDROID_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY,
|
|
|
|
text: [aText],
|
|
|
|
fromIndex: from,
|
|
|
|
toIndex: to
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: androidEvents
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
viewportChanged: function AndroidPresenter_viewportChanged(aWindow) {
|
2012-06-25 17:34:52 +00:00
|
|
|
if (Utils.AndroidSdkVersion < 14)
|
2012-10-01 20:33:26 +00:00
|
|
|
return null;
|
2012-06-25 17:34:52 +00:00
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: [{
|
2012-06-25 17:34:52 +00:00
|
|
|
eventType: this.ANDROID_VIEW_SCROLLED,
|
|
|
|
text: [],
|
2012-10-01 20:33:26 +00:00
|
|
|
scrollX: aWindow.scrollX,
|
|
|
|
scrollY: aWindow.scrollY,
|
|
|
|
maxScrollX: aWindow.scrollMaxX,
|
|
|
|
maxScrollY: aWindow.scrollMaxY
|
|
|
|
}]
|
|
|
|
};
|
2012-06-25 17:34:52 +00:00
|
|
|
},
|
|
|
|
|
2012-07-10 23:10:15 +00:00
|
|
|
editingModeChanged: function AndroidPresenter_editingModeChanged(aIsEditing) {
|
2012-12-07 18:39:17 +00:00
|
|
|
return this.announce(
|
|
|
|
UtteranceGenerator.genForEditingMode(aIsEditing).join(' '));
|
2012-07-10 23:10:15 +00:00
|
|
|
},
|
|
|
|
|
2012-12-07 18:39:17 +00:00
|
|
|
announce: function AndroidPresenter_announce(aAnnouncement) {
|
2012-10-01 20:33:26 +00:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: [{
|
2012-08-20 22:29:22 +00:00
|
|
|
eventType: (Utils.AndroidSdkVersion >= 16) ?
|
|
|
|
this.ANDROID_ANNOUNCEMENT : this.ANDROID_VIEW_TEXT_CHANGED,
|
2012-12-07 18:39:17 +00:00
|
|
|
text: [aAnnouncement],
|
|
|
|
addedCount: aAnnouncement.length,
|
2012-07-10 23:10:15 +00:00
|
|
|
removedCount: 0,
|
|
|
|
fromIndex: 0
|
2012-10-01 20:33:26 +00:00
|
|
|
}]
|
|
|
|
};
|
2013-08-21 16:40:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
liveRegion: function AndroidPresenter_liveRegion(aContext, aIsPolite,
|
|
|
|
aIsHide, aModifiedText) {
|
|
|
|
return this.announce(
|
|
|
|
UtteranceGenerator.genForLiveRegion(aContext, aIsHide,
|
|
|
|
aModifiedText).join(' '));
|
2012-05-14 21:21:59 +00:00
|
|
|
}
|
2012-04-13 23:18:57 +00:00
|
|
|
};
|
2012-05-18 18:56:38 +00:00
|
|
|
|
2012-07-20 16:46:54 +00:00
|
|
|
/**
|
|
|
|
* A speech presenter for direct TTS output
|
|
|
|
*/
|
|
|
|
|
2012-11-12 23:46:09 +00:00
|
|
|
this.SpeechPresenter = function SpeechPresenter() {};
|
2012-07-20 16:46:54 +00:00
|
|
|
|
|
|
|
SpeechPresenter.prototype = {
|
|
|
|
__proto__: Presenter.prototype,
|
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
type: 'Speech',
|
2012-07-20 16:46:54 +00:00
|
|
|
|
|
|
|
pivotChanged: function SpeechPresenter_pivotChanged(aContext, aReason) {
|
|
|
|
if (!aContext.accessible)
|
2012-10-01 20:33:26 +00:00
|
|
|
return null;
|
2012-07-20 16:46:54 +00:00
|
|
|
|
2012-10-01 20:33:26 +00:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: {
|
|
|
|
actions: [
|
2013-11-27 00:53:45 +00:00
|
|
|
{method: 'playEarcon',
|
|
|
|
data: aContext.accessible.role === Roles.KEY ?
|
|
|
|
'virtual_cursor_key' : 'virtual_cursor_move',
|
|
|
|
options: {}},
|
2013-04-04 22:16:37 +00:00
|
|
|
{method: 'speak',
|
2013-07-03 22:20:11 +00:00
|
|
|
data: UtteranceGenerator.genForContext(aContext).output.join(' '),
|
2013-04-04 22:16:37 +00:00
|
|
|
options: {enqueue: true}}
|
2012-10-01 20:33:26 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
2013-06-27 21:15:37 +00:00
|
|
|
},
|
|
|
|
|
2014-03-19 17:08:54 +00:00
|
|
|
valueChanged: function SpeechPresenter_valueChanged(aAccessible) {
|
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: {
|
|
|
|
actions: [
|
|
|
|
{ method: 'speak',
|
|
|
|
data: aAccessible.value,
|
|
|
|
options: { enqueue: false } }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-06-27 21:15:37 +00:00
|
|
|
actionInvoked: function SpeechPresenter_actionInvoked(aObject, aActionName) {
|
2013-11-27 00:53:45 +00:00
|
|
|
let actions = [];
|
|
|
|
if (aActionName === 'click') {
|
|
|
|
actions.push({method: 'playEarcon',
|
|
|
|
data: 'clicked',
|
|
|
|
options: {}});
|
|
|
|
} else {
|
|
|
|
actions.push({method: 'speak',
|
|
|
|
data: UtteranceGenerator.genForAction(aObject, aActionName).join(' '),
|
|
|
|
options: {enqueue: false}});
|
|
|
|
}
|
|
|
|
return { type: this.type, details: { actions: actions } };
|
2013-08-21 16:40:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
liveRegion: function SpeechPresenter_liveRegion(aContext, aIsPolite, aIsHide,
|
|
|
|
aModifiedText) {
|
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: {
|
|
|
|
actions: [{
|
|
|
|
method: 'speak',
|
|
|
|
data: UtteranceGenerator.genForLiveRegion(aContext, aIsHide,
|
|
|
|
aModifiedText).join(' '),
|
|
|
|
options: {enqueue: aIsPolite}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
2014-03-04 18:10:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
announce: function SpeechPresenter_announce(aAnnouncement) {
|
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: {
|
|
|
|
actions: [{
|
|
|
|
method: 'speak', data: aAnnouncement, options: { enqueue: false }
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
2012-07-20 16:46:54 +00:00
|
|
|
}
|
2012-10-01 20:33:26 +00:00
|
|
|
};
|
2012-11-12 23:46:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A haptic presenter
|
|
|
|
*/
|
|
|
|
|
|
|
|
this.HapticPresenter = function HapticPresenter() {};
|
|
|
|
|
|
|
|
HapticPresenter.prototype = {
|
|
|
|
__proto__: Presenter.prototype,
|
|
|
|
|
|
|
|
type: 'Haptic',
|
|
|
|
|
2014-03-04 18:27:17 +00:00
|
|
|
PIVOT_CHANGE_PATTERN: [40],
|
2012-11-12 23:46:09 +00:00
|
|
|
|
|
|
|
pivotChanged: function HapticPresenter_pivotChanged(aContext, aReason) {
|
2014-03-04 18:27:17 +00:00
|
|
|
return { type: this.type, details: { pattern: this.PIVOT_CHANGE_PATTERN } };
|
2012-11-12 23:46:09 +00:00
|
|
|
}
|
|
|
|
};
|
2012-07-20 16:46:54 +00:00
|
|
|
|
2013-06-17 14:36:41 +00:00
|
|
|
/**
|
|
|
|
* A braille presenter
|
|
|
|
*/
|
|
|
|
|
|
|
|
this.BraillePresenter = function BraillePresenter() {};
|
|
|
|
|
|
|
|
BraillePresenter.prototype = {
|
|
|
|
__proto__: Presenter.prototype,
|
|
|
|
|
|
|
|
type: 'Braille',
|
|
|
|
|
|
|
|
pivotChanged: function BraillePresenter_pivotChanged(aContext, aReason) {
|
|
|
|
if (!aContext.accessible) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-07-03 22:20:11 +00:00
|
|
|
let brailleOutput = BrailleGenerator.genForContext(aContext);
|
|
|
|
brailleOutput.output = brailleOutput.output.join(' ');
|
2013-07-11 19:55:40 +00:00
|
|
|
brailleOutput.selectionStart = 0;
|
|
|
|
brailleOutput.selectionEnd = 0;
|
2013-06-17 14:36:41 +00:00
|
|
|
|
2013-07-03 22:20:11 +00:00
|
|
|
return { type: this.type, details: brailleOutput };
|
2013-07-11 19:55:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
textSelectionChanged: function BraillePresenter_textSelectionChanged(aText, aStart,
|
|
|
|
aEnd, aOldStart,
|
|
|
|
aOldEnd, aIsFromUser) {
|
|
|
|
return { type: this.type,
|
|
|
|
details: { selectionStart: aStart,
|
|
|
|
selectionEnd: aEnd } };
|
|
|
|
},
|
|
|
|
|
2013-06-17 14:36:41 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-12-07 18:39:17 +00:00
|
|
|
this.Presentation = {
|
|
|
|
get presenters() {
|
|
|
|
delete this.presenters;
|
2014-03-19 07:38:25 +00:00
|
|
|
let presenterMap = {
|
|
|
|
'mobile/android': [VisualPresenter, AndroidPresenter],
|
|
|
|
'b2g': [VisualPresenter, SpeechPresenter, HapticPresenter],
|
|
|
|
'browser': [VisualPresenter, SpeechPresenter, HapticPresenter,
|
|
|
|
AndroidPresenter]
|
|
|
|
};
|
|
|
|
this.presenters = [new P() for (P of presenterMap[Utils.MozBuildApp])];
|
2012-12-07 18:39:17 +00:00
|
|
|
return this.presenters;
|
|
|
|
},
|
|
|
|
|
2013-07-24 21:52:57 +00:00
|
|
|
pivotChanged: function Presentation_pivotChanged(aPosition, aOldPosition, aReason,
|
|
|
|
aStartOffset, aEndOffset) {
|
|
|
|
let context = new PivotContext(aPosition, aOldPosition, aStartOffset, aEndOffset);
|
2012-12-07 18:39:17 +00:00
|
|
|
return [p.pivotChanged(context, aReason)
|
|
|
|
for each (p in this.presenters)];
|
|
|
|
},
|
|
|
|
|
|
|
|
actionInvoked: function Presentation_actionInvoked(aObject, aActionName) {
|
|
|
|
return [p.actionInvoked(aObject, aActionName)
|
|
|
|
for each (p in this.presenters)];
|
|
|
|
},
|
|
|
|
|
|
|
|
textChanged: function Presentation_textChanged(aIsInserted, aStartOffset,
|
|
|
|
aLength, aText,
|
|
|
|
aModifiedText) {
|
|
|
|
return [p.textChanged(aIsInserted, aStartOffset, aLength,
|
|
|
|
aText, aModifiedText)
|
|
|
|
for each (p in this.presenters)];
|
|
|
|
},
|
|
|
|
|
2013-07-11 19:55:40 +00:00
|
|
|
textSelectionChanged: function textSelectionChanged(aText, aStart, aEnd,
|
|
|
|
aOldStart, aOldEnd,
|
|
|
|
aIsFromUser) {
|
|
|
|
return [p.textSelectionChanged(aText, aStart, aEnd,
|
|
|
|
aOldStart, aOldEnd, aIsFromUser)
|
2013-06-19 20:11:46 +00:00
|
|
|
for each (p in this.presenters)];
|
|
|
|
},
|
|
|
|
|
2014-03-19 17:08:54 +00:00
|
|
|
valueChanged: function valueChanged(aAccessible) {
|
|
|
|
return [ p.valueChanged(aAccessible) for (p of this.presenters) ];
|
|
|
|
},
|
|
|
|
|
2012-12-07 18:39:17 +00:00
|
|
|
tabStateChanged: function Presentation_tabStateChanged(aDocObj, aPageState) {
|
|
|
|
return [p.tabStateChanged(aDocObj, aPageState)
|
|
|
|
for each (p in this.presenters)];
|
|
|
|
},
|
|
|
|
|
|
|
|
viewportChanged: function Presentation_viewportChanged(aWindow) {
|
|
|
|
return [p.viewportChanged(aWindow)
|
|
|
|
for each (p in this.presenters)];
|
|
|
|
},
|
|
|
|
|
|
|
|
editingModeChanged: function Presentation_editingModeChanged(aIsEditing) {
|
|
|
|
return [p.editingModeChanged(aIsEditing)
|
|
|
|
for each (p in this.presenters)];
|
2012-12-07 18:39:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
announce: function Presentation_announce(aAnnouncement) {
|
|
|
|
// XXX: Typically each presenter uses the UtteranceGenerator,
|
|
|
|
// but there really isn't a point here.
|
|
|
|
return [p.announce(UtteranceGenerator.genForAnnouncement(aAnnouncement)[0])
|
|
|
|
for each (p in this.presenters)];
|
2013-08-21 16:40:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
liveRegion: function Presentation_liveRegion(aAccessible, aIsPolite, aIsHide,
|
|
|
|
aModifiedText) {
|
|
|
|
let context;
|
|
|
|
if (!aModifiedText) {
|
|
|
|
context = new PivotContext(aAccessible, null, -1, -1, true,
|
|
|
|
aIsHide ? true : false);
|
|
|
|
}
|
|
|
|
return [p.liveRegion(context, aIsPolite, aIsHide, aModifiedText) for (
|
|
|
|
p of this.presenters)];
|
2012-12-07 18:39:17 +00:00
|
|
|
}
|
|
|
|
};
|