Edwin Yip
Edwin Yip

Reputation: 4220

Chromium-embedded for Delphi - TChromiumOSR.OnPaint is not fired when a modal window is shown

I'm using the Off-screen rendering component TChromiumOSR in the dcef3 package - the Delphi wrapper for Chromium-embedded library.

Situation

FormA contains a TChromiumOSR and paints the output. Modal FormB modifies the web page by executing some js code against FormA.TChromiumOSR.

Issue

The TChromiumOSR.OnPaint event (in FormA) is not triggered until FormB.ShowModal returns.

Notes

I assume the `TForm.ShowModal' method only blocks the input of the background forms, but not the painting?

Or does it caused by the internal working of cef3?

Anyway, how to solve it? Thanks.

dcef3 master branch is here

Upvotes: 0

Views: 612

Answers (2)

Edwin Yip
Edwin Yip

Reputation: 4220

Ok, I found the source of the problem - it's not a bug in cef3 or dcef3 but was caused by my improper use of Delphi Event Bus, and the following are the steps to reproduce the issue:

  1. In one the 'delphi event bus' handler, the program shows a modal form at this point the execution of the main thread is blocked.
  2. On top of the modal form, the user doing certain actions will start a background thread, which in turn will send a message to the main thread, which in turn will calls the 'delphi event bus' to post another new event, which in turn will execute some js code to update the web page inside dcef3, which in turn will trigger some of the dcef3 events (in the main thread), and here is where the program stuck - since the TEventBus.Post() method is locked by a TCriticalSection.

Solution: In Step #1, don't call ShowModal directly, but use a technique such as PostMessage winapi to 'delay' the execution of ShowModal.

I'm not sure if I have described it clearly...

Upvotes: 0

Victoria
Victoria

Reputation: 7912

I've succeeded updating an HTML element by using the ExecuteJavaScript method called from a modal form. But you might have use CEF V8 as well (that's what I haven't tested). For cases when you need to invalidate the current view manually, you can call Invalidate:

MyChromiumOSR.Browser.Host.Invalidate(PET_VIEW);

But that's workaround rather than solution. Invalidating of relevant elements should happen by the CEF engine for you. And if you come up with an MCVE, I can investigate more about your specific problem.

Upvotes: 1

Related Questions