Commit graph

75304 commits

Author SHA1 Message Date
Vadim Zeitlin
dfe4fc858f Add x64 support and improve wxWebViewChromium sample MSVS project
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.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
6b04c6ca49 Add CEF includes to x64 configs in wxWebViewChromium MSVS project
This was only done for Win32 configurations before.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
4395a47d40 Remove redundant wxWebViewChromium forward declaration
There is no need to do it just before the full class declaration.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
013940da8f Move ClientHandler to wxCEF namespace
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.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
e5e727747b Improve waiting for browser close to avoid crash on shutdown
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.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
ed131c9364 Improve work scheduling logic
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.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
dc92de0c3a Don't bother using DeferWindowPos() for resizing one window
This doesn't seem to be necessary, just call SetWindowPos() instead,
this is simpler and has the same effect.

No real changes.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
7dc4abd99f Add ClientHandler::GetWindowHandle() helper
No real changes, just move the code from wxWebViewChromium::OnSize() to
a reusable function.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
efe58535d1 Hide private wxWebViewChromium data into a private struct
No real changes, just a refactoring to make further changes simpler.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
f5e2af9a28 Make wxWebViewChromium work with wxGTK3 and X11
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.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
d3cc4678d5 Add entry hook mechanism and use it for Chromium helper processes
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.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
89987807df Remove superfluous semicolons from wxWebViewChromiumModule
No real changes, just avoid warnings in gcc pedantic mode.
2023-09-06 03:50:05 +02:00
Vadim Zeitlin
6762d5eaa5 Merge branch 'master' into webview-chromium
Merge the changes required by wxWebViewChromium, notably support for the
entry hooks and new wxDynamicLibrary::ListLoaded() Unix implementation.
2023-09-06 03:49:49 +02:00
Vadim Zeitlin
3861ad6b6d Merge branch 'init-data-refactor'
Refactor and improve command line arguments handling during
initialization.

See #23847.
2023-09-06 02:46:51 +02:00
Joan Bruguera Micó
952de605f6 Handle map/unmap events on Wayland's wxGLCanvasEGL
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.
2023-09-06 02:45:03 +02:00
Joan Bruguera Micó
19936c2176 Don't clobber std::string_view equality with char *
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.
2023-09-06 02:44:11 +02:00
Vadim Zeitlin
b3cfab1433 Merge branch 'msw-dont-preprocess-unknown'
Don't preprocess messages for unknown windows in wxMSW.

See #23824.
2023-09-06 02:41:08 +02:00
Vadim Zeitlin
d5d8c1ad28 Add a hack to fix link problem with wxScrolledCanvas in wx DLL
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.
2023-09-06 02:40:01 +02:00
Vadim Zeitlin
aec49d9c9d Use dl_iterate_phdr() in wxDynamicLibrary::ListLoaded()
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().
2023-09-06 00:40:11 +02:00
Vadim Zeitlin
497f6f993b Describe ownership rules for wxInitData pointers in comments
No real changes, just add some comments.
2023-09-02 23:17:49 +02:00
Vadim Zeitlin
ad7f5805bf Remove wxInitData::argvOrig which is not needed, finally
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.
2023-09-02 23:17:49 +02:00
Vadim Zeitlin
5f17915e63 Store original command line options passed to main()
This allows to avoid converting them back from Unicode to UTF-8 when we
need them in wxGTK initialization code and can also be useful elsewhere.
2023-09-02 23:17:49 +02:00
Vadim Zeitlin
229b749b34 Merge wxMSWCommandLineInit and wxInitData structs
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.
2023-09-02 23:17:49 +02:00
Vadim Zeitlin
b01bd389a2 Extract local InitData struct into a new private header
No real changes, just refactor the code to allow reusing this struct
from wxMSW in upcoming commits.
2023-09-02 23:17:49 +02:00
Vadim Zeitlin
ec33980a5f Wait until events are dispatched when closing the browser window
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.
2023-09-01 21:18:55 +02:00
Vadim Zeitlin
61cb46cbed Implement external message pump support in recommended way
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.
2023-09-01 21:18:17 +02:00
Vadim Zeitlin
0fd0496f81 Disable WS_EX_COMPOSITED when using wxWebViewChromium
It is incompatible with it and not only doesn't repaint properly, but
also is broken in various other mysterious ways, see
https://github.com/chromiumembedded/cef/issues/3562
2023-09-01 21:18:17 +02:00
Vadim Zeitlin
eb3a0675d8 Reformat call to CefBrowserHost::CreateBrowser()
No real changes.
2023-09-01 21:18:17 +02:00
Vadim Zeitlin
18456e7de2 Add tracing messages to wxWebViewChromium code
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.
2023-09-01 21:18:17 +02:00
Vadim Zeitlin
05fcc0588d Simplify ClientHandler construction
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.
2023-09-01 21:17:39 +02:00
Vadim Zeitlin
c42f611689 Use PostSizeEvent() instead of explicitly calling the handler
This is simpler and more robust.
2023-09-01 21:17:16 +02:00
Vadim Zeitlin
fa3f680e8f Construct temporary CefRefPtr instead of using a cast
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.
2023-09-01 21:17:16 +02:00
Vadim Zeitlin
cd690e9ae7 Fix CefWindowInfo::SetAsChild() call for the new API
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.
2023-09-01 21:17:16 +02:00
Vadim Zeitlin
34a70a8acd Prefer compile-time warning to assert in SetZoom()
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".
2023-09-01 21:16:53 +02:00
Vadim Zeitlin
d22275ce0a Merge branch 'update-msw-screenshots' of https://github.com/PBfordev/wxWidgets
Update screenshots of controls under wxMSW in documentation.

See #23842.
2023-09-01 17:47:12 +02:00
Juriy Petrochenkov
2503725d7d Fix typo in wxUSE_LONGLONG preprocessor constant 2023-09-01 15:22:14 +03:00
PB
2714bf19df Update screenshot in wxSplitterWindow Overview
Use screenshot of the splitter sample under Windows 11.
2023-08-31 21:56:05 +02:00
PB
ae1bf96788 Update screenshots of controls under wxMSW in documentation
In the documentation, replace all the screenshots of various
controls under wxMSW with those on Windows 11 22H2 (light mode).
2023-08-31 21:55:31 +02:00
Vadim Zeitlin
46ffe49be7 Update to latest CEF 116 API
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().
2023-08-31 18:11:02 +02:00
Vadim Zeitlin
50a3569c7b Stop using CefBrowser::LoadString()
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.
2023-08-31 18:10:32 +02:00
Vadim Zeitlin
8c32af7059 Handle all unknown error codes as wxWEBVIEW_NAV_ERR_OTHER
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.
2023-08-31 18:07:19 +02:00
Vadim Zeitlin
bb7d2eafae Don't use gtk_scrolled_window_add_with_viewport() with GTK 3
This function is deprecated, replace it with gtk_container_add().
2023-08-31 18:06:28 +02:00
Martin Corino
8ca3d3bc75 Fix wxTextCtrl proof checking functions return values
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.
2023-08-31 18:00:35 +02:00
Vadim Zeitlin
cdab976148 Build fixes for wxUSE_WEBVIEW_CHROMIUM && !wxUSE_WEBVIEW_WEBKIT
Fix wxGTK build when CEF backend is available but WebKit(2) one is not.
2023-08-31 16:01:21 +02:00
Martin Corino
a64004970c Fix wxHyperlinkCtrl::{Get,Set}Visited() signature in the docs
Don't document these functions as being pure virtual because they are
not.

Closes #23838.
2023-08-30 15:43:19 +02:00
Vadim Zeitlin
7f1e2de126 Document what wxWindow::WarpPointer() doesn't work with Wayland
There is nothing we can do about it, but we can at least document it.

See #23778.
2023-08-30 15:17:50 +02:00
Vadim Zeitlin
6ee4a4a88c Update the version since which Chromium backend is available 2023-08-30 02:04:05 +02:00
Vadim Zeitlin
bde58068dd Correct CEF webview library name in the sample bakefiles
It shouldn't have any underscore in it.
2023-08-30 02:04:05 +02:00
Vadim Zeitlin
f02bccac89 Avoid harmless unused parameter warnings
Just ads a couple of missing WXUNUSED().
2023-08-30 02:04:05 +02:00
Vadim Zeitlin
81fe0cb3be Implement wxWebViewChromium::{Get,Set}ZoomFactor()
Just use the corresponding CefBrowserHost methods.
2023-08-30 02:04:05 +02:00