2018-09-13 19:38:07 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var EXPORTED_SYMBOLS = ["UrlbarView"];
|
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2018-10-02 17:22:29 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetters(this, {
|
2019-01-18 13:40:22 +03:00
|
|
|
Services: "resource://gre/modules/Services.jsm",
|
2019-02-05 19:51:43 +03:00
|
|
|
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
|
2019-02-17 21:12:01 +03:00
|
|
|
UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.jsm",
|
2018-10-02 17:22:29 +03:00
|
|
|
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
|
2019-04-30 18:03:21 +03:00
|
|
|
AppConstants: "resource://gre/modules/AppConstants.jsm",
|
2018-10-02 17:22:29 +03:00
|
|
|
});
|
|
|
|
|
2019-01-18 13:40:22 +03:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "bundle", function() {
|
|
|
|
return Services.strings.createBundle("chrome://global/locale/autocomplete.properties");
|
|
|
|
});
|
|
|
|
|
2018-09-13 19:38:07 +03:00
|
|
|
/**
|
|
|
|
* Receives and displays address bar autocomplete results.
|
|
|
|
*/
|
|
|
|
class UrlbarView {
|
|
|
|
/**
|
2018-12-07 00:33:30 +03:00
|
|
|
* @param {UrlbarInput} input
|
2018-09-13 19:38:07 +03:00
|
|
|
* The UrlbarInput instance belonging to this UrlbarView instance.
|
|
|
|
*/
|
2018-12-07 00:33:30 +03:00
|
|
|
constructor(input) {
|
|
|
|
this.input = input;
|
|
|
|
this.panel = input.panel;
|
|
|
|
this.controller = input.controller;
|
|
|
|
this.document = this.panel.ownerDocument;
|
2018-09-13 19:38:07 +03:00
|
|
|
this.window = this.document.defaultView;
|
|
|
|
|
|
|
|
this._mainContainer = this.panel.querySelector(".urlbarView-body-inner");
|
2019-03-08 16:42:11 +03:00
|
|
|
this._rows = this.panel.querySelector("#urlbarView-results");
|
2018-09-13 19:38:07 +03:00
|
|
|
|
2019-03-29 16:28:27 +03:00
|
|
|
this._rows.addEventListener("mousedown", this);
|
2019-03-29 17:53:52 +03:00
|
|
|
this._rows.addEventListener("mouseup", this);
|
2018-12-07 00:33:30 +03:00
|
|
|
|
2018-09-13 19:38:07 +03:00
|
|
|
// For the horizontal fade-out effect, set the overflow attribute on result
|
|
|
|
// rows when they overflow.
|
2018-12-04 22:26:49 +03:00
|
|
|
this._rows.addEventListener("overflow", this);
|
|
|
|
this._rows.addEventListener("underflow", this);
|
2018-09-20 16:07:18 +03:00
|
|
|
|
2019-02-05 19:51:43 +03:00
|
|
|
this.panel.addEventListener("popupshowing", this);
|
2019-03-14 16:59:14 +03:00
|
|
|
this.panel.addEventListener("popupshown", this);
|
2019-01-24 15:22:14 +03:00
|
|
|
this.panel.addEventListener("popuphiding", this);
|
|
|
|
|
2018-12-07 00:33:30 +03:00
|
|
|
this.controller.setView(this);
|
2018-09-20 16:07:18 +03:00
|
|
|
this.controller.addQueryListener(this);
|
2018-09-13 19:38:07 +03:00
|
|
|
}
|
|
|
|
|
2018-11-17 11:46:35 +03:00
|
|
|
get oneOffSearchButtons() {
|
2019-02-19 01:32:05 +03:00
|
|
|
if (!this._oneOffSearchButtons) {
|
|
|
|
this._oneOffSearchButtons =
|
|
|
|
new this.window.SearchOneOffs(this.panel.querySelector(".search-one-offs"));
|
|
|
|
this._oneOffSearchButtons.addEventListener("SelectedOneOffButtonChanged", this);
|
|
|
|
}
|
|
|
|
return this._oneOffSearchButtons;
|
2018-11-17 11:46:35 +03:00
|
|
|
}
|
|
|
|
|
2018-12-07 00:33:30 +03:00
|
|
|
/**
|
|
|
|
* @returns {boolean}
|
|
|
|
* Whether the panel is open.
|
|
|
|
*/
|
|
|
|
get isOpen() {
|
|
|
|
return this.panel.state == "open" || this.panel.state == "showing";
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:06:54 +03:00
|
|
|
get allowEmptySelection() {
|
|
|
|
return !(this._queryContext &&
|
|
|
|
this._queryContext.results[0] &&
|
|
|
|
this._queryContext.results[0].heuristic);
|
|
|
|
}
|
|
|
|
|
2019-02-12 17:53:22 +03:00
|
|
|
get selectedIndex() {
|
|
|
|
if (!this.isOpen || !this._selected) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return parseInt(this._selected.getAttribute("resultIndex"));
|
|
|
|
}
|
|
|
|
|
|
|
|
set selectedIndex(val) {
|
|
|
|
if (!this.isOpen) {
|
|
|
|
throw new Error("UrlbarView: Cannot select an item if the view isn't open.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val < 0) {
|
|
|
|
this._selectItem(null);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2019-05-09 00:14:35 +03:00
|
|
|
let items = Array.from(this._rows.children)
|
|
|
|
.filter(r => r.style.display != "none");
|
2019-02-12 17:53:22 +03:00
|
|
|
if (val >= items.length) {
|
|
|
|
throw new Error(`UrlbarView: Index ${val} is out of bounds.`);
|
|
|
|
}
|
|
|
|
this._selectItem(items[val]);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2019-01-14 19:58:21 +03:00
|
|
|
/**
|
2019-01-24 14:23:20 +03:00
|
|
|
* @returns {UrlbarResult}
|
2019-01-14 19:58:21 +03:00
|
|
|
* The currently selected result.
|
|
|
|
*/
|
|
|
|
get selectedResult() {
|
2019-02-11 15:22:02 +03:00
|
|
|
if (!this.isOpen || !this._selected) {
|
2019-01-14 19:58:21 +03:00
|
|
|
return null;
|
|
|
|
}
|
2019-04-19 23:09:13 +03:00
|
|
|
return this._selected.result;
|
2019-01-14 19:58:21 +03:00
|
|
|
}
|
|
|
|
|
2019-02-15 17:57:23 +03:00
|
|
|
/**
|
|
|
|
* Gets the result for the index.
|
|
|
|
* @param {number} index
|
|
|
|
* The index to look up.
|
|
|
|
* @returns {UrlbarResult}
|
|
|
|
*/
|
|
|
|
getResult(index) {
|
|
|
|
if (index < 0 || index > this._queryContext.results.length) {
|
|
|
|
throw new Error(`UrlbarView: Index ${index} is out of bounds`);
|
|
|
|
}
|
|
|
|
return this._queryContext.results[index];
|
|
|
|
}
|
|
|
|
|
2018-12-07 00:33:30 +03:00
|
|
|
/**
|
2019-02-21 21:53:07 +03:00
|
|
|
* Moves the view selection forward or backward.
|
2018-12-07 00:33:30 +03:00
|
|
|
*
|
2019-02-21 21:53:07 +03:00
|
|
|
* @param {number} amount
|
|
|
|
* The number of steps to move.
|
2018-12-07 00:33:30 +03:00
|
|
|
* @param {boolean} options.reverse
|
|
|
|
* Set to true to select the previous item. By default the next item
|
|
|
|
* will be selected.
|
|
|
|
*/
|
2019-02-21 21:53:07 +03:00
|
|
|
selectBy(amount, {reverse = false} = {}) {
|
2018-12-07 00:33:30 +03:00
|
|
|
if (!this.isOpen) {
|
2018-12-11 18:14:56 +03:00
|
|
|
throw new Error("UrlbarView: Cannot select an item if the view isn't open.");
|
2018-12-07 00:33:30 +03:00
|
|
|
}
|
|
|
|
|
2019-03-29 17:53:52 +03:00
|
|
|
// Freeze results as the user is interacting with them.
|
|
|
|
this.controller.cancelQuery();
|
|
|
|
|
2019-02-21 21:53:07 +03:00
|
|
|
let row = this._selected;
|
|
|
|
|
2019-05-09 00:14:35 +03:00
|
|
|
// Results over maxResults may be hidden and should not be selectable.
|
|
|
|
let lastElementChild = this._rows.lastElementChild;
|
|
|
|
while (lastElementChild && lastElementChild.style.display == "none") {
|
|
|
|
lastElementChild = lastElementChild.previousElementSibling;
|
|
|
|
}
|
|
|
|
|
2019-02-21 21:53:07 +03:00
|
|
|
if (!row) {
|
2019-05-09 00:14:35 +03:00
|
|
|
this._selectItem(reverse ? lastElementChild :
|
2019-02-21 21:53:07 +03:00
|
|
|
this._rows.firstElementChild);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let endReached = reverse ?
|
|
|
|
(row == this._rows.firstElementChild) :
|
2019-05-09 00:14:35 +03:00
|
|
|
(row == lastElementChild);
|
2019-02-21 21:53:07 +03:00
|
|
|
if (endReached) {
|
|
|
|
if (this.allowEmptySelection) {
|
|
|
|
row = null;
|
|
|
|
} else {
|
2019-05-09 00:14:35 +03:00
|
|
|
row = reverse ? lastElementChild :
|
2019-02-21 21:53:07 +03:00
|
|
|
this._rows.firstElementChild;
|
|
|
|
}
|
|
|
|
this._selectItem(row);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (amount-- > 0) {
|
|
|
|
let next = reverse ? row.previousElementSibling : row.nextElementSibling;
|
|
|
|
if (!next) {
|
|
|
|
break;
|
|
|
|
}
|
2019-05-09 00:14:35 +03:00
|
|
|
if (next.style.display == "none") {
|
|
|
|
continue;
|
|
|
|
}
|
2019-02-21 21:53:07 +03:00
|
|
|
row = next;
|
2018-12-07 00:33:30 +03:00
|
|
|
}
|
2019-02-12 17:53:22 +03:00
|
|
|
this._selectItem(row);
|
2018-12-07 00:33:30 +03:00
|
|
|
}
|
|
|
|
|
2019-03-27 13:38:52 +03:00
|
|
|
removeAccessibleFocus() {
|
|
|
|
this._setAccessibleFocus(null);
|
|
|
|
}
|
|
|
|
|
2018-09-13 19:38:07 +03:00
|
|
|
/**
|
2019-02-28 12:33:08 +03:00
|
|
|
* Closes the autocomplete popup, cancelling the query if necessary.
|
2018-09-13 19:38:07 +03:00
|
|
|
*/
|
2019-05-09 00:14:33 +03:00
|
|
|
close() {
|
|
|
|
this.controller.cancelQuery();
|
2018-10-12 19:13:42 +03:00
|
|
|
this.panel.hidePopup();
|
2018-09-13 19:38:07 +03:00
|
|
|
}
|
|
|
|
|
2018-09-20 16:07:18 +03:00
|
|
|
// UrlbarController listener methods.
|
|
|
|
onQueryStarted(queryContext) {
|
2019-05-09 00:14:33 +03:00
|
|
|
this._queryWasCancelled = false;
|
2019-04-19 23:09:13 +03:00
|
|
|
this._startRemoveStaleRowsTimer();
|
2018-09-20 16:07:18 +03:00
|
|
|
}
|
|
|
|
|
2018-11-06 00:54:09 +03:00
|
|
|
onQueryCancelled(queryContext) {
|
2019-05-09 00:14:33 +03:00
|
|
|
this._queryWasCancelled = true;
|
2019-04-19 23:09:13 +03:00
|
|
|
this._cancelRemoveStaleRowsTimer();
|
2018-11-06 00:54:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onQueryFinished(queryContext) {
|
2019-04-19 23:09:13 +03:00
|
|
|
this._cancelRemoveStaleRowsTimer();
|
2019-05-09 00:14:33 +03:00
|
|
|
// If the query has not been canceled, remove stale rows immediately.
|
|
|
|
if (!this._queryWasCancelled) {
|
|
|
|
this._removeStaleRows();
|
|
|
|
}
|
2018-11-06 00:54:09 +03:00
|
|
|
}
|
|
|
|
|
2018-09-20 16:07:18 +03:00
|
|
|
onQueryResults(queryContext) {
|
2018-10-12 19:13:42 +03:00
|
|
|
this._queryContext = queryContext;
|
2019-01-29 23:47:42 +03:00
|
|
|
|
2019-04-19 23:09:13 +03:00
|
|
|
this._updateResults(queryContext);
|
2019-01-17 20:13:51 +03:00
|
|
|
|
2019-02-17 21:12:14 +03:00
|
|
|
let isFirstPreselectedResult = false;
|
2019-02-09 18:39:20 +03:00
|
|
|
if (queryContext.lastResultCount == 0) {
|
|
|
|
if (queryContext.preselected) {
|
2019-02-17 21:12:14 +03:00
|
|
|
isFirstPreselectedResult = true;
|
2019-03-28 20:08:04 +03:00
|
|
|
this._selectItem(this._rows.firstElementChild, {
|
2019-03-27 13:38:52 +03:00
|
|
|
updateInput: false,
|
2019-05-03 21:32:15 +03:00
|
|
|
setAccessibleFocus: this.controller._userSelectionBehavior == "arrow",
|
2019-03-27 13:38:52 +03:00
|
|
|
});
|
2019-02-12 17:53:22 +03:00
|
|
|
} else {
|
2019-02-09 18:39:20 +03:00
|
|
|
// Clear the selection when we get a new set of results.
|
2019-02-12 17:53:22 +03:00
|
|
|
this._selectItem(null);
|
2019-02-09 18:39:20 +03:00
|
|
|
}
|
2019-02-17 21:12:01 +03:00
|
|
|
// Hide the one-off search buttons if the input starts with a potential @
|
|
|
|
// search alias or the search restriction character.
|
|
|
|
let trimmedValue = this.input.textValue.trim();
|
|
|
|
this._enableOrDisableOneOffSearches(
|
|
|
|
!trimmedValue ||
|
|
|
|
(trimmedValue[0] != "@" &&
|
|
|
|
(trimmedValue[0] != UrlbarTokenizer.RESTRICT.SEARCH ||
|
|
|
|
trimmedValue.length != 1))
|
|
|
|
);
|
2019-03-28 20:08:04 +03:00
|
|
|
}
|
2019-01-29 23:47:42 +03:00
|
|
|
|
2018-12-11 18:14:56 +03:00
|
|
|
this._openPanel();
|
2019-02-17 21:12:14 +03:00
|
|
|
|
|
|
|
if (isFirstPreselectedResult) {
|
|
|
|
// The first, preselected result may be a search alias result, so apply
|
|
|
|
// formatting if necessary. Conversely, the first result of the previous
|
|
|
|
// query may have been an alias, so remove formatting if necessary.
|
|
|
|
this.input.formatValue();
|
|
|
|
}
|
2018-09-20 16:07:18 +03:00
|
|
|
}
|
|
|
|
|
2019-01-15 15:20:48 +03:00
|
|
|
/**
|
|
|
|
* Handles removing a result from the view when it is removed from the query,
|
|
|
|
* and attempts to select the new result on the same row.
|
|
|
|
*
|
|
|
|
* This assumes that the result rows are in index order.
|
|
|
|
*
|
|
|
|
* @param {number} index The index of the result that has been removed.
|
|
|
|
*/
|
|
|
|
onQueryResultRemoved(index) {
|
|
|
|
// Change the index for any rows above the removed index.
|
|
|
|
for (let i = index + 1; i < this._rows.children.length; i++) {
|
|
|
|
let child = this._rows.children[i];
|
|
|
|
child.setAttribute("resultIndex", child.getAttribute("resultIndex") - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
let rowToRemove = this._rows.children[index];
|
|
|
|
rowToRemove.remove();
|
|
|
|
|
|
|
|
if (rowToRemove != this._selected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select the row at the same index, if possible.
|
|
|
|
let newSelectionIndex = index;
|
|
|
|
if (index >= this._queryContext.results.length) {
|
|
|
|
newSelectionIndex = this._queryContext.results.length - 1;
|
|
|
|
}
|
|
|
|
if (newSelectionIndex >= 0) {
|
2019-02-12 17:53:22 +03:00
|
|
|
this.selectedIndex = newSelectionIndex;
|
2019-01-15 15:20:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 19:51:43 +03:00
|
|
|
/**
|
|
|
|
* Passes DOM events for the view to the _on_<event type> methods.
|
|
|
|
* @param {Event} event
|
|
|
|
* DOM event from the <view>.
|
|
|
|
*/
|
|
|
|
handleEvent(event) {
|
|
|
|
let methodName = "_on_" + event.type;
|
|
|
|
if (methodName in this) {
|
|
|
|
this[methodName](event);
|
|
|
|
} else {
|
|
|
|
throw new Error("Unrecognized UrlbarView event: " + event.type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called when a one-off is clicked and when "search in new tab"
|
|
|
|
* is selected from a one-off context menu.
|
|
|
|
* @param {Event} event
|
|
|
|
* @param {nsISearchEngine} engine
|
|
|
|
* @param {string} where
|
|
|
|
* @param {object} params
|
|
|
|
*/
|
|
|
|
handleOneOffSearch(event, engine, where, params) {
|
|
|
|
this.input.handleCommand(event, where, params);
|
|
|
|
}
|
|
|
|
|
2018-09-13 19:38:07 +03:00
|
|
|
// Private methods below.
|
|
|
|
|
|
|
|
_getBoundsWithoutFlushing(element) {
|
|
|
|
return this.window.windowUtils.getBoundsWithoutFlushing(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
_createElement(name) {
|
|
|
|
return this.document.createElementNS("http://www.w3.org/1999/xhtml", name);
|
|
|
|
}
|
|
|
|
|
2018-12-11 18:14:56 +03:00
|
|
|
_openPanel() {
|
2018-12-10 19:05:39 +03:00
|
|
|
if (this.isOpen) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-17 09:57:58 +03:00
|
|
|
this.controller.userSelectionBehavior = "none";
|
2018-12-10 19:05:39 +03:00
|
|
|
|
2018-12-11 18:14:56 +03:00
|
|
|
this.panel.removeAttribute("hidden");
|
2019-02-05 16:24:39 +03:00
|
|
|
this.panel.removeAttribute("actionoverride");
|
2018-12-11 18:14:56 +03:00
|
|
|
|
2018-11-22 19:29:51 +03:00
|
|
|
// Make the panel span the width of the window.
|
2019-04-15 16:05:03 +03:00
|
|
|
let px = number => number.toFixed(2) + "px";
|
2018-11-22 19:29:51 +03:00
|
|
|
let documentRect =
|
|
|
|
this._getBoundsWithoutFlushing(this.document.documentElement);
|
|
|
|
let width = documentRect.right - documentRect.left;
|
|
|
|
this.panel.setAttribute("width", width);
|
2019-04-15 16:05:03 +03:00
|
|
|
this._mainContainer.style.maxWidth = px(width);
|
2018-11-22 19:29:51 +03:00
|
|
|
|
2018-12-07 00:33:30 +03:00
|
|
|
// Keep the popup items' site icons aligned with the input's identity
|
2018-11-22 19:29:51 +03:00
|
|
|
// icon if it's not too far from the edge of the window. We define
|
|
|
|
// "too far" as "more than 30% of the window's width AND more than
|
|
|
|
// 250px".
|
2018-11-26 14:59:04 +03:00
|
|
|
let boundToCheck = this.window.RTL_UI ? "right" : "left";
|
2018-12-07 00:33:30 +03:00
|
|
|
let inputRect = this._getBoundsWithoutFlushing(this.input.textbox);
|
2018-11-22 19:29:51 +03:00
|
|
|
let startOffset = Math.abs(inputRect[boundToCheck] - documentRect[boundToCheck]);
|
|
|
|
let alignSiteIcons = startOffset / width <= 0.3 || startOffset <= 250;
|
|
|
|
if (alignSiteIcons) {
|
|
|
|
// Calculate the end margin if we have a start margin.
|
2018-11-26 14:59:04 +03:00
|
|
|
let boundToCheckEnd = this.window.RTL_UI ? "left" : "right";
|
2018-11-22 19:29:51 +03:00
|
|
|
let endOffset = Math.abs(inputRect[boundToCheckEnd] -
|
|
|
|
documentRect[boundToCheckEnd]);
|
|
|
|
if (endOffset > startOffset * 2) {
|
|
|
|
// Provide more space when aligning would result in an unbalanced
|
|
|
|
// margin. This allows the location bar to be moved to the start
|
|
|
|
// of the navigation toolbar to reclaim space for results.
|
|
|
|
endOffset = startOffset;
|
|
|
|
}
|
|
|
|
let identityIcon = this.document.getElementById("identity-icon");
|
|
|
|
let identityRect = this._getBoundsWithoutFlushing(identityIcon);
|
2018-11-26 14:59:04 +03:00
|
|
|
let start = this.window.RTL_UI ?
|
|
|
|
documentRect.right - identityRect.right :
|
|
|
|
identityRect.left;
|
2018-11-22 19:29:51 +03:00
|
|
|
|
2019-04-15 16:05:03 +03:00
|
|
|
this.panel.style.setProperty("--item-padding-start", px(start));
|
|
|
|
this.panel.style.setProperty("--item-padding-end", px(endOffset));
|
2018-11-22 19:29:51 +03:00
|
|
|
} else {
|
|
|
|
this.panel.style.removeProperty("--item-padding-start");
|
|
|
|
this.panel.style.removeProperty("--item-padding-end");
|
|
|
|
}
|
2019-03-29 21:49:44 +03:00
|
|
|
|
|
|
|
// Align the panel with the input's parent toolbar.
|
|
|
|
let toolbarRect =
|
|
|
|
this._getBoundsWithoutFlushing(this.input.textbox.closest("toolbar"));
|
2019-04-30 18:03:21 +03:00
|
|
|
let horizontalOffset = this.window.RTL_UI ?
|
2019-04-02 17:39:38 +03:00
|
|
|
inputRect.right - documentRect.right :
|
2019-04-30 18:03:21 +03:00
|
|
|
documentRect.left - inputRect.left;
|
|
|
|
let verticalOffset = inputRect.top - toolbarRect.top;
|
|
|
|
if (AppConstants.platform == "macosx") {
|
|
|
|
// Adjust vertical offset to account for the popup's native outer border.
|
|
|
|
verticalOffset++;
|
|
|
|
}
|
|
|
|
this.panel.style.marginInlineStart = px(horizontalOffset);
|
|
|
|
this.panel.style.marginTop = px(verticalOffset);
|
2019-04-02 17:39:38 +03:00
|
|
|
|
2019-04-11 14:47:18 +03:00
|
|
|
this.panel.openPopup(this.input.textbox, "after_start");
|
2018-11-22 19:29:51 +03:00
|
|
|
}
|
|
|
|
|
2019-05-09 00:14:35 +03:00
|
|
|
/**
|
|
|
|
* Whether a result is a search suggestion.
|
|
|
|
* @param {UrlbarResult} result The result to examine.
|
|
|
|
* @returns {boolean} Whether the result is a search suggestion.
|
|
|
|
*/
|
|
|
|
_resultIsSearchSuggestion(result) {
|
|
|
|
return Boolean(result &&
|
|
|
|
result.type == UrlbarUtils.RESULT_TYPE.SEARCH &&
|
|
|
|
result.payload.suggestion);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the given row index can be update to the result we want
|
|
|
|
* to apply. This is used in _updateResults to avoid flickering of results, by
|
|
|
|
* reusing existing rows.
|
|
|
|
* @param {number} rowIndex Index of the row to examine.
|
|
|
|
* @param {UrlbarResult} result The result we'd like to apply.
|
|
|
|
* @param {number} firstSearchSuggestionIndex Index of the first search suggestion.
|
|
|
|
* @param {number} lastSearchSuggestionIndex Index of the last search suggestion.
|
|
|
|
* @returns {boolean} Whether the row can be updated to this result.
|
|
|
|
*/
|
|
|
|
_rowCanUpdateToResult(rowIndex, result, firstSearchSuggestionIndex,
|
|
|
|
lastSearchSuggestionIndex) {
|
|
|
|
// The heuristic result must always be current, thus it's always compatible.
|
|
|
|
if (result.heuristic) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
let row = this._rows.children[rowIndex];
|
|
|
|
let resultIsSearchSuggestion = this._resultIsSearchSuggestion(result);
|
|
|
|
// If the row is same type, just update it.
|
|
|
|
if (resultIsSearchSuggestion == this._resultIsSearchSuggestion(row.result)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// If the row has a different type, update it if we are in a compatible
|
|
|
|
// index range.
|
|
|
|
// In practice we don't want to overwrite a search suggestion with a non
|
|
|
|
// search suggestion, but we allow the opposite.
|
|
|
|
return resultIsSearchSuggestion && rowIndex >= firstSearchSuggestionIndex;
|
|
|
|
}
|
|
|
|
|
2019-04-19 23:09:13 +03:00
|
|
|
_updateResults(queryContext) {
|
2019-05-09 00:14:35 +03:00
|
|
|
// TODO: For now this just compares search suggestions to the rest, in the
|
|
|
|
// future we should make it support any type of result. Or, even better,
|
|
|
|
// results should be grouped, thus we can directly update groups.
|
|
|
|
|
|
|
|
// Find where are existing search suggestions.
|
|
|
|
let firstSearchSuggestionIndex = -1;
|
|
|
|
let lastSearchSuggestionIndex = -1;
|
|
|
|
for (let i = 0; i < this._rows.children.length; ++i) {
|
|
|
|
let row = this._rows.children[i];
|
|
|
|
// Mark every row as stale, _updateRow will unmark them later.
|
|
|
|
row.setAttribute("stale", "true");
|
|
|
|
// Skip any row that isn't a search suggestion, or is non-visible because
|
|
|
|
// over maxResults.
|
|
|
|
if (row.result.heuristic ||
|
|
|
|
i >= queryContext.maxResults ||
|
|
|
|
!this._resultIsSearchSuggestion(row.result)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (firstSearchSuggestionIndex == -1) {
|
|
|
|
firstSearchSuggestionIndex = i;
|
|
|
|
}
|
|
|
|
lastSearchSuggestionIndex = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Walk rows and find an insertion index for results. To avoid flicker, we
|
|
|
|
// skip rows until we find one compatible with the result we want to apply.
|
|
|
|
// If we couldn't find a compatible range, we'll just update.
|
2019-04-19 23:09:13 +03:00
|
|
|
let results = queryContext.results;
|
2019-05-09 00:14:35 +03:00
|
|
|
let resultIndex = 0;
|
|
|
|
// We can have more rows than the visible ones.
|
|
|
|
for (let rowIndex = 0;
|
|
|
|
rowIndex < this._rows.children.length && resultIndex < results.length;
|
|
|
|
++rowIndex) {
|
|
|
|
let row = this._rows.children[rowIndex];
|
|
|
|
let result = results[resultIndex];
|
|
|
|
if (this._rowCanUpdateToResult(rowIndex, result,
|
|
|
|
firstSearchSuggestionIndex,
|
|
|
|
lastSearchSuggestionIndex)) {
|
|
|
|
this._updateRow(row, result);
|
|
|
|
resultIndex++;
|
2019-04-19 23:09:13 +03:00
|
|
|
}
|
|
|
|
}
|
2019-05-09 00:14:35 +03:00
|
|
|
// Add remaining results, if we have fewer rows than results.
|
|
|
|
for (; resultIndex < results.length; ++resultIndex) {
|
2019-04-19 23:09:13 +03:00
|
|
|
let row = this._createRow();
|
2019-05-09 00:14:35 +03:00
|
|
|
this._updateRow(row, results[resultIndex]);
|
|
|
|
// Due to stale rows, we may have more rows than maxResults, thus we must
|
|
|
|
// hide them, and we'll revert this when stale rows are removed.
|
|
|
|
if (this._rows.children.length >= queryContext.maxResults) {
|
|
|
|
row.style.display = "none";
|
|
|
|
}
|
2019-04-19 23:09:13 +03:00
|
|
|
this._rows.appendChild(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 20:08:04 +03:00
|
|
|
_createRow() {
|
2019-03-28 18:57:20 +03:00
|
|
|
let item = this._createElement("div");
|
|
|
|
item.className = "urlbarView-row";
|
|
|
|
item.setAttribute("role", "option");
|
2019-03-28 20:08:04 +03:00
|
|
|
item._elements = new Map;
|
|
|
|
|
|
|
|
let content = this._createElement("span");
|
|
|
|
content.className = "urlbarView-row-inner";
|
|
|
|
item.appendChild(content);
|
|
|
|
|
|
|
|
let typeIcon = this._createElement("span");
|
|
|
|
typeIcon.className = "urlbarView-type-icon";
|
|
|
|
content.appendChild(typeIcon);
|
|
|
|
|
|
|
|
let favicon = this._createElement("img");
|
|
|
|
favicon.className = "urlbarView-favicon";
|
|
|
|
content.appendChild(favicon);
|
|
|
|
item._elements.set("favicon", favicon);
|
|
|
|
|
|
|
|
let title = this._createElement("span");
|
|
|
|
title.className = "urlbarView-title";
|
|
|
|
content.appendChild(title);
|
|
|
|
item._elements.set("title", title);
|
|
|
|
|
2019-03-29 17:05:52 +03:00
|
|
|
let tagsContainer = this._createElement("span");
|
2019-03-28 20:08:04 +03:00
|
|
|
tagsContainer.className = "urlbarView-tags";
|
|
|
|
content.appendChild(tagsContainer);
|
|
|
|
item._elements.set("tagsContainer", tagsContainer);
|
|
|
|
|
|
|
|
let titleSeparator = this._createElement("span");
|
|
|
|
titleSeparator.className = "urlbarView-title-separator";
|
|
|
|
content.appendChild(titleSeparator);
|
2019-05-02 16:00:16 +03:00
|
|
|
item._elements.set("titleSeparator", titleSeparator);
|
2019-03-28 20:08:04 +03:00
|
|
|
|
|
|
|
let action = this._createElement("span");
|
|
|
|
action.className = "urlbarView-secondary urlbarView-action";
|
|
|
|
content.appendChild(action);
|
|
|
|
item._elements.set("action", action);
|
|
|
|
|
|
|
|
let url = this._createElement("span");
|
|
|
|
url.className = "urlbarView-secondary urlbarView-url";
|
|
|
|
content.appendChild(url);
|
|
|
|
item._elements.set("url", url);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2019-04-19 23:09:13 +03:00
|
|
|
_updateRow(item, result) {
|
|
|
|
let resultIndex = this._queryContext.results.indexOf(result);
|
|
|
|
item.result = result;
|
|
|
|
item.removeAttribute("stale");
|
2019-03-28 20:08:04 +03:00
|
|
|
item.id = "urlbarView-row-" + resultIndex;
|
|
|
|
item.setAttribute("resultIndex", resultIndex);
|
2018-12-08 00:21:41 +03:00
|
|
|
|
2019-02-08 11:53:07 +03:00
|
|
|
if (result.type == UrlbarUtils.RESULT_TYPE.SEARCH &&
|
|
|
|
!result.payload.isKeywordOffer) {
|
2019-02-01 04:07:33 +03:00
|
|
|
item.setAttribute("type", "search");
|
|
|
|
} else if (result.type == UrlbarUtils.RESULT_TYPE.REMOTE_TAB) {
|
|
|
|
item.setAttribute("type", "remotetab");
|
2019-02-05 16:24:39 +03:00
|
|
|
} else if (result.type == UrlbarUtils.RESULT_TYPE.TAB_SWITCH) {
|
|
|
|
item.setAttribute("type", "switchtab");
|
2019-01-29 12:29:21 +03:00
|
|
|
} else if (result.source == UrlbarUtils.RESULT_SOURCE.BOOKMARKS) {
|
2018-12-08 00:21:41 +03:00
|
|
|
item.setAttribute("type", "bookmark");
|
2019-03-28 20:08:04 +03:00
|
|
|
} else {
|
|
|
|
item.removeAttribute("type");
|
2018-09-13 19:38:07 +03:00
|
|
|
}
|
|
|
|
|
2019-03-28 20:08:04 +03:00
|
|
|
let favicon = item._elements.get("favicon");
|
2019-01-25 19:14:21 +03:00
|
|
|
if (result.type == UrlbarUtils.RESULT_TYPE.SEARCH ||
|
|
|
|
result.type == UrlbarUtils.RESULT_TYPE.KEYWORD) {
|
2019-02-15 00:41:31 +03:00
|
|
|
favicon.src = result.payload.icon || UrlbarUtils.ICON.SEARCH_GLASS;
|
2019-01-15 22:21:11 +03:00
|
|
|
} else {
|
2019-02-01 19:33:24 +03:00
|
|
|
favicon.src = result.payload.icon || UrlbarUtils.ICON.DEFAULT;
|
2019-01-15 22:21:11 +03:00
|
|
|
}
|
2018-09-13 19:38:07 +03:00
|
|
|
|
2019-05-07 19:39:04 +03:00
|
|
|
let title = item._elements.get("title");
|
2018-12-12 02:22:54 +03:00
|
|
|
this._addTextContentWithHighlights(
|
2019-05-07 19:39:04 +03:00
|
|
|
title, result.title, result.titleHighlights);
|
2019-05-09 16:06:53 +03:00
|
|
|
title._tooltip = result.title;
|
|
|
|
if (title.hasAttribute("overflow")) {
|
|
|
|
title.setAttribute("title", title._tooltip);
|
|
|
|
}
|
2018-09-13 19:38:07 +03:00
|
|
|
|
2019-03-28 20:08:04 +03:00
|
|
|
let tagsContainer = item._elements.get("tagsContainer");
|
2019-03-29 21:50:27 +03:00
|
|
|
tagsContainer.textContent = "";
|
2019-01-22 00:57:22 +03:00
|
|
|
if (result.payload.tags && result.payload.tags.length > 0) {
|
|
|
|
tagsContainer.append(...result.payload.tags.map((tag, i) => {
|
|
|
|
const element = this._createElement("span");
|
|
|
|
element.className = "urlbarView-tag";
|
|
|
|
this._addTextContentWithHighlights(
|
|
|
|
element, tag, result.payloadHighlights.tags[i]);
|
|
|
|
return element;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2019-03-28 20:08:04 +03:00
|
|
|
let action = "";
|
2019-05-07 19:39:04 +03:00
|
|
|
let isVisitAction = false;
|
2019-03-28 20:08:04 +03:00
|
|
|
let setURL = false;
|
2019-01-18 13:40:22 +03:00
|
|
|
switch (result.type) {
|
2019-01-25 19:14:21 +03:00
|
|
|
case UrlbarUtils.RESULT_TYPE.TAB_SWITCH:
|
2019-03-28 20:08:04 +03:00
|
|
|
action = bundle.GetStringFromName("switchToTab2");
|
|
|
|
setURL = true;
|
2019-01-18 13:40:22 +03:00
|
|
|
break;
|
2019-01-31 19:51:46 +03:00
|
|
|
case UrlbarUtils.RESULT_TYPE.REMOTE_TAB:
|
2019-03-28 20:08:04 +03:00
|
|
|
action = result.payload.device;
|
|
|
|
setURL = true;
|
2019-01-31 19:51:46 +03:00
|
|
|
break;
|
2019-01-25 19:14:21 +03:00
|
|
|
case UrlbarUtils.RESULT_TYPE.SEARCH:
|
2019-03-28 20:08:04 +03:00
|
|
|
action = bundle.formatStringFromName("searchWithEngine",
|
|
|
|
[result.payload.engine], 1);
|
2019-01-18 13:40:22 +03:00
|
|
|
break;
|
2019-02-11 00:44:46 +03:00
|
|
|
case UrlbarUtils.RESULT_TYPE.KEYWORD:
|
2019-05-07 19:39:04 +03:00
|
|
|
isVisitAction = result.payload.input.trim() == result.payload.keyword;
|
2019-02-11 00:44:46 +03:00
|
|
|
break;
|
2019-02-28 12:25:22 +03:00
|
|
|
case UrlbarUtils.RESULT_TYPE.OMNIBOX:
|
2019-03-28 20:08:04 +03:00
|
|
|
action = result.payload.content;
|
2019-02-28 12:25:22 +03:00
|
|
|
break;
|
2019-01-18 13:40:22 +03:00
|
|
|
default:
|
2019-02-15 23:55:30 +03:00
|
|
|
if (result.heuristic) {
|
2019-05-07 19:39:04 +03:00
|
|
|
isVisitAction = true;
|
2019-01-30 13:10:34 +03:00
|
|
|
} else {
|
2019-03-28 20:08:04 +03:00
|
|
|
setURL = true;
|
2019-01-30 13:10:34 +03:00
|
|
|
}
|
2019-01-18 13:40:22 +03:00
|
|
|
break;
|
2018-09-13 19:38:07 +03:00
|
|
|
}
|
2019-05-07 19:39:04 +03:00
|
|
|
|
2019-03-28 20:08:04 +03:00
|
|
|
let url = item._elements.get("url");
|
|
|
|
if (setURL) {
|
|
|
|
this._addTextContentWithHighlights(url, result.payload.displayUrl,
|
|
|
|
result.payloadHighlights.displayUrl || []);
|
2019-05-09 16:06:53 +03:00
|
|
|
url._tooltip = result.payload.displayUrl;
|
2019-03-28 20:08:04 +03:00
|
|
|
} else {
|
|
|
|
url.textContent = "";
|
2019-05-09 16:06:53 +03:00
|
|
|
url._tooltip = "";
|
|
|
|
}
|
|
|
|
if (url.hasAttribute("overflow")) {
|
|
|
|
url.setAttribute("title", url._tooltip);
|
2019-02-01 04:07:33 +03:00
|
|
|
}
|
2019-05-07 19:39:04 +03:00
|
|
|
|
|
|
|
if (isVisitAction) {
|
|
|
|
action = bundle.GetStringFromName("visit");
|
|
|
|
title.setAttribute("isurl", "true");
|
|
|
|
} else {
|
|
|
|
title.removeAttribute("isurl");
|
|
|
|
}
|
2019-03-28 20:08:04 +03:00
|
|
|
item._elements.get("action").textContent = action;
|
2019-05-07 19:39:04 +03:00
|
|
|
|
2019-05-02 16:00:16 +03:00
|
|
|
item._elements.get("titleSeparator").hidden = !action && !setURL;
|
2018-09-13 19:38:07 +03:00
|
|
|
}
|
2018-12-12 02:22:54 +03:00
|
|
|
|
2019-04-19 23:09:13 +03:00
|
|
|
_removeStaleRows() {
|
|
|
|
let row = this._rows.lastElementChild;
|
|
|
|
while (row) {
|
|
|
|
let next = row.previousElementSibling;
|
|
|
|
if (row.hasAttribute("stale")) {
|
|
|
|
row.remove();
|
2019-05-09 00:14:35 +03:00
|
|
|
} else {
|
|
|
|
row.style.display = "";
|
2019-04-19 23:09:13 +03:00
|
|
|
}
|
|
|
|
row = next;
|
|
|
|
}
|
|
|
|
}
|
2019-04-19 23:54:08 +03:00
|
|
|
|
2019-04-19 23:09:13 +03:00
|
|
|
_startRemoveStaleRowsTimer() {
|
|
|
|
this._removeStaleRowsTimer = this.window.setTimeout(() => {
|
|
|
|
this._removeStaleRowsTimer = null;
|
|
|
|
this._removeStaleRows();
|
2019-05-09 18:00:47 +03:00
|
|
|
}, 400);
|
2019-04-19 23:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_cancelRemoveStaleRowsTimer() {
|
|
|
|
if (this._removeStaleRowsTimer) {
|
|
|
|
this.window.clearTimeout(this._removeStaleRowsTimer);
|
|
|
|
this._removeStaleRowsTimer = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-27 13:38:52 +03:00
|
|
|
_selectItem(item, {
|
|
|
|
updateInput = true,
|
|
|
|
setAccessibleFocus = true,
|
|
|
|
} = {}) {
|
2019-02-12 17:53:22 +03:00
|
|
|
if (this._selected) {
|
|
|
|
this._selected.toggleAttribute("selected", false);
|
2019-03-27 13:38:52 +03:00
|
|
|
this._selected.removeAttribute("aria-selected");
|
2019-02-12 17:53:22 +03:00
|
|
|
}
|
2019-03-09 15:15:26 +03:00
|
|
|
if (item) {
|
|
|
|
item.toggleAttribute("selected", true);
|
2019-03-27 13:38:52 +03:00
|
|
|
item.setAttribute("aria-selected", "true");
|
2019-02-12 17:53:22 +03:00
|
|
|
}
|
2019-03-27 13:38:52 +03:00
|
|
|
this._setAccessibleFocus(setAccessibleFocus && item);
|
|
|
|
this._selected = item;
|
2019-02-12 17:53:22 +03:00
|
|
|
|
2019-03-09 15:15:26 +03:00
|
|
|
if (updateInput) {
|
2019-04-19 23:09:13 +03:00
|
|
|
this.input.setValueFromResult(item && item.result);
|
2019-02-12 17:53:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-27 13:38:52 +03:00
|
|
|
_setAccessibleFocus(item) {
|
|
|
|
if (item) {
|
|
|
|
this.input.inputField.setAttribute("aria-activedescendant", item.id);
|
|
|
|
} else {
|
|
|
|
this.input.inputField.removeAttribute("aria-activedescendant");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 02:22:54 +03:00
|
|
|
/**
|
|
|
|
* Adds text content to a node, placing substrings that should be highlighted
|
|
|
|
* inside <em> nodes.
|
|
|
|
*
|
|
|
|
* @param {Node} parentNode
|
|
|
|
* The text content will be added to this node.
|
|
|
|
* @param {string} textContent
|
|
|
|
* The text content to give the node.
|
|
|
|
* @param {array} highlights
|
|
|
|
* The matches to highlight in the text.
|
|
|
|
*/
|
|
|
|
_addTextContentWithHighlights(parentNode, textContent, highlights) {
|
2019-03-28 20:08:04 +03:00
|
|
|
parentNode.textContent = "";
|
2018-12-12 02:22:54 +03:00
|
|
|
if (!textContent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
highlights = (highlights || []).concat([[textContent.length, 0]]);
|
|
|
|
let index = 0;
|
|
|
|
for (let [highlightIndex, highlightLength] of highlights) {
|
|
|
|
if (highlightIndex - index > 0) {
|
|
|
|
parentNode.appendChild(
|
|
|
|
this.document.createTextNode(
|
|
|
|
textContent.substring(index, highlightIndex)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (highlightLength > 0) {
|
|
|
|
let strong = this._createElement("strong");
|
|
|
|
strong.textContent = textContent.substring(
|
|
|
|
highlightIndex,
|
|
|
|
highlightIndex + highlightLength
|
|
|
|
);
|
|
|
|
parentNode.appendChild(strong);
|
|
|
|
}
|
|
|
|
index = highlightIndex + highlightLength;
|
|
|
|
}
|
|
|
|
}
|
2018-10-12 19:13:42 +03:00
|
|
|
|
2019-02-17 21:12:01 +03:00
|
|
|
_enableOrDisableOneOffSearches(enable = true) {
|
|
|
|
if (enable && UrlbarPrefs.get("oneOffSearches")) {
|
2019-02-05 19:51:43 +03:00
|
|
|
this.oneOffSearchButtons.telemetryOrigin = "urlbar";
|
|
|
|
this.oneOffSearchButtons.style.display = "";
|
|
|
|
// Set .textbox first, since the popup setter will cause
|
|
|
|
// a _rebuild call that uses it.
|
|
|
|
this.oneOffSearchButtons.textbox = this.input.textbox;
|
|
|
|
this.oneOffSearchButtons.view = this;
|
2019-03-27 22:09:01 +03:00
|
|
|
} else {
|
2019-02-05 19:51:43 +03:00
|
|
|
this.oneOffSearchButtons.telemetryOrigin = null;
|
|
|
|
this.oneOffSearchButtons.style.display = "none";
|
|
|
|
this.oneOffSearchButtons.textbox = null;
|
|
|
|
this.oneOffSearchButtons.view = null;
|
2018-10-12 19:13:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 01:32:05 +03:00
|
|
|
_on_SelectedOneOffButtonChanged() {
|
2019-03-06 11:25:44 +03:00
|
|
|
if (!this.isOpen || !this._queryContext) {
|
2019-02-19 01:32:05 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update all search suggestion results to use the newly selected engine, or
|
|
|
|
// if no engine is selected, revert to their original engines.
|
|
|
|
let engine =
|
2019-03-27 22:09:01 +03:00
|
|
|
this.oneOffSearchButtons.selectedButton &&
|
|
|
|
this.oneOffSearchButtons.selectedButton.engine;
|
2019-02-19 01:32:05 +03:00
|
|
|
for (let i = 0; i < this._queryContext.results.length; i++) {
|
|
|
|
let result = this._queryContext.results[i];
|
|
|
|
if (result.type != UrlbarUtils.RESULT_TYPE.SEARCH ||
|
|
|
|
(!result.heuristic && !result.payload.suggestion)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (engine) {
|
|
|
|
if (!result.payload.originalEngine) {
|
|
|
|
result.payload.originalEngine = result.payload.engine;
|
|
|
|
}
|
|
|
|
result.payload.engine = engine.name;
|
|
|
|
} else if (result.payload.originalEngine) {
|
|
|
|
result.payload.engine = result.payload.originalEngine;
|
|
|
|
delete result.payload.originalEngine;
|
|
|
|
}
|
|
|
|
let item = this._rows.children[i];
|
|
|
|
let action = item.querySelector(".urlbarView-action");
|
|
|
|
action.textContent =
|
|
|
|
bundle.formatStringFromName("searchWithEngine",
|
|
|
|
[(engine && engine.name) || result.payload.engine], 1);
|
|
|
|
// If we just changed the engine from the original engine and it had an
|
|
|
|
// icon, then make sure the result now uses the new engine's icon or
|
|
|
|
// failing that the default icon. If we changed it back to the original
|
|
|
|
// engine, go back to the original or default icon.
|
|
|
|
let favicon = item.querySelector(".urlbarView-favicon");
|
|
|
|
if (engine && result.payload.icon) {
|
|
|
|
favicon.src =
|
|
|
|
(engine.iconURI && engine.iconURI.spec) ||
|
|
|
|
UrlbarUtils.ICON.SEARCH_GLASS;
|
|
|
|
} else if (!engine) {
|
|
|
|
favicon.src = result.payload.icon || UrlbarUtils.ICON.SEARCH_GLASS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 16:45:48 +03:00
|
|
|
_on_mousedown(event) {
|
|
|
|
if (event.button == 2) {
|
|
|
|
// Ignore right clicks.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let row = event.target;
|
|
|
|
while (!row.classList.contains("urlbarView-row")) {
|
|
|
|
row = row.parentNode;
|
|
|
|
}
|
2019-03-27 13:38:52 +03:00
|
|
|
this._selectItem(row, { updateInput: false });
|
2019-02-12 17:53:22 +03:00
|
|
|
this.controller.speculativeConnect(this._queryContext, this.selectedIndex, "mousedown");
|
2019-01-28 16:45:48 +03:00
|
|
|
}
|
|
|
|
|
2019-01-16 14:51:44 +03:00
|
|
|
_on_mouseup(event) {
|
|
|
|
if (event.button == 2) {
|
|
|
|
// Ignore right clicks.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-12 19:13:42 +03:00
|
|
|
let row = event.target;
|
|
|
|
while (!row.classList.contains("urlbarView-row")) {
|
|
|
|
row = row.parentNode;
|
|
|
|
}
|
2019-02-15 17:57:23 +03:00
|
|
|
this.input.pickResult(event, parseInt(row.getAttribute("resultIndex")));
|
2018-10-12 19:13:42 +03:00
|
|
|
}
|
2018-12-04 22:26:49 +03:00
|
|
|
|
|
|
|
_on_overflow(event) {
|
2019-05-08 18:49:33 +03:00
|
|
|
if (event.detail == 1 &&
|
|
|
|
(event.target.classList.contains("urlbarView-url") ||
|
|
|
|
event.target.classList.contains("urlbarView-title"))) {
|
2018-12-04 22:26:49 +03:00
|
|
|
event.target.toggleAttribute("overflow", true);
|
2019-05-09 16:06:53 +03:00
|
|
|
event.target.setAttribute("title", event.target._tooltip);
|
2018-12-04 22:26:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_on_underflow(event) {
|
2019-05-08 18:49:33 +03:00
|
|
|
if (event.detail == 1 &&
|
|
|
|
(event.target.classList.contains("urlbarView-url") ||
|
|
|
|
event.target.classList.contains("urlbarView-title"))) {
|
2018-12-04 22:26:49 +03:00
|
|
|
event.target.toggleAttribute("overflow", false);
|
2019-05-09 16:06:53 +03:00
|
|
|
event.target.removeAttribute("title");
|
2018-12-04 22:26:49 +03:00
|
|
|
}
|
|
|
|
}
|
2019-01-24 15:22:14 +03:00
|
|
|
|
2019-02-05 19:51:43 +03:00
|
|
|
_on_popupshowing() {
|
2019-02-10 16:07:27 +03:00
|
|
|
this.window.addEventListener("resize", this);
|
2019-02-05 19:51:43 +03:00
|
|
|
}
|
|
|
|
|
2019-03-14 16:59:14 +03:00
|
|
|
_on_popupshown() {
|
|
|
|
this.input.inputField.setAttribute("aria-expanded", "true");
|
|
|
|
}
|
|
|
|
|
2019-02-05 19:51:43 +03:00
|
|
|
_on_popuphiding() {
|
2019-01-24 15:22:14 +03:00
|
|
|
this.controller.cancelQuery();
|
2019-02-10 16:07:27 +03:00
|
|
|
this.window.removeEventListener("resize", this);
|
2019-03-27 13:38:52 +03:00
|
|
|
this.removeAccessibleFocus();
|
2019-03-14 16:59:14 +03:00
|
|
|
this.input.inputField.setAttribute("aria-expanded", "false");
|
2019-05-09 00:14:33 +03:00
|
|
|
this._rows.textContent = "";
|
2019-02-10 16:07:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
_on_resize() {
|
|
|
|
// Close the popup as it would be wrongly sized. This can
|
|
|
|
// happen when using special OS resize functions like Win+Arrow.
|
|
|
|
this.close();
|
2019-01-24 15:22:14 +03:00
|
|
|
}
|
2018-09-13 19:38:07 +03:00
|
|
|
}
|