Bug 939705 - Arrow keys not working in context menu r=mbrubeck

--HG--
extra : rebase_source : d63f915eec428aaf8932689c25bd81e40635a7e3
This commit is contained in:
Rodrigo Silveira 2013-11-26 17:07:51 -08:00
parent 4c584f3f4a
commit 99b3c7cc3f
3 changed files with 54 additions and 47 deletions

View File

@ -129,7 +129,7 @@ FormAssistant.prototype = {
}
// Don't re-open when navigating to avoid repopulating list when changing selection.
if (this._isAutocomplete(aElement) && this._open && this._isNavigationKey(aEvent)) {
if (this._isAutocomplete(aElement) && this._open && Util.isNavigationKey(aEvent.keyCode)) {
return false;
}
@ -293,22 +293,6 @@ FormAssistant.prototype = {
}
},
_isNavigationKey: function (aEvent) {
// Ignore navigation keys
if (aEvent.keyCode) {
let navigationKeys = [
aEvent.DOM_VK_DOWN,
aEvent.DOM_VK_UP,
aEvent.DOM_VK_LEFT,
aEvent.DOM_VK_RIGHT,
aEvent.DOM_VK_PAGE_UP,
aEvent.DOM_VK_PAGE_DOWN];
return navigationKeys.indexOf(aEvent.keyCode) != -1;
}
return false;
},
_executeDelayed: function formHelperExecuteSoon(aCallback) {
let self = this;
let timer = new Util.Timeout(function() {

View File

@ -50,7 +50,6 @@ var AutofillMenuUI = {
show: function show(aAnchorRect, aSuggestionsList) {
this.commands.addEventListener("select", this, true);
window.addEventListener("keypress", this, true);
this._anchorRect = aAnchorRect;
this._emptyCommands();
@ -72,7 +71,6 @@ var AutofillMenuUI = {
},
hide: function hide () {
window.removeEventListener("keypress", this, true);
this.commands.removeEventListener("select", this, true);
this._menuPopup.hide();
@ -80,30 +78,6 @@ var AutofillMenuUI = {
handleEvent: function (aEvent) {
switch (aEvent.type) {
case "keypress":
switch (aEvent.keyCode) {
case aEvent.DOM_VK_ESCAPE:
this.hide();
break;
case aEvent.DOM_VK_DOWN:
this.commands.moveByOffset(1, true, false);
break;
case aEvent.DOM_VK_UP:
this.commands.moveByOffset(-1, true, false);
break;
case aEvent.DOM_VK_PAGE_DOWN:
this.commands.moveByOffset(this.commands.scrollOnePage(1), true, false);
break;
case aEvent.DOM_VK_PAGE_UP:
this.commands.moveByOffset(this.commands.scrollOnePage(-1), true, false);
break;
}
break;
case "select":
FormHelperUI.doAutoComplete(this.commands.value);
break;
@ -527,12 +501,47 @@ MenuPopup.prototype = {
handleEvent: function handleEvent(aEvent) {
switch (aEvent.type) {
case "keypress":
if (!this._wantTypeBehind) {
// this.commands is not holding focus and not processing key events.
// Proxying events so that they're handled properly.
// Avoid recursion
if (aEvent.mine)
break;
let ev = document.createEvent("KeyboardEvent");
ev.initKeyEvent(
"keypress", // in DOMString typeArg,
false, // in boolean canBubbleArg,
true, // in boolean cancelableArg,
null, // in nsIDOMAbstractView viewArg, Specifies UIEvent.view. This value may be null.
aEvent.ctrlKey, // in boolean ctrlKeyArg,
aEvent.altKey, // in boolean altKeyArg,
aEvent.shiftKey, // in boolean shiftKeyArg,
aEvent.metaKey, // in boolean metaKeyArg,
aEvent.keyCode, // in unsigned long keyCodeArg,
aEvent.charCode); // in unsigned long charCodeArg);
ev.mine = true;
this.commands.dispatchEvent(ev);
switch (aEvent.keyCode) {
case aEvent.DOM_VK_ESCAPE:
this.hide();
break;
case aEvent.DOM_VK_RETURN:
this.commands.currentItem.click();
break;
}
if (Util.isNavigationKey(aEvent.keyCode)) {
aEvent.stopPropagation();
aEvent.preventDefault();
} else if (!this._wantTypeBehind) {
// Hide the context menu so you can't type behind it.
aEvent.stopPropagation();
aEvent.preventDefault();
if (aEvent.keyCode != aEvent.DOM_VK_ESCAPE)
this.hide();
this.hide();
}
break;
case "blur":

View File

@ -6,6 +6,7 @@
this.EXPORTED_SYMBOLS = ["ContentUtil"];
const XHTML_NS = "http://www.w3.org/1999/xhtml";
const nsIDOMKeyEvent = Components.interfaces.nsIDOMKeyEvent;
this.ContentUtil = {
populateFragmentFromString: function populateFragmentFromString(fragment, str) {
@ -87,6 +88,19 @@ this.ContentUtil = {
// Return the modified object
return target;
}
},
// Checks if a keycode is used for list navigation.
isNavigationKey: function (keyCode) {
let navigationKeys = [
nsIDOMKeyEvent.DOM_VK_DOWN,
nsIDOMKeyEvent.DOM_VK_UP,
nsIDOMKeyEvent.DOM_VK_LEFT,
nsIDOMKeyEvent.DOM_VK_RIGHT,
nsIDOMKeyEvent.DOM_VK_PAGE_UP,
nsIDOMKeyEvent.DOM_VK_PAGE_DOWN,
nsIDOMKeyEvent.DOM_VK_ESCAPE];
return navigationKeys.indexOf(keyCode) != -1;
}
};