| 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/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/cocoa/constrained_window/constrained_window_alert.h" | 9 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" |
| 10 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.h" | 10 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac2.h" |
| 11 #include "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 11 #include "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 13 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 12 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
| 14 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 15 #include "ui/base/l10n/l10n_util_mac.h" | 14 #include "ui/base/l10n/l10n_util_mac.h" |
| 16 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 17 | 16 |
| 18 // static | 17 // static |
| 19 TabModalConfirmDialog* TabModalConfirmDialog::Create( | 18 TabModalConfirmDialog* TabModalConfirmDialog::Create( |
| 20 TabModalConfirmDialogDelegate* delegate, | 19 TabModalConfirmDialogDelegate* delegate, |
| 21 TabContents* tab_contents) { | 20 content::WebContents* web_contents) { |
| 22 if (chrome::IsFramelessConstrainedDialogEnabled()) { | 21 if (chrome::IsFramelessConstrainedDialogEnabled()) { |
| 23 // Deletes itself when closed. | 22 // Deletes itself when closed. |
| 24 return new TabModalConfirmDialogMac2(delegate, tab_contents); | 23 return new TabModalConfirmDialogMac2(delegate, web_contents); |
| 25 } | 24 } |
| 26 // Deletes itself when closed. | 25 // Deletes itself when closed. |
| 27 return new TabModalConfirmDialogMac(delegate, tab_contents); | 26 return new TabModalConfirmDialogMac(delegate, web_contents); |
| 28 } | 27 } |
| 29 | 28 |
| 30 // The delegate of the NSAlert used to display the dialog. Forwards the alert's | 29 // The delegate of the NSAlert used to display the dialog. Forwards the alert's |
| 31 // completion event to the C++ class |TabModalConfirmDialogDelegate|. | 30 // completion event to the C++ class |TabModalConfirmDialogDelegate|. |
| 32 @interface TabModalConfirmDialogMacBridge : NSObject { | 31 @interface TabModalConfirmDialogMacBridge : NSObject { |
| 33 TabModalConfirmDialogDelegate* delegate_; // weak | 32 TabModalConfirmDialogDelegate* delegate_; // weak |
| 34 } | 33 } |
| 35 - (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate; | 34 - (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate; |
| 36 - (void)alertDidEnd:(NSAlert*)alert | 35 - (void)alertDidEnd:(NSAlert*)alert |
| 37 returnCode:(int)returnCode | 36 returnCode:(int)returnCode |
| (...skipping 14 matching lines...) Expand all Loading... |
| 52 if (returnCode == NSAlertFirstButtonReturn) { | 51 if (returnCode == NSAlertFirstButtonReturn) { |
| 53 delegate_->Accept(); | 52 delegate_->Accept(); |
| 54 } else { | 53 } else { |
| 55 delegate_->Cancel(); | 54 delegate_->Cancel(); |
| 56 } | 55 } |
| 57 } | 56 } |
| 58 @end | 57 @end |
| 59 | 58 |
| 60 TabModalConfirmDialogMac::TabModalConfirmDialogMac( | 59 TabModalConfirmDialogMac::TabModalConfirmDialogMac( |
| 61 TabModalConfirmDialogDelegate* delegate, | 60 TabModalConfirmDialogDelegate* delegate, |
| 62 TabContents* tab_contents) | 61 content::WebContents* web_contents) |
| 63 : ConstrainedWindowMacDelegateSystemSheet( | 62 : ConstrainedWindowMacDelegateSystemSheet( |
| 64 [[[TabModalConfirmDialogMacBridge alloc] initWithDelegate:delegate] | 63 [[[TabModalConfirmDialogMacBridge alloc] initWithDelegate:delegate] |
| 65 autorelease], | 64 autorelease], |
| 66 @selector(alertDidEnd:returnCode:contextInfo:)), | 65 @selector(alertDidEnd:returnCode:contextInfo:)), |
| 67 delegate_(delegate) { | 66 delegate_(delegate) { |
| 68 scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | 67 scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); |
| 69 [alert setMessageText: | 68 [alert setMessageText: |
| 70 l10n_util::FixUpWindowsStyleLabel(delegate->GetTitle())]; | 69 l10n_util::FixUpWindowsStyleLabel(delegate->GetTitle())]; |
| 71 [alert setInformativeText: | 70 [alert setInformativeText: |
| 72 l10n_util::FixUpWindowsStyleLabel(delegate->GetMessage())]; | 71 l10n_util::FixUpWindowsStyleLabel(delegate->GetMessage())]; |
| 73 [alert addButtonWithTitle: | 72 [alert addButtonWithTitle: |
| 74 l10n_util::FixUpWindowsStyleLabel(delegate->GetAcceptButtonTitle())]; | 73 l10n_util::FixUpWindowsStyleLabel(delegate->GetAcceptButtonTitle())]; |
| 75 [alert addButtonWithTitle: | 74 [alert addButtonWithTitle: |
| 76 l10n_util::FixUpWindowsStyleLabel(delegate->GetCancelButtonTitle())]; | 75 l10n_util::FixUpWindowsStyleLabel(delegate->GetCancelButtonTitle())]; |
| 77 gfx::Image* icon = delegate->GetIcon(); | 76 gfx::Image* icon = delegate->GetIcon(); |
| 78 if (icon) | 77 if (icon) |
| 79 [alert setIcon:icon->ToNSImage()]; | 78 [alert setIcon:icon->ToNSImage()]; |
| 80 | 79 |
| 81 set_sheet(alert); | 80 set_sheet(alert); |
| 82 | 81 |
| 83 delegate->set_window( | 82 delegate->set_window(new ConstrainedWindowMac(web_contents, this)); |
| 84 new ConstrainedWindowMac(tab_contents->web_contents(), this)); | |
| 85 } | 83 } |
| 86 | 84 |
| 87 TabModalConfirmDialogMac::~TabModalConfirmDialogMac() { | 85 TabModalConfirmDialogMac::~TabModalConfirmDialogMac() { |
| 88 CancelTabModalDialog(); | 86 CancelTabModalDialog(); |
| 89 } | 87 } |
| 90 | 88 |
| 91 // "DeleteDelegate" refers to this class being a ConstrainedWindow delegate | 89 // "DeleteDelegate" refers to this class being a ConstrainedWindow delegate |
| 92 // and deleting itself, not to deleting the member variable |delegate_|. | 90 // and deleting itself, not to deleting the member variable |delegate_|. |
| 93 void TabModalConfirmDialogMac::DeleteDelegate() { | 91 void TabModalConfirmDialogMac::DeleteDelegate() { |
| 94 delete this; | 92 delete this; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 129 } |
| 132 | 130 |
| 133 - (void)onCancelButton:(id)sender { | 131 - (void)onCancelButton:(id)sender { |
| 134 delegate_->Cancel(); | 132 delegate_->Cancel(); |
| 135 } | 133 } |
| 136 | 134 |
| 137 @end | 135 @end |
| 138 | 136 |
| 139 TabModalConfirmDialogMac2::TabModalConfirmDialogMac2( | 137 TabModalConfirmDialogMac2::TabModalConfirmDialogMac2( |
| 140 TabModalConfirmDialogDelegate* delegate, | 138 TabModalConfirmDialogDelegate* delegate, |
| 141 TabContents* tab_contents) | 139 content::WebContents* web_contents) |
| 142 : delegate_(delegate) { | 140 : delegate_(delegate) { |
| 143 bridge_.reset([[TabModalConfirmDialogMacBridge2 alloc] | 141 bridge_.reset([[TabModalConfirmDialogMacBridge2 alloc] |
| 144 initWithDelegate:delegate]); | 142 initWithDelegate:delegate]); |
| 145 | 143 |
| 146 alert_.reset([[ConstrainedWindowAlert alloc] init]); | 144 alert_.reset([[ConstrainedWindowAlert alloc] init]); |
| 147 [alert_ setMessageText: | 145 [alert_ setMessageText: |
| 148 l10n_util::FixUpWindowsStyleLabel(delegate->GetTitle())]; | 146 l10n_util::FixUpWindowsStyleLabel(delegate->GetTitle())]; |
| 149 [alert_ setInformativeText: | 147 [alert_ setInformativeText: |
| 150 l10n_util::FixUpWindowsStyleLabel(delegate->GetMessage())]; | 148 l10n_util::FixUpWindowsStyleLabel(delegate->GetMessage())]; |
| 151 [alert_ addButtonWithTitle: | 149 [alert_ addButtonWithTitle: |
| 152 l10n_util::FixUpWindowsStyleLabel(delegate->GetAcceptButtonTitle()) | 150 l10n_util::FixUpWindowsStyleLabel(delegate->GetAcceptButtonTitle()) |
| 153 keyEquivalent:kKeyEquivalentReturn | 151 keyEquivalent:kKeyEquivalentReturn |
| 154 target:bridge_ | 152 target:bridge_ |
| 155 action:@selector(onAcceptButton:)]; | 153 action:@selector(onAcceptButton:)]; |
| 156 [alert_ addButtonWithTitle: | 154 [alert_ addButtonWithTitle: |
| 157 l10n_util::FixUpWindowsStyleLabel(delegate->GetCancelButtonTitle()) | 155 l10n_util::FixUpWindowsStyleLabel(delegate->GetCancelButtonTitle()) |
| 158 keyEquivalent:kKeyEquivalentEscape | 156 keyEquivalent:kKeyEquivalentEscape |
| 159 target:bridge_ | 157 target:bridge_ |
| 160 action:@selector(onCancelButton:)]; | 158 action:@selector(onCancelButton:)]; |
| 161 [[alert_ closeButton] setTarget:bridge_]; | 159 [[alert_ closeButton] setTarget:bridge_]; |
| 162 [[alert_ closeButton] setAction:@selector(onCancelButton:)]; | 160 [[alert_ closeButton] setAction:@selector(onCancelButton:)]; |
| 163 [alert_ layout]; | 161 [alert_ layout]; |
| 164 | 162 |
| 165 window_.reset(new ConstrainedWindowMac2( | 163 window_.reset(new ConstrainedWindowMac2(this, web_contents, [alert_ window])); |
| 166 this, tab_contents->web_contents(), [alert_ window])); | |
| 167 delegate->set_window(window_.get()); | 164 delegate->set_window(window_.get()); |
| 168 } | 165 } |
| 169 | 166 |
| 170 TabModalConfirmDialogMac2::~TabModalConfirmDialogMac2() { | 167 TabModalConfirmDialogMac2::~TabModalConfirmDialogMac2() { |
| 171 } | 168 } |
| 172 | 169 |
| 173 void TabModalConfirmDialogMac2::AcceptTabModalDialog() { | 170 void TabModalConfirmDialogMac2::AcceptTabModalDialog() { |
| 174 delegate_->Accept(); | 171 delegate_->Accept(); |
| 175 } | 172 } |
| 176 | 173 |
| 177 void TabModalConfirmDialogMac2::CancelTabModalDialog() { | 174 void TabModalConfirmDialogMac2::CancelTabModalDialog() { |
| 178 delegate_->Cancel(); | 175 delegate_->Cancel(); |
| 179 } | 176 } |
| 180 | 177 |
| 181 void TabModalConfirmDialogMac2::OnConstrainedWindowClosed( | 178 void TabModalConfirmDialogMac2::OnConstrainedWindowClosed( |
| 182 ConstrainedWindowMac2* window) { | 179 ConstrainedWindowMac2* window) { |
| 183 delete this; | 180 delete this; |
| 184 } | 181 } |
| OLD | NEW |