From 330c3bc1364e1c99f47878c560312618ddbd9605 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 17 Jun 2021 02:13:42 +0900 Subject: [PATCH] chore: remove c-style conversion for vibrantView (#29724) --- shell/browser/native_window_mac.mm | 34 ++++++++++----------- shell/browser/ui/cocoa/electron_ns_window.h | 2 +- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 7864ac48f48a..58939680b6e3 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1308,10 +1308,9 @@ void NativeWindowMac::SetAutoHideCursor(bool auto_hide) { } void NativeWindowMac::UpdateVibrancyRadii(bool fullscreen) { - NSView* vibrant_view = [window_ vibrantView]; - NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view; + NSVisualEffectView* vibrantView = [window_ vibrantView]; - if (effect_view != nil && !vibrancy_type_.empty()) { + if (vibrantView != nil && !vibrancy_type_.empty()) { const bool no_rounded_corner = [window_ styleMask] & NSWindowStyleMaskFullSizeContentView; if (!has_frame() && !is_modal() && !no_rounded_corner) { @@ -1341,43 +1340,42 @@ void NativeWindowMac::UpdateVibrancyRadii(bool fullscreen) { [maskImage setCapInsets:NSEdgeInsetsMake(radius, radius, radius, radius)]; [maskImage setResizingMode:NSImageResizingModeStretch]; - [effect_view setMaskImage:maskImage]; + [vibrantView setMaskImage:maskImage]; [window_ setCornerMask:maskImage]; } } } void NativeWindowMac::SetVibrancy(const std::string& type) { - NSView* vibrant_view = [window_ vibrantView]; + NSVisualEffectView* vibrantView = [window_ vibrantView]; if (type.empty()) { - if (vibrant_view == nil) + if (vibrantView == nil) return; - [vibrant_view removeFromSuperview]; + [vibrantView removeFromSuperview]; [window_ setVibrantView:nil]; return; } - NSVisualEffectView* effect_view = (NSVisualEffectView*)vibrant_view; - if (effect_view == nil) { - effect_view = [[[NSVisualEffectView alloc] + if (vibrantView == nil) { + vibrantView = [[[NSVisualEffectView alloc] initWithFrame:[[window_ contentView] bounds]] autorelease]; - [window_ setVibrantView:(NSView*)effect_view]; + [window_ setVibrantView:vibrantView]; - [effect_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; - [effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; + [vibrantView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + [vibrantView setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; if (visual_effect_state_ == VisualEffectState::kActive) { - [effect_view setState:NSVisualEffectStateActive]; + [vibrantView setState:NSVisualEffectStateActive]; } else if (visual_effect_state_ == VisualEffectState::kInactive) { - [effect_view setState:NSVisualEffectStateInactive]; + [vibrantView setState:NSVisualEffectStateInactive]; } else { - [effect_view setState:NSVisualEffectStateFollowsWindowActiveState]; + [vibrantView setState:NSVisualEffectStateFollowsWindowActiveState]; } - [[window_ contentView] addSubview:effect_view + [[window_ contentView] addSubview:vibrantView positioned:NSWindowBelow relativeTo:nil]; @@ -1447,7 +1445,7 @@ void NativeWindowMac::SetVibrancy(const std::string& type) { if (vibrancyType) { vibrancy_type_ = type; - [effect_view setMaterial:vibrancyType]; + [vibrantView setMaterial:vibrancyType]; } } diff --git a/shell/browser/ui/cocoa/electron_ns_window.h b/shell/browser/ui/cocoa/electron_ns_window.h index 48e32def1ea4..c5adf86469e9 100644 --- a/shell/browser/ui/cocoa/electron_ns_window.h +++ b/shell/browser/ui/cocoa/electron_ns_window.h @@ -35,7 +35,7 @@ class ScopedDisableResize { @property BOOL enableLargerThanScreen; @property BOOL disableAutoHideCursor; @property BOOL disableKeyOrMainWindow; -@property(nonatomic, retain) NSView* vibrantView; +@property(nonatomic, retain) NSVisualEffectView* vibrantView; @property(nonatomic, retain) NSImage* cornerMask; - (id)initWithShell:(electron::NativeWindowMac*)shell styleMask:(NSUInteger)styleMask;