More wxWebView miscellaneous improvements.

See https://github.com/wxWidgets/wxWidgets/pull/2221
This commit is contained in:
Vadim Zeitlin
2021-02-08 13:50:25 +01:00
6 changed files with 46 additions and 29 deletions

View File

@@ -105,7 +105,7 @@ private:
void OnSize(wxSizeEvent& event);
void OnShow(wxShowEvent& event);
void OnTopLevelParentIconized(wxIconizeEvent& event);
bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const;

View File

@@ -113,15 +113,16 @@ private:
class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory
{
public:
virtual wxWebView* Create() { return new wxWebViewWebKit; }
virtual wxWebView* Create() wxOVERRIDE { return new wxWebViewWebKit; }
virtual wxWebView* Create(wxWindow* parent,
wxWindowID id,
const wxString& url = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxASCII_STR(wxWebViewNameStr))
const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE
{ return new wxWebViewWebKit(parent, id, url, pos, size, style, name); }
virtual wxVersionInfo GetVersionInfo() wxOVERRIDE;
};
#endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT

View File

@@ -296,6 +296,7 @@ HRESULT wxWebViewEdgeImpl::OnWebViewCreated(HRESULT result, ICoreWebView2Control
m_initialized = true;
UpdateBounds();
m_webViewController->put_IsVisible(true);
// Connect and handle the various WebView events
m_webView->add_NavigationStarting(
@@ -362,7 +363,9 @@ ICoreWebView2Settings* wxWebViewEdgeImpl::GetSettings()
wxWebViewEdge::~wxWebViewEdge()
{
Unbind(wxEVT_SHOW, &wxWebViewEdge::OnShow, this);
wxWindow* topLevelParent = wxGetTopLevelParent(this);
if (topLevelParent)
topLevelParent->Unbind(wxEVT_ICONIZE, &wxWebViewEdge::OnTopLevelParentIconized, this);
delete m_impl;
}
@@ -387,7 +390,9 @@ bool wxWebViewEdge::Create(wxWindow* parent,
if (!m_impl->Create())
return false;
Bind(wxEVT_SIZE, &wxWebViewEdge::OnSize, this);
Bind(wxEVT_SHOW, &wxWebViewEdge::OnShow, this);
wxWindow* topLevelParent = wxGetTopLevelParent(this);
if (topLevelParent)
topLevelParent->Bind(wxEVT_ICONIZE, &wxWebViewEdge::OnTopLevelParentIconized, this);
LoadURL(url);
return true;
@@ -399,10 +404,10 @@ void wxWebViewEdge::OnSize(wxSizeEvent& event)
event.Skip();
}
void wxWebViewEdge::OnShow(wxShowEvent& event)
void wxWebViewEdge::OnTopLevelParentIconized(wxIconizeEvent& event)
{
if (m_impl->m_webView)
m_impl->m_webViewController->put_IsVisible(event.IsShown());
if (m_impl && m_impl->m_webViewController)
m_impl->m_webViewController->put_IsVisible(!event.IsIconized());
event.Skip();
}

View File

@@ -87,6 +87,17 @@ wxEND_EVENT_TABLE()
@end
#endif // macOS 10.13+
//-----------------------------------------------------------------------------
// wxWebViewFactoryWebKit
//-----------------------------------------------------------------------------
wxVersionInfo wxWebViewFactoryWebKit::GetVersionInfo()
{
int verMaj, verMin, verMicro;
wxGetOsVersion(&verMaj, &verMin, &verMicro);
return wxVersionInfo("WKWebView", verMaj, verMin, verMicro);
}
// ----------------------------------------------------------------------------
// creation/destruction
// ----------------------------------------------------------------------------