summaryrefslogtreecommitdiffstats
path: root/browser/base/content/nsContextMenu.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
commitdef92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch)
tree2ef34b9ad8bb9a9220e05d60352558b15f513894 /browser/base/content/nsContextMenu.js
parentAdding debian version 125.0.3-1. (diff)
downloadfirefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz
firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/base/content/nsContextMenu.js')
-rw-r--r--browser/base/content/nsContextMenu.js58
1 files changed, 30 insertions, 28 deletions
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);
},
};
@@ -2494,23 +2494,6 @@ class nsContextMenu {
}
/**
- * 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.
*
* @returns {boolean}
@@ -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
+ );
}
/**
@@ -2583,6 +2577,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.
*/
showTranslateSelectionItem() {
@@ -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.