Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3276)

Unified Diff: chrome/browser/ui/cocoa/tab_modal_dialog_mac.mm

Issue 8851007: WIP / Do not commit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/tab_modal_dialog_mac.h ('k') | chrome/browser/ui/gtk/browser_window_gtk.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/tab_modal_dialog_mac.mm
diff --git a/chrome/browser/ui/cocoa/tab_modal_dialog_mac.mm b/chrome/browser/ui/cocoa/tab_modal_dialog_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..01f9a43de4e23426d338d844a5eb9e01ccffe283
--- /dev/null
+++ b/chrome/browser/ui/cocoa/tab_modal_dialog_mac.mm
@@ -0,0 +1,93 @@
+// Copyright (c) 2011 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/ui/cocoa/tab_modal_dialog_mac.h"
+
+#include "base/memory/scoped_nsobject.h"
+#include "chrome/browser/ui/tab_modal_dialog_delegate.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "ui/base/l10n/l10n_util_mac.h"
+#include "ui/gfx/image/image.h"
+
+// The delegate of the NSAlert used to display the dialog. Forwards the alert's
+// completion event to the C++ class |TabModalDialogDelegate|.
+@interface TabModalDialogMacBridge : NSObject {
+ TabModalDialogDelegate* delegate_; // weak
+}
+- (id)initWithDelegate:(TabModalDialogDelegate*)delegate;
+- (void)alertDidEnd:(NSAlert*)alert
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo;
+@end
+
+@implementation TabModalDialogMacBridge
+- (id)initWithDelegate:(TabModalDialogDelegate*)delegate {
+ if ((self = [super init])) {
+ delegate_ = delegate;
+ }
+ return self;
+}
+
+- (void)alertDidEnd:(NSAlert*)alert
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo {
+ if (returnCode == NSAlertFirstButtonReturn) {
+ delegate_->Accept();
+ } else {
+ delegate_->Cancel();
+ }
+}
+@end
+
+namespace browser {
+
+// Declared in browser_dialogs.h so others don't have to depend on our header.
+void ShowTabModalDialog(TabModalDialogDelegate* delegate,
+ gfx::NativeWindow parent_window,
+ TabContents* tab_contents) {
+ new TabModalDialogMac(parent_window, delegate, tab_contents);
+}
+
+}
+
+TabModalDialogMac::TabModalDialogMac(
+ NSWindow* parent,
+ TabModalDialogDelegate* delegate,
+ TabContents* tab_contents)
+ : ConstrainedWindowMacDelegateSystemSheet(
+ [[[TabModalDialogMacBridge alloc] initWithDelegate:delegate]
+ autorelease],
+ @selector(alertDidEnd:returnCode:contextInfo:)),
+ delegate_(delegate) {
+ scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
+ [alert setMessageText:
+ l10n_util::FixUpWindowsStyleLabel(delegate->GetTitle())];
+ [alert setInformativeText:
+ l10n_util::FixUpWindowsStyleLabel(delegate->GetMessage())];
+ [alert addButtonWithTitle:
+ l10n_util::FixUpWindowsStyleLabel(delegate->GetAcceptButtonTitle())];
+ [alert addButtonWithTitle:
+ l10n_util::FixUpWindowsStyleLabel(delegate->GetCancelButtonTitle())];
+ gfx::Image* icon = delegate->GetIcon();
+ if (icon)
+ [alert setIcon:icon->ToNSImage()];
+
+ set_sheet(alert);
+
+ TabContentsWrapper* wrapper =
+ TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
+ delegate->set_window(new ConstrainedWindowMac(wrapper, this));
+}
+
+TabModalDialogMac::~TabModalDialogMac() {
+ NSWindow* window = [(NSAlert*)sheet() window];
+ if (window && is_sheet_open()) {
+ [NSApp endSheet:window
+ returnCode:NSAlertSecondButtonReturn];
+ }
+}
+
+void TabModalDialogMac::DeleteDelegate() {
+ delete this;
+}
« no previous file with comments | « chrome/browser/ui/cocoa/tab_modal_dialog_mac.h ('k') | chrome/browser/ui/gtk/browser_window_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698