mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-27 08:55:52 +00:00
New: added methods viewWillLayout and viewDidLayout
Previously, when a view was about to layout, only layoutSubviews was called. Now the methods viewWillLayout and viewDidLayout are called as well. This is like in Cocoa. This PR fixed the issue with the appearance and the view based tableView. We now handle everything related with appearance when making the layout of a view. This PR removed a small optimization in CPView. Now when making setNeedsLayout and setNeedsDisplay, the methods drawRect: and layoutSubviews are always called even if there are not override. (As in cocoa)
This commit is contained in:
1 parent
42c3c7bc48
commit
b30103c790
2 files changed
+33
-55
No files matched your search
+23
-54
@@ -231,8 +231,6 @@ var CPViewHighDPIDrawingEnabled = YES;
|
||||
CPView _nextKeyView;
|
||||
CPView _previousKeyView;
|
||||
|
||||
unsigned _viewClassFlags;
|
||||
|
||||
// ToolTips
|
||||
CPString _toolTip @accessors(getter=toolTip);
|
||||
Function _toolTipFunctionIn;
|
||||
@@ -295,27 +293,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,12 +308,6 @@ var CPViewHighDPIDrawingEnabled = YES;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)awakeFromCib
|
||||
{
|
||||
[super awakeFromCib];
|
||||
|
||||
[self _recomputeAppearance];
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
@@ -391,8 +362,6 @@ var CPViewHighDPIDrawingEnabled = YES;
|
||||
_DOMImageSizes = [];
|
||||
#endif
|
||||
|
||||
[self _setupViewFlags];
|
||||
|
||||
[self _loadThemeAttributes];
|
||||
}
|
||||
|
||||
@@ -850,8 +819,7 @@ var CPViewHighDPIDrawingEnabled = YES;
|
||||
*/
|
||||
- (void)viewDidMoveToSuperview
|
||||
{
|
||||
[self _recomputeAppearance];
|
||||
|
||||
[self setNeedsLayout:YES];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
@@ -2489,9 +2457,6 @@ setBoundsOrigin:
|
||||
*/
|
||||
- (void)setNeedsDisplayInRect:(CGRect)aRect
|
||||
{
|
||||
if (!(_viewClassFlags & CPViewHasCustomDrawRect))
|
||||
return;
|
||||
|
||||
if (CGRectIsEmpty(aRect))
|
||||
return;
|
||||
|
||||
@@ -2632,7 +2597,7 @@ setBoundsOrigin:
|
||||
|
||||
- (void)setNeedsLayout:(BOOL)needLayout
|
||||
{
|
||||
if (!(_viewClassFlags & CPViewHasCustomLayoutSubviews) || !needLayout)
|
||||
if (!needLayout)
|
||||
{
|
||||
_needsLayout = NO;
|
||||
return;
|
||||
@@ -2654,12 +2619,31 @@ setBoundsOrigin:
|
||||
{
|
||||
_needsLayout = NO;
|
||||
|
||||
[self viewWillLayout];
|
||||
[self layoutSubviews];
|
||||
[self viewDidLayout];
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)viewWillLayout
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
@ignore
|
||||
*/
|
||||
- (void)viewDidLayout
|
||||
{
|
||||
[self _recomputeAppearance];
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -3544,19 +3528,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 +3696,6 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
|
||||
_opacity = 1.0;
|
||||
|
||||
[self setBackgroundColor:[aCoder decodeObjectForKey:CPViewBackgroundColorKey]];
|
||||
[self _setupViewFlags];
|
||||
|
||||
_theme = [CPTheme defaultTheme];
|
||||
_themeClass = [aCoder decodeObjectForKey:CPViewThemeClassKey];
|
||||
@@ -3737,15 +3714,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
|
||||
_themeAttributes[attributeName] = CPThemeAttributeDecode(aCoder, attributeName, attributes[count], _theme, themeClass);
|
||||
}
|
||||
|
||||
var appearance = [aCoder decodeObjectForKey:CPViewAppearanceKey];
|
||||
|
||||
// TODO : find a way to fix this horrible things
|
||||
// We only set the appearance here when everything and every subviews were unarchived.
|
||||
// Otherwise this causes a crash with some subviews not unarchived but already created (how ? init is not called, neither initWithFrame or initWithCoder) in the coder (I have no idea why these views are present in _objects of the coder)
|
||||
// To reproduce, uncomment the timeout and open the test Tests/Manual/TableTests/ViewBasedCib
|
||||
window.setTimeout(function() {
|
||||
[self setAppearance:appearance];
|
||||
},0);
|
||||
[self setAppearance:[aCoder decodeObjectForKey:CPViewAppearanceKey]];
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
[self setNeedsLayout];
|
||||
|
||||
@@ -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]];
|
||||
|
||||
Reference in new issue
Block a user