diff --git a/browser/base/content/usbDevicePicker.css b/browser/base/content/usbDevicePicker.css new file mode 100644 index 0000000000..80b1a01b57 --- /dev/null +++ b/browser/base/content/usbDevicePicker.css @@ -0,0 +1,29 @@ +/* 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/. */ + +#usb-device-picker { + min-width: 360px; + min-height: 220px; +} + +#picker { + padding: 16px; +} + +#message { + margin: 0 0 10px; +} + +#devices { + min-height: 100px; + margin: 0 0 12px; +} + +#buttons { + margin-inline-start: 8px; +} + +#buttons > button + button { + margin-inline-start: 8px; +} diff --git a/browser/base/content/usbDevicePicker.js b/browser/base/content/usbDevicePicker.js new file mode 100644 index 0000000000..a1be97175f --- /dev/null +++ b/browser/base/content/usbDevicePicker.js @@ -0,0 +1,50 @@ +/* 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 USBDevicePicker = { + args: null, + + init() { + this.args = window.arguments[0]; + document.title = this.args.title; + document.getElementById("message").value = this.args.message; + document.getElementById("select").label = this.args.selectLabel; + document.getElementById("cancel").label = this.args.cancelLabel; + + let list = document.getElementById("devices"); + for (let choice of this.args.choices) { + list.appendItem(choice, choice); + } + list.selectedIndex = 0; + list.focus(); + }, + + select() { + let list = document.getElementById("devices"); + this.args.prompt.select(list.selectedIndex); + }, + + cancel() { + this.args.prompt.cancel(); + }, + + destroy() { + if (this.args && !this.args.prompt.completed) { + // The window manager can close this window directly. Detach it first + // so cancel() does not try to close an already-unloading window. + this.args.prompt.window = null; + this.args.prompt.cancel(); + } + this.args = null; + }, +}; + +window.addEventListener("keydown", event => { + if (event.key == "Escape") { + USBDevicePicker.cancel(); + } else if (event.key == "Enter") { + USBDevicePicker.select(); + } +}); diff --git a/browser/base/content/usbDevicePicker.xul b/browser/base/content/usbDevicePicker.xul new file mode 100644 index 0000000000..6175a3f627 --- /dev/null +++ b/browser/base/content/usbDevicePicker.xul @@ -0,0 +1,22 @@ + + + + + +