Skip to content

Commit

Permalink
Fixes #198: Setting the HwndParent for the Chrome_WidgetWin_0 window …
Browse files Browse the repository at this point in the history
…makes the popupmenu to close if the user clicks somewhere else.
  • Loading branch information
ahausladen committed Nov 11, 2019
1 parent e9f4bb1 commit 688969b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions source/uCEFChromiumCore.pas
Expand Up @@ -4513,6 +4513,22 @@ procedure TChromiumCore.doOnRenderProcessTerminated(const browser: ICefBrowser;
if Assigned(FOnRenderProcessTerminated) then FOnRenderProcessTerminated(Self, browser, status);
end;

{$IFDEF MSWINDOWS}
function EnumProcOSRChromeWidgetWin0(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
var
ClsName: array[0..256] of Char;
begin
ClsName[GetClassName(hWnd, ClsName, 256)] := #0;
if StrComp(ClsName, 'Chrome_WidgetWin_0') = 0 then
begin
PHandle(lParam)^ := hWnd;
Result := False;
end
else
Result := True;
end;
{$ENDIF MSWINDOWS}

procedure TChromiumCore.doOnRenderViewReady(const browser: ICefBrowser);
{$IFDEF MSWINDOWS}
var
Expand All @@ -4532,7 +4548,19 @@ procedure TChromiumCore.doOnRenderViewReady(const browser: ICefBrowser);
FBrowserCompHWND := browser.Host.WindowHandle;
{$IFDEF MSWINDOWS}
if (FBrowserCompHWND <> 0) then
begin
FWidgetCompHWND := FindWindowEx(FBrowserCompHWND, 0, 'Chrome_WidgetWin_0', '');
if (FWidgetCompHWND = 0) and FIsOSR and CefCurrentlyOn(TID_UI) then
begin
// The WidgetCompHWND window doesn't have a HwndParent (Owner). If we are in OSR mode this
// causes popup menus that are opened by CEF to stay open if the user clicks somewhere else.
// With this code we search for the Widget window in the UI Thread's window list and set
// the Browser window as its HwndParent. This works around the bug.
EnumThreadWindows(GetCurrentThreadId, @EnumProcOSRChromeWidgetWin0, NativeInt(@FWidgetCompHWND));
if FWidgetCompHWND <> 0 then
SetWindowLongPtr(FWidgetCompHWND, GWLP_HWNDPARENT, NativeInt(FBrowserCompHWND));
end;
end;

if (FWidgetCompHWND <> 0) then
FRenderCompHWND := FindWindowEx(FWidgetCompHWND, 0, 'Chrome_RenderWidgetHostHWND', 'Chrome Legacy Window');
Expand Down
1 change: 1 addition & 0 deletions source/uCEFMiscFunctions.pas
Expand Up @@ -138,6 +138,7 @@ function PathIsURLUnicode(pszPath: LPCWSTR): BOOL; stdcall; external SHLWAPIDLL
{$IFNDEF DELPHI12_UP}
const
GWLP_WNDPROC = GWL_WNDPROC;
GWLP_HWNDPARENT = GWL_HWNDPARENT;
{$IFDEF WIN64}
function SetWindowLongPtr(hWnd: HWND; nIndex: Integer; dwNewLong: int64): int64; stdcall; external user32 name 'SetWindowLongPtrW';
{$ELSE}
Expand Down

0 comments on commit 688969b

Please sign in to comment.