Bug 1577120 - Use the control accent color for the dock download progress bar. r=spohl

Differential Revision: https://phabricator.services.mozilla.com/D79358
This commit is contained in:
Markus Stange 2020-06-12 17:03:31 +00:00
Родитель 67ffb08651
Коммит 885aebc919
3 изменённых файлов: 25 добавлений и 22 удалений

Просмотреть файл

@ -8,6 +8,7 @@
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsMacDockSupport.h" #include "nsMacDockSupport.h"
#include "nsObjCExceptions.h" #include "nsObjCExceptions.h"
#include "nsNativeThemeColors.h"
NS_IMPL_ISUPPORTS(nsMacDockSupport, nsIMacDockSupport, nsITaskbarProgress) NS_IMPL_ISUPPORTS(nsMacDockSupport, nsIMacDockSupport, nsITaskbarProgress)
@ -44,12 +45,12 @@ NS_IMPL_ISUPPORTS(nsMacDockSupport, nsIMacDockSupport, nsITaskbarProgress)
[[NSColor colorWithDeviceWhite:0 alpha:0.1] setFill]; [[NSColor colorWithDeviceWhite:0 alpha:0.1] setFill];
[path fill]; [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; NSRect progressFillRect = self.bounds;
progressFillRect.size.width *= mFractionValue; progressFillRect.size.width *= mFractionValue;
[NSGraphicsContext saveGraphicsState]; [NSGraphicsContext saveGraphicsState];
[NSBezierPath clipRect:progressFillRect]; [NSBezierPath clipRect:progressFillRect];
[[NSColor keyboardFocusIndicatorColor] setFill]; [ControlAccentColor() setFill];
[path fill]; [path fill];
[NSGraphicsContext restoreGraphicsState]; [NSGraphicsContext restoreGraphicsState];

Просмотреть файл

@ -2664,12 +2664,6 @@ void nsNativeThemeCocoa::DrawSourceList(CGContextRef cgContext, const CGRect& in
CGColorSpaceRelease(rgb); 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, void nsNativeThemeCocoa::DrawSourceListSelection(CGContextRef aContext, const CGRect& aRect,
bool aWindowIsActive, bool aSelectionIsActive) { bool aWindowIsActive, bool aSelectionIsActive) {
if (!nsCocoaFeatures::OnYosemiteOrLater()) { if (!nsCocoaFeatures::OnYosemiteOrLater()) {
@ -2688,16 +2682,7 @@ void nsNativeThemeCocoa::DrawSourceListSelection(CGContextRef aContext, const CG
NSColor* fillColor; NSColor* fillColor;
if (aSelectionIsActive) { if (aSelectionIsActive) {
// Active selection, blue or graphite. // Active selection, blue or graphite.
if (@available(macOS 10.14, *)) { fillColor = ControlAccentColor();
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];
}
}
} else { } else {
// Inactive selection, gray. // Inactive selection, gray.
if (aWindowIsActive) { if (aWindowIsActive) {

Просмотреть файл

@ -31,20 +31,37 @@ static const int sYosemiteThemeColors[][2] = {
{0xB3, 0xD1}, // bottom separator line {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]; if (nsCocoaFeatures::OnYosemiteOrLater()) return sYosemiteThemeColors[name][isMain ? 0 : 1];
return sLionThemeColors[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; return NativeGreyColorAsInt(name, isMain) / 255.0f;
} }
__attribute__((unused)) static void DrawNativeGreyColorInRect(CGContextRef context, ColorName name, inline void DrawNativeGreyColorInRect(CGContextRef context, ColorName name, CGRect rect,
CGRect rect, BOOL isMain) { BOOL isMain) {
float grey = NativeGreyColorAsFloat(name, isMain); float grey = NativeGreyColorAsFloat(name, isMain);
CGContextSetRGBFillColor(context, grey, grey, grey, 1.0f); CGContextSetRGBFillColor(context, grey, grey, grey, 1.0f);
CGContextFillRect(context, rect); 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_ #endif // nsNativeThemeColors_h_