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/javascript_app_modal_dialog_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/javascript_app_modal_dialog_cocoa.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #import "base/mac/foundation_util.h" | 11 #import "base/mac/foundation_util.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #import "chrome/browser/chrome_browser_application_mac.h" | 13 #import "chrome/browser/chrome_browser_application_mac.h" |
14 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 14 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/ui_strings.h" | 16 #include "grit/ui_strings.h" |
17 #include "ui/base/l10n/l10n_util_mac.h" | 17 #include "ui/base/l10n/l10n_util_mac.h" |
18 #include "ui/base/ui_base_types.h" | 18 #include "ui/base/ui_base_types.h" |
19 | 19 |
20 // Helper object that receives the notification that the dialog/sheet is | 20 // Helper object that receives the notification that the dialog/sheet is |
21 // going away. Is responsible for cleaning itself up. | 21 // going away. Is responsible for cleaning itself up. |
22 @interface JavaScriptAppModalDialogHelper : NSObject<NSAlertDelegate> { | 22 @interface JavaScriptAppModalDialogHelper : NSObject<NSAlertDelegate> { |
23 @private | 23 @private |
24 scoped_nsobject<NSAlert> alert_; | 24 base::scoped_nsobject<NSAlert> alert_; |
25 NSTextField* textField_; // WEAK; owned by alert_ | 25 NSTextField* textField_; // WEAK; owned by alert_ |
26 } | 26 } |
27 | 27 |
28 - (NSAlert*)alert; | 28 - (NSAlert*)alert; |
29 - (NSTextField*)textField; | 29 - (NSTextField*)textField; |
30 - (void)alertDidEnd:(NSAlert*)alert | 30 - (void)alertDidEnd:(NSAlert*)alert |
31 returnCode:(int)returnCode | 31 returnCode:(int)returnCode |
32 contextInfo:(void*)contextInfo; | 32 contextInfo:(void*)contextInfo; |
33 | 33 |
34 @end | 34 @end |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 informative_text_field = text_field; | 201 informative_text_field = text_field; |
202 } | 202 } |
203 | 203 |
204 // This may fail in future OS releases, but it will still work for shipped | 204 // This may fail in future OS releases, but it will still work for shipped |
205 // versions of Chromium. | 205 // versions of Chromium. |
206 DCHECK(message_text_field); | 206 DCHECK(message_text_field); |
207 DCHECK(informative_text_field); | 207 DCHECK(informative_text_field); |
208 } | 208 } |
209 | 209 |
210 if (message_has_rtl && message_text_field) { | 210 if (message_has_rtl && message_text_field) { |
211 scoped_nsobject<NSMutableParagraphStyle> alignment( | 211 base::scoped_nsobject<NSMutableParagraphStyle> alignment( |
212 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); | 212 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); |
213 [alignment setAlignment:NSRightTextAlignment]; | 213 [alignment setAlignment:NSRightTextAlignment]; |
214 | 214 |
215 NSDictionary* alignment_attributes = | 215 NSDictionary* alignment_attributes = |
216 @{ NSParagraphStyleAttributeName : alignment }; | 216 @{ NSParagraphStyleAttributeName : alignment }; |
217 scoped_nsobject<NSAttributedString> attr_string( | 217 base::scoped_nsobject<NSAttributedString> attr_string( |
218 [[NSAttributedString alloc] initWithString:message_text | 218 [[NSAttributedString alloc] initWithString:message_text |
219 attributes:alignment_attributes]); | 219 attributes:alignment_attributes]); |
220 | 220 |
221 [message_text_field setAttributedStringValue:attr_string]; | 221 [message_text_field setAttributedStringValue:attr_string]; |
222 [message_text_field setSelectable:NO]; | 222 [message_text_field setSelectable:NO]; |
223 } | 223 } |
224 | 224 |
225 if (informative_has_rtl && informative_text_field) { | 225 if (informative_has_rtl && informative_text_field) { |
226 base::i18n::TextDirection direction = | 226 base::i18n::TextDirection direction = |
227 base::i18n::GetFirstStrongCharacterDirection(dialog_->message_text()); | 227 base::i18n::GetFirstStrongCharacterDirection(dialog_->message_text()); |
228 scoped_nsobject<NSMutableParagraphStyle> alignment( | 228 base::scoped_nsobject<NSMutableParagraphStyle> alignment( |
229 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); | 229 [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); |
230 [alignment setAlignment: | 230 [alignment setAlignment: |
231 (direction == base::i18n::RIGHT_TO_LEFT) ? NSRightTextAlignment | 231 (direction == base::i18n::RIGHT_TO_LEFT) ? NSRightTextAlignment |
232 : NSLeftTextAlignment]; | 232 : NSLeftTextAlignment]; |
233 | 233 |
234 NSDictionary* alignment_attributes = | 234 NSDictionary* alignment_attributes = |
235 @{ NSParagraphStyleAttributeName : alignment }; | 235 @{ NSParagraphStyleAttributeName : alignment }; |
236 scoped_nsobject<NSAttributedString> attr_string( | 236 base::scoped_nsobject<NSAttributedString> attr_string( |
237 [[NSAttributedString alloc] initWithString:informative_text | 237 [[NSAttributedString alloc] initWithString:informative_text |
238 attributes:alignment_attributes]); | 238 attributes:alignment_attributes]); |
239 | 239 |
240 [informative_text_field setAttributedStringValue:attr_string]; | 240 [informative_text_field setAttributedStringValue:attr_string]; |
241 [informative_text_field setSelectable:NO]; | 241 [informative_text_field setSelectable:NO]; |
242 } | 242 } |
243 } | 243 } |
244 | 244 |
245 JavaScriptAppModalDialogCocoa::~JavaScriptAppModalDialogCocoa() { | 245 JavaScriptAppModalDialogCocoa::~JavaScriptAppModalDialogCocoa() { |
246 } | 246 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 298 |
299 //////////////////////////////////////////////////////////////////////////////// | 299 //////////////////////////////////////////////////////////////////////////////// |
300 // NativeAppModalDialog, public: | 300 // NativeAppModalDialog, public: |
301 | 301 |
302 // static | 302 // static |
303 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( | 303 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( |
304 JavaScriptAppModalDialog* dialog, | 304 JavaScriptAppModalDialog* dialog, |
305 gfx::NativeWindow parent_window) { | 305 gfx::NativeWindow parent_window) { |
306 return new JavaScriptAppModalDialogCocoa(dialog); | 306 return new JavaScriptAppModalDialogCocoa(dialog); |
307 } | 307 } |
OLD | NEW |