Skip to content
Browse files

Merge branch 'master' into imports-cleanup

Conflicts:
	lib/UIKit/TUIView.m
  • Loading branch information...
2 parents 704266a + 19ae557 commit 6ae2f1a2db71834a55d44f08e121eaf52bf9a53b @jspahrsummers jspahrsummers committed Jul 24, 2012
View
43 lib/Support/NSTextView+TUIExtensions.m
@@ -1,8 +1,8 @@
//
-// NSTextView+TUIExtensions.m
+// NSTextView+TUIExtensions.m
//
-// Created by Justin Spahr-Summers on 10.03.12.
-// Copyright (c) 2012 Bitswift. All rights reserved.
+// Created by Justin Spahr-Summers on 10.03.12.
+// Copyright (c) 2012 Bitswift. All rights reserved.
//
#import "NSTextView+TUIExtensions.h"
@@ -11,33 +11,36 @@
static void (*originalDrawRectIMP)(id, SEL, NSRect);
static void fixedDrawRect (NSTextView *self, SEL _cmd, NSRect rect) {
- CGContextRef context = [NSGraphicsContext currentContext].graphicsPort;
+ CGContextRef context = [NSGraphicsContext currentContext].graphicsPort;
- CGContextSetAllowsAntialiasing(context, YES);
- CGContextSetAllowsFontSmoothing(context, YES);
- CGContextSetAllowsFontSubpixelPositioning(context, YES);
- CGContextSetAllowsFontSubpixelQuantization(context, YES);
+ CGContextSetAllowsAntialiasing(context, YES);
+ CGContextSetAllowsFontSmoothing(context, YES);
+ CGContextSetAllowsFontSubpixelPositioning(context, YES);
+ CGContextSetAllowsFontSubpixelQuantization(context, YES);
- CGContextSetShouldAntialias(context, YES);
- CGContextSetShouldSmoothFonts(context, YES);
- CGContextSetShouldSubpixelPositionFonts(context, YES);
- CGContextSetShouldSubpixelQuantizeFonts(context, YES);
+ CGContextSetShouldAntialias(context, YES);
- if (self.superview) {
- // NSTextView likes to fall on non-integral points sometimes -- fix that
- self.frame = [self.superview backingAlignedRect:self.frame options:NSAlignAllEdgesNearest];
- }
+ // TODO: SPAA seems to stop working when text fields and text views lose
+ // focus, so it's disabled for now.
+ CGContextSetShouldSmoothFonts(context, NO);
+ CGContextSetShouldSubpixelPositionFonts(context, NO);
+ CGContextSetShouldSubpixelQuantizeFonts(context, NO);
- originalDrawRectIMP(self, _cmd, rect);
+ if (self.superview) {
+ // NSTextView likes to fall on non-integral points sometimes -- fix that
+ self.frame = [self.superview backingAlignedRect:self.frame options:NSAlignAllEdgesNearest];
+ }
+
+ originalDrawRectIMP(self, _cmd, rect);
}
@implementation NSTextView (TUIExtensions)
+ (void)load {
- Method drawRect = class_getInstanceMethod(self, @selector(drawRect:));
- originalDrawRectIMP = (void (*)(id, SEL, NSRect))method_getImplementation(drawRect);
+ Method drawRect = class_getInstanceMethod(self, @selector(drawRect:));
+ originalDrawRectIMP = (void (*)(id, SEL, NSRect))method_getImplementation(drawRect);
- class_replaceMethod(self, method_getName(drawRect), (IMP)&fixedDrawRect, method_getTypeEncoding(drawRect));
+ class_replaceMethod(self, method_getName(drawRect), (IMP)&fixedDrawRect, method_getTypeEncoding(drawRect));
}
@end
View
76 lib/Support/TUIAnimationManager.m
@@ -1,8 +1,8 @@
//
-// TUIAnimationManager.m
+// TUIAnimationManager.m
//
-// Created by Justin Spahr-Summers on 10.03.12.
-// Copyright (c) 2012 Bitswift. All rights reserved.
+// Created by Justin Spahr-Summers on 10.03.12.
+// Copyright (c) 2012 Bitswift. All rights reserved.
//
#import "TUIAnimationManager.h"
@@ -11,7 +11,7 @@
* Disables implicit AppKit animations on every run loop iteration.
*/
static void mainRunLoopObserverCallback (CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) {
- [[NSAnimationContext currentContext] setDuration:0];
+ [[NSAnimationContext currentContext] setDuration:0];
}
@interface TUIAnimationManager ()
@@ -40,18 +40,18 @@ @implementation TUIAnimationManager
@synthesize mainRunLoopObserver = m_mainRunLoopObserver;
- (void)setMainRunLoopObserver:(CFRunLoopObserverRef)observer {
- if (observer == m_mainRunLoopObserver)
- return;
+ if (observer == m_mainRunLoopObserver)
+ return;
- if (m_mainRunLoopObserver) {
- CFRunLoopRemoveObserver(CFRunLoopGetMain(), m_mainRunLoopObserver, kCFRunLoopCommonModes);
- CFRelease(m_mainRunLoopObserver);
- }
+ if (m_mainRunLoopObserver) {
+ CFRunLoopRemoveObserver(CFRunLoopGetMain(), m_mainRunLoopObserver, kCFRunLoopCommonModes);
+ CFRelease(m_mainRunLoopObserver);
+ }
- if (observer)
- CFRetain(observer);
+ if (observer)
+ CFRetain(observer);
- m_mainRunLoopObserver = observer;
+ m_mainRunLoopObserver = observer;
}
#pragma mark Lifecycle
@@ -68,47 +68,47 @@ + (void)load {
}
+ (TUIAnimationManager *)defaultManager; {
- static id singleton = nil;
- static dispatch_once_t pred;
+ static id singleton = nil;
+ static dispatch_once_t pred;
- dispatch_once(&pred, ^{
- singleton = [[self alloc] init];
- });
+ dispatch_once(&pred, ^{
+ singleton = [[self alloc] init];
+ });
- return singleton;
+ return singleton;
}
- (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
- self.mainRunLoopObserver = NULL;
+ self.mainRunLoopObserver = NULL;
}
#pragma mark Run Loop Observer
- (void)registerRunLoopObserver; {
- // set up an observer on the main run loop that can disable implicit
- // animations
- CFRunLoopObserverRef observer = CFRunLoopObserverCreate(
- NULL,
- kCFRunLoopBeforeTimers,
- YES,
- 10000,
- &mainRunLoopObserverCallback,
- NULL
- );
-
- CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes);
-
- self.mainRunLoopObserver = observer;
- CFRelease(observer);
+ // set up an observer on the main run loop that can disable implicit
+ // animations
+ CFRunLoopObserverRef observer = CFRunLoopObserverCreate(
+ NULL,
+ kCFRunLoopBeforeTimers,
+ YES,
+ 10000,
+ &mainRunLoopObserverCallback,
+ NULL
+ );
+
+ CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes);
+
+ self.mainRunLoopObserver = observer;
+ CFRelease(observer);
}
#pragma mark Notifications
- (void)applicationDidFinishLaunchingNotification:(NSNotification *)notification; {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:notification.name object:nil];
- [self registerRunLoopObserver];
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:notification.name object:nil];
+ [self registerRunLoopObserver];
}
@end
View
66 lib/UIKit/TUINSView.m
@@ -31,6 +31,12 @@
#import "TUITooltipWindow.h"
#import <CoreFoundation/CoreFoundation.h>
+// If enabled, NSViews contained within TUIViewNSViewContainers will be clipped
+// by any TwUI ancestors that enable clipping to bounds.
+//
+// This should really only be disabled for debugging.
+#define ENABLE_NSVIEW_CLIPPING 1
+
static NSComparisonResult compareNSViewOrdering (NSView *viewA, NSView *viewB, void *context) {
TUIViewNSViewContainer *hostA = viewA.hostView;
TUIViewNSViewContainer *hostB = viewB.hostView;
@@ -625,6 +631,8 @@ - (void)setUp {
opaque = YES;
_maskLayer = [CAShapeLayer layer];
+ _maskLayer.frame = self.bounds;
+ _maskLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
// enable layer-backing for this view
self.wantsLayer = YES;
@@ -643,9 +651,12 @@ - (void)setUp {
// set up masking on the AppKit host view, and make ourselves the layout
// manager, so that we'll know when new sublayers are added
- self.appKitHostView.layer.mask = self.maskLayer;
self.appKitHostView.layer.layoutManager = self;
+
+ #if ENABLE_NSVIEW_CLIPPING
+ self.appKitHostView.layer.mask = self.maskLayer;
[self recalculateNSViewClipping];
+ #endif
}
- (void)didAddSubview:(NSView *)view {
@@ -690,11 +701,18 @@ - (NSView *)hitTest:(NSPoint)point {
}
- (void)recalculateNSViewOrdering; {
+ NSAssert([NSThread isMainThread], @"");
[self.appKitHostView sortSubviewsUsingFunction:&compareNSViewOrdering context:NULL];
}
- (void)recalculateNSViewClipping; {
- CGMutablePathRef path = CGPathCreateMutable();
+ NSAssert([NSThread isMainThread], @"");
+
+ #if !ENABLE_NSVIEW_CLIPPING
+ return;
+ #endif
+
+ CGMutablePathRef clippingPath = CGPathCreateMutable();
for (NSView *view in self.appKitHostView.subviews) {
id<TUIBridgedView> hostView = view.hostView;
@@ -703,9 +721,24 @@ - (void)recalculateNSViewClipping; {
CALayer *focusRingLayer = [self focusRingLayerForView:view];
if (focusRingLayer) {
- id<TUIBridgedScrollView> clippingView = [hostView ancestorScrollView];
+ id<TUIBridgedScrollView> clippingView = hostView.ancestorScrollView;
+ CGRect clippedFocusRingBounds = CGRectNull;
+
+ if (clippingView && self.ancestorScrollView != clippingView) {
+ CGRect rect = [clippingView.layer tui_convertAndClipRect:clippingView.layer.visibleRect toLayer:focusRingLayer];
+ if (!CGRectIsNull(rect) && !CGRectIsInfinite(rect) && !CGRectContainsRect(rect, clippedFocusRingBounds)) {
+ clippedFocusRingBounds = CGRectIntersection(rect, focusRingLayer.bounds);
+ }
+ }
+
+ // the frame of the focus ring, represented in the TUINSView's
+ // coordinate system
+ CGRect focusRingFrame;
- if (clippingView) {
+ if (CGRectIsNull(clippedFocusRingBounds)) {
+ focusRingLayer.mask = nil;
+ focusRingFrame = [focusRingLayer tui_convertAndClipRect:focusRingLayer.bounds toLayer:self.layer];
+ } else {
// set up a mask on the focus ring that clips to any ancestor scroll views
CAShapeLayer *maskLayer = (id)focusRingLayer.mask;
if (![maskLayer isKindOfClass:[CAShapeLayer class]]) {
@@ -714,39 +747,34 @@ - (void)recalculateNSViewClipping; {
focusRingLayer.mask = maskLayer;
}
- CGRect rect = [clippingView.layer tui_convertAndClipRect:clippingView.layer.visibleRect toLayer:focusRingLayer];
- if (CGRectIsNull(rect) || CGRectIsInfinite(rect)) {
- rect = CGRectZero;
- }
-
- CGPathRef focusRingPath = CGPathCreateWithRect(rect, NULL);
+ CGPathRef focusRingPath = CGPathCreateWithRect(clippedFocusRingBounds, NULL);
maskLayer.path = focusRingPath;
CGPathRelease(focusRingPath);
-
- CGPathAddRect(path, NULL, [focusRingLayer tui_convertAndClipRect:rect toLayer:self.layer]);
- } else {
- focusRingLayer.mask = nil;
-
- CGPathAddRect(path, NULL, [focusRingLayer tui_convertAndClipRect:focusRingLayer.bounds toLayer:self.layer]);
+
+ focusRingFrame = [focusRingLayer tui_convertAndClipRect:clippedFocusRingBounds toLayer:self.layer];
}
+
+ CGPathAddRect(clippingPath, NULL, focusRingFrame);
}
// clip the frame of each NSView using the TwUI hierarchy
CGRect rect = [hostView.layer tui_convertAndClipRect:hostView.layer.visibleRect toLayer:self.layer];
if (CGRectIsNull(rect) || CGRectIsInfinite(rect))
continue;
- CGPathAddRect(path, NULL, rect);
+ CGPathAddRect(clippingPath, NULL, rect);
}
// mask them all at once (so fast!)
- self.maskLayer.path = path;
- CGPathRelease(path);
+ self.maskLayer.path = clippingPath;
+ CGPathRelease(clippingPath);
}
#pragma mark CALayer delegate
- (void)layoutSublayersOfLayer:(CALayer *)layer {
+ NSAssert([NSThread isMainThread], @"");
+
if (layer == self.layer) {
// TUINSView.layer is being laid out
return;
View
7 lib/UIKit/TUIView+Animation.m
@@ -145,6 +145,8 @@ + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))
+ (void)beginAnimations:(NSString *)animationID context:(void *)context
{
+ [NSAnimationContext beginGrouping];
+
TUIViewAnimation *animation = [[TUIViewAnimation alloc] init];
animation.context = context;
animation.animationID = animationID;
@@ -160,6 +162,7 @@ + (void)beginAnimations:(NSString *)animationID context:(void *)context
+ (void)commitAnimations
{
[[self _animationStack] removeLastObject];
+ [NSAnimationContext endGrouping];
// NSLog(@"--- %d", [[self _animationStack] count]);
}
@@ -188,7 +191,9 @@ static CGFloat SlomoTime()
+ (void)setAnimationDuration:(NSTimeInterval)duration
{
- [self _currentAnimation].basicAnimation.duration = duration * SlomoTime();
+ duration *= SlomoTime();
+ [self _currentAnimation].basicAnimation.duration = duration;
+ [NSAnimationContext currentContext].duration = duration;
}
+ (void)setAnimationDelay:(NSTimeInterval)delay // default = 0.0
View
178 lib/UIKit/TUIView.m
@@ -27,6 +27,13 @@
#import "TUIView+TUIBridgedView.h"
#import "TUIViewController.h"
+/*
+ * Enable this to debug blending.
+ *
+ * Opaque views will be colored green, and blended views will be colored red.
+ */
+#define CA_COLOR_OVERLAY_DEBUG 0
+
NSString * const TUIViewWillMoveToWindowNotification = @"TUIViewWillMoveToWindowNotification";
NSString * const TUIViewDidMoveToWindowNotification = @"TUIViewDidMoveToWindowNotification";
NSString * const TUIViewWindow = @"TUIViewWindow";
@@ -66,6 +73,13 @@ - (TUIView *)closestAssociatedView
@interface TUIView ()
@property (nonatomic, strong) NSMutableArray *subviews;
+
+/*
+ * Sets up the given view as a subview of the receiver. The given block is
+ * expected to perform the actual insertion into the subviews array or the
+ * layer.
+ */
+- (void)prepareSubview:(TUIView *)view insertionBlock:(void (^)(void))block;
@end
@implementation TUIView
@@ -326,69 +340,70 @@ static void TUISetCurrentContextScaleFactor(CGFloat s)
- (void)displayLayer:(CALayer *)layer
{
- if(_viewFlags.delegateWillDisplayLayer)
+ if (_viewFlags.delegateWillDisplayLayer) {
[_viewDelegate viewWillDisplayLayer:self];
+ }
typedef void (*DrawRectIMP)(id,SEL,CGRect);
SEL drawRectSEL = @selector(drawRect:);
DrawRectIMP drawRectIMP = (DrawRectIMP)[self methodForSelector:drawRectSEL];
DrawRectIMP dontCallThisBasicDrawRectIMP = (DrawRectIMP)[TUIView instanceMethodForSelector:drawRectSEL];
-#if 0
-#define CA_COLOR_OVERLAY_DEBUG \
-if(self.opaque) CGContextSetRGBFillColor(context, 0, 1, 0, 0.3); \
-else CGContextSetRGBFillColor(context, 1, 0, 0, 0.3); CGContextFillRect(context, b);
-#else
-#define CA_COLOR_OVERLAY_DEBUG
-#endif
-
-#define PRE_DRAW \
- CGRect b = self.bounds; \
- CGContextRef context = [self _CGContext]; \
- TUIGraphicsPushContext(context); \
- if(_viewFlags.clearsContextBeforeDrawing) \
- CGContextClearRect(context, b); \
- CGFloat scale = [self.layer respondsToSelector:@selector(contentsScale)] ? self.layer.contentsScale : 1.0f; \
- TUISetCurrentContextScaleFactor(scale); \
- CGContextScaleCTM(context, scale, scale); \
- CGContextSetAllowsAntialiasing(context, true); \
- CGContextSetShouldAntialias(context, true); \
- CGContextSetShouldSmoothFonts(context, !_viewFlags.disableSubpixelTextRendering);
-
-#define POST_DRAW \
- CA_COLOR_OVERLAY_DEBUG \
- TUIImage *image = TUIGraphicsGetImageFromCurrentImageContext(); \
- layer.contents = (id)image.CGImage; \
- CGContextScaleCTM(context, 1.0f / scale, 1.0f / scale); \
- TUIGraphicsPopContext(); \
- if(self.drawInBackground) [CATransaction flush];
+ if (!self.drawRect && (drawRectIMP == dontCallThisBasicDrawRectIMP || [self _disableDrawRect])) {
+ // drawRect isn't overridden by subclass, don't call, let the CA machinery just handle backgroundColor (fast path)
+ return;
+ }
CGRect rectToDraw = self.bounds;
- if(!CGRectEqualToRect(_context.dirtyRect, CGRectZero)) {
+ if (!CGRectEqualToRect(_context.dirtyRect, CGRectZero)) {
rectToDraw = _context.dirtyRect;
_context.dirtyRect = CGRectZero;
}
-
+
void (^drawBlock)(void) = ^{
- if(drawRect) {
+ CGContextRef context = [self _CGContext];
+ TUIGraphicsPushContext(context);
+ if (_viewFlags.clearsContextBeforeDrawing) {
+ CGContextClearRect(context, rectToDraw);
+ }
+
+ CGFloat scale = [self.layer respondsToSelector:@selector(contentsScale)] ? self.layer.contentsScale : 1.0f;
+ TUISetCurrentContextScaleFactor(scale);
+ CGContextScaleCTM(context, scale, scale);
+
+ CGContextSetAllowsAntialiasing(context, true);
+ CGContextSetShouldAntialias(context, true);
+ CGContextSetShouldSmoothFonts(context, !_viewFlags.disableSubpixelTextRendering);
+
+ if (self.drawRect) {
// drawRect is implemented via a block
- PRE_DRAW
- drawRect(self, rectToDraw);
- POST_DRAW
- } else if((drawRectIMP != dontCallThisBasicDrawRectIMP) && ![self _disableDrawRect]) {
+ self.drawRect(self, rectToDraw);
+ } else if ((drawRectIMP != dontCallThisBasicDrawRectIMP) && ![self _disableDrawRect]) {
// drawRect is overridden by subclass
- PRE_DRAW
drawRectIMP(self, drawRectSEL, rectToDraw);
- POST_DRAW
+ }
+
+ #if CA_COLOR_OVERLAY_DEBUG
+ if (self.opaque) {
+ CGContextSetRGBFillColor(context, 0, 1, 0, 0.3);
} else {
- // drawRect isn't overridden by subclass, don't call, let the CA machinery just handle backgroundColor (fast path)
+ CGContextSetRGBFillColor(context, 1, 0, 0, 0.3);
+ CGContextFillRect(context, rectToDraw);
}
+ #endif
+
+ TUIImage *image = TUIGraphicsGetImageFromCurrentImageContext();
+ layer.contents = (id)image.CGImage;
+ CGContextScaleCTM(context, 1.0f / scale, 1.0f / scale);
+ TUIGraphicsPopContext();
+
+ if (self.drawInBackground) [CATransaction flush];
};
- if(self.drawInBackground) {
+ if (self.drawInBackground) {
layer.contents = nil;
- if(self.drawQueue != nil) {
+ if (self.drawQueue != nil) {
[self.drawQueue addOperationWithBlock:drawBlock];
} else {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), drawBlock);
@@ -546,6 +561,31 @@ - (void)_updateLayerScaleFactor
}
}
+- (void)prepareSubview:(TUIView *)view insertionBlock:(void (^)(void))block
+{
+ if (!_subviews) {
+ _subviews = [[NSMutableArray alloc] init];
+ }
+
+ TUINSView *originalNSView = view.ancestorTUINSView;
+
+ /* will call willAdd:nil and didAdd (nil) */
+ [view removeFromSuperview];
+
+ [view willMoveToTUINSView:_nsView];
+ [view willMoveToSuperview:self];
+ view.nsView = _nsView;
+
+ block();
+
+ [self didAddSubview:view];
+ [view didMoveToSuperview];
+ [view didMoveFromTUINSView:originalNSView];
+
+ [view setNextResponder:self];
+ [self _blockLayout];
+}
+
@end
@@ -783,45 +823,23 @@ - (void)setNextResponder:(NSResponder *)r
}
}
-// TODO: get rid of these macros, and just always go through a single method
-#define PRE_ADDSUBVIEW(index) \
- if (!_subviews) \
- _subviews = [[NSMutableArray alloc] init]; \
- \
- if (index == NSUIntegerMax) {\
- [self.subviews addObject:view]; \
- } else {\
- [self.subviews insertObject:view atIndex:index];\
- }\
- [view removeFromSuperview]; /* will call willAdd:nil and didAdd (nil) */ \
- \
- TUINSView *originalNSView_ = view.ancestorTUINSView; \
- [view willMoveToTUINSView:_nsView]; \
- \
- [view willMoveToSuperview:self]; \
- view.nsView = _nsView;
-
-#define POST_ADDSUBVIEW \
- [self didAddSubview:view]; \
- [view didMoveToSuperview]; \
- [view didMoveFromTUINSView:originalNSView_]; \
- [view setNextResponder:self]; \
- [self _blockLayout];
-
-- (void)addSubview:(TUIView *)view // everything should go through this
+- (void)addSubview:(TUIView *)view
{
if(!view)
return;
- PRE_ADDSUBVIEW(NSUIntegerMax)
- [self.layer addSublayer:view.layer];
- POST_ADDSUBVIEW
+
+ [self prepareSubview:view insertionBlock:^{
+ [self.subviews addObject:view];
+ [self.layer addSublayer:view.layer];
+ }];
}
- (void)insertSubview:(TUIView *)view atIndex:(NSInteger)index
{
- PRE_ADDSUBVIEW(index)
- [self.layer insertSublayer:view.layer atIndex:(unsigned int)index];
- POST_ADDSUBVIEW
+ [self prepareSubview:view insertionBlock:^{
+ [self.subviews insertObject:view atIndex:index];
+ [self.layer insertSublayer:view.layer atIndex:(unsigned)index];
+ }];
}
- (void)insertSubview:(TUIView *)view belowSubview:(TUIView *)siblingSubview
@@ -830,9 +848,10 @@ - (void)insertSubview:(TUIView *)view belowSubview:(TUIView *)siblingSubview
if (siblingIndex == NSNotFound)
return;
- PRE_ADDSUBVIEW(siblingIndex + 1)
- [self.layer insertSublayer:view.layer below:siblingSubview.layer];
- POST_ADDSUBVIEW
+ [self prepareSubview:view insertionBlock:^{
+ [self.subviews insertObject:view atIndex:siblingIndex + 1];
+ [self.layer insertSublayer:view.layer below:siblingSubview.layer];
+ }];
}
- (void)insertSubview:(TUIView *)view aboveSubview:(TUIView *)siblingSubview
@@ -841,9 +860,10 @@ - (void)insertSubview:(TUIView *)view aboveSubview:(TUIView *)siblingSubview
if (siblingIndex == NSNotFound)
return;
- PRE_ADDSUBVIEW(siblingIndex)
- [self.layer insertSublayer:view.layer above:siblingSubview.layer];
- POST_ADDSUBVIEW
+ [self prepareSubview:view insertionBlock:^{
+ [self.subviews insertObject:view atIndex:siblingIndex];
+ [self.layer insertSublayer:view.layer above:siblingSubview.layer];
+ }];
}
- (TUIView *)_topSubview
View
27 lib/UIKit/TUIViewNSViewContainer.m
@@ -82,6 +82,16 @@ - (CGRect)NSViewFrame; {
return [self convertRect:self.bounds toView:self.ancestorTUINSView.rootView];
}
+- (void)setFrame:(CGRect)frame {
+ [super setFrame:frame];
+ [self synchronizeNSViewGeometry];
+}
+
+- (void)setBounds:(CGRect)bounds {
+ [super setBounds:bounds];
+ [self synchronizeNSViewGeometry];
+}
+
- (void)setCenter:(CGPoint)center {
[super setCenter:center];
[self synchronizeNSViewGeometry];
@@ -98,8 +108,8 @@ - (BOOL)isRenderingContainedView {
#pragma mark Lifecycle
-- (id)init {
- self = [super init];
+- (id)initWithFrame:(CGRect)frame {
+ self = [super initWithFrame:frame];
if (!self)
return nil;
@@ -114,12 +124,11 @@ - (id)init {
- (id)initWithNSView:(NSView *)view; {
NSAssert1([NSThread isMainThread], @"%s should only be called from the main thread", __func__);
- self = [self init];
+ self = [self initWithFrame:view.frame];
if (!self)
return nil;
self.rootView = view;
- self.frame = view.frame;
return self;
}
@@ -269,6 +278,16 @@ - (CGSize)sizeThatFits:(CGSize)constraint {
return cellSize;
}
+- (void)sizeToFit {
+ if ([self.rootView respondsToSelector:@selector(sizeToFit)]) {
+ [self.rootView performSelector:@selector(sizeToFit)];
+
+ self.bounds = self.rootView.bounds;
+ } else {
+ [super sizeToFit];
+ }
+}
+
#pragma mark NSObject overrides
- (NSString *)description {

0 comments on commit 6ae2f1a

Please sign in to comment.
Something went wrong with that request. Please try again.