From f062fda2f7d2e5767468a71a2656eed661edd1dc Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Tue, 6 Oct 2015 14:41:01 -0700 Subject: [PATCH] Fixed: optimization with layoutSubviews and viewWillLayout --- AppKit/CPView.j | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 31d8f21fa..0057c0b89 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -128,7 +128,8 @@ var DOMElementPrototype = nil, var CPViewFlags = { }, CPViewHasCustomDrawRect = 1 << 0, - CPViewHasCustomLayoutSubviews = 1 << 1; + CPViewHasCustomLayoutSubviews = 1 << 1, + CPViewHasCustomViewWillLayout = 1 << 2; var CPViewHighDPIDrawingEnabled = YES; @@ -317,6 +318,12 @@ var CPViewHighDPIDrawingEnabled = YES; || [theClass instanceMethodForSelector:@selector(viewWillDraw)] !== [CPView instanceMethodForSelector:@selector(viewWillDraw)]) flags |= CPViewHasCustomDrawRect; + if ([theClass instanceMethodForSelector:@selector(viewWillLayout)] !== [CPView instanceMethodForSelector:@selector(viewWillLayout)]) + flags |= CPViewHasCustomViewWillLayout; + + if ([theClass instanceMethodForSelector:@selector(layoutSubviews)] !== [CPView instanceMethodForSelector:@selector(layoutSubviews)]) + flags |= CPViewHasCustomLayoutSubviews; + CPViewFlags[classUID] = flags; } @@ -2637,8 +2644,12 @@ setBoundsOrigin: { _needsLayout = NO; - [self viewWillLayout]; - [self layoutSubviews]; + if (_viewClassFlags & CPViewHasCustomViewWillLayout) + [self viewWillLayout]; + + if (_viewClassFlags & CPViewHasCustomLayoutSubviews) + [self layoutSubviews]; + [self viewDidLayout]; } }