Merge pull request #13336 from trop-bot/3-0-x-bp-revert-"fix--drop-support-for-os-x-mavericks-(version-10.9)"-1529497748886

Backport (3-0-x) - Revert "fix: Drop support for OS X Mavericks (version 10.9)"
This commit is contained in:
John Kleinschmidt 2018-06-20 09:07:46 -04:00 committed by GitHub
commit cdbd4792e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 290 additions and 156 deletions

View file

@ -147,9 +147,13 @@ void Browser::SetUserActivity(const std::string& type,
} }
std::string Browser::GetCurrentActivityType() { std::string Browser::GetCurrentActivityType() {
NSUserActivity* userActivity = if (@available(macOS 10.10, *)) {
[[AtomApplication sharedApplication] getCurrentActivity]; NSUserActivity* userActivity =
return base::SysNSStringToUTF8(userActivity.activityType); [[AtomApplication sharedApplication] getCurrentActivity];
return base::SysNSStringToUTF8(userActivity.activityType);
} else {
return std::string();
}
} }
void Browser::InvalidateCurrentActivity() { void Browser::InvalidateCurrentActivity() {

View file

@ -11,7 +11,7 @@
NSUserActivityDelegate> { NSUserActivityDelegate> {
@private @private
BOOL handlingSendEvent_; BOOL handlingSendEvent_;
base::scoped_nsobject<NSUserActivity> currentActivity_; base::scoped_nsobject<NSUserActivity> currentActivity_ API_AVAILABLE(macosx(10.10));
NSCondition* handoffLock_; NSCondition* handoffLock_;
BOOL updateReceived_; BOOL updateReceived_;
base::Callback<bool()> shouldShutdown_; base::Callback<bool()> shouldShutdown_;
@ -27,7 +27,7 @@
// CrAppControlProtocol: // CrAppControlProtocol:
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent; - (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
- (NSUserActivity*)getCurrentActivity; - (NSUserActivity*)getCurrentActivity API_AVAILABLE(macosx(10.10));
- (void)setCurrentActivity:(NSString*)type - (void)setCurrentActivity:(NSString*)type
withUserInfo:(NSDictionary*)userInfo withUserInfo:(NSDictionary*)userInfo
withWebpageURL:(NSURL*)webpageURL; withWebpageURL:(NSURL*)webpageURL;

View file

@ -58,13 +58,15 @@ inline void dispatch_sync_main(dispatch_block_t block) {
- (void)setCurrentActivity:(NSString*)type - (void)setCurrentActivity:(NSString*)type
withUserInfo:(NSDictionary*)userInfo withUserInfo:(NSDictionary*)userInfo
withWebpageURL:(NSURL*)webpageURL { withWebpageURL:(NSURL*)webpageURL {
currentActivity_ = base::scoped_nsobject<NSUserActivity>( if (@available(macOS 10.10, *)) {
[[NSUserActivity alloc] initWithActivityType:type]); currentActivity_ = base::scoped_nsobject<NSUserActivity>(
[currentActivity_ setUserInfo:userInfo]; [[NSUserActivity alloc] initWithActivityType:type]);
[currentActivity_ setWebpageURL:webpageURL]; [currentActivity_ setUserInfo:userInfo];
[currentActivity_ setDelegate:self]; [currentActivity_ setWebpageURL:webpageURL];
[currentActivity_ becomeCurrent]; [currentActivity_ setDelegate:self];
[currentActivity_ setNeedsSave:YES]; [currentActivity_ becomeCurrent];
[currentActivity_ setNeedsSave:YES];
}
} }
- (NSUserActivity*)getCurrentActivity { - (NSUserActivity*)getCurrentActivity {
@ -90,7 +92,8 @@ inline void dispatch_sync_main(dispatch_block_t block) {
[handoffLock_ unlock]; [handoffLock_ unlock];
} }
- (void)userActivityWillSave:(NSUserActivity*)userActivity { - (void)userActivityWillSave:(NSUserActivity*)userActivity
API_AVAILABLE(macosx(10.10)) {
__block BOOL shouldWait = NO; __block BOOL shouldWait = NO;
dispatch_sync_main(^{ dispatch_sync_main(^{
std::string activity_type( std::string activity_type(
@ -118,7 +121,8 @@ inline void dispatch_sync_main(dispatch_block_t block) {
[userActivity setNeedsSave:YES]; [userActivity setNeedsSave:YES];
} }
- (void)userActivityWasContinued:(NSUserActivity*)userActivity { - (void)userActivityWasContinued:(NSUserActivity*)userActivity
API_AVAILABLE(macosx(10.10)) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
std::string activity_type( std::string activity_type(
base::SysNSStringToUTF8(userActivity.activityType)); base::SysNSStringToUTF8(userActivity.activityType));

View file

@ -98,7 +98,8 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
- (BOOL)application:(NSApplication*)sender - (BOOL)application:(NSApplication*)sender
continueUserActivity:(NSUserActivity*)userActivity continueUserActivity:(NSUserActivity*)userActivity
restorationHandler: restorationHandler:
(void (^)(NSArray* restorableObjects))restorationHandler { (void (^)(NSArray* restorableObjects))restorationHandler
API_AVAILABLE(macosx(10.10)) {
std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType)); std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType));
std::unique_ptr<base::DictionaryValue> user_info = std::unique_ptr<base::DictionaryValue> user_info =
atom::NSDictionaryToDictionaryValue(userActivity.userInfo); atom::NSDictionaryToDictionaryValue(userActivity.userInfo);

View file

@ -153,6 +153,8 @@ class NativeWindowMac : public NativeWindow {
private: private:
void InternalSetParentWindow(NativeWindow* parent, bool attach); void InternalSetParentWindow(NativeWindow* parent, bool attach);
void ShowWindowButton(NSWindowButton button);
void SetForwardMouseMessages(bool forward); void SetForwardMouseMessages(bool forward);
AtomNSWindow* window_; // Weak ref, managed by widget_. AtomNSWindow* window_; // Weak ref, managed by widget_.

View file

@ -295,9 +295,11 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
} }
NSUInteger styleMask = NSTitledWindowMask; NSUInteger styleMask = NSTitledWindowMask;
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER && if (@available(macOS 10.10, *)) {
(!useStandardWindow || transparent() || !has_frame())) { if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER &&
styleMask = NSFullSizeContentViewWindowMask; (!useStandardWindow || transparent() || !has_frame())) {
styleMask = NSFullSizeContentViewWindowMask;
}
} }
if (minimizable) { if (minimizable) {
styleMask |= NSMiniaturizableWindowMask; styleMask |= NSMiniaturizableWindowMask;
@ -352,10 +354,11 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
[window_ setDisableKeyOrMainWindow:YES]; [window_ setDisableKeyOrMainWindow:YES];
if (transparent() || !has_frame()) { if (transparent() || !has_frame()) {
// Don't show title bar. if (@available(macOS 10.10, *)) {
[window_ setTitlebarAppearsTransparent:YES]; // Don't show title bar.
[window_ setTitleVisibility:NSWindowTitleHidden]; [window_ setTitlebarAppearsTransparent:YES];
[window_ setTitleVisibility:NSWindowTitleHidden];
}
// Remove non-transparent corners, see http://git.io/vfonD. // Remove non-transparent corners, see http://git.io/vfonD.
[window_ setOpaque:NO]; [window_ setOpaque:NO];
} }
@ -374,15 +377,22 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
// Hide the title bar background // Hide the title bar background
if (title_bar_style_ != NORMAL) { if (title_bar_style_ != NORMAL) {
[window_ setTitlebarAppearsTransparent:YES]; if (@available(macOS 10.10, *)) {
[window_ setTitlebarAppearsTransparent:YES];
}
} }
// Hide the title bar. // Hide the title bar.
if (title_bar_style_ == HIDDEN_INSET) { if (title_bar_style_ == HIDDEN_INSET) {
base::scoped_nsobject<NSToolbar> toolbar( if (@available(macOS 10.10, *)) {
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); base::scoped_nsobject<NSToolbar> toolbar(
[toolbar setShowsBaselineSeparator:NO]; [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
[window_ setToolbar:toolbar]; [toolbar setShowsBaselineSeparator:NO];
[window_ setToolbar:toolbar];
} else {
[window_ enableWindowButtonsOffset];
[window_ setWindowButtonsOffset:NSMakePoint(12, 10)];
}
} }
// Resize to content bounds. // Resize to content bounds.
@ -435,8 +445,9 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
SetContentView(new views::View()); SetContentView(new views::View());
// Make sure the bottom corner is rounded for non-modal windows: // Make sure the bottom corner is rounded for non-modal windows:
// http://crbug.com/396264. // http://crbug.com/396264. But do not enable it on OS X 10.9 for transparent
if (!is_modal()) { // window, otherwise a semi-transparent frame would show.
if (!(transparent() && base::mac::IsOS10_9()) && !is_modal()) {
base::scoped_nsobject<CALayer> background_layer([[CALayer alloc] init]); base::scoped_nsobject<CALayer> background_layer([[CALayer alloc] init]);
[background_layer [background_layer
setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable]; setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
@ -468,6 +479,11 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
[[window_ contentView] addSubview:buttons_view_]; [[window_ contentView] addSubview:buttons_view_];
} else { } else {
if (title_bar_style_ != NORMAL) { if (title_bar_style_ != NORMAL) {
if (base::mac::IsOS10_9()) {
ShowWindowButton(NSWindowZoomButton);
ShowWindowButton(NSWindowMiniaturizeButton);
ShowWindowButton(NSWindowCloseButton);
}
return; return;
} }
@ -842,11 +858,17 @@ void NativeWindowMac::Invalidate() {
} }
void NativeWindowMac::SetTitle(const std::string& title) { void NativeWindowMac::SetTitle(const std::string& title) {
// For macOS <= 10.9, the setTitleVisibility API is not available, we have
// to avoid calling setTitle for frameless window.
if (!base::mac::IsAtLeastOS10_10() && (transparent() || !has_frame()))
return;
[window_ setTitle:base::SysUTF8ToNSString(title)]; [window_ setTitle:base::SysUTF8ToNSString(title)];
} }
std::string NativeWindowMac::GetTitle() { std::string NativeWindowMac::GetTitle() {
return base::SysNSStringToUTF8([window_ title]); return base::SysNSStringToUTF8([window_ title]);
;
} }
void NativeWindowMac::FlashFrame(bool flash) { void NativeWindowMac::FlashFrame(bool flash) {
@ -1156,83 +1178,86 @@ bool NativeWindowMac::AddTabbedWindow(NativeWindow* window) {
} }
void NativeWindowMac::SetVibrancy(const std::string& type) { void NativeWindowMac::SetVibrancy(const std::string& type) {
NSView* vibrant_view = [window_ vibrantView]; if (@available(macOS 10.10, *)) {
NSView* vibrant_view = [window_ vibrantView];
if (type.empty()) {
if (background_color_before_vibrancy_) {
[window_ setBackgroundColor:background_color_before_vibrancy_];
[window_ setTitlebarAppearsTransparent:transparency_before_vibrancy_];
}
if (vibrant_view == nil)
return;
[vibrant_view removeFromSuperview];
[window_ setVibrantView:nil];
ui::GpuSwitchingManager::SetTransparent(transparent());
if (type.empty()) {
if (background_color_before_vibrancy_) {
[window_ setBackgroundColor:background_color_before_vibrancy_];
[window_ setTitlebarAppearsTransparent:transparency_before_vibrancy_];
}
if (vibrant_view == nil)
return; return;
[vibrant_view removeFromSuperview];
[window_ setVibrantView:nil];
ui::GpuSwitchingManager::SetTransparent(transparent());
return;
}
background_color_before_vibrancy_.reset([[window_ backgroundColor] retain]);
transparency_before_vibrancy_ = [window_ titlebarAppearsTransparent];
ui::GpuSwitchingManager::SetTransparent(true);
if (title_bar_style_ != NORMAL) {
[window_ setTitlebarAppearsTransparent:YES];
[window_ setBackgroundColor:[NSColor clearColor]];
}
NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view;
if (effect_view == nil) {
effect_view = [[[NSVisualEffectView alloc]
initWithFrame:[[window_ contentView] bounds]] autorelease];
[window_ setVibrantView:(NSView*)effect_view];
[effect_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
[effect_view setState:NSVisualEffectStateActive];
[[window_ contentView] addSubview:effect_view
positioned:NSWindowBelow
relativeTo:nil];
}
NSVisualEffectMaterial vibrancyType = NSVisualEffectMaterialLight;
if (type == "appearance-based") {
vibrancyType = NSVisualEffectMaterialAppearanceBased;
} else if (type == "light") {
vibrancyType = NSVisualEffectMaterialLight;
} else if (type == "dark") {
vibrancyType = NSVisualEffectMaterialDark;
} else if (type == "titlebar") {
vibrancyType = NSVisualEffectMaterialTitlebar;
}
if (@available(macOS 10.11, *)) {
// TODO(kevinsawicki): Use NSVisualEffectMaterial* constants directly once
// they are available in the minimum SDK version
if (type == "selection") {
// NSVisualEffectMaterialSelection
vibrancyType = static_cast<NSVisualEffectMaterial>(4);
} else if (type == "menu") {
// NSVisualEffectMaterialMenu
vibrancyType = static_cast<NSVisualEffectMaterial>(5);
} else if (type == "popover") {
// NSVisualEffectMaterialPopover
vibrancyType = static_cast<NSVisualEffectMaterial>(6);
} else if (type == "sidebar") {
// NSVisualEffectMaterialSidebar
vibrancyType = static_cast<NSVisualEffectMaterial>(7);
} else if (type == "medium-light") {
// NSVisualEffectMaterialMediumLight
vibrancyType = static_cast<NSVisualEffectMaterial>(8);
} else if (type == "ultra-dark") {
// NSVisualEffectMaterialUltraDark
vibrancyType = static_cast<NSVisualEffectMaterial>(9);
} }
}
[effect_view setMaterial:vibrancyType]; background_color_before_vibrancy_.reset([[window_ backgroundColor] retain]);
transparency_before_vibrancy_ = [window_ titlebarAppearsTransparent];
ui::GpuSwitchingManager::SetTransparent(true);
if (title_bar_style_ != NORMAL) {
[window_ setTitlebarAppearsTransparent:YES];
[window_ setBackgroundColor:[NSColor clearColor]];
}
NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view;
if (effect_view == nil) {
effect_view = [[[NSVisualEffectView alloc]
initWithFrame:[[window_ contentView] bounds]] autorelease];
[window_ setVibrantView:(NSView*)effect_view];
[effect_view
setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
[effect_view setState:NSVisualEffectStateActive];
[[window_ contentView] addSubview:effect_view
positioned:NSWindowBelow
relativeTo:nil];
}
NSVisualEffectMaterial vibrancyType = NSVisualEffectMaterialLight;
if (type == "appearance-based") {
vibrancyType = NSVisualEffectMaterialAppearanceBased;
} else if (type == "light") {
vibrancyType = NSVisualEffectMaterialLight;
} else if (type == "dark") {
vibrancyType = NSVisualEffectMaterialDark;
} else if (type == "titlebar") {
vibrancyType = NSVisualEffectMaterialTitlebar;
}
if (@available(macOS 10.11, *)) {
// TODO(kevinsawicki): Use NSVisualEffectMaterial* constants directly once
// they are available in the minimum SDK version
if (type == "selection") {
// NSVisualEffectMaterialSelection
vibrancyType = static_cast<NSVisualEffectMaterial>(4);
} else if (type == "menu") {
// NSVisualEffectMaterialMenu
vibrancyType = static_cast<NSVisualEffectMaterial>(5);
} else if (type == "popover") {
// NSVisualEffectMaterialPopover
vibrancyType = static_cast<NSVisualEffectMaterial>(6);
} else if (type == "sidebar") {
// NSVisualEffectMaterialSidebar
vibrancyType = static_cast<NSVisualEffectMaterial>(7);
} else if (type == "medium-light") {
// NSVisualEffectMaterialMediumLight
vibrancyType = static_cast<NSVisualEffectMaterial>(8);
} else if (type == "ultra-dark") {
// NSVisualEffectMaterialUltraDark
vibrancyType = static_cast<NSVisualEffectMaterial>(9);
}
}
[effect_view setMaterial:vibrancyType];
}
} }
void NativeWindowMac::SetTouchBar( void NativeWindowMac::SetTouchBar(
@ -1316,6 +1341,11 @@ void NativeWindowMac::InternalSetParentWindow(NativeWindow* parent,
[parent->GetNativeWindow() addChildWindow:window_ ordered:NSWindowAbove]; [parent->GetNativeWindow() addChildWindow:window_ ordered:NSWindowAbove];
} }
void NativeWindowMac::ShowWindowButton(NSWindowButton button) {
auto view = [window_ standardWindowButton:button];
[view.superview addSubview:view positioned:NSWindowAbove relativeTo:nil];
}
void NativeWindowMac::SetForwardMouseMessages(bool forward) { void NativeWindowMac::SetForwardMouseMessages(bool forward) {
[window_ setAcceptsMouseMovedEvents:forward]; [window_ setAcceptsMouseMovedEvents:forward];
} }

View file

@ -29,16 +29,19 @@ class ScopedDisableResize {
@interface AtomNSWindow : NativeWidgetMacNSWindow { @interface AtomNSWindow : NativeWidgetMacNSWindow {
@private @private
atom::NativeWindowMac* shell_; atom::NativeWindowMac* shell_;
CGFloat windowButtonsInterButtonSpacing_;
} }
@property BOOL acceptsFirstMouse; @property BOOL acceptsFirstMouse;
@property BOOL enableLargerThanScreen; @property BOOL enableLargerThanScreen;
@property BOOL disableAutoHideCursor; @property BOOL disableAutoHideCursor;
@property BOOL disableKeyOrMainWindow; @property BOOL disableKeyOrMainWindow;
@property NSPoint windowButtonsOffset;
@property(nonatomic, retain) NSView* vibrantView; @property(nonatomic, retain) NSView* vibrantView;
- (id)initWithShell:(atom::NativeWindowMac*)shell - (id)initWithShell:(atom::NativeWindowMac*)shell
styleMask:(NSUInteger)styleMask; styleMask:(NSUInteger)styleMask;
- (atom::NativeWindowMac*)shell; - (atom::NativeWindowMac*)shell;
- (NSRect)originalContentRectForFrameRect:(NSRect)frameRect; - (NSRect)originalContentRectForFrameRect:(NSRect)frameRect;
- (void)enableWindowButtonsOffset;
- (void)toggleFullScreenMode:(id)sender; - (void)toggleFullScreenMode:(id)sender;
@end @end

View file

@ -21,6 +21,7 @@ bool ScopedDisableResize::disable_resize_ = false;
@synthesize enableLargerThanScreen; @synthesize enableLargerThanScreen;
@synthesize disableAutoHideCursor; @synthesize disableAutoHideCursor;
@synthesize disableKeyOrMainWindow; @synthesize disableKeyOrMainWindow;
@synthesize windowButtonsOffset;
@synthesize vibrantView; @synthesize vibrantView;
- (id)initWithShell:(atom::NativeWindowMac*)shell - (id)initWithShell:(atom::NativeWindowMac*)shell
@ -116,6 +117,78 @@ bool ScopedDisableResize::disable_resize_ = false;
return !self.disableKeyOrMainWindow; return !self.disableKeyOrMainWindow;
} }
- (void)enableWindowButtonsOffset {
auto closeButton = [self standardWindowButton:NSWindowCloseButton];
auto miniaturizeButton =
[self standardWindowButton:NSWindowMiniaturizeButton];
auto zoomButton = [self standardWindowButton:NSWindowZoomButton];
[closeButton setPostsFrameChangedNotifications:YES];
[miniaturizeButton setPostsFrameChangedNotifications:YES];
[zoomButton setPostsFrameChangedNotifications:YES];
windowButtonsInterButtonSpacing_ =
NSMinX([miniaturizeButton frame]) - NSMaxX([closeButton frame]);
auto center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(adjustCloseButton:)
name:NSViewFrameDidChangeNotification
object:closeButton];
[center addObserver:self
selector:@selector(adjustMiniaturizeButton:)
name:NSViewFrameDidChangeNotification
object:miniaturizeButton];
[center addObserver:self
selector:@selector(adjustZoomButton:)
name:NSViewFrameDidChangeNotification
object:zoomButton];
}
- (void)adjustCloseButton:(NSNotification*)notification {
[self adjustButton:[notification object] ofKind:NSWindowCloseButton];
}
- (void)adjustMiniaturizeButton:(NSNotification*)notification {
[self adjustButton:[notification object] ofKind:NSWindowMiniaturizeButton];
}
- (void)adjustZoomButton:(NSNotification*)notification {
[self adjustButton:[notification object] ofKind:NSWindowZoomButton];
}
- (void)adjustButton:(NSButton*)button ofKind:(NSWindowButton)kind {
NSRect buttonFrame = [button frame];
NSRect frameViewBounds = [[self frameView] bounds];
NSPoint offset = self.windowButtonsOffset;
buttonFrame.origin = NSMakePoint(
offset.x, (NSHeight(frameViewBounds) - NSHeight(buttonFrame) - offset.y));
switch (kind) {
case NSWindowZoomButton:
buttonFrame.origin.x += NSWidth(
[[self standardWindowButton:NSWindowMiniaturizeButton] frame]);
buttonFrame.origin.x += windowButtonsInterButtonSpacing_;
// fallthrough
case NSWindowMiniaturizeButton:
buttonFrame.origin.x +=
NSWidth([[self standardWindowButton:NSWindowCloseButton] frame]);
buttonFrame.origin.x += windowButtonsInterButtonSpacing_;
// fallthrough
default:
break;
}
BOOL didPost = [button postsBoundsChangedNotifications];
[button setPostsFrameChangedNotifications:NO];
[button setFrame:buttonFrame];
[button setPostsFrameChangedNotifications:didPost];
}
- (NSView*)frameView { - (NSView*)frameView {
return [[self contentView] superview]; return [[self contentView] superview];
} }

View file

@ -168,54 +168,60 @@
shell_->SetResizable(true); shell_->SetResizable(true);
// Hide the native toolbar before entering fullscreen, so there is no visual // Hide the native toolbar before entering fullscreen, so there is no visual
// artifacts. // artifacts.
if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { if (@available(macOS 10.10, *)) {
NSWindow* window = shell_->GetNativeWindow(); if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) {
[window setToolbar:nil]; NSWindow* window = shell_->GetNativeWindow();
[window setToolbar:nil];
}
} }
} }
- (void)windowDidEnterFullScreen:(NSNotification*)notification { - (void)windowDidEnterFullScreen:(NSNotification*)notification {
shell_->NotifyWindowEnterFullScreen(); shell_->NotifyWindowEnterFullScreen();
// For frameless window we don't show set title for normal mode since the if (@available(macOS 10.10, *)) {
// titlebar is expected to be empty, but after entering fullscreen mode we // For frameless window we don't show set title for normal mode since the
// have to set one, because title bar is visible here. // titlebar is expected to be empty, but after entering fullscreen mode we
NSWindow* window = shell_->GetNativeWindow(); // have to set one, because title bar is visible here.
if ((shell_->transparent() || !shell_->has_frame()) && NSWindow* window = shell_->GetNativeWindow();
// FIXME(zcbenz): Showing titlebar for hiddenInset window is weird under if ((shell_->transparent() || !shell_->has_frame()) &&
// fullscreen mode. // FIXME(zcbenz): Showing titlebar for hiddenInset window is weird under
// Show title if fullscreen_window_title flag is set // fullscreen mode.
(shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET || // Show title if fullscreen_window_title flag is set
shell_->fullscreen_window_title())) { (shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET ||
[window setTitleVisibility:NSWindowTitleVisible]; shell_->fullscreen_window_title())) {
} [window setTitleVisibility:NSWindowTitleVisible];
}
// Restore the native toolbar immediately after entering fullscreen, if we // Restore the native toolbar immediately after entering fullscreen, if we
// do this before leaving fullscreen, traffic light buttons will be jumping. // do this before leaving fullscreen, traffic light buttons will be jumping.
if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) {
base::scoped_nsobject<NSToolbar> toolbar( base::scoped_nsobject<NSToolbar> toolbar(
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
[toolbar setShowsBaselineSeparator:NO]; [toolbar setShowsBaselineSeparator:NO];
[window setToolbar:toolbar]; [window setToolbar:toolbar];
// Set window style to hide the toolbar, otherwise the toolbar will show // Set window style to hide the toolbar, otherwise the toolbar will show
// in fullscreen mode. // in fullscreen mode.
shell_->SetStyleMask(true, NSFullSizeContentViewWindowMask); shell_->SetStyleMask(true, NSFullSizeContentViewWindowMask);
}
} }
} }
- (void)windowWillExitFullScreen:(NSNotification*)notification { - (void)windowWillExitFullScreen:(NSNotification*)notification {
// Restore the titlebar visibility. if (@available(macOS 10.10, *)) {
NSWindow* window = shell_->GetNativeWindow(); // Restore the titlebar visibility.
if ((shell_->transparent() || !shell_->has_frame()) && NSWindow* window = shell_->GetNativeWindow();
(shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET || if ((shell_->transparent() || !shell_->has_frame()) &&
shell_->fullscreen_window_title())) { (shell_->title_bar_style() != atom::NativeWindowMac::HIDDEN_INSET ||
[window setTitleVisibility:NSWindowTitleHidden]; shell_->fullscreen_window_title())) {
} [window setTitleVisibility:NSWindowTitleHidden];
}
// Turn off the style for toolbar. // Turn off the style for toolbar.
if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) { if (shell_->title_bar_style() == atom::NativeWindowMac::HIDDEN_INSET) {
shell_->SetStyleMask(false, NSFullSizeContentViewWindowMask); shell_->SetStyleMask(false, NSFullSizeContentViewWindowMask);
}
} }
} }

View file

@ -29,7 +29,8 @@ class CocoaNotification : public Notification {
void NotificationDisplayed(); void NotificationDisplayed();
void NotificationReplied(const std::string& reply); void NotificationReplied(const std::string& reply);
void NotificationActivated(); void NotificationActivated();
void NotificationActivated(NSUserNotificationAction* action); void NotificationActivated(NSUserNotificationAction* action)
API_AVAILABLE(macosx(10.10));
NSUserNotification* notification() const { return notification_; } NSUserNotification* notification() const { return notification_; }

View file

@ -72,18 +72,24 @@ void CocoaNotification::Show(const NotificationOptions& options) {
// All of the rest are appended to the list of additional actions // All of the rest are appended to the list of additional actions
NSString* actionIdentifier = NSString* actionIdentifier =
[NSString stringWithFormat:@"%@Action%d", identifier, i]; [NSString stringWithFormat:@"%@Action%d", identifier, i];
NSUserNotificationAction* notificationAction = [NSUserNotificationAction if (@available(macOS 10.10, *)) {
actionWithIdentifier:actionIdentifier NSUserNotificationAction* notificationAction =
title:base::SysUTF16ToNSString(action.text)]; [NSUserNotificationAction
[additionalActions addObject:notificationAction]; actionWithIdentifier:actionIdentifier
additional_action_indices_.insert( title:base::SysUTF16ToNSString(action.text)];
std::make_pair(base::SysNSStringToUTF8(actionIdentifier), i)); [additionalActions addObject:notificationAction];
additional_action_indices_.insert(
std::make_pair(base::SysNSStringToUTF8(actionIdentifier), i));
}
} }
} }
i++; i++;
} }
if ([additionalActions count] > 0) { if ([additionalActions count] > 0 &&
[notification_ setAdditionalActions:additionalActions]; [notification_ respondsToSelector:@selector(setAdditionalActions:)]) {
if (@available(macOS 10.10, *)) {
[notification_ setAdditionalActions:additionalActions];
}
} }
if (options.has_reply) { if (options.has_reply) {

View file

@ -48,9 +48,12 @@
NSUserNotificationActivationTypeReplied) { NSUserNotificationActivationTypeReplied) {
notification->NotificationReplied([notif.response.string UTF8String]); notification->NotificationReplied([notif.response.string UTF8String]);
} else { } else {
if (notif.activationType == if (@available(macOS 10.10, *)) {
NSUserNotificationActivationTypeAdditionalActionClicked) { if (notif.activationType ==
notification->NotificationActivated([notif additionalActivationAction]); NSUserNotificationActivationTypeAdditionalActionClicked) {
notification->NotificationActivated(
[notif additionalActivationAction]);
}
} }
} }
} }

View file

@ -21,10 +21,11 @@ win.show()
### Alternatives on macOS ### Alternatives on macOS
There's an alternative way to specify a chromeless window. On macOS 10.9 Mavericks and newer, there's an alternative way to specify
Instead of setting `frame` to `false` which disables both the titlebar and window controls, a chromeless window. Instead of setting `frame` to `false` which disables
you may want to have the title bar hidden and your content extend to the full window size, both the titlebar and window controls, you may want to have the title bar
yet still preserve the window controls ("traffic lights") for standard window actions. hidden and your content extend to the full window size, yet still preserve
the window controls ("traffic lights") for standard window actions.
You can do so by specifying the `titleBarStyle` option: You can do so by specifying the `titleBarStyle` option:
#### `hidden` #### `hidden`

View file

@ -7,7 +7,7 @@ rudimentary understanding of your operating system's command line client.
## Setting up macOS ## Setting up macOS
> Electron supports OS X Yosemite (version 10.10) and up. Apple > Electron supports Mac OS X 10.9 (and all versions named macOS) and up. Apple
does not allow running macOS in virtual machines unless the host computer is does not allow running macOS in virtual machines unless the host computer is
already an Apple computer, so if you find yourself in need of a Mac, consider already an Apple computer, so if you find yourself in need of a Mac, consider
using a cloud service that rents access to Macs (like [MacInCloud][macincloud] using a cloud service that rents access to Macs (like [MacInCloud][macincloud]

View file

@ -61,7 +61,7 @@ Following platforms are supported by Electron:
### macOS ### macOS
Only 64bit binaries are provided for macOS, and the minimum macOS version Only 64bit binaries are provided for macOS, and the minimum macOS version
supported is OS X Yosemite (version 10.10). supported is macOS 10.9.
### Windows ### Windows