Bug 757598 - Fallback for items that don't have accessible actions. r=davidb
authorEitan Isaacson <eitan@monotonous.org>
Wed, 23 May 2012 12:10:04 -0700
changeset 97137 995cc950c60ea16abc0cb20ab95c45e6889743cd
parent 97006 71075a6e5d4d887f65d1f44d3a724787a96b2ab9
child 97138 913e0063106749e7ef4b2f782d035afb602dec57
push idunknown
push userunknown
push dateunknown
reviewersdavidb
bugs757598
milestone15.0a1
Bug 757598 - Fallback for items that don't have accessible actions. r=davidb
accessible/src/jsat/VirtualCursorController.jsm
--- a/accessible/src/jsat/VirtualCursorController.jsm
+++ b/accessible/src/jsat/VirtualCursorController.jsm
@@ -131,18 +131,38 @@ var VirtualCursorController = {
       }
     }
   },
 
   activateCurrent: function activateCurrent(document) {
     let virtualCursor = this.getVirtualCursor(document);
     let acc = virtualCursor.position;
 
-    if (acc.numActions > 0)
+    if (acc.numActions > 0) {
       acc.doAction(0);
+    } else {
+      // XXX Some mobile widget sets do not expose actions properly
+      // (via ARIA roles, etc.), so we need to generate a click.
+      // Could possibly be made simpler in the future. Maybe core
+      // engine could expose nsCoreUtiles::DispatchMouseEvent()?
+      let docAcc = gAccRetrieval.getAccessibleFor(this.chromeWin.document);
+      let docX = {}, docY = {}, docW = {}, docH = {};
+      docAcc.getBounds(docX, docY, docW, docH);
+
+      let objX = {}, objY = {}, objW = {}, objH = {};
+      acc.getBounds(objX, objY, objW, objH);
+
+      let x = Math.round((objX.value - docX.value) + objW.value/2);
+      let y = Math.round((objY.value - docY.value) + objH.value/2);
+
+      let cwu = this.chromeWin.QueryInterface(Ci.nsIInterfaceRequestor).
+        getInterface(Ci.nsIDOMWindowUtils);
+      cwu.sendMouseEventToWindow('mousedown', x, y, 0, 1, 0, false);
+      cwu.sendMouseEventToWindow('mouseup', x, y, 0, 1, 0, false);
+    }
   },
 
   getVirtualCursor: function getVirtualCursor(document) {
     return gAccRetrieval.getAccessibleFor(document).
       QueryInterface(Ci.nsIAccessibleCursorable).virtualCursor;
   },
 
   SimpleTraversalRule: {