Skip to content

Commit

Permalink
Remove NSAppearance.isHighContrast
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Sep 25, 2024
1 parent 239c976 commit d043a8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
15 changes: 1 addition & 14 deletions CotEditor/Sources/Extensions/AppKit/NSAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 7 additions & 6 deletions CotEditor/Sources/Views/FormPopUpButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -109,7 +110,7 @@ final class FormPopUpButtonCell: NSPopUpButtonCell {
fillPath.fill()
}

if appearance.isHighContrast {
if isHighContrast {
let strokeColor: NSColor = self.isEnabled ? .labelColor : .quaternaryLabelColor

strokeColor.setStroke()
Expand All @@ -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)
Expand Down

0 comments on commit d043a8e

Please sign in to comment.