From f53aabaef57ab29f28a9ee7ce8eae76f1b7bd278 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 17 May 2016 15:48:14 +0900 Subject: [PATCH] Implement titleBarStyle without using NSFullSizeContentViewWindowMask --- atom/browser/native_window.cc | 3 +-- atom/browser/native_window.h | 12 ++---------- atom/browser/native_window_mac.h | 4 ++++ atom/browser/native_window_mac.mm | 25 ++++++++++++------------- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index a5abc56f898c..0d5c26c560d1 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -49,7 +49,6 @@ NativeWindow::NativeWindow( const mate::Dictionary& options) : content::WebContentsObserver(inspectable_web_contents->GetWebContents()), has_frame_(true), - force_using_draggable_region_(false), transparent_(false), enable_larger_than_screen_(false), is_closed_(false), @@ -573,7 +572,7 @@ bool NativeWindow::OnMessageReceived(const IPC::Message& message) { void NativeWindow::UpdateDraggableRegions( const std::vector& regions) { // Draggable region is not supported for non-frameless window. - if (has_frame_ && !force_using_draggable_region_) + if (has_frame_) return; draggable_region_ = DraggableRegionsToSkRegion(regions); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index f3acf6222314..7317a7ba6f76 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -246,18 +246,13 @@ class NativeWindow : public base::SupportsUserData, } bool has_frame() const { return has_frame_; } + void set_has_frame(bool has_frame) { has_frame_ = has_frame; } + bool transparent() const { return transparent_; } SkRegion* draggable_region() const { return draggable_region_.get(); } bool enable_larger_than_screen() const { return enable_larger_than_screen_; } gfx::ImageSkia icon() const { return icon_; } - bool force_using_draggable_region() const { - return force_using_draggable_region_; - } - void set_force_using_draggable_region(bool force) { - force_using_draggable_region_ = true; - } - void set_has_dialog_attached(bool has_dialog_attached) { has_dialog_attached_ = has_dialog_attached; } @@ -299,9 +294,6 @@ class NativeWindow : public base::SupportsUserData, // Whether window has standard frame. bool has_frame_; - // Force the window to be aware of draggable regions. - bool force_using_draggable_region_; - // Whether window is transparent. bool transparent_; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 93d03e4c157c..5ad4f39e722f 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -142,6 +142,10 @@ class NativeWindowMac : public NativeWindow { // The presentation options before entering kiosk mode. NSApplicationPresentationOptions kiosk_options_; + // Force showing the buttons for frameless window. + bool force_show_buttons_; + + // Whether to hide the native toolbar under fullscreen mode. bool should_hide_native_toolbar_in_fullscreen_; DISALLOW_COPY_AND_ASSIGN(NativeWindowMac); diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 04569d8f50f9..4a646a9eb931 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -391,6 +391,7 @@ NativeWindowMac::NativeWindowMac( : NativeWindow(web_contents, options), is_kiosk_(false), attention_request_id_(0), + force_show_buttons_(false), should_hide_native_toolbar_in_fullscreen_(false) { int width = 800, height = 600; options.Get(options::kWidth, &width); @@ -438,22 +439,17 @@ NativeWindowMac::NativeWindowMac( if (closable) { styleMask |= NSClosableWindowMask; } + if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) { + // The window without titlebar is treated the same with frameless window. + set_has_frame(false); + force_show_buttons_ = true; + } if (!useStandardWindow || transparent() || !has_frame()) { styleMask |= NSTexturedBackgroundWindowMask; } if (resizable) { styleMask |= NSResizableWindowMask; } - if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) { - styleMask |= NSFullSizeContentViewWindowMask; - styleMask |= NSUnifiedTitleAndToolbarWindowMask; - } - // We capture this because we need to access the option later when - // entering/exiting fullscreen and since the options dict is only passed to - // the constructor but not stored, let’s store this option this way. - if (titleBarStyle == "hidden-inset") { - should_hide_native_toolbar_in_fullscreen_ = true; - } window_.reset([[AtomNSWindow alloc] initWithContentRect:cocoa_bounds @@ -498,9 +494,8 @@ NativeWindowMac::NativeWindowMac( [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); [toolbar setShowsBaselineSeparator:NO]; [window_ setToolbar:toolbar]; + should_hide_native_toolbar_in_fullscreen_ = true; } - // We should be aware of draggable regions when using hidden titlebar. - set_force_using_draggable_region(true); } // On OS X the initial window size doesn't include window frame. @@ -1013,6 +1008,10 @@ void NativeWindowMac::InstallView() { [view setFrame:[content_view_ bounds]]; [content_view_ addSubview:view]; + if (force_show_buttons_) + return; + + // Hide the window buttons. [[window_ standardWindowButton:NSWindowZoomButton] setHidden:YES]; [[window_ standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; [[window_ standardWindowButton:NSWindowCloseButton] setHidden:YES]; @@ -1031,7 +1030,7 @@ void NativeWindowMac::UninstallView() { void NativeWindowMac::UpdateDraggableRegionViews( const std::vector& regions) { - if (has_frame() && !force_using_draggable_region()) + if (has_frame()) return; // All ControlRegionViews should be added as children of the WebContentsView,