Chromium Code Reviews| 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/command_line.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
| 9 #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" | 10 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 gfx::Image* icon = delegate->GetIcon(); | 83 gfx::Image* icon = delegate->GetIcon(); |
| 84 if (icon) | 84 if (icon) |
| 85 [alert setIcon:icon->ToNSImage()]; | 85 [alert setIcon:icon->ToNSImage()]; |
| 86 | 86 |
| 87 set_sheet(alert); | 87 set_sheet(alert); |
| 88 | 88 |
| 89 delegate->set_window(new ConstrainedWindowMac(tab_contents, this)); | 89 delegate->set_window(new ConstrainedWindowMac(tab_contents, this)); |
| 90 } | 90 } |
| 91 | 91 |
| 92 TabModalConfirmDialogMac::~TabModalConfirmDialogMac() { | 92 TabModalConfirmDialogMac::~TabModalConfirmDialogMac() { |
| 93 NSWindow* window = [(NSAlert*)sheet() window]; | 93 NSWindow* window = [(NSAlert*)sheet() window]; |
|
Peter Kasting
2012/09/25 00:39:20
Nit: This can call CancelTabModalDialog() instead
tfarina
2012/09/25 02:03:38
Done.
| |
| 94 if (window && is_sheet_open()) { | 94 if (window && is_sheet_open()) { |
| 95 [NSApp endSheet:window | 95 [NSApp endSheet:window |
| 96 returnCode:NSAlertSecondButtonReturn]; | 96 returnCode:NSAlertSecondButtonReturn]; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 // "DeleteDelegate" refers to this class being a ConstrainedWindow delegate | 100 // "DeleteDelegate" refers to this class being a ConstrainedWindow delegate |
| 101 // and deleting itself, not to deleting the member variable |delegate_|. | 101 // and deleting itself, not to deleting the member variable |delegate_|. |
| 102 void TabModalConfirmDialogMac::DeleteDelegate() { | 102 void TabModalConfirmDialogMac::DeleteDelegate() { |
| 103 delete this; | 103 delete this; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void TabModalConfirmDialogMac::AcceptTabModalDialog() { | |
| 107 NSWindow* window = [(NSAlert*)sheet() window]; | |
| 108 if (window && is_sheet_open()) { | |
| 109 [NSApp endSheet:window | |
| 110 returnCode:NSAlertFirstButtonReturn]; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 void TabModalConfirmDialogMac::CancelTabModalDialog() { | |
| 115 NSWindow* window = [(NSAlert*)sheet() window]; | |
| 116 if (window && is_sheet_open()) { | |
| 117 [NSApp endSheet:window | |
| 118 returnCode:NSAlertSecondButtonReturn]; | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 // static | |
|
Peter Kasting
2012/09/25 00:39:20
Nit: Place this atop this .cc file
tfarina
2012/09/25 02:03:38
Done.
| |
| 123 TabModalConfirmDialog* TabModalConfirmDialog::Create( | |
| 124 TabModalConfirmDialogDelegate* delegate, | |
| 125 TabContents* tab_contents) { | |
| 126 return new TabModalConfirmDialogMac(delegate, tab_contents); | |
| 127 } | |
| 128 | |
| 106 @interface TabModalConfirmDialogMacBridge2 : NSObject { | 129 @interface TabModalConfirmDialogMacBridge2 : NSObject { |
| 107 TabModalConfirmDialogDelegate* delegate_; // weak | 130 TabModalConfirmDialogDelegate* delegate_; // weak |
| 108 } | 131 } |
| 109 @end | 132 @end |
| 110 | 133 |
| 111 @implementation TabModalConfirmDialogMacBridge2 | 134 @implementation TabModalConfirmDialogMacBridge2 |
| 112 | 135 |
| 113 - (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate { | 136 - (id)initWithDelegate:(TabModalConfirmDialogDelegate*)delegate { |
| 114 if ((self = [super init])) { | 137 if ((self = [super init])) { |
| 115 delegate_ = delegate; | 138 delegate_ = delegate; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 [[alert_ closeButton] setTarget:bridge_]; | 176 [[alert_ closeButton] setTarget:bridge_]; |
| 154 [[alert_ closeButton] setAction:@selector(onCancelButton:)]; | 177 [[alert_ closeButton] setAction:@selector(onCancelButton:)]; |
| 155 [alert_ layout]; | 178 [alert_ layout]; |
| 156 | 179 |
| 157 delegate->set_window( | 180 delegate->set_window( |
| 158 new ConstrainedWindowMac2(tab_contents, [alert_ window])); | 181 new ConstrainedWindowMac2(tab_contents, [alert_ window])); |
| 159 } | 182 } |
| 160 | 183 |
| 161 TabModalConfirmDialogMac2::~TabModalConfirmDialogMac2() { | 184 TabModalConfirmDialogMac2::~TabModalConfirmDialogMac2() { |
| 162 } | 185 } |
| OLD | NEW |