mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-01-27 09:41:17 +01:00
views: mac: Add CEF_SHOW_STATE_HIDDEN (fixes #3630)
- Adds `--initial-show-state=hidden` support for cefclient and cefsimple where the window launches as initially hidden (no dock thumbnail). - Adds `--hide-window-on-close` support for cefclient where clicking the red traffic light button hides the window instead of closing it.
This commit is contained in:
parent
47fe9f834a
commit
57bad703ee
@ -42,13 +42,13 @@
|
||||
// way that may cause binary incompatibility with other builds. The universal
|
||||
// hash value will change if any platform is affected whereas the platform hash
|
||||
// values will change only if that particular platform is affected.
|
||||
#define CEF_API_HASH_UNIVERSAL "26455bea1da0a2592502ac7a3889bbb7c7c41652"
|
||||
#define CEF_API_HASH_UNIVERSAL "60ecc3c751154b2b2b41e5d3ac0ccbeba588918d"
|
||||
#if defined(OS_WIN)
|
||||
#define CEF_API_HASH_PLATFORM "e29ebe81ef26bdbf93ee46ca2f6437ffbb91bb36"
|
||||
#define CEF_API_HASH_PLATFORM "7819cee8508a9b048ccfa80acea7351a5b549c45"
|
||||
#elif defined(OS_MAC)
|
||||
#define CEF_API_HASH_PLATFORM "36f2affe168d233f9864b0c2d23144f01a737bac"
|
||||
#define CEF_API_HASH_PLATFORM "f2bb2e5a9d14dcad463fd3fc8ed4af16b6fe6196"
|
||||
#elif defined(OS_LINUX)
|
||||
#define CEF_API_HASH_PLATFORM "cb887a91b5128574e18ff99b03798a8aed936561"
|
||||
#define CEF_API_HASH_PLATFORM "bcf76490ddea85c12ea8feeee9190ffe24dedcc6"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -3452,10 +3452,21 @@ typedef enum {
|
||||
/// Show states supported by CefWindowDelegate::GetInitialShowState.
|
||||
///
|
||||
typedef enum {
|
||||
// Show the window as normal.
|
||||
CEF_SHOW_STATE_NORMAL = 1,
|
||||
|
||||
// Show the window as minimized.
|
||||
CEF_SHOW_STATE_MINIMIZED,
|
||||
|
||||
// Show the window as maximized.
|
||||
CEF_SHOW_STATE_MAXIMIZED,
|
||||
|
||||
// Show the window as fullscreen.
|
||||
CEF_SHOW_STATE_FULLSCREEN,
|
||||
|
||||
// Show the window as hidden (no dock thumbnail).
|
||||
// Only supported on MacOS.
|
||||
CEF_SHOW_STATE_HIDDEN,
|
||||
} cef_show_state_t;
|
||||
|
||||
///
|
||||
|
@ -451,6 +451,13 @@ void CefWindowView::CreateWidget(gfx::AcceleratedWidget parent_widget) {
|
||||
case CEF_SHOW_STATE_FULLSCREEN:
|
||||
params.show_state = ui::SHOW_STATE_FULLSCREEN;
|
||||
break;
|
||||
case CEF_SHOW_STATE_HIDDEN:
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
params.show_state = ui::SHOW_STATE_HIDDEN;
|
||||
#else
|
||||
params.show_state = ui::SHOW_STATE_MINIMIZED;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
bool is_menu = false;
|
||||
|
@ -121,6 +121,9 @@ patches = [
|
||||
# chrome: Allow override of Widget::Activate() to support activation of
|
||||
# DevTools windows with external parent.
|
||||
# https://github.com/chromiumembedded/cef/issues/3282
|
||||
#
|
||||
# mac: Add support for ui::SHOW_STATE_HIDDEN.
|
||||
# https://github.com/chromiumembedded/cef/issues/3630
|
||||
'name': 'views_widget',
|
||||
},
|
||||
{
|
||||
|
@ -1,3 +1,65 @@
|
||||
diff --git chrome/browser/extensions/api/sessions/sessions_api.cc chrome/browser/extensions/api/sessions/sessions_api.cc
|
||||
index cbecf407dfce8..35c2bf2687283 100644
|
||||
--- chrome/browser/extensions/api/sessions/sessions_api.cc
|
||||
+++ chrome/browser/extensions/api/sessions/sessions_api.cc
|
||||
@@ -333,6 +333,7 @@ SessionsGetDevicesFunction::CreateWindowModel(
|
||||
state = api::windows::WindowState::kNormal;
|
||||
break;
|
||||
case ui::SHOW_STATE_MINIMIZED:
|
||||
+ case ui::SHOW_STATE_HIDDEN:
|
||||
state = api::windows::WindowState::kMinimized;
|
||||
break;
|
||||
case ui::SHOW_STATE_MAXIMIZED:
|
||||
diff --git chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.cc chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.cc
|
||||
index cef40af382b1e..a2cf4691edc37 100644
|
||||
--- chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.cc
|
||||
+++ chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.cc
|
||||
@@ -43,6 +43,7 @@ ChromeNativeAppWindowViewsAura::GetRestorableState(
|
||||
|
||||
case ui::SHOW_STATE_DEFAULT:
|
||||
case ui::SHOW_STATE_MINIMIZED:
|
||||
+ case ui::SHOW_STATE_HIDDEN:
|
||||
case ui::SHOW_STATE_INACTIVE:
|
||||
case ui::SHOW_STATE_END:
|
||||
return ui::SHOW_STATE_NORMAL;
|
||||
diff --git components/sessions/core/session_service_commands.cc components/sessions/core/session_service_commands.cc
|
||||
index 70781f59a7528..65f30d4ff614d 100644
|
||||
--- components/sessions/core/session_service_commands.cc
|
||||
+++ components/sessions/core/session_service_commands.cc
|
||||
@@ -165,9 +165,10 @@ enum PersistedWindowShowState {
|
||||
PERSISTED_SHOW_STATE_MAXIMIZED = 3,
|
||||
// SHOW_STATE_INACTIVE (4) never persisted.
|
||||
PERSISTED_SHOW_STATE_FULLSCREEN = 5,
|
||||
- PERSISTED_SHOW_STATE_DETACHED_DEPRECATED = 6,
|
||||
- PERSISTED_SHOW_STATE_DOCKED_DEPRECATED = 7,
|
||||
- PERSISTED_SHOW_STATE_END = 8,
|
||||
+ // SHOW_STATE_HIDDEN (6) never persisted.
|
||||
+ PERSISTED_SHOW_STATE_DETACHED_DEPRECATED = 7,
|
||||
+ PERSISTED_SHOW_STATE_DOCKED_DEPRECATED = 8,
|
||||
+ PERSISTED_SHOW_STATE_END = 9,
|
||||
};
|
||||
|
||||
// TODO(crbug.com/1506068): Remove this around December 2024. This is part of a
|
||||
@@ -191,6 +192,7 @@ PersistedWindowShowState ShowStateToPersistedShowState(
|
||||
case ui::SHOW_STATE_NORMAL:
|
||||
return PERSISTED_SHOW_STATE_NORMAL;
|
||||
case ui::SHOW_STATE_MINIMIZED:
|
||||
+ case ui::SHOW_STATE_HIDDEN:
|
||||
return PERSISTED_SHOW_STATE_MINIMIZED;
|
||||
case ui::SHOW_STATE_MAXIMIZED:
|
||||
return PERSISTED_SHOW_STATE_MAXIMIZED;
|
||||
diff --git components/sessions/core/tab_restore_service_impl.cc components/sessions/core/tab_restore_service_impl.cc
|
||||
index 837fbd223fe94..0f751768e5e32 100644
|
||||
--- components/sessions/core/tab_restore_service_impl.cc
|
||||
+++ components/sessions/core/tab_restore_service_impl.cc
|
||||
@@ -192,6 +192,7 @@ int SerializeWindowShowState(ui::WindowShowState show_state) {
|
||||
case ui::SHOW_STATE_NORMAL:
|
||||
return kSerializedShowStateNormal;
|
||||
case ui::SHOW_STATE_MINIMIZED:
|
||||
+ case ui::SHOW_STATE_HIDDEN:
|
||||
return kSerializedShowStateMinimized;
|
||||
case ui::SHOW_STATE_MAXIMIZED:
|
||||
return kSerializedShowStateMaximized;
|
||||
diff --git content/browser/renderer_host/render_widget_host_view_base.cc content/browser/renderer_host/render_widget_host_view_base.cc
|
||||
index 6b51fa563b1b7..4dfac0e609ae6 100644
|
||||
--- content/browser/renderer_host/render_widget_host_view_base.cc
|
||||
@ -151,6 +213,32 @@ index b3acdceb83879..7a2de7e7d0678 100644
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
// Set the view's active state (i.e., tint state of controls).
|
||||
virtual void SetActive(bool active) = 0;
|
||||
diff --git ui/base/mojom/ui_base_types_mojom_traits.h ui/base/mojom/ui_base_types_mojom_traits.h
|
||||
index 1d79fc2dc34cc..ce5bf0ebf531f 100644
|
||||
--- ui/base/mojom/ui_base_types_mojom_traits.h
|
||||
+++ ui/base/mojom/ui_base_types_mojom_traits.h
|
||||
@@ -172,6 +172,7 @@ struct EnumTraits<ui::mojom::WindowShowState, ui::WindowShowState> {
|
||||
case ui::SHOW_STATE_INACTIVE:
|
||||
return ui::mojom::WindowShowState::SHOW_STATE_INACTIVE;
|
||||
case ui::SHOW_STATE_MINIMIZED:
|
||||
+ case ui::SHOW_STATE_HIDDEN:
|
||||
return ui::mojom::WindowShowState::SHOW_STATE_MINIMIZED;
|
||||
case ui::SHOW_STATE_MAXIMIZED:
|
||||
return ui::mojom::WindowShowState::SHOW_STATE_MAXIMIZED;
|
||||
diff --git ui/base/ui_base_types.h ui/base/ui_base_types.h
|
||||
index 8bfbd2d675db6..ee90ad2884db7 100644
|
||||
--- ui/base/ui_base_types.h
|
||||
+++ ui/base/ui_base_types.h
|
||||
@@ -26,7 +26,8 @@ enum WindowShowState {
|
||||
SHOW_STATE_MAXIMIZED = 3,
|
||||
SHOW_STATE_INACTIVE = 4, // Views only, not persisted.
|
||||
SHOW_STATE_FULLSCREEN = 5,
|
||||
- SHOW_STATE_END = 6 // The end of show state enum.
|
||||
+ SHOW_STATE_HIDDEN = 6, // Views and MacOS only.
|
||||
+ SHOW_STATE_END = 7 // The end of show state enum.
|
||||
};
|
||||
|
||||
// Specifies which edges of the window are tiled.
|
||||
diff --git ui/ozone/platform/x11/x11_window.cc ui/ozone/platform/x11/x11_window.cc
|
||||
index 449f721727fb1..ab549b482bc36 100644
|
||||
--- ui/ozone/platform/x11/x11_window.cc
|
||||
@ -359,8 +447,20 @@ index e963c861f7099..6bc0ac23db5e9 100644
|
||||
// Visibility of the cursor. On Windows we can have multiple root windows and
|
||||
// the implementation of ::ShowCursor() is based on a counter, so making this
|
||||
// member static ensures that ::ShowCursor() is always called exactly once
|
||||
diff --git ui/views/widget/native_widget_mac.mm ui/views/widget/native_widget_mac.mm
|
||||
index 3a6617aefe420..6eeffcab6bb65 100644
|
||||
--- ui/views/widget/native_widget_mac.mm
|
||||
+++ ui/views/widget/native_widget_mac.mm
|
||||
@@ -640,6 +640,7 @@ void NativeWidgetMac::Show(ui::WindowShowState show_state,
|
||||
break;
|
||||
case ui::SHOW_STATE_MAXIMIZED:
|
||||
case ui::SHOW_STATE_FULLSCREEN:
|
||||
+ case ui::SHOW_STATE_HIDDEN:
|
||||
NOTIMPLEMENTED();
|
||||
break;
|
||||
case ui::SHOW_STATE_END:
|
||||
diff --git ui/views/widget/widget.cc ui/views/widget/widget.cc
|
||||
index 5093dee22b9da..3f29234369599 100644
|
||||
index 5093dee22b9da..df7f86de04259 100644
|
||||
--- ui/views/widget/widget.cc
|
||||
+++ ui/views/widget/widget.cc
|
||||
@@ -399,7 +399,8 @@ void Widget::Init(InitParams params) {
|
||||
@ -373,7 +473,7 @@ index 5093dee22b9da..3f29234369599 100644
|
||||
is_headless_ = params.ShouldInitAsHeadless();
|
||||
|
||||
if (params.opacity == views::Widget::InitParams::WindowOpacity::kInferred &&
|
||||
@@ -497,14 +498,22 @@ void Widget::Init(InitParams params) {
|
||||
@@ -497,14 +498,24 @@ void Widget::Init(InitParams params) {
|
||||
|
||||
if (show_state == ui::SHOW_STATE_MAXIMIZED) {
|
||||
Maximize();
|
||||
@ -383,6 +483,8 @@ index 5093dee22b9da..3f29234369599 100644
|
||||
saved_show_state_ = ui::SHOW_STATE_MINIMIZED;
|
||||
+ } else if (show_state == ui::SHOW_STATE_FULLSCREEN) {
|
||||
+ SetFullscreen(true);
|
||||
+ } else if (show_state == ui::SHOW_STATE_HIDDEN) {
|
||||
+ Hide();
|
||||
}
|
||||
} else if (delegate) {
|
||||
SetContentsView(delegate->TransferOwnershipOfContentsView());
|
||||
@ -397,7 +499,7 @@ index 5093dee22b9da..3f29234369599 100644
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1646,10 +1655,16 @@ void Widget::OnNativeWidgetParentChanged(gfx::NativeView parent) {
|
||||
@@ -1646,10 +1657,16 @@ void Widget::OnNativeWidgetParentChanged(gfx::NativeView parent) {
|
||||
}
|
||||
|
||||
gfx::Size Widget::GetMinimumSize() const {
|
||||
@ -414,6 +516,16 @@ index 5093dee22b9da..3f29234369599 100644
|
||||
return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size();
|
||||
}
|
||||
|
||||
@@ -1900,7 +1917,8 @@ bool Widget::SetInitialFocus(ui::WindowShowState show_state) {
|
||||
return false;
|
||||
View* v = widget_delegate_->GetInitiallyFocusedView();
|
||||
if (!focus_on_creation_ || show_state == ui::SHOW_STATE_INACTIVE ||
|
||||
- show_state == ui::SHOW_STATE_MINIMIZED) {
|
||||
+ show_state == ui::SHOW_STATE_MINIMIZED ||
|
||||
+ show_state == ui::SHOW_STATE_HIDDEN) {
|
||||
// If not focusing the window now, tell the focus manager which view to
|
||||
// focus when the window is restored.
|
||||
if (v)
|
||||
diff --git ui/views/widget/widget.h ui/views/widget/widget.h
|
||||
index 1939476d29da5..895df61324a2e 100644
|
||||
--- ui/views/widget/widget.h
|
||||
|
@ -36,6 +36,10 @@ static struct {
|
||||
{"minimized", CEF_SHOW_STATE_MINIMIZED},
|
||||
{"maximized", CEF_SHOW_STATE_MAXIMIZED},
|
||||
{"fullscreen", CEF_SHOW_STATE_FULLSCREEN},
|
||||
#if defined(OS_MAC)
|
||||
// Hidden show state is only supported on MacOS.
|
||||
{"hidden", CEF_SHOW_STATE_HIDDEN},
|
||||
#endif
|
||||
};
|
||||
|
||||
std::optional<cef_show_state_t> ShowStateFromString(const std::string& str) {
|
||||
|
@ -223,6 +223,12 @@ void RootWindowViews::OnExtensionsChanged(const ExtensionSet& extensions) {
|
||||
|
||||
bool RootWindowViews::InitiallyHidden() {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
#if defined(OS_MAC)
|
||||
// Hidden show state is only supported on MacOS.
|
||||
if (initial_show_state_ == CEF_SHOW_STATE_HIDDEN) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return config_->initially_hidden;
|
||||
}
|
||||
|
||||
|
@ -238,6 +238,13 @@ void ViewsWindow::Close(bool force) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(OS_MAC)
|
||||
if (hide_on_close_) {
|
||||
// Don't hide on close if we actually want to close.
|
||||
hide_on_close_ = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
|
||||
if (browser) {
|
||||
// This will result in a call to CefWindow::Close() which will then call
|
||||
@ -677,6 +684,14 @@ void ViewsWindow::OnWindowFullscreenTransition(CefRefPtr<CefWindow> window,
|
||||
browser->GetHost()->ExitFullscreen(/*will_cause_resize=*/false);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(OS_MAC)
|
||||
// Continue hide logic from CanClose.
|
||||
if (is_completed && hide_after_fullscreen_exit_) {
|
||||
hide_after_fullscreen_exit_ = false;
|
||||
window->Hide();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ViewsWindow::OnWindowCreated(CefRefPtr<CefWindow> window) {
|
||||
@ -790,6 +805,21 @@ void ViewsWindow::OnWindowBoundsChanged(CefRefPtr<CefWindow> window,
|
||||
bool ViewsWindow::CanClose(CefRefPtr<CefWindow> window) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
#if defined(OS_MAC)
|
||||
// On MacOS we might hide the window instead of closing it.
|
||||
if (hide_on_close_) {
|
||||
if (window->IsFullscreen()) {
|
||||
// Need to exit fullscreen mode before hiding the window.
|
||||
// Execution continues in OnWindowFullscreenTransition.
|
||||
hide_after_fullscreen_exit_ = true;
|
||||
window->SetFullscreen(false);
|
||||
} else {
|
||||
window->Hide();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Allow the window to close if the browser says it's OK.
|
||||
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
|
||||
if (browser) {
|
||||
@ -1072,6 +1102,8 @@ ViewsWindow::ViewsWindow(WindowType type,
|
||||
default_titlebar_height_ = kTitleBarHeight;
|
||||
override_titlebar_height_ = kTitleBarHeight;
|
||||
}
|
||||
|
||||
hide_on_close_ = command_line->HasSwitch(switches::kHideWindowOnClose);
|
||||
#endif
|
||||
|
||||
const std::string& toolbar_type =
|
||||
|
@ -283,6 +283,11 @@ class ViewsWindow : public CefBrowserViewDelegate,
|
||||
std::optional<float> default_titlebar_height_;
|
||||
std::optional<float> override_titlebar_height_;
|
||||
|
||||
#if defined(OS_MAC)
|
||||
bool hide_on_close_ = false;
|
||||
bool hide_after_fullscreen_exit_ = false;
|
||||
#endif
|
||||
|
||||
// Structure representing an extension.
|
||||
struct ExtensionInfo {
|
||||
ExtensionInfo(CefRefPtr<CefExtension> extension, CefRefPtr<CefImage> image)
|
||||
|
@ -321,13 +321,16 @@ void RemoveMenuItem(NSMenu* menu, SEL action_selector) {
|
||||
[self testsItemSelected:ID_TESTS_OTHER_TESTS];
|
||||
}
|
||||
|
||||
- (scoped_refptr<client::RootWindow>)getActiveRootWindow {
|
||||
return client::MainContext::Get()
|
||||
->GetRootWindowManager()
|
||||
->GetActiveRootWindow();
|
||||
}
|
||||
|
||||
- (CefRefPtr<CefBrowser>)getActiveBrowser {
|
||||
auto root_window =
|
||||
client::MainContext::Get()->GetRootWindowManager()->GetActiveRootWindow();
|
||||
if (root_window) {
|
||||
if (auto root_window = [self getActiveRootWindow]) {
|
||||
return root_window->GetBrowser();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -504,6 +507,15 @@ void RemoveMenuItem(NSMenu* menu, SEL action_selector) {
|
||||
<< [sender tag];
|
||||
}
|
||||
|
||||
// Called when the user clicks the app dock icon while the application is
|
||||
// already running.
|
||||
- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication
|
||||
hasVisibleWindows:(BOOL)flag {
|
||||
if (auto root_window = [self getActiveRootWindow]) {
|
||||
root_window->Show(client::RootWindow::ShowNormal);
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
@end
|
||||
|
||||
namespace client {
|
||||
@ -580,6 +592,9 @@ int RunMain(int argc, char* argv[]) {
|
||||
// Create the application delegate and window.
|
||||
ClientAppDelegate* delegate = [[ClientAppDelegate alloc]
|
||||
initWithOsr:settings.windowless_rendering_enabled ? true : false];
|
||||
// Set as the delegate for application events.
|
||||
NSApp.delegate = delegate;
|
||||
|
||||
[delegate performSelectorOnMainThread:@selector(createApplication:)
|
||||
withObject:nil
|
||||
waitUntilDone:NO];
|
||||
|
@ -108,6 +108,17 @@
|
||||
(NSApplication*)sender {
|
||||
return NSTerminateNow;
|
||||
}
|
||||
|
||||
// Called when the user clicks the app dock icon while the application is
|
||||
// already running.
|
||||
- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication
|
||||
hasVisibleWindows:(BOOL)flag {
|
||||
SimpleHandler* handler = SimpleHandler::GetInstance();
|
||||
if (handler && !handler->IsClosing()) {
|
||||
handler->ShowMainWindow();
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
@end
|
||||
|
||||
// Entry point function for the browser process.
|
||||
@ -167,7 +178,10 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// Create the application delegate.
|
||||
NSObject* delegate = [[SimpleAppDelegate alloc] init];
|
||||
SimpleAppDelegate* delegate = [[SimpleAppDelegate alloc] init];
|
||||
// Set as the delegate for application events.
|
||||
NSApp.delegate = delegate;
|
||||
|
||||
[delegate performSelectorOnMainThread:@selector(createApplication:)
|
||||
withObject:nil
|
||||
waitUntilDone:NO];
|
||||
|
@ -19,16 +19,23 @@ namespace {
|
||||
// implementation for the CefWindow that hosts the Views-based browser.
|
||||
class SimpleWindowDelegate : public CefWindowDelegate {
|
||||
public:
|
||||
explicit SimpleWindowDelegate(CefRefPtr<CefBrowserView> browser_view)
|
||||
: browser_view_(browser_view) {}
|
||||
SimpleWindowDelegate(CefRefPtr<CefBrowserView> browser_view,
|
||||
cef_show_state_t initial_show_state)
|
||||
: browser_view_(browser_view), initial_show_state_(initial_show_state) {}
|
||||
|
||||
void OnWindowCreated(CefRefPtr<CefWindow> window) override {
|
||||
// Add the browser view and show the window.
|
||||
window->AddChildView(browser_view_);
|
||||
window->Show();
|
||||
|
||||
// Give keyboard focus to the browser view.
|
||||
browser_view_->RequestFocus();
|
||||
if (initial_show_state_ != CEF_SHOW_STATE_HIDDEN) {
|
||||
window->Show();
|
||||
}
|
||||
|
||||
if (initial_show_state_ != CEF_SHOW_STATE_MINIMIZED &&
|
||||
initial_show_state_ != CEF_SHOW_STATE_HIDDEN) {
|
||||
// Give keyboard focus to the browser view.
|
||||
browser_view_->RequestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void OnWindowDestroyed(CefRefPtr<CefWindow> window) override {
|
||||
@ -48,8 +55,13 @@ class SimpleWindowDelegate : public CefWindowDelegate {
|
||||
return CefSize(800, 600);
|
||||
}
|
||||
|
||||
cef_show_state_t GetInitialShowState(CefRefPtr<CefWindow> window) override {
|
||||
return initial_show_state_;
|
||||
}
|
||||
|
||||
private:
|
||||
CefRefPtr<CefBrowserView> browser_view_;
|
||||
const cef_show_state_t initial_show_state_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(SimpleWindowDelegate);
|
||||
DISALLOW_COPY_AND_ASSIGN(SimpleWindowDelegate);
|
||||
@ -65,7 +77,7 @@ class SimpleBrowserViewDelegate : public CefBrowserViewDelegate {
|
||||
// Create a new top-level Window for the popup. It will show itself after
|
||||
// creation.
|
||||
CefWindow::CreateTopLevelWindow(
|
||||
new SimpleWindowDelegate(popup_browser_view));
|
||||
new SimpleWindowDelegate(popup_browser_view, CEF_SHOW_STATE_NORMAL));
|
||||
|
||||
// We created the Window.
|
||||
return true;
|
||||
@ -86,13 +98,8 @@ void SimpleApp::OnContextInitialized() {
|
||||
CefRefPtr<CefCommandLine> command_line =
|
||||
CefCommandLine::GetGlobalCommandLine();
|
||||
|
||||
// Create the browser using the Views framework if "--use-views" is specified
|
||||
// via the command-line. Otherwise, create the browser using the native
|
||||
// platform framework.
|
||||
const bool use_views = command_line->HasSwitch("use-views");
|
||||
|
||||
// SimpleHandler implements browser-level callbacks.
|
||||
CefRefPtr<SimpleHandler> handler(new SimpleHandler(use_views));
|
||||
CefRefPtr<SimpleHandler> handler(new SimpleHandler());
|
||||
|
||||
// Specify CEF browser settings here.
|
||||
CefBrowserSettings browser_settings;
|
||||
@ -106,14 +113,34 @@ void SimpleApp::OnContextInitialized() {
|
||||
url = "http://www.google.com";
|
||||
}
|
||||
|
||||
if (use_views) {
|
||||
// Create the browser using the Views framework if "--use-views" is specified
|
||||
// via the command-line. Otherwise, create the browser using the native
|
||||
// platform framework.
|
||||
if (command_line->HasSwitch("use-views")) {
|
||||
// Create the BrowserView.
|
||||
CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
|
||||
handler, url, browser_settings, nullptr, nullptr,
|
||||
new SimpleBrowserViewDelegate());
|
||||
|
||||
// Optionally configure the initial show state.
|
||||
cef_show_state_t initial_show_state = CEF_SHOW_STATE_NORMAL;
|
||||
const std::string& show_state_value =
|
||||
command_line->GetSwitchValue("initial-show-state");
|
||||
if (show_state_value == "minimized") {
|
||||
initial_show_state = CEF_SHOW_STATE_MINIMIZED;
|
||||
} else if (show_state_value == "maximized") {
|
||||
initial_show_state = CEF_SHOW_STATE_MAXIMIZED;
|
||||
}
|
||||
#if defined(OS_MAC)
|
||||
// Hidden show state is only supported on MacOS.
|
||||
else if (show_state_value == "hidden") {
|
||||
initial_show_state = CEF_SHOW_STATE_HIDDEN;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create the Window. It will show itself after creation.
|
||||
CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browser_view));
|
||||
CefWindow::CreateTopLevelWindow(
|
||||
new SimpleWindowDelegate(browser_view, initial_show_state));
|
||||
} else {
|
||||
// Information used when creating the native window.
|
||||
CefWindowInfo window_info;
|
||||
|
@ -28,7 +28,7 @@ std::string GetDataURI(const std::string& data, const std::string& mime_type) {
|
||||
|
||||
} // namespace
|
||||
|
||||
SimpleHandler::SimpleHandler(bool use_views) : use_views_(use_views) {
|
||||
SimpleHandler::SimpleHandler() {
|
||||
DCHECK(!g_instance);
|
||||
g_instance = this;
|
||||
}
|
||||
@ -46,15 +46,11 @@ void SimpleHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
if (use_views_) {
|
||||
if (auto browser_view = CefBrowserView::GetForBrowser(browser)) {
|
||||
// Set the title of the window using the Views framework.
|
||||
CefRefPtr<CefBrowserView> browser_view =
|
||||
CefBrowserView::GetForBrowser(browser);
|
||||
if (browser_view) {
|
||||
CefRefPtr<CefWindow> window = browser_view->GetWindow();
|
||||
if (window) {
|
||||
window->SetTitle(title);
|
||||
}
|
||||
CefRefPtr<CefWindow> window = browser_view->GetWindow();
|
||||
if (window) {
|
||||
window->SetTitle(title);
|
||||
}
|
||||
} else if (!IsChromeRuntimeEnabled()) {
|
||||
// Set the title of the window using platform APIs.
|
||||
@ -130,6 +126,29 @@ void SimpleHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
|
||||
frame->LoadURL(GetDataURI(ss.str(), "text/html"));
|
||||
}
|
||||
|
||||
void SimpleHandler::ShowMainWindow() {
|
||||
if (!CefCurrentlyOn(TID_UI)) {
|
||||
// Execute on the UI thread.
|
||||
CefPostTask(TID_UI, base::BindOnce(&SimpleHandler::ShowMainWindow, this));
|
||||
return;
|
||||
}
|
||||
|
||||
if (browser_list_.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto main_browser = browser_list_.front();
|
||||
|
||||
if (auto browser_view = CefBrowserView::GetForBrowser(main_browser)) {
|
||||
// Show the window using the Views framework.
|
||||
if (auto window = browser_view->GetWindow()) {
|
||||
window->Show();
|
||||
}
|
||||
} else if (!IsChromeRuntimeEnabled()) {
|
||||
PlatformShowWindow(main_browser);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleHandler::CloseAllBrowsers(bool force_close) {
|
||||
if (!CefCurrentlyOn(TID_UI)) {
|
||||
// Execute on the UI thread.
|
||||
@ -156,3 +175,9 @@ bool SimpleHandler::IsChromeRuntimeEnabled() {
|
||||
}();
|
||||
return enabled;
|
||||
}
|
||||
|
||||
#if !defined(OS_MAC)
|
||||
void SimpleHandler::PlatformShowWindow(CefRefPtr<CefBrowser> browser) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
#endif
|
||||
|
@ -14,7 +14,7 @@ class SimpleHandler : public CefClient,
|
||||
public CefLifeSpanHandler,
|
||||
public CefLoadHandler {
|
||||
public:
|
||||
explicit SimpleHandler(bool use_views);
|
||||
SimpleHandler();
|
||||
~SimpleHandler() override;
|
||||
|
||||
// Provide access to the single global instance of this object.
|
||||
@ -41,6 +41,8 @@ class SimpleHandler : public CefClient,
|
||||
const CefString& errorText,
|
||||
const CefString& failedUrl) override;
|
||||
|
||||
void ShowMainWindow();
|
||||
|
||||
// Request that all existing browser windows close.
|
||||
void CloseAllBrowsers(bool force_close);
|
||||
|
||||
@ -53,9 +55,7 @@ class SimpleHandler : public CefClient,
|
||||
// Platform-specific implementation.
|
||||
void PlatformTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title);
|
||||
|
||||
// True if the application is using the Views framework.
|
||||
const bool use_views_;
|
||||
void PlatformShowWindow(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
// List of existing browser windows. Only accessed on the CEF UI thread.
|
||||
typedef std::list<CefRefPtr<CefBrowser>> BrowserList;
|
||||
|
@ -8,12 +8,25 @@
|
||||
|
||||
#include "include/cef_browser.h"
|
||||
|
||||
void SimpleHandler::PlatformTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) {
|
||||
namespace {
|
||||
|
||||
NSWindow* GetNSWindowForBrowser(CefRefPtr<CefBrowser> browser) {
|
||||
NSView* view =
|
||||
CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(browser->GetHost()->GetWindowHandle());
|
||||
NSWindow* window = [view window];
|
||||
return [view window];
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void SimpleHandler::PlatformTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) {
|
||||
NSWindow* window = GetNSWindowForBrowser(browser);
|
||||
std::string titleStr(title);
|
||||
NSString* str = [NSString stringWithUTF8String:titleStr.c_str()];
|
||||
[window setTitle:str];
|
||||
}
|
||||
|
||||
void SimpleHandler::PlatformShowWindow(CefRefPtr<CefBrowser> browser) {
|
||||
NSWindow* window = GetNSWindowForBrowser(browser);
|
||||
[window makeKeyAndOrderFront:window];
|
||||
}
|
||||
|
@ -116,6 +116,8 @@ void RunWindowShow(cef_show_state_t initial_show_state,
|
||||
EXPECT_FALSE(window->IsMinimized());
|
||||
EXPECT_TRUE(window->IsFullscreen());
|
||||
break;
|
||||
case CEF_SHOW_STATE_HIDDEN:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,5 +56,6 @@ const char kUseWindowModalDialog[] = "use-window-modal-dialog";
|
||||
const char kUseBottomControls[] = "use-bottom-controls";
|
||||
const char kHidePipFrame[] = "hide-pip-frame";
|
||||
const char kHideChromeBubbles[] = "hide-chrome-bubbles";
|
||||
const char kHideWindowOnClose[] = "hide-window-on-close";
|
||||
|
||||
} // namespace client::switches
|
||||
|
@ -50,6 +50,7 @@ extern const char kUseWindowModalDialog[];
|
||||
extern const char kUseBottomControls[];
|
||||
extern const char kHidePipFrame[];
|
||||
extern const char kHideChromeBubbles[];
|
||||
extern const char kHideWindowOnClose[];
|
||||
|
||||
} // namespace client::switches
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user