diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 22:03:17 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 22:03:17 +0000 |
commit | a9e8afc41dd0adfe4ac5900f2b73ff259276e2bd (patch) | |
tree | 7c82250d47888a4057e3048bfc7f54c07027fdb2 /chrome/browser/app_controller_mac.mm | |
parent | e819b55cf062822a23280b4da7760abfd2a86e64 (diff) | |
download | chromium_src-a9e8afc41dd0adfe4ac5900f2b73ff259276e2bd.zip chromium_src-a9e8afc41dd0adfe4ac5900f2b73ff259276e2bd.tar.gz chromium_src-a9e8afc41dd0adfe4ac5900f2b73ff259276e2bd.tar.bz2 |
Add support for constrained windows on os x, based on Avi's GTMWindowSheetController. Add carpet bombing dialog as first per-tab sheet.
Depends http://codereview.appspot.com/105064 .
The main issue with this patch is that GTMWindowSheetController doesn't provide an api to move sheets between windows, so this CL disables tab dragging for tabs with sheets, and fullscreen mode for windows with sheets. We can fix this later.
Other stuff that should be done at some point, but not now:
* Open/Save panels should be per-tab
* Need an ui test that goes to page, then page with sheet, then hit back, forward, reload.
* Bookmark sheets should not be sheets but in a separate window
BUG=14666
TEST=Go to skypher.com/SkyLined/Repro/Chrome/carpet bombing/repro.html , a per-window sheet should appear. Things to test with this dialog:
* Hitting cmd-q while a sheet is open in any tab should not quit but instead focus the sheet.
* Hitting cmd-w while a sheet is open in any tab should not close the window but instead focus the sheet.
* Dragging a tab with a sheet should move the window (and keep the tab visible), not detach the tab.
* Going fullscreen should be disabled for windows with open tabs.
* When a per-tab sheet is open in a non-active tab, it shouldn't steal the focus, i.e. going to the page above, then hitting cmd-t, and then hitting cmd-l should work.
* Closing a non-frontmost tab with a per-tab sheet shouldn't crash.
* Going to the url above and quickly opening a new tab, so that the sheet opens while its tab is not front-most should work (sheet should display only when you switch back to the tab with the sheet).
* Go to google.com, then to skypher.com/SkyLined/Repro/Chrome/carpet bombing/repro.html ,
hit "backward" with open sheet, hit forward, focus location bar, hit enter. This shouldn't crash.
* Hitting escape should dismiss the sheet
* Hitting enter should confirm the sheet.
Review URL: http://codereview.chromium.org/159780
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23091 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/app_controller_mac.mm')
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index d7f4a97..40ccaad 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -18,6 +18,8 @@ #include "chrome/browser/browser_window.h" #import "chrome/browser/cocoa/about_window_controller.h" #import "chrome/browser/cocoa/bookmark_menu_bridge.h" +#import "chrome/browser/cocoa/browser_window_cocoa.h" +#import "chrome/browser/cocoa/browser_window_controller.h" #import "chrome/browser/cocoa/history_menu_bridge.h" #import "chrome/browser/cocoa/clear_browsing_data_controller.h" #import "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h" @@ -27,6 +29,7 @@ #import "chrome/browser/cocoa/ui_localizer.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/download/download_manager.h" +#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" @@ -108,6 +111,45 @@ [self initMenuState]; } +// Checks if there are any tabs with sheets open, and if so, raises one of +// the tabs with a sheet and returns NO. +- (BOOL)shouldQuitWithOpenPerTabSheets { + BrowserList::const_iterator it = BrowserList::begin(); + for (; it != BrowserList::end(); ++it) { + Browser* browser = *it; + BrowserWindowCocoa* window = + static_cast<BrowserWindowCocoa*>(browser->window()); + + // Could do this more nicely with a method e.g. on BWC. If I decide for + // keeping it this way, at least add a DCHECK(). + BrowserWindowController* controller = + (BrowserWindowController*)[window->GetNativeHandle() windowController]; + + if (![controller shouldCloseWithOpenPerTabSheets]) + return NO; + } + + return YES; +} + +// We do not use the normal application teardown process -- this function is +// not called by the system but by us in |quit:|. |NSTerminateLater| is not a +// return value that is supported by |quit:|. +- (NSApplicationTerminateReply)applicationShouldTerminate: + (NSApplication *)sender { + // Do not quit if any per-tab sheets are open, as required by + // GTMWindowSheetController. + if (![self shouldQuitWithOpenPerTabSheets]) + return NSTerminateCancel; + + // Check for in-progress downloads, and prompt the user if they really want to + // quit (and thus cancel the downloads). + if (![self shouldQuitWithInProgressDownloads]) + return NSTerminateCancel; + + return NSTerminateNow; +} + // Called when the app is shutting down. Clean-up as appropriate. - (void)applicationWillTerminate:(NSNotification *)aNotification { DCHECK(!BrowserList::HasBrowserWithProfile([self defaultProfile])); @@ -338,6 +380,9 @@ // the app and leave things on the stack in an unfinalized state. We need to // post a quit message to our run loop so the stack can gracefully unwind. - (IBAction)quit:(id)sender { + if ([self applicationShouldTerminate:NSApp] == NSTerminateCancel) + return; + // TODO(pinkerton): // since we have to roll it ourselves, ask the delegate (ourselves, really) // if we should terminate. For example, we might not want to if the user @@ -346,11 +391,6 @@ // handle it. If it says to continue, post the quit message, otherwise // go back to normal. - // Check for in-progress downloads, and prompt the user if they really want to - // quit (and thus cancel the downloads). - if (![self shouldQuitWithInProgressDownloads]) - return; - NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; [em removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL]; |