Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/zen/common/sys/ZenActorsManager.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/zen/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ DIRS += [
"sessionstore",
"share",
"spaces",
"split-view",
]
9 changes: 9 additions & 0 deletions src/zen/split-view/ZenViewSplitter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
39 changes: 39 additions & 0 deletions src/zen/split-view/actors/ZenSplitViewChild.sys.mjs
Original file line number Diff line number Diff line change
@@ -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 });
}
}
23 changes: 23 additions & 0 deletions src/zen/split-view/actors/ZenSplitViewParent.sys.mjs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
9 changes: 9 additions & 0 deletions src/zen/split-view/moz.build
Original file line number Diff line number Diff line change
@@ -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",
]