Accessibility/SoftFocus: Difference between revisions

 
(4 intermediate revisions by the same user not shown)
Line 6: Line 6:
=== nsIAccessiblePivot ===
=== nsIAccessiblePivot ===


typedef short nsAccessiblePivotBoundary;
  interface nsIAccessiblePivot : nsISupports
  interface nsIAccessiblePivot : nsISupports
  {
  {
  const nsAccessiblePivotBoundary BOUNDARY_CHAR            = 0;
  const nsAccessiblePivotBoundary BOUNDARY_WORD            = 1;
  const nsAccessiblePivotBoundary BOUNDARY_LINE            = 2;
  const nsAccessiblePivotBoundary BOUNDARY_ATTRIBUTE_RANGE = 3;
   /*
   /*
     * The accessible the pivot is currently pointed at.
     * The accessible the pivot is currently pointed at.
Line 51: Line 58:
     */
     */
   void setTextOffset(in long aStartOffset, in long aEndOffset);
   void setTextOffset(in long aStartOffset, in long aEndOffset);
  /**
    * Move pivot to next object via given traversal rule, which defines a filter
    *  and a search order.
    *
    * @param aRule traversal rule to use.
    * @param aLast traverse to the last occurance in the document.
    * @return true on success, false if there are no new nodes to traverse to.
    */
  boolean nexObject(in nsIAccessibleTraversalRule aRule, in boolean aLast);
  /**
    * Move pivot to previous object via given traversal rule, which defines a
    *  filter and a search order.
    *
    * @param aRule traversal rule to use.
    * @param aFirst traverse to the first occurance in the document.
    * @return true on success, false if there are no new nodes to traverse to.
    */
  boolean previousObject(in nsIAccessibleTraversalRule aRule, in boolean aFirst);
  /**
    * Move pivot to next text range.
    *
    * @param aBoundary type of boundary for next text range, character, word, etc.
    * @param aLast traverse to the last occurance in the document.
    * @return true on success, false if there are is no more text.
    */
  boolean nextText(in nsAccessiblePivotBoundary aBoundary, in boolean aLast);
  /**
    * Move pivot to previous text range.
    *
    * @param aBoundary type of boundary for previous text range, character, word,
    *  etc.
    * @param aFirst traverse to the first occurance in the document.
    * @return true on success, false if there are is no more text.
    */
  boolean previousText(in nsAccessiblePivotBoundary aBoundary, in boolean aFirst);
   
   
   /*
   /*
Line 92: Line 138:
   readonly attribute nsIAccessiblePivot virtualCursor;
   readonly attribute nsIAccessiblePivot virtualCursor;
  }
  }
=== nsIAccessibleVirtualCursorChangeEvent ===
An accessible event of  type EVENT_VIRTUALCURSOR_CHANGE. Fired when the virtual cursor's pivot is moved.
interface nsIAccessibleVirtualCursorChangeEvent: nsISupports
{
  /**
    * Document's virtual cursor pivot.
    */
  readonly attribute nsIAccessiblePivot pivot;
  /**
    * Previous object pointed at by virtual cursor. null if none.
    */
  readonly attribute nsIAccessible oldAccessible;
  /**
    * Previous start offset of pivot. -1 if none.
    */
  readonly attribute long oldStartOffset;
  /**
    * Previous end offset of pivot. -1 if none.
    */
  readonly attribute long oldEndOffset;
};


== Example Usage ==
== Example Usage ==


=== Setting Virtual Cursor ===
=== Setting Virtual Cursor ===
A traversal rule that goes to headers.
var headerTraversalRule = {
  QueryInterface: XPCOMUtils.generateQI([Ci.nsIAccessibleTraversalRule]),
  acceptRoles: [Ci.nsIAccessibleRole.ROLE_HEADER],
  acceptStates: 0xffffffff,
  acceptExtStates: 0xffffffff,
  skipStates: Ci.nsIAccessibleStates.STATE_INVISIBLE,
  skipExtStates: Ci.nsIAccessibleStates.EXT_STATE_DEFUNCT,
  traversalOrder: Ci.nsIAccessibleTraversalRule.ORDER_DEPTH_FIRST,
  filterAccessible: function (aAccessible) {return Ci.nsIAccessibleTraversalRule.FILTER_ACCEPT;}
}
A simple object traversal rule that goes to all leaves or focusable items.
var objectTraversalRule = {
  QueryInterface: XPCOMUtils.generateQI([Ci.nsIAccessibleTraversalRule]),
  acceptRoles: [],
  acceptStates: 0xffffffff,
  acceptExtStates: 0xffffffff,
  skipStates: Ci.nsIAccessibleStates.STATE_INVISIBLE,
  skipExtStates: Ci.nsIAccessibleStates.EXT_STATE_DEFUNCT,
  traversalOrder: Ci.nsIAccessibleTraversalRule.ORDER_DEPTH_FIRST,
  filterAccessible: function (aAccessible) {
      if (this._isFocusable(aAccessible))
        return Ci.nsIAccessibleTraversalRule.FILTER_ACCEPT;
      if (this._isFocusable(aAccessible.parent))
        return Ci.nsIAccessibleTraversalRule.FILTER_REJECT;
      if (aAccessible.childCount == 0)
        return Ci.nsIAccessibleTraversalRule.FILTER_ACCEPT;
  },
  _isFocusable: function (aAccessible) {
    let state = {};
    aAccessible.getState(state, null);
    return state.value & Ci.nsIAccessibleStates.EXT_STATE_FOCUSABLE != 0;
  }
}
An input event handler that changes the virtual cursor.
An input event handler that changes the virtual cursor.


  function inputEventHandler(event) {
  function inputEventHandler(event) {
   ...
   switch(event.keyCode) {
   treeWalker.currentNode = docAcc.virtualCursor.accessible;
  case 40:
   if (treeWalker.next())
    docAcc.virtualCursor.nextObject(objectTraversalRule, event.shiftKey);
     docAcc.virtualCursor.setAccessible(treeWalker.currentNode);
    break;
   case 38:
    docAcc.virtualCursor.previousObject(objectTraversalRule, event.shiftKey);
    break;
   case 39:
    docAcc.virtualCursor.nextObject(headerTraversalRule, event.shiftKey);
    break;
  case 37:
     docAcc.virtualCursor.previousObject(headerTraversalRule, event.shiftKey);
    break;
  default:
    break;
  }
  }


Line 109: Line 230:


  var VirtualCursorView = {
  var VirtualCursorView = {
   onPivotChanged: function onPivotChanged(aPivot, aOldAccessible, aOldStart, aOldEnd) {
   handleEvent: function (aEvent) {
     this.showRing(aPivot.accessible, aPivot.startOffset, aPivot.endOffset);
    if (aEvent.type != Cu.nsIAccessibleEvent.EVENT_VIRTUALCURSOR_CHANGED)
      return;
    let event = aEvent.QueryInterface(Ci.nsIAccessibleVirtualCursorChangeEvent);
     this.showRing(event.pivot.accessible, event.pivot.startOffset, event.pivot.endOffset);
   },
   },
   
   
Line 134: Line 259:
     aAccessible.getBounds(x, y, w, h);
     aAccessible.getBounds(x, y, w, h);
     drawRect(x.value, y.value, w.value, h.value);
     drawRect(x.value, y.value, w.value, h.value);
   },
   }
  QueryInterface: XPCOMUtils.generateQI([nsIAccessiblePivotObserver])
  }
  }
Confirmed users
198

edits