From f82b478a772d63c7e9d1eb36cacef9e43cbde0cc Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Fri, 20 Feb 2015 14:36:27 -0800 Subject: [PATCH 1/2] New: added the method setNeedsLayout: This PR adds the possibility to layout or not a CPView. Previously, once setNeedsLayout was called on a CPView, it wasn't possible to cancel the layout of the view. Now we can as in cocoa. The method setNeedsLayout will still work (it calls the method setNeedsLayout: with YES). UnitTests in Tests/AppKit/CPViewTest.j --- AppKit/CPView.j | 10 +++++- Tests/AppKit/CPViewTest.j | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index c047da60e..d7248a743 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -2608,8 +2608,16 @@ setBoundsOrigin: - (void)setNeedsLayout { - if (!(_viewClassFlags & CPViewHasCustomLayoutSubviews)) + [self setNeedsLayout:YES]; +} + +- (void)setNeedsLayout:(BOOL)needLayout +{ + if (!(_viewClassFlags & CPViewHasCustomLayoutSubviews) || !needLayout) + { + _needsLayout = NO; return; + } _needsLayout = YES; 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 From bb64d0dd54ba4dd271b09498dad193a8be12215a Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Fri, 20 Feb 2015 15:49:08 -0800 Subject: [PATCH 2/2] New: added method needsLayout in CPView --- AppKit/CPView.j | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index d7248a743..12f207bd6 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -2624,6 +2624,11 @@ setBoundsOrigin: _CPDisplayServerAddLayoutObject(self); } +- (BOOL)needsLayout +{ + return _needsLayout; +} + - (void)layoutIfNeeded { if (_needsLayout)