From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- .../components/prompts/src/CommonDialog.sys.mjs | 62 +++++----------------- 1 file changed, 14 insertions(+), 48 deletions(-) (limited to 'toolkit/components/prompts/src/CommonDialog.sys.mjs') diff --git a/toolkit/components/prompts/src/CommonDialog.sys.mjs b/toolkit/components/prompts/src/CommonDialog.sys.mjs index a0812aa8ec..c788248442 100644 --- a/toolkit/components/prompts/src/CommonDialog.sys.mjs +++ b/toolkit/components/prompts/src/CommonDialog.sys.mjs @@ -30,11 +30,10 @@ CommonDialog.prototype = { initialFocusResolver: null, /** - * @param [commonDialogEl] - Dialog element from commonDialog.xhtml, - * null for TabModalPrompts. + * @param [commonDialogEl] - Dialog element from commonDialog.xhtml. */ - async onLoad(commonDialogEl = null) { - let isEmbedded = !!commonDialogEl?.ownerGlobal.docShell.chromeEventHandler; + async onLoad(commonDialogEl) { + let isEmbedded = !!commonDialogEl.ownerGlobal.docShell.chromeEventHandler; switch (this.args.promptType) { case "alert": @@ -106,36 +105,19 @@ CommonDialog.prototype = { throw new Error("unknown dialog type"); } - if (commonDialogEl) { - commonDialogEl.setAttribute( - "windowtype", - "prompt:" + this.args.promptType - ); - } + commonDialogEl.setAttribute("windowtype", "prompt:" + this.args.promptType); // set the document title let title = this.args.title; let infoTitle = this.ui.infoTitle; infoTitle.appendChild(infoTitle.ownerDocument.createTextNode(title)); - // Specific check to prevent showing the title on the old content prompts for macOS. - // This should be removed when the old content prompts are removed. - let contentSubDialogPromptEnabled = Services.prefs.getBoolPref( - "prompts.contentPromptSubDialog" - ); - let isOldContentPrompt = - !contentSubDialogPromptEnabled && - this.args.modalType == Ci.nsIPrompt.MODAL_TYPE_CONTENT; - // After making these preventative checks, we can determine to show it if we're on // macOS (where there is no titlebar) or if the prompt is a common dialog document // and has been embedded (has a chromeEventHandler). - infoTitle.hidden = - isOldContentPrompt || !(AppConstants.platform === "macosx" || isEmbedded); + infoTitle.hidden = !(AppConstants.platform === "macosx" || isEmbedded); - if (commonDialogEl) { - commonDialogEl.ownerDocument.title = title; - } + commonDialogEl.ownerDocument.title = title; // Set button labels and visibility // @@ -193,7 +175,7 @@ CommonDialog.prototype = { // set the icon let icon = this.ui.infoIcon; if (icon) { - this.iconClass.forEach((el, idx, arr) => icon.classList.add(el)); + this.iconClass.forEach(el => icon.classList.add(el)); } // set default result to cancelled @@ -202,15 +184,7 @@ CommonDialog.prototype = { // Set the default button let b = this.args.defaultButtonNum || 0; - let button = this.ui["button" + b]; - - if (commonDialogEl) { - commonDialogEl.defaultButton = ["accept", "cancel", "extra1", "extra2"][ - b - ]; - } else { - button.setAttribute("default", "true"); - } + commonDialogEl.defaultButton = ["accept", "cancel", "extra1", "extra2"][b]; if (!isEmbedded && !this.ui.promptContainer?.hidden) { // Set default focus and select textbox contents if applicable. If we're @@ -229,7 +203,7 @@ CommonDialog.prototype = { // Play a sound (unless we're showing a content prompt -- don't want those // to feel like OS prompts). try { - if (commonDialogEl && this.soundID && !this.args.openedWithTabDialog) { + if (this.soundID && !this.args.openedWithTabDialog) { Cc["@mozilla.org/sound;1"] .getService(Ci.nsISound) .playEventSound(this.soundID); @@ -238,20 +212,12 @@ CommonDialog.prototype = { console.error("Couldn't play common dialog event sound: ", e); } - if (commonDialogEl) { - if (isEmbedded) { - // If we delayed default focus above, wait for it to be ready before - // sending the notification. - await this.initialFocusPromise; - } - Services.obs.notifyObservers(this.ui.prompt, "common-dialog-loaded"); - } else { - // ui.promptContainer is the element. - Services.obs.notifyObservers( - this.ui.promptContainer, - "tabmodal-dialog-loaded" - ); + if (isEmbedded) { + // If we delayed default focus above, wait for it to be ready before + // sending the notification. + await this.initialFocusPromise; } + Services.obs.notifyObservers(this.ui.prompt, "common-dialog-loaded"); }, setLabelForNode(aNode, aLabel) { -- cgit v1.2.3