diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 10b6a10c5..2821a8147 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]; } @@ -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]]) @@ -3718,7 +3720,6 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", _opacity = 1.0; [self setBackgroundColor:[aCoder decodeObjectForKey:CPViewBackgroundColorKey]]; - [self _setupViewFlags]; _theme = [CPTheme defaultTheme]; _themeClass = [aCoder decodeObjectForKey:CPViewThemeClassKey]; 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/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]];