diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 17:38:32 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 17:38:32 +0000 |
commit | 5845cffa85aabe4a05d6b3e41a769d60fd6658fa (patch) | |
tree | c91d06ec7b47b8f7875126f3edbd558ee262f63c | |
parent | 5306d118a2880703b2e7d24d1267f7c3e67b376b (diff) | |
download | chromium_src-5845cffa85aabe4a05d6b3e41a769d60fd6658fa.zip chromium_src-5845cffa85aabe4a05d6b3e41a769d60fd6658fa.tar.gz chromium_src-5845cffa85aabe4a05d6b3e41a769d60fd6658fa.tar.bz2 |
[Mac] Bring the correct window to the front when calling BrowserWindow::Activate(). Before this would ignore the existence of fullscreen windows.
BUG=http://crbug.com/21145
TEST=Trigger a javascript alert dialog. The original non-fullscreen window should not appear.
Review URL: http://codereview.chromium.org/274060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29137 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 36 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 66711aa..38b001e 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -71,7 +71,7 @@ void BrowserWindowCocoa::Close() { } void BrowserWindowCocoa::Activate() { - [window_ makeKeyAndOrderFront:controller_]; + [controller_ activate]; } void BrowserWindowCocoa::FlashFrame() { diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index da08d45..1be8fbc 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -110,6 +110,9 @@ class TabStripModelObserverBridge; // Called to tell the selected tab to update its loading state. - (void)setIsLoading:(BOOL)isLoading; +// Brings this controller's window to the front. +- (void)activate; + // Make the location bar the first responder, if possible. - (void)focusLocationBar; diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 94eca85..030384d 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -756,6 +756,17 @@ willPositionSheet:(NSWindow*)sheet [toolbarController_ setIsLoading:isLoading]; } +- (void)activate { + // TODO(rohitrao): Figure out the proper activation behavior for fullscreen + // windows. When there is only one window open, this code makes sense, but + // what should we do if we need to activate a non-fullscreen background window + // while a fullscreen window has focus? http://crbug.com/24893 + if (fullscreen_) + [fullscreen_window_ makeKeyAndOrderFront:self]; + else + [window_ makeKeyAndOrderFront:self]; +} + // Make the location bar the first responder, if possible. - (void)focusLocationBar { [toolbarController_ focusLocationBar]; diff --git a/chrome/browser/cocoa/browser_window_controller_unittest.mm b/chrome/browser/cocoa/browser_window_controller_unittest.mm index 29a3221..4df1482 100644 --- a/chrome/browser/cocoa/browser_window_controller_unittest.mm +++ b/chrome/browser/cocoa/browser_window_controller_unittest.mm @@ -132,6 +132,27 @@ TEST_F(BrowserWindowControllerTest, TestFullscreen) { EXPECT_TRUE([controller_ fullscreenWindow]); } +TEST_F(BrowserWindowControllerTest, TestActivate) { + // Note use of "controller", not "controller_" + scoped_nsobject<BrowserWindowController> controller; + controller.reset([[BrowserWindowControllerFakeFullscreen alloc] + initWithBrowser:browser_helper_.browser() + takeOwnership:NO]); + EXPECT_FALSE([controller isFullscreen]); + + [controller activate]; + NSWindow* frontmostWindow = [[NSApp orderedWindows] objectAtIndex:0]; + EXPECT_EQ(frontmostWindow, [controller window]); + + [controller setFullscreen:YES]; + [controller activate]; + frontmostWindow = [[NSApp orderedWindows] objectAtIndex:0]; + EXPECT_EQ(frontmostWindow, [controller fullscreenWindow]); + + // We have to cleanup after ourselves by unfullscreening. + [controller setFullscreen:NO]; +} + TEST_F(BrowserWindowControllerTest, TestNormal) { // Force the bookmark bar to be shown. browser_helper_.profile()->GetPrefs()-> |