views: Support configuration of initial window show state

Known issues:
- Exiting full-screen mode currently crashes with the Chrome runtime
  (see issue #3182).
This commit is contained in:
Marshall Greenblatt
2021-09-07 17:04:55 +03:00
parent 2b40cab3fe
commit dc1f934865
16 changed files with 147 additions and 17 deletions

View File

@@ -133,7 +133,7 @@ void ViewsWindow::Show() {
CEF_REQUIRE_UI_THREAD();
if (window_)
window_->Show();
if (browser_view_) {
if (browser_view_ && !window_->IsMinimized()) {
// Give keyboard focus to the BrowserView.
browser_view_->RequestFocus();
}
@@ -529,6 +529,11 @@ void ViewsWindow::OnWindowCreated(CefRefPtr<CefWindow> window) {
// Add keyboard accelerators to the Window.
AddAccelerators();
// Hide the top controls while in full-screen mode.
if (initial_show_state_ == CEF_SHOW_STATE_FULLSCREEN) {
ShowTopControls(false);
}
} else {
// Add the BrowserView as the only child of the Window.
window_->AddChildView(browser_view_);
@@ -599,6 +604,11 @@ CefRect ViewsWindow::GetInitialBounds(CefRefPtr<CefWindow> window) {
return CefRect();
}
cef_show_state_t ViewsWindow::GetInitialShowState(CefRefPtr<CefWindow> window) {
CEF_REQUIRE_UI_THREAD();
return initial_show_state_;
}
bool ViewsWindow::IsFrameless(CefRefPtr<CefWindow> window) {
CEF_REQUIRE_UI_THREAD();
return frameless_;
@@ -786,6 +796,16 @@ ViewsWindow::ViewsWindow(Delegate* delegate,
chrome_toolbar_type_ = CEF_CTT_NONE;
}
const std::string& show_state =
command_line->GetSwitchValue(switches::kInitialShowState);
if (show_state == "minimized") {
initial_show_state_ = CEF_SHOW_STATE_MINIMIZED;
} else if (show_state == "maximized") {
initial_show_state_ = CEF_SHOW_STATE_MAXIMIZED;
} else if (show_state == "fullscreen") {
initial_show_state_ = CEF_SHOW_STATE_FULLSCREEN;
}
#if !defined(OS_MAC)
// On Mac we don't show a top menu on the window. The options are available in
// the app menu instead.

View File

@@ -157,6 +157,7 @@ class ViewsWindow : public CefBrowserViewDelegate,
bool* is_menu,
bool* can_activate_menu) override;
CefRect GetInitialBounds(CefRefPtr<CefWindow> window) override;
cef_show_state_t GetInitialShowState(CefRefPtr<CefWindow> window) override;
bool IsFrameless(CefRefPtr<CefWindow> window) override;
bool CanResize(CefRefPtr<CefWindow> window) override;
bool CanClose(CefRefPtr<CefWindow> window) override;
@@ -236,6 +237,7 @@ class ViewsWindow : public CefBrowserViewDelegate,
int last_focused_view_;
CefSize minimum_window_size_;
cef_show_state_t initial_show_state_ = CEF_SHOW_STATE_NORMAL;
CefRefPtr<ViewsOverlayControls> overlay_controls_;

View File

@@ -46,6 +46,7 @@ const char kLoadExtension[] = "load-extension";
const char kNoActivate[] = "no-activate";
const char kEnableChromeRuntime[] = "enable-chrome-runtime";
const char kShowChromeToolbar[] = "show-chrome-toolbar";
const char kInitialShowState[] = "initial-show-state";
} // namespace switches
} // namespace client

View File

@@ -40,6 +40,7 @@ extern const char kLoadExtension[];
extern const char kNoActivate[];
extern const char kEnableChromeRuntime[];
extern const char kShowChromeToolbar[];
extern const char kInitialShowState[];
} // namespace switches
} // namespace client