summaryrefslogtreecommitdiffstats
path: root/widget/cocoa/nsCocoaFeatures.mm
diff options
context:
space:
mode:
Diffstat (limited to 'widget/cocoa/nsCocoaFeatures.mm')
-rw-r--r--widget/cocoa/nsCocoaFeatures.mm168
1 files changed, 86 insertions, 82 deletions
diff --git a/widget/cocoa/nsCocoaFeatures.mm b/widget/cocoa/nsCocoaFeatures.mm
index 0b22c51bd..e0fafb7d9 100644
--- a/widget/cocoa/nsCocoaFeatures.mm
+++ b/widget/cocoa/nsCocoaFeatures.mm
@@ -3,27 +3,29 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-// This file makes some assumptions about the versions of OS X.
-// We are assuming that the minor and bugfix versions are less than 16.
+// This file makes some assumptions about the versions of macOS.
+// We are assuming that the major, minor and bugfix versions are each less than
+// 256.
// There are MOZ_ASSERTs for that.
-// The formula for the version integer based on OS X version 10.minor.bugfix is
-// 0x1000 + (minor << 4) + bugifix. See AssembleVersion() below for major > 10.
-// Major version < 10 is not allowed.
-
-#define MAC_OS_X_VERSION_MASK 0x0000FFFF
-#define MAC_OS_X_VERSION_10_0_HEX 0x00001000
-#define MAC_OS_X_VERSION_10_7_HEX 0x00001070
-#define MAC_OS_X_VERSION_10_8_HEX 0x00001080
-#define MAC_OS_X_VERSION_10_9_HEX 0x00001090
-#define MAC_OS_X_VERSION_10_10_HEX 0x000010A0
-#define MAC_OS_X_VERSION_10_11_HEX 0x000010B0
-#define MAC_OS_X_VERSION_10_12_HEX 0x000010C0
-#define MAC_OS_X_VERSION_10_13_HEX 0x000010D0
-#define MAC_OS_X_VERSION_10_14_HEX 0x000010E0
-#define MAC_OS_X_VERSION_10_15_HEX 0x000010F0
-#define MAC_OS_X_VERSION_10_16_HEX 0x000A1000
-#define MAC_OS_X_VERSION_11_0_HEX 0x000B0000
+// The formula for the version integer is (major << 16) + (minor << 8) + bugfix.
+
+#define MACOS_VERSION_MASK 0x00FFFFFF
+#define MACOS_MAJOR_VERSION_MASK 0x00FFFFFF
+#define MACOS_MINOR_VERSION_MASK 0x00FFFFFF
+#define MACOS_BUGFIX_VERSION_MASK 0x00FFFFFF
+#define MACOS_VERSION_10_0_HEX 0x000A0000
+#define MACOS_VERSION_10_7_HEX 0x000A0700
+#define MACOS_VERSION_10_8_HEX 0x000A0800
+#define MACOS_VERSION_10_9_HEX 0x000A0900
+#define MACOS_VERSION_10_10_HEX 0x000A0A00
+#define MACOS_VERSION_10_11_HEX 0x000A0B00
+#define MACOS_VERSION_10_12_HEX 0x000A0C00
+#define MACOS_VERSION_10_13_HEX 0x000A0D00
+#define MACOS_VERSION_10_14_HEX 0x000A0E00
+#define MACOS_VERSION_10_15_HEX 0x000A0F00
+#define MACOS_VERSION_10_16_HEX 0x000A1000
+#define MACOS_VERSION_11_0_HEX 0x000B0000
#include "nsCocoaFeatures.h"
#include "nsCocoaUtils.h"
@@ -32,36 +34,36 @@
#import <Cocoa/Cocoa.h>
-int32_t nsCocoaFeatures::mOSXVersion = 0;
+int32_t nsCocoaFeatures::mOSVersion = 0;
// This should not be called with unchecked aMajor, which should be >= 10.
inline int32_t AssembleVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix)
{
- MOZ_ASSERT(aMajor >= 10);
- return MAC_OS_X_VERSION_10_0_HEX + (aMajor-10) * 0x100 + (aMinor << 4) + aBugFix;
+ MOZ_ASSERT(aMajor >= 10);
+ return (aMajor << 16) + (aMinor << 8) + aBugFix;
}
int32_t nsCocoaFeatures::ExtractMajorVersion(int32_t aVersion)
{
- MOZ_ASSERT((aVersion & MAC_OS_X_VERSION_MASK) == aVersion);
- return ((aVersion & 0xFF00) - 0x1000) / 0x100 + 10;
+ MOZ_ASSERT((aVersion & MACOS_VERSION_MASK) == aVersion);
+ return (aVersion & 0xFF0000) >> 16;
}
int32_t nsCocoaFeatures::ExtractMinorVersion(int32_t aVersion)
{
- MOZ_ASSERT((aVersion & MAC_OS_X_VERSION_MASK) == aVersion);
- return (aVersion & 0xF0) >> 4;
+ MOZ_ASSERT((aVersion & MACOS_VERSION_MASK) == aVersion);
+ return (aVersion & 0xFF00) >> 8;
}
int32_t nsCocoaFeatures::ExtractBugFixVersion(int32_t aVersion)
{
- MOZ_ASSERT((aVersion & MAC_OS_X_VERSION_MASK) == aVersion);
- return aVersion & 0x0F;
+ MOZ_ASSERT((aVersion & MACOS_VERSION_MASK) == aVersion);
+ return aVersion & 0xFF;
}
static int intAtStringIndex(NSArray *array, int index)
{
- return [(NSString *)[array objectAtIndex:index] integerValue];
+ return [(NSString*)[array objectAtIndex:index] integerValue];
}
void nsCocoaFeatures::GetSystemVersion(int &major, int &minor, int &bugfix)
@@ -85,121 +87,123 @@ void nsCocoaFeatures::GetSystemVersion(int &major, int &minor, int &bugfix)
int32_t nsCocoaFeatures::GetVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix)
{
- int32_t osxVersion;
- if (aMajor < 10) {
- aMajor = 10;
- NS_ERROR("Couldn't determine OS X version, assuming 10.7");
- osxVersion = MAC_OS_X_VERSION_10_7_HEX;
- } else if (aMinor < 7) {
- aMinor = 7;
- NS_ERROR("OS X version too old, assuming 10.7");
- osxVersion = MAC_OS_X_VERSION_10_7_HEX;
- } else {
- MOZ_ASSERT(aMajor == 10); // For now, even though we're ready...
- MOZ_ASSERT(aMinor < 16);
- MOZ_ASSERT(aBugFix >= 0);
- MOZ_ASSERT(aBugFix < 16);
- osxVersion = AssembleVersion(aMajor, aMinor, aBugFix);
- }
- MOZ_ASSERT(aMajor == ExtractMajorVersion(osxVersion));
- MOZ_ASSERT(aMinor == ExtractMinorVersion(osxVersion));
- MOZ_ASSERT(aBugFix == ExtractBugFixVersion(osxVersion));
- return osxVersion;
+ int32_t macOSVersion;
+ if (aMajor < 10) {
+ aMajor = 10;
+ NS_ERROR("Couldn't determine macOS version, assuming 10.7");
+ macOSVersion = MACOS_VERSION_10_7_HEX;
+ } else if (aMajor == 10 && aMinor < 7) {
+ aMinor = 7;
+ NS_ERROR("macOS version too old, assuming 10.7");
+ macOSVersion = MACOS_VERSION_10_7_HEX;
+ } else {
+ MOZ_ASSERT(aMajor >= 10);
+ MOZ_ASSERT(aMajor < 256);
+ MOZ_ASSERT(aMinor >= 0);
+ MOZ_ASSERT(aMinor < 256);
+ MOZ_ASSERT(aBugFix >= 0);
+ MOZ_ASSERT(aBugFix < 256);
+ macOSVersion = AssembleVersion(aMajor, aMinor, aBugFix);
+ }
+ MOZ_ASSERT(aMajor == ExtractMajorVersion(macOSVersion));
+ MOZ_ASSERT(aMinor == ExtractMinorVersion(macOSVersion));
+ MOZ_ASSERT(aBugFix == ExtractBugFixVersion(macOSVersion));
+ return macOSVersion;
}
/*static*/ void
nsCocoaFeatures::InitializeVersionNumbers()
{
- NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
+ NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
- // Provide an autorelease pool to avoid leaking Cocoa objects,
- // as this gets called before the main autorelease pool is in place.
- nsAutoreleasePool localPool;
+ // Provide an autorelease pool to avoid leaking Cocoa objects,
+ // as this gets called before the main autorelease pool is in place.
+ nsAutoreleasePool localPool;
- int major, minor, bugfix;
- GetSystemVersion(major, minor, bugfix);
- mOSXVersion = GetVersion(major, minor, bugfix);
+ int major, minor, bugfix;
+ GetSystemVersion(major, minor, bugfix);
+ mOSVersion = GetVersion(major, minor, bugfix);
- NS_OBJC_END_TRY_ABORT_BLOCK;
+ NS_OBJC_END_TRY_ABORT_BLOCK;
}
/* static */ int32_t
-nsCocoaFeatures::OSXVersion()
+nsCocoaFeatures::macOSVersion()
{
- // Don't let this be called while we're first setting the value...
- MOZ_ASSERT((mOSXVersion & MAC_OS_X_VERSION_MASK) >= 0);
- if (!mOSXVersion) {
- mOSXVersion = -1;
- InitializeVersionNumbers();
- }
- return mOSXVersion;
+ // Don't let this be called while we're first setting the value...
+ MOZ_ASSERT((mOSVersion & MACOS_VERSION_MASK) >= 0);
+ if (!mOSVersion) {
+ mOSVersion = -1;
+ InitializeVersionNumbers();
+ }
+ return mOSVersion;
}
/* static */ int32_t
-nsCocoaFeatures::OSXVersionMajor()
+nsCocoaFeatures::macOSVersionMajor()
{
- MOZ_ASSERT((OSXVersion() & MAC_OS_X_VERSION_10_0_HEX) == MAC_OS_X_VERSION_10_0_HEX);
- return 10;
+ return ExtractMajorVersion(macOSVersion());
}
/* static */ int32_t
-nsCocoaFeatures::OSXVersionMinor()
+nsCocoaFeatures::macOSVersionMinor()
{
- return ExtractMinorVersion(OSXVersion());
+ return ExtractMinorVersion(macOSVersion());
}
/* static */ int32_t
-nsCocoaFeatures::OSXVersionBugFix()
+nsCocoaFeatures::macOSVersionBugFix()
{
- return ExtractBugFixVersion(OSXVersion());
+ return ExtractBugFixVersion(macOSVersion());
}
/* static */ bool
nsCocoaFeatures::OnYosemiteOrLater()
{
- return (OSXVersion() >= MAC_OS_X_VERSION_10_10_HEX);
+ return (macOSVersion() >= MACOS_VERSION_10_10_HEX);
}
/* static */ bool
nsCocoaFeatures::OnElCapitanOrLater()
{
- return (OSXVersion() >= MAC_OS_X_VERSION_10_11_HEX);
+ return (macOSVersion() >= MACOS_VERSION_10_11_HEX);
}
/* static */ bool
nsCocoaFeatures::OnSierraOrLater()
{
- return (OSXVersion() >= MAC_OS_X_VERSION_10_12_HEX);
+ return (macOSVersion() >= MACOS_VERSION_10_12_HEX);
}
/* static */ bool
nsCocoaFeatures::OnHighSierraOrLater()
{
- return (OSXVersion() >= MAC_OS_X_VERSION_10_13_HEX);
+ return (macOSVersion() >= MACOS_VERSION_10_13_HEX);
}
/* static */ bool
nsCocoaFeatures::OnMojaveOrLater()
{
- return (OSXVersion() >= MAC_OS_X_VERSION_10_14_HEX);
+ return (macOSVersion() >= MACOS_VERSION_10_14_HEX);
}
/* static */ bool
nsCocoaFeatures::OnCatalinaOrLater()
{
- return (OSXVersion() >= MAC_OS_X_VERSION_10_15_HEX);
+ return (macOSVersion() >= MACOS_VERSION_10_15_HEX);
}
/* static */ bool
-nsCocoaFeatures::OnBigSurOrLater() {
+nsCocoaFeatures::OnBigSurOrLater()
+{
// Account for the version being 10.16 (which occurs when the
// application is linked with an older SDK) or 11.0 on Big Sur.
- return ((OSXVersion() >= MAC_OS_X_VERSION_10_16_HEX) ||
- (OSXVersion() >= MAC_OS_X_VERSION_11_0_HEX));
+ return ((macOSVersion() >= MACOS_VERSION_10_16_HEX) ||
+ (macOSVersion() >= MACOS_VERSION_11_0_HEX));
}
/* static */ bool
nsCocoaFeatures::IsAtLeastVersion(int32_t aMajor, int32_t aMinor, int32_t aBugFix)
{
- return OSXVersion() >= GetVersion(aMajor, aMinor, aBugFix);
+ return macOSVersion() >= GetVersion(aMajor, aMinor, aBugFix);
}