/* 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"; // This is loaded into all XUL windows. Wrap in a block to prevent // leaking to window scope. { const { Services } = ChromeUtils.import( "resource://gre/modules/Services.jsm" ); const { AppConstants } = ChromeUtils.import( "resource://gre/modules/AppConstants.jsm" ); class MozDialog extends MozXULElement { constructor() { super(); this.attachShadow({ mode: "open" }); document.addEventListener( "keypress", event => { if (event.keyCode == KeyEvent.DOM_VK_RETURN) { this._hitEnter(event); } else if ( event.keyCode == KeyEvent.DOM_VK_ESCAPE && !event.defaultPrevented ) { this.cancelDialog(); } }, { mozSystemGroup: true } ); if (AppConstants.platform == "macosx") { document.addEventListener( "keypress", event => { if (event.key == "." && event.metaKey) { this.cancelDialog(); } }, true ); } else { this.addEventListener("focus", this, true); this.shadowRoot.addEventListener("focus", this, true); } // listen for when window is closed via native close buttons window.addEventListener("close", event => { if (!this.cancelDialog()) { event.preventDefault(); } }); // for things that we need to initialize after onload fires window.addEventListener("load", event => this.postLoadInit(event)); } static get observedAttributes() { return super.observedAttributes.concat("subdialog"); } attributeChangedCallback(name, oldValue, newValue) { if (name == "subdialog") { console.assert( newValue, `Turning off subdialog style is not supported` ); if (this.isConnectedAndReady && !oldValue && newValue) { this.shadowRoot.appendChild( MozXULElement.parseXULToFragment(this.inContentStyle) ); } return; } super.attributeChangedCallback(name, oldValue, newValue); } static get inheritedAttributes() { return { ".dialog-button-box": "pack=buttonpack,align=buttonalign,dir=buttondir,orient=buttonorient", "[dlgtype='accept']": "disabled=buttondisabledaccept", }; } get inContentStyle() { return ` `; } get _markup() { let buttons = AppConstants.XP_UNIX ? `