Dusk Audio Framework
Loading...
Searching...
No Matches
WebViewImpl.hpp
1/*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with
6 * or without fee is hereby granted, provided that the above copyright notice and this
7 * permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#if !defined(DAF_WEB_VIEW_HPP_INCLUDED) && !defined(DGL_WEB_VIEW_HPP_INCLUDED)
18# error bad include
19#endif
20
21#if !defined(DGL_USE_WEB_VIEW) && defined(DAF_UI_WEB_VIEW) && DAF_UI_WEB_VIEW == 0
22# error To use WebViews in DAF plugins please set DAF_UI_WEB_VIEW to 1
23#endif
24
25// --------------------------------------------------------------------------------------------------------------------
26// Web View stuff
27
28struct WebViewData;
29typedef WebViewData* WebViewHandle;
30typedef void (*WebViewMessageCallback)(void* arg, char* msg);
31
32// --------------------------------------------------------------------------------------------------------------------
33
34/**
35 Web view options, for customizing web view details.
36*/
38 /**
39 Position offset, for cases of mixing regular widgets with web views.
40 */
42 /** Horizontal offset, with scale factor pre-applied */
43 int x;
44
45 /** Vertical offset, with scale factor pre-applied */
46 int y;
47
48 /** Constructor for default values */
49 PositionOffset() : x(0), y(0) {}
50 } offset;
51
52 /**
53 Set some JavaScript to evaluate on every new page load.
54 */
55 const char* initialJS;
56
57 /**
58 Message callback triggered from JavaScript code inside the WebView.
59 */
60 WebViewMessageCallback callback;
61 void* callbackPtr;
62
63 /** Constructor for default values */
65 : offset(),
66 initialJS(nullptr),
67 callback(nullptr),
68 callbackPtr(nullptr) {}
69
70 /** Constructor providing a callback */
71 WebViewOptions(const WebViewMessageCallback cb, void* const ptr)
72 : offset(),
73 initialJS(nullptr),
74 callback(cb),
75 callbackPtr(ptr) {}
76};
77
78// --------------------------------------------------------------------------------------------------------------------
79
80/**
81 Create a new web view.
82
83 The web view will be added on top of an existing platform-specific view/window.
84 This means it will draw on top of whatever is below it,
85 something to take into consideration if mixing regular widgets with web views.
86
87 Provided metrics must have scale factor pre-applied.
88
89 @p url: The URL to open, assumed to be in encoded form (e.g spaces converted to %20)
90 @p windowId: The native window id to attach this view to (X11 Window, HWND or NSView*)
91 @p scaleFactor: Scale factor in use
92 @p options: Extra options, optional
93*/
94WebViewHandle webViewCreate(const char* url,
95 uintptr_t windowId,
96 uint initialWidth,
97 uint initialHeight,
98 double scaleFactor,
99 const WebViewOptions& options = WebViewOptions());
100
101/**
102 Destroy the web view, handle must not be used afterwards.
103*/
104void webViewDestroy(WebViewHandle webview);
105
106/**
107 Idle the web view, to be called on regular intervals.
108 Can cause callbacks to trigger.
109*/
110void webViewIdle(WebViewHandle webview);
111
112/**
113 Evaluate/run JavaScript on the web view.
114*/
115void webViewEvaluateJS(WebViewHandle webview, const char* js);
116
117/**
118 Reload the web view current page.
119*/
120void webViewReload(WebViewHandle webview);
121
122/**
123 Resize the web view.
124*/
125void webViewResize(WebViewHandle webview, uint width, uint height, double scaleFactor);
126
127// --------------------------------------------------------------------------------------------------------------------
128
129/**
130 Helper class for usage in std::shared_ptr and std::unique_ptr.
131*/
133 void operator()(WebViewHandle handle) { webViewDestroy(handle); }
134};
135
136// --------------------------------------------------------------------------------------------------------------------
Definition WebViewImpl.cpp:415
Definition WebViewImpl.hpp:132
int x
Definition WebViewImpl.hpp:43
int y
Definition WebViewImpl.hpp:46
PositionOffset()
Definition WebViewImpl.hpp:49
Definition WebViewImpl.hpp:37
WebViewOptions(const WebViewMessageCallback cb, void *const ptr)
Definition WebViewImpl.hpp:71
WebViewMessageCallback callback
Definition WebViewImpl.hpp:60
WebViewOptions()
Definition WebViewImpl.hpp:64
const char * initialJS
Definition WebViewImpl.hpp:55