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
This commit is contained in:
PB 2021-07-24 20:36:03 +02:00 committed by Vadim Zeitlin
parent d50a707b0f
commit 3a0bb1b18c
2 changed files with 10 additions and 0 deletions

View File

@ -109,6 +109,8 @@ private:
void OnSize(wxSizeEvent& event); void OnSize(wxSizeEvent& event);
void OnSetFocus(wxFocusEvent& event);
void OnTopLevelParentIconized(wxIconizeEvent& event); void OnTopLevelParentIconized(wxIconizeEvent& event);
bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const; bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const;

View File

@ -535,6 +535,7 @@ bool wxWebViewEdge::Create(wxWindow* parent,
if (!m_impl->Create()) if (!m_impl->Create())
return false; return false;
Bind(wxEVT_SIZE, &wxWebViewEdge::OnSize, this); Bind(wxEVT_SIZE, &wxWebViewEdge::OnSize, this);
Bind(wxEVT_SET_FOCUS, &wxWebViewEdge::OnSetFocus, this);
wxWindow* topLevelParent = wxGetTopLevelParent(this); wxWindow* topLevelParent = wxGetTopLevelParent(this);
if (topLevelParent) if (topLevelParent)
topLevelParent->Bind(wxEVT_ICONIZE, &wxWebViewEdge::OnTopLevelParentIconized, this); topLevelParent->Bind(wxEVT_ICONIZE, &wxWebViewEdge::OnTopLevelParentIconized, this);
@ -549,6 +550,13 @@ void wxWebViewEdge::OnSize(wxSizeEvent& event)
event.Skip(); 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) void wxWebViewEdge::OnTopLevelParentIconized(wxIconizeEvent& event)
{ {
if (m_impl && m_impl->m_webViewController) if (m_impl && m_impl->m_webViewController)