Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_utils.mm

Issue 9310075: Ensure the previously active browser window gets the focus after a browser window is closed on OSX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: separate return to its own line Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/browser_window_utils.h" 5 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
6 6
7 #include <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/global_keyboard_shortcuts_mac.h" 11 #include "chrome/browser/global_keyboard_shortcuts_mac.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/browser_window.h"
13 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" 15 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
14 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" 16 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
15 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 17 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
16 #include "content/public/browser/native_web_keyboard_event.h" 18 #include "content/public/browser/native_web_keyboard_event.h"
17 19
18 @interface MenuWalker : NSObject 20 @interface MenuWalker : NSObject
19 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key 21 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
20 menu:(NSMenu*)menu; 22 menu:(NSMenu*)menu;
21 @end 23 @end
22 24
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 181
180 + (void)activateWindowForController:(NSWindowController*)controller { 182 + (void)activateWindowForController:(NSWindowController*)controller {
181 // Per http://crbug.com/73779 and http://crbug.com/75223, we need this to 183 // Per http://crbug.com/73779 and http://crbug.com/75223, we need this to
182 // properly activate windows if Chrome is not the active application. 184 // properly activate windows if Chrome is not the active application.
183 [[controller window] makeKeyAndOrderFront:controller]; 185 [[controller window] makeKeyAndOrderFront:controller];
184 ProcessSerialNumber psn; 186 ProcessSerialNumber psn;
185 GetCurrentProcess(&psn); 187 GetCurrentProcess(&psn);
186 SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); 188 SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly);
187 } 189 }
188 190
191 + (void)selectPreviousActiveBrowserWindow:(Browser*)closedBrowser {
192 if (![NSApp isActive] || closedBrowser != BrowserList::GetLastActive())
193 return;
Scott Hess - ex-Googler 2012/02/09 22:51:54 Are you sure about the -isActive test? You would
jennb 2012/02/09 23:25:24 My thinking is that if Chrome is not active, then
194
195 // Select previous active window if this is the current active window.
196 // Otherwise, OSX will always give focus to a Panel window after this one
197 // is closed because Panels have a higher priority NSWindowLevel.
198 BrowserList::const_reverse_iterator iter = BrowserList::begin_last_active();
199 BrowserList::const_reverse_iterator end = BrowserList::end_last_active();
200 for (; iter != end; ++iter) {
201 Browser* browser = *iter;
202 if (browser != closedBrowser &&
203 [browser->window()->GetNativeHandle() canBecomeKeyWindow]) {
204 browser->window()->Activate();
205 return;
206 }
207 }
208 }
Scott Hess - ex-Googler 2012/02/09 22:51:54 This will subvert the ordering logic if there are
jennb 2012/02/09 23:25:24 Thanks for pointing out the non-browser window cas
189 @end 209 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_utils.h ('k') | chrome/browser/ui/cocoa/tabs/tab_window_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698