Files
lbmk/config/firefox/default/patches/0036-ui-patches-add-translate-page-context-menu.patch.patch
T
Leah Rowe 2b34aeea5d WIP: convert to lwmk
Signed-off-by: Leah Rowe <leah@libreboot.org>
2026-09-08 06:44:40 +01:00

97 lines
3.6 KiB
Diff

From 484614c225f0e13d9713ee5f85d579938b4dfe96 Mon Sep 17 00:00:00 2001
From: LibreWolf Developers <noreply@librewolf.net>
Date: Sun, 6 Sep 2026 10:11:36 +0100
Subject: [PATCH 36/52] ui-patches/add-translate-page-context-menu.patch
---
.../base/content/browser-context.inc.xhtml | 2 +
browser/base/content/browser-context.js | 3 ++
browser/base/content/nsContextMenu.sys.mjs | 37 +++++++++++++++++++
3 files changed, 42 insertions(+)
diff --git a/browser/base/content/browser-context.inc.xhtml b/browser/base/content/browser-context.inc.xhtml
index 621be24e4e0c..b5ec280b761f 100644
--- a/browser/base/content/browser-context.inc.xhtml
+++ b/browser/base/content/browser-context.inc.xhtml
@@ -369,6 +369,8 @@
<menuitem id="context-searchselect-private"/>
<menuitem id="context-translate-selection"
data-l10n-id="main-context-menu-translate-selection"/>
+ <menuitem id="context-translate-page"
+ data-l10n-id="main-context-menu-translate-page"/>
<menu id="context-ask-chat"/>
<menuseparator id="frame-sep"/>
diff --git a/browser/base/content/browser-context.js b/browser/base/content/browser-context.js
index 042341cecb1a..a59e92ab302d 100644
--- a/browser/base/content/browser-context.js
+++ b/browser/base/content/browser-context.js
@@ -212,6 +212,9 @@ document.addEventListener(
case "context-translate-selection":
gContextMenu.openSelectTranslationsPanel(event);
break;
+ case "context-translate-page":
+ gContextMenu.openFullPageTranslationsPanel(event);
+ break;
case "context-showonlythisframe":
gContextMenu.showOnlyThisFrame();
break;
diff --git a/browser/base/content/nsContextMenu.sys.mjs b/browser/base/content/nsContextMenu.sys.mjs
index 305a6b1eb41d..d1a9aba3cc94 100644
--- a/browser/base/content/nsContextMenu.sys.mjs
+++ b/browser/base/content/nsContextMenu.sys.mjs
@@ -906,6 +906,7 @@ export class nsContextMenu {
this.showAndFormatSearchContextItem();
this.showTranslateSelectionItem();
+ this.showTranslatePageItem();
lazy.GenAI.buildAskChatMenu(document.getElementById("context-ask-chat"), {
browser: this.browser,
selectionInfo: this.selectionInfo,
@@ -2608,6 +2609,42 @@ export class nsContextMenu {
this.window.openTrustedLinkIn(drmInfoURL, dest);
}
+ /**
+ * Opens the FullPageTranslationsPanel singleton instance.
+ *
+ * @param {Event} event - The triggering event for opening the panel.
+ */
+ openFullPageTranslationsPanel(event) {
+ this.window.FullPageTranslationsPanel.open(event);
+ }
+
+ /**
+ * Displays or hides the translate-page item in the context menu.
+ */
+ showTranslatePageItem() {
+ const translatePageItem = this.document.getElementById(
+ "context-translate-page"
+ );
+ const translationsEnabled = lazy.TranslationsParent.AIFeature.isEnabled;
+ const isAboutPage = this.browser?.currentURI?.schemeIs?.("about");
+
+ translatePageItem.hidden =
+ // Only show the item if the feature is enabled.
+ !translationsEnabled ||
+ // Only show the item if Translations is supported on this hardware.
+ !lazy.TranslationsParent.getIsTranslationsEngineSupported() ||
+ // Do not show page translation on internal about: pages.
+ isAboutPage ||
+ // Do not show page translation for page contexts where it does not make sense.
+ this.onTextInput ||
+ this.isContentSelected ||
+ this.onLink ||
+ this.onImage ||
+ this.onCanvas ||
+ this.onVideo ||
+ this.onAudio;
+ }
+
/**
* Opens the SelectTranslationsPanel singleton instance.
*
--
2.47.3