Bug 935807: Restore arrow key input field navigation behavior. r=bnicholson a=bajaj
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 04 Dec 2013 15:43:32 -0800
changeset 167646 4fb95c60417e65f5e4d051d0072c770309fbeb09
parent 167645 f3d6a773ab72afd8c7a88f62898cca8840a04c0a
child 167647 2c001ca401cc6c9b52379846a1a9fb0946177a41
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson, bajaj
bugs935807
milestone27.0a2
Bug 935807: Restore arrow key input field navigation behavior. r=bnicholson a=bajaj
toolkit/modules/SpatialNavigation.jsm
--- a/toolkit/modules/SpatialNavigation.jsm
+++ b/toolkit/modules/SpatialNavigation.jsm
@@ -120,16 +120,38 @@ function _onInputKeyPress (event, callba
   // loaded, and this is the first keypress in the page.
   if (currentlyFocused instanceof Ci.nsIDOMHTMLBodyElement) {
     focusManager.moveFocus(currentlyFocusedWindow, null, focusManager.MOVEFOCUS_FIRST, 0);
     event.stopPropagation();
     event.preventDefault();
     return;
   }
 
+  if ((currentlyFocused instanceof Ci.nsIDOMHTMLInputElement &&
+      currentlyFocused.mozIsTextField(false)) ||
+      currentlyFocused instanceof Ci.nsIDOMHTMLTextAreaElement) {
+    // If there is a text selection, remain in the element.
+    if (currentlyFocused.selectionEnd - currentlyFocused.selectionStart != 0) {
+      return;
+    }
+
+    // If there is no text, there is nothing special to do.
+    if (currentlyFocused.textLength > 0) {
+      if (key == PrefObserver['keyCodeRight'] ||
+          key == PrefObserver['keyCodeDown'] ) {
+        // We are moving forward into the document.
+        if (currentlyFocused.textLength != currentlyFocused.selectionEnd) {
+          return;
+        }
+      } else if (currentlyFocused.selectionStart != 0) {
+        return;
+      }
+    }
+  }
+
   let windowUtils = currentlyFocusedWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                                           .getInterface(Ci.nsIDOMWindowUtils);
   let cssPageRect = _getRootBounds(windowUtils);
   let searchRect = _getSearchRect(currentlyFocused, key, cssPageRect);
 
   let nodes = {};
   nodes.length = 0;