/* 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";
// Wrap in a block to prevent leaking to window scope.
{
ChromeUtils.defineESModuleGetters(this, {
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
SearchOneOffs: "resource:///modules/SearchOneOffs.sys.mjs",
});
/** * A richlistbox popup custom element for for a browser search autocomplete * widget.
*/ class MozSearchAutocompleteRichlistboxPopup extends MozElements.MozAutocompleteRichlistboxPopup {
constructor() { super();
this.addEventListener("popupshowing", () => { // First handle deciding if we are showing the reduced version of the // popup containing only the preferences button. We do this if the // glass icon has been clicked if the text field is empty. if (this.searchbar.hasAttribute("showonlysettings")) { this.searchbar.removeAttribute("showonlysettings"); this.setAttribute("showonlysettings", "true");
// Setting this with an xbl-inherited attribute gets overridden the // second time the user clicks the glass icon for some reason... this.richlistbox.collapsed = true;
} else { this.removeAttribute("showonlysettings"); // Uncollapse as long as we have a view which has >= 1 row. // The autocomplete binding itself will take care of uncollapsing later, // if we currently have no rows but end up having some in the future // when the search string changes this.richlistbox.collapsed = this.matchCount == 0;
}
// Show the current default engine in the top header of the panel. this.updateHeader().catch(console.error);
this._oneOffButtons.addEventListener( "SelectedOneOffButtonChanged", this
);
});
this.addEventListener("popuphiding", () => { this._oneOffButtons.removeEventListener( "SelectedOneOffButtonChanged", this
);
});
/** * This handles clicks on the topmost "Foo Search" header in the * popup (hbox.search-panel-header]).
*/ this.addEventListener("click", event => { if (event.button == 2) { // Ignore right clicks. return;
}
let button = event.originalTarget;
let engine = button.parentNode.engine; if (!engine) { return;
} if (this.searchbar.value) { this.oneOffButtons.handleSearchCommand(event, engine);
} elseif (event.shiftKey) { this.openSearchForm(event, engine);
}
});
// We override this because even though we have a shadow root, we want our // inheritance to be done on the light tree.
getElementForAttrInheritance(selector) { returnthis.querySelector(selector);
}
// Check for unmodified left-click, and use default behavior if (
aEvent.button == 0 &&
!aEvent.shiftKey &&
!aEvent.ctrlKey &&
!aEvent.altKey &&
!aEvent.metaKey
) { this.input.controller.handleEnter(true, aEvent); return;
}
// Check for middle-click or modified clicks on the search bar
BrowserSearchTelemetry.recordSearchSuggestionSelectionMethod(
aEvent, "searchbar", this.selectedIndex
);
// Handle search bar popup clicks
let search = this.input.controller.getValueAt(this.selectedIndex);
// open the search results according to the clicking subtlety
let where = BrowserUtils.whereToOpenLink(aEvent, false, true);
let params = {};
// But open ctrl/cmd clicks on autocomplete items in a new background tab.
let modifier =
AppConstants.platform == "macosx" ? aEvent.metaKey : aEvent.ctrlKey; if (
where == "tab" &&
MouseEvent.isInstance(aEvent) &&
(aEvent.button == 1 || modifier)
) {
params.inBackground = true;
}
// leave the popup open for background tab loads if (!(where == "tab" && params.inBackground)) { // close the autocomplete popup and revert the entered search term this.closePopup(); this.input.controller.handleEscape();
}
let uri = await engine.getIconURL(); if (uri) { this.setAttribute("src", uri);
} else { // If the default has just been changed to a provider without icon, // avoid showing the icon of the previous default provider. this.removeAttribute("src");
}
/** * This is called when a one-off is clicked and when "search in new tab" * is selected from a one-off context menu.
*/ /* eslint-disable-next-line valid-jsdoc */
handleOneOffSearch(event, engine, where, params) { this.searchbar.handleSearchCommandWhere(event, engine, where, params);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.