summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/constrained_window_mac.mm
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 22:03:17 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 22:03:17 +0000
commita9e8afc41dd0adfe4ac5900f2b73ff259276e2bd (patch)
tree7c82250d47888a4057e3048bfc7f54c07027fdb2 /chrome/browser/cocoa/constrained_window_mac.mm
parente819b55cf062822a23280b4da7760abfd2a86e64 (diff)
downloadchromium_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/cocoa/constrained_window_mac.mm')
-rw-r--r--chrome/browser/cocoa/constrained_window_mac.mm87
1 files changed, 87 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/constrained_window_mac.mm b/chrome/browser/cocoa/constrained_window_mac.mm
new file mode 100644
index 0000000..67d1030
--- /dev/null
+++ b/chrome/browser/cocoa/constrained_window_mac.mm
@@ -0,0 +1,87 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/cocoa/constrained_window_mac.h"
+
+#import "chrome/browser/cocoa/browser_window_controller.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_contents_view.h"
+#import "third_party/GTM/AppKit/GTMWindowSheetController.h"
+
+ConstrainedWindowMacDelegate::~ConstrainedWindowMacDelegate() {}
+
+void ConstrainedWindowMacDelegateSystemSheet::RunSheet(
+ GTMWindowSheetController* sheetController,
+ NSView* view) {
+ NSArray* params = [NSArray arrayWithObjects:
+ [NSNull null], // window, must be [NSNull null]
+ delegate_.get(),
+ [NSValue valueWithPointer:didEndSelector_],
+ [NSValue valueWithPointer:NULL], // context info for didEndSelector_.
+ nil];
+ [sheetController beginSystemSheet:systemSheet_
+ modalForView:view
+ withParameters:params];
+}
+
+void ConstrainedWindowMacDelegateCustomSheet::RunSheet(
+ GTMWindowSheetController* sheetController,
+ NSView* view) {
+ [sheetController beginSheet:customSheet_.get()
+ modalForView:view modalDelegate:delegate_.get()
+ didEndSelector:didEndSelector_
+ contextInfo:NULL];
+}
+
+// static
+ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog(
+ TabContents* parent,
+ ConstrainedWindowMacDelegate* delegate) {
+ return new ConstrainedWindowMac(parent, delegate);
+}
+
+ConstrainedWindowMac::ConstrainedWindowMac(
+ TabContents* owner, ConstrainedWindowMacDelegate* delegate)
+ : owner_(owner),
+ delegate_(delegate),
+ controller_(nil) {
+ DCHECK(owner);
+ DCHECK(delegate);
+
+ // The TabContents only has a native window if it is currently visible. In
+ // this case, open the sheet now. Else, Realize() will be called later, when
+ // our tab becomes visible.
+ NSWindow* browserWindow = owner_->view()->GetTopLevelNativeWindow();
+ NSWindowController* controller = [browserWindow windowController];
+ if (controller != nil) {
+ DCHECK([controller isKindOfClass:[BrowserWindowController class]]);
+ Realize(static_cast<BrowserWindowController*>(controller));
+ }
+}
+
+ConstrainedWindowMac::~ConstrainedWindowMac() {}
+
+void ConstrainedWindowMac::CloseConstrainedWindow() {
+ // Note: controller_ can be `nil` here if the sheet was never realized. That's
+ // ok.
+ [controller_ removeConstrainedWindow:this];
+ delegate_->DeleteDelegate();
+ owner_->WillClose(this);
+
+ delete this;
+}
+
+void ConstrainedWindowMac::Realize(BrowserWindowController* controller) {
+ if (controller_ != nil) {
+ DCHECK(controller_ == controller);
+ return;
+ }
+ DCHECK(controller != nil);
+
+ // Remember the controller we're adding ourselves to, so that we can later
+ // remove us from it.
+ controller_ = controller;
+ [controller_ attachConstrainedWindow:this];
+ delegate_->set_sheet_open(true);
+}