diff --git a/src/zen/common/sys/ZenActorsManager.sys.mjs b/src/zen/common/sys/ZenActorsManager.sys.mjs index 766193ad35..7f5c1a8125 100644 --- a/src/zen/common/sys/ZenActorsManager.sys.mjs +++ b/src/zen/common/sys/ZenActorsManager.sys.mjs @@ -57,6 +57,22 @@ let JSWINDOWACTORS = { remoteTypes: ["web", "file"], enablePreference: "zen.glance.enabled", }, + ZenSplitView: { + parent: { + esModuleURI: "resource:///actors/ZenSplitViewParent.sys.mjs", + }, + child: { + esModuleURI: "resource:///actors/ZenSplitViewChild.sys.mjs", + events: { + DOMContentLoaded: {}, + click: { + capture: true, + }, + }, + }, + allFrames: true, + remoteTypes: ["web", "file"], + }, }; if (!Services.appinfo.inSafeMode) { diff --git a/src/zen/moz.build b/src/zen/moz.build index e1efea2056..eabacf5a8e 100644 --- a/src/zen/moz.build +++ b/src/zen/moz.build @@ -19,4 +19,5 @@ DIRS += [ "sessionstore", "share", "spaces", + "split-view", ] diff --git a/src/zen/split-view/ZenViewSplitter.mjs b/src/zen/split-view/ZenViewSplitter.mjs index 783f2646df..174c1e4709 100644 --- a/src/zen/split-view/ZenViewSplitter.mjs +++ b/src/zen/split-view/ZenViewSplitter.mjs @@ -1228,6 +1228,15 @@ class nsZenViewSplitter extends nsZenDOMOperatedFeature { window.gContextMenu.mediaURL || window.gContextMenu.contentData.docLocation || window.gContextMenu.target.ownerDocument.location.href; + this.splitLinkFromURL(url); + } + + /** + * Opens a URL in a new tab and splits it with the current tab. + * + * @param {string} url - The URL to open in split view. + */ + splitLinkFromURL(url) { const currentTab = gZenGlanceManager.getTabOrGlanceParent( window.gBrowser.selectedTab ); diff --git a/src/zen/split-view/actors/ZenSplitViewChild.sys.mjs b/src/zen/split-view/actors/ZenSplitViewChild.sys.mjs new file mode 100644 index 0000000000..03c93b27a3 --- /dev/null +++ b/src/zen/split-view/actors/ZenSplitViewChild.sys.mjs @@ -0,0 +1,39 @@ +// 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/. + +export class ZenSplitViewChild extends JSWindowActorChild { + #glanceActivationMethod; + + async handleEvent(event) { + const handler = this[`on_${event.type}`]; + if (typeof handler === "function") { + await handler.call(this, event); + } + } + + async on_DOMContentLoaded() { + this.#glanceActivationMethod = await this.sendQuery( + "ZenSplitView:GetGlanceActivationMethod" + ); + } + + on_click(event) { + if (event.button !== 0 || event.defaultPrevented) { + return; + } + if (!event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) { + return; + } + if (this.#glanceActivationMethod === "shift") { + return; + } + const anchor = event.target.closest("a[href]"); + if (!anchor) { + return; + } + event.preventDefault(); + event.stopPropagation(); + this.sendAsyncMessage("ZenSplitView:OpenInSplit", { url: anchor.href }); + } +} diff --git a/src/zen/split-view/actors/ZenSplitViewParent.sys.mjs b/src/zen/split-view/actors/ZenSplitViewParent.sys.mjs new file mode 100644 index 0000000000..a194fbd4ac --- /dev/null +++ b/src/zen/split-view/actors/ZenSplitViewParent.sys.mjs @@ -0,0 +1,23 @@ +// 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/. + +export class ZenSplitViewParent extends JSWindowActorParent { + async receiveMessage(message) { + switch (message.name) { + case "ZenSplitView:GetGlanceActivationMethod": + return Services.prefs.getStringPref( + "zen.glance.activation-method", + "ctrl" + ); + case "ZenSplitView:OpenInSplit": + this.browsingContext.topChromeWindow.gZenViewSplitter?.splitLinkFromURL( + message.data.url + ); + return null; + default: + console.warn(`[split-view]: Unknown message: ${message.name}`); + return null; + } + } +} diff --git a/src/zen/split-view/moz.build b/src/zen/split-view/moz.build new file mode 100644 index 0000000000..4e2e19750f --- /dev/null +++ b/src/zen/split-view/moz.build @@ -0,0 +1,9 @@ +# +# 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/. + +FINAL_TARGET_FILES.actors += [ + "actors/ZenSplitViewChild.sys.mjs", + "actors/ZenSplitViewParent.sys.mjs", +]