Skip to content

Commit c10c84b

Browse files
committed
[cef] adjust windows code
While view framework used - hide window before it appears
1 parent 862da93 commit c10c84b

2 files changed

Lines changed: 26 additions & 15 deletions

File tree

gui/cefdisplay/src/RCefWebDisplayHandle.cxx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,26 @@ std::unique_ptr<ROOT::RWebDisplayHandle> RCefWebDisplayHandle::CefCreator::Displ
134134
bool supress_log = (settings.log_severity == LOGSEVERITY_DISABLE) ||
135135
(settings.log_severity == LOGSEVERITY_FATAL);
136136

137-
#ifdef OS_WIN
138-
CefMainArgs main_args(GetModuleHandle(nullptr));
139-
#else
140137
TApplication *root_app = gROOT->GetApplication();
141138

142139
std::vector<const char *> cef_argv = { root_app->Argv(0) };
143140

141+
#ifdef OS_WIN
142+
143+
CefMainArgs main_args(args.IsHeadless() ? (HINSTANCE) 0 : GetModuleHandle(nullptr));
144+
145+
#else
146+
144147
if (args.IsHeadless()) {
145148
cef_argv.emplace_back("--user-data-dir=.");
146149
cef_argv.emplace_back("--allow-file-access-from-files");
147150
cef_argv.emplace_back("--disable-web-security");
148151
cef_argv.emplace_back("--disable-gpu");
149152
cef_argv.emplace_back("--ignore-gpu-blocklist");
153+
#ifdef OS_LINUX
150154
cef_argv.emplace_back("--use-gl=swiftshader");
151155
cef_argv.emplace_back("--enable-unsafe-swiftshader");
156+
#endif
152157
cef_argv.emplace_back("--off-screen-rendering-enabled");
153158
if (use_views)
154159
cef_argv.emplace_back("--ozone-platform=headless");
@@ -163,6 +168,7 @@ std::unique_ptr<ROOT::RWebDisplayHandle> RCefWebDisplayHandle::CefCreator::Displ
163168
cef_argv.emplace_back(nullptr);
164169

165170
CefMainArgs main_args(cef_argv.size() - 1, (char **) cef_argv.data());
171+
166172
#endif
167173

168174
// CEF applications have multiple sub-processes (render, plugin, GPU, etc)

gui/cefdisplay/src/simple_app.cxx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,26 @@ namespace {
4444
// implementation for the CefWindow that hosts the Views-based browser.
4545
class SimpleWindowDelegate : public CefWindowDelegate {
4646
CefRefPtr<CefBrowserView> fBrowserView;
47-
int fWidth{800}; ///< preferred window width
48-
int fHeight{600}; ///< preferred window height
47+
int fWidth = 800; ///< preferred window width
48+
int fHeight = 600; ///< preferred window height
49+
bool fBatch = false;
4950
public:
50-
explicit SimpleWindowDelegate(CefRefPtr<CefBrowserView> browser_view, int width = 800, int height = 600)
51-
: fBrowserView(browser_view), fWidth(width), fHeight(height)
51+
explicit SimpleWindowDelegate(CefRefPtr<CefBrowserView> browser_view, int width = 800, int height = 600, bool batch = false)
52+
: fBrowserView(browser_view), fWidth(width), fHeight(height), fBatch(batch)
5253
{
5354
}
5455

5556
void OnWindowCreated(CefRefPtr<CefWindow> window) override
5657
{
57-
// Add the browser view and show the window.
5858
window->AddChildView(fBrowserView);
59-
window->Show();
6059

61-
// Give keyboard focus to the browser view.
62-
fBrowserView->RequestFocus();
60+
if (fBatch) {
61+
window->Hide();
62+
} else {
63+
window->Show();
64+
// Give keyboard focus to the browser view.
65+
fBrowserView->RequestFocus();
66+
}
6367
}
6468

6569
void OnWindowDestroyed(CefRefPtr<CefWindow> window) override { fBrowserView = nullptr; }
@@ -202,7 +206,7 @@ void SimpleApp::StartWindow(THttpServer *serv, const std::string &addr, const st
202206
CefBrowserView::CreateBrowserView(fGuiHandler, url, browser_settings, nullptr, nullptr, new SimpleBrowserViewDelegate());
203207

204208
// Create the Window. It will show itself after creation.
205-
CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browser_view, rect.width, rect.height));
209+
CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browser_view, rect.width, rect.height, is_batch));
206210

207211
if (fNextHandle) {
208212
fNextHandle->SetBrowser(browser_view->GetBrowser());
@@ -217,13 +221,14 @@ void SimpleApp::StartWindow(THttpServer *serv, const std::string &addr, const st
217221
// one should implement CefRenderHandler
218222

219223
#if defined(OS_WIN)
220-
RECT wnd_rect = {rect.x, rect.y, rect.x + rect.width, rect.y + rect.height};
221-
if (!rect.IsEmpty()) window_info.SetAsChild(0, wnd_rect);
224+
if (!rect.IsEmpty())
225+
window_info.SetAsChild(0, rect);
222226
// On Windows we need to specify certain flags that will be passed to
223227
// CreateWindowEx().
224228
window_info.SetAsPopup(0, "cefsimple");
225229
if (is_batch)
226-
window_info.SetAsWindowless(GetDesktopWindow());
230+
// window_info.SetAsWindowless(GetDesktopWindow());
231+
window_info.SetAsWindowless(kNullWindowHandle);
227232
#else
228233
if (!rect.IsEmpty())
229234
window_info.SetAsChild(0, rect);

0 commit comments

Comments
 (0)