Merge remote-tracking branch 'upstream/main' into Aristo3

This commit is contained in:
daboe01 committed 2026-03-25 19:33:44 +01:00
commit e49144c80a
4 files changed
+431 -161

No files matched your search

+31 -32
View File
@@ -51,6 +51,7 @@ CPColorPickerViewWidth = 265;
CPColorPickerViewHeight = 370;
CPColorPanelColorDidChangeNotification = @"CPColorPanelColorDidChangeNotification";
CPColorDragType = @"CPColorDragType";
var PREVIEW_HEIGHT = 20.0,
TOOLBAR_HEIGHT = 32.0,
@@ -129,8 +130,6 @@ var SharedColorPanel = nil,
if (self)
{
//[[self contentView] setBackgroundColor:[CPColor colorWithWhite:0.95 alpha:1.0]];
[self setTitle:@"Color Panel"];
[self setLevel:CPFloatingWindowLevel];
@@ -149,9 +148,13 @@ var SharedColorPanel = nil,
*/
- (void)setColor:(CPColor)aColor
{
if ([_color isEqual:aColor])
return;
_color = aColor;
[_previewView setBackgroundColor:_color];
// Push color via Responder Chain (targets First Responder, i.e., the active CPColorWell)
[CPApp sendAction:@selector(changeColor:) to:nil from:self];
if (_target && _action)
@@ -161,8 +164,11 @@ var SharedColorPanel = nil,
postNotificationName:CPColorPanelColorDidChangeNotification
object:self];
[_activePicker setColor:_color];
[_opacitySlider setFloatValue:[_color alphaComponent]];
if (_activePicker)
[_activePicker setColor:_color];
if (_opacitySlider)
[_opacitySlider setFloatValue:[_color alphaComponent]];
}
/*!
@@ -174,7 +180,7 @@ var SharedColorPanel = nil,
{
[self setColor:aColor];
if (bool)
if (bool && _activePicker)
[_activePicker setColor:_color];
}
@@ -332,7 +338,7 @@ var SharedColorPanel = nil,
buttonForLater = button;
}
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
// Preview
var previewBox = [[CPView alloc] initWithFrame:CGRectMake(76, TOOLBAR_HEIGHT + 10, CGRectGetWidth(bounds) - 86, PREVIEW_HEIGHT)];
_previewView = [[_CPColorPanelPreview alloc] initWithFrame:CGRectInset([previewBox bounds], 2.0, 2.0)];
@@ -350,7 +356,7 @@ var SharedColorPanel = nil,
[_previewLabel setTextColor:[CPColor blackColor]];
[_previewLabel setAlignment:CPRightTextAlignment];
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
// Swatches
var swatchBox = [[CPView alloc] initWithFrame:CGRectMake(76, TOOLBAR_HEIGHT + 10 + PREVIEW_HEIGHT + 5, CGRectGetWidth(bounds) - 86, SWATCH_HEIGHT + 2.0)];
[swatchBox setBackgroundColor:[CPColor colorWithWhite:0.8 alpha:1.0]];
@@ -391,8 +397,6 @@ var SharedColorPanel = nil,
[contentView addSubview:opacityLabel];
[contentView addSubview:_opacitySlider];
_target = nil;
_action = nil;
_activePicker = nil;
[_previewView setBackgroundColor:_color];
@@ -412,8 +416,6 @@ var SharedColorPanel = nil,
@end
CPColorDragType = "CPColorDragType";
var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
/* @ignore */
@@ -431,7 +433,7 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
[self setBackgroundColor:[CPColor grayColor]];
[self registerForDraggedTypes:[CPArray arrayWithObjects:CPColorDragType]];
[self registerForDraggedTypes:[CPArray arrayWithObjects:@"CPColorDragType"]];
var whiteColor = [CPColor whiteColor];
@@ -442,7 +444,6 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
for (var i = 0; i < 50; i++)
{
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
var view = [[CPView alloc] initWithFrame:CGRectMake(13 * i + 1, 1, 12, 12)],
fillView = [[CPView alloc] initWithFrame:CGRectInset([view bounds], 1.0, 1.0)];
@@ -494,7 +495,6 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
- (CPArray)saveColorList
{
var result = [];
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
for (var i = 0; i < _swatches.length; i++)
result.push([[[_swatches[i] subviews][0] backgroundColor] hexString]);
@@ -521,7 +521,6 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
- (void)setColor:(CPColor)aColor atIndex:(int)index
{
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
[[_swatches[index] subviews][0] setBackgroundColor:aColor];
[self saveColorList];
}
@@ -544,16 +543,11 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
if (point.x > [self bounds].size.width - 1 || point.x < 1)
return NO;
[[CPPasteboard pasteboardWithName:CPDragPboard] declareTypes:[CPArray arrayWithObject:CPColorDragType] owner:self];
var swatch = _swatches[FLOOR(point.x / 13)];
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
_dragColor = [[swatch subviews][0] backgroundColor];
var bounds = CGRectMakeCopy([swatch bounds]);
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
var dragView = [[CPView alloc] initWithFrame:bounds],
dragFillView = [[CPView alloc] initWithFrame:CGRectInset(bounds, 1.0, 1.0)];
@@ -562,18 +556,22 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
[dragView addSubview:dragFillView];
var pasteboard = [CPPasteboard pasteboardWithName:CPDragPboard];
[pasteboard declareTypes:[CPArray arrayWithObject:@"CPColorDragType"] owner:self];
[pasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:_dragColor] forType:@"CPColorDragType"];
[self dragView:dragView
at:CGPointMake(point.x - bounds.size.width / 2.0, point.y - bounds.size.height / 2.0)
offset:CGPointMake(0.0, 0.0)
event:anEvent
pasteboard:nil
pasteboard:pasteboard
source:self
slideBack:YES];
}
- (void)pasteboard:(CPPasteboard)aPasteboard provideDataForType:(CPString)aType
{
if (aType == CPColorDragType)
if (aType == @"CPColorDragType")
[aPasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:_dragColor] forType:aType];
}
@@ -583,10 +581,10 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
pasteboard = [aSender draggingPasteboard],
swatch = nil;
if (![pasteboard availableTypeFromArray:[CPColorDragType]] || location.x > [self bounds].size.width - 1 || location.x < 1)
if (![pasteboard availableTypeFromArray:[@"CPColorDragType"]] || location.x > [self bounds].size.width - 1 || location.x < 1)
return NO;
[self setColor:[CPKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:CPColorDragType]] atIndex:FLOOR(location.x / 13)];
[self setColor:[CPKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:@"CPColorDragType"]] atIndex:FLOOR(location.x / 13)];
}
@end
@@ -601,7 +599,7 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
{
self = [super initWithFrame:aFrame];
[self registerForDraggedTypes:[CPArray arrayWithObjects:CPColorDragType]];
[self registerForDraggedTypes:[CPArray arrayWithObjects:@"CPColorDragType"]];
return self;
}
@@ -620,10 +618,10 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
{
var pasteboard = [aSender draggingPasteboard];
if (![pasteboard availableTypeFromArray:[CPColorDragType]])
if (![pasteboard availableTypeFromArray:[@"CPColorDragType"]])
return NO;
var color = [CPKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:CPColorDragType]];
var color = [CPKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:@"CPColorDragType"]];
[_colorPanel setColor:color updatePicker:YES];
}
@@ -636,11 +634,8 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
{
var point = [self convertPoint:[anEvent locationInWindow] fromView:nil];
[[CPPasteboard pasteboardWithName:CPDragPboard] declareTypes:[CPColorDragType] owner:self];
var bounds = CGRectMake(0, 0, 15, 15);
// FIXME: http://280north.lighthouseapp.com/projects/13294-cappuccino/tickets/25-implement-cpbox
var dragView = [[CPView alloc] initWithFrame:bounds],
dragFillView = [[CPView alloc] initWithFrame:CGRectInset(bounds, 1.0, 1.0)];
@@ -649,18 +644,22 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
[dragView addSubview:dragFillView];
var pasteboard = [CPPasteboard pasteboardWithName:CPDragPboard];
[pasteboard declareTypes:[CPArray arrayWithObject:@"CPColorDragType"] owner:self];
[pasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:[self backgroundColor]] forType:@"CPColorDragType"];
[self dragView:dragView
at:CGPointMake(point.x - bounds.size.width / 2.0, point.y - bounds.size.height / 2.0)
offset:CGPointMake(0.0, 0.0)
event:anEvent
pasteboard:nil
pasteboard:pasteboard
source:self
slideBack:YES];
}
- (void)pasteboard:(CPPasteboard)aPasteboard provideDataForType:(CPString)aType
{
if (aType == CPColorDragType)
if (aType == @"CPColorDragType")
[aPasteboard setData:[CPKeyedArchiver archivedDataWithRootObject:[self backgroundColor]] forType:aType];
}
+143 -129
View File
@@ -26,7 +26,6 @@
@import "CPColor.j"
@import "CPColorPanel.j"
var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiveNotification";
/*!
@@ -39,10 +38,9 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
*/
@implementation CPColorWell : CPControl
{
BOOL _active;
BOOL _bordered;
CPColor _color;
BOOL _isChangingColorFromPanel; // Guard flag to prevent recursion
}
+ (Class)_binderClassForBinding:(CPString)aBinding
@@ -77,52 +75,54 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
[theBinding reverseSetValueFor:@"color"];
}
- (BOOL)isFirstResponder
{
return [[self window] firstResponder] === self;
}
- (BOOL)acceptsFirstResponder
{
return [self isEnabled];
}
- (void)activate:(BOOL)shouldBeExclusive
{
[[self window] makeFirstResponder:self];
[[CPColorPanel sharedColorPanel] orderFront:self];
}
- (BOOL)isActive
{
return [self isFirstResponder] && [self isEnabled];
}
/*!
Deactivates the color well.
*/
- (void)deactivate
{
if ([self isFirstResponder])
[[self window] makeFirstResponder:nil];
}
- (id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if (self)
{
_active = NO;
_color = [CPColor whiteColor];
[self setBordered:YES];
// Register using string literal to avoid dependency issues
[self registerForDraggedTypes:[CPArray arrayWithObject:@"CPColorDragType"]];
}
return self;
}
- (void)_registerNotifications
{
var defaultCenter = [CPNotificationCenter defaultCenter];
[defaultCenter
addObserver:self
selector:@selector(colorWellDidBecomeExclusive:)
name:_CPColorWellDidBecomeExclusiveNotification
object:nil];
[defaultCenter
addObserver:self
selector:@selector(colorPanelWillClose:)
name:CPWindowWillCloseNotification
object:[CPColorPanel sharedColorPanel]];
}
- (void)_removeNotifications
{
var defaultCenter = [CPNotificationCenter defaultCenter];
[defaultCenter
removeObserver:self
name:_CPColorWellDidBecomeExclusiveNotification
object:nil];
[defaultCenter
removeObserver:self
name:CPWindowWillCloseNotification
object:[CPColorPanel sharedColorPanel]];
}
#pragma mark -
#pragma mark Draw
/*!
Sets whether the color well is bordered.
@@ -143,7 +143,8 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
return [self hasThemeState:CPThemeStateBordered];
}
// Managing Color From Color Wells
#pragma mark -
#pragma mark Managing Color
/*!
Returns the color well's current color.
@@ -158,12 +159,17 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
*/
- (void)setColor:(CPColor)aColor
{
if (_color == aColor)
if ([_color isEqual:aColor])
return;
_color = aColor;
[self setNeedsLayout];
// Only push back to the panel if we initiated the change (not if the panel pushed it to us)
// AND if we are the current focus.
if (!_isChangingColorFromPanel && [self isFirstResponder])
[[CPColorPanel sharedColorPanel] setColor:_color];
}
/*!
@@ -175,96 +181,127 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
[self setColor:[aSender color]];
}
// Activating and Deactivating Color Wells
/*!
Standard action method sent by CPColorPanel via the Responder Chain.
*/
- (void)changeColor:(id)aSender
{
if ([aSender isKindOfClass:[CPColorPanel class]])
{
_isChangingColorFromPanel = YES;
[self setColor:[aSender color]];
_isChangingColorFromPanel = NO;
// Forward the action to our target (e.g. controller)
[self sendAction:[self action] to:[self target]];
}
}
#pragma mark -
#pragma mark Activating and Deactivating
/*!
Activates the color well, displays the color panel, and makes the panel's current color the same as its own.
If exclusive is \c YES, deactivates any other CPColorWells. \c NO, keeps them active.
@param shouldBeExclusive whether other color wells should be deactivated.
*/
- (void)activate:(BOOL)shouldBeExclusive
- (BOOL)becomeFirstResponder
{
if (shouldBeExclusive)
// FIXME: make this queue!
[[CPNotificationCenter defaultCenter]
postNotificationName:_CPColorWellDidBecomeExclusiveNotification
object:self];
[self setThemeState:CPThemeStateFirstResponder];
var panel = [CPColorPanel sharedColorPanel];
// EXPLICITLY set ourselves as the target.
// This ensures that when the user clicks the panel (making Panel key),
// the panel still knows to send messages back to us.
[panel setTarget:self];
[panel setAction:@selector(changeColor:)];
// Sync panel to our current color
[panel setColor:_color];
if ([self isActive])
return;
_active = YES;
[[CPNotificationCenter defaultCenter]
addObserver:self
selector:@selector(colorPanelDidChangeColor:)
name:CPColorPanelColorDidChangeNotification
object:[CPColorPanel sharedColorPanel]];
[[CPNotificationCenter defaultCenter] postNotificationName:_CPColorWellDidBecomeExclusiveNotification object:self];
return YES;
}
/*!
Deactivates the color well.
*/
- (void)deactivate
- (BOOL)resignFirstResponder
{
if (![self isActive])
return;
[self unsetThemeState:CPThemeStateFirstResponder];
var panel = [CPColorPanel sharedColorPanel];
_active = NO;
[[CPNotificationCenter defaultCenter]
removeObserver:self
name:CPColorPanelColorDidChangeNotification
object:[CPColorPanel sharedColorPanel]];
// Clean up if we were the target
if ([panel target] == self)
[panel setTarget:nil];
return YES;
}
/*!
Returns \c YES if the color well is active.
*/
- (BOOL)isActive
#pragma mark -
#pragma mark Event Handling
- (void)mouseDown:(CPEvent)anEvent
{
return _active;
}
- (void)colorPanelDidChangeColor:(CPNotification)aNotification
{
[self takeColorFrom:[aNotification object]];
[self sendAction:[self action] to:[self target]];
}
- (void)colorWellDidBecomeExclusive:(CPNotification)aNotification
{
if (self != [aNotification object])
[self deactivate];
}
- (void)colorPanelWillClose:(CPNotification)aNotification
{
[self deactivate];
}
- (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
{
[self highlight:NO];
if (!mouseIsUp || !CGRectContainsPoint([self bounds], aPoint) || ![self isEnabled])
if (![self isEnabled])
return;
[self activate:YES];
var colorPanel = [CPColorPanel sharedColorPanel];
[colorPanel setPlatformWindow:[[self window] platformWindow]];
[colorPanel setColor:_color];
[colorPanel orderFront:self];
}
#pragma mark -
#pragma mark Drag and Drop
- (void)draggingEntered:(id)sender
{
var pasteboard = [sender draggingPasteboard];
if ([[pasteboard types] containsObject:@"CPColorDragType"])
{
[self setThemeState:CPThemeStateHighlighted];
return CPDragOperationCopy;
}
return CPDragOperationNone;
}
- (void)draggingExited:(id)sender
{
[self unsetThemeState:CPThemeStateHighlighted];
}
- (BOOL)performDragOperation:(id)sender
{
var pasteboard = [sender draggingPasteboard];
if ([[pasteboard types] containsObject:@"CPColorDragType"])
{
var data = [pasteboard dataForType:@"CPColorDragType"],
newColor = [CPKeyedUnarchiver unarchiveObjectWithData:data];
if (newColor && [newColor isKindOfClass:[CPColor class]])
{
[self setColor:newColor];
[self sendAction:[self action] to:[self target]];
// Activate nicely after drop
[self activate:YES];
[self unsetThemeState:CPThemeStateHighlighted];
return YES;
}
}
return NO;
}
#pragma mark -
#pragma mark Layout
- (CGRect)contentRectForBounds:(CGRect)bounds
{
var contentInset = [self currentValueForThemeAttribute:@"content-inset"];
return CGRectInsetByInset(bounds, contentInset);
}
@@ -318,7 +355,6 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
positioned:CPWindowAbove
relativeToEphemeralSubviewNamed:@"bezel-view"];
[contentView setBackgroundColor:_color];
var contentBorderView = [self layoutEphemeralSubviewNamed:@"content-border-view"
@@ -328,28 +364,6 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv
[contentBorderView setBackgroundColor:[self currentValueForThemeAttribute:@"content-border-color"]];
}
#pragma mark -
#pragma mark Observers method
- (void)_addObservers
{
if (_isObserving)
return;
[super _addObservers];
[self _registerNotifications];
}
- (void)_removeObservers
{
if (!_isObserving)
return;
[super _removeObservers];
[self _removeNotifications];
}
@end
@implementation CPColorWellValueBinder : CPBinder
@@ -398,9 +412,9 @@ var CPColorWellColorKey = "CPColorWellColorKey",
if (self)
{
_active = NO;
_color = [aCoder decodeObjectForKey:CPColorWellColorKey];
[self setBordered:[aCoder decodeBoolForKey:CPColorWellBorderedKey]];
[self registerForDraggedTypes:[CPArray arrayWithObject:@"CPColorDragType"]];
}
return self;
+184
View File
@@ -0,0 +1,184 @@
/*
* CPColorPanelTest.j
* AppKit
*
* Created to test CPColorPanel architectural refactoring.
*/
@import <AppKit/CPColorPanel.j>
/*
* Mock color picker for testing
*/
@implementation _MockColorPicker : CPObject
{
CPArray _receivedColors;
CPView _view;
}
- (id)init
{
if (self = [super init])
{
_receivedColors = [];
_view = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
}
return self;
}
- (void)setColor:(CPColor)aColor
{
[_receivedColors addObject:aColor];
}
- (CPArray)receivedColors
{
return _receivedColors;
}
- (CPView)provideNewView:(BOOL)initial
{
return _view;
}
@end
@implementation CPColorPanelTest : OJTestCase
{
CPColorPanel _panel;
}
- (void)setUp
{
// Get shared panel and ensure it's initialized
_panel = [CPColorPanel sharedColorPanel];
[_panel _loadContentsIfNecessary];
}
- (void)tearDown
{
// Reset panel state between tests
[_panel setColor:[CPColor whiteColor]];
}
/*
* Test that setting a color updates the opacity slider to match the color's alpha component.
* This ensures the slider always reflects the current color's opacity.
*/
- (void)testSetColorUpdatesOpacitySlider
{
var initialColor = [CPColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5];[_panel setColor:initialColor];
[self assert:0.5 equals:[_panel._opacitySlider floatValue]
message:"Opacity slider should match the color's alpha component"];
}
/*
* Test that setOpacity: creates a new color with the correct alpha value.
*/
- (void)testOpacityChangeUpdatesColorAlpha
{
var initialColor = [CPColor colorWithRed:0.5 green:0.5 blue:1.0 alpha:1.0];
[_panel setColor:initialColor];[_panel._opacitySlider setFloatValue:0.3];
[_panel setOpacity:_panel._opacitySlider];
var newColor = [_panel color];
[self assert:0.3 equals:[newColor alphaComponent]
message:"Color's alpha should match slider value"];
// RGB components should remain unchanged
var components = [newColor components];
[self assert:0.5 equals:components[0] message:"Red component should be unchanged"];
[self assert:0.5 equals:components[1] message:"Green component should be unchanged"];
[self assert:1.0 equals:components[2] message:"Blue component should be unchanged"];
}
/*
* Test that the active picker receives setColor: when a color changes.
* Regression test: active picker was not notified of color changes.
*/
- (void)testActivePickerNotifiedOfColorChanges
{
var mockPicker = [[_MockColorPicker alloc] init];
_panel._activePicker = mockPicker;
var color1 = [CPColor redColor];
var color2 = [CPColor blueColor];
[_panel setColor:color1];
[_panel setColor:color2];
var receivedColors = [mockPicker receivedColors];
[self assert:2 equals:[receivedColors count]
message:"Active picker should receive setColor for each color change"];
[self assert:color1 same:receivedColors[0]];
[self assert:color2 same:receivedColors[1]];
}
/*
* Test that a picker receives setColor: when it becomes active.
* Regression test: picker was not notified of current color on activation.
*/
- (void)testPickerNotifiedOnActivation
{
var testColor = [CPColor colorWithRed:0.5 green:0.5 blue:1.0 alpha:1.0];
[_panel setColor:testColor];
var mockPicker = [[_MockColorPicker alloc] init];
_panel._colorPickers = [mockPicker];
var button = [[CPButton alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
[button setTag:0];
[_panel _setPicker:button];
var receivedColors = [mockPicker receivedColors];
[self assert:1 equals:[receivedColors count]
message:"Picker should receive setColor when activated"];
[self assert:testColor same:receivedColors[0]];
}
/*
* Test that opacity() method returns the current color's alpha component.
*/
- (void)testOpacityMethodReturnsAlpha
{
var testColor = [CPColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.42];
[_panel setColor:testColor];
[self assert:0.42 equals:[_panel opacity]
message:"opacity method should return color's alpha component"];
}
/*
* Test that setColor: with equal color does not trigger updates.
* This is an optimization to prevent unnecessary work.
*/
- (void)testSetColorWithEqualColorDoesNothing
{
var testColor = [CPColor colorWithRed:1.0 green:0.5 blue:0.0 alpha:0.7];
[_panel setColor:testColor];
var mockPicker = [[_MockColorPicker alloc] init];
_panel._activePicker = mockPicker;
// Set same color again
[_panel setColor:testColor];
var receivedColors = [mockPicker receivedColors];
[self assert:0 equals:[receivedColors count]
message:"Setting equal color should not trigger picker update"];
}
/*
* Test color() method returns the current color.
*/
- (void)testColorMethodReturnsCurrentColor
{
var testColor = [CPColor colorWithRed:0.2 green:0.4 blue:0.6 alpha:0.8];[_panel setColor:testColor];
[self assert:testColor same:[_panel color]
message:"color method should return current color"];
}
@end
+73
View File
@@ -31,4 +31,77 @@
[self assert:[CPColor greenColor] equals:[colorWell color] message:"color well archived color"];
}
/**
* Tests that color well objects maintain visual state consistency.
*
* Validates the object's responsibility to synchronize public properties
* with internal theme state management.
*/
- (void)testColorWellMaintainsVisualStateConsistency
{
[colorWell setBordered:NO];
[self assertFalse:[colorWell isBordered] message:"object correctly reports bordered state"];
[colorWell setBordered:YES];
[self assertTrue:[colorWell isBordered] message:"object correctly reports changed bordered state"];
}
/**
* Tests that color well objects properly handle activation responsibilities.
*
* Validates the object's role in responder chain participation and
* exclusive activation behavior.
*/
- (void)testColorWellHandlesActivationResponsibilities
{
// Note: We test activation through observable effects, not internal state
[colorWell activate:YES];
[self assertTrue:[colorWell acceptsFirstResponder] message:"activated object accepts responder chain participation"];
}
/**
* Tests that disabled color well objects behave appropriately.
*
* Validates the object's responsibility to modify its behavior
* when in a disabled state.
*/
- (void)testDisabledColorWellModifiesBehaviorAppropriately
{
[colorWell setEnabled:NO];
[self assertFalse:[colorWell acceptsFirstResponder] message:"disabled object modifies responder behavior"];
[colorWell setEnabled:YES];
[self assertTrue:[colorWell acceptsFirstResponder] message:"re-enabled object restores normal behavior"];
}
/**
* Tests that color well objects interact correctly with other wells.
*
* Validates the object's responsibility to handle exclusive activation
* scenarios with other color well instances.
*/
- (void)testColorWellInteractsCorrectlyWithOtherWells
{
var well1 = colorWell,
well2 = [[CPColorWell alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[well1 activate:YES]; // Exclusive activation
[well2 activate:NO]; // Non-exclusive should still work
[self assertTrue:[well2 acceptsFirstResponder] message:"objects maintain independence where appropriate"];
}
/**
* Tests basic color assignment functionality.
*
* Validates the core contract: setting a color should change what's
* returned by the color getter.
*/
- (void)testBasicColorAssignment
{
var testColor = [CPColor colorWithCalibratedRed:0.2 green:0.4 blue:0.6 alpha:0.8];
[colorWell setColor:testColor];
[self assert:[colorWell color] equals:testColor message:"object correctly handles color assignment"];
}
@end