Revert "fix: Drop support for OS X Mavericks (version 10.9)" (#13333)
This commit is contained in:
parent
562eddf0e9
commit
79fbd6bab1
15 changed files with 290 additions and 156 deletions
|
@ -295,9 +295,11 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
|||
}
|
||||
|
||||
NSUInteger styleMask = NSTitledWindowMask;
|
||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER &&
|
||||
(!useStandardWindow || transparent() || !has_frame())) {
|
||||
styleMask = NSFullSizeContentViewWindowMask;
|
||||
if (@available(macOS 10.10, *)) {
|
||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER &&
|
||||
(!useStandardWindow || transparent() || !has_frame())) {
|
||||
styleMask = NSFullSizeContentViewWindowMask;
|
||||
}
|
||||
}
|
||||
if (minimizable) {
|
||||
styleMask |= NSMiniaturizableWindowMask;
|
||||
|
@ -352,10 +354,11 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
|||
[window_ setDisableKeyOrMainWindow:YES];
|
||||
|
||||
if (transparent() || !has_frame()) {
|
||||
// Don't show title bar.
|
||||
[window_ setTitlebarAppearsTransparent:YES];
|
||||
[window_ setTitleVisibility:NSWindowTitleHidden];
|
||||
|
||||
if (@available(macOS 10.10, *)) {
|
||||
// Don't show title bar.
|
||||
[window_ setTitlebarAppearsTransparent:YES];
|
||||
[window_ setTitleVisibility:NSWindowTitleHidden];
|
||||
}
|
||||
// Remove non-transparent corners, see http://git.io/vfonD.
|
||||
[window_ setOpaque:NO];
|
||||
}
|
||||
|
@ -374,15 +377,22 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
|||
|
||||
// Hide the title bar background
|
||||
if (title_bar_style_ != NORMAL) {
|
||||
[window_ setTitlebarAppearsTransparent:YES];
|
||||
if (@available(macOS 10.10, *)) {
|
||||
[window_ setTitlebarAppearsTransparent:YES];
|
||||
}
|
||||
}
|
||||
|
||||
// Hide the title bar.
|
||||
if (title_bar_style_ == HIDDEN_INSET) {
|
||||
base::scoped_nsobject<NSToolbar> toolbar(
|
||||
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
|
||||
[toolbar setShowsBaselineSeparator:NO];
|
||||
[window_ setToolbar:toolbar];
|
||||
if (@available(macOS 10.10, *)) {
|
||||
base::scoped_nsobject<NSToolbar> toolbar(
|
||||
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
|
||||
[toolbar setShowsBaselineSeparator:NO];
|
||||
[window_ setToolbar:toolbar];
|
||||
} else {
|
||||
[window_ enableWindowButtonsOffset];
|
||||
[window_ setWindowButtonsOffset:NSMakePoint(12, 10)];
|
||||
}
|
||||
}
|
||||
|
||||
// Resize to content bounds.
|
||||
|
@ -435,8 +445,9 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
|||
SetContentView(new views::View());
|
||||
|
||||
// Make sure the bottom corner is rounded for non-modal windows:
|
||||
// http://crbug.com/396264.
|
||||
if (!is_modal()) {
|
||||
// http://crbug.com/396264. But do not enable it on OS X 10.9 for transparent
|
||||
// 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]);
|
||||
[background_layer
|
||||
setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
|
||||
|
@ -468,6 +479,11 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
|||
[[window_ contentView] addSubview:buttons_view_];
|
||||
} else {
|
||||
if (title_bar_style_ != NORMAL) {
|
||||
if (base::mac::IsOS10_9()) {
|
||||
ShowWindowButton(NSWindowZoomButton);
|
||||
ShowWindowButton(NSWindowMiniaturizeButton);
|
||||
ShowWindowButton(NSWindowCloseButton);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -842,11 +858,17 @@ void NativeWindowMac::Invalidate() {
|
|||
}
|
||||
|
||||
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)];
|
||||
}
|
||||
|
||||
std::string NativeWindowMac::GetTitle() {
|
||||
return base::SysNSStringToUTF8([window_ title]);
|
||||
;
|
||||
}
|
||||
|
||||
void NativeWindowMac::FlashFrame(bool flash) {
|
||||
|
@ -1156,83 +1178,86 @@ bool NativeWindowMac::AddTabbedWindow(NativeWindow* window) {
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
[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(
|
||||
|
@ -1316,6 +1341,11 @@ void NativeWindowMac::InternalSetParentWindow(NativeWindow* parent,
|
|||
[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) {
|
||||
[window_ setAcceptsMouseMovedEvents:forward];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue