1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsNativeThemeColors_h_
7 #define nsNativeThemeColors_h_
9 #import <Cocoa/Cocoa.h>
11 #include "nsCocoaFeatures.h"
12 #include "SDKDeclarations.h"
13 #include "mozilla/ColorScheme.h"
18 toolbarBottomBorderGrey
,
21 static const int sLionThemeColors
[][2] = {
22 /* { active window, inactive window } */
24 {0xD0, 0xF0}, // top separator line
25 {0xB2, 0xE1}, // fill color
26 {0x59, 0x87}, // bottom separator line
29 static const int sYosemiteThemeColors
[][2] = {
30 /* { active window, inactive window } */
32 {0xBD, 0xDF}, // top separator line
33 {0xD3, 0xF6}, // fill color
34 {0xB3, 0xD1}, // bottom separator line
37 inline int NativeGreyColorAsInt(ColorName name
, BOOL isMain
) {
38 return sYosemiteThemeColors
[name
][isMain
? 0 : 1];
41 inline float NativeGreyColorAsFloat(ColorName name
, BOOL isMain
) {
42 return NativeGreyColorAsInt(name
, isMain
) / 255.0f
;
45 inline void DrawNativeGreyColorInRect(CGContextRef context
, ColorName name
, CGRect rect
,
47 float grey
= NativeGreyColorAsFloat(name
, isMain
);
48 CGContextSetRGBFillColor(context
, grey
, grey
, grey
, 1.0f
);
49 CGContextFillRect(context
, rect
);
52 #if !defined(MAC_OS_X_VERSION_10_14) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_14
53 @interface
NSColor (NSColorControlAccentColor
)
54 @
property(class, strong
, readonly
) NSColor
* controlAccentColor
NS_AVAILABLE_MAC(10_14
);
58 inline NSColor
* ControlAccentColor() {
59 if (@
available(macOS
10.14, *)) {
60 return [NSColor controlAccentColor
];
63 // Pre-10.14, use hardcoded colors.
64 return [NSColor currentControlTint
] == NSGraphiteControlTint
65 ? [NSColor colorWithSRGBRed
:0.635 green
:0.635 blue
:0.655 alpha
:1.0]
66 : [NSColor colorWithSRGBRed
:0.247 green
:0.584 blue
:0.965 alpha
:1.0];
69 inline NSAppearance
* NSAppearanceForColorScheme(mozilla::ColorScheme aScheme
) {
70 if (@
available(macOS
10.14, *)) {
71 NSAppearanceName appearanceName
=
72 aScheme
== mozilla::ColorScheme::Light
? NSAppearanceNameAqua
: NSAppearanceNameDarkAqua
;
73 return [NSAppearance appearanceNamed
:appearanceName
];
75 return [NSAppearance appearanceNamed
:NSAppearanceNameAqua
];
78 #endif // nsNativeThemeColors_h_