Page 1 of 1

Everything freezes when resizing

Posted: Tue Apr 22, 2025 8:59 am
by Isaev
I have TCEFWindowParent and TChromium on the form, and I'm handling the ChromiumKeyEvent

Code: Select all

...
  if event^.kind = KEYEVENT_RAWKEYDOWN then
  begin
    //Ctrl + Shift + L
    if ((event^.modifiers and EVENTFLAG_CONTROL_DOWN) <> 0) and
       ((event^.modifiers and EVENTFLAG_SHIFT_DOWN) <> 0) and
       (event^.windows_key_code = Ord('L')) then
    begin
      Result := True;
      PanelEditVisibleChange; //Everything freezes when resizing — the only option is to kill the process.
    end;
  end;
...
 
procedure TWebForm.PanelEditVisibleChange;
var
  vis: Boolean;
begin
  CEFWindowParent.Visible := False;
  Application.ProcessMessages;

  //if Assigned(Chromium.Browser) then
  // Chromium.Browser.Host.NotifyMoveOrResizeStarted;

  vis := not(pnlEdit.Visible);

  if vis then begin
    //FOrigWidth := Self.Width;
    Self.Width := FOrigWidth + pnlEdit.Width + spHaupt.Width;
    pnlEdit.Visible := vis;
    spHaupt.Visible := vis;
    spHaupt.Left := pnlEdit.Left - spHaupt.Width - 10;
  end
    else
  begin
    spHaupt.Visible := vis;
    pnlEdit.Visible := vis;
    //FOrigWidth := Self.Width;
    Self.Width := FOrigWidth;
  end;
  CEFWindowParent.Visible := True;
end;
[CEF4Delphi uses CEF 135.0.17 which includes Chromium 135.0.7049.52]

Re: Everything freezes when resizing

Posted: Tue Apr 22, 2025 9:23 am
by salvadordf
Hi,

Most of the demos are configured to trigger the Chromium events in the context of a CEF thread which is different than the main application thread.

Save the information you may need in the TChromium event and use your preferred method to execute the code that updates the user interface in the main application thread. You can use TThread.Queue, a custom message to the main form, etc.

Re: Everything freezes when resizing

Posted: Tue Apr 22, 2025 10:32 am
by Isaev
But if I configure it at startup, like

Code: Select all

GlobalCEFApp.SingleProcess := True;
shouldn't it already work in the main application thread?

If I change the form size in the Chromium.OnAfterCreated event, everything works perfectly,
but in Chromium.OnKeyEvent it causes a freeze.

Re: Everything freezes when resizing

Posted: Tue Apr 22, 2025 1:13 pm
by Isaev
Yes, sending via an event to the main form works, thanks!
I did it like this:

Code: Select all

...
  USER_CEF_DOFORMRESIZE = {$IFDEF MSWINDOWS}WM_APP +{$ENDIF} $B00;
...
  procedure BrowserFormResize(var aMessage: TMessage); message USER_CEF_DOFORMRESIZE;
...
  PostMessage(Handle, USER_CEF_DOFORMRESIZE, 0, 0);
...
Is this the right approach?

Re: Everything freezes when resizing

Posted: Tue Apr 22, 2025 1:25 pm
by salvadordf
GlobalCEFApp.SingleProcess should only be used for debugging purposes. Read all the details in the code comments of that property and here : https://www.briskbard.com/index.php?lang=en&pageid=cef#debugging

Sending a custom message to the main form is one of the ways to fix this issue.

All Chromium and CEF events are executed in a CEF thread and sometimes in a different process.
The user interface is not thread safe and we must always handle it in the main application thread.

Read this document and the Wiki for more information :
https://www.briskbard.com/index.php?lang=en&pageid=cef
https://github.com/salvadordf/CEF4Delphi/wiki