Skip to content

Commit

Permalink
Merge pull request github#131 from github/tracking-view-memory-manage…
Browse files Browse the repository at this point in the history
…ment

Fix TUINSView trackingView memory management
  • Loading branch information
jwilling committed Oct 31, 2012
2 parents d6b53a9 + 7e01c96 commit 2f55099
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
25 changes: 10 additions & 15 deletions lib/UIKit/TUINSView+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,22 @@

#import "TUINSView.h"

/*
* Private functionality of TUINSView that needs to be exposed to other parts of
* the framework.
*/
// Private functionality of TUINSView that needs to be exposed to other parts of
// the framework.
@interface TUINSView ()

/*
* The layer-backed view which actually holds the AppKit hierarchy.
*/
// The layer-backed view which actually holds the AppKit hierarchy.
@property (nonatomic, readonly, strong) NSView *appKitHostView;

/*
* Informs the receiver that the clipping of a TUIViewNSViewContainer it is hosting has
* changed, and asks it to update clipping paths accordingly.
*/
// The view currently tracking mouse events.
@property (nonatomic, unsafe_unretained) TUIView *trackingView;

// Informs the receiver that the clipping of a TUIViewNSViewContainer it is hosting has
// changed, and asks it to update clipping paths accordingly.
- (void)recalculateNSViewClipping;

/*
* Informs the receiver that the ordering of a TUIViewNSViewContainer it is hosting has
* changed, and asks it to reorder its subviews to match TwUI.
*/
// Informs the receiver that the ordering of a TUIViewNSViewContainer it is hosting has
// changed, and asks it to reorder its subviews to match TwUI.
- (void)recalculateNSViewOrdering;

- (TUIView *)viewForLocalPoint:(NSPoint)p;
Expand Down
1 change: 0 additions & 1 deletion lib/UIKit/TUINSView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
{
TUIView *_hoverView;

__unsafe_unretained TUIView *_trackingView; // dragging view, weak
__unsafe_unretained TUIView *_hyperFocusView; // hyperfocus view, weak

TUIView *_hyperFadeView;
Expand Down
25 changes: 13 additions & 12 deletions lib/UIKit/TUINSView.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ @implementation TUINSView
// these cannot be implicitly synthesized because they're from protocols/categories
@synthesize hostView = _hostView;
@synthesize appKitHostView = _appKitHostView;
@synthesize trackingView = _trackingView;
@synthesize rootView = _rootView;
@synthesize maskLayer = _maskLayer;

Expand Down Expand Up @@ -433,27 +434,27 @@ - (void)mouseDown:(NSEvent *)event
// normal case
normal:
;
_trackingView = [self viewForEvent:event];
[_trackingView mouseDown:event];
self.trackingView = [self viewForEvent:event];
[self.trackingView mouseDown:event];
}

[TUITooltipWindow endTooltip];
}

- (void)mouseUp:(NSEvent *)event
{
TUIView *lastTrackingView = _trackingView;
TUIView *lastTrackingView = self.trackingView;

_trackingView = nil;
self.trackingView = nil;

[lastTrackingView mouseUp:event]; // after _trackingView set to nil, will call mouseUp:fromSubview:
[lastTrackingView mouseUp:event]; // after trackingView is set to nil, will call mouseUp:fromSubview:

[self _updateHoverViewWithEvent:event];
}

- (void)mouseDragged:(NSEvent *)event
{
[_trackingView mouseDragged:event];
[self.trackingView mouseDragged:event];
}

- (void)mouseMoved:(NSEvent *)event
Expand All @@ -471,19 +472,19 @@ -(void)mouseExited:(NSEvent *)event {

- (void)rightMouseDown:(NSEvent *)event
{
_trackingView = [self viewForEvent:event];
[_trackingView rightMouseDown:event];
self.trackingView = [self viewForEvent:event];
[self.trackingView rightMouseDown:event];
[TUITooltipWindow endTooltip];
[super rightMouseDown:event]; // we need to send this up the responder chain so that -menuForEvent: will get called for two-finger taps
}

- (void)rightMouseUp:(NSEvent *)event
{
TUIView *lastTrackingView = _trackingView;
TUIView *lastTrackingView = self.trackingView;

_trackingView = nil;
self.trackingView = nil;

[lastTrackingView rightMouseUp:event]; // after _trackingView set to nil, will call mouseUp:fromSubview:
[lastTrackingView rightMouseUp:event]; // after trackingView is set to nil, will call mouseUp:fromSubview:
}

- (void)scrollWheel:(NSEvent *)event
Expand Down Expand Up @@ -554,7 +555,7 @@ - (void)setEverythingNeedsDisplay

- (BOOL)isTrackingSubviewOfView:(TUIView *)v
{
return [_trackingView isDescendantOfView:v];
return [self.trackingView isDescendantOfView:v];
}

- (BOOL)isHoveringSubviewOfView:(TUIView *)v
Expand Down
7 changes: 5 additions & 2 deletions lib/UIKit/TUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#import "TUIView.h"
#import "TUILayoutManager.h"
#import "TUINSView.h"
#import "TUINSView+Private.h"
#import "TUINSWindow.h"
#import "TUITextRenderer.h"
#import "TUIViewController.h"
Expand Down Expand Up @@ -128,8 +129,10 @@ + (Class)layerClass

- (void)dealloc
{
[[TUILayoutManager sharedLayoutManager] removeLayoutConstraintsFromView:self];
[[TUILayoutManager sharedLayoutManager] setLayoutName:nil forView:self];
[[TUILayoutManager sharedLayoutManager] removeLayoutConstraintsFromView:self];
[[TUILayoutManager sharedLayoutManager] setLayoutName:nil forView:self];

if (self.nsView.trackingView == self) self.nsView.trackingView = nil;

[self setTextRenderers:nil];
_layer.delegate = nil;
Expand Down

0 comments on commit 2f55099

Please sign in to comment.