Bug 1389908 - Make sure the NSColorPanel never has a dangling target, and make sure to set the new target before calling setColor. r=spohl, a=gchang
authorMarkus Stange <mstange@themasta.com>
Mon, 21 Aug 2017 19:16:22 -0400
changeset 423723 eb87d01a73ec69c07750e3ac3a554cbda5c39972
parent 423722 fb00d84ec8256da72ae02815a7754a2214bf3153
child 423724 f53fa9ca89b98c01ced273b0ad560aca051838ac
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl, gchang
bugs1389908
milestone56.0
Bug 1389908 - Make sure the NSColorPanel never has a dangling target, and make sure to set the new target before calling setColor. r=spohl, a=gchang MozReview-Commit-ID: L71yb593eR2
widget/cocoa/nsColorPicker.mm
--- 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