SNAV: snav can move focus out from single-line input fields only if cursor is at one of the widget edges. r=dougt

This commit is contained in:
Antonio Gomes (tonikitoo) 2009-02-23 18:07:43 -04:00
Родитель 4d66bc6ccb
Коммит 73b187a40e
3 изменённых файлов: 105 добавлений и 97 удалений

Просмотреть файл

@ -119,34 +119,62 @@ function _onInputKeyPress (event, callback) {
if (!PrefObserver['xulContentEnabled'] && doc instanceof Ci.nsIDOMXULDocument)
return ;
// check to see if we are in a textarea or text input element, and if so,
// Check to see if we are in a textarea or text input element, and if so,
// ensure that we let the arrow keys work properly.
if (target instanceof Ci.nsIDOMHTMLHtmlElement) {
_focusNextUsingCmdDispatcher(key, callback);
return;
}
if ((target instanceof Ci.nsIDOMHTMLInputElement && (target.type == "text" || target.type == "password")) ||
target instanceof Ci.nsIDOMHTMLTextAreaElement ) {
// If it is a single-line input fields ...
if (target instanceof Ci.nsIDOMHTMLInputElement &&
(target.type == "text" || target.type == "password")) {
// if there is any selection at all, just ignore
// Up/Down should not care and just move. However, Right/Left
// should check the following before move.
if (key != PrefObserver['keyCodeUp'] &&
key != PrefObserver['keyCodeDown']) {
// If there is any selection at all, then do not move.
if (target.selectionEnd - target.selectionStart > 0)
return;
// if there is no text, there is nothing special to do.
// If there is text, check if it is okay to move.
if (target.textLength > 0) {
if (key == PrefObserver['keyCodeRight'] ||
key == PrefObserver['keyCodeDown'] ) {
// we are moving forward into the document
if (target.textLength != target.selectionEnd)
// Cursor not at the beginning.
if (key == PrefObserver['keyCodeLeft'] &&
target.selectionStart != 0)
return;
// Cursor not at the end.
if (key == PrefObserver['keyCodeRight'] &&
target.textLength != target.selectionEnd)
return;
}
else
{
// we are at the start of the text, okay to move
}
}
// 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 text, there check if it is okay to move.
if (target.textLength > 0) {
if (key == PrefObserver['keyCodeUp'] ||
key == PrefObserver['keyCodeLeft']) {
// Cursor not at the beginning.
if (target.selectionStart != 0)
return;
}
else {
if (key == PrefObserver['keyCodeDown'] ||
key == PrefObserver['keyCodeRight'])
// Cursor not at the end.
if (target.selectionEnd != target.textLength)
return;
}
}
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -6,7 +6,7 @@
https://bugzilla.mozilla.org/show_bug.cgi?id=436084
-->
<window title="Mozilla Bug 288254"
<window title="Mozilla Bug 436084"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="onLoad();">
@ -27,7 +27,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=436084
</p>
<p>
<textarea id="textarea" name="textarea" cols="30" rows="3" wrap="hard">The Book of Mozilla</textarea>
<textarea id="textarea" name="textarea" cols="30" rows="3" wrap="hard">Firefox</textarea>
</p>
<p>
@ -36,75 +36,56 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=436084
</body>
<script class="testbody" type="application/javascript">
<![CDATA[
Components.utils.import("resource://gre/modules/SpatialNavigation.js");
var moveTable = [
["DOWN", "textinput"],
["DOWN", "textinput"],
["DOWN", "textarea"],
["DOWN", "textarea"],
["DOWN", "end"],
["UP", "textarea"],
["UP", "textarea"],
["UP", "textinput"],
["UP", "textinput"],
["UP", "start"],
["DOWN", "textinput"],
["LEFT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textinput"],
["RIGHT", "textarea"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["LEFT", "textinput"],
["DOWN", "textarea"],
["LEFT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "textarea"],
["RIGHT", "end"],
["UP", "textarea"],
["LEFT", "textarea"],
["LEFT", "textarea"],
["LEFT", "textarea"],
["LEFT", "textarea"],
["LEFT", "textarea"],
["LEFT", "textarea"],
["DOWN", "textarea"],
["DOWN", "end"],
["DONE", "DONE"],
];