summaryrefslogtreecommitdiffstats
path: root/widget/cocoa/nsCocoaWindow.mm
diff options
context:
space:
mode:
Diffstat (limited to 'widget/cocoa/nsCocoaWindow.mm')
-rw-r--r--widget/cocoa/nsCocoaWindow.mm80
1 files changed, 41 insertions, 39 deletions
diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm
index 8e54d9e7fd..5032f35fa1 100644
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -6,7 +6,6 @@
#include "nsCocoaWindow.h"
-#include "AppearanceOverride.h"
#include "NativeKeyBindings.h"
#include "ScreenHelperCocoa.h"
#include "TextInputHandler.h"
@@ -158,6 +157,13 @@ void nsCocoaWindow::DestroyNativeWindow() {
// we clear our delegate.
EndOurNativeTransition();
+ // We are about to destroy mWindow. Before we do that, make sure that we
+ // hide the window using the Show() method, because it has several side
+ // effects that our parent and listeners might be expecting. If we don't
+ // do this now, then these side effects will never execute, though the
+ // window will definitely no longer be shown.
+ Show(false);
+
[mWindow releaseJSObjects];
// We want to unhook the delegate here because we don't want events
// sent to it after this object has been destroyed.
@@ -525,10 +531,6 @@ nsresult nsCocoaWindow::CreateNativeWindow(const NSRect& aRect,
[WindowDataMap.sharedWindowDataMap ensureDataForWindow:mWindow];
mWindowMadeHere = true;
- // Make the window respect the global appearance, which follows the
- // browser.theme.toolbar-theme pref.
- mWindow.appearanceSource = MOZGlobalAppearance.sharedInstance;
-
return NS_OK;
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
@@ -1969,7 +1971,6 @@ void nsCocoaWindow::BackingScaleFactorChanged() {
if (PresShell* presShell = mWidgetListener->GetPresShell()) {
presShell->BackingScaleFactorChanged();
}
- mWidgetListener->UIResolutionChanged();
}
int32_t nsCocoaWindow::RoundsWidgetCoordinatesTo() {
@@ -2327,9 +2328,11 @@ void nsCocoaWindow::SetColorScheme(const Maybe<ColorScheme>& aScheme) {
if (!mWindow) {
return;
}
-
- mWindow.appearance = aScheme ? NSAppearanceForColorScheme(*aScheme) : nil;
-
+ NSAppearance* appearance =
+ aScheme ? NSAppearanceForColorScheme(*aScheme) : nil;
+ if (mWindow.appearance != appearance) {
+ mWindow.appearance = appearance;
+ }
NS_OBJC_END_TRY_IGNORE_BLOCK;
}
@@ -3071,10 +3074,6 @@ static NSMutableSet* gSwizzledFrameViewClasses = nil;
- (void)_setNeedsDisplayInRect:(NSRect)aRect;
@end
-@interface NSView (NSVisualEffectViewSetMaskImage)
-- (void)setMaskImage:(NSImage*)image;
-@end
-
@interface BaseWindow (Private)
- (void)removeTrackingArea;
- (void)cursorUpdated:(NSEvent*)aEvent;
@@ -3174,35 +3173,38 @@ static NSImage* GetMenuMaskImage() {
return maskImage;
}
-- (void)swapOutChildViewWrapper:(NSView*)aNewWrapper {
- aNewWrapper.frame = self.contentView.frame;
+// Add an effect view wrapper if needed so that the OS draws the appropriate
+// vibrancy effect and window border.
+- (void)setEffectViewWrapperForStyle:(WindowShadow)aStyle {
+ NSView* wrapper = [&]() -> NSView* {
+ if (aStyle == WindowShadow::Menu || aStyle == WindowShadow::Tooltip) {
+ const bool isMenu = aStyle == WindowShadow::Menu;
+ auto* effectView =
+ [[NSVisualEffectView alloc] initWithFrame:self.contentView.frame];
+ effectView.material =
+ isMenu ? NSVisualEffectMaterialMenu : NSVisualEffectMaterialToolTip;
+ // Tooltip and menu windows are never "key", so we need to tell the
+ // vibrancy effect to look active regardless of window state.
+ effectView.state = NSVisualEffectStateActive;
+ effectView.blendingMode = NSVisualEffectBlendingModeBehindWindow;
+ if (isMenu) {
+ // Turn on rounded corner masking.
+ effectView.maskImage = GetMenuMaskImage();
+ }
+ return effectView;
+ }
+ return [[NSView alloc] initWithFrame:self.contentView.frame];
+ }();
+
+ wrapper.wantsLayer = YES;
+ // Swap out our content view by the new view. Setting .contentView releases
+ // the old view.
NSView* childView = [self.mainChildView retain];
[childView removeFromSuperview];
- [aNewWrapper addSubview:childView];
+ [wrapper addSubview:childView];
[childView release];
- [super setContentView:aNewWrapper];
-}
-
-- (void)setEffectViewWrapperForStyle:(WindowShadow)aStyle {
- if (aStyle == WindowShadow::Menu || aStyle == WindowShadow::Tooltip) {
- // Add an effect view wrapper so that the OS draws the appropriate
- // vibrancy effect and window border.
- BOOL isMenu = aStyle == WindowShadow::Menu;
- NSView* effectView = VibrancyManager::CreateEffectView(
- isMenu ? VibrancyType::MENU : VibrancyType::TOOLTIP, YES);
- if (isMenu) {
- // Turn on rounded corner masking.
- [effectView setMaskImage:GetMenuMaskImage()];
- }
- [self swapOutChildViewWrapper:effectView];
- [effectView release];
- } else {
- // Remove the existing wrapper.
- NSView* wrapper = [[NSView alloc] initWithFrame:NSZeroRect];
- [wrapper setWantsLayer:YES];
- [self swapOutChildViewWrapper:wrapper];
- [wrapper release];
- }
+ super.contentView = wrapper;
+ [wrapper release];
}
- (NSTouchBar*)makeTouchBar {