@@ -43,7 +43,7 @@ public: | |||||
/** | /** | ||||
Constructor for a WebViewWidget. | Constructor for a WebViewWidget. | ||||
*/ | */ | ||||
explicit WebViewWidget(Window& windowToMapTo); | |||||
explicit WebViewWidget(Window& windowToMapTo, bool initLater = false); | |||||
/** | /** | ||||
Destructor. | Destructor. | ||||
@@ -55,11 +55,13 @@ public: | |||||
void reload(); | void reload(); | ||||
protected: | protected: | ||||
void init(const char* initialJS); | |||||
virtual void onMessage(char* message); | virtual void onMessage(char* message); | ||||
void onResize(const ResizeEvent& ev) override; | void onResize(const ResizeEvent& ev) override; | ||||
private: | private: | ||||
const DISTRHO_NAMESPACE::WebViewHandle webview; | |||||
DISTRHO_NAMESPACE::WebViewHandle webview; | |||||
void idleCallback() override; | void idleCallback() override; | ||||
void onDisplay() override {} | void onDisplay() override {} | ||||
@@ -26,15 +26,15 @@ | |||||
START_NAMESPACE_DGL | START_NAMESPACE_DGL | ||||
// ----------------------------------------------------------------------- | |||||
// -------------------------------------------------------------------------------------------------------------------- | |||||
WebViewWidget::WebViewWidget(Window& windowToMapTo) | |||||
WebViewWidget::WebViewWidget(Window& windowToMapTo, bool initLater) | |||||
: TopLevelWidget(windowToMapTo), | : TopLevelWidget(windowToMapTo), | ||||
webview(webViewCreate(windowToMapTo.getNativeWindowHandle(), | |||||
windowToMapTo.getWidth(), | |||||
windowToMapTo.getHeight(), | |||||
windowToMapTo.getScaleFactor(), | |||||
WebViewOptions(_on_msg, this))) | |||||
webview(initLater ? nullptr : webViewCreate(windowToMapTo.getNativeWindowHandle(), | |||||
windowToMapTo.getWidth(), | |||||
windowToMapTo.getHeight(), | |||||
windowToMapTo.getScaleFactor(), | |||||
WebViewOptions(_on_msg, this))) | |||||
{ | { | ||||
#if !(defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS)) | #if !(defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS)) | ||||
if (webview != nullptr) | if (webview != nullptr) | ||||
@@ -53,6 +53,24 @@ WebViewWidget::~WebViewWidget() | |||||
} | } | ||||
} | } | ||||
void WebViewWidget::init(const char* const initialJS) | |||||
{ | |||||
DISTRHO_SAFE_ASSERT_RETURN(webview == nullptr,); | |||||
WebViewOptions options(_on_msg, this); | |||||
options.initialJS = initialJS; | |||||
webview = webViewCreate(getWindow().getNativeWindowHandle(), getWidth(), getHeight(), getScaleFactor(), options); | |||||
// FIXME implement initialJS | |||||
if (webview != nullptr) | |||||
webViewEvaluateJS(webview, initialJS); | |||||
#if !(defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS)) | |||||
if (webview != nullptr) | |||||
addIdleCallback(this, 1000 / 60); | |||||
#endif | |||||
} | |||||
void WebViewWidget::evaluateJS(const char* const js) | void WebViewWidget::evaluateJS(const char* const js) | ||||
{ | { | ||||
if (webview != nullptr) | if (webview != nullptr) | ||||
@@ -87,7 +105,7 @@ void WebViewWidget::idleCallback() | |||||
webViewIdle(webview); | webViewIdle(webview); | ||||
} | } | ||||
// ----------------------------------------------------------------------- | |||||
// -------------------------------------------------------------------------------------------------------------------- | |||||
static void notImplemented(const char* const name) | static void notImplemented(const char* const name) | ||||
{ | { | ||||
@@ -45,6 +45,11 @@ struct WebViewOptions { | |||||
PositionOffset() : x(0), y(0) {} | PositionOffset() : x(0), y(0) {} | ||||
} offset; | } offset; | ||||
/** | |||||
Set some JavaScript to evalute on every new page load. | |||||
*/ | |||||
const char* initialJS; | |||||
/** | /** | ||||
Message callback triggered from JavaScript code inside the WebView. | Message callback triggered from JavaScript code inside the WebView. | ||||
*/ | */ | ||||
@@ -54,12 +59,14 @@ struct WebViewOptions { | |||||
/** Constructor for default values */ | /** Constructor for default values */ | ||||
WebViewOptions() | WebViewOptions() | ||||
: offset(), | : offset(), | ||||
initialJS(nullptr), | |||||
callback(nullptr), | callback(nullptr), | ||||
callbackPtr(nullptr) {} | callbackPtr(nullptr) {} | ||||
/** Constructor providing a callback */ | /** Constructor providing a callback */ | ||||
WebViewOptions(const WebViewMessageCallback cb, void* const ptr) | WebViewOptions(const WebViewMessageCallback cb, void* const ptr) | ||||
: offset(), | : offset(), | ||||
initialJS(nullptr), | |||||
callback(cb), | callback(cb), | ||||
callbackPtr(ptr) {} | callbackPtr(ptr) {} | ||||
}; | }; | ||||
@@ -246,7 +246,11 @@ UI::UI(const uint width, const uint height, const bool automaticallyScaleAndSetA | |||||
#else | #else | ||||
false | false | ||||
#endif | #endif | ||||
)), | |||||
) | |||||
#if DISTRHO_UI_WEB_VIEW | |||||
, true | |||||
#endif | |||||
), | |||||
uiData(UI::PrivateData::s_nextPrivateData) | uiData(UI::PrivateData::s_nextPrivateData) | ||||
{ | { | ||||
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | #if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | ||||
@@ -269,7 +273,7 @@ UI::UI(const uint width, const uint height, const bool automaticallyScaleAndSetA | |||||
#endif | #endif | ||||
#if DISTRHO_UI_WEB_VIEW | #if DISTRHO_UI_WEB_VIEW | ||||
evaluateJS( | |||||
init( | |||||
"editParameter=function(index,started){window.webkit.messageHandlers.external.postMessage('editparam '+index+' '+(started ? 1 : 0))};" | "editParameter=function(index,started){window.webkit.messageHandlers.external.postMessage('editparam '+index+' '+(started ? 1 : 0))};" | ||||
"setParameterValue=function(index,value){window.webkit.messageHandlers.external.postMessage('setparam '+index+' '+value)};" | "setParameterValue=function(index,value){window.webkit.messageHandlers.external.postMessage('setparam '+index+' '+value)};" | ||||
#if DISTRHO_PLUGIN_WANT_STATE | #if DISTRHO_PLUGIN_WANT_STATE | ||||