Bug 1182214 - Update highlight rect as you scroll. r=yzen
authorEitan Isaacson <eitan@monotonous.org>
Mon, 14 Sep 2015 10:52:43 -0700
changeset 295001 013a4f0f60e3d353a4dbf16cf4c12033fc94306c
parent 295000 2ed46aca6ae071b59fb287f3aaf325129d9e4327
child 295002 108cd7f55f80b0291a997f082bd0f0f0c161c668
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyzen
bugs1182214
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1182214 - Update highlight rect as you scroll. r=yzen
accessible/jsat/Presentation.jsm
--- a/accessible/jsat/Presentation.jsm
+++ b/accessible/jsat/Presentation.jsm
@@ -103,18 +103,19 @@ Presenter.prototype = {
    *   virtual cursor position.
    */
   tabSelected: function tabSelected(aDocContext, aVCContext) {}, // jshint ignore:line
 
   /**
    * The viewport has changed, either a scroll, pan, zoom, or
    *    landscape/portrait toggle.
    * @param {Window} aWindow window of viewport that changed.
+   * @param {PivotContext} aCurrentContext context of last pivot change.
    */
-  viewportChanged: function viewportChanged(aWindow) {}, // jshint ignore:line
+  viewportChanged: function viewportChanged(aWindow, aCurrentContext) {}, // jshint ignore:line
 
   /**
    * We have entered or left text editing mode.
    */
   editingModeChanged: function editingModeChanged(aIsEditing) {}, // jshint ignore:line
 
   /**
    * Announce something. Typically an app state change.
@@ -137,39 +138,36 @@ Presenter.prototype = {
    */
   liveRegion: function liveRegionShown(aContext, aIsPolite, aIsHide, // jshint ignore:line
     aModifiedText) {} // jshint ignore:line
 };
 
 /**
  * Visual presenter. Draws a box around the virtual cursor's position.
  */
-function VisualPresenter() {
-  this._displayedAccessibles = new WeakMap();
-}
+function VisualPresenter() {}
 
 VisualPresenter.prototype = Object.create(Presenter.prototype);
 
 VisualPresenter.prototype.type = 'Visual';
 
 /**
  * The padding in pixels between the object and the highlight border.
  */
 VisualPresenter.prototype.BORDER_PADDING = 2;
 
 VisualPresenter.prototype.viewportChanged =
-  function VisualPresenter_viewportChanged(aWindow) {
-    let currentDisplay = this._displayedAccessibles.get(aWindow);
-    if (!currentDisplay) {
+  function VisualPresenter_viewportChanged(aWindow, aCurrentContext) {
+    if (!aCurrentContext) {
       return null;
     }
 
-    let currentAcc = currentDisplay.accessible;
-    let start = currentDisplay.startOffset;
-    let end = currentDisplay.endOffset;
+    let currentAcc = aCurrentContext.accessibleForBounds;
+    let start = aCurrentContext.startOffset;
+    let end = aCurrentContext.endOffset;
     if (Utils.isAliveAndVisible(currentAcc)) {
       let bounds = (start === -1 && end === -1) ? Utils.getBounds(currentAcc) :
                    Utils.getTextBounds(currentAcc, start, end);
 
       return {
         type: this.type,
         details: {
           eventType: 'viewport-change',
@@ -184,21 +182,16 @@ VisualPresenter.prototype.viewportChange
 
 VisualPresenter.prototype.pivotChanged =
   function VisualPresenter_pivotChanged(aContext) {
     if (!aContext.accessible) {
       // XXX: Don't hide because another vc may be using the highlight.
       return null;
     }
 
-    this._displayedAccessibles.set(aContext.accessible.document.window,
-                                   { accessible: aContext.accessibleForBounds,
-                                     startOffset: aContext.startOffset,
-                                     endOffset: aContext.endOffset });
-
     try {
       aContext.accessibleForBounds.scrollTo(
         Ci.nsIAccessibleScrollType.SCROLL_TYPE_ANYWHERE);
 
       let bounds = (aContext.startOffset === -1 && aContext.endOffset === -1) ?
             aContext.bounds : Utils.getTextBounds(aContext.accessibleForBounds,
                                                   aContext.startOffset,
                                                   aContext.endOffset);
@@ -408,31 +401,43 @@ AndroidPresenter.prototype.textSelection
 
     return {
       type: this.type,
       details: androidEvents
     };
   };
 
 AndroidPresenter.prototype.viewportChanged =
-  function AndroidPresenter_viewportChanged(aWindow) {
+  function AndroidPresenter_viewportChanged(aWindow, aCurrentContext) {
     if (Utils.AndroidSdkVersion < 14) {
       return null;
     }
 
+    let events = [{
+      eventType: this.ANDROID_VIEW_SCROLLED,
+      text: [],
+      scrollX: aWindow.scrollX,
+      scrollY: aWindow.scrollY,
+      maxScrollX: aWindow.scrollMaxX,
+      maxScrollY: aWindow.scrollMaxY
+    }];
+
+    if (Utils.AndroidSdkVersion >= 16 && aCurrentContext) {
+      let currentAcc = aCurrentContext.accessibleForBounds;
+      if (Utils.isAliveAndVisible(currentAcc)) {
+        events.push({
+          eventType: this.ANDROID_VIEW_ACCESSIBILITY_FOCUSED,
+          bounds: Utils.getBounds(currentAcc)
+        });
+      }
+    }
+
     return {
       type: this.type,
-      details: [{
-        eventType: this.ANDROID_VIEW_SCROLLED,
-        text: [],
-        scrollX: aWindow.scrollX,
-        scrollY: aWindow.scrollY,
-        maxScrollX: aWindow.scrollMaxX,
-        maxScrollY: aWindow.scrollMaxY
-      }]
+      details: events
     };
   };
 
 AndroidPresenter.prototype.editingModeChanged =
   function AndroidPresenter_editingModeChanged(aIsEditing) {
     return this.announce(UtteranceGenerator.genForEditingMode(aIsEditing));
   };
 
@@ -678,20 +683,27 @@ this.Presentation = { // jshint ignore:l
       'mobile/android': [VisualPresenter, AndroidPresenter],
       'b2g': [VisualPresenter, B2GPresenter],
       'browser': [VisualPresenter, B2GPresenter, AndroidPresenter]
     };
     this.presenters = [new P() for (P of presenterMap[Utils.MozBuildApp])]; // jshint ignore:line
     return this.presenters;
   },
 
+  get displayedAccessibles() {
+    delete this.displayedAccessibles;
+    this.displayedAccessibles = new WeakMap();
+  },
+
   pivotChanged: function Presentation_pivotChanged(
     aPosition, aOldPosition, aReason, aStartOffset, aEndOffset, aIsUserInput) {
     let context = new PivotContext(
       aPosition, aOldPosition, aStartOffset, aEndOffset);
+    this.displayedAccessibles.set(context.accessible.document.window, context);
+
     return [p.pivotChanged(context, aReason, aIsUserInput)
       for each (p in this.presenters)]; // jshint ignore:line
   },
 
   actionInvoked: function Presentation_actionInvoked(aObject, aActionName) {
     return [p.actionInvoked(aObject, aActionName) // jshint ignore:line
       for each (p in this.presenters)]; // jshint ignore:line
   },
@@ -719,17 +731,19 @@ this.Presentation = { // jshint ignore:l
   },
 
   tabStateChanged: function Presentation_tabStateChanged(aDocObj, aPageState) {
     return [p.tabStateChanged(aDocObj, aPageState) // jshint ignore:line
       for each (p in this.presenters)]; // jshint ignore:line
   },
 
   viewportChanged: function Presentation_viewportChanged(aWindow) {
-    return [p.viewportChanged(aWindow) for each (p in this.presenters)]; // jshint ignore:line
+    let context = this.displayedAccessibles.get(aWindow);
+    return [p.viewportChanged(aWindow, context) // jshint ignore:line
+      for each (p in this.presenters)]; // jshint ignore:line
   },
 
   editingModeChanged: function Presentation_editingModeChanged(aIsEditing) {
     return [p.editingModeChanged(aIsEditing) for each (p in this.presenters)]; // jshint ignore:line
   },
 
   announce: function Presentation_announce(aAnnouncement) {
     // XXX: Typically each presenter uses the UtteranceGenerator,