hamden wrote: Sat Jan 27, 2024 11:36 pm
I modified the SimpleBrowser_D7 source to implement all necessary and required events
Code: Select all
// It's necessary to handle these messages to call NotifyParentWindowPositionChanged or some page elements will be misaligned.
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
Hello, @hamden
Can you show any specific case about "some page elements will be misaligned." ?
I commented out these two functions and i see nothing bad in Win 10 + Delphi 2007, maybe i don't know where to look...
Microsoft docs are VERY ambiguous there.
- https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2controller?view=webview2-1.0.2903.40#notifyparentwindowpositionchanged
- https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2controller.notifyparentwindowpositionchanged?view=webview2-dotnet-1.0.2792.45
This is needed for accessibility and certain dialogs in WebView to work correctly.
Tells WebView that the main WebView parent (or any ancestor) HWND moved.
Really, what should it mean?..
I played a bit with the Simple Demo (after commenting out WM_MOV*) and could not trigger any bug.
-----
Your quick-fix is ok for a demo, but would hardly be a good thing for a library.
- It is unsafe-by-default. Unless made a part of the control itself - it would be mostly forgotten by the library users.
- It is very boilerplaty and error-prone...
- It is not enough
- Is it even needed really?
About being enough, for this simplistic demo the "or any ancestor HWND" clause would not matter, but in most practical implementation the browser would be placed in some panel and/or pagecontrol and/or frame/CCPack, etc
I modified the Simple Demo
Code: Select all
TPanel = class(ExtCtrls.TPanel)
private
procedure WMMove(var aMessage : TWMMove); message WM_MOVE;
procedure WMMoving(var aMessage : TMessage); message WM_MOVING;
end;
TMainForm = class(TForm)
When i run it there was one single call to
TPanel.WMMove and nothing after it.
So, we may think in practical applications form-level events would not be enough.
If, against the intuition, Windows or VCL would be sending those to child windows, all we would have to do would be a simplistic modification in the procedure TWVWindowParent.WndProc(var aMessage: TMessage); but sadly it would not work
There are hooking facilities in Windows,
SetWindowsHookEx and
SetWinEventHook: https://stackoverflow.com/a/22025978/976391
However those would be dependent upon filtering HWND real quick.
It would not be hard to add the global
TObjectList keeping track of all the created browsers.
However should we do naive iterating through all of them?
Because mere caching the HWND parenting chain would be fragile in case of later re-parenting.
Or should we somehow hook the re-parenting events (i think i saw something about it, but i am not sure) and invalidate those chains?
Make me convinced
NotifyParentWindowPositionChanged is worth attention at all, or we have to do it properly, which is kinda demanding
----