-
Notifications
You must be signed in to change notification settings - Fork 54
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
Implement draggable regions #200
Comments
Thanks for trying out WebView2! In the case of Chrome apps & Electron, the app framework owns the top level app window and can drag it along with the app region. To support this with WebView2, I suppose you would need a callback to the host app to tell it to move the parent window? |
That is a fantastic question on the "mechanics of how". There is a reference implementation I am looking through for CefSharp that does just this: This weekend (if I am allowed 😄) I will look into reverse engineering how that was done. Otherwise, I'll do some hook injection and see what can would be the "minimal" eventing to hook something like this up. Cross-process HWND hierarchies is an interesting problem, indeed! |
Turns out it is fairly easy for implementors to fill in this behavior with a registered host object and an injected script. I suppose that raises the question of whether or not the WebView2 control needs to have this behavior built-in, but I would still think its a "nice to have". For those who might stumble across this issue while searching for something similar - here's the approach to implement it yourself: Host Object (C#)
Host Hookup (C#)
Preload (js)
Maybe I'll put this up in a demo repo somewhere 😄 ... |
Thanks Nicholas!! |
Thanks for this issue and especially for the solution, @nicholasdgoodman! I'm going to close out this issue. But we are still keeping track of this and your suggestion of it being "nice to have". We have been looking into some design changes that would possibly incorporate this into WebView2. But don't have any concrete proposal to share out yet. |
Very interesting, very cool solution, but what if the window is dragged to the edge of the screen? will the maximize option appear as in the native function? I still couldn't test this proposed solution, but I thought it was really cool! |
Easy enough to add edge detection and show another form as preview frame. |
I've implemented the suggested workaround in C++ using an ATL IDispatchImpl, moving the window works as described. Any suggestion on how I might raise the window to the foreground when it is clicked? I have tried: SetWindowPos( ..., HWND_TOP, ... , SWP_NOMOVE| SWP_NOSIZE) Not really acceptable to make the window WM_EX_TOPMOST This has turned out to be a bit of a time sink, perhaps enabling WM_NCHITTEST pass through can be reconsidered? Any suggestions welcome. |
Intercepting the WM_NCLBUTTONDOWN in the window message loop and then calling SwitchToThisWindow from that thread seems to raise the window topmost: SwitchToThisWindow(hWnd, FALSE); However, MSDN hints that it may be removed: "[This function is not intended for general use. It may be altered or unavailable in subsequent versions of Windows.] " https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-switchtothiswindow Are there any safe alternatives to this? |
@Coder666 Would you please consider sharing your C++ solution here? |
More than happy to discuss contract work to accomplish this, please get in touch via the website if you are interested. |
@nicholasdgoodman Thanks for the workaround. However, I'm having trouble getting it to work. I'm adding the script to a window that I'm opening (intercepting via the NewWindowRequested event), but it seems like the preload script doesn't even execute since the top-level console.log statement don't get hit. I'm using WPF. I'm doing something roughly like this:
Is there something obvious that I'm doing wrong? I get the same issue when I pass in the script contents directly into |
A side-effect to this approach is that click and doubleclick events on the element aren't fired because (it would seem that) |
using this method, in version 109, repeatedly refreshing the page and dragging the form crashes |
Draggable regions are a feature implemented in Chrome apps (formerly) and are also available in Electron.
Elements with the style:
behave as a non-client area of the window and allow the window to be dragged (like a titlebar).
The text was updated successfully, but these errors were encountered: