mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 11:26:09 +00:00
0de6e5d4aa
This custom element replaces XBL <content> usage by directly prepend the two needed child nodes when the element is connected. This is doable because - There isn't any direct access of child nodes under <menulist>. Everyone seems to access via .menupopup, which is usually the only child. - We don't need to move the children under <menulist>. If we need to and if the child is a <xbl:children> (which could happen if <menulist> is inside an XBL <content> that just get cloned to the document), the layout will get very confused and crash (see finding in bug 1514926) Differential Revision: https://phabricator.services.mozilla.com/D16149 --HG-- rename : toolkit/content/widgets/menulist.xml => toolkit/content/widgets/menulist.js extra : moz-landing-system : lando
33 lines
966 B
JavaScript
33 lines
966 B
JavaScript
/* - 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 = ["SelectionChangedMenulist"];
|
|
|
|
class SelectionChangedMenulist {
|
|
// A menulist wrapper that will open the popup when navigating with the
|
|
// keyboard on Windows and trigger the provided handler when the popup
|
|
// is hiding. This matches the behaviour of MacOS and Linux more closely.
|
|
|
|
constructor(menulist, onCommand) {
|
|
let popup = menulist.menupopup;
|
|
let lastEvent;
|
|
|
|
menulist.addEventListener("command", event => {
|
|
lastEvent = event;
|
|
if (popup.state != "open" && popup.state != "showing") {
|
|
popup.openPopup();
|
|
}
|
|
});
|
|
|
|
popup.addEventListener("popuphiding", () => {
|
|
if (lastEvent) {
|
|
onCommand(lastEvent);
|
|
lastEvent = null;
|
|
}
|
|
});
|
|
}
|
|
}
|