| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.h" | 5 #include "chrome/browser/ui/cocoa/tab_modal_confirm_dialog_mac.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
| 8 #include "chrome/browser/ui/browser_dialogs.h" | 8 #include "chrome/browser/ui/browser_dialogs.h" |
| 9 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 9 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 10 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
| 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 11 #include "ui/base/l10n/l10n_util_mac.h" | 11 #include "ui/base/l10n/l10n_util_mac.h" |
| 12 #include "ui/gfx/image/image.h" | 12 #include "ui/gfx/image/image.h" |
| 13 | 13 |
| 14 // The delegate of the NSAlert used to display the dialog. Forwards the alert's | 14 // The delegate of the NSAlert used to display the dialog. Forwards the alert's |
| 15 // completion event to the C++ class |TabModalConfirmDialogDelegate|. | 15 // completion event to the C++ class |TabModalConfirmDialogDelegate|. |
| 16 @interface TabModalConfirmDialogMacBridge : NSObject { | 16 @interface TabModalConfirmDialogMacBridge : NSObject { |
| 17 TabModalConfirmDialogDelegate* delegate_; // weak | 17 TabModalConfirmDialogDelegate* delegate_; // weak |
| 18 } | 18 } |
| 19 - (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate; | 19 - (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate; |
| 20 - (void)alertDidEnd:(NSAlert*)alert | 20 - (void)alertDidEnd:(NSAlert*)alert |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 returnCode:(int)returnCode | 34 returnCode:(int)returnCode |
| 35 contextInfo:(void*)contextInfo { | 35 contextInfo:(void*)contextInfo { |
| 36 if (returnCode == NSAlertFirstButtonReturn) { | 36 if (returnCode == NSAlertFirstButtonReturn) { |
| 37 delegate_->Accept(); | 37 delegate_->Accept(); |
| 38 } else { | 38 } else { |
| 39 delegate_->Cancel(); | 39 delegate_->Cancel(); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 @end | 42 @end |
| 43 | 43 |
| 44 namespace browser { | 44 namespace chrome { |
| 45 | 45 |
| 46 // Declared in browser_dialogs.h so others don't have to depend on our header. | 46 // Declared in browser_dialogs.h so others don't have to depend on our header. |
| 47 void ShowTabModalConfirmDialog(TabModalConfirmDialogDelegate* delegate, | 47 void ShowTabModalConfirmDialog(TabModalConfirmDialogDelegate* delegate, |
| 48 TabContents* tab_contents) { | 48 TabContents* tab_contents) { |
| 49 // Deletes itself when closed. | 49 // Deletes itself when closed. |
| 50 new TabModalConfirmDialogMac(delegate, tab_contents); | 50 new TabModalConfirmDialogMac(delegate, tab_contents); |
| 51 } | 51 } |
| 52 | 52 |
| 53 } | 53 } // namespace chrome |
| 54 | 54 |
| 55 TabModalConfirmDialogMac::TabModalConfirmDialogMac( | 55 TabModalConfirmDialogMac::TabModalConfirmDialogMac( |
| 56 TabModalConfirmDialogDelegate* delegate, | 56 TabModalConfirmDialogDelegate* delegate, |
| 57 TabContents* tab_contents) | 57 TabContents* tab_contents) |
| 58 : ConstrainedWindowMacDelegateSystemSheet( | 58 : ConstrainedWindowMacDelegateSystemSheet( |
| 59 [[[TabModalConfirmDialogMacBridge alloc] initWithDelegate:delegate] | 59 [[[TabModalConfirmDialogMacBridge alloc] initWithDelegate:delegate] |
| 60 autorelease], | 60 autorelease], |
| 61 @selector(alertDidEnd:returnCode:contextInfo:)), | 61 @selector(alertDidEnd:returnCode:contextInfo:)), |
| 62 delegate_(delegate) { | 62 delegate_(delegate) { |
| 63 scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | 63 scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 84 [NSApp endSheet:window | 84 [NSApp endSheet:window |
| 85 returnCode:NSAlertSecondButtonReturn]; | 85 returnCode:NSAlertSecondButtonReturn]; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 // "DeleteDelegate" refers to this class being a ConstrainedWindow delegate | 89 // "DeleteDelegate" refers to this class being a ConstrainedWindow delegate |
| 90 // and deleting itself, not to deleting the member variable |delegate_|. | 90 // and deleting itself, not to deleting the member variable |delegate_|. |
| 91 void TabModalConfirmDialogMac::DeleteDelegate() { | 91 void TabModalConfirmDialogMac::DeleteDelegate() { |
| 92 delete this; | 92 delete this; |
| 93 } | 93 } |
| OLD | NEW |