diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-14 21:15:05 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-14 21:15:05 +0000 |
commit | 817694ec628728a771a9be586c66706f3739209c (patch) | |
tree | 25b68eccb22892e7ce30e41e6c25d75dcfa32b16 | |
parent | f94f0f14dd3c9c49c6da8bdf3d7de19f4a6fb6b7 (diff) | |
download | chromium_src-817694ec628728a771a9be586c66706f3739209c.zip chromium_src-817694ec628728a771a9be586c66706f3739209c.tar.gz chromium_src-817694ec628728a771a9be586c66706f3739209c.tar.bz2 |
Implement PanelBrowserWindowCocoa::Activate.
BUG=none
TEST=Double-clicking a panel in the task manager brings it to the foreground.
Review URL: http://codereview.chromium.org/7787010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101158 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 47 insertions, 7 deletions
diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm index 6444bbc..3508698 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller.mm @@ -4,8 +4,6 @@ #import "chrome/browser/ui/cocoa/browser_window_controller.h" -#include <Carbon/Carbon.h> - #include <cmath> #include <numeric> @@ -724,10 +722,7 @@ enum { } - (void)activate { - [[self window] makeKeyAndOrderFront:self]; - ProcessSerialNumber psn; - GetCurrentProcess(&psn); - SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); + [BrowserWindowUtils activateWindowForController:self]; } // Determine whether we should let a window zoom/unzoom to the given |newFrame|. diff --git a/chrome/browser/ui/cocoa/browser_window_utils.h b/chrome/browser/ui/cocoa/browser_window_utils.h index 6c6edcc..1b67ed9 100644 --- a/chrome/browser/ui/cocoa/browser_window_utils.h +++ b/chrome/browser/ui/cocoa/browser_window_utils.h @@ -37,6 +37,8 @@ struct NativeWebKeyboardEvent; + (NSPoint)themePatternPhaseFor:(NSView*)windowView withTabStrip:(NSView*)tabStripView; + ++ (void)activateWindowForController:(NSWindowController*)controller; @end #endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_UTILS_H_ diff --git a/chrome/browser/ui/cocoa/browser_window_utils.mm b/chrome/browser/ui/cocoa/browser_window_utils.mm index aea2e9b..d0809b7 100644 --- a/chrome/browser/ui/cocoa/browser_window_utils.mm +++ b/chrome/browser/ui/cocoa/browser_window_utils.mm @@ -4,6 +4,8 @@ #import "chrome/browser/ui/cocoa/browser_window_utils.h" +#include <Carbon/Carbon.h> + #include "base/logging.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/global_keyboard_shortcuts_mac.h" @@ -175,4 +177,13 @@ const CGFloat kPatternVerticalOffsetNoTabStrip = 3; + kPatternVerticalOffset); } ++ (void)activateWindowForController:(NSWindowController*)controller { + // Per http://crbug.com/73779 and http://crbug.com/75223, we need this to + // properly activate windows if Chrome is not the active application. + [[controller window] makeKeyAndOrderFront:controller]; + ProcessSerialNumber psn; + GetCurrentProcess(&psn); + SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); +} + @end diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa.h b/chrome/browser/ui/panels/panel_browser_window_cocoa.h index 558ad65..5cd7e1c 100644 --- a/chrome/browser/ui/panels/panel_browser_window_cocoa.h +++ b/chrome/browser/ui/panels/panel_browser_window_cocoa.h @@ -76,6 +76,7 @@ class PanelBrowserWindowCocoa : public NativePanel { FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, KeyEvent); FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, ThemeProvider); FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, SetTitle); + FRIEND_TEST_ALL_PREFIXES(PanelBrowserWindowCocoaTest, ActivatePanel); bool isClosed(); diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm index f335ee3..dabb216 100644 --- a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm +++ b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm @@ -110,10 +110,13 @@ void PanelBrowserWindowCocoa::ClosePanel() { } void PanelBrowserWindowCocoa::ActivatePanel() { - NOTIMPLEMENTED(); + if (!is_shown_) + return; + [BrowserWindowUtils activateWindowForController:controller_]; } void PanelBrowserWindowCocoa::DeactivatePanel() { + // TODO(dcheng): Implement. See crbug.com/51364 for more details. NOTIMPLEMENTED(); } diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm b/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm index 814f448..682911f 100644 --- a/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm +++ b/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm @@ -376,3 +376,31 @@ TEST_F(PanelBrowserWindowCocoaTest, SetTitle) { EXPECT_NSNE([[native_window->controller_ window] title], previousTitle); ClosePanelAndWait(panel->browser()); } + +TEST_F(PanelBrowserWindowCocoaTest, ActivatePanel) { + Panel* panel = CreateTestPanel("Test Panel"); + Panel* panel2 = CreateTestPanel("Test Panel 2"); + ASSERT_TRUE(panel); + ASSERT_TRUE(panel2); + + PanelBrowserWindowCocoa* native_window = + static_cast<PanelBrowserWindowCocoa*>(panel->native_panel()); + ASSERT_TRUE(native_window); + PanelBrowserWindowCocoa* native_window2 = + static_cast<PanelBrowserWindowCocoa*>(panel2->native_panel()); + ASSERT_TRUE(native_window2); + + // No one has a good answer why but apparently windows can't take keyboard + // focus outside of interactive UI tests. BrowserWindowController uses the + // same way of testing this. + native_window->ActivatePanel(); + NSWindow* frontmostWindow = [[NSApp orderedWindows] objectAtIndex:0]; + EXPECT_NSEQ(frontmostWindow, [native_window->controller_ window]); + + native_window2->ActivatePanel(); + frontmostWindow = [[NSApp orderedWindows] objectAtIndex:0]; + EXPECT_NSEQ(frontmostWindow, [native_window2->controller_ window]); + + ClosePanelAndWait(panel->browser()); + ClosePanelAndWait(panel2->browser()); +} |