Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Gnome/testsuite/svg/parser/   (Gnome Linux Desktop Version 4.23.2©)  Datei vom 30.5.2026 mit Größe 232 B image not shown  

Bilddatei

AutoCompleteChild.sys.mjs


products/Sources/formale Sprachen/C/Firefox/toolkit/actors/AutoCompleteChild.sys.mjs

/* 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/. */ /* eslint no-unused-vars: ["error", {args: "none"}] */ const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { ContentDOMReference: "resource://gre/modules/ContentDOMReference.sys.mjs", LoginHelper: "resource://gre/modules/LoginHelper.sys.mjs", }); const gFormFillController = Cc[ "@mozilla.org/satchel/form-fill-controller;1" ].getService(Ci.nsIFormFillController); export class AutoCompleteChild extends JSWindowActorChild { constructor() { super(); this._input = null; this._popupOpen = false; } receiveMessage(message) { switch (message.name) { case "AutoComplete:HandleEnter": { this.selectedIndex = message.data.selectedIndex; let controller = Cc[ "@mozilla.org/autocomplete/controller;1" ].getService(Ci.nsIAutoCompleteController); controller.handleEnter(message.data.isPopupSelection); break; } case "AutoComplete:PopupClosed": { this._popupOpen = false; break; } case "AutoComplete:PopupOpened": { this._popupOpen = true; break; } case "AutoComplete:Focus": { // XXX See bug 1582722 // Before bug 1573836, the messages here didn't match // ("AutoComplete:Focus" versus "AutoComplete:RequestFocus") // so this was never called. However this._input is actually a // nsIAutoCompleteInput, which doesn't have a focus() method, so it // wouldn't have worked anyway. So for now, I have just disabled this. /* if (this._input) { this._input.focus(); } */ break; } } } get input() { return this._input; } set selectedIndex(index) { this.sendAsyncMessage("AutoComplete:SetSelectedIndex", { index }); } get selectedIndex() { // selectedIndex getter must be synchronous because we need the // correct value when the controller is in controller::HandleEnter. // We can't easily just let the parent inform us the new value every // time it changes because not every action that can change the // selectedIndex is trivial to catch (e.g. moving the mouse over the // list). let selectedIndexResult = Services.cpmm.sendSyncMessage( "AutoComplete:GetSelectedIndex", { browsingContext: this.browsingContext, } ); if ( selectedIndexResult.length != 1 || !Number.isInteger(selectedIndexResult[0]) ) { throw new Error("Invalid autocomplete selectedIndex"); } return selectedIndexResult[0]; } get popupOpen() { return this._popupOpen; } openAutocompletePopup(input, element) { if (this._popupOpen || !input || !element?.isConnected) { return; } let window = element.documentGlobal; let rect = window.windowUtils.getElementBoundingScreenRect(element); let dir = window.getComputedStyle(element).direction; let results = this.getResultsFromController(input); let formOrigin = lazy.LoginHelper.getLoginOrigin( element.ownerDocument.documentURI ); let inputElementIdentifier = lazy.ContentDOMReference.get(element); // If the input element isn't focused, we select the first item by default // for accessibility reason. let selectedIndex = Services.focus.focusedElement == element ? -1 : 0; this.sendAsyncMessage("AutoComplete:MaybeOpenPopup", { results, rect, dir, inputElementIdentifier, formOrigin, selectedIndex, }); this._input = input; } closePopup() { // We set this here instead of just waiting for the // PopupClosed message to do it so that we don't end // up in a state where the content thinks that a popup // is open when it isn't (or soon won't be). this._popupOpen = false; this.sendAsyncMessage("AutoComplete:ClosePopup", {}); } invalidate() { if (this._popupOpen) { let results = this.getResultsFromController(this._input); this.sendAsyncMessage("AutoComplete:Invalidate", { results }); } } selectBy(reverse, page) { Services.cpmm.sendSyncMessage("AutoComplete:SelectBy", { browsingContext: this.browsingContext, reverse, page, }); } getResultsFromController(inputField) { let results = []; if (!inputField) { return results; } let controller = inputField.controller; if (!(controller instanceof Ci.nsIAutoCompleteController)) { return results; } for (let i = 0; i < controller.matchCount; ++i) { let result = {}; result.value = controller.getValueAt(i); result.label = controller.getLabelAt(i); result.comment = controller.getCommentAt(i); result.style = controller.getStyleAt(i); result.image = controller.getImageAt(i); results.push(result); } return results; } getNoRollupOnEmptySearch(input) { const providers = this.providersByInput(input); return Array.from(providers).find(p => p.actorName == "LoginManager"); } // Store the input to interested autocomplete providers mapping #providersByInput = new WeakMap(); // This functions returns the interested providers that have called // `markAsAutoCompletableField` for the given input and also the hard-coded // autocomplete providers based on input type. providersByInput(input) { const providers = new Set(this.#providersByInput.get(input)); if (input.hasBeenTypePassword) { providers.add( input.documentGlobal.windowGlobalChild.getActor("LoginManager") ); } else { // The current design is that FormHistory doesn't call `markAsAutoCompletable` // for every eligilbe input. Instead, when FormFillController receives a focus event, // it would control the