2012-04-14 03:18:57 +04: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 17:38:56 +04:00
|
|
|
/* exported Presentation */
|
|
|
|
|
2017-08-01 19:13:27 +03:00
|
|
|
"use strict";
|
2012-04-14 03:18:57 +04:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/accessibility/Utils.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "PivotContext", // jshint ignore:line
|
2017-08-01 19:13:27 +03:00
|
|
|
"resource://gre/modules/accessibility/Utils.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "UtteranceGenerator", // jshint ignore:line
|
2017-08-01 19:13:27 +03:00
|
|
|
"resource://gre/modules/accessibility/OutputGenerator.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "States", // jshint ignore:line
|
2017-08-01 19:13:27 +03:00
|
|
|
"resource://gre/modules/accessibility/Constants.jsm");
|
2018-07-10 17:31:00 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "Roles", // jshint ignore:line
|
|
|
|
"resource://gre/modules/accessibility/Constants.jsm");
|
2018-04-24 14:43:00 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "AndroidEvents", // jshint ignore:line
|
|
|
|
"resource://gre/modules/accessibility/Constants.jsm");
|
2017-08-01 19:13:27 +03:00
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["Presentation"]; // jshint ignore:line
|
2012-04-14 03:18:57 +04:00
|
|
|
|
2018-07-10 17:31:00 +03:00
|
|
|
const EDIT_TEXT_ROLES = new Set([
|
|
|
|
Roles.SPINBUTTON, Roles.PASSWORD_TEXT,
|
|
|
|
Roles.AUTOCOMPLETE, Roles.ENTRY, Roles.EDITCOMBOBOX]);
|
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
class AndroidPresentor {
|
|
|
|
constructor() {
|
|
|
|
this.type = "Android";
|
|
|
|
this.displayedAccessibles = new WeakMap();
|
|
|
|
}
|
2012-10-02 00:33:26 +04:00
|
|
|
|
2012-04-14 03:18:57 +04:00
|
|
|
/**
|
|
|
|
* The virtual cursor's position changed.
|
2013-04-05 02:16:37 +04:00
|
|
|
* @param {PivotContext} aContext the context object for the new pivot
|
2012-05-18 22:56:38 +04:00
|
|
|
* position.
|
2012-06-25 21:34:52 +04:00
|
|
|
* @param {int} aReason the reason for the pivot change.
|
|
|
|
* See nsIAccessiblePivot.
|
2014-08-16 09:06:16 +04:00
|
|
|
* @param {bool} aIsFromUserInput the pivot change was invoked by the user
|
2012-04-14 03:18:57 +04:00
|
|
|
*/
|
2018-04-24 14:43:00 +03:00
|
|
|
pivotChanged(aPosition, aOldPosition, aReason, aStartOffset, aEndOffset, aIsUserInput) {
|
|
|
|
let context = new PivotContext(
|
|
|
|
aPosition, aOldPosition, aStartOffset, aEndOffset);
|
|
|
|
if (!context.accessible) {
|
2012-10-02 00:33:26 +04:00
|
|
|
return null;
|
2014-08-06 17:38:56 +04:00
|
|
|
}
|
2012-05-22 22:01:39 +04:00
|
|
|
|
2012-10-02 00:33:26 +04:00
|
|
|
let androidEvents = [];
|
|
|
|
|
2018-07-10 17:31:00 +03:00
|
|
|
const isExploreByTouch = aReason == Ci.nsIAccessiblePivot.REASON_POINT;
|
2012-06-25 21:34:52 +04:00
|
|
|
|
|
|
|
if (isExploreByTouch) {
|
|
|
|
// This isn't really used by TalkBack so this is a half-hearted attempt
|
|
|
|
// for now.
|
2018-05-07 17:37:00 +03:00
|
|
|
androidEvents.push({eventType: AndroidEvents.VIEW_HOVER_EXIT, text: []});
|
2013-06-17 18:36:41 +04:00
|
|
|
}
|
|
|
|
|
2013-07-25 01:52:57 +04:00
|
|
|
if (aReason === Ci.nsIAccessiblePivot.REASON_TEXT) {
|
2018-07-10 17:31:00 +03:00
|
|
|
const adjustedText = context.textAndAdjustedOffsets;
|
|
|
|
|
|
|
|
androidEvents.push({
|
|
|
|
eventType: AndroidEvents.VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY,
|
|
|
|
text: [adjustedText.text],
|
|
|
|
fromIndex: adjustedText.startOffset,
|
|
|
|
toIndex: adjustedText.endOffset
|
|
|
|
});
|
2013-07-25 01:52:57 +04:00
|
|
|
} else {
|
2018-05-11 08:30:00 +03:00
|
|
|
let info = this._infoFromContext(context);
|
|
|
|
let eventType = isExploreByTouch ?
|
2018-07-10 17:31:00 +03:00
|
|
|
AndroidEvents.VIEW_HOVER_ENTER :
|
|
|
|
AndroidEvents.VIEW_ACCESSIBILITY_FOCUSED;
|
2018-05-11 08:30:00 +03:00
|
|
|
androidEvents.push({...info, eventType});
|
2013-07-25 01:52:57 +04:00
|
|
|
}
|
2013-05-23 18:06:27 +04:00
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
try {
|
|
|
|
context.accessibleForBounds.scrollTo(
|
|
|
|
Ci.nsIAccessibleScrollType.SCROLL_TYPE_ANYWHERE);
|
|
|
|
} catch (e) {}
|
2013-05-23 18:06:27 +04:00
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
if (context.accessible) {
|
|
|
|
this.displayedAccessibles.set(context.accessible.document.window, context);
|
|
|
|
}
|
2012-05-15 01:21:59 +04:00
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
return androidEvents;
|
|
|
|
}
|
|
|
|
|
2018-05-11 08:30:00 +03:00
|
|
|
focused(aObject) {
|
|
|
|
let info = this._infoFromContext(
|
|
|
|
new PivotContext(aObject, null, -1, -1, true, false));
|
|
|
|
return [{ eventType: AndroidEvents.VIEW_FOCUSED, ...info }];
|
|
|
|
}
|
|
|
|
|
2018-04-24 14:43:00 +03: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(aObject, aActionName) {
|
2014-01-28 04:35:13 +04:00
|
|
|
let state = Utils.getState(aObject);
|
2013-11-27 04:53:45 +04:00
|
|
|
|
2015-02-20 20:38:50 +03:00
|
|
|
// Checkable objects use TalkBack's text derived from the event state,
|
|
|
|
// so we don't populate the text here.
|
2017-02-09 03:50:32 +03:00
|
|
|
let text = null;
|
2015-02-20 20:38:50 +03:00
|
|
|
if (!state.contains(States.CHECKABLE)) {
|
|
|
|
text = Utils.localize(UtteranceGenerator.genForAction(aObject,
|
|
|
|
aActionName));
|
2014-08-06 17:38:56 +04:00
|
|
|
}
|
2013-11-27 04:53:45 +04:00
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
return [{
|
2018-05-07 17:37:00 +03:00
|
|
|
eventType: AndroidEvents.VIEW_CLICKED,
|
2018-04-24 14:43:00 +03:00
|
|
|
text,
|
|
|
|
checked: state.contains(States.CHECKED)
|
|
|
|
}];
|
|
|
|
}
|
2012-05-15 01:21:59 +04:00
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
/**
|
|
|
|
* Text has changed, either by the user or by the system. TODO.
|
|
|
|
*/
|
|
|
|
textChanged(aAccessible, aIsInserted, aStart, aLength, aText, aModifiedText) {
|
|
|
|
let androidEvent = {
|
2018-05-07 17:37:00 +03:00
|
|
|
eventType: AndroidEvents.VIEW_TEXT_CHANGED,
|
2012-10-20 00:39:37 +04:00
|
|
|
text: [aText],
|
|
|
|
fromIndex: aStart,
|
|
|
|
removedCount: 0,
|
|
|
|
addedCount: 0
|
2012-05-15 01:21:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (aIsInserted) {
|
2018-04-24 14:43:00 +03:00
|
|
|
androidEvent.addedCount = aLength;
|
|
|
|
androidEvent.beforeText =
|
2012-05-15 01:21:59 +04:00
|
|
|
aText.substring(0, aStart) + aText.substring(aStart + aLength);
|
|
|
|
} else {
|
2018-04-24 14:43:00 +03:00
|
|
|
androidEvent.removedCount = aLength;
|
|
|
|
androidEvent.beforeText =
|
2012-05-15 01:21:59 +04:00
|
|
|
aText.substring(0, aStart) + aModifiedText + aText.substring(aStart);
|
2012-04-14 03:18:57 +04:00
|
|
|
}
|
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
return [androidEvent];
|
|
|
|
}
|
2012-04-14 03:18:57 +04:00
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
/**
|
|
|
|
* Text selection has changed. TODO.
|
|
|
|
*/
|
|
|
|
textSelectionChanged(aText, aStart, aEnd, aOldStart, aOldEnd, aIsFromUserInput) {
|
2013-06-20 00:11:46 +04:00
|
|
|
let androidEvents = [];
|
|
|
|
|
2018-07-10 17:31:00 +03:00
|
|
|
if (aIsFromUserInput) {
|
2014-08-06 17:38:56 +04:00
|
|
|
let [from, to] = aOldStart < aStart ?
|
|
|
|
[aOldStart, aStart] : [aStart, aOldStart];
|
2013-06-20 00:11:46 +04:00
|
|
|
androidEvents.push({
|
2018-05-07 17:37:00 +03:00
|
|
|
eventType: AndroidEvents.VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY,
|
2013-06-20 00:11:46 +04:00
|
|
|
text: [aText],
|
|
|
|
fromIndex: from,
|
|
|
|
toIndex: to
|
|
|
|
});
|
2018-07-10 17:31:00 +03:00
|
|
|
} else {
|
|
|
|
androidEvents.push({
|
|
|
|
eventType: AndroidEvents.VIEW_TEXT_SELECTION_CHANGED,
|
|
|
|
text: [aText],
|
|
|
|
fromIndex: aStart,
|
|
|
|
toIndex: aEnd,
|
|
|
|
itemCount: aText.length
|
|
|
|
});
|
2013-06-20 00:11:46 +04:00
|
|
|
}
|
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
return androidEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selection has changed.
|
|
|
|
* XXX: Implement android event?
|
|
|
|
* @param {nsIAccessible} aObject the object that has been selected.
|
|
|
|
*/
|
|
|
|
selectionChanged(aObject) {
|
2018-05-08 21:59:00 +03:00
|
|
|
return ["todo.selection-changed"];
|
2018-04-24 14:43:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name has changed.
|
|
|
|
* XXX: Implement android event?
|
|
|
|
* @param {nsIAccessible} aAccessible the object whose value has changed.
|
|
|
|
*/
|
|
|
|
nameChanged(aAccessible) {
|
2018-05-08 21:59:00 +03:00
|
|
|
return ["todo.name-changed"];
|
2018-04-24 14:43:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Value has changed.
|
|
|
|
* XXX: Implement android event?
|
|
|
|
* @param {nsIAccessible} aAccessible the object whose value has changed.
|
|
|
|
*/
|
|
|
|
valueChanged(aAccessible) {
|
2018-05-08 21:59:00 +03:00
|
|
|
return ["todo.value-changed"];
|
2018-04-24 14:43:00 +03: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'.
|
|
|
|
*/
|
|
|
|
tabStateChanged(aDocObj, aPageState) {
|
|
|
|
return this.announce(
|
|
|
|
UtteranceGenerator.genForTabStateChange(aDocObj, aPageState));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current tab has changed.
|
|
|
|
* @param {PivotContext} aDocContext context object for tab's
|
|
|
|
* document.
|
|
|
|
* @param {PivotContext} aVCContext context object for tab's current
|
|
|
|
* virtual cursor position.
|
|
|
|
*/
|
|
|
|
tabSelected(aDocContext, aVCContext) {
|
|
|
|
return this.pivotChanged(aVCContext, Ci.nsIAccessiblePivot.REASON_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The viewport has changed, either a scroll, pan, zoom, or
|
|
|
|
* landscape/portrait toggle.
|
|
|
|
* @param {Window} aWindow window of viewport that changed.
|
|
|
|
*/
|
|
|
|
viewportChanged(aWindow) {
|
|
|
|
let currentContext = this.displayedAccessibles.get(aWindow);
|
2013-06-20 00:11:46 +04:00
|
|
|
|
2015-09-14 20:52:43 +03:00
|
|
|
let events = [{
|
2018-05-07 17:37:00 +03:00
|
|
|
eventType: AndroidEvents.VIEW_SCROLLED,
|
2015-09-14 20:52:43 +03:00
|
|
|
scrollX: aWindow.scrollX,
|
|
|
|
scrollY: aWindow.scrollY,
|
|
|
|
maxScrollX: aWindow.scrollMaxX,
|
2018-07-10 17:31:00 +03:00
|
|
|
maxScrollY: aWindow.scrollMaxY,
|
2015-09-14 20:52:43 +03:00
|
|
|
}];
|
|
|
|
|
2018-07-10 17:31:00 +03:00
|
|
|
if (currentContext) {
|
2018-04-24 14:43:00 +03:00
|
|
|
let currentAcc = currentContext.accessibleForBounds;
|
2015-09-14 20:52:43 +03:00
|
|
|
if (Utils.isAliveAndVisible(currentAcc)) {
|
|
|
|
events.push({
|
2018-07-10 17:31:00 +03:00
|
|
|
eventType: AndroidEvents.WINDOW_CONTENT_CHANGED,
|
2015-09-14 20:52:43 +03:00
|
|
|
bounds: Utils.getBounds(currentAcc)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
return events;
|
|
|
|
}
|
2012-06-25 21:34:52 +04:00
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
/**
|
|
|
|
* Announce something. Typically an app state change.
|
|
|
|
*/
|
|
|
|
announce(aAnnouncement) {
|
2017-08-01 19:13:27 +03:00
|
|
|
let localizedAnnouncement = Utils.localize(aAnnouncement).join(" ");
|
2018-04-24 14:43:00 +03:00
|
|
|
return [{
|
2018-07-10 17:31:00 +03:00
|
|
|
eventType: AndroidEvents.ANNOUNCEMENT,
|
2018-04-24 14:43:00 +03:00
|
|
|
text: [localizedAnnouncement],
|
|
|
|
addedCount: localizedAnnouncement.length,
|
|
|
|
removedCount: 0,
|
|
|
|
fromIndex: 0
|
|
|
|
}];
|
|
|
|
}
|
2012-12-07 22:39:17 +04:00
|
|
|
|
2015-09-14 20:52:43 +03:00
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
/**
|
|
|
|
* User tried to move cursor forward or backward with no success.
|
|
|
|
* @param {string} aMoveMethod move method that was used (eg. 'moveNext').
|
|
|
|
*/
|
|
|
|
noMove(aMoveMethod) {
|
|
|
|
return [{
|
2018-05-07 17:37:00 +03:00
|
|
|
eventType: AndroidEvents.VIEW_ACCESSIBILITY_FOCUSED,
|
2018-04-24 14:43:00 +03:00
|
|
|
exitView: aMoveMethod,
|
|
|
|
text: [""]
|
|
|
|
}];
|
|
|
|
}
|
2015-09-14 20:52:43 +03:00
|
|
|
|
2018-04-24 14:43:00 +03:00
|
|
|
/**
|
|
|
|
* 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(aAccessible, aIsPolite, aIsHide, aModifiedText) {
|
|
|
|
let context = !aModifiedText ?
|
|
|
|
new PivotContext(aAccessible, null, -1, -1, true, !!aIsHide) : null;
|
|
|
|
return this.announce(
|
|
|
|
UtteranceGenerator.genForLiveRegion(context, aIsHide, aModifiedText));
|
2012-12-07 22:39:17 +04:00
|
|
|
}
|
2018-05-11 08:30:00 +03:00
|
|
|
|
|
|
|
_infoFromContext(aContext) {
|
2018-07-10 17:31:00 +03:00
|
|
|
const state = Utils.getState(aContext.accessible);
|
|
|
|
const info = {
|
2018-05-11 08:30:00 +03:00
|
|
|
bounds: aContext.bounds,
|
|
|
|
focusable: state.contains(States.FOCUSABLE),
|
|
|
|
focused: state.contains(States.FOCUSED),
|
|
|
|
clickable: aContext.accessible.actionCount > 0,
|
|
|
|
checkable: state.contains(States.CHECKABLE),
|
|
|
|
checked: state.contains(States.CHECKED),
|
|
|
|
editable: state.contains(States.EDITABLE),
|
|
|
|
};
|
2018-07-10 17:31:00 +03:00
|
|
|
|
|
|
|
if (EDIT_TEXT_ROLES.has(aContext.accessible.role)) {
|
|
|
|
let textAcc = aContext.accessible.QueryInterface(Ci.nsIAccessibleText);
|
|
|
|
return {
|
|
|
|
...info,
|
|
|
|
className: "android.widget.EditText",
|
|
|
|
hint: aContext.accessible.name,
|
|
|
|
text: [textAcc.getText(0, -1)]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...info,
|
|
|
|
className: "android.view.View",
|
|
|
|
text: Utils.localize(UtteranceGenerator.genForContext(aContext)),
|
|
|
|
};
|
2018-05-11 08:30:00 +03:00
|
|
|
}
|
2018-04-24 14:43:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const Presentation = new AndroidPresentor();
|