Bug 887586 - Replace referece to current accessible in VisualPresenter with a WeakMap. r=davidb

This patch does other things to:
1. Refactor out getBounds()
2. Fix a mistake in PivotContext._isDefunct()
This commit is contained in:
Eitan Isaacson 2013-07-03 15:02:44 -07:00
parent 0fb1de1a60
commit 738fc1e2b7
2 changed files with 47 additions and 11 deletions

View File

@ -109,7 +109,9 @@ Presenter.prototype = {
* Visual presenter. Draws a box around the virtual cursor's position.
*/
this.VisualPresenter = function VisualPresenter() {};
this.VisualPresenter = function VisualPresenter() {
this._displayedAccessibles = new WeakMap();
};
VisualPresenter.prototype = {
__proto__: Presenter.prototype,
@ -122,13 +124,14 @@ VisualPresenter.prototype = {
BORDER_PADDING: 2,
viewportChanged: function VisualPresenter_viewportChanged(aWindow) {
if (this._currentAccessible) {
let context = new PivotContext(this._currentAccessible);
let currentAcc = this._displayedAccessibles.get(aWindow);
if (Utils.isAliveAndVisible(currentAcc)) {
let bounds = Utils.getBounds(currentAcc);
return {
type: this.type,
details: {
method: 'showBounds',
bounds: context.bounds,
bounds: bounds,
padding: this.BORDER_PADDING
}
};
@ -138,7 +141,8 @@ VisualPresenter.prototype = {
},
pivotChanged: function VisualPresenter_pivotChanged(aContext, aReason) {
this._currentAccessible = aContext.accessible;
this._displayedAccessibles.set(aContext.accessible.document.window,
aContext.accessible);
if (!aContext.accessible)
return {type: this.type, details: {method: 'hideBounds'}};

View File

@ -224,6 +224,42 @@ this.Utils = {
getPixelsPerCSSPixel: function getPixelsPerCSSPixel(aWindow) {
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils).screenPixelsPerCSSPixel;
},
getBounds: function getBounds(aAccessible) {
let objX = {}, objY = {}, objW = {}, objH = {};
aAccessible.getBounds(objX, objY, objW, objH);
return new Rect(objX.value, objY.value, objW.value, objH.value);
},
inHiddenSubtree: function inHiddenSubtree(aAccessible) {
for (let acc=aAccessible; acc; acc=acc.parent) {
if (JSON.parse(Utils.getAttributes(acc).hidden)) {
return true;
}
}
return false;
},
isAliveAndVisible: function isAliveAndVisible(aAccessible) {
if (!aAccessible) {
return false;
}
try {
let extstate = {};
let state = {};
aAccessible.getState(state, extstate);
if (extstate.value & Ci.nsIAccessibleStates.EXT_STATE_DEFUNCT ||
state.value & Ci.nsIAccessibleStates.STATE_INVISIBLE ||
Utils.inHiddenSubtree(aAccessible)) {
return false;
}
} catch (x) {
return false;
}
return true;
}
};
@ -559,11 +595,7 @@ PivotContext.prototype = {
get bounds() {
if (!this._bounds) {
let objX = {}, objY = {}, objW = {}, objH = {};
this._accessible.getBounds(objX, objY, objW, objH);
this._bounds = new Rect(objX.value, objY.value, objW.value, objH.value);
this._bounds = Utils.getBounds(this._accessible);
}
return this._bounds.clone();
@ -573,7 +605,7 @@ PivotContext.prototype = {
try {
let extstate = {};
aAccessible.getState({}, extstate);
return !!(aAccessible.value & Ci.nsIAccessibleStates.EXT_STATE_DEFUNCT);
return !!(extstate.value & Ci.nsIAccessibleStates.EXT_STATE_DEFUNCT);
} catch (x) {
return true;
}