From b4e5b8455191baa71a2ff75310c6a8e7d6927573 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Tue, 11 Feb 2014 10:41:02 -0800 Subject: [PATCH] Bug 965628 - Clear cursor when leaving iframe. r=yzen --- accessible/src/jsat/EventManager.jsm | 12 +++++++++--- accessible/src/jsat/content-script.js | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/accessible/src/jsat/EventManager.jsm b/accessible/src/jsat/EventManager.jsm index 96af9b30c4c0..5774ab7e234a 100644 --- a/accessible/src/jsat/EventManager.jsm +++ b/accessible/src/jsat/EventManager.jsm @@ -155,12 +155,18 @@ this.EventManager.prototype = { let event = aEvent. QueryInterface(Ci.nsIAccessibleVirtualCursorChangeEvent); let reason = event.reason; + let oldAccessible = event.oldAccessible; + + if (oldAccessible && oldAccessible.role == Roles.INTERNAL_FRAME) { + let mm = Utils.getMessageManager(oldAccessible.DOMNode); + mm.sendAsyncMessage('AccessFu:ClearCursor', {}); + } if (this.editState.editing) { aEvent.accessibleDocument.takeFocus(); } this.present( - Presentation.pivotChanged(position, event.oldAccessible, reason, + Presentation.pivotChanged(position, oldAccessible, reason, pivot.startOffset, pivot.endOffset)); break; @@ -184,7 +190,7 @@ this.EventManager.prototype = { } case Events.SCROLLING_START: { - let vc = Utils.getVirtualCursor(aEvent.accessibleDocument); + let vc = Utils.getVirtualCursor(this.contentScope.content.document); vc.moveNext(TraversalRules.Simple, aEvent.accessible, true); break; } @@ -283,7 +289,7 @@ this.EventManager.prototype = { case Events.DOCUMENT_LOAD_COMPLETE: { this._autoMove = this.contentScope.content.setTimeout(() => { - Utils.getVirtualCursor(aEvent.accessibleDocument) + Utils.getVirtualCursor(this.contentScope.content.document) .moveNext(TraversalRules.Simple, aEvent.accessible, true); }, 500); break; diff --git a/accessible/src/jsat/content-script.js b/accessible/src/jsat/content-script.js index 953fc24b4ea8..a61f68934a6a 100644 --- a/accessible/src/jsat/content-script.js +++ b/accessible/src/jsat/content-script.js @@ -27,6 +27,15 @@ Logger.debug('content-script.js'); let eventManager = null; +function clearCursor(aMessage) { + try { + Utils.getVirtualCursor(content.document).position = null; + forwardToChild(aMessage); + } catch (x) { + Logger.logException(x); + } +} + function moveCursor(aMessage) { if (Logger.logLevel >= Logger.DEBUG) { Logger.debug(aMessage.name, JSON.stringify(aMessage.json, null, ' ')); @@ -144,7 +153,11 @@ function forwardToChild(aMessage, aListener, aVCPosition) { } let mm = Utils.getMessageManager(acc.DOMNode); - mm.addMessageListener(aMessage.name, aListener); + + if (aListener) { + mm.addMessageListener(aMessage.name, aListener); + } + // XXX: This is a silly way to make a deep copy let newJSON = JSON.parse(JSON.stringify(aMessage.json)); newJSON.origin = 'parent'; @@ -381,6 +394,7 @@ addMessageListener( addMessageListener('AccessFu:AdjustRange', adjustRange); addMessageListener('AccessFu:MoveCaret', moveCaret); addMessageListener('AccessFu:MoveByGranularity', moveByGranularity); + addMessageListener('AccessFu:ClearCursor', clearCursor); if (!eventManager) { eventManager = new EventManager(this); @@ -401,6 +415,7 @@ addMessageListener( removeMessageListener('AccessFu:Scroll', scroll); removeMessageListener('AccessFu:MoveCaret', moveCaret); removeMessageListener('AccessFu:MoveByGranularity', moveByGranularity); + removeMessageListener('AccessFu:ClearCursor', clearCursor); eventManager.stop(); });