mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
CPColor: Add default DarkAqua system color definitions
System colors previously provided default fallback values only for Aqua. Consequently, themes lacking explicit dark overrides rendered every system color—including labelColor—with its light Aqua value inside dark views. CPColor now maintains default color tables for all selectable system appearances: the existing Aqua set, a complete DarkAqua set using AppKit's sRGB DarkAqua values, and two empty high-contrast tables. Two DarkAqua colors use Cappuccino-specific values: textInsertionPointColor is white, and selectedTextBackgroundColor is dark blue. System color resolution continues to prioritize active theme values before falling back to default definitions. Default lookups resolve against the theme-supported variant of the target appearance, ensuring Aqua-only themes retain Aqua system colors even within dark views. Vibrant and high-contrast appearances fall back to the standard color table matching their lightness.
This commit is contained in:
1 parent
175fa1dcab
commit
cd3372e2b1
2 files changed
+414
-12
No files matched your search
+139
-12
@@ -86,8 +86,8 @@ var _CPColorSystemCatalogName = @"System";
|
||||
var _CPColorThemeCatalogName = @"Theme";
|
||||
|
||||
/*
|
||||
The colours of the System catalog, with each colour's value when the current theme gives
|
||||
it none. These are the names that Interface Builder writes into a XIB and that AppKit
|
||||
The colours of the System catalog, with each colour's built-in value for the Aqua
|
||||
appearance, which applies when the current theme gives none (see _CPSystemColorBuiltInSets). These are the names that Interface Builder writes into a XIB and that AppKit
|
||||
resolves, including older names that it still resolves and one private name. Where
|
||||
Cappuccino already produced a value, the entry keeps it: the four colours that CPColor
|
||||
and Aristo2 already defined, and the three that nib2cib maps (controlColor,
|
||||
@@ -163,11 +163,138 @@ var _CPSystemColorDefaults = {
|
||||
"windowFrameColor": [0.6667, 0.6667, 0.6667, 1.0],
|
||||
"windowFrameTextColor": [0.0, 0.0, 0.0, 0.8471]
|
||||
},
|
||||
/*
|
||||
The system colours whose DarkAqua value differs from their entry in
|
||||
_CPSystemColorDefaults: AppKit's DarkAqua value on macOS 27.2.1, in sRGB. Two entries
|
||||
are Cappuccino's own. textInsertionPointColor is white, the dark value of textColor,
|
||||
because AppKit's black cannot show on the dark text background. selectedTextBackgroundColor
|
||||
is a dark blue, because the Aqua entry is a blue and AppKit gives only a grey. Every other
|
||||
name keeps its Aqua entry in DarkAqua. See _CPSystemColorBuiltInSets.
|
||||
*/
|
||||
_CPSystemColorDarkAquaChanges = {
|
||||
"_sourceListBackgroundColor": [0.1765, 0.1765, 0.1765, 0.9],
|
||||
"alternateSelectedControlColor": [0.0, 0.349, 0.8196, 1.0],
|
||||
"alternatingContentBackgroundColor": [1.0, 1.0, 1.0, 0.0471],
|
||||
"controlBackgroundColor": [0.1176, 0.1176, 0.1176, 1.0],
|
||||
"controlColor": [1.0, 1.0, 1.0, 0.2471],
|
||||
"controlHighlightColor": [1.0, 1.0, 1.0, 0.098],
|
||||
"controlLightHighlightColor": [1.0, 1.0, 1.0, 0.098],
|
||||
"controlTextColor": [1.0, 1.0, 1.0, 0.8471],
|
||||
"disabledControlTextColor": [1.0, 1.0, 1.0, 0.2471],
|
||||
"gridColor": [0.102, 0.102, 0.102, 1.0],
|
||||
"headerColor": [1.0, 1.0, 1.0, 1.0],
|
||||
"headerTextColor": [1.0, 1.0, 1.0, 1.0],
|
||||
"highlightColor": [0.7059, 0.7059, 0.7059, 1.0],
|
||||
"keyboardFocusIndicatorColor": [0.102, 0.6627, 1.0, 0.498],
|
||||
"labelColor": [1.0, 1.0, 1.0, 0.8471],
|
||||
"linkColor": [0.2549, 0.6118, 1.0, 1.0],
|
||||
"placeholderTextColor": [1.0, 1.0, 1.0, 0.549],
|
||||
"quaternaryLabelColor": [1.0, 1.0, 1.0, 0.098],
|
||||
"quaternarySystemFillColor": [1.0, 1.0, 1.0, 0.0275],
|
||||
"quinaryLabelColor": [1.0, 1.0, 1.0, 0.0471],
|
||||
"quinarySystemFillColor": [1.0, 1.0, 1.0, 0.0078],
|
||||
"secondaryLabelColor": [1.0, 1.0, 1.0, 0.549],
|
||||
"secondarySelectedControlColor": [0.2745, 0.2745, 0.2745, 1.0],
|
||||
"secondarySystemFillColor": [1.0, 1.0, 1.0, 0.0784],
|
||||
"selectedContentBackgroundColor": [0.0, 0.349, 0.8196, 1.0],
|
||||
"selectedControlColor": [0.2471, 0.2471, 0.2471, 1.0],
|
||||
"selectedControlTextColor": [1.0, 1.0, 1.0, 0.8471],
|
||||
"selectedTextBackgroundColor": [0.2471, 0.3882, 0.5451, 1.0],
|
||||
"separatorColor": [1.0, 1.0, 1.0, 0.12],
|
||||
"systemBlueColor": [0.0, 0.5686, 1.0, 1.0],
|
||||
"systemBrownColor": [0.7176, 0.5412, 0.4, 1.0],
|
||||
"systemCyanColor": [0.2353, 0.8275, 0.9961, 1.0],
|
||||
"systemFillColor": [1.0, 1.0, 1.0, 0.098],
|
||||
"systemGrayColor": [0.5961, 0.5961, 0.6157, 1.0],
|
||||
"systemGreenColor": [0.1882, 0.8196, 0.3451, 1.0],
|
||||
"systemIndigoColor": [0.4275, 0.4863, 1.0, 1.0],
|
||||
"systemMintColor": [0.0, 0.8549, 0.7647, 1.0],
|
||||
"systemOrangeColor": [1.0, 0.5725, 0.1882, 1.0],
|
||||
"systemPinkColor": [1.0, 0.2157, 0.3725, 1.0],
|
||||
"systemPurpleColor": [0.8588, 0.2039, 0.949, 1.0],
|
||||
"systemRedColor": [1.0, 0.2588, 0.2706, 1.0],
|
||||
"systemTealColor": [0.0, 0.8235, 0.8784, 1.0],
|
||||
"systemYellowColor": [1.0, 0.8392, 0.0, 1.0],
|
||||
"tertiaryLabelColor": [1.0, 1.0, 1.0, 0.2471],
|
||||
"tertiarySystemFillColor": [1.0, 1.0, 1.0, 0.0471],
|
||||
"textBackgroundColor": [0.1176, 0.1176, 0.1176, 1.0],
|
||||
"textColor": [1.0, 1.0, 1.0, 1.0],
|
||||
"textInsertionPointColor": [1.0, 1.0, 1.0, 1.0],
|
||||
"underPageBackgroundColor": [0.1569, 0.1569, 0.1569, 1.0],
|
||||
"unemphasizedSelectedContentBackgroundColor": [0.2745, 0.2745, 0.2745, 1.0],
|
||||
"unemphasizedSelectedTextBackgroundColor": [0.2745, 0.2745, 0.2745, 1.0],
|
||||
"unemphasizedSelectedTextColor": [1.0, 1.0, 1.0, 1.0],
|
||||
"windowBackgroundColor": [0.1176, 0.1176, 0.1176, 1.0],
|
||||
"windowFrameTextColor": [1.0, 1.0, 1.0, 0.8471]
|
||||
},
|
||||
_CPSystemColors = {},
|
||||
_CPSystemColorDefaultValues = {},
|
||||
_CPSystemColorBuiltInColors = {},
|
||||
_CPThemeColors = {},
|
||||
_CPThemeColorMissingNames = {};
|
||||
|
||||
/*
|
||||
Returns a set of built-in values that holds every name of _CPSystemColorDefaults: the entry
|
||||
in someChanges where it has one, else the Aqua entry.
|
||||
*/
|
||||
function _CPSystemColorSetWithChanges(someChanges)
|
||||
{
|
||||
var values = {};
|
||||
|
||||
for (var colorName in _CPSystemColorDefaults)
|
||||
values[colorName] = someChanges.hasOwnProperty(colorName) ? someChanges[colorName] : _CPSystemColorDefaults[colorName];
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
/*
|
||||
The built-in values of the system colours, one set for each appearance that the system can
|
||||
select, found by the appearance's name. The Aqua set is _CPSystemColorDefaults, and the
|
||||
DarkAqua set is complete too. A high-contrast set holds a name only when its value differs
|
||||
from the set of normal contrast; both are empty, because no source gives such values yet.
|
||||
There is no vibrant set: a vibrant appearance takes the set of the plain appearance of its
|
||||
lightness, through the order of _CPAppearanceMatchingNames().
|
||||
*/
|
||||
var _CPSystemColorBuiltInSets = {};
|
||||
|
||||
_CPSystemColorBuiltInSets[CPAppearanceNameAqua] = _CPSystemColorDefaults;
|
||||
_CPSystemColorBuiltInSets[CPAppearanceNameDarkAqua] = _CPSystemColorSetWithChanges(_CPSystemColorDarkAquaChanges);
|
||||
_CPSystemColorBuiltInSets[CPAppearanceNameAccessibilityHighContrastAqua] = {};
|
||||
_CPSystemColorBuiltInSets[CPAppearanceNameAccessibilityHighContrastDarkAqua] = {};
|
||||
|
||||
/*
|
||||
Returns the built-in value of the system colour aName for anAppearance. The lookup takes
|
||||
the supported form of anAppearance under the default theme (see _CPAppearanceSupportedName),
|
||||
so a theme without dark controls gets no dark values around its light ones. It then takes
|
||||
the first set, in the order of _CPAppearanceMatchingNames(), that holds aName, and the Aqua
|
||||
set when none does. The values are made once for each set and kept.
|
||||
*/
|
||||
function _CPSystemColorBuiltInValue(aName, anAppearance)
|
||||
{
|
||||
var appearanceName = anAppearance ? _CPAppearanceSupportedName([anAppearance name]) : CPAppearanceNameAqua,
|
||||
matchingNames = _CPAppearanceMatchingNames(appearanceName).concat([CPAppearanceNameAqua]);
|
||||
|
||||
for (var i = 0, count = matchingNames.length; i < count; i++)
|
||||
{
|
||||
var setName = matchingNames[i],
|
||||
values = _CPSystemColorBuiltInSets[setName];
|
||||
|
||||
if (!values || !values.hasOwnProperty(aName))
|
||||
continue;
|
||||
|
||||
var colors = _CPSystemColorBuiltInColors[setName];
|
||||
|
||||
if (!colors)
|
||||
colors = _CPSystemColorBuiltInColors[setName] = {};
|
||||
|
||||
if (!colors.hasOwnProperty(aName))
|
||||
colors[aName] = [[CPColor alloc] _initWithRGBA:values[aName].slice()];
|
||||
|
||||
return colors[aName];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the theme attribute of CPColor that holds a theme's values for the system colour
|
||||
aName: the name in lower case with words joined by hyphens, as the attributes that CPColor
|
||||
@@ -183,9 +310,14 @@ function _CPThemeAttributeForSystemColorName(aName)
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the value of the system colour aName for anAppearance: the current theme's value for
|
||||
anAppearance (see _CPThemeAttributeValueForAppearance), then the value in
|
||||
_CPSystemColorDefaults.
|
||||
Returns the value of the system colour aName for anAppearance, in two steps. First the
|
||||
current theme's value: the value for the closest appearance, then the value without a state
|
||||
(see _CPThemeAttributeValueForAppearance). A value without a state is a value for every
|
||||
appearance, as everywhere in CPTheme, so it comes before the built-in value. Then the
|
||||
built-in value (see _CPSystemColorBuiltInValue).
|
||||
|
||||
The built-in values had only the Aqua set, so every theme that gave no dark value of its own
|
||||
drew a system colour, labelColor for example, in its Aqua value in a dark view.
|
||||
*/
|
||||
function _CPSystemColorValue(aName, anAppearance)
|
||||
{
|
||||
@@ -195,12 +327,7 @@ function _CPSystemColorValue(aName, anAppearance)
|
||||
if (themeValue)
|
||||
return themeValue;
|
||||
|
||||
var defaultValue = _CPSystemColorDefaultValues[aName];
|
||||
|
||||
if (!defaultValue)
|
||||
defaultValue = _CPSystemColorDefaultValues[aName] = [[CPColor alloc] _initWithRGBA:_CPSystemColorDefaults[aName].slice()];
|
||||
|
||||
return defaultValue;
|
||||
return _CPSystemColorBuiltInValue(aName, anAppearance);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
* CPSystemColorDarkAquaTest.j
|
||||
* AppKit
|
||||
*
|
||||
* Created by David Richardson on 2026-11-18.
|
||||
* Copyright David Richardson 2026.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import <AppKit/AppKit.j>
|
||||
|
||||
/*
|
||||
A system colour has a built-in value for Aqua and for DarkAqua, with AppKit's values. The
|
||||
built-in value applies when the default theme gives none, and it takes the supported form
|
||||
of the appearance: under a theme that supports Aqua only, a dark view gets the Aqua value.
|
||||
|
||||
The names of the System catalog: the 66 public names and the private source list name.
|
||||
*/
|
||||
var CPSystemColorDarkAquaTestNames = [
|
||||
"_sourceListBackgroundColor",
|
||||
"alternateSelectedControlColor", "alternateSelectedControlTextColor", "alternatingContentBackgroundColor",
|
||||
"controlAccentColor", "controlBackgroundColor", "controlColor", "controlDarkShadowColor", "controlHighlightColor",
|
||||
"controlLightHighlightColor", "controlShadowColor", "controlTextColor", "disabledControlTextColor", "findHighlightColor",
|
||||
"gridColor", "headerColor", "headerTextColor", "highlightColor", "keyboardFocusIndicatorColor", "knobColor", "labelColor",
|
||||
"linkColor", "placeholderTextColor", "quaternaryLabelColor", "quaternarySystemFillColor", "quinaryLabelColor",
|
||||
"quinarySystemFillColor", "scrollBarColor", "secondaryLabelColor", "secondarySelectedControlColor",
|
||||
"secondarySystemFillColor", "selectedContentBackgroundColor", "selectedControlColor", "selectedControlTextColor",
|
||||
"selectedKnobColor", "selectedMenuItemColor", "selectedMenuItemTextColor", "selectedTextBackgroundColor",
|
||||
"selectedTextColor", "separatorColor", "shadowColor", "systemBlueColor", "systemBrownColor", "systemCyanColor",
|
||||
"systemFillColor", "systemGrayColor", "systemGreenColor", "systemIndigoColor", "systemMintColor", "systemOrangeColor",
|
||||
"systemPinkColor", "systemPurpleColor", "systemRedColor", "systemTealColor", "systemYellowColor", "tertiaryLabelColor",
|
||||
"tertiarySystemFillColor", "textBackgroundColor", "textColor", "textInsertionPointColor", "underPageBackgroundColor",
|
||||
"unemphasizedSelectedContentBackgroundColor", "unemphasizedSelectedTextBackgroundColor", "unemphasizedSelectedTextColor",
|
||||
"windowBackgroundColor", "windowFrameColor", "windowFrameTextColor"
|
||||
];
|
||||
|
||||
@implementation CPSystemColorDarkAquaTest : OJTestCase
|
||||
{
|
||||
CPTheme _previousTheme;
|
||||
}
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
// This will init the global var CPApp which are used internally in the AppKit
|
||||
[[CPApplication alloc] init];
|
||||
|
||||
_previousTheme = [CPTheme defaultTheme];
|
||||
[CPTheme setDefaultTheme:[self themeSupporting:[CPAppearanceNameAqua, CPAppearanceNameDarkAqua] labelColors:nil]];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
[CPTheme setDefaultTheme:_previousTheme];
|
||||
[CPAppearance setCurrentAppearance:nil];
|
||||
}
|
||||
|
||||
// MARK: Helpers
|
||||
|
||||
/*
|
||||
Returns a theme whose attribute "supported-appearances" holds someNames, or a theme with no
|
||||
list when someNames is nil. someLabelColors maps a theme state, or nil for no state, to a
|
||||
value of labelColor; with nil the theme gives no system colour a value.
|
||||
*/
|
||||
- (CPTheme)themeSupporting:(CPArray)someNames labelColors:(CPArray)someLabelColors
|
||||
{
|
||||
var theme = [[CPTheme alloc] initWithName:@"CPSystemColorDarkAquaTest"],
|
||||
template = [CPColor colorWithWhite:0.0 alpha:1.0];
|
||||
|
||||
if (someNames)
|
||||
[template setValue:someNames forThemeAttribute:@"supported-appearances"];
|
||||
|
||||
for (var i = 0; someLabelColors && i < someLabelColors.length; i += 2)
|
||||
{
|
||||
if (someLabelColors[i])
|
||||
[template setValue:someLabelColors[i + 1] forThemeAttribute:@"label-color" inState:someLabelColors[i]];
|
||||
else
|
||||
[template setValue:someLabelColors[i + 1] forThemeAttribute:@"label-color"];
|
||||
}
|
||||
|
||||
[theme takeThemeFromObject:template];
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the value of the system colour aName while the appearance named anAppearanceName
|
||||
is the drawing appearance.
|
||||
*/
|
||||
- (CPColor)systemColor:(CPString)aName in:(CPString)anAppearanceName
|
||||
{
|
||||
var color = [CPColor colorWithCatalogName:@"System" colorName:aName],
|
||||
resolvedColor = nil;
|
||||
|
||||
[[CPAppearance appearanceNamed:anAppearanceName] performAsCurrentDrawingAppearance:function()
|
||||
{
|
||||
resolvedColor = [color colorUsingColorSpaceName:nil];
|
||||
}];
|
||||
|
||||
return resolvedColor;
|
||||
}
|
||||
|
||||
- (void)assertComponents:(CPArray)expected of:(CPColor)aColor
|
||||
{
|
||||
var components = [aColor components];
|
||||
|
||||
for (var i = 0; i < 4; i++)
|
||||
[self assert:ROUND(expected[i] * 10000) equals:ROUND(components[i] * 10000) message:[aColor description] + ", component " + i];
|
||||
}
|
||||
|
||||
// MARK: The built-in sets
|
||||
|
||||
- (void)testEveryNameHasAnAquaAndADarkAquaValue
|
||||
{
|
||||
var missing = [];
|
||||
|
||||
CPSystemColorDarkAquaTestNames.forEach(function(aName)
|
||||
{
|
||||
[CPAppearanceNameAqua, CPAppearanceNameDarkAqua].forEach(function(anAppearanceName)
|
||||
{
|
||||
if (![self systemColor:aName in:anAppearanceName])
|
||||
missing.push(aName + " in " + anAppearanceName);
|
||||
});
|
||||
});
|
||||
|
||||
[self assert:67 equals:CPSystemColorDarkAquaTestNames.length];
|
||||
[self assertTrue:missing.length === 0 message:missing.join("\n")];
|
||||
}
|
||||
|
||||
- (void)testADarkAppearanceTakesAppKitsDarkAquaValues
|
||||
{
|
||||
[self assertComponents:[1.0, 1.0, 1.0, 0.8471] of:[self systemColor:@"labelColor" in:CPAppearanceNameDarkAqua]];
|
||||
[self assertComponents:[0.1176, 0.1176, 0.1176, 1.0] of:[self systemColor:@"windowBackgroundColor" in:CPAppearanceNameDarkAqua]];
|
||||
[self assertComponents:[1.0, 1.0, 1.0, 0.12] of:[self systemColor:@"separatorColor" in:CPAppearanceNameDarkAqua]];
|
||||
[self assertComponents:[0.0, 0.5686, 1.0, 1.0] of:[self systemColor:@"systemBlueColor" in:CPAppearanceNameDarkAqua]];
|
||||
}
|
||||
|
||||
- (void)testAnAquaAppearanceKeepsTheAquaValues
|
||||
{
|
||||
[self assertComponents:[0.0, 0.0, 0.0, 0.8471] of:[self systemColor:@"labelColor" in:CPAppearanceNameAqua]];
|
||||
[self assertComponents:[1.0, 1.0, 1.0, 1.0] of:[self systemColor:@"windowBackgroundColor" in:CPAppearanceNameAqua]];
|
||||
}
|
||||
|
||||
/*
|
||||
A name whose AppKit value is the same in both appearances keeps its Aqua entry, Cappuccino's
|
||||
own shadowColor among them.
|
||||
*/
|
||||
- (void)testANameWithoutADarkValueKeepsItsAquaEntry
|
||||
{
|
||||
[self assertComponents:[0.0, 0.0, 0.0, 1.0 / 3.0] of:[self systemColor:@"shadowColor" in:CPAppearanceNameDarkAqua]];
|
||||
[self assertComponents:[1.0, 1.0, 1.0, 1.0] of:[self systemColor:@"selectedMenuItemTextColor" in:CPAppearanceNameDarkAqua]];
|
||||
}
|
||||
|
||||
/*
|
||||
Two dark values are Cappuccino's own: the insertion point is white, so that it shows on the
|
||||
dark text background, and the selected text background is a dark blue.
|
||||
*/
|
||||
- (void)testTheDarkValuesThatAreCappuccinosOwn
|
||||
{
|
||||
[self assertComponents:[1.0, 1.0, 1.0, 1.0] of:[self systemColor:@"textInsertionPointColor" in:CPAppearanceNameDarkAqua]];
|
||||
[self assertComponents:[0.2471, 0.3882, 0.5451, 1.0] of:[self systemColor:@"selectedTextBackgroundColor" in:CPAppearanceNameDarkAqua]];
|
||||
}
|
||||
|
||||
/*
|
||||
There is no vibrant set, and the high-contrast sets are empty: each of these appearances
|
||||
takes the value of the plain appearance of its lightness.
|
||||
*/
|
||||
- (void)testHighContrastAndVibrantAppearancesTakeThePlainValueOfTheirLightness
|
||||
{
|
||||
var dark = [1.0, 1.0, 1.0, 0.8471],
|
||||
light = [0.0, 0.0, 0.0, 0.8471];
|
||||
|
||||
[self assertComponents:dark of:[self systemColor:@"labelColor" in:CPAppearanceNameVibrantDark]];
|
||||
[self assertComponents:dark of:[self systemColor:@"labelColor" in:CPAppearanceNameAccessibilityHighContrastDarkAqua]];
|
||||
[self assertComponents:dark of:[self systemColor:@"labelColor" in:CPAppearanceNameAccessibilityHighContrastVibrantDark]];
|
||||
[self assertComponents:light of:[self systemColor:@"labelColor" in:CPAppearanceNameVibrantLight]];
|
||||
[self assertComponents:light of:[self systemColor:@"labelColor" in:CPAppearanceNameAccessibilityHighContrastAqua]];
|
||||
[self assertComponents:light of:[self systemColor:@"labelColor" in:CPAppearanceNameAccessibilityHighContrastVibrantLight]];
|
||||
}
|
||||
|
||||
// MARK: The order of the lookup
|
||||
|
||||
- (void)testAThemeValueKeyedByTheAppearanceComesFirst
|
||||
{
|
||||
[CPTheme setDefaultTheme:[self themeSupporting:[CPAppearanceNameAqua, CPAppearanceNameDarkAqua]
|
||||
labelColors:[CPThemeStateAppearanceDarkAqua, [CPColor blueColor]]]];
|
||||
|
||||
[self assert:[CPColor blueColor] equals:[self systemColor:@"labelColor" in:CPAppearanceNameDarkAqua]];
|
||||
[self assertComponents:[0.0, 0.0, 0.0, 0.8471] of:[self systemColor:@"labelColor" in:CPAppearanceNameAqua]];
|
||||
}
|
||||
|
||||
/*
|
||||
A theme value without a state is a value for every appearance, so it comes before the
|
||||
built-in dark value.
|
||||
*/
|
||||
- (void)testAThemeValueWithoutAStateComesBeforeTheBuiltInValue
|
||||
{
|
||||
[CPTheme setDefaultTheme:[self themeSupporting:[CPAppearanceNameAqua, CPAppearanceNameDarkAqua]
|
||||
labelColors:[nil, [CPColor redColor]]]];
|
||||
|
||||
[self assert:[CPColor redColor] equals:[self systemColor:@"labelColor" in:CPAppearanceNameDarkAqua]];
|
||||
[self assert:[CPColor redColor] equals:[self systemColor:@"labelColor" in:CPAppearanceNameAqua]];
|
||||
}
|
||||
|
||||
// MARK: The supported form
|
||||
|
||||
/*
|
||||
Under a theme that supports Aqua only, a view with the DarkAqua appearance keeps that
|
||||
appearance, but the built-in values take their Aqua form, so they agree with the light
|
||||
controls around them.
|
||||
*/
|
||||
- (void)testUnderAnAquaOnlyThemeADarkViewTakesTheAquaValues
|
||||
{
|
||||
[CPTheme setDefaultTheme:[self themeSupporting:[CPAppearanceNameAqua] labelColors:nil]];
|
||||
|
||||
var view = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 10.0, 10.0)];
|
||||
|
||||
[view setAppearance:[CPAppearance appearanceNamed:CPAppearanceNameDarkAqua]];
|
||||
|
||||
[self assert:CPAppearanceNameDarkAqua equals:[[view effectiveAppearance] name]];
|
||||
[self assertComponents:[0.0, 0.0, 0.0, 0.8471] of:[self systemColor:@"labelColor" in:CPAppearanceNameDarkAqua]];
|
||||
[self assertComponents:[0.0, 0.0, 0.0, 0.8471] of:[self systemColor:@"labelColor" in:CPAppearanceNameVibrantDark]];
|
||||
}
|
||||
|
||||
- (void)testAThemeWithoutAListTakesTheAquaValues
|
||||
{
|
||||
[CPTheme setDefaultTheme:[self themeSupporting:nil labelColors:nil]];
|
||||
|
||||
[self assertComponents:[1.0, 1.0, 1.0, 1.0] of:[self systemColor:@"windowBackgroundColor" in:CPAppearanceNameDarkAqua]];
|
||||
}
|
||||
|
||||
/*
|
||||
The supported form limits only the built-in values. A value that the theme keys by DarkAqua
|
||||
applies under a theme that supports Aqua only.
|
||||
*/
|
||||
- (void)testUnderAnAquaOnlyThemeAThemeValueForDarkAquaStillApplies
|
||||
{
|
||||
[CPTheme setDefaultTheme:[self themeSupporting:[CPAppearanceNameAqua]
|
||||
labelColors:[CPThemeStateAppearanceDarkAqua, [CPColor blueColor]]]];
|
||||
|
||||
[self assert:[CPColor blueColor] equals:[self systemColor:@"labelColor" in:CPAppearanceNameDarkAqua]];
|
||||
}
|
||||
|
||||
/*
|
||||
Under a theme that supports DarkAqua only, a light view takes the dark values.
|
||||
*/
|
||||
- (void)testUnderADarkOnlyThemeALightViewTakesTheDarkValues
|
||||
{
|
||||
[CPTheme setDefaultTheme:[self themeSupporting:[CPAppearanceNameDarkAqua] labelColors:nil]];
|
||||
|
||||
[self assertComponents:[1.0, 1.0, 1.0, 0.8471] of:[self systemColor:@"labelColor" in:CPAppearanceNameAqua]];
|
||||
}
|
||||
|
||||
- (void)testACatalogColorFollowsAThemeSwitch
|
||||
{
|
||||
[CPTheme setDefaultTheme:[self themeSupporting:[CPAppearanceNameAqua] labelColors:nil]];
|
||||
[self assertComponents:[0.0, 0.0, 0.0, 0.8471] of:[self systemColor:@"labelColor" in:CPAppearanceNameDarkAqua]];
|
||||
|
||||
[CPTheme setDefaultTheme:[self themeSupporting:[CPAppearanceNameAqua, CPAppearanceNameDarkAqua] labelColors:nil]];
|
||||
[self assertComponents:[1.0, 1.0, 1.0, 0.8471] of:[self systemColor:@"labelColor" in:CPAppearanceNameDarkAqua]];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user