From def92d1b8e9d373e2f6f27c366d578d97d8960c6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:34:50 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- browser/base/content/nsContextMenu.js | 58 ++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'browser/base/content/nsContextMenu.js') diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js index 031a32dddf..9769552dce 100644 --- a/browser/base/content/nsContextMenu.js +++ b/browser/base/content/nsContextMenu.js @@ -1619,7 +1619,7 @@ class nsContextMenu { // Open new "view source" window with the frame's URL. viewFrameSource() { - BrowserViewSourceOfDocument({ + BrowserCommands.viewSourceOfDocument({ browser: this.browser, URL: this.contentData.docLocation, outerWindowID: this.frameOuterWindowID, @@ -1627,7 +1627,7 @@ class nsContextMenu { } viewInfo() { - BrowserPageInfo( + BrowserCommands.pageInfo( this.contentData.docLocation, null, null, @@ -1637,7 +1637,7 @@ class nsContextMenu { } viewImageInfo() { - BrowserPageInfo( + BrowserCommands.pageInfo( this.contentData.docLocation, "mediaTab", this.imageInfo, @@ -1661,7 +1661,7 @@ class nsContextMenu { } viewFrameInfo() { - BrowserPageInfo( + BrowserCommands.pageInfo( this.contentData.docLocation, null, null, @@ -1982,7 +1982,7 @@ class nsContextMenu { // we give up waiting for the filename. function timerCallback() {} timerCallback.prototype = { - notify: function sLA_timer_notify(aTimer) { + notify: function sLA_timer_notify() { channel.cancel(NS_ERROR_SAVE_LINK_AS_TIMEOUT); }, }; @@ -2493,23 +2493,6 @@ class nsContextMenu { openTrustedLinkIn(drmInfoURL, dest); } - /** - * Retrieves an instance of the TranslationsParent actor. - * @returns {TranslationsParent} - The TranslationsParent actor. - * @throws Throws if an instance of the actor cannot be retrieved. - */ - static #getTranslationsActor() { - const actor = - gBrowser.selectedBrowser.browsingContext.currentWindowGlobal.getActor( - "Translations" - ); - - if (!actor) { - throw new Error("Unable to get the TranslationsParent"); - } - return actor; - } - /** * Determines if Full Page Translations is currently active on this page. * @@ -2518,7 +2501,9 @@ class nsContextMenu { static #isFullPageTranslationsActive() { try { const { requestedTranslationPair } = - this.#getTranslationsActor().languageState; + TranslationsParent.getTranslationsActor( + gBrowser.selectedBrowser + ).languageState; return requestedTranslationPair !== null; } catch { // Failed to retrieve the Full Page Translations actor, do nothing. @@ -2532,7 +2517,16 @@ class nsContextMenu { * @param {Event} event - The triggering event for opening the panel. */ openSelectTranslationsPanel(event) { - SelectTranslationsPanel.open(event, this.#translationsLangPairPromise); + const context = this.contentData.context; + let screenX = context.screenXDevPx / window.devicePixelRatio; + let screenY = context.screenYDevPx / window.devicePixelRatio; + SelectTranslationsPanel.open( + event, + screenX, + screenY, + this.#getTextToTranslate(), + this.#translationsLangPairPromise + ); } /** @@ -2582,6 +2576,17 @@ class nsContextMenu { ); } + /** + * Fetches text for translation, prioritizing selected text over link text. + * + * @returns {string} The text to translate. + */ + #getTextToTranslate() { + return this.isTextSelected + ? this.selectionInfo.fullText.trim() + : this.linkTextStr.trim(); + } + /** * Displays or hides the translate-selection item in the context menu. */ @@ -2596,10 +2601,7 @@ class nsContextMenu { "browser.translations.select.enable" ); - // Selected text takes precedence over link text. - const textToTranslate = this.isTextSelected - ? this.selectedText.trim() - : this.linkTextStr.trim(); + const textToTranslate = this.#getTextToTranslate(); translateSelectionItem.hidden = // Only show the item if the feature is enabled. -- cgit v1.2.3