Bug 775659 - move getVirtualCursor to util function. Fix moveCursorToObject. r=davidb

This commit is contained in:
Eitan Isaacson 2012-07-20 09:46:54 -07:00
parent 353de3e964
commit 8947c75b9d
3 changed files with 31 additions and 27 deletions

View File

@ -357,7 +357,8 @@ var AccessFu = {
}
case Ci.nsIAccessibleEvent.EVENT_SCROLLING_START:
{
VirtualCursorController.moveCursorToObject(aEvent.accessible);
VirtualCursorController.moveCursorToObject(
Utils.getVirtualCursor(aEvent.accessibleDocument), aEvent.accessible);
break;
}
case Ci.nsIAccessibleEvent.EVENT_FOCUS:
@ -366,7 +367,8 @@ var AccessFu = {
let doc = aEvent.accessibleDocument;
if (acc.role != Ci.nsIAccessibleRole.ROLE_DOCUMENT &&
doc.role != Ci.nsIAccessibleRole.ROLE_CHROME_WINDOW)
VirtualCursorController.moveCursorToObject(acc);
VirtualCursorController.moveCursorToObject(
Utils.getVirtualCursor(doc), acc);
let [,extState] = Utils.getStates(acc);
let editableState = extState &

View File

@ -88,6 +88,21 @@ var Utils = {
let extState = {};
aAccessible.getState(state, extState);
return [state.value, extState.value];
},
getVirtualCursor: function getVirtualCursor(aDocument) {
let doc = (aDocument instanceof Ci.nsIAccessible) ? aDocument :
gAccRetrieval.getAccessibleFor(aDocument);
while (doc) {
try {
return doc.QueryInterface(Ci.nsIAccessibleCursorable).virtualCursor;
} catch (x) {
doc = doc.parentDocument;
}
}
return null;
}
};

View File

@ -334,12 +334,12 @@ var VirtualCursorController = {
},
moveToPoint: function moveToPoint(aDocument, aX, aY) {
this.getVirtualCursor(aDocument).moveToPoint(TraversalRules.Simple,
Utils.getVirtualCursor(aDocument).moveToPoint(TraversalRules.Simple,
aX, aY, true);
},
moveForward: function moveForward(aDocument, aLast, aRule) {
let virtualCursor = this.getVirtualCursor(aDocument);
let virtualCursor = Utils.getVirtualCursor(aDocument);
if (aLast) {
virtualCursor.moveLast(TraversalRules.Simple);
} else {
@ -347,13 +347,14 @@ var VirtualCursorController = {
virtualCursor.moveNext(aRule || TraversalRules.Simple);
} catch (x) {
this.moveCursorToObject(
virtualCursor,
gAccRetrieval.getAccessibleFor(aDocument.activeElement), aRule);
}
}
},
moveBackward: function moveBackward(aDocument, aFirst, aRule) {
let virtualCursor = this.getVirtualCursor(aDocument);
let virtualCursor = Utils.getVirtualCursor(aDocument);
if (aFirst) {
virtualCursor.moveFirst(TraversalRules.Simple);
} else {
@ -361,13 +362,14 @@ var VirtualCursorController = {
virtualCursor.movePrevious(aRule || TraversalRules.Simple);
} catch (x) {
this.moveCursorToObject(
virtualCursor,
gAccRetrieval.getAccessibleFor(aDocument.activeElement), aRule);
}
}
},
activateCurrent: function activateCurrent(document) {
let virtualCursor = this.getVirtualCursor(document);
let virtualCursor = Utils.getVirtualCursor(document);
let acc = virtualCursor.position;
if (acc.actionCount > 0) {
@ -394,24 +396,9 @@ var VirtualCursorController = {
}
},
getVirtualCursor: function getVirtualCursor(document) {
return gAccRetrieval.getAccessibleFor(document).
QueryInterface(Ci.nsIAccessibleCursorable).virtualCursor;
},
moveCursorToObject: function moveCursorToObject(aAccessible, aRule) {
let doc = aAccessible.document;
while (doc) {
let vc = null;
try {
vc = doc.QueryInterface(Ci.nsIAccessibleCursorable).virtualCursor;
} catch (x) {
doc = doc.parentDocument;
continue;
}
vc.moveNext(aRule || TraversalRules.Simple, aAccessible, true);
break;
}
moveCursorToObject: function moveCursorToObject(aVirtualCursor,
aAccessible, aRule) {
aVirtualCursor.moveNext(aRule || TraversalRules.Simple, aAccessible, true);
},
keyMap: {