diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 21:13:51 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 21:13:51 +0000 |
commit | 8ecce348742249122fbaf4a21870c849e4876d04 (patch) | |
tree | 8e2af74412c7dab1e6236dbd98e9cb88f28185c8 /chrome/browser/cocoa | |
parent | ca57825692d6af2d3425d2f37490b9255a058210 (diff) | |
download | chromium_src-8ecce348742249122fbaf4a21870c849e4876d04.zip chromium_src-8ecce348742249122fbaf4a21870c849e4876d04.tar.gz chromium_src-8ecce348742249122fbaf4a21870c849e4876d04.tar.bz2 |
[Mac] Make the Confirm to Quit floaty panel a singleton so multiple panels do not appear.
BUG=61815
TEST=With the confirm-to-quit lab enabled, mash Cmd+Q. Only 1 floaty window appears.
Review URL: http://codereview.chromium.org/5255001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67001 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
3 files changed, 31 insertions, 12 deletions
diff --git a/chrome/browser/cocoa/confirm_quit_panel_controller.h b/chrome/browser/cocoa/confirm_quit_panel_controller.h index c518222..fccafa9f 100644 --- a/chrome/browser/cocoa/confirm_quit_panel_controller.h +++ b/chrome/browser/cocoa/confirm_quit_panel_controller.h @@ -11,8 +11,9 @@ @interface ConfirmQuitPanelController : NSWindowController<NSWindowDelegate> { } -// Designated initializer. Loads window from NIB but does not show it. -- (id)init; +// Returns a singleton instance of the Controller. This will create one if it +// does not currently exist. ++ (ConfirmQuitPanelController*)sharedController; // Shows the window. - (void)showWindow:(id)sender; diff --git a/chrome/browser/cocoa/confirm_quit_panel_controller.mm b/chrome/browser/cocoa/confirm_quit_panel_controller.mm index 5b624dd..131c40db 100644 --- a/chrome/browser/cocoa/confirm_quit_panel_controller.mm +++ b/chrome/browser/cocoa/confirm_quit_panel_controller.mm @@ -11,12 +11,23 @@ #import "chrome/browser/cocoa/confirm_quit_panel_controller.h" @interface ConfirmQuitPanelController (Private) +- (id)initInternal; - (void)animateFadeOut; @end +ConfirmQuitPanelController* g_confirmQuitPanelController = nil; + @implementation ConfirmQuitPanelController -- (id)init { ++ (ConfirmQuitPanelController*)sharedController { + if (!g_confirmQuitPanelController) { + g_confirmQuitPanelController = + [[ConfirmQuitPanelController alloc] initInternal]; + } + return g_confirmQuitPanelController; +} + +- (id)initInternal { NSString* nibPath = [mac_util::MainAppBundle() pathForResource:@"ConfirmQuitPanel" ofType:@"nib"]; @@ -34,10 +45,15 @@ // Release all animations because CAAnimation retains its delegate (self), // which will cause a retain cycle. Break it! [[self window] setAnimations:[NSDictionary dictionary]]; + g_confirmQuitPanelController = nil; [self autorelease]; } - (void)showWindow:(id)sender { + // If a panel that is fading out is going to be reused here, make sure it + // does not get released when the animation finishes. + scoped_nsobject<ConfirmQuitPanelController> stayAlive([self retain]); + [[self window] setAnimations:[NSDictionary dictionary]]; [[self window] center]; [[self window] setAlphaValue:1.0]; [super showWindow:sender]; @@ -62,7 +78,7 @@ [[window animator] setAlphaValue:0.0]; } -- (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)flag { +- (void)animationDidStop:(CAAnimation*)theAnimation finished:(BOOL)finished { [self close]; } diff --git a/chrome/browser/cocoa/confirm_quit_panel_controller_unittest.mm b/chrome/browser/cocoa/confirm_quit_panel_controller_unittest.mm index fddf164..93de9ba 100644 --- a/chrome/browser/cocoa/confirm_quit_panel_controller_unittest.mm +++ b/chrome/browser/cocoa/confirm_quit_panel_controller_unittest.mm @@ -9,18 +9,20 @@ namespace { class ConfirmQuitPanelControllerTest : public CocoaTest { - public: - ConfirmQuitPanelControllerTest() : controller_(nil) { - } - - ConfirmQuitPanelController* controller_; // Weak, owns self. }; TEST_F(ConfirmQuitPanelControllerTest, ShowAndDismiss) { - controller_ = [[ConfirmQuitPanelController alloc] init]; - [controller_ showWindow:nil]; - [controller_ dismissPanel]; // Releases self. + ConfirmQuitPanelController* controller = + [ConfirmQuitPanelController sharedController]; + // Test singleton. + EXPECT_EQ(controller, [ConfirmQuitPanelController sharedController]); + [controller showWindow:nil]; + [controller dismissPanel]; // Releases self. + // The controller should still be the singleton instance until after the + // animation runs and the window closes. That will happen after this test body + // finishes executing. + EXPECT_EQ(controller, [ConfirmQuitPanelController sharedController]); } } // namespace |