FIXED: lot's of error with CPAppearance

This commit is contained in:
Antoine Mercadal committed 2015-08-14 01:44:22 -07:00
1 parent 547764e3c1
commit 7e4e1ec68f
3 files changed
+48 -38

No files matched your search

+20 -23
View File
@@ -244,7 +244,6 @@ var CPViewHighDPIDrawingEnabled = YES;
BOOL _allowsVibrancy @accessors(property=allowsVibrancy);
CPAppearance _appearance @accessors(getter=appearance);
CPAppearance _effectiveAppearance;
BOOL _effectiveAppearanceCached;
}
/*
@@ -332,6 +331,13 @@ var CPViewHighDPIDrawingEnabled = YES;
return nil;
}
- (void)awakeFromCib
{
[super awakeFromCib];
[self _recomputeAppearance];
}
- (id)init
{
return [self initWithFrame:CGRectMakeZero()];
@@ -374,8 +380,6 @@ var CPViewHighDPIDrawingEnabled = YES;
_theme = [CPTheme defaultTheme];
_themeState = CPThemeStateNormal;
_effectiveAppearanceCached = NO;
#if PLATFORM(DOM)
_DOMElement = DOMElementPrototype.cloneNode(false);
AppKitTagDOMElement(self, _DOMElement);
@@ -846,10 +850,9 @@ var CPViewHighDPIDrawingEnabled = YES;
*/
- (void)viewDidMoveToSuperview
{
[self setNeedsDisplay:YES];
[self _recomputeAppearance];
[self _resetCachedEffectiveAppearance];
[self _updateAppearanceThemeState];
[self setNeedsDisplay:YES];
}
/*!
@@ -3529,13 +3532,7 @@ setBoundsOrigin:
if (_appearance)
return _appearance;
if (_effectiveAppearanceCached)
return _effectiveAppearance;
_effectiveAppearance = [_superview effectiveAppearance];
_effectiveAppearanceCached = YES;
return _effectiveAppearance;
return [_superview effectiveAppearance];
}
- (void)setAppearance:(CPAppearance)anAppearance
@@ -3547,20 +3544,19 @@ setBoundsOrigin:
_appearance = anAppearance;
[self didChangeValueForKey:@"appearance"];
[self _resetCachedEffectiveAppearance];
[self _updateAppearanceThemeState];
[self _recomputeAppearance];
}
/*! @ignore
*/
- (void)_resetCachedEffectiveAppearance
- (void)_recomputeAppearance
{
_effectiveAppearanceCached = NO;
[_subviews makeObjectsPerformSelector:@selector(_resetCachedEffectiveAppearance)];
}
// 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;
- (void)_updateAppearanceThemeState
{
var effectiveAppearance = [self effectiveAppearance];
if ([effectiveAppearance isEqual:[CPAppearance appearanceNamed:CPAppearanceNameAqua]])
@@ -3598,6 +3594,8 @@ setBoundsOrigin:
[self unsetThemeState:CPThemeStateAppearanceVibrantLight];
[self unsetThemeState:CPThemeStateAppearanceVibrantDark];
}
[_subviews makeObjectsPerformSelector:@selector(_recomputeAppearance)];
}
@@ -3739,8 +3737,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
_themeAttributes[attributeName] = CPThemeAttributeDecode(aCoder, attributeName, attributes[count], _theme, themeClass);
}
_appearance = [aCoder decodeObjectForKey:CPViewAppearanceKey];
_effectiveAppearanceCached = NO;
[self setAppearance:[aCoder decodeObjectForKey:CPViewAppearanceKey]];
[self setNeedsDisplay:YES];
[self setNeedsLayout];
+10 -8
View File
@@ -161,25 +161,27 @@ CPVisualEffectStateInactive = 2;
- (BOOL)setThemeState:(ThemeState)aState
{
if (aState.isa && [aState isKindOfClass:CPArray])
aState = CPThemeState.apply(null, aState);
aState = CPThemeState.apply(null, aState);
var ret = [super setThemeState:aState];
var r = [super setThemeState:aState];
[self _applyVibrancyState];
if (r)
[self _applyVibrancyState];
return ret;
return r;
}
- (BOOL)unsetThemeState:(ThemeState)aState
{
if (aState.isa && [aState isKindOfClass:CPArray])
aState = CPThemeState.apply(null, aState);
aState = CPThemeState.apply(null, aState);
var ret = [super unsetThemeState:aState];
var r = [super unsetThemeState:aState];
[self _applyVibrancyState];
if (r)
[self _applyVibrancyState];
return ret;
return r;
}
- (void)viewDidMoveToSuperview
+18 -7
View File
@@ -774,11 +774,9 @@ var methodCalled;
- (void)testAppearanceDefaultvalue
{
[self assert:nil equals:[view appearance]];
[self assertFalse:view._effectiveAppearanceCached];
[self assertFalse:[view hasThemeState:CPThemeStateAppearanceVibrantDark]];
[self assertFalse:[view hasThemeState:CPThemeStateAppearanceVibrantLight]];
[self assert:nil equals:[view effectiveAppearance]];
[self assertTrue:view._effectiveAppearanceCached];
}
- (void)testAppearanceWithVibrantDark
@@ -816,18 +814,13 @@ var methodCalled;
{
var secondView = [[CPView alloc] initWithFrame:CGRectMakeZero()];
[self assertFalse:secondView._effectiveAppearanceCached];
[view addSubview:secondView];
[self assertTrue:secondView._effectiveAppearanceCached];
[self assert:nil equals:[secondView appearance]];
[view setAppearance:[CPAppearance appearanceNamed:CPAppearanceNameVibrantLight]];
[self assertFalse:secondView._effectiveAppearanceCached];
[self assert:[CPAppearance appearanceNamed:CPAppearanceNameVibrantLight] equals:[secondView effectiveAppearance]];
[self assertTrue:secondView._effectiveAppearanceCached];
}
- (void)testEffectiveAppearanceWithMovingViews
@@ -851,6 +844,24 @@ var methodCalled;
[self assertTrue:[view hasThemeState:CPThemeStateAppearanceVibrantDark]];
}
- (void)testEffectiveAppearanceWithMovingViewHierarchy
{
var viewC = [[CPView alloc] initWithFrame:CGRectMakeZero()],
viewA = [[CPView alloc] initWithFrame:CGRectMakeZero()],
viewB = [[CPView alloc] initWithFrame:CGRectMakeZero()];
[view setAppearance:[CPAppearance appearanceNamed:CPAppearanceNameVibrantLight]];
[viewC setAppearance:[CPAppearance appearanceNamed:CPAppearanceNameVibrantDark]];
[viewA addSubview:viewB];
[view addSubview:viewA];
[self assert:[CPAppearance appearanceNamed:CPAppearanceNameVibrantLight] equals:[viewB effectiveAppearance]];
[viewC addSubview:viewA];
[self assert:[CPAppearance appearanceNamed:CPAppearanceNameVibrantDark] equals:[viewB effectiveAppearance]];
}
- (void)testEffectiveAppearanceReset
{
var viewA = [[CPView alloc] initWithFrame:CGRectMakeZero()],