| 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/views/js_modal_dialog_views.h" | 5 #include "chrome/browser/ui/views/js_modal_dialog_views.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 8 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
| 9 #include "chrome/browser/ui/views/window.h" | 9 #include "chrome/browser/ui/views/window.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 11 #include "ui/base/keycodes/keyboard_codes.h" | 11 #include "ui/base/keycodes/keyboard_codes.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/base/message_box_flags.h" | 13 #include "ui/base/message_box_flags.h" |
| 14 #include "views/controls/message_box_view.h" | 14 #include "views/controls/message_box_view.h" |
| 15 #include "views/controls/textfield/textfield.h" | 15 #include "views/controls/textfield/textfield.h" |
| 16 #include "views/window/window.h" | 16 #include "views/window/window.h" |
| 17 | 17 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 19 // JSModalDialogViews, public: | 19 // JSModalDialogViews, public: |
| 20 | 20 |
| 21 JSModalDialogViews::JSModalDialogViews( | 21 JSModalDialogViews::JSModalDialogViews( |
| 22 JavaScriptAppModalDialog* parent) | 22 JavaScriptAppModalDialog* parent) |
| 23 : parent_(parent), | 23 : parent_(parent), |
| 24 message_box_view_(new views::MessageBoxView( | 24 message_box_view_(new views::MessageBoxView( |
| 25 parent->dialog_flags() | ui::MessageBoxFlags::kAutoDetectAlignment, | 25 parent->dialog_flags() | ui::MessageBoxFlags::kAutoDetectAlignment, |
| 26 parent->message_text(), parent->default_prompt_text())) { | 26 UTF16ToWideHack(parent->message_text()), |
| 27 UTF16ToWideHack(parent->default_prompt_text()))) { |
| 27 DCHECK(message_box_view_); | 28 DCHECK(message_box_view_); |
| 28 | 29 |
| 29 message_box_view_->AddAccelerator( | 30 message_box_view_->AddAccelerator( |
| 30 views::Accelerator(ui::VKEY_C, false, true, false)); | 31 views::Accelerator(ui::VKEY_C, false, true, false)); |
| 31 if (parent->display_suppress_checkbox()) { | 32 if (parent->display_suppress_checkbox()) { |
| 32 message_box_view_->SetCheckBoxLabel(UTF16ToWide( | 33 message_box_view_->SetCheckBoxLabel(UTF16ToWide( |
| 33 l10n_util::GetStringUTF16(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION))); | 34 l10n_util::GetStringUTF16(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION))); |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 | 37 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 if (parent_->dialog_flags() & ui::MessageBoxFlags::kFlagHasOKButton) | 84 if (parent_->dialog_flags() & ui::MessageBoxFlags::kFlagHasOKButton) |
| 84 dialog_buttons = ui::MessageBoxFlags::DIALOGBUTTON_OK; | 85 dialog_buttons = ui::MessageBoxFlags::DIALOGBUTTON_OK; |
| 85 | 86 |
| 86 if (parent_->dialog_flags() & ui::MessageBoxFlags::kFlagHasCancelButton) | 87 if (parent_->dialog_flags() & ui::MessageBoxFlags::kFlagHasCancelButton) |
| 87 dialog_buttons |= ui::MessageBoxFlags::DIALOGBUTTON_CANCEL; | 88 dialog_buttons |= ui::MessageBoxFlags::DIALOGBUTTON_CANCEL; |
| 88 | 89 |
| 89 return dialog_buttons; | 90 return dialog_buttons; |
| 90 } | 91 } |
| 91 | 92 |
| 92 std::wstring JSModalDialogViews::GetWindowTitle() const { | 93 std::wstring JSModalDialogViews::GetWindowTitle() const { |
| 93 return parent_->title(); | 94 return UTF16ToWideHack(parent_->title()); |
| 94 } | 95 } |
| 95 | 96 |
| 96 | 97 |
| 97 void JSModalDialogViews::WindowClosing() { | 98 void JSModalDialogViews::WindowClosing() { |
| 98 } | 99 } |
| 99 | 100 |
| 100 void JSModalDialogViews::DeleteDelegate() { | 101 void JSModalDialogViews::DeleteDelegate() { |
| 101 delete parent_; | 102 delete parent_; |
| 102 delete this; | 103 delete this; |
| 103 } | 104 } |
| 104 | 105 |
| 105 bool JSModalDialogViews::Cancel() { | 106 bool JSModalDialogViews::Cancel() { |
| 106 parent_->OnCancel(message_box_view_->IsCheckBoxSelected()); | 107 parent_->OnCancel(message_box_view_->IsCheckBoxSelected()); |
| 107 return true; | 108 return true; |
| 108 } | 109 } |
| 109 | 110 |
| 110 bool JSModalDialogViews::Accept() { | 111 bool JSModalDialogViews::Accept() { |
| 111 parent_->OnAccept(message_box_view_->GetInputText(), | 112 parent_->OnAccept(WideToUTF16Hack(message_box_view_->GetInputText()), |
| 112 message_box_view_->IsCheckBoxSelected()); | 113 message_box_view_->IsCheckBoxSelected()); |
| 113 return true; | 114 return true; |
| 114 } | 115 } |
| 115 | 116 |
| 116 void JSModalDialogViews::OnClose() { | 117 void JSModalDialogViews::OnClose() { |
| 117 parent_->OnClose(); | 118 parent_->OnClose(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 std::wstring JSModalDialogViews::GetDialogButtonLabel( | 121 std::wstring JSModalDialogViews::GetDialogButtonLabel( |
| 121 ui::MessageBoxFlags::DialogButton button) const { | 122 ui::MessageBoxFlags::DialogButton button) const { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 154 |
| 154 // static | 155 // static |
| 155 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( | 156 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( |
| 156 JavaScriptAppModalDialog* dialog, | 157 JavaScriptAppModalDialog* dialog, |
| 157 gfx::NativeWindow parent_window) { | 158 gfx::NativeWindow parent_window) { |
| 158 JSModalDialogViews* d = new JSModalDialogViews(dialog); | 159 JSModalDialogViews* d = new JSModalDialogViews(dialog); |
| 159 | 160 |
| 160 browser::CreateViewsWindow(parent_window, gfx::Rect(), d); | 161 browser::CreateViewsWindow(parent_window, gfx::Rect(), d); |
| 161 return d; | 162 return d; |
| 162 } | 163 } |
| OLD | NEW |