From f53aabaef57ab29f28a9ee7ce8eae76f1b7bd278 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 17 May 2016 15:48:14 +0900 Subject: [PATCH 1/2] 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 a5abc56f898..0d5c26c560d 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 f3acf622231..7317a7ba6f7 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 93d03e4c157..5ad4f39e722 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 04569d8f50f..4a646a9eb93 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, From 13bfb099a2d23c302d43e26829a8fbf7a571dc2d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 17 May 2016 16:19:28 +0900 Subject: [PATCH 2/2] Fix the toolbar showing when titleBarStyle is hidden-inset --- atom/browser/native_window_mac.h | 8 ++++---- atom/browser/native_window_mac.mm | 14 +++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 5ad4f39e722..22390f42dd0 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -91,6 +91,10 @@ class NativeWindowMac : public NativeWindow { UpdateDraggableRegionViews(draggable_regions_); } + // Set the attribute of NSWindow while work around a bug of zoom button. + void SetStyleMask(bool on, NSUInteger flag); + void SetCollectionBehavior(bool on, NSUInteger flag); + bool should_hide_native_toolbar_in_fullscreen() const { return should_hide_native_toolbar_in_fullscreen_; } @@ -120,10 +124,6 @@ class NativeWindowMac : public NativeWindow { // whehter we can drag. void UpdateDraggableRegionViews(const std::vector& regions); - // Set the attribute of NSWindow while work around a bug of zo0m button. - void SetStyleMask(bool on, NSUInteger flag); - void SetCollectionBehavior(bool on, NSUInteger flag); - base::scoped_nsobject window_; base::scoped_nsobject window_delegate_; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 4a646a9eb93..0f782d58516 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -214,10 +214,22 @@ bool ScopedDisableResize::disable_resize_ = false; [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); [toolbar setShowsBaselineSeparator:NO]; [window setToolbar:toolbar]; + + // Set window style to hide the toolbar, otherwise the toolbar will show in + // fullscreen mode. + shell_->SetStyleMask(true, NSFullSizeContentViewWindowMask); } } +- (void)windowWillExitFullScreen:(NSNotification*)notification { + // Turn off the style for toolbar. + if (shell_->should_hide_native_toolbar_in_fullscreen()) + shell_->SetStyleMask(false, NSFullSizeContentViewWindowMask); +} + - (void)windowDidExitFullScreen:(NSNotification*)notification { + // For certain versions of OS X the fullscreen button will automatically show + // after exiting fullscreen mode. if (!shell_->has_frame()) { NSWindow* window = shell_->GetNativeWindow(); [[window standardWindowButton:NSWindowFullScreenButton] setHidden:YES]; @@ -486,7 +498,7 @@ NativeWindowMac::NativeWindowMac( [window_ setReleasedWhenClosed:NO]; // Hide the title bar. - if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) { + if (titleBarStyle == "hidden-inset") { [window_ setTitlebarAppearsTransparent:YES]; [window_ setTitleVisibility:NSWindowTitleHidden]; if (titleBarStyle == "hidden-inset") {