diff --git a/AppKit/CPView.j b/AppKit/CPView.j index c047da60e..12f207bd6 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -2608,14 +2608,27 @@ setBoundsOrigin: - (void)setNeedsLayout { - if (!(_viewClassFlags & CPViewHasCustomLayoutSubviews)) + [self setNeedsLayout:YES]; +} + +- (void)setNeedsLayout:(BOOL)needLayout +{ + if (!(_viewClassFlags & CPViewHasCustomLayoutSubviews) || !needLayout) + { + _needsLayout = NO; return; + } _needsLayout = YES; _CPDisplayServerAddLayoutObject(self); } +- (BOOL)needsLayout +{ + return _needsLayout; +} + - (void)layoutIfNeeded { if (_needsLayout) diff --git a/Tests/AppKit/CPViewTest.j b/Tests/AppKit/CPViewTest.j index 3d1430492..e6eb4d091 100644 --- a/Tests/AppKit/CPViewTest.j +++ b/Tests/AppKit/CPViewTest.j @@ -643,8 +643,78 @@ var methodCalled; [self assert:expectedRestult equals:methodCalled]; } +- (void)testLayoutSubviews +{ + var layoutView = [[CPLayoutView alloc] initWithFrame:CGRectMakeZero()]; + + [layoutView setIdentifier:@"layoutView"]; + + [[window contentView] addSubview:layoutView]; + [layoutView setNeedsLayout] + + methodCalled = []; + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + var expectedRestult = ["layoutSubivews_layoutView"]; + [self assert:expectedRestult equals:methodCalled]; + + + [layoutView setNeedsLayout] + [layoutView setNeedsLayout] + + methodCalled = []; + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + expectedRestult = ["layoutSubivews_layoutView"]; + [self assert:expectedRestult equals:methodCalled]; + + + [layoutView setNeedsLayout:YES] + + methodCalled = []; + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + expectedRestult = ["layoutSubivews_layoutView"]; + [self assert:expectedRestult equals:methodCalled]; + + + [layoutView setNeedsLayout:YES]; + [layoutView setNeedsLayout:NO]; + + methodCalled = []; + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + expectedRestult = []; + [self assert:expectedRestult equals:methodCalled]; + + + [layoutView setNeedsLayout:YES]; + [layoutView setNeedsLayout:NO]; + [layoutView setNeedsLayout:YES]; + + methodCalled = []; + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + expectedRestult = ["layoutSubivews_layoutView"]; + [self assert:expectedRestult equals:methodCalled]; +} + @end +@implementation CPLayoutView : CPView +{ + +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + var string = @"layoutSubivews_" + [self identifier]; + [methodCalled addObject:string]; +} + +@end @implementation CPResponderView : CPView