Bug 1389908 - Make sure the NSColorPanel never has a dangling target, and make sure to set the new target before calling setColor. r?spohl draft
authorMarkus Stange <mstange@themasta.com>
Mon, 21 Aug 2017 19:16:22 -0400
changeset 650177 d0e81a4d2e195de17b0095ffd40f645742266fe2
parent 650176 99796c8f320a229750002c12e0cdb359efa61a6a
child 727316 9c05a200e6b2a7eab5630206c35fea87636b9adc
push id75289
push userbmo:mstange@themasta.com
push dateMon, 21 Aug 2017 23:16:56 +0000
reviewersspohl
bugs1389908
milestone57.0a1
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
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