Skip to content

Commit 4c58bc3

Browse files
committed
webview: Add a wrapper pane around the real <webview>.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 9a8680d commit 4c58bc3

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

app/renderer/css/main.css

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ body {
303303
visibility: hidden;
304304
}
305305

306-
webview,
306+
.webview-pane,
307307
.functional-view {
308308
position: absolute;
309309
width: 100%;
@@ -312,7 +312,16 @@ webview,
312312
visibility: hidden;
313313
}
314314

315-
webview.active,
315+
.webview-pane {
316+
display: flex;
317+
flex-direction: column;
318+
}
319+
320+
.webview-pane > webview {
321+
flex: 1;
322+
}
323+
324+
.webview-pane.active,
316325
.functional-view.active {
317326
z-index: 1;
318327
visibility: visible;

app/renderer/js/components/webview.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,28 @@ type WebViewProps = {
3737
export default class WebView {
3838
static templateHtml(props: WebViewProps): Html {
3939
return html`
40-
<webview
41-
data-tab-id="${props.tabIndex}"
42-
src="${props.url}"
43-
${props.preload === undefined
44-
? html``
45-
: html`preload="${props.preload}"`}
46-
partition="persist:webviewsession"
47-
allowpopups
48-
>
49-
</webview>
40+
<div class="webview-pane">
41+
<webview
42+
data-tab-id="${props.tabIndex}"
43+
src="${props.url}"
44+
${props.preload === undefined
45+
? html``
46+
: html`preload="${props.preload}"`}
47+
partition="persist:webviewsession"
48+
allowpopups
49+
>
50+
</webview>
51+
</div>
5052
`;
5153
}
5254

5355
static async create(props: WebViewProps): Promise<WebView> {
54-
const $webview = generateNodeFromHtml(
56+
const $pane = generateNodeFromHtml(
5557
WebView.templateHtml(props),
5658
) as HTMLElement;
57-
props.$root.append($webview);
59+
props.$root.append($pane);
5860

61+
const $webview: HTMLElement = $pane.querySelector(":scope > webview")!;
5962
await new Promise<void>((resolve) => {
6063
$webview.addEventListener(
6164
"did-attach",
@@ -87,7 +90,7 @@ export default class WebView {
8790
throw new TypeError("Failed to get WebContents ID");
8891
}
8992

90-
return new WebView(props, $webview, webContentsId);
93+
return new WebView(props, $pane, $webview, webContentsId);
9194
}
9295

9396
badgeCount = 0;
@@ -98,6 +101,7 @@ export default class WebView {
98101

99102
private constructor(
100103
readonly props: WebViewProps,
104+
private readonly $pane: HTMLElement,
101105
private readonly $webview: HTMLElement,
102106
readonly webContentsId: number,
103107
) {
@@ -110,7 +114,7 @@ export default class WebView {
110114
}
111115

112116
destroy(): void {
113-
this.$webview.remove();
117+
this.$pane.remove();
114118
}
115119

116120
getWebContents(): WebContents {
@@ -128,7 +132,7 @@ export default class WebView {
128132
}
129133

130134
hide(): void {
131-
this.$webview.classList.remove("active");
135+
this.$pane.classList.remove("active");
132136
}
133137

134138
load(): void {
@@ -278,7 +282,7 @@ export default class WebView {
278282
// To show or hide the loading indicator in the active tab
279283
this.$webviewsContainer.toggle("loaded", !this.loading);
280284

281-
this.$webview.classList.add("active");
285+
this.$pane.classList.add("active");
282286
this.focus();
283287
this.props.onTitleChange();
284288
// Injecting preload css in webview to override some css rules

0 commit comments

Comments
 (0)