diff --git a/widget/cocoa/nsMacDockSupport.mm b/widget/cocoa/nsMacDockSupport.mm index 94c07b9de185..7929755aa14f 100644 --- a/widget/cocoa/nsMacDockSupport.mm +++ b/widget/cocoa/nsMacDockSupport.mm @@ -8,6 +8,7 @@ #include "nsComponentManagerUtils.h" #include "nsMacDockSupport.h" #include "nsObjCExceptions.h" +#include "nsNativeThemeColors.h" NS_IMPL_ISUPPORTS(nsMacDockSupport, nsIMacDockSupport, nsITaskbarProgress) @@ -44,12 +45,12 @@ NS_IMPL_ISUPPORTS(nsMacDockSupport, nsIMacDockSupport, nsITaskbarProgress) [[NSColor colorWithDeviceWhite:0 alpha:0.1] setFill]; [path fill]; - // Draw a blue or gray fill (depending on graphite or not) for the progress part. + // Draw a fill in the control accent color for the progress part. NSRect progressFillRect = self.bounds; progressFillRect.size.width *= mFractionValue; [NSGraphicsContext saveGraphicsState]; [NSBezierPath clipRect:progressFillRect]; - [[NSColor keyboardFocusIndicatorColor] setFill]; + [ControlAccentColor() setFill]; [path fill]; [NSGraphicsContext restoreGraphicsState]; diff --git a/widget/cocoa/nsNativeThemeCocoa.mm b/widget/cocoa/nsNativeThemeCocoa.mm index 441725315cfe..338f5fd9d1f7 100644 --- a/widget/cocoa/nsNativeThemeCocoa.mm +++ b/widget/cocoa/nsNativeThemeCocoa.mm @@ -2664,12 +2664,6 @@ void nsNativeThemeCocoa::DrawSourceList(CGContextRef cgContext, const CGRect& in CGColorSpaceRelease(rgb); } -#if !defined(MAC_OS_X_VERSION_10_14) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_14 -@interface NSColor (NSColorControlAccentColor) -@property(class, strong, readonly) NSColor* controlAccentColor NS_AVAILABLE_MAC(10_14); -@end -#endif - void nsNativeThemeCocoa::DrawSourceListSelection(CGContextRef aContext, const CGRect& aRect, bool aWindowIsActive, bool aSelectionIsActive) { if (!nsCocoaFeatures::OnYosemiteOrLater()) { @@ -2688,16 +2682,7 @@ void nsNativeThemeCocoa::DrawSourceListSelection(CGContextRef aContext, const CG NSColor* fillColor; if (aSelectionIsActive) { // Active selection, blue or graphite. - if (@available(macOS 10.14, *)) { - fillColor = [NSColor controlAccentColor]; - } else { - // Pre-10.14, use hardcoded colors. - if ([NSColor currentControlTint] == NSGraphiteControlTint) { - fillColor = [NSColor colorWithSRGBRed:0.635 green:0.635 blue:0.655 alpha:1.0]; - } else { - fillColor = [NSColor colorWithSRGBRed:0.247 green:0.584 blue:0.965 alpha:1.0]; - } - } + fillColor = ControlAccentColor(); } else { // Inactive selection, gray. if (aWindowIsActive) { diff --git a/widget/cocoa/nsNativeThemeColors.h b/widget/cocoa/nsNativeThemeColors.h index 670eea59b715..b896b536dabd 100644 --- a/widget/cocoa/nsNativeThemeColors.h +++ b/widget/cocoa/nsNativeThemeColors.h @@ -31,20 +31,37 @@ static const int sYosemiteThemeColors[][2] = { {0xB3, 0xD1}, // bottom separator line }; -__attribute__((unused)) static int NativeGreyColorAsInt(ColorName name, BOOL isMain) { +inline int NativeGreyColorAsInt(ColorName name, BOOL isMain) { if (nsCocoaFeatures::OnYosemiteOrLater()) return sYosemiteThemeColors[name][isMain ? 0 : 1]; return sLionThemeColors[name][isMain ? 0 : 1]; } -__attribute__((unused)) static float NativeGreyColorAsFloat(ColorName name, BOOL isMain) { +inline float NativeGreyColorAsFloat(ColorName name, BOOL isMain) { return NativeGreyColorAsInt(name, isMain) / 255.0f; } -__attribute__((unused)) static void DrawNativeGreyColorInRect(CGContextRef context, ColorName name, - CGRect rect, BOOL isMain) { +inline void DrawNativeGreyColorInRect(CGContextRef context, ColorName name, CGRect rect, + BOOL isMain) { float grey = NativeGreyColorAsFloat(name, isMain); CGContextSetRGBFillColor(context, grey, grey, grey, 1.0f); CGContextFillRect(context, rect); } +#if !defined(MAC_OS_X_VERSION_10_14) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_14 +@interface NSColor (NSColorControlAccentColor) +@property(class, strong, readonly) NSColor* controlAccentColor NS_AVAILABLE_MAC(10_14); +@end +#endif + +inline NSColor* ControlAccentColor() { + if (@available(macOS 10.14, *)) { + return [NSColor controlAccentColor]; + } + + // Pre-10.14, use hardcoded colors. + return [NSColor currentControlTint] == NSGraphiteControlTint + ? [NSColor colorWithSRGBRed:0.635 green:0.635 blue:0.655 alpha:1.0] + : [NSColor colorWithSRGBRed:0.247 green:0.584 blue:0.965 alpha:1.0]; +} + #endif // nsNativeThemeColors_h_