From 1849bde7d25d01b064c1b4064305e0fe6eed079e Mon Sep 17 00:00:00 2001 From: broly Date: Sun, 11 Aug 2024 11:42:00 -0600 Subject: [PATCH] small changes, big difference. fix DL crashes pre 10.10, errant tooltips (centralle) wow what a difference two changes made. a lot of work went into their detection, but now there are no errant, or empty tooltips when you mouseover menubuttons. also downloads would crash after completing because the clang team likes to engage in butthole play (being assholes ha), by failing to backport newer enums that don't work on older systems. they just don't care. APPUL pays their bills and probably encourages this behaviour. --- widget/cocoa/VibrancyManager.h | 7 +++++++ widget/cocoa/VibrancyManager.mm | 14 ++++++++++++++ widget/cocoa/nsCocoaWindow.mm | 6 ++++++ widget/cocoa/nsMacUserActivityUpdater.mm | 14 ++++++-------- xpcom/io/CocoaFileUtils.mm | 10 +++++++++- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/widget/cocoa/VibrancyManager.h b/widget/cocoa/VibrancyManager.h index 839674ca2ce12..bc1c85bf50c3a 100644 --- a/widget/cocoa/VibrancyManager.h +++ b/widget/cocoa/VibrancyManager.h @@ -69,6 +69,13 @@ class VibrancyManager { LayoutDeviceIntRegion GetUnionOfVibrantRegions() const; + /** + * Check whether the operating system supports vibrancy at all. + * You may only create a VibrancyManager instance if this returns true. + * @return Whether VibrancyManager can be used on this OS. + */ + static bool SystemSupportsVibrancy(); + /** * Create an NSVisualEffectView for the specified vibrancy type. The return * value is not autoreleased. We return an object of type NSView* because we diff --git a/widget/cocoa/VibrancyManager.mm b/widget/cocoa/VibrancyManager.mm index da42a972f9aa3..1fe49964a071f 100644 --- a/widget/cocoa/VibrancyManager.mm +++ b/widget/cocoa/VibrancyManager.mm @@ -120,3 +120,17 @@ - (BOOL)allowsVibrancy { } +static bool ComputeSystemSupportsVibrancy() { +#ifdef __x86_64__ + return NSClassFromString(@"NSAppearance") && NSClassFromString(@"NSVisualEffectView"); +#else + // objc_allocateClassPair doesn't work in 32 bit mode, so turn off vibrancy. + return false; +#endif +} + +/* static */ bool VibrancyManager::SystemSupportsVibrancy() { + static bool supportsVibrancy = ComputeSystemSupportsVibrancy(); + return supportsVibrancy; +} + diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index b671592091fdd..8f05f624cfcbc 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -3320,6 +3320,10 @@ - (id)initWithContentRect:(NSRect)aContentRect // Add an effect view wrapper if needed so that the OS draws the appropriate // vibrancy effect and window border. - (void)setEffectViewWrapperForStyle:(WindowShadow)aStyle { + if (!VibrancyManager::SystemSupportsVibrancy()) { + return; + } + NSView* wrapper = [&]() -> NSView* { if (aStyle == WindowShadow::Menu || aStyle == WindowShadow::Tooltip) { const bool isMenu = aStyle == WindowShadow::Menu; @@ -3332,7 +3336,9 @@ - (void)setEffectViewWrapperForStyle:(WindowShadow)aStyle { effectView.blendingMode = NSVisualEffectBlendingModeBehindWindow; if (isMenu) { // Turn on rounded corner masking. + if ([effectView respondsToSelector:@selector(setMaskImage:)]) { effectView.maskImage = GetMenuMaskImage(); + } effectView.material = NSVisualEffectMaterialMenu; } else { if(@available(macOS 10.14, *)) { diff --git a/widget/cocoa/nsMacUserActivityUpdater.mm b/widget/cocoa/nsMacUserActivityUpdater.mm index a3d94ac6ce894..72efbf727f2cb 100644 --- a/widget/cocoa/nsMacUserActivityUpdater.mm +++ b/widget/cocoa/nsMacUserActivityUpdater.mm @@ -41,14 +41,12 @@ pageTitle = pageUrl.absoluteString; } - if(__builtin_available(macOS 10.10, *)) { - NSUserActivity* userActivity = [[NSUserActivity alloc] - initWithActivityType:NSUserActivityTypeBrowsingWeb]; - userActivity.webpageURL = pageUrl; - userActivity.title = pageTitle; - cocoaWin.userActivity = userActivity; - [userActivity release]; - } + NSUserActivity* userActivity = [[NSUserActivity alloc] + initWithActivityType:NSUserActivityTypeBrowsingWeb]; + userActivity.webpageURL = pageUrl; + userActivity.title = pageTitle; + cocoaWin.userActivity = userActivity; + [userActivity release]; } return NS_OK; diff --git a/xpcom/io/CocoaFileUtils.mm b/xpcom/io/CocoaFileUtils.mm index b5c189adb8fe4..6d78db68d312a 100644 --- a/xpcom/io/CocoaFileUtils.mm +++ b/xpcom/io/CocoaFileUtils.mm @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "CocoaFileUtils.h" +#include "nsCocoaFeatures.h" #include "nsCocoaUtils.h" #include #include "nsObjCExceptions.h" @@ -215,6 +216,13 @@ typedef OSStatus (*MDItemSetAttribute_type)(MDItemRef, CFStringRef, ::CFRelease(mdItem); } +static CFStringRef GetQuarantinePropKey() { + if (nsCocoaFeatures::OnYosemiteOrLater()) { + return kCFURLQuarantinePropertiesKey; + } + return kLSItemQuarantineProperties; +} + // Can be called off of the main thread. static CFMutableDictionaryRef CreateQuarantineDictionary( const CFURLRef aFileURL, const bool aCreateProps) { @@ -227,7 +235,7 @@ static CFMutableDictionaryRef CreateQuarantineDictionary( &kCFTypeDictionaryValueCallBacks); } else { Boolean success = ::CFURLCopyResourcePropertyForKey( - aFileURL, kCFURLQuarantinePropertiesKey, &quarantineProps, NULL); + aFileURL, GetQuarantinePropKey(), &quarantineProps, NULL); // If there aren't any quarantine properties then the user probably // set up an exclusion and we don't need to add metadata. if (!success || !quarantineProps) {