зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1512661 - Let up/down keys open the results popup. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D13980 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
fcf46c0f6d
Коммит
cadc97f7fd
|
@ -37,7 +37,7 @@ class QueryContext {
|
|||
* The maximum number of results that will be displayed for this query.
|
||||
* @param {boolean} [options.autoFill]
|
||||
* Whether or not to include autofill results. Optional, as this is normally
|
||||
* set by the AddressBarController.
|
||||
* set by the UrlbarController.
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
this._checkRequiredOptions(options, [
|
||||
|
@ -224,18 +224,20 @@ class UrlbarController {
|
|||
this.input.handleCommand(event);
|
||||
return;
|
||||
case KeyEvent.DOM_VK_TAB:
|
||||
this.view.selectNextItem({ reverse: event.shiftKey });
|
||||
event.preventDefault();
|
||||
break;
|
||||
case KeyEvent.DOM_VK_DOWN:
|
||||
if (!event.ctrlKey && !event.altKey) {
|
||||
this.view.selectNextItem();
|
||||
if (this.view.isOpen) {
|
||||
this.view.selectNextItem({ reverse: event.shiftKey });
|
||||
event.preventDefault();
|
||||
}
|
||||
break;
|
||||
case KeyEvent.DOM_VK_DOWN:
|
||||
case KeyEvent.DOM_VK_UP:
|
||||
if (!event.ctrlKey && !event.altKey) {
|
||||
this.view.selectNextItem({ reverse: true });
|
||||
if (this.view.isOpen) {
|
||||
this.view.selectNextItem({
|
||||
reverse: event.keyCode == KeyEvent.DOM_VK_UP });
|
||||
} else {
|
||||
this.input.startQuery();
|
||||
}
|
||||
event.preventDefault();
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -135,10 +135,6 @@ class UrlbarInput {
|
|||
this.view.close();
|
||||
}
|
||||
|
||||
openResults() {
|
||||
this.view.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an internal URI (e.g. a wyciwyg URI) into one which we can
|
||||
* expose to the user.
|
||||
|
@ -331,6 +327,26 @@ class UrlbarInput {
|
|||
this.value = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a query based on the user input.
|
||||
*
|
||||
* @param {string} [options.searchString]
|
||||
* The string the user entered in autocomplete.
|
||||
* @param {number} [options.lastKey]
|
||||
* The last key the user entered (as a key code).
|
||||
*/
|
||||
startQuery({
|
||||
searchString = "",
|
||||
lastKey = null,
|
||||
} = {}) {
|
||||
this.controller.startQuery(new QueryContext({
|
||||
searchString,
|
||||
lastKey,
|
||||
maxResults: UrlbarPrefs.get("maxRichResults"),
|
||||
isPrivate: this.isPrivate,
|
||||
}));
|
||||
}
|
||||
|
||||
// Getters and Setters below.
|
||||
|
||||
get focused() {
|
||||
|
@ -653,12 +669,10 @@ class UrlbarInput {
|
|||
}
|
||||
|
||||
// XXX Fill in lastKey, and add anything else we need.
|
||||
this.controller.startQuery(new QueryContext({
|
||||
this.startQuery({
|
||||
searchString: value,
|
||||
lastKey: "",
|
||||
maxResults: UrlbarPrefs.get("maxRichResults"),
|
||||
isPrivate: this.isPrivate,
|
||||
}));
|
||||
lastKey: null,
|
||||
});
|
||||
}
|
||||
|
||||
_on_select(event) {
|
||||
|
|
|
@ -64,8 +64,7 @@ class UrlbarView {
|
|||
*/
|
||||
selectNextItem({reverse = false} = {}) {
|
||||
if (!this.isOpen) {
|
||||
this.open();
|
||||
return;
|
||||
throw new Error("UrlbarView: Cannot select an item if the view isn't open.");
|
||||
}
|
||||
|
||||
// TODO: handle one-off search buttons
|
||||
|
@ -90,24 +89,6 @@ class UrlbarView {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the autocomplete results popup.
|
||||
*/
|
||||
open() {
|
||||
this.panel.removeAttribute("hidden");
|
||||
|
||||
this._alignPanel();
|
||||
|
||||
// TODO: Search one off buttons are a stub right now.
|
||||
// We'll need to set them up properly.
|
||||
this.oneOffSearchButtons;
|
||||
|
||||
this.panel.openPopup(this.input.textbox.closest("toolbar"), "after_end", 0, -1);
|
||||
|
||||
this._selected = this._rows.firstElementChild;
|
||||
this._selected.toggleAttribute("selected", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the autocomplete results popup.
|
||||
*/
|
||||
|
@ -136,7 +117,7 @@ class UrlbarView {
|
|||
for (let resultIndex in queryContext.results) {
|
||||
this._addRow(resultIndex);
|
||||
}
|
||||
this.open();
|
||||
this._openPanel();
|
||||
}
|
||||
|
||||
// Private methods below.
|
||||
|
@ -149,6 +130,21 @@ class UrlbarView {
|
|||
return this.document.createElementNS("http://www.w3.org/1999/xhtml", name);
|
||||
}
|
||||
|
||||
_openPanel() {
|
||||
this.panel.removeAttribute("hidden");
|
||||
|
||||
this._alignPanel();
|
||||
|
||||
// TODO: Search one off buttons are a stub right now.
|
||||
// We'll need to set them up properly.
|
||||
this.oneOffSearchButtons;
|
||||
|
||||
this.panel.openPopup(this.input.textbox.closest("toolbar"), "after_end", 0, -1);
|
||||
|
||||
this._selected = this._rows.firstElementChild;
|
||||
this._selected.toggleAttribute("selected", true);
|
||||
}
|
||||
|
||||
_alignPanel() {
|
||||
// Make the panel span the width of the window.
|
||||
let documentRect =
|
||||
|
|
Загрузка…
Ссылка в новой задаче