| 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/dialog_style.h" | 9 #include "chrome/browser/ui/dialog_style.h" |
| 10 #include "chrome/browser/ui/views/window.h" | 10 #include "chrome/browser/ui/views/window.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 #include "ui/base/keycodes/keyboard_codes.h" | 12 #include "ui/base/keycodes/keyboard_codes.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/message_box_flags.h" | |
| 15 #include "ui/views/controls/message_box_view.h" | 14 #include "ui/views/controls/message_box_view.h" |
| 16 #include "ui/views/controls/textfield/textfield.h" | 15 #include "ui/views/controls/textfield/textfield.h" |
| 17 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 18 | 17 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 20 // JSModalDialogViews, public: | 19 // JSModalDialogViews, public: |
| 21 | 20 |
| 22 JSModalDialogViews::JSModalDialogViews( | 21 JSModalDialogViews::JSModalDialogViews(JavaScriptAppModalDialog* parent) |
| 23 JavaScriptAppModalDialog* parent) | 22 : parent_(parent) { |
| 24 : parent_(parent), | 23 int options = views::MessageBoxView::DETECT_ALIGNMENT; |
| 25 message_box_view_(new views::MessageBoxView( | 24 if (parent->javascript_message_type() == ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT) |
| 26 parent->dialog_flags() | ui::MessageBoxFlags::kAutoDetectAlignment, | 25 options |= views::MessageBoxView::HAS_PROMPT_FIELD; |
| 27 parent->message_text(), | 26 |
| 28 parent->default_prompt_text())) { | 27 message_box_view_ = new views::MessageBoxView(options, |
| 28 parent->message_text(), |
| 29 parent->default_prompt_text()); |
| 29 DCHECK(message_box_view_); | 30 DCHECK(message_box_view_); |
| 30 | 31 |
| 31 message_box_view_->AddAccelerator( | 32 message_box_view_->AddAccelerator( |
| 32 ui::Accelerator(ui::VKEY_C, false, true, false)); | 33 ui::Accelerator(ui::VKEY_C, false, true, false)); |
| 33 if (parent->display_suppress_checkbox()) { | 34 if (parent->display_suppress_checkbox()) { |
| 34 message_box_view_->SetCheckBoxLabel( | 35 message_box_view_->SetCheckBoxLabel( |
| 35 l10n_util::GetStringUTF16(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION)); | 36 l10n_util::GetStringUTF16(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION)); |
| 36 } | 37 } |
| 37 } | 38 } |
| 38 | 39 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 64 } | 65 } |
| 65 | 66 |
| 66 void JSModalDialogViews::CancelAppModalDialog() { | 67 void JSModalDialogViews::CancelAppModalDialog() { |
| 67 GetDialogClientView()->CancelWindow(); | 68 GetDialogClientView()->CancelWindow(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 ////////////////////////////////////////////////////////////////////////////// | 71 ////////////////////////////////////////////////////////////////////////////// |
| 71 // JSModalDialogViews, views::DialogDelegate implementation: | 72 // JSModalDialogViews, views::DialogDelegate implementation: |
| 72 | 73 |
| 73 int JSModalDialogViews::GetDefaultDialogButton() const { | 74 int JSModalDialogViews::GetDefaultDialogButton() const { |
| 74 if (parent_->dialog_flags() & ui::MessageBoxFlags::kFlagHasOKButton) | 75 if (parent_->javascript_message_type() == ui::JAVASCRIPT_MESSAGE_TYPE_ALERT) |
| 75 return ui::DIALOG_BUTTON_OK; | 76 return ui::DIALOG_BUTTON_OK; |
| 76 | 77 |
| 77 if (parent_->dialog_flags() & ui::MessageBoxFlags::kFlagHasCancelButton) | 78 return ui::DIALOG_BUTTON_CANCEL; |
| 78 return ui::DIALOG_BUTTON_CANCEL; | |
| 79 | |
| 80 return ui::DIALOG_BUTTON_NONE; | |
| 81 } | 79 } |
| 82 | 80 |
| 83 int JSModalDialogViews::GetDialogButtons() const { | 81 int JSModalDialogViews::GetDialogButtons() const { |
| 84 int dialog_buttons = ui::DIALOG_BUTTON_NONE; | 82 if (parent_->javascript_message_type() == ui::JAVASCRIPT_MESSAGE_TYPE_ALERT) |
| 85 if (parent_->dialog_flags() & ui::MessageBoxFlags::kFlagHasOKButton) | 83 return ui::DIALOG_BUTTON_OK; |
| 86 dialog_buttons = ui::DIALOG_BUTTON_OK; | |
| 87 | 84 |
| 88 if (parent_->dialog_flags() & ui::MessageBoxFlags::kFlagHasCancelButton) | 85 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
| 89 dialog_buttons |= ui::DIALOG_BUTTON_CANCEL; | |
| 90 | |
| 91 return dialog_buttons; | |
| 92 } | 86 } |
| 93 | 87 |
| 94 string16 JSModalDialogViews::GetWindowTitle() const { | 88 string16 JSModalDialogViews::GetWindowTitle() const { |
| 95 return parent_->title(); | 89 return parent_->title(); |
| 96 } | 90 } |
| 97 | 91 |
| 98 | |
| 99 void JSModalDialogViews::WindowClosing() { | 92 void JSModalDialogViews::WindowClosing() { |
| 100 } | 93 } |
| 101 | 94 |
| 102 void JSModalDialogViews::DeleteDelegate() { | 95 void JSModalDialogViews::DeleteDelegate() { |
| 103 delete parent_; | 96 delete parent_; |
| 104 delete this; | 97 delete this; |
| 105 } | 98 } |
| 106 | 99 |
| 107 bool JSModalDialogViews::Cancel() { | 100 bool JSModalDialogViews::Cancel() { |
| 108 parent_->OnCancel(message_box_view_->IsCheckBoxSelected()); | 101 parent_->OnCancel(message_box_view_->IsCheckBoxSelected()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 156 |
| 164 // static | 157 // static |
| 165 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( | 158 NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt( |
| 166 JavaScriptAppModalDialog* dialog, | 159 JavaScriptAppModalDialog* dialog, |
| 167 gfx::NativeWindow parent_window) { | 160 gfx::NativeWindow parent_window) { |
| 168 JSModalDialogViews* d = new JSModalDialogViews(dialog); | 161 JSModalDialogViews* d = new JSModalDialogViews(dialog); |
| 169 | 162 |
| 170 browser::CreateViewsWindow(parent_window, d, STYLE_GENERIC); | 163 browser::CreateViewsWindow(parent_window, d, STYLE_GENERIC); |
| 171 return d; | 164 return d; |
| 172 } | 165 } |
| OLD | NEW |