From 623e6a4fc3312e73c339fef9cf971c777c383ead Mon Sep 17 00:00:00 2001 From: PB Date: Sun, 7 Feb 2021 21:28:50 +0100 Subject: [PATCH 1/5] Make wxWebViewEdge visible after creating Fixes: #18851 --- include/wx/msw/webview_edge.h | 2 -- src/msw/webview_edge.cpp | 10 +--------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/include/wx/msw/webview_edge.h b/include/wx/msw/webview_edge.h index be7eeeac2a..b36fe61324 100644 --- a/include/wx/msw/webview_edge.h +++ b/include/wx/msw/webview_edge.h @@ -105,8 +105,6 @@ private: void OnSize(wxSizeEvent& event); - void OnShow(wxShowEvent& event); - bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const; wxDECLARE_DYNAMIC_CLASS(wxWebViewEdge); diff --git a/src/msw/webview_edge.cpp b/src/msw/webview_edge.cpp index 06b1f1126a..dc52b28ead 100644 --- a/src/msw/webview_edge.cpp +++ b/src/msw/webview_edge.cpp @@ -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,6 @@ ICoreWebView2Settings* wxWebViewEdgeImpl::GetSettings() wxWebViewEdge::~wxWebViewEdge() { - Unbind(wxEVT_SHOW, &wxWebViewEdge::OnShow, this); delete m_impl; } @@ -387,7 +387,6 @@ bool wxWebViewEdge::Create(wxWindow* parent, if (!m_impl->Create()) return false; Bind(wxEVT_SIZE, &wxWebViewEdge::OnSize, this); - Bind(wxEVT_SHOW, &wxWebViewEdge::OnShow, this); LoadURL(url); return true; @@ -399,13 +398,6 @@ void wxWebViewEdge::OnSize(wxSizeEvent& event) event.Skip(); } -void wxWebViewEdge::OnShow(wxShowEvent& event) -{ - if (m_impl->m_webView) - m_impl->m_webViewController->put_IsVisible(event.IsShown()); - event.Skip(); -} - void wxWebViewEdge::LoadURL(const wxString& url) { if (!m_impl->m_webView) From 334872e726850ebd5a96f4bd9044c9d5ed513748 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Sun, 7 Feb 2021 21:48:02 +0100 Subject: [PATCH 2/5] Notify WebView2 API when minimizing a window with wxWebView As suggested by the ICoreWebView2Controller documentation call put_isVisible() when the window containing the wxWebViewEdge is minimized/restored. --- include/wx/msw/webview_edge.h | 2 ++ src/msw/webview_edge.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/wx/msw/webview_edge.h b/include/wx/msw/webview_edge.h index b36fe61324..ffd54f2077 100644 --- a/include/wx/msw/webview_edge.h +++ b/include/wx/msw/webview_edge.h @@ -105,6 +105,8 @@ private: void OnSize(wxSizeEvent& event); + void OnTopLevelParentIconized(wxIconizeEvent& event); + bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const; wxDECLARE_DYNAMIC_CLASS(wxWebViewEdge); diff --git a/src/msw/webview_edge.cpp b/src/msw/webview_edge.cpp index dc52b28ead..fc2feae8ee 100644 --- a/src/msw/webview_edge.cpp +++ b/src/msw/webview_edge.cpp @@ -363,6 +363,9 @@ ICoreWebView2Settings* wxWebViewEdgeImpl::GetSettings() wxWebViewEdge::~wxWebViewEdge() { + wxWindow* topLevelParent = wxGetTopLevelParent(this); + if (topLevelParent) + topLevelParent->Unbind(wxEVT_ICONIZE, &wxWebViewEdge::OnTopLevelParentIconized, this); delete m_impl; } @@ -387,6 +390,9 @@ bool wxWebViewEdge::Create(wxWindow* parent, if (!m_impl->Create()) return false; Bind(wxEVT_SIZE, &wxWebViewEdge::OnSize, this); + wxWindow* topLevelParent = wxGetTopLevelParent(this); + if (topLevelParent) + topLevelParent->Bind(wxEVT_ICONIZE, &wxWebViewEdge::OnTopLevelParentIconized, this); LoadURL(url); return true; @@ -398,6 +404,13 @@ void wxWebViewEdge::OnSize(wxSizeEvent& event) event.Skip(); } +void wxWebViewEdge::OnTopLevelParentIconized(wxIconizeEvent& event) +{ + if (m_impl && m_impl->m_webViewController) + m_impl->m_webViewController->put_IsVisible(!event.IsIconized()); + event.Skip(); +} + void wxWebViewEdge::LoadURL(const wxString& url) { if (!m_impl->m_webView) From 8a9db461ff788875220b28a1bd8cede509f02e51 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Sun, 7 Feb 2021 22:14:18 +0100 Subject: [PATCH 3/5] Implement wxWebView::GetVersionInfo() for macOS Return the operating system version as the WebKit version used by WKWebView is bound to the OS. (Also works for iOS) --- include/wx/osx/webview_webkit.h | 1 + src/osx/webview_webkit.mm | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/wx/osx/webview_webkit.h b/include/wx/osx/webview_webkit.h index 1c92faac73..1b5fd57b97 100644 --- a/include/wx/osx/webview_webkit.h +++ b/include/wx/osx/webview_webkit.h @@ -122,6 +122,7 @@ public: long style = 0, const wxString& name = wxASCII_STR(wxWebViewNameStr)) { return new wxWebViewWebKit(parent, id, url, pos, size, style, name); } + virtual wxVersionInfo GetVersionInfo() wxOVERRIDE; }; #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT diff --git a/src/osx/webview_webkit.mm b/src/osx/webview_webkit.mm index 5350081e78..a788f8c4a3 100644 --- a/src/osx/webview_webkit.mm +++ b/src/osx/webview_webkit.mm @@ -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 // ---------------------------------------------------------------------------- From e0c705648f43abb04b7d5a3c1a03243e681bc2be Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Mon, 8 Feb 2021 09:18:10 +0100 Subject: [PATCH 4/5] Add missing wxOVERRIDE to wxWebViewFactoryWebKit --- include/wx/osx/webview_webkit.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/wx/osx/webview_webkit.h b/include/wx/osx/webview_webkit.h index 1b5fd57b97..6bd6da02f3 100644 --- a/include/wx/osx/webview_webkit.h +++ b/include/wx/osx/webview_webkit.h @@ -113,14 +113,14 @@ 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; }; From 1cd0904260c0ddf069455c8b660d5ed1d74b7186 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Mon, 8 Feb 2021 11:27:49 +0100 Subject: [PATCH 5/5] Fix mixed line breaks in webview sources --- include/wx/private/json.h | 4 ++-- src/msw/webview_edge.cpp | 18 +++++++++--------- src/msw/webview_ie.cpp | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/wx/private/json.h b/include/wx/private/json.h index 12d78e4a2e..8e93b7d9c8 100644 --- a/include/wx/private/json.h +++ b/include/wx/private/json.h @@ -56,8 +56,8 @@ bool DecodeString(const wxString& in, wxString* out) out->append('\\'); break; case 'u': -#if SIZEOF_WCHAR_T == 2 - // In this case, we handle surrogates without doing anything special was wchar_t strings use UTF-17 encoding. +#if SIZEOF_WCHAR_T == 2 + // In this case, we handle surrogates without doing anything special was wchar_t strings use UTF-17 encoding. if (wxIsxdigit(ch[1]) && wxIsxdigit(ch[2]) && wxIsxdigit(ch[3]) && wxIsxdigit(ch[4])) { diff --git a/src/msw/webview_edge.cpp b/src/msw/webview_edge.cpp index fc2feae8ee..bdf8ce5b76 100644 --- a/src/msw/webview_edge.cpp +++ b/src/msw/webview_edge.cpp @@ -746,15 +746,15 @@ bool wxWebViewFactoryEdge::IsAvailable() wxVersionInfo wxWebViewFactoryEdge::GetVersionInfo() { IsAvailable(); // Make sure ms_version string is initialized (if available) - long major = 0, - minor = 0, - micro = 0; - wxStringTokenizer tk(wxWebViewEdgeImpl::ms_version, ". "); - // Ignore the return value because if the version component is missing - // or invalid (i.e. non-numeric), the only thing we can do is to ignore - // it anyhow. - tk.GetNextToken().ToLong(&major); - tk.GetNextToken().ToLong(&minor); + long major = 0, + minor = 0, + micro = 0; + wxStringTokenizer tk(wxWebViewEdgeImpl::ms_version, ". "); + // Ignore the return value because if the version component is missing + // or invalid (i.e. non-numeric), the only thing we can do is to ignore + // it anyhow. + tk.GetNextToken().ToLong(&major); + tk.GetNextToken().ToLong(&minor); tk.GetNextToken().ToLong(µ); return wxVersionInfo("Microsoft Edge WebView2", major, minor, micro); diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index a008166b6a..6b0f194dc7 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -58,16 +58,16 @@ wxVersionInfo wxWebViewFactoryIE::GetVersionInfo() wxRegKey key(wxRegKey::HKLM, "Software\\Microsoft\\Internet Explorer"); wxString value; key.QueryValue("Version", value); - long major = 0, - minor = 0, - micro = 0; - wxStringTokenizer tk(value, ". "); - // Ignore the return value because if the version component is missing - // or invalid (i.e. non-numeric), the only thing we can do is to ignore - // it anyhow. - tk.GetNextToken().ToLong(&major); - tk.GetNextToken().ToLong(&minor); - tk.GetNextToken().ToLong(µ); + long major = 0, + minor = 0, + micro = 0; + wxStringTokenizer tk(value, ". "); + // Ignore the return value because if the version component is missing + // or invalid (i.e. non-numeric), the only thing we can do is to ignore + // it anyhow. + tk.GetNextToken().ToLong(&major); + tk.GetNextToken().ToLong(&minor); + tk.GetNextToken().ToLong(µ); return wxVersionInfo("Internet Explorer", major, minor, micro); }