Bug 1389908 - Make sure the NSColorPanel never has a dangling target, and make sure to set the new target before calling setColor. r?spohl
MozReview-Commit-ID: L71yb593eR2
--- a/widget/cocoa/nsColorPicker.mm
+++ b/widget/cocoa/nsColorPicker.mm
@@ -49,21 +49,21 @@ HexStrToInt(NSString* str)
mColorPanel = [NSColorPanel sharedColorPanel];
self = [super init];
return self;
}
- (void)open:(NSColor*)aInitialColor title:(NSString*)aTitle
{
- [mColorPanel setTitle:aTitle];
- [mColorPanel setColor:aInitialColor];
[mColorPanel setTarget:self];
[mColorPanel setAction:@selector(colorChanged:)];
[mColorPanel setDelegate:self];
+ [mColorPanel setTitle:aTitle];
+ [mColorPanel setColor:aInitialColor];
[mColorPanel makeKeyAndOrderFront:nil];
}
- (void)colorChanged:(NSColorPanel*)aPanel
{
mColorPicker->Update([mColorPanel color]);
}
@@ -75,21 +75,19 @@ HexStrToInt(NSString* str)
- (void)retarget:(nsColorPicker*)aPicker
{
mColorPicker->DoneWithRetarget();
mColorPicker = aPicker;
}
- (void)dealloc
{
- if ([mColorPanel delegate] == self) {
- [mColorPanel setTarget:nil];
- [mColorPanel setAction:nil];
- [mColorPanel setDelegate:nil];
- }
+ [mColorPanel setTarget:nil];
+ [mColorPanel setAction:nil];
+ [mColorPanel setDelegate:nil];
mColorPanel = nil;
mColorPicker = nullptr;
[super dealloc];
}
@end