Call CefDoMessageLoopWork() even more aggressively

Calling this function from OnInternalIdle() is not always enough, so
call it before processing each and every event to ensure that CEF can
really do whatever it needs to be doing internally.

This doesn't seem to noticeably slow down the program and solves weird
problems, like embedded text boxes (e.g. search zones on the web sites)
not getting focus on click.
This commit is contained in:
Vadim Zeitlin 2023-12-22 02:20:49 +01:00
parent ed128bbe15
commit 4f1a249b76
2 changed files with 21 additions and 8 deletions

View file

@ -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;

View file

@ -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;