Use variables defined in our .props files instead of hard-coded values
and use DPI aware manifest instead of using "compatibility" one with
which the sample didn't work correctly in high DPI.
Use "wxCEF" prefix for this class to avoid any conflicts by using
non-wx-prefixed name.
Also replace wxWebViewChromiumImplData with wxCEF::ImplData as this is
shorter and more consistent with ClientHandler.
Finally stop using anonymous namespace for wxBrowserProcessHandler and
wxCefApp, as we can now put them into the same wxCEF namespace.
Ensure that CefLifeSpanHandler::OnBeforeClose() is called before
returning from wxWebViewChromium dtor, as otherwise we may try to shut
down CEF before the browser object is destroyed.
Under MSW it's enough to destroy the window ourselves to make this
happen, but under GTK/X11 we need to manually pump the messages, as
OnBeforeClose() is only called when the X event notifying about the
actual window destruction arrives.
Also make the code cleaner by using flags in wxWebViewChromiumImplData
instead of reusing m_clientHandler pointer to indicate that DoClose()
was called.
Restart the timer if it's already running but its expiration time is
beyond the specified delay, otherwise we could be waiting for too long.
This commit is best viewed ignoring whitespace-only changes.
Make browser creation actually work by postponing it until the host
window is realized and so has a valid X11 Window.
Remove unnecessary code manually creating GTK widget and just use the
standard wxGTK wxWindow instead.
Add code for setting the visual compatible with CEF to avoid X11 errors,
see https://github.com/chromiumembedded/cef/issues/3564, with many
thanks to Jiří Janoušek for finding and solving this problem originally.
Adjust the sample to handle wxWebView::Create() failure (not very
gracefully, but still better than just crashing) and to avoid using it
until it is fully created.
Update documentation to mention GTK limitations.
At least when using wxGTK Chromium helper process can't be executed once
GTK is initialized because doing this creates background threads and
Chromium code aborts if there are any threads running.
As we don't want to initialize CEF unconditionally before initializing
GTK in all applications (even those not using CEF), the only solution is
to detect if we need to run a Chromium helper process ourselves before
GTK initialization, i.e. before wxApp creation, which means that it
can't be done via the existing wxModule mechanism because modules are
initialized after creating the global application instance.
So add a way to hijack wxWidgets initialization entirely if some special
command line option (such as Chromium "--type=xxx") is specified and use
it in wxWebViewChromium to call CefExecuteProcess() before initializing
GTK or even wxWidgets itself -- as it won't be needed in a CEF helper
process anyhow.
Fixes hiding a wxGLCanvas on Wayland, either directly (`->Show(false)`)
or indirectly (e.g. when it is contained in a wxNotebook).
On Wayland, unlike on X11, to show the canvas on the screen, we need to
create a Wayland subsurface. This subsurface is detached from the GTK
widget associated to the canvas, thus it is not automatically mapped or
unmapped when the associated GTK widget is.
Rather, we need to manually keep it in sync with the widget's state.
Knowing what has to be done to map and unmap the canvas, while dealing
with edge cases properly, is not easy to someone not used to Wayland.
When the canvas is mapped, we have this graph of resources:
EGL Surface (m_surface)
|
|
v
wl_egl window (m_wlEGLWindow)
|
|
v
Canvas wl_surface GDK's toplevel window wl_surface
(m_wlSurface) (gdk_wayland_window_get_wl_surface(w))
\ which is shown to the user
\ ^
\ /
\ /
v /
Subsurface (m_wlSubsurface) to overlay
the canvas onto the toplevel window
A simple way would be to destroy everything (m_surface, m_wlEGLWindow,
m_wlSurface, m_wlSubsurface) on unmap, and re-create it again on map.
Inefficiencies aside, this mostly works. However, it can mess with the
current OpenGL context. For example, suppose we have a (fragile)
program that places a canvas inside one of wxNotebook's tabs, and makes
the OpenGL context current only once at startup (e.g. on wxEVT_SHOW).
Switching between tabs will destroy and re-create the EGL Surface, so
the canvas will not be properly rendered when going back to its tab.
So we need to be smarter, and find some way to hide the subsurface
instead. The obvious way would be to unmap the canvas wl_surface
(m_wlSurface), as according to the Wayland spec., "a sub-surface is
hidden [...] if a NULL wl_buffer is applied [to the canvas surface]."
(https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_subsurface)
However, as far as I can tell, this can't be done. There's no API to
hide an wl_egl window, and directly applying a NULL wl_buffer to the
canvas surface initially hides it, but seems to breaks the associated
window so that it crashes when one attempts to show it again.
So what remains, is destroying the overlay subsurface (m_wlSubsurface).
When doing it, to the spec, "the wl_surface is unmapped immediately.".
And not only does this work, but it also deals with the annoying fact
that on current GTK3 versions, when the GDK's toplevel window is
unmapped, its wl_surface is not just unmapped, but entirely destroyed.
(Side note: This may not have been intended, and has been changed for
GTK4, see: 5d3cec5441)
So we'd have to re-create the subsurface because of this anyway.
So, this works nicely, and as far as I can tell (documentation is a bit
scarce), there's no problem to leaving m_wlSurface (and its associated
m_wlEGLWindow and m_surface) unmapped in this way.
Fixes#22580.
Closes#23835.
Make the wxString(std::string_view) constructor explicit.
Otherwise, when comparing a std::string_view with a const char *, the
cast to wxString will be considered as a candidate for the comparison,
ultimately causing an "ambiguous overload for 'operator=='" error.
For example, this sample only builds if the constructor is explicit:
#include <wx/string.h>
#include <string_view>
int main() {
std::string_view view = "abc";
const char *str = "abc";
return view == str;
}
However, making the constructor explicit will break assignment:
std::string_view view = "abc";
wxString s;
s = view; // Error: no match for "operator="
That we can fix by implementing operator=(std::string_view)
That, however, introduces another ambiguity:
std::string str = "abc";
wxString s;
s = str; // Ambiguous between s = wxString(str)
and s = std::string_view(str)
That we can fix by implementing operator=(std::string)
Finally, note that some rather obscure ambiguities remain, such as:
wxString s;
s = {"abc", 2}; // Ambiguous between s = wxString("abc", 2)
and s = std::string_view("abc", 2)
Avoiding them is not simple (https://cplusplus.github.io/LWG/issue2946)
and doesn't add much value.
Closes#23834.
When using MSVC, wxScrolledCanvas could be instantiated multiple times
when including wx/scrolwin.h directly and when including wx/grid.h,
which declares a class deriving from wxScrolledCanvas, later.
Fix this by defining a dummy class deriving from wxScrolledCanvas in the
same header, as this is enough to convince MSVC to generate the
definition of wxScrolledCanvas itself in the DLL instead of doing it
inline.
Closes#23774.
Closes#23803.
This has the advantage of returning libraries in their load order, which
is more useful than the unspecified order that was used before.
It also means that this function now has a chance of working under other
systems such as FreeBSD, which also provides dl_iterate_phdr().
We never really used the "original" version of the command line, i.e.
before it was (possibly) modified by gtk_init_check(), so don't bother
keeping it and just free the pointers corresponding to the arguments
consumed by GTK in wxGTK code.
There should be no real changes, this is just a simplification.
This is a bit ugly because we need to have some __WINDOWS__ checks in
common code, but less uglier than before, e.g. it allows us to get rid
of wxEntryCleanupReal redefinition hack.
Otherwise our callbacks might not be called in time and some objects
could still exist when CefShutdown() was called on program exit,
resulting in assertion failures in debug CEF builds.
Override OnScheduleMessagePumpWork() to schedule work to be done on the
main thread instead of relying on only doing this in wxEVT_IDLE handler.
Still keep the latter, however, as without it the window doesn't refresh
correctly -- which might indicate some other problem somewhere.
This also allows to remove an ugly loop calling CefDoMessageLoopWork()
10 times before shutting down CEF and, most importantly, avoids a fatal
assert with "Object reference incorrectly held at CefShutdown" error on
exit in debug builds.
Log calls to some callbacks using "cef" trace mask.
To make these messages actually visible in the sample, use a log target
showing only debug messages and pass messages through to it from
wxLogWindow.
No real changes, just pass the associated wxWebView object to the ctor
instead of using a separate function for this, this is shorter and makes
it more clear that this pointer is required and also allows to make it a
reference rather than a (never null) pointer.
Also remove unnecessary dtor and initialize members in their declaration
when possible.
Even if CefRefPtr<T> has the same representation as T*, it is still
wrong to cast the latter to the former.
Instead, construct a temporary smart pointer object: this will make
extra calls to AddRef() and Release() but it's really not a big deal
when creating a new browser object.
Pass CefRect to it instead of 4 elements, as there is no overload taking
them any more.
Also unify wxMSW and wxOSX branches as they do exactly the same thing.
Finally, use client size instead of full size of the window.
Return the default case from the switch to make sure we get a warning if
an enum element is not handled.
Also avoid a warning about using possibly initialized "mapzoom".
Add new arguments to the various functions.
Stop using int64, which is not defined in the CEF headers any longer,
and use int64_t directly instead.
Don't rely on an implicit conversion of scoped_refptr<T> to T* which
doesn't exist any longer, so use an explicit get().
This function doesn't exist in the latest CEF versions and apparently
didn't work for a long time before it, see chromiumembedded/cef#2586, so
stop using it and use data: URI instead for loading the fixed text.
This replacement is not quite perfect, notably it doesn't show the
correct URI in the title bar, but better than nothing.
This avoids many warnings about unhandled enum values in the switch
statement.
It would be better to map all the error code to the correct category,
but it seems like this enum is being modified relatively often in
Chromium/CEF, so for now just use wxWEBVIEW_NAV_ERR_OTHER for all of the
unknown values.
Also handle ERR_NONE here, even if it's not clear if we can ever get it.
Return true, not false, from EnableProofCheck() when turning the checks
off in wxMSW.
Also fix wxTextProofOptions::IsSpellCheckEnabled() return value in
wxGTK, where EnableProofCheck() already returned the correct value but
only due to a combination of two bugs.
Closes#23831, #23832.