Accessibility/SoftFocus: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| Line 110: | Line 110: | ||
var VirtualCursorView = { | var VirtualCursorView = { | ||
onPivotChanged: function onPivotChanged(aPivot, aOldAccessible, aOldStart, aOldEnd) { | onPivotChanged: function onPivotChanged(aPivot, aOldAccessible, aOldStart, aOldEnd) { | ||
this.showVirtualCursorRing(aPivot.accessible, | |||
aPivot.startOffset, | |||
aPivot.endOffset); | |||
this.showVirtualCursorRing( | |||
}, | }, | ||
showVirtualCursorRing: function showVirtualCursorRing (aAccessible, | showVirtualCursorRing: function showVirtualCursorRing (aAccessible, aStartOffset, aEndOffset) { | ||
let x = {}; | let x = {}; | ||
let y = {}; | let y = {}; | ||
Revision as of 02:07, 27 November 2011
Background
It is useful to have a focus-like state that is exclusive to accessibility and is independant of the DOM state. From the user's perspective this allows reviewing a document or web application without directly affecting its state, like moving the caret or cycling through focusable elements. This is useful in mobile, for example a user could navigate to a text entry without having it capture input. Only if the user chooses to enter text they would "activate" the text entry which would bring up an on screen keyboard, etc. This feature would also allow easier navigation of content.
Interfaces
nsIAccessibleVirtualPivot
interface nsIAccessiblePivot : nsISupports
{
/*
* The accessible the pivot is currently pointed at.
*/
readonly attribute nsIAccessible accessible;
/*
* The document that owns this pivot.
*/
readonly attribute nsIAccessibleDocument rootAccessible;
/*
* The start offset in the accessible's text. Only supported when the accessible has
* the nsIAccessibleText interface. If no explicit offset was set or if it is not
* supported in the pivot's accessible this is -1.
*/
readonly attribute long startOffset;
/*
* The end offset in the accessible's text. Only supported when the accessible has
* the nsIAccessibleText interface. If no explicit offset was set or if it is not
* supported in the pivot's accessible this is -1.
*/
readonly attribute long endOffset;
/*
* Set the accessible this pivot should point to.
*
* @param aAccessible the new accessible to point to.
* @throws NS_ERROR_INVALID_ARG when given accessible is not in the pivot's document.
*/
void setAccessible(in nsIAccessible aAccessible);
/**
* Set the pivot's text range in a text accessible.
*
* @param aStartOffset the start offset to set.
* @param aEndOffset the end offset to set.
* @throws NS_ERROR_FAILURE when the pivot's accessible does not have the
* nsIAccessibleText inteface.
*/
void setTextOffset(in long aStartOffset, in long aEndOffset);
/*
* Add an observer for pivot changes.
*
* @param aObserver the observer object to be notified of pivot changes.
*/
void addObserver(in nsIAccessiblePivotObserver aObserver);
/*
* Remove an observer for pivot changes.
*
* @param aObserver the observer object to remove from being notified.
*/
void removeObserver(in nsIAccessiblePivotObserver aObserver);
};
nsIAccessibleVirtualPivotObserver
interface nsIAccessibleVirtualPivotObserver : nsISupports
{
/**
* Called when observed pivot changes.
*/
void onPivotChanged(in nsIAccessiblePivot aPivot,
in nsIAccessible aOldAccessible,
in long aOldStart, in long aOldEnd);
}
nsIAccessibleDocument
interface nsIAccessibleDocument : nsISupports
{
...
/**
* The virtual cursor pivot for this document.
*/
readonly attribute nsIAccessibleVirtualPivot virtualCursor;
/**
* Create a new pivot in this document.
*/
nsIAccessibleVirtualPivot createVirtualPivot();
}
Example Usage
Setting Virtual Cursor
An input event handler that changes the virtual cursor.
function inputEventHandler(event) {
...
treeWalker.currentNode = docAcc.virtualCursor.accessible;
if (treeWalker.next())
docAcc.virtualCursor.setAccessible(treeWalker.currentNode);
}
Presenting Virtual Cursor
An event listener that draws a ring for the virtual cursor. drawRect() is left to your imagination.
var VirtualCursorView = {
onPivotChanged: function onPivotChanged(aPivot, aOldAccessible, aOldStart, aOldEnd) {
this.showVirtualCursorRing(aPivot.accessible,
aPivot.startOffset,
aPivot.endOffset);
},
showVirtualCursorRing: function showVirtualCursorRing (aAccessible, aStartOffset, aEndOffset) {
let x = {};
let y = {};
let w = {};
let h = {};
if (aStartOffset >= 0 && aEndOffset >= 0) {
try {
let textAcc = aAccessible.QueryInterface(nsIAccessibleText);
let start = {};
let end = {};
textAcc.getRangeExtents(aStartOffset, aEndOffset, x, y, w, h,
COORDTYPE_SCREEN_RELATIVE);
drawRect(x.value, y.value, w.value, h.value);
return;
} catch (e) {
}
}
aAccessible.getBounds(x, y, w, h);
drawRect(x.value, y.value, w.value, h.value);
},
QueryInterface: XPCOMUtils.generateQI([nsIAccessibleVirtualPivotObserver])
}