Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Everything freezes when resizing

Post Reply
Isaev
Posts: 4
Joined: Tue Apr 22, 2025 8:57 am

Everything freezes when resizing

Post 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]
User avatar
salvadordf
Posts: 4563
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Everything freezes when resizing

Post 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.
Isaev
Posts: 4
Joined: Tue Apr 22, 2025 8:57 am

Re: Everything freezes when resizing

Post 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.
Isaev
Posts: 4
Joined: Tue Apr 22, 2025 8:57 am

Re: Everything freezes when resizing

Post 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?
User avatar
salvadordf
Posts: 4563
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Everything freezes when resizing

Post 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
Post Reply