Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / browser / modules / SelectionChangedMenulist.sys.mjs
blobfd794004ede29198d855c1cc7090eb2758f85226
1 /* - This Source Code Form is subject to the terms of the Mozilla Public
2    - License, v. 2.0. If a copy of the MPL was not distributed with this file,
3    - You can obtain one at http://mozilla.org/MPL/2.0/. */
5 export class SelectionChangedMenulist {
6   // A menulist wrapper that will open the popup when navigating with the
7   // keyboard on Windows and trigger the provided handler when the popup
8   // is hiding. This matches the behaviour of MacOS and Linux more closely.
10   constructor(menulist, onCommand) {
11     let popup = menulist.menupopup;
12     let lastEvent;
14     menulist.addEventListener("command", event => {
15       lastEvent = event;
16       if (popup.state != "open" && popup.state != "showing") {
17         popup.openPopup();
18       }
19     });
21     popup.addEventListener("popuphiding", () => {
22       if (lastEvent) {
23         onCommand(lastEvent);
24         lastEvent = null;
25       }
26     });
27   }