Skip to content
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

CEF bug the modal stack in application #282

Closed
betonetotbo opened this issue Jun 18, 2020 · 12 comments
Closed

CEF bug the modal stack in application #282

betonetotbo opened this issue Jun 18, 2020 · 12 comments

Comments

@betonetotbo
Copy link

betonetotbo commented Jun 18, 2020

I'm using CEF4Delphi to display some charts. This charts are created using ApexCharts.

At this charts, there are a "hamburguer" icon on the right, who opens a popupmenu (pure html). When my user click on it my delphi application bug the modals.

All modals after clicking on the hamburguer are created behind the main form. And I cannot access them anymore.

Here is the bug:

bug-cef

And here is the code:

bug-cef.zip

My application is build with Delphi 7.1 enterprise (I'm not able to migrate to a new delphi version because incompatible routines).

And the windows host is Windows 7 x64 (6.1.7601). On Windows 10 (for example) it doesn't occurs.
The problem also occurred in WIndows 2008 R2 (6.1.7601).

@betonetotbo
Copy link
Author

Here we can see the active windows on my device, note that the window stack precedence is from the topmost to the bottommost.

image

@salvadordf
Copy link
Owner

Thank you for reporting this issue!
This could be caused by several things and right now I'm very busy but I'll try to take a look as soon as possible.

@salvadordf
Copy link
Owner

This seems to be a Delphi 7 issue :
https://stackoverflow.com/questions/8007449/delphi-messagebox-appearing-behind-other-form

Replace the MessageDlg line with this :
if Application.MessageBox('Deseja realmente fechar?','Title', + MB_APPLMODAL + MB_TOPMOST + MB_ICONQUESTION + MB_YESNO) = IDNO then exit;

@betonetotbo
Copy link
Author

The problem is that this bug occurs with other modals of my application and not only the MessageDlg.

@salvadordf
Copy link
Owner

Please, use our forums and provide all the details to find workarounds like the previous MessageBox example.

https://www.briskbard.com/forum/

@betonetotbo
Copy link
Author

@salvadordf , I tried to change your code at uCEFChromiumCore.pas at the method InitializeWindowInfo, I just added WS_EX_NOACTIVATE at the call to WindowInfoAsChild and seems to worked!

I will to test harder this solution and will report.

This change was based on post: https://www.briskbard.com/forum/viewtopic.php?t=723#p3299

@salvadordf
Copy link
Owner

I'm glad that it worked for you but please, also read the linked CEF issue. Another developer using CEF4Delphi pointed out some possible side effects :
https://bitbucket.org/chromiumembedded/cef/issues/1856/branch-2526-cef-activates-browser-window

salvadordf added a commit that referenced this issue Jun 22, 2020
DefaultWindowInfoExStyle is used to initialize the browser window with that ExStyle. In some cases a focus issue may be fixed if we use the WS_EX_NOACTIVATE value instead of 0 but it may have some side effects.

This could be used to fix issue #282
@salvadordf
Copy link
Owner

I just uploaded a new version of CEF4Delphi with a new TChromium.DefaultWindowInfoExStyle property to modify the ExStyle easily.

Try setting it to WS_EX_NOACTIVATE before the TChromium.CreateBrowser call.

@betonetotbo
Copy link
Author

I just uploaded a new version of CEF4Delphi with a new TChromium.DefaultWindowInfoExStyle property to modify the ExStyle easily.

Try setting it to WS_EX_NOACTIVATE before the TChromium.CreateBrowser call.

Solved! Thanks!

PS: there will be a release or just download the master version?

@salvadordf
Copy link
Owner

That feature is only available at the master version at this moment.
I'll create a new release with this in a few weeks when CEF4Delphi is updated to CEF 84.

@betonetotbo
Copy link
Author

betonetotbo commented Jun 22, 2020

@salvadordf sorry to inform, but this not solved the problem at all. Sometimes the bug continues to occur...

I found this at chromium repository: https://bitbucket.org/chromiumembedded/cef/issues/1856/branch-2526-cef-activates-browser-window

I think this problem is a "old friend" of CEF....

I tried also to use the --no-activate command line arg ( #283 ) but it seems also not to work, but I don't know if due to CEF4Delphi or not.

As ugly workaround I'll use this:

// TMyChromiumWindow = class(TChromiumWindow)
procedure TMyChromiumWindow.WndProc(var aMessage: TMessage);
begin
  inherited;
  SetWindowPos(Application.MainForm.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
end;

@salvadordf
Copy link
Owner

salvadordf commented Jun 23, 2020

CEF and Chromium have a special way to create the embedded browsers that can create issues as the one you linked.

Delphi also has its own issues with modal forms created behind the visible form but most of them were fixed in the latest Delphi version.

In fact, the MessageDlg issue you describe here can only be reproduced in Delphi 7. When I tried it in Delphi 10 it worked perfectly which means that it's probably a Delphi 7 issue.

It can be tricky to find a fix when you mix all of these possible focus issues in one application.

If you can't find a workaround for Delphi 7 then you can try 2 other browser configurations :

  • Use an "Enternal Pump" as described in the SimpleExternalPumpBrowser demo. Some developers use this to fix some issues with popup menus.
  • Use the "Off-screen mode" (OSR mode) found in the SimpleOSRBrowser demo. This mode gives you total control at the cost of browser performance. If you still have focus issues with this demo it means that it's a Delphi 7 issue.

Please, use our forums for more questions :
https://www.briskbard.com/forum/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants