From 1547cbf97dceb953d8e58821838c893676ca42d3 Mon Sep 17 00:00:00 2001 From: Antonio Gomes Date: Thu, 22 Jan 2009 11:07:27 -0400 Subject: [PATCH] Bug 464598 (SNAV: snav can move focus out from single-line input fields only if cursor is at one of the widget edges) r=dougt --- .../spatial-navigation/SpatialNavigation.js | 52 ++++++++++++++----- toolkit/spatial-navigation/tests/Makefile.in | 3 +- .../tests/chrome/test_snav_textFields.xul | 10 ++-- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/toolkit/spatial-navigation/SpatialNavigation.js b/toolkit/spatial-navigation/SpatialNavigation.js index 682a0e105124..0c007e66d3f0 100644 --- a/toolkit/spatial-navigation/SpatialNavigation.js +++ b/toolkit/spatial-navigation/SpatialNavigation.js @@ -126,27 +126,53 @@ function _onInputKeyPress (event, callback) { return; } - if ((target instanceof Ci.nsIDOMHTMLInputElement && (target.type == "text" || target.type == "password")) || - target instanceof Ci.nsIDOMHTMLTextAreaElement ) { - - // if there is any selection at all, just ignore + // if it is a single-line input fields ... + if (target instanceof Ci.nsIDOMHTMLInputElement && + (target.type == "text" || target.type == "password")) { + + // up/down should not care and just move. + if (key != PrefObserver['keyCodeUp'] && + key != PrefObserver['keyCodeDown']) { + + // if there is any selection at all, just ignore + if (target.selectionEnd - target.selectionStart > 0) + return; + + // if there is no text, there is nothing special to do. + if (target.textLength > 0) + if (key == PrefObserver['keyCodeLeft']) { + // if there is text, there it isn't okay to move + if (target.selectionStart != 0) + return; + } + else if (key == PrefObserver['keyCodeRight']) { + // we are moving forward into the document + if (target.textLength != target.selectionEnd) + return; + } + } + } + // if it is a multi-line input field ... + else if (target instanceof Ci.nsIDOMHTMLTextAreaElement) { + + // if there is any selection at all, again just ignore if (target.selectionEnd - target.selectionStart > 0) return; // if there is no text, there is nothing special to do. if (target.textLength > 0) { - if (key == PrefObserver['keyCodeRight'] || - key == PrefObserver['keyCodeDown'] ) { - // we are moving forward into the document - if (target.textLength != target.selectionEnd) - return; - } - else - { - // we are at the start of the text, okay to move + if (key == PrefObserver['keyCodeUp'] || + key == PrefObserver['keyCodeLeft']) { + // if there is text, there it isn't okay to move if (target.selectionStart != 0) return; } + else { + if (key == PrefObserver['keyCodeDown'] || + key == PrefObserver['keyCodeRight']) + if (target.selectionEnd != target.textLength) + return; + } } } diff --git a/toolkit/spatial-navigation/tests/Makefile.in b/toolkit/spatial-navigation/tests/Makefile.in index 97bc9e9bfdc8..fd1568bd7bdd 100644 --- a/toolkit/spatial-navigation/tests/Makefile.in +++ b/toolkit/spatial-navigation/tests/Makefile.in @@ -50,11 +50,10 @@ MOCHI_TESTS = chrome/test_snav.xul \ chrome/test_snav_selects.xul \ chrome/test_snav_prefDisabled.xul \ chrome/test_snav_prefKeyCode.xul \ + chrome/test_snav_textFields.xul \ chrome/SpatialNavUtils.js \ $(NULL) -# bug 447671 chrome/test_snav_textFields.xul \ - include $(topsrcdir)/config/rules.mk libs:: $(MOCHI_TESTS) $(MOCHI_CONTENT) diff --git a/toolkit/spatial-navigation/tests/chrome/test_snav_textFields.xul b/toolkit/spatial-navigation/tests/chrome/test_snav_textFields.xul index 470e847e1544..dfc17fe69e55 100644 --- a/toolkit/spatial-navigation/tests/chrome/test_snav_textFields.xul +++ b/toolkit/spatial-navigation/tests/chrome/test_snav_textFields.xul @@ -6,7 +6,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=436084 --> - @@ -36,25 +36,21 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=436084 -