From d043a8eebad75d9d32684af93b81f466f68176d5 Mon Sep 17 00:00:00 2001 From: 1024jp <1024jp@wolfrosch.com> Date: Wed, 25 Sep 2024 23:01:18 +0900 Subject: [PATCH] Remove NSAppearance.isHighContrast --- .../Sources/Extensions/AppKit/NSAppearance.swift | 15 +-------------- CotEditor/Sources/Views/FormPopUpButton.swift | 13 +++++++------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/CotEditor/Sources/Extensions/AppKit/NSAppearance.swift b/CotEditor/Sources/Extensions/AppKit/NSAppearance.swift index 712aa001e7..08c71034e9 100644 --- a/CotEditor/Sources/Extensions/AppKit/NSAppearance.swift +++ b/CotEditor/Sources/Extensions/AppKit/NSAppearance.swift @@ -27,26 +27,13 @@ import AppKit.NSAppearance extension NSAppearance { + /// The receiver is in the Dark Mode. final var isDark: Bool { self.bestMatch(from: [.aqua, .darkAqua]) == .darkAqua } - final var isHighContrast: Bool { - - switch self.name { - case .accessibilityHighContrastAqua, - .accessibilityHighContrastDarkAqua, - .accessibilityHighContrastVibrantLight, - .accessibilityHighContrastVibrantDark: - true - default: - false - } - } - - /// The corresponding appearance for the light/dark mode. /// /// - Parameter isDark: Whether the return value to be for dark mode or not. diff --git a/CotEditor/Sources/Views/FormPopUpButton.swift b/CotEditor/Sources/Views/FormPopUpButton.swift index eb07015faf..06251c1677 100644 --- a/CotEditor/Sources/Views/FormPopUpButton.swift +++ b/CotEditor/Sources/Views/FormPopUpButton.swift @@ -86,15 +86,16 @@ final class FormPopUpButtonCell: NSPopUpButtonCell { : cellFrame.maxX - width - 6 let rect = NSRect(x: x, y: cellFrame.minY + 3, width: width, height: cellFrame.height - 9) - let appearance = controlView.effectiveAppearance + let isDark = controlView.effectiveAppearance.isDark + let isHighContrast = NSWorkspace.shared.accessibilityDisplayShouldIncreaseContrast // draw capsule let fillPath = NSBezierPath(roundedRect: rect, xRadius: 4, yRadius: 4) - if self.isEnabled, !appearance.isDark, appearance.isHighContrast { + if self.isEnabled, !isDark, isHighContrast { NSGradient(starting: .init(white: 0.4, alpha: 1), ending: .init(white: 0.3, alpha: 1))! .draw(in: fillPath, angle: 90) } else { - let fillColor: NSColor = switch (appearance.isHighContrast, appearance.isDark, self.isEnabled) { + let fillColor: NSColor = switch (isHighContrast, isDark, self.isEnabled) { case (false, false, true): .quaternarySystemFill case (false, false, false): .quinarySystemFill case (false, true, true): .tertiarySystemFill @@ -109,7 +110,7 @@ final class FormPopUpButtonCell: NSPopUpButtonCell { fillPath.fill() } - if appearance.isHighContrast { + if isHighContrast { let strokeColor: NSColor = self.isEnabled ? .labelColor : .quaternaryLabelColor strokeColor.setStroke() @@ -118,10 +119,10 @@ final class FormPopUpButtonCell: NSPopUpButtonCell { // draw chevron let chevron: NSImage = .chevronUpChevronDownNarrow - let chevronColor: NSColor = switch (appearance.isHighContrast, self.isEnabled) { + let chevronColor: NSColor = switch (isHighContrast, self.isEnabled) { case (false, true): .controlTextColor case (false, false): .disabledControlTextColor - case (true, true): appearance.isDark ? .black : .selectedMenuItemTextColor + case (true, true): isDark ? .black : .selectedMenuItemTextColor case (true, false): .tertiaryLabelColor } chevron.tinted(with: chevronColor)