1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

WebBrowserComponent: Enable click-through behaviour for WkWebView, add option to disable it

The default is enabled to behave similarly to NSViewComponentPeer. The
behaviour for the old Apple WebView is unchanged.
This commit is contained in:
attila 2024-06-03 18:41:19 +02:00
parent 4d2986ea59
commit 0d8b05e8ee
2 changed files with 32 additions and 3 deletions

View file

@ -229,10 +229,24 @@ public:
return withMember (*this, &AppleWkWebView::allowAccessToEnclosingDirectory, x);
}
/** If this options is specified, the underlying WebView will return NO from its
acceptsFirstMouse method.
This disables the click-through behaviour, meaning that clicking a previously
unfocused application window only makes the window focused, but will not pass on the
click to whichever control inside the WebView is under the mouse.
*/
[[nodiscard]] AppleWkWebView withDisabledAcceptsFirstMouse() const
{
return withMember (*this, &AppleWkWebView::acceptsFirstMouse, false);
}
auto getAllowAccessToEnclosingDirectory() const { return allowAccessToEnclosingDirectory; }
auto getAcceptsFirstMouse() const { return acceptsFirstMouse; }
private:
bool allowAccessToEnclosingDirectory = false;
bool acceptsFirstMouse = true;
};
/** Specifies options that apply to the Windows implementation when the WebView2 feature is

View file

@ -202,7 +202,7 @@ struct WebViewKeyEquivalentResponder final : public ObjCClass<WebViewClass>
{
using Base = ObjCClass<WebViewClass>;
WebViewKeyEquivalentResponder()
explicit WebViewKeyEquivalentResponder (bool acceptsFirstMouse)
: Base ("WebViewKeyEquivalentResponder_")
{
this->template addIvar<LastFocusChange*> (lastFocusChangeMemberName);
@ -283,6 +283,9 @@ struct WebViewKeyEquivalentResponder final : public ObjCClass<WebViewClass>
return result;
});
if (acceptsFirstMouse)
this->addMethod (@selector (acceptsFirstMouse:), [] (id, SEL, NSEvent*) { return YES; });
this->registerClass();
}
};
@ -680,7 +683,7 @@ class WebBrowserComponent::Impl::Platform::WebViewImpl : public WebBrowserCompo
public:
WebViewImpl (WebBrowserComponent::Impl& implIn, const String& userAgent) : browser (implIn.owner)
{
static WebViewKeyEquivalentResponder<WebView> webviewClass;
static WebViewKeyEquivalentResponder<WebView> webviewClass { false };
webView.reset ([webviewClass.createInstance() initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
frameName: nsEmptyString()
@ -863,7 +866,19 @@ public:
#endif
#if JUCE_MAC
static WebViewKeyEquivalentResponder<WKWebView> webviewClass;
auto& webviewClass = [&]() -> auto&
{
if (browserOptions.getAppleWkWebViewOptions().getAcceptsFirstMouse())
{
static WebViewKeyEquivalentResponder<WKWebView> juceWebviewClass { true };
return juceWebviewClass;
}
else
{
static WebViewKeyEquivalentResponder<WKWebView> juceWebviewClass { false };
return juceWebviewClass;
}
}();
webView.reset ([webviewClass.createInstance() initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
configuration: config.get()]);