Fix crashes when window closed with key-combination (alters previous fix to work on both Tiger and Leopard). b=396860 r=joshmoz sr=roc a=dsicore
authorsmichaud@pobox.com
Tue, 23 Oct 2007 11:34:29 -0700
changeset 7106 b0ffb1d916561a3f3cb5a7e49b3a9da44f01ac3d
parent 7105 ce6093b9f6625abba78ca0222223e899e8a0b8ad
child 7107 0644ef61b858a9e132d2c7cca2f51db1a4c3913c
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoshmoz, roc, dsicore
bugs396860
milestone1.9a9pre
Fix crashes when window closed with key-combination (alters previous fix to work on both Tiger and Leopard). b=396860 r=joshmoz sr=roc a=dsicore
widget/src/cocoa/nsChildView.mm
widget/src/cocoa/nsCocoaWindow.mm
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -4020,26 +4020,18 @@ static BOOL keyUpAlreadySentKeyDown = NO
 
 
 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent
 {
   // don't bother if we don't have a gecko widget or we're in composition
   if (!mGeckoChild || nsTSMManager::IsComposing())
     return NO;
 
-  // Retain and release our native window to avoid crashes when it's closed
-  // as a result of processing a key equivalent (e.g. Command+w or Command+q).
-  NSWindow *ourNativeWindow = [self nativeWindow];
-  if (ourNativeWindow)
-    ourNativeWindow = [ourNativeWindow retain];
   // see if the menu system will handle the event
-  BOOL menuRetval = [[NSApp mainMenu] performKeyEquivalent:theEvent];
-  if (ourNativeWindow)
-    [ourNativeWindow release];
-  if (menuRetval)
+  if ([[NSApp mainMenu] performKeyEquivalent:theEvent])
     return YES;
 
   // don't handle this if certain modifiers are down - those should
   // be sent as normal key up/down events and cocoa will do so automatically
   // if we reject here
   unsigned int modifierFlags = [theEvent modifierFlags];
   if ((modifierFlags & NSFunctionKeyMask) || (modifierFlags & NSNumericPadKeyMask))
     return NO;
--- a/widget/src/cocoa/nsCocoaWindow.mm
+++ b/widget/src/cocoa/nsCocoaWindow.mm
@@ -1310,16 +1310,28 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKe
 {
   nsCocoaWindow *geckoWindow = [[self delegate] geckoWidget];
   nsEventStatus status = nsEventStatus_eIgnore;
   nsGUIEvent guiEvent(PR_TRUE, NS_OS_TOOLBAR, geckoWindow);
   guiEvent.time = PR_IntervalNow();
   geckoWindow->DispatchEvent(&guiEvent, status);
 }
 
+// Retain and release "self" to avoid crashes when our widget (and its native
+// window) is closed as a result of processing a key equivalent (e.g.
+// Command+w or Command+q).  This workaround is only needed for a window
+// that can become key.
+- (BOOL)performKeyEquivalent:(NSEvent*)theEvent
+{
+  NSWindow *nativeWindow = [self retain];
+  BOOL retval = [super performKeyEquivalent:theEvent];
+  [nativeWindow release];
+  return retval;
+}
+
 @end
 
 @implementation PopupWindow
 
 // The OS treats our custom popup windows very strangely -- many mouse events
 // sent to them never reach their target NSView objects.  (That these windows
 // are borderless and of level NSPopUpMenuWindowLevel may have something to do
 // with it.)  The best solution is to pre-empt the OS, as follows.  (All
@@ -1489,9 +1501,21 @@ NS_IMETHODIMP nsCocoaWindow::EndSecureKe
 // accurate test of what Apple means by "visibility".
 - (BOOL)canBecomeMainWindow
 {
   if (![self isVisible])
     return NO;
   return YES;
 }
 
+// Retain and release "self" to avoid crashes when our widget (and its native
+// window) is closed as a result of processing a key equivalent (e.g.
+// Command+w or Command+q).  This workaround is only needed for a window
+// that can become key.
+- (BOOL)performKeyEquivalent:(NSEvent*)theEvent
+{
+  NSWindow *nativeWindow = [self retain];
+  BOOL retval = [super performKeyEquivalent:theEvent];
+  [nativeWindow release];
+  return retval;
+}
+
 @end