Files
cappuccino/Tests/AppKit/CPVisualEffectViewTest.j
David Richardson 774f1381d7 AppKit: Add appearance manager and effective appearance chain
Resolve effective appearance through view, superviews, window, appearance parent, application and system. Apply appearance theme state to each view at once, parent first. Lay out and draw each view under its effective appearance.

* _CPAppearanceManager.j: Add manager; derive system appearance from prefers-color-scheme, prefers-contrast and forced-colors media queries; notify application on change.

* CPAppearance.j: Add theme state composite and fallback order of nine appearances; add drawing appearance brackets; make application appearance default drawing appearance; decode shared instance by name.

* CPApplication.j: Adopt CPAppearanceCustomization; add appearance, effectiveAppearance and setAppearance:; pass changes to windows.

* CPWindow.j: Adopt CPAppearanceCustomization; inherit from attached sheet parent, parent window or application; pass changes to root views, child windows and sheet.

* _CPShadowWindowView.j: Take appearance of window view's window.

* _CPMenuWindow.j: Pass appearance to menu view and to menu item views outside view tree.

* CPView.j: Add effective appearance chain and viewDidChangeEffectiveAppearance; apply appearance state with KVO, layout and display; bracket layout and display with drawing appearance; resolve background colour under effective appearance; replace _currentAppearance with _appliedAppearance.

* CPTheme.j: Fall back through appearance order when no key with view's appearance state matches.

* _CPObject+Theme.j: Leave appearance states out of archived theme state.

* CPColor.j: Add -_resolvedColor to static colours.

* _CPImageAndTextView.j: Rewrite text colour on appearance change; compare CSS string as well as object in setTextColor:.

* CPImageView.j: Resolve image under effective appearance; apply image again on appearance change.

* CPPopover.j: Accept CPAppearance beside legacy integers; set effective appearance on popover window; archive appearance object under new key.

* _CPPopoverWindow.j: Remove integer appearance ivar and setter.

* _CPPopoverWindowView.j: Choose light or dark style from effective appearance.

* CPVisualEffectView.j: Remove own appearance setter; choose dark material from effective appearance.

* _CPCibWindowTemplate.j: Archive window appearance; set it on window before content view.

* CPSearchField.j: Bracket _layoutSubviews with effective appearance.

* CPButton.j, CPOutlineView.j, CPSearchField.j, CPSplitView.j, CPStackView.j, CPTextField.j, CPTokenField.j, _CPRuleEditorViewSliceRow.j: Send direct layout calls through _layoutSubviewsInEffectiveAppearance.

* _CPAppearanceManagerTest.j, CPApplicationAppearanceTest.j, CPWindowAppearanceTest.j, CPViewAppearanceTest.j, CPThemeAttributeAppearanceTest.j, CPVisualEffectViewTest.j, CPPopoverAppearanceTest.j: Add tests for system appearance, appearance chain, theme fallback, popover and visual effect view.

* CPAppearanceTest.j: Add tests for nil current appearance and decoded shared instance.

* CPViewTest.j: Expect application appearance as default effective appearance.

* Manual/CPAppearanceTest: Add application with asset catalog colour and image for each appearance.
2026-11-10 15:52:55 -06:00

114 lines
3.5 KiB
Plaintext

/*
* CPVisualEffectViewTest.j
* AppKit
*
* Created by David Richardson on 2026-11-10.
* 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>
@import <AppKit/CPVisualEffectView.j>
@implementation CPVisualEffectViewTest : OJTestCase
{
CPWindow window;
}
- (void)setUp
{
// This will init the global var CPApp which are used internally in the AppKit
[[CPApplication alloc] init];
window = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 400.0, 300.0) styleMask:CPTitledWindowMask];
}
- (void)tearDown
{
[CPApp setAppearance:nil];
}
- (CPVisualEffectView)effectView
{
return [[CPVisualEffectView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
}
/*
Returns the background colour that anEffectView takes when it lays out below a parent
with the appearance named aName.
*/
- (CPColor)backgroundColorOf:(CPVisualEffectView)anEffectView belowParentNamed:(CPString)aName
{
var parent = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 200.0)];
[parent setAppearance:[CPAppearance appearanceNamed:aName]];
[parent addSubview:anEffectView];
[[window contentView] addSubview:parent];
[anEffectView setNeedsLayout];
[anEffectView layoutIfNeeded];
return [anEffectView backgroundColor];
}
- (void)testAnyAppearanceIsAccepted
{
var view = [self effectView];
[view setAppearance:[CPAppearance appearanceNamed:CPAppearanceNameAqua]];
[self assert:[CPAppearance appearanceNamed:CPAppearanceNameAqua] same:[view appearance]];
[view setAppearance:[CPAppearance appearanceNamed:CPAppearanceNameDarkAqua]];
[self assert:[CPAppearance appearanceNamed:CPAppearanceNameDarkAqua] same:[view appearance]];
[view setAppearance:nil];
[self assertNull:[view appearance]];
}
- (void)testAViewMadeInCodeHasVibrantDark
{
[self assert:[CPAppearance appearanceNamed:CPAppearanceNameVibrantDark] same:[[self effectView] appearance]];
}
- (void)testWithoutAnAppearanceTheViewFollowsItsParent
{
var darkView = [self effectView],
lightView = [self effectView];
[darkView setAppearance:nil];
[lightView setAppearance:nil];
[self assertTrue:[[self backgroundColorOf:darkView belowParentNamed:CPAppearanceNameDarkAqua] isEqual:[CPColor colorWithHexString:@"1e1e1e"]]];
[self assertTrue:[[self backgroundColorOf:lightView belowParentNamed:CPAppearanceNameAqua] isEqual:[CPColor whiteColor]]];
}
- (void)testAViewArchivedWithoutAnAppearanceDecodes
{
var view = [self effectView],
decoded = nil;
[view setAppearance:nil];
[self assertNoThrow:function()
{
decoded = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:view]];
}];
[self assertNull:[decoded appearance]];
}
@end