Skip to content

Commit fef13e6

Browse files
committed
[frontend] fix iframes eating focus for context menu clickouts
1 parent 4205b1a commit fef13e6

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

frontend/src/Menu.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import type { Component, DLElement } from "dreamland/core";
2+
import { browser } from "./main";
23

34
export const Menu: Component<{
45
x: number;
56
y: number;
67
items: { label: string; action?: () => void }[];
78
}> = function (cx) {
89
cx.mount = () => {
10+
browser.unfocusframes = true;
911
document.body.appendChild(cx.root);
1012
const { top, left, width, height } = cx.root.getBoundingClientRect();
1113
let maxX = document.documentElement.clientWidth - width;
@@ -17,6 +19,7 @@ export const Menu: Component<{
1719
"click",
1820
() => {
1921
cx.root.remove();
22+
browser.unfocusframes = false;
2023
},
2124
{ once: true }
2225
);

frontend/src/Omnibox.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import iconShield from "@ktibow/iconset-material-symbols/shield";
1010
import iconStar from "@ktibow/iconset-material-symbols/star";
1111
import iconSearch from "@ktibow/iconset-material-symbols/search";
1212
import { createMenu } from "./Menu";
13-
import { client } from "./main";
13+
import { browser, client } from "./main";
1414

1515
export const Spacer: Component = function (cx) {
1616
return <div></div>;
@@ -70,8 +70,10 @@ export const UrlInput: Component<
7070
<div
7171
on:click={(e: MouseEvent) => {
7272
this.active = true;
73+
browser.unfocusframes = true;
7374
document.body.addEventListener("click", (e) => {
7475
this.active = false;
76+
browser.unfocusframes = false;
7577
e.stopPropagation();
7678
});
7779
this.input.focus();

frontend/src/Shell.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Component } from "dreamland/core";
22
import type { Tab } from "./tabs";
3+
import { browser } from "./main";
34

45
export let pushTab: (tab: Tab) => void;
56
export let popTab: (tab: Tab) => void;
@@ -28,12 +29,15 @@ export const Shell: Component<{
2829
}
2930
};
3031

31-
return <div></div>;
32+
return <div class:unfocus={use(browser.unfocusframes)}></div>;
3233
};
3334
Shell.css = `
3435
:scope {
3536
flex: 1;
3637
}
38+
.unfocus {
39+
pointer-events: none;
40+
}
3741
.container {
3842
width: 100%;
3943
height: 100%;

frontend/src/browser.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IconButton, Omnibox } from "./Omnibox";
55
import { scramjet } from "./main";
66
import iconAdd from "@ktibow/iconset-material-symbols/add";
77
import { popTab, pushTab, Shell } from "./Shell";
8+
import { createMenu } from "./Menu";
89

910
// let a = createState({
1011
// b: createState({
@@ -29,6 +30,8 @@ export class Browser extends StatefulClass {
2930
tabs: Tab[] = [];
3031
activetab: Tab;
3132

33+
unfocusframes: boolean = false;
34+
3235
constructor(state: Stateful<any>) {
3336
super(state);
3437

@@ -68,6 +71,14 @@ export class Browser extends StatefulClass {
6871
});
6972
frame.addEventListener("contextInit", (e) => {
7073
const framedoc = frame.frame.contentDocument!;
74+
75+
framedoc.addEventListener("contextmenu", (e) => {
76+
createMenu(e.x, e.y, [
77+
{
78+
label: "??",
79+
},
80+
]);
81+
});
7182
const head = framedoc.querySelector("head")!;
7283
const observer = new MutationObserver(() => {
7384
const title = framedoc.querySelector("title");

frontend/src/main.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,12 @@ export const scramjet = new ScramjetController({
3434
scramjet.init();
3535
navigator.serviceWorker.register("./sw.js");
3636

37-
let browser = createBrowser();
37+
export let browser = createBrowser();
3838
(self as any).browser = browser;
3939

4040
try {
4141
let built = browser.build();
4242
built.id = "app";
43-
built.addEventListener("contextmenu", (e) => {
44-
createMenu(e.x, e.y, [
45-
{
46-
label: "Reload",
47-
},
48-
]);
49-
e.preventDefault();
50-
});
5143

5244
app.replaceWith(built);
5345
} catch (e) {

0 commit comments

Comments
 (0)