From 3a0bb1b18cade7ca146c44c15fb58987f3bb2a06 Mon Sep 17 00:00:00 2001 From: PB Date: Sat, 24 Jul 2021 20:36:03 +0200 Subject: [PATCH] Fix setting focus to wxWebViewEdge It was impossible to give focus to the actual web view in wxWebViewEdge by keyboard navigation or programmatically with wxWebViewEdge::SetFocus(). Fix it by calling CoreWebView2Controller::MoveFocus() in the wxWebViewEdge's wxEVT_SET_FOCUS handler. Closes https://github.com/wxWidgets/wxWidgets/pull/2444 --- include/wx/msw/webview_edge.h | 2 ++ src/msw/webview_edge.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/include/wx/msw/webview_edge.h b/include/wx/msw/webview_edge.h index c273697a29..fa33d16755 100644 --- a/include/wx/msw/webview_edge.h +++ b/include/wx/msw/webview_edge.h @@ -109,6 +109,8 @@ private: void OnSize(wxSizeEvent& event); + void OnSetFocus(wxFocusEvent& event); + void OnTopLevelParentIconized(wxIconizeEvent& event); bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const; diff --git a/src/msw/webview_edge.cpp b/src/msw/webview_edge.cpp index 3abb6382eb..73d27e16aa 100644 --- a/src/msw/webview_edge.cpp +++ b/src/msw/webview_edge.cpp @@ -535,6 +535,7 @@ bool wxWebViewEdge::Create(wxWindow* parent, if (!m_impl->Create()) return false; Bind(wxEVT_SIZE, &wxWebViewEdge::OnSize, this); + Bind(wxEVT_SET_FOCUS, &wxWebViewEdge::OnSetFocus, this); wxWindow* topLevelParent = wxGetTopLevelParent(this); if (topLevelParent) topLevelParent->Bind(wxEVT_ICONIZE, &wxWebViewEdge::OnTopLevelParentIconized, this); @@ -549,6 +550,13 @@ void wxWebViewEdge::OnSize(wxSizeEvent& event) event.Skip(); } +void wxWebViewEdge::OnSetFocus(wxFocusEvent& event) +{ + if (m_impl && m_impl->m_webViewController) + m_impl->m_webViewController->MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC); + event.Skip(); +} + void wxWebViewEdge::OnTopLevelParentIconized(wxIconizeEvent& event) { if (m_impl && m_impl->m_webViewController)