Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example to embedding webview with exist UI framework #965

Open
taozuhong opened this issue Jul 25, 2023 · 3 comments
Open

Add example to embedding webview with exist UI framework #965

taozuhong opened this issue Jul 25, 2023 · 3 comments
Labels
enhancement New feature, enhancement of an existing feature or a request

Comments

@taozuhong
Copy link

taozuhong commented Jul 25, 2023

For making webview library release more power, the example should consider to add example to embedding webview with exist UI framework, like GTK / wxWidgets / QT / MAUI / ...

pls see #938 #842 #466 #787 #243

@SteffenL SteffenL added the enhancement New feature, enhancement of an existing feature or a request label Jul 25, 2023
@SteffenL
Copy link
Collaborator

SteffenL commented Jul 31, 2023

Note: This is a "living" comment. I update it with the current information as I make progress with my experiments related to this topic.

I think this is a great idea, and is from what I can understand supposed to be a supported use case, but I'm not sure if the feature has ever really been in a usable state. I doubt that the library in its current state can be integrated cleanly with an existing UI framework.

wxWidgets (Windows 10)

On Windows we might need to get rid of the library's dependency on internal event/message loops as to not interfere with the existing loop provided by the UI framework.

Here's a demo of the library being integrated with wxWidgets on Windows 10. I was only able to do it this by making changes to the library itself.

wxwidgets.webm

In my experimental code, it creates a new child window which is used as the parent window for WebView2, and a message-only window for internal messaging (dispatch()). This child window (widget) is exposed by the library and passed into a wxNativeWindow which makes it work with wxWidgets. wxNativeWindow was introduced in wxWidgets 3.1 and I'm not yet sure how to do it with earlier versions.

GTK3 (Ubuntu 22.04)

gtk3.webm

WinAPI/Win32 (Windows)

Kind of cumbersome to work with but here's a demo for native Windows API.

win32.webm

Cocoa (macOS)

ARC Enabled

Not much luck yet due to memory-related crashes (EXC_BAD_ACCESS).

We also can't use NSAutoreleasePool but I think we can detect when ARC is enabled and use @autoreleasepool {...} instead.

ARC Disabled

It's possible to create an Objective-C++ class with ARC disabled for its source file. The implementation can call the C++ webview library with ARC disabled.

The Objective-C side can look similar to this:

#import "ViewController.h"
#import "WebviewBridge.h"

@implementation ViewController {
    WebviewBridge *_bridge;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    _bridge = [[WebviewBridge alloc] initWithDebug:NO window:_webContainer.window];
    // add _bridge.widget as subview of _webContainer
    [_bridge bindWithName: @"increment" block:^(NSString * req) {
        // ...
        return @"";
    }];

   // [_bridge setHTML:html];

}

@end

cocoa_1
cocoa_2

@PierceNg
Copy link
Contributor

Take a look at fpwebview, my Pascal binding, especially the demo lclembed, which embeds webview inside a Lazarus GUI application.

Lazarus is an IDE-cum-widget set interface for developing cross platform GUI applications in Pascal.

The demo works on macOS (using Lazarus Cocoa widget set) and Windows (using Lazarus Windows widget set).

For Linux:

  • with Lazarus GTK2: Impossible, as GTK2 and GTK3 (which webview on Linux uses) cannot coexist in one application (that executes as one operating system process).

  • with Lazarus GTK3: Should be trivial. Note that at present Lazarus GTK3 is work-in-progress and not mature.

  • with Lazarus Qt5/Qt6: Possible, potentially tricky. The basic requirement is to convert a Qt window handle into a GTK3 window suitable for use with webview.

@harrier77
Copy link

I am an absolute beginner, I wanted to try to embed webview in gtk using nim language. But from what I can understand it seems it is not possibile at now. But why the function webview_create() offers the possibility to pass a window handler if the embedding does not work?
I mean: in webview.h there is this:

The window parameter can be a pointer to the native window handle. If it's non-null - then child WebView
 is embedded into the given parent window.

but if it is so hard to make it work why is it there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, enhancement of an existing feature or a request
Development

No branches or pull requests

4 participants