OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/command_line.h" |
7 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
8 #include "chrome/browser/ui/browser_dialogs.h" | 9 #include "chrome/browser/ui/browser_dialogs.h" |
| 10 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" |
| 11 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.h" |
| 12 #include "chrome/browser/ui/cocoa/view_util.h" |
9 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
10 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 14 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
| 15 #include "chrome/common/chrome_switches.h" |
11 #include "ui/base/l10n/l10n_util_mac.h" | 16 #include "ui/base/l10n/l10n_util_mac.h" |
12 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
13 | 18 |
14 // The delegate of the NSAlert used to display the dialog. Forwards the alert's | 19 // The delegate of the NSAlert used to display the dialog. Forwards the alert's |
15 // completion event to the C++ class |TabModalConfirmDialogDelegate|. | 20 // completion event to the C++ class |TabModalConfirmDialogDelegate|. |
16 @interface TabModalConfirmDialogMacBridge : NSObject { | 21 @interface TabModalConfirmDialogMacBridge : NSObject { |
17 TabModalConfirmDialogDelegate* delegate_; // weak | 22 TabModalConfirmDialogDelegate* delegate_; // weak |
18 } | 23 } |
19 - (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate; | 24 - (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate; |
20 - (void)alertDidEnd:(NSAlert*)alert | 25 - (void)alertDidEnd:(NSAlert*)alert |
(...skipping 18 matching lines...) Expand all Loading... |
39 delegate_->Cancel(); | 44 delegate_->Cancel(); |
40 } | 45 } |
41 } | 46 } |
42 @end | 47 @end |
43 | 48 |
44 namespace chrome { | 49 namespace chrome { |
45 | 50 |
46 // Declared in browser_dialogs.h so others don't have to depend on our header. | 51 // Declared in browser_dialogs.h so others don't have to depend on our header. |
47 void ShowTabModalConfirmDialog(TabModalConfirmDialogDelegate* delegate, | 52 void ShowTabModalConfirmDialog(TabModalConfirmDialogDelegate* delegate, |
48 TabContents* tab_contents) { | 53 TabContents* tab_contents) { |
49 // Deletes itself when closed. | 54 if (CommandLine::ForCurrentProcess()->HasSwitch( |
50 new TabModalConfirmDialogMac(delegate, tab_contents); | 55 switches::kEnableFramelessConstrainedDialogs)) { |
| 56 // Deletes itself when closed. |
| 57 new TabModalConfirmDialogMac2(delegate, tab_contents); |
| 58 } else { |
| 59 // Deletes itself when closed. |
| 60 new TabModalConfirmDialogMac(delegate, tab_contents); |
| 61 } |
51 } | 62 } |
52 | 63 |
53 } // namespace chrome | 64 } // namespace chrome |
54 | 65 |
55 TabModalConfirmDialogMac::TabModalConfirmDialogMac( | 66 TabModalConfirmDialogMac::TabModalConfirmDialogMac( |
56 TabModalConfirmDialogDelegate* delegate, | 67 TabModalConfirmDialogDelegate* delegate, |
57 TabContents* tab_contents) | 68 TabContents* tab_contents) |
58 : ConstrainedWindowMacDelegateSystemSheet( | 69 : ConstrainedWindowMacDelegateSystemSheet( |
59 [[[TabModalConfirmDialogMacBridge alloc] initWithDelegate:delegate] | 70 [[[TabModalConfirmDialogMacBridge alloc] initWithDelegate:delegate] |
60 autorelease], | 71 autorelease], |
(...skipping 23 matching lines...) Expand all Loading... |
84 [NSApp endSheet:window | 95 [NSApp endSheet:window |
85 returnCode:NSAlertSecondButtonReturn]; | 96 returnCode:NSAlertSecondButtonReturn]; |
86 } | 97 } |
87 } | 98 } |
88 | 99 |
89 // "DeleteDelegate" refers to this class being a ConstrainedWindow delegate | 100 // "DeleteDelegate" refers to this class being a ConstrainedWindow delegate |
90 // and deleting itself, not to deleting the member variable |delegate_|. | 101 // and deleting itself, not to deleting the member variable |delegate_|. |
91 void TabModalConfirmDialogMac::DeleteDelegate() { | 102 void TabModalConfirmDialogMac::DeleteDelegate() { |
92 delete this; | 103 delete this; |
93 } | 104 } |
| 105 |
| 106 |
| 107 |
| 108 |
| 109 |
| 110 |
| 111 |
| 112 |
| 113 |
| 114 |
| 115 @interface TabModalConfirmDialogMacBridge2 : NSObject { |
| 116 TabModalConfirmDialogDelegate* delegate_; // weak |
| 117 } |
| 118 @end |
| 119 |
| 120 @implementation TabModalConfirmDialogMacBridge2 |
| 121 |
| 122 - (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate { |
| 123 if ((self = [super init])) { |
| 124 delegate_ = delegate; |
| 125 DCHECK(delegate_); |
| 126 } |
| 127 return self; |
| 128 } |
| 129 |
| 130 - (void)onAcceptButton:(id)sender { |
| 131 delegate_->Accept(); |
| 132 } |
| 133 |
| 134 - (void)onCancelButton:(id)sender { |
| 135 delegate_->Cancel(); |
| 136 } |
| 137 |
| 138 @end |
| 139 |
| 140 TabModalConfirmDialogMac2::TabModalConfirmDialogMac2( |
| 141 TabModalConfirmDialogDelegate* delegate, |
| 142 TabContents* tab_contents) |
| 143 : delegate_(delegate) { |
| 144 bridge_.reset([[TabModalConfirmDialogMacBridge2 alloc] |
| 145 initWithDelegate:delegate]); |
| 146 |
| 147 alert_.reset([[ConstrainedWindowAlert alloc] init]); |
| 148 [alert_ setMessageText: |
| 149 l10n_util::FixUpWindowsStyleLabel(delegate->GetTitle())]; |
| 150 [alert_ setInformativeText: |
| 151 l10n_util::FixUpWindowsStyleLabel(delegate->GetMessage())]; |
| 152 [alert_ addButtonWithTitle: |
| 153 l10n_util::FixUpWindowsStyleLabel(delegate->GetAcceptButtonTitle()) |
| 154 keyEquivalent:kKeyEquivalentReturn |
| 155 target:bridge_ |
| 156 action:@selector(onAcceptButton:)]; |
| 157 [alert_ addButtonWithTitle: |
| 158 l10n_util::FixUpWindowsStyleLabel(delegate->GetCancelButtonTitle()) |
| 159 keyEquivalent:kKeyEquivalentEscape |
| 160 target:bridge_ |
| 161 action:@selector(onCancelButton:)]; |
| 162 [[alert_ closeButton] setTarget:bridge_]; |
| 163 [[alert_ closeButton] setAction:@selector(onCancelButton:)]; |
| 164 [alert_ layout]; |
| 165 |
| 166 delegate->set_window( |
| 167 new ConstrainedWindowMac2(tab_contents, [alert_ window])); |
| 168 } |
| 169 |
| 170 TabModalConfirmDialogMac2::~TabModalConfirmDialogMac2() { |
| 171 } |
OLD | NEW |