diff --git a/AppKit/CPRuleEditor/CPRuleEditor.j b/AppKit/CPRuleEditor/CPRuleEditor.j index 404c5546e..141e06d63 100644 --- a/AppKit/CPRuleEditor/CPRuleEditor.j +++ b/AppKit/CPRuleEditor/CPRuleEditor.j @@ -2121,7 +2121,7 @@ TODO: implement return; var point = [self convertPoint:[event locationInWindow] fromView:nil], - view = [_slices objectAtIndex:FLOOR(point.y / _sliceHeight)]; + view = [_slices objectAtIndex:FLOOR(MAX(0, point.y) / _sliceHeight)]; if ([self _dragShouldBeginFromMouseDown:view]) [self _performDragForSlice:view withEvent:event]; diff --git a/AppKit/CPTabView.j b/AppKit/CPTabView.j index cb09a6639..12899624b 100644 --- a/AppKit/CPTabView.j +++ b/AppKit/CPTabView.j @@ -34,6 +34,8 @@ CPNoTabsBezelBorder = 4; //Displays no tabs and has a bezeled border. CPNoTabsLineBorder = 5; //Has no tabs and displays a line border. CPNoTabsNoBorder = 6; //Displays no tabs and no border. +@class _CPTabViewBox + var CPTabViewDidSelectTabViewItemSelector = 1 << 1, CPTabViewShouldSelectTabViewItemSelector = 1 << 2, CPTabViewWillSelectTabViewItemSelector = 1 << 3, @@ -64,7 +66,7 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1, CPArray _items; CPSegmentedControl _tabs; - CPBox _box; + _CPTabViewBox _box; CPView _placeHolderView; CPTabViewItem _selectedTabViewItem; @@ -97,7 +99,8 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1, var height = [_tabs valueForThemeAttribute:@"min-size"].height; [_tabs setFrameSize:CGSizeMake(0, height)]; - _box = [[CPBox alloc] initWithFrame:[self bounds]]; + _box = [[_CPTabViewBox alloc] initWithFrame:[self bounds]]; + [_box setTabView:self]; [self setBackgroundColor:[CPColor colorWithCalibratedWhite:0.95 alpha:1.0]]; [self addSubview:_box]; @@ -634,6 +637,17 @@ var CPTabViewDidSelectTabViewItemSelector = 1 << 1, [self _displayItemView:_placeHolderView]; } +#pragma mark - +#pragma mark Override + +/*! + Enabled controls accept first mouse by default. +*/ +- (BOOL)acceptsFirstMouse:(CPEvent)anEvent +{ + return YES; +} + @end var _CPTabViewContentBinderNull = @"NO CONTENT"; @@ -806,3 +820,26 @@ var CPTabViewItemsKey = "CPTabViewItemsKey", } @end + +@implementation _CPTabViewBox : CPBox +{ + CPTabView _tabView @accessors(property=tabView); +} + + +#pragma mark - +#pragma mark Override + +- (CPView)hitTest:(CGPoint)aPoint +{ + // Here we check if we have clicked on the segmentedControl of the tabView or not + // If YES, the CPBox should not handle the click + var segmentIndex = [_tabView._tabs testSegment:[_tabView._tabs convertPoint:aPoint fromView:[self superview]]]; + + if (segmentIndex != CPNotFound) + return nil; + + return [super hitTest:aPoint]; +} + +@end \ No newline at end of file diff --git a/AppKit/CPView.j b/AppKit/CPView.j index d40d1ad6f..089b6d07e 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -295,27 +295,6 @@ var CPViewHighDPIDrawingEnabled = YES; return CPViewHighDPIDrawingEnabled; } -- (void)_setupViewFlags -{ - var theClass = [self class], - classUID = [theClass UID]; - - if (CPViewFlags[classUID] === undefined) - { - var flags = 0; - - if ([theClass instanceMethodForSelector:@selector(drawRect:)] !== [CPView instanceMethodForSelector:@selector(drawRect:)]) - flags |= CPViewHasCustomDrawRect; - - if ([theClass instanceMethodForSelector:@selector(layoutSubviews)] !== [CPView instanceMethodForSelector:@selector(layoutSubviews)]) - flags |= CPViewHasCustomLayoutSubviews; - - CPViewFlags[classUID] = flags; - } - - _viewClassFlags = CPViewFlags[classUID]; -} - + (CPSet)keyPathsForValuesAffectingFrame { return [CPSet setWithObjects:@"frameOrigin", @"frameSize"]; @@ -331,11 +310,23 @@ var CPViewHighDPIDrawingEnabled = YES; return nil; } -- (void)awakeFromCib +- (void)_setupViewFlags { - [super awakeFromCib]; + var theClass = [self class], + classUID = [theClass UID]; - [self _recomputeAppearance]; + if (CPViewFlags[classUID] === undefined) + { + var flags = 0; + + if ([theClass instanceMethodForSelector:@selector(drawRect:)] !== [CPView instanceMethodForSelector:@selector(drawRect:)] + || [theClass instanceMethodForSelector:@selector(viewWillDraw)] !== [CPView instanceMethodForSelector:@selector(viewWillDraw)]) + flags |= CPViewHasCustomDrawRect; + + CPViewFlags[classUID] = flags; + } + + _viewClassFlags = CPViewFlags[classUID]; } - (id)init @@ -392,7 +383,6 @@ var CPViewHighDPIDrawingEnabled = YES; #endif [self _setupViewFlags]; - [self _loadThemeAttributes]; } @@ -850,8 +840,7 @@ var CPViewHighDPIDrawingEnabled = YES; */ - (void)viewDidMoveToSuperview { - [self _recomputeAppearance]; - + [self setNeedsLayout:YES]; [self setNeedsDisplay:YES]; } @@ -2605,7 +2594,7 @@ setBoundsOrigin: } #if PLATFORM(DOM) - if (_needToSetTransformMatrix) + if (_needToSetTransformMatrix && _highDPIRatio !== 1) [_graphicsContext graphicsPort].setTransform(_highDPIRatio, 0, 0 , _highDPIRatio, 0, 0); #endif @@ -2632,7 +2621,7 @@ setBoundsOrigin: - (void)setNeedsLayout:(BOOL)needLayout { - if (!(_viewClassFlags & CPViewHasCustomLayoutSubviews) || !needLayout) + if (!needLayout) { _needsLayout = NO; return; @@ -2654,12 +2643,31 @@ setBoundsOrigin: { _needsLayout = NO; + [self viewWillLayout]; [self layoutSubviews]; + [self viewDidLayout]; } } +/*! + @ignore +*/ +- (void)viewWillLayout +{ + +} + +/*! + @ignore +*/ +- (void)viewDidLayout +{ + [self _recomputeAppearance]; +} + - (void)layoutSubviews { + } /*! @@ -3544,19 +3552,13 @@ setBoundsOrigin: _appearance = anAppearance; [self didChangeValueForKey:@"appearance"]; - [self _recomputeAppearance]; + [self setNeedsLayout:YES]; } /*! @ignore */ - (void)_recomputeAppearance { - // if we don't have a themeState, it means - // the view is not decoding from a cib, so we just return. - // this method will be called again in awakeFromCib - if (!_themeState) - return; - var effectiveAppearance = [self effectiveAppearance]; if ([effectiveAppearance isEqual:[CPAppearance appearanceNamed:CPAppearanceNameAqua]]) diff --git a/AppKit/CPVisualEffectView.j b/AppKit/CPVisualEffectView.j index ece566562..2618b611f 100644 --- a/AppKit/CPVisualEffectView.j +++ b/AppKit/CPVisualEffectView.j @@ -89,7 +89,8 @@ CPVisualEffectStateInactive = 2; [CPException raise:CPInvalidArgumentException reason:"Appearance can only be CPAppearanceNameVibrantDark or CPAppearanceNameVibrantLight in CPVisualEffectView, but is " + anAppearance]; [super setAppearance:anAppearance]; - [self _applyVibrancyState]; + + [self setNeedsLayout:YES]; } /*! Sets the received effect state. @@ -109,7 +110,7 @@ CPVisualEffectStateInactive = 2; _state = aState; [self didChangeValueForKey:"state"]; - [self _applyVibrancyState]; + [self setNeedsLayout:YES]; } @@ -131,7 +132,7 @@ CPVisualEffectStateInactive = 2; } -- (void)_applyVibrancyState +- (void)layoutSubviews { switch (_state) { @@ -155,52 +156,6 @@ CPVisualEffectStateInactive = 2; } -#pragma mark - -#pragma mark Overrides - -- (BOOL)setThemeState:(ThemeState)aState -{ - if (aState.isa && [aState isKindOfClass:CPArray]) - aState = CPThemeState.apply(null, aState); - - var r = [super setThemeState:aState]; - - if (r) - [self _applyVibrancyState]; - - return r; -} - -- (BOOL)unsetThemeState:(ThemeState)aState -{ - if (aState.isa && [aState isKindOfClass:CPArray]) - aState = CPThemeState.apply(null, aState); - - var r = [super unsetThemeState:aState]; - - if (r) - [self _applyVibrancyState]; - - return r; -} - -- (void)viewDidMoveToSuperview -{ - [super viewDidMoveToSuperview]; - - if (_superview) - [self _applyVibrancyState]; -} - -- (void)viewDidMoveToWindow -{ - [super viewDidMoveToWindow]; - - if (_window) - [self _applyVibrancyState]; -} - - #pragma mark - #pragma mark CPCoding diff --git a/AppKit/_CPToolTip.j b/AppKit/_CPToolTip.j index 6268f8ab4..296293d02 100644 --- a/AppKit/_CPToolTip.j +++ b/AppKit/_CPToolTip.j @@ -176,6 +176,8 @@ var _CPToolTipHeight = 24.0, _toolTipWindow = aWindow; _constrainsToUsableScreen = NO; + [self setPlatformWindow:[_toolTipWindow platformWindow]]; + textFrameSize.height += 4; _content = [CPTextField labelWithTitle:aString]; @@ -193,6 +195,7 @@ var _CPToolTipHeight = 24.0, [self setAlphaValue:0.9]; [_windowView setNeedsDisplay:YES]; + } return self; diff --git a/Foundation/CPArray/_CPJavaScriptArray.j b/Foundation/CPArray/_CPJavaScriptArray.j index 0246790dd..d0ed91782 100644 --- a/Foundation/CPArray/_CPJavaScriptArray.j +++ b/Foundation/CPArray/_CPJavaScriptArray.j @@ -91,7 +91,7 @@ var concat = Array.prototype.concat, - (id)initWithObjects:(CPArray)objects count:(CPUInteger)aCount { if ([objects isKindOfClass:_CPJavaScriptArray]) - return slice.call(objects, 0); + return slice.call(objects, 0, aCount); var array = [], index = 0; diff --git a/Tests/AppKit/CPViewTest.j b/Tests/AppKit/CPViewTest.j index b3f1b80e2..9c11b4de5 100644 --- a/Tests/AppKit/CPViewTest.j +++ b/Tests/AppKit/CPViewTest.j @@ -773,6 +773,8 @@ var methodCalled; - (void)testAppearanceDefaultvalue { + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + [self assert:nil equals:[view appearance]]; [self assertFalse:[view hasThemeState:CPThemeStateAppearanceVibrantDark]]; [self assertFalse:[view hasThemeState:CPThemeStateAppearanceVibrantLight]]; @@ -782,9 +784,10 @@ var methodCalled; - (void)testAppearanceWithVibrantDark { [view setAppearance:[CPAppearance appearanceNamed:CPAppearanceNameVibrantDark]]; - [self assert:[CPAppearance appearanceNamed:CPAppearanceNameVibrantDark] equals:[view appearance]]; [self assert:[CPAppearance appearanceNamed:CPAppearanceNameVibrantDark] equals:[view effectiveAppearance]]; + + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; [self assertTrue:[view hasThemeState:CPThemeStateAppearanceVibrantDark]]; [self assertFalse:[view hasThemeState:CPThemeStateAppearanceVibrantLight]]; } @@ -795,6 +798,8 @@ var methodCalled; [self assert:[CPAppearance appearanceNamed:CPAppearanceNameVibrantLight] equals:[view appearance]]; [self assert:[CPAppearance appearanceNamed:CPAppearanceNameVibrantLight] equals:[view effectiveAppearance]]; + + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; [self assertTrue:[view hasThemeState:CPThemeStateAppearanceVibrantLight]]; [self assertFalse:[view hasThemeState:CPThemeStateAppearanceVibrantDark]]; } @@ -806,6 +811,8 @@ var methodCalled; [self assert:nil equals:[view appearance]]; [self assert:nil equals:[view effectiveAppearance]]; + + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; [self assertFalse:[view hasThemeState:CPThemeStateAppearanceVibrantLight]]; [self assertFalse:[view hasThemeState:CPThemeStateAppearanceVibrantDark]]; } @@ -833,12 +840,14 @@ var methodCalled; [viewA addSubview:view]; + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; [self assert:[CPAppearance appearanceNamed:CPAppearanceNameVibrantLight] equals:[view effectiveAppearance]]; [self assertTrue:[view hasThemeState:CPThemeStateAppearanceVibrantLight]]; [self assertFalse:[view hasThemeState:CPThemeStateAppearanceVibrantDark]]; [viewB addSubview:view]; + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; [self assert:[CPAppearance appearanceNamed:CPAppearanceNameVibrantDark] equals:[view effectiveAppearance]]; [self assertFalse:[view hasThemeState:CPThemeStateAppearanceVibrantLight]]; [self assertTrue:[view hasThemeState:CPThemeStateAppearanceVibrantDark]]; diff --git a/Tests/Foundation/CPArrayTest.j b/Tests/Foundation/CPArrayTest.j index d3d1bb3b8..3b113fe00 100644 --- a/Tests/Foundation/CPArrayTest.j +++ b/Tests/Foundation/CPArrayTest.j @@ -11,6 +11,16 @@ return ConcreteArray; } +- (void)test_initWithObjects_count_ +{ + var arrayClass = [[self class] arrayClass], + array = [[arrayClass alloc] initWithObjects:[@"hello", @"bye", @"goodnight", @"seeya"] count:2]; + + [self assert:[array count] equals:2]; + [self assert:[array objectAtIndex:0] equals:@"hello"]; + [self assert:[array objectAtIndex:1] equals:@"bye"]; +} + - (void)test_containsObject_ { var arrayClass = [[self class] arrayClass], @@ -763,6 +773,21 @@ return self; } +- (id)initWithObjects:(CPArray)objects count:(CPUInteger)aCount +{ + self = [super init]; + + if (self) + { + array = []; + + for (var index = 0; index < aCount; ++index) + array.push([objects objectAtIndex:index]); + } + + return self; +} + - (CPUInteger)count { return array.length; diff --git a/Tests/Foundation/CPMutableArrayTest.j b/Tests/Foundation/CPMutableArrayTest.j index cdc75b7b4..03d8129b3 100644 --- a/Tests/Foundation/CPMutableArrayTest.j +++ b/Tests/Foundation/CPMutableArrayTest.j @@ -555,6 +555,21 @@ return self; } +- (id)initWithObjects:(CPArray)objects count:(CPUInteger)aCount +{ + self = [super init]; + + if (self) + { + array = []; + + for (var index = 0; index < aCount; ++index) + array.push([objects objectAtIndex:index]); + } + + return self; +} + - (CPUInteger)count { return array.length;