2012-04-13 16:18:57 -07: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;
|
|
|
|
|
2012-06-20 14:07:51 -07:00
|
|
|
Cu.import('resource://gre/modules/accessibility/Utils.jsm');
|
2012-04-13 16:18:57 -07:00
|
|
|
Cu.import('resource://gre/modules/accessibility/UtteranceGenerator.jsm');
|
2012-08-20 15:29:22 -07:00
|
|
|
Cu.import('resource://gre/modules/Geometry.jsm');
|
2012-04-13 16:18:57 -07:00
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.EXPORTED_SYMBOLS = ['VisualPresenter',
|
|
|
|
'AndroidPresenter',
|
|
|
|
'DummyAndroidPresenter',
|
|
|
|
'SpeechPresenter',
|
2012-11-12 15:46:09 -08:00
|
|
|
'HapticPresenter',
|
2012-10-31 09:13:28 -07:00
|
|
|
'PresenterContext'];
|
2012-04-13 16:18:57 -07: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 13:33:26 -07:00
|
|
|
/**
|
|
|
|
* The type of presenter. Used for matching it with the appropriate output method.
|
|
|
|
*/
|
|
|
|
type: 'Base',
|
|
|
|
|
2012-04-13 16:18:57 -07:00
|
|
|
/**
|
|
|
|
* Attach function for presenter.
|
|
|
|
* @param {ChromeWindow} aWindow Chrome window the presenter could use.
|
|
|
|
*/
|
|
|
|
attach: function attach(aWindow) {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detach function.
|
|
|
|
*/
|
|
|
|
detach: function detach() {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The virtual cursor's position changed.
|
2012-05-18 11:56:38 -07:00
|
|
|
* @param {PresenterContext} aContext the context object for the new pivot
|
|
|
|
* position.
|
2012-06-25 10:34:52 -07:00
|
|
|
* @param {int} aReason the reason for the pivot change.
|
|
|
|
* See nsIAccessiblePivot.
|
2012-04-13 16:18:57 -07:00
|
|
|
*/
|
2012-06-25 10:34:52 -07:00
|
|
|
pivotChanged: function pivotChanged(aContext, aReason) {},
|
2012-04-13 16:18:57 -07: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 14:21:59 -07:00
|
|
|
textChanged: function textChanged(aIsInserted, aStartOffset,
|
|
|
|
aLength, aText,
|
|
|
|
aModifiedText) {},
|
2012-04-13 16:18:57 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Text selection has changed. TODO.
|
|
|
|
*/
|
|
|
|
textSelectionChanged: function textSelectionChanged() {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selection has changed. TODO.
|
|
|
|
* @param {nsIAccessible} aObject the object that has been selected.
|
|
|
|
*/
|
|
|
|
selectionChanged: function selectionChanged(aObject) {},
|
|
|
|
|
|
|
|
/**
|
2012-05-07 09:44:44 -07: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 16:18:57 -07:00
|
|
|
*/
|
2012-05-07 09:44:44 -07:00
|
|
|
tabStateChanged: function tabStateChanged(aDocObj, aPageState) {},
|
2012-04-13 16:18:57 -07:00
|
|
|
|
|
|
|
/**
|
2012-05-07 09:44:44 -07:00
|
|
|
* The current tab has changed.
|
2012-05-18 11:56:38 -07:00
|
|
|
* @param {PresenterContext} aDocContext context object for tab's
|
|
|
|
* document.
|
|
|
|
* @param {PresenterContext} aVCContext context object for tab's current
|
|
|
|
* virtual cursor position.
|
2012-04-13 16:18:57 -07:00
|
|
|
*/
|
2012-05-18 11:56:38 -07:00
|
|
|
tabSelected: function tabSelected(aDocContext, aVCContext) {},
|
2012-04-13 16:18:57 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The viewport has changed, either a scroll, pan, zoom, or
|
|
|
|
* landscape/portrait toggle.
|
2012-10-01 13:33:26 -07:00
|
|
|
* @param {Window} aWindow window of viewport that changed.
|
2012-04-13 16:18:57 -07:00
|
|
|
*/
|
2012-10-01 13:33:26 -07:00
|
|
|
viewportChanged: function viewportChanged(aWindow) {},
|
2012-07-10 16:10:15 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We have entered or left text editing mode.
|
|
|
|
*/
|
2012-10-19 10:06:08 -07:00
|
|
|
editingModeChanged: function editingModeChanged(aIsEditing) {}
|
2012-04-13 16:18:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Visual presenter. Draws a box around the virtual cursor's position.
|
|
|
|
*/
|
|
|
|
|
2012-11-12 15:46:09 -08:00
|
|
|
this.VisualPresenter = function VisualPresenter() {};
|
2012-04-13 16:18:57 -07:00
|
|
|
|
2012-05-14 14:21:59 -07:00
|
|
|
VisualPresenter.prototype = {
|
|
|
|
__proto__: Presenter.prototype,
|
2012-04-13 16:18:57 -07:00
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
type: 'Visual',
|
|
|
|
|
2012-05-14 14:21:59 -07:00
|
|
|
/**
|
|
|
|
* The padding in pixels between the object and the highlight border.
|
|
|
|
*/
|
|
|
|
BORDER_PADDING: 2,
|
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
viewportChanged: function VisualPresenter_viewportChanged(aWindow) {
|
2012-10-17 10:23:26 -07:00
|
|
|
if (this._currentAccessible) {
|
|
|
|
let context = new PresenterContext(this._currentAccessible);
|
2012-10-01 13:33:26 -07:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: {
|
|
|
|
method: 'show',
|
2012-10-17 10:23:26 -07:00
|
|
|
bounds: context.bounds,
|
2012-10-01 13:33:26 -07:00
|
|
|
padding: this.BORDER_PADDING
|
|
|
|
}
|
|
|
|
};
|
2012-10-17 10:23:26 -07:00
|
|
|
}
|
2012-10-01 13:33:26 -07:00
|
|
|
|
|
|
|
return null;
|
2012-05-14 14:21:59 -07:00
|
|
|
},
|
|
|
|
|
2012-06-25 10:34:52 -07:00
|
|
|
pivotChanged: function VisualPresenter_pivotChanged(aContext, aReason) {
|
2012-10-17 10:23:26 -07:00
|
|
|
this._currentAccessible = aContext.accessible;
|
2012-05-14 14:21:59 -07:00
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
if (!aContext.accessible)
|
|
|
|
return {type: this.type, details: {method: 'hide'}};
|
2012-04-13 16:18:57 -07:00
|
|
|
|
2012-05-14 14:21:59 -07:00
|
|
|
try {
|
2012-05-18 11:56:38 -07:00
|
|
|
aContext.accessible.scrollTo(
|
|
|
|
Ci.nsIAccessibleScrollType.SCROLL_TYPE_ANYWHERE);
|
2012-10-01 13:33:26 -07:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: {
|
|
|
|
method: 'show',
|
|
|
|
bounds: aContext.bounds,
|
|
|
|
padding: this.BORDER_PADDING
|
|
|
|
}
|
|
|
|
};
|
2012-05-14 14:21:59 -07:00
|
|
|
} catch (e) {
|
2012-06-20 14:07:51 -07:00
|
|
|
Logger.error('Failed to get bounds: ' + e);
|
2012-10-01 13:33:26 -07:00
|
|
|
return null;
|
2012-05-14 14:21:59 -07:00
|
|
|
}
|
|
|
|
},
|
2012-04-13 16:18:57 -07:00
|
|
|
|
2012-05-18 11:56:38 -07:00
|
|
|
tabSelected: function VisualPresenter_tabSelected(aDocContext, aVCContext) {
|
2012-10-01 13:33:26 -07:00
|
|
|
return this.pivotChanged(aVCContext, Ci.nsIAccessiblePivot.REASON_NONE);
|
2012-05-14 14:21:59 -07:00
|
|
|
},
|
2012-04-13 16:18:57 -07:00
|
|
|
|
2012-05-14 14:21:59 -07:00
|
|
|
tabStateChanged: function VisualPresenter_tabStateChanged(aDocObj,
|
|
|
|
aPageState) {
|
|
|
|
if (aPageState == 'newdoc')
|
2012-10-01 13:33:26 -07:00
|
|
|
return {type: this.type, details: {method: 'hide'}};
|
2012-05-07 09:44:44 -07:00
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
return null;
|
2012-04-13 16:18:57 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Android presenter. Fires Android a11y events.
|
|
|
|
*/
|
|
|
|
|
2012-11-12 15:46:09 -08:00
|
|
|
this.AndroidPresenter = function AndroidPresenter() {};
|
2012-04-13 16:18:57 -07:00
|
|
|
|
2012-05-14 14:21:59 -07:00
|
|
|
AndroidPresenter.prototype = {
|
|
|
|
__proto__: Presenter.prototype,
|
2012-04-13 16:18:57 -07:00
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
type: 'Android',
|
|
|
|
|
2012-05-14 14:21:59 -07: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 10:34:52 -07:00
|
|
|
ANDROID_VIEW_HOVER_ENTER: 0x80,
|
|
|
|
ANDROID_VIEW_HOVER_EXIT: 0x100,
|
2012-06-25 10:34:52 -07:00
|
|
|
ANDROID_VIEW_SCROLLED: 0x1000,
|
2012-08-20 15:29:22 -07:00
|
|
|
ANDROID_ANNOUNCEMENT: 0x4000,
|
|
|
|
ANDROID_VIEW_ACCESSIBILITY_FOCUSED: 0x8000,
|
2012-06-25 10:34:52 -07:00
|
|
|
|
2012-06-25 10:34:52 -07:00
|
|
|
pivotChanged: function AndroidPresenter_pivotChanged(aContext, aReason) {
|
2012-05-22 11:01:39 -07:00
|
|
|
if (!aContext.accessible)
|
2012-10-01 13:33:26 -07:00
|
|
|
return null;
|
2012-05-22 11:01:39 -07:00
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
let androidEvents = [];
|
|
|
|
|
2012-06-25 10:34:52 -07:00
|
|
|
let isExploreByTouch = (aReason == Ci.nsIAccessiblePivot.REASON_POINT &&
|
|
|
|
Utils.AndroidSdkVersion >= 14);
|
2012-08-20 15:29:22 -07:00
|
|
|
let focusEventType = (Utils.AndroidSdkVersion >= 16) ?
|
|
|
|
this.ANDROID_VIEW_ACCESSIBILITY_FOCUSED :
|
|
|
|
this.ANDROID_VIEW_FOCUSED;
|
2012-06-25 10:34:52 -07:00
|
|
|
|
|
|
|
if (isExploreByTouch) {
|
|
|
|
// This isn't really used by TalkBack so this is a half-hearted attempt
|
|
|
|
// for now.
|
2012-10-01 13:33:26 -07:00
|
|
|
androidEvents.push({eventType: this.ANDROID_VIEW_HOVER_EXIT, text: []});
|
2012-06-25 10:34:52 -07:00
|
|
|
}
|
|
|
|
|
2012-05-14 14:21:59 -07:00
|
|
|
let output = [];
|
2012-06-25 10:34:52 -07:00
|
|
|
|
2012-06-29 11:30:27 -07:00
|
|
|
aContext.newAncestry.forEach(
|
|
|
|
function(acc) {
|
|
|
|
output.push.apply(output, UtteranceGenerator.genForObject(acc));
|
2012-05-29 13:46:08 -07:00
|
|
|
}
|
2012-06-29 11:30:27 -07:00
|
|
|
);
|
2012-04-13 16:18:57 -07:00
|
|
|
|
2012-05-14 14:21:59 -07:00
|
|
|
output.push.apply(output,
|
2012-05-29 13:46:08 -07:00
|
|
|
UtteranceGenerator.genForObject(aContext.accessible));
|
|
|
|
|
|
|
|
aContext.subtreePreorder.forEach(
|
2012-06-20 14:07:51 -07:00
|
|
|
function(acc) {
|
2012-05-29 13:46:08 -07:00
|
|
|
output.push.apply(output, UtteranceGenerator.genForObject(acc));
|
|
|
|
}
|
|
|
|
);
|
2012-05-14 14:21:59 -07:00
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
androidEvents.push({eventType: (isExploreByTouch) ?
|
|
|
|
this.ANDROID_VIEW_HOVER_ENTER : focusEventType,
|
|
|
|
text: output,
|
|
|
|
bounds: aContext.bounds});
|
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: androidEvents
|
|
|
|
};
|
2012-05-14 14:21:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
actionInvoked: function AndroidPresenter_actionInvoked(aObject, aActionName) {
|
2012-10-01 13:33:26 -07:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: [{
|
2012-05-14 14:21:59 -07:00
|
|
|
eventType: this.ANDROID_VIEW_CLICKED,
|
|
|
|
text: UtteranceGenerator.genForAction(aObject, aActionName)
|
2012-10-01 13:33:26 -07:00
|
|
|
}]
|
|
|
|
};
|
2012-05-14 14:21:59 -07:00
|
|
|
},
|
|
|
|
|
2012-05-18 11:56:38 -07:00
|
|
|
tabSelected: function AndroidPresenter_tabSelected(aDocContext, aVCContext) {
|
2012-05-14 14:21:59 -07:00
|
|
|
// Send a pivot change message with the full context utterance for this doc.
|
2012-10-01 13:33:26 -07:00
|
|
|
return this.pivotChanged(aVCContext, Ci.nsIAccessiblePivot.REASON_NONE);
|
2012-05-14 14:21:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
tabStateChanged: function AndroidPresenter_tabStateChanged(aDocObj,
|
|
|
|
aPageState) {
|
2012-10-01 13:33:26 -07:00
|
|
|
return this._appAnnounce(
|
2012-07-10 16:10:15 -07:00
|
|
|
UtteranceGenerator.genForTabStateChange(aDocObj, aPageState));
|
2012-05-14 14:21:59 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
textChanged: function AndroidPresenter_textChanged(aIsInserted, aStart,
|
|
|
|
aLength, aText,
|
|
|
|
aModifiedText) {
|
2012-10-19 13:39:37 -07:00
|
|
|
let eventDetails = {
|
|
|
|
eventType: this.ANDROID_VIEW_TEXT_CHANGED,
|
|
|
|
text: [aText],
|
|
|
|
fromIndex: aStart,
|
|
|
|
removedCount: 0,
|
|
|
|
addedCount: 0
|
2012-05-14 14:21:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (aIsInserted) {
|
2012-10-19 13:39:37 -07:00
|
|
|
eventDetails.addedCount = aLength;
|
|
|
|
eventDetails.beforeText =
|
2012-05-14 14:21:59 -07:00
|
|
|
aText.substring(0, aStart) + aText.substring(aStart + aLength);
|
|
|
|
} else {
|
2012-10-19 13:39:37 -07:00
|
|
|
eventDetails.removedCount = aLength;
|
|
|
|
eventDetails.beforeText =
|
2012-05-14 14:21:59 -07:00
|
|
|
aText.substring(0, aStart) + aModifiedText + aText.substring(aStart);
|
2012-04-13 16:18:57 -07:00
|
|
|
}
|
|
|
|
|
2012-10-19 13:39:37 -07:00
|
|
|
return {type: this.type, details: [eventDetails]};
|
2012-05-14 14:21:59 -07:00
|
|
|
},
|
2012-04-13 16:18:57 -07:00
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
viewportChanged: function AndroidPresenter_viewportChanged(aWindow) {
|
2012-06-25 10:34:52 -07:00
|
|
|
if (Utils.AndroidSdkVersion < 14)
|
2012-10-01 13:33:26 -07:00
|
|
|
return null;
|
2012-06-25 10:34:52 -07:00
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: [{
|
2012-06-25 10:34:52 -07:00
|
|
|
eventType: this.ANDROID_VIEW_SCROLLED,
|
|
|
|
text: [],
|
2012-10-01 13:33:26 -07:00
|
|
|
scrollX: aWindow.scrollX,
|
|
|
|
scrollY: aWindow.scrollY,
|
|
|
|
maxScrollX: aWindow.scrollMaxX,
|
|
|
|
maxScrollY: aWindow.scrollMaxY
|
|
|
|
}]
|
|
|
|
};
|
2012-06-25 10:34:52 -07:00
|
|
|
},
|
|
|
|
|
2012-07-10 16:10:15 -07:00
|
|
|
editingModeChanged: function AndroidPresenter_editingModeChanged(aIsEditing) {
|
2012-10-01 13:33:26 -07:00
|
|
|
return this._appAnnounce(UtteranceGenerator.genForEditingMode(aIsEditing));
|
2012-07-10 16:10:15 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_appAnnounce: function _appAnnounce(aUtterance) {
|
|
|
|
if (!aUtterance.length)
|
2012-10-01 13:33:26 -07:00
|
|
|
return null;
|
2012-07-10 16:10:15 -07:00
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: [{
|
2012-08-20 15:29:22 -07:00
|
|
|
eventType: (Utils.AndroidSdkVersion >= 16) ?
|
|
|
|
this.ANDROID_ANNOUNCEMENT : this.ANDROID_VIEW_TEXT_CHANGED,
|
2012-07-10 16:10:15 -07:00
|
|
|
text: aUtterance,
|
|
|
|
addedCount: aUtterance.join(' ').length,
|
|
|
|
removedCount: 0,
|
|
|
|
fromIndex: 0
|
2012-10-01 13:33:26 -07:00
|
|
|
}]
|
|
|
|
};
|
2012-05-14 14:21:59 -07:00
|
|
|
}
|
2012-04-13 16:18:57 -07:00
|
|
|
};
|
2012-05-18 11:56:38 -07:00
|
|
|
|
2012-07-20 09:46:54 -07:00
|
|
|
/**
|
|
|
|
* A speech presenter for direct TTS output
|
|
|
|
*/
|
|
|
|
|
2012-11-12 15:46:09 -08:00
|
|
|
this.SpeechPresenter = function SpeechPresenter() {};
|
2012-07-20 09:46:54 -07:00
|
|
|
|
|
|
|
SpeechPresenter.prototype = {
|
|
|
|
__proto__: Presenter.prototype,
|
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
type: 'Speech',
|
2012-07-20 09:46:54 -07:00
|
|
|
|
|
|
|
pivotChanged: function SpeechPresenter_pivotChanged(aContext, aReason) {
|
|
|
|
if (!aContext.accessible)
|
2012-10-01 13:33:26 -07:00
|
|
|
return null;
|
2012-07-20 09:46:54 -07:00
|
|
|
|
|
|
|
let output = [];
|
|
|
|
|
|
|
|
aContext.newAncestry.forEach(
|
|
|
|
function(acc) {
|
|
|
|
output.push.apply(output, UtteranceGenerator.genForObject(acc));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
output.push.apply(output,
|
|
|
|
UtteranceGenerator.genForObject(aContext.accessible));
|
|
|
|
|
|
|
|
aContext.subtreePreorder.forEach(
|
|
|
|
function(acc) {
|
|
|
|
output.push.apply(output, UtteranceGenerator.genForObject(acc));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
details: {
|
|
|
|
actions: [
|
|
|
|
{method: 'playEarcon', data: 'tick', options: {}},
|
|
|
|
{method: 'speak', data: output.join(' '), options: {enqueue: true}}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
2012-07-20 09:46:54 -07:00
|
|
|
}
|
2012-10-01 13:33:26 -07:00
|
|
|
};
|
2012-11-12 15:46:09 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A haptic presenter
|
|
|
|
*/
|
|
|
|
|
|
|
|
this.HapticPresenter = function HapticPresenter() {};
|
|
|
|
|
|
|
|
HapticPresenter.prototype = {
|
|
|
|
__proto__: Presenter.prototype,
|
|
|
|
|
|
|
|
type: 'Haptic',
|
|
|
|
|
|
|
|
PIVOT_CHANGE_PATTHERN: [20],
|
|
|
|
|
|
|
|
pivotChanged: function HapticPresenter_pivotChanged(aContext, aReason) {
|
|
|
|
return { type: this.type, details: { pattern: this.PIVOT_CHANGE_PATTHERN } };
|
|
|
|
}
|
|
|
|
};
|
2012-07-20 09:46:54 -07:00
|
|
|
|
2012-05-18 11:56:38 -07:00
|
|
|
/**
|
|
|
|
* PresenterContext: An object that generates and caches context information
|
|
|
|
* for a given accessible and its relationship with another accessible.
|
|
|
|
*/
|
2012-10-31 09:13:28 -07:00
|
|
|
this.PresenterContext = function PresenterContext(aAccessible, aOldAccessible) {
|
2012-05-18 11:56:38 -07:00
|
|
|
this._accessible = aAccessible;
|
2012-05-22 11:01:39 -07:00
|
|
|
this._oldAccessible =
|
|
|
|
this._isDefunct(aOldAccessible) ? null : aOldAccessible;
|
2012-05-18 11:56:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PresenterContext.prototype = {
|
|
|
|
get accessible() {
|
|
|
|
return this._accessible;
|
|
|
|
},
|
|
|
|
|
|
|
|
get oldAccessible() {
|
|
|
|
return this._oldAccessible;
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
|
|
|
let newLineage = [];
|
|
|
|
let oldLineage = [];
|
|
|
|
|
|
|
|
let parent = this._accessible;
|
2012-05-29 13:46:08 -07:00
|
|
|
while (parent && (parent = parent.parent))
|
2012-05-18 11:56:38 -07:00
|
|
|
newLineage.push(parent);
|
|
|
|
|
2012-05-29 13:46:08 -07:00
|
|
|
parent = this._oldAccessible;
|
|
|
|
while (parent && (parent = parent.parent))
|
|
|
|
oldLineage.push(parent);
|
2012-05-18 11:56:38 -07:00
|
|
|
|
|
|
|
this._newAncestry = [];
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
let newAncestor = newLineage.pop();
|
|
|
|
let oldAncestor = oldLineage.pop();
|
|
|
|
|
|
|
|
if (newAncestor == undefined)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (newAncestor != oldAncestor)
|
|
|
|
this._newAncestry.push(newAncestor);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._newAncestry;
|
2012-05-22 11:01:39 -07:00
|
|
|
},
|
|
|
|
|
2012-05-29 13:46:08 -07:00
|
|
|
/*
|
|
|
|
* This is a flattened list of the accessible's subtree in preorder.
|
|
|
|
* It only includes the accessible's visible chidren.
|
|
|
|
*/
|
|
|
|
get subtreePreorder() {
|
|
|
|
function traversePreorder(aAccessible) {
|
|
|
|
let list = [];
|
|
|
|
let child = aAccessible.firstChild;
|
|
|
|
while (child) {
|
|
|
|
let state = {};
|
|
|
|
child.getState(state, {});
|
|
|
|
|
|
|
|
if (!(state.value & Ci.nsIAccessibleStates.STATE_INVISIBLE)) {
|
|
|
|
list.push(child);
|
|
|
|
list.push.apply(list, traversePreorder(child));
|
|
|
|
}
|
|
|
|
|
|
|
|
child = child.nextSibling;
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._subtreePreOrder)
|
|
|
|
this._subtreePreOrder = traversePreorder(this._accessible);
|
|
|
|
|
|
|
|
return this._subtreePreOrder;
|
|
|
|
},
|
|
|
|
|
2012-08-20 15:29:22 -07:00
|
|
|
get bounds() {
|
|
|
|
if (!this._bounds) {
|
|
|
|
let objX = {}, objY = {}, objW = {}, objH = {};
|
|
|
|
|
|
|
|
this._accessible.getBounds(objX, objY, objW, objH);
|
|
|
|
|
2012-10-01 13:33:26 -07:00
|
|
|
// XXX: OOP content provides a screen offset of 0, while in-process provides a real
|
|
|
|
// offset. Removing the offset and using content-relative coords normalizes this.
|
2012-08-20 15:29:22 -07:00
|
|
|
let docX = {}, docY = {};
|
|
|
|
let docRoot = this._accessible.rootDocument.
|
|
|
|
QueryInterface(Ci.nsIAccessible);
|
|
|
|
docRoot.getBounds(docX, docY, {}, {});
|
|
|
|
|
|
|
|
this._bounds = new Rect(objX.value, objY.value, objW.value, objH.value).
|
|
|
|
translate(-docX.value, -docY.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._bounds.clone();
|
|
|
|
},
|
|
|
|
|
2012-05-22 11:01:39 -07:00
|
|
|
_isDefunct: function _isDefunct(aAccessible) {
|
|
|
|
try {
|
|
|
|
let extstate = {};
|
|
|
|
aAccessible.getState({}, extstate);
|
|
|
|
return !!(aAccessible.value & Ci.nsIAccessibleStates.EXT_STATE_DEFUNCT);
|
|
|
|
} catch (x) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-05-18 11:56:38 -07:00
|
|
|
}
|
|
|
|
};
|