From d2989de5d9b7ae4a3d860620bbf7e760fc9be5ed Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 27 Jul 2021 01:22:21 +0900 Subject: [PATCH] fix: update traffic lights position for macOS 11 (#30263) --- shell/browser/native_window_mac.mm | 2 +- shell/browser/ui/cocoa/window_buttons_view.h | 2 ++ shell/browser/ui/cocoa/window_buttons_view.mm | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 5e420ad8edaf..6b708b4e9a20 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1800,7 +1800,7 @@ void NativeWindowMac::AddContentViewLayers() { [buttons_view_ setShowOnHover:YES]; if (title_bar_style_ == TitleBarStyle::kHiddenInset && !traffic_light_position_) - [buttons_view_ setMargin:gfx::Point(12, 11)]; + [buttons_view_ setMargin:[WindowButtonsView hiddenInsetMargin]]; if (!IsClosable()) [[buttons_view_ viewWithTag:0] setEnabled:NO]; diff --git a/shell/browser/ui/cocoa/window_buttons_view.h b/shell/browser/ui/cocoa/window_buttons_view.h index d1941bcb4276..7786f83c42fe 100644 --- a/shell/browser/ui/cocoa/window_buttons_view.h +++ b/shell/browser/ui/cocoa/window_buttons_view.h @@ -22,6 +22,8 @@ base::scoped_nsobject tracking_area_; } ++ (gfx::Point)defaultMargin; ++ (gfx::Point)hiddenInsetMargin; - (id)initWithMargin:(const absl::optional&)margin; - (void)setMargin:(const absl::optional&)margin; - (void)setShowOnHover:(BOOL)yes; diff --git a/shell/browser/ui/cocoa/window_buttons_view.mm b/shell/browser/ui/cocoa/window_buttons_view.mm index ff0cc75dd4e0..3d52dd7fdcd1 100644 --- a/shell/browser/ui/cocoa/window_buttons_view.mm +++ b/shell/browser/ui/cocoa/window_buttons_view.mm @@ -23,6 +23,21 @@ const NSWindowButton kButtonTypes[] = { @implementation WindowButtonsView ++ (gfx::Point)defaultMargin { + if (@available(macOS 11.0, *)) { + return gfx::Point(7, 6); + } else { + return gfx::Point(7, 3); + } +} + ++ (gfx::Point)hiddenInsetMargin { + // For macOS >= 11, while this value does not match offical macOS apps like + // Safari or Notes, it matches titleBarStyle's old implementation before + // Electron <= 12. + return gfx::Point(12, 11); +} + - (id)initWithMargin:(const absl::optional&)margin { self = [super initWithFrame:NSZeroRect]; [self setMargin:margin]; @@ -51,7 +66,7 @@ const NSWindowButton kButtonTypes[] = { } - (void)setMargin:(const absl::optional&)margin { - margin_ = margin.value_or(gfx::Point(7, 3)); + margin_ = margin.value_or([WindowButtonsView defaultMargin]); } - (void)setShowOnHover:(BOOL)yes {