diff --git a/include/wx/webview_chromium.h b/include/wx/webview_chromium.h index 8afb22480d..57e407d2c9 100644 --- a/include/wx/webview_chromium.h +++ b/include/wx/webview_chromium.h @@ -132,8 +132,6 @@ public: virtual void GTKHandleRealized() override; #endif - virtual void OnInternalIdle() override; - protected: virtual void DoSetPage(const wxString& html, const wxString& baseUrl) override; diff --git a/src/common/webview_chromium.cpp b/src/common/webview_chromium.cpp index ed239ff187..e8f84949f5 100644 --- a/src/common/webview_chromium.cpp +++ b/src/common/webview_chromium.cpp @@ -10,6 +10,7 @@ #include "wx/webview.h" #include "wx/webview_chromium.h" +#include "wx/eventfilter.h" #include "wx/filename.h" #include "wx/filesys.h" #include "wx/rtti.h" @@ -94,11 +95,26 @@ namespace wxCEF // AppImplData contains data shared by all wxWebViewChromium objects // ---------------------------------------------------------------------------- -struct AppImplData +struct AppImplData : wxEventFilter { // This function is called to dispatch events to the browser. void DoMessageLoopWork(); + // Call the function above before processing every event. + // + // This is a bit brutal, but DoMessageLoopWork() should return pretty + // quickly if it has nothing to do and not doing this results in weird + // bugs, e.g. clicking embedded text boxes doesn't give focus to them. + virtual int FilterEvent(wxEvent& event) override + { + // But we can at least skip doing it for the idle events, as they don't + // correspond to anything CEF is interested in. + if ( event.GetEventType() != wxEVT_IDLE ) + DoMessageLoopWork(); + + return Event_Skip; + } + #ifdef __WXGTK__ // Called from DoMessageLoopWork() if the thread context is allocated. void StartThreadDispatch(GMainContext* threadContext); @@ -931,6 +947,8 @@ bool wxWebViewChromium::InitCEF() return false; } + wxEvtHandler::AddFilter(&gs_appData); + ms_cefInitialized = true; return true; } @@ -939,6 +957,8 @@ void wxWebViewChromium::ShutdownCEF() { if (ms_cefInitialized) { + wxEvtHandler::RemoveFilter(&gs_appData); + CefShutdown(); } } @@ -965,11 +985,6 @@ void wxWebViewChromium::OnSize(wxSizeEvent& event) #endif } -void wxWebViewChromium::OnInternalIdle() -{ - gs_appData.DoMessageLoopWork(); -} - void wxWebViewChromium::SetPageSource(const wxString& pageSource) { m_pageSource = pageSource;