From 738fc1e2b72b201c88abaa235793030e054b65d9 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Wed, 3 Jul 2013 15:02:44 -0700 Subject: [PATCH] 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() --- accessible/src/jsat/Presentation.jsm | 14 +++++---- accessible/src/jsat/Utils.jsm | 44 ++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/accessible/src/jsat/Presentation.jsm b/accessible/src/jsat/Presentation.jsm index b88a934b201f..66acd9cd3520 100644 --- a/accessible/src/jsat/Presentation.jsm +++ b/accessible/src/jsat/Presentation.jsm @@ -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'}}; diff --git a/accessible/src/jsat/Utils.jsm b/accessible/src/jsat/Utils.jsm index 3aa43429a4c4..9968dbf15155 100644 --- a/accessible/src/jsat/Utils.jsm +++ b/accessible/src/jsat/Utils.jsm @@ -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; }