Bug 1056251 - Changing to a Firefox window in a different workspace does not focus automatically. r=masayuki a=lmandel
authorSteven Michaud <smichaud@pobox.com>
Tue, 23 Sep 2014 12:28:40 -0500
changeset 216827 7c118b1cf343
parent 216826 f631df57b34c
child 216828 fb8ff9258d02
push id3931
push userryanvm@gmail.com
push date2014-09-23 19:07 +0000
treeherdermozilla-beta@7c118b1cf343 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki, lmandel
bugs1056251
milestone33.0
Bug 1056251 - Changing to a Firefox window in a different workspace does not focus automatically. r=masayuki a=lmandel
widget/cocoa/nsChildView.mm
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -5617,16 +5617,28 @@ static int32_t RoundUp(double aDouble)
 {
   return YES;
 }
 
 - (void)keyDown:(NSEvent*)theEvent
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
+  // Weird things can happen on keyboard input if the key window isn't in the
+  // current space.  For example see bug 1056251.  To get around this, always
+  // make sure that, if our window is key, it's also made frontmost.  Doing
+  // this automatically switches to whatever space our window is in.  Safari
+  // does something similar.  Our window should normally always be key --
+  // otherwise why is the OS sending us a key down event?  But it's just
+  // possible we're in Gecko's hidden window, so we check first.
+  NSWindow *viewWindow = [self window];
+  if (viewWindow && [viewWindow isKeyWindow]) {
+    [viewWindow orderWindow:NSWindowAbove relativeTo:0];
+  }
+
 #if !defined(RELEASE_BUILD) || defined(DEBUG)
   if (mGeckoChild && mTextInputHandler && mTextInputHandler->IsFocused()) {
 #ifdef MOZ_CRASHREPORTER
     NSWindow* window = [self window];
     NSString* info = [NSString stringWithFormat:@"\nview [%@], window [%@], key event [%@], window is key %i, is fullscreen %i, app is active %i",
                       self, window, theEvent, [window isKeyWindow], ([window styleMask] & (1 << 14)) != 0,
                       [NSApp isActive]];
     nsAutoCString additionalInfo([info UTF8String]);