Skip to content

Commit a25b80c

Browse files
committed
Update CHOC-based win32 webview
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 12694ee commit a25b80c

File tree

7 files changed

+886
-586
lines changed

7 files changed

+886
-586
lines changed

distrho/extra/WebViewImpl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,31 +411,31 @@ WebViewHandle webViewCreate(const char* const url,
411411
const WebViewOptions& options)
412412
{
413413
#if WEB_VIEW_USING_CHOC
414-
WebView* const webview = webview_choc_create(options);
414+
WebView* const webview = webview_choc_create(url, options);
415415
if (webview == nullptr)
416416
return nullptr;
417417

418418
const HWND hwnd = static_cast<HWND>(webview_choc_handle(webview));
419+
ShowWindow(hwnd, SW_HIDE);
419420

420421
LONG_PTR flags = GetWindowLongPtr(hwnd, -16);
421422
flags = (flags & ~WS_POPUP) | WS_CHILD;
422423
SetWindowLongPtr(hwnd, -16, flags);
423424

424425
SetParent(hwnd, reinterpret_cast<HWND>(windowId));
425-
SetWindowPos(hwnd, nullptr,
426+
SetWindowPos(hwnd,
427+
nullptr,
426428
options.offset.x,
427429
options.offset.y,
428-
initialWidth - options.offset.x,
429-
initialHeight - options.offset.y,
430+
initialWidth + options.offset.x,
431+
initialHeight + options.offset.y,
430432
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
431433
ShowWindow(hwnd, SW_SHOW);
432434

433435
WebViewData* const whandle = new WebViewData;
434436
whandle->webview = webview;
435437
whandle->url = url;
436438

437-
webview_choc_navigate(webview, url);
438-
439439
return whandle;
440440
#elif WEB_VIEW_USING_MACOS_WEBKIT
441441
NSView* const view = reinterpret_cast<NSView*>(windowId);
@@ -835,7 +835,7 @@ void webViewResize(const WebViewHandle handle, const uint width, const uint heig
835835
{
836836
#if WEB_VIEW_USING_CHOC
837837
const HWND hwnd = static_cast<HWND>(webview_choc_handle(handle->webview));
838-
SetWindowPos(hwnd, nullptr, 0, 0, width, height, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
838+
SetWindowPos(hwnd, nullptr, 0, 0, width, height, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);
839839
#elif WEB_VIEW_USING_MACOS_WEBKIT
840840
[handle->webview setFrameSize:NSMakeSize(width / scaleFactor, height / scaleFactor)];
841841
#elif WEB_VIEW_USING_X11_IPC

distrho/extra/WebViewWin32.hpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* DISTRHO Plugin Framework (DPF)
3-
* Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
3+
* Copyright (C) 2012-2026 Filipe Coelho <falktx@falktx.com>
44
*
55
* Permission to use, copy, modify, and/or distribute this software for any purpose with
66
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -35,7 +35,7 @@ using DISTRHO_NAMESPACE::WebView;
3535
START_NAMESPACE_DISTRHO
3636
#endif
3737

38-
WebView* webview_choc_create(const WEB_VIEW_NAMESPACE::WebViewOptions& opts);
38+
WebView* webview_choc_create(const char* url, const WEB_VIEW_NAMESPACE::WebViewOptions& opts);
3939
void webview_choc_destroy(WebView*);
4040
void* webview_choc_handle(WebView*);
4141
void webview_choc_eval(WebView*, const char* js);
@@ -60,34 +60,33 @@ START_NAMESPACE_DGL
6060
START_NAMESPACE_DISTRHO
6161
#endif
6262

63-
WebView* webview_choc_create(const WEB_VIEW_NAMESPACE::WebViewOptions& opts)
63+
WebView* webview_choc_create(const char* const url, const WEB_VIEW_NAMESPACE::WebViewOptions& opts)
6464
{
6565
WebView::Options wopts;
66-
wopts.acceptsFirstMouseClick = true;
6766
wopts.enableDebugMode = true;
67+
wopts.transparentBackground = true;
68+
wopts.webviewIsReady = [url, opts](WebView& webview){
69+
if (const WEB_VIEW_NAMESPACE::WebViewMessageCallback callback = opts.callback)
70+
{
71+
webview.addInitScript("function postMessage(m){window.chrome.webview.postMessage(m);}");
72+
webview.bind([opts](std::string& value) {
73+
opts.callback(opts.callbackPtr, value.data());
74+
});
75+
}
76+
else
77+
{
78+
webview.addInitScript("function postMessage(m){}");
79+
}
80+
81+
if (opts.initialJS != nullptr)
82+
webview.addInitScript(opts.initialJS);
83+
84+
webview.navigate(url);
85+
};
6886

6987
std::unique_ptr<WebView> webview = std::make_unique<WebView>(wopts);
7088
DISTRHO_SAFE_ASSERT_RETURN(webview->loadedOK(), nullptr);
7189

72-
if (const WEB_VIEW_NAMESPACE::WebViewMessageCallback callback = opts.callback)
73-
{
74-
webview->addInitScript("function postMessage(m){window.chrome.webview.postMessage(m);}");
75-
76-
void* const callbackPtr = opts.callbackPtr;
77-
webview->bind([callback, callbackPtr](const std::string& value) {
78-
char* const data = strdup(value.data());
79-
callback(callbackPtr, data);
80-
std::free(data);
81-
});
82-
}
83-
else
84-
{
85-
webview->addInitScript("function postMessage(m){}");
86-
}
87-
88-
if (opts.initialJS != nullptr)
89-
webview->addInitScript(opts.initialJS);
90-
9190
return webview.release();
9291
}
9392

distrho/extra/choc/README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Taken from https://github.com/Tracktion/choc
22

33
```
4-
commit 2512542b2d65f3e92df7f2f1f7eeb712fa41a0de (HEAD -> main, origin/main, origin/HEAD)
5-
Author: Cesare Ferrari <cesare.ferrari@gmail.com>
6-
Date: Sun Apr 28 12:53:17 2024 +0100
4+
commit ae4c54d22b53a599222c1dfaa4b4007d0ec310c7 (HEAD -> main, origin/main, origin/HEAD)
5+
Author: Julian Storer <julianstorer@gmail.com>
6+
Date: Thu Jan 15 08:56:50 2026 +0000
77
8-
Disable additional gcc warnin
8+
Added a zip file creation class, ZipWriter
99
```
1010

1111
With the big [choc.patch](./choc.patch) patch applied to top for:
@@ -16,7 +16,3 @@ With the big [choc.patch](./choc.patch) patch applied to top for:
1616
- remove even more stuff (json no longer needed)
1717
- convert choc asserts into distrho ones
1818
- put everything inside distrho namespace
19-
20-
And then backported:
21-
22-
- https://github.com/Tracktion/choc/commit/792e4bd9bedf38b9a28f12be0535c90649d5616b

0 commit comments

Comments
 (0)