Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(690)

Side by Side Diff: components/app_modal_dialogs/views/javascript_app_modal_dialog_views.cc

Issue 735473002: Rename app_modal_dialogs dir to app_modal (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: rebase Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/app_modal_dialogs/views/javascript_app_modal_dialog_views.h "
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/app_modal_dialogs/javascript_app_modal_dialog.h"
9 #include "components/constrained_window/constrained_window_views.h"
10 #include "grit/components_strings.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/events/keycodes/keyboard_codes.h"
13 #include "ui/views/controls/message_box_view.h"
14 #include "ui/views/controls/textfield/textfield.h"
15 #include "ui/views/widget/widget.h"
16 #include "ui/views/window/dialog_client_view.h"
17
18 ////////////////////////////////////////////////////////////////////////////////
19 // JavaScriptAppModalDialogViews, public:
20
21 JavaScriptAppModalDialogViews::JavaScriptAppModalDialogViews(
22 JavaScriptAppModalDialog* parent)
23 : parent_(parent) {
24 int options = views::MessageBoxView::DETECT_DIRECTIONALITY;
25 if (parent->javascript_message_type() ==
26 content::JAVASCRIPT_MESSAGE_TYPE_PROMPT)
27 options |= views::MessageBoxView::HAS_PROMPT_FIELD;
28
29 views::MessageBoxView::InitParams params(parent->message_text());
30 params.options = options;
31 params.default_prompt = parent->default_prompt_text();
32 message_box_view_ = new views::MessageBoxView(params);
33 DCHECK(message_box_view_);
34
35 message_box_view_->AddAccelerator(
36 ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN));
37 if (parent->display_suppress_checkbox()) {
38 message_box_view_->SetCheckBoxLabel(
39 l10n_util::GetStringUTF16(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION));
40 }
41 }
42
43 JavaScriptAppModalDialogViews::~JavaScriptAppModalDialogViews() {
44 }
45
46 ////////////////////////////////////////////////////////////////////////////////
47 // JavaScriptAppModalDialogViews, NativeAppModalDialog implementation:
48
49 int JavaScriptAppModalDialogViews::GetAppModalDialogButtons() const {
50 return GetDialogButtons();
51 }
52
53 void JavaScriptAppModalDialogViews::ShowAppModalDialog() {
54 GetWidget()->Show();
55 }
56
57 void JavaScriptAppModalDialogViews::ActivateAppModalDialog() {
58 GetWidget()->Show();
59 GetWidget()->Activate();
60 }
61
62 void JavaScriptAppModalDialogViews::CloseAppModalDialog() {
63 GetWidget()->Close();
64 }
65
66 void JavaScriptAppModalDialogViews::AcceptAppModalDialog() {
67 GetDialogClientView()->AcceptWindow();
68 }
69
70 void JavaScriptAppModalDialogViews::CancelAppModalDialog() {
71 GetDialogClientView()->CancelWindow();
72 }
73
74 //////////////////////////////////////////////////////////////////////////////
75 // JavaScriptAppModalDialogViews, views::DialogDelegate implementation:
76
77 int JavaScriptAppModalDialogViews::GetDefaultDialogButton() const {
78 return ui::DIALOG_BUTTON_OK;
79 }
80
81 int JavaScriptAppModalDialogViews::GetDialogButtons() const {
82 if (parent_->javascript_message_type() ==
83 content::JAVASCRIPT_MESSAGE_TYPE_ALERT)
84 return ui::DIALOG_BUTTON_OK;
85
86 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
87 }
88
89 base::string16 JavaScriptAppModalDialogViews::GetWindowTitle() const {
90 return parent_->title();
91 }
92
93 void JavaScriptAppModalDialogViews::DeleteDelegate() {
94 delete this;
95 }
96
97 bool JavaScriptAppModalDialogViews::Cancel() {
98 parent_->OnCancel(message_box_view_->IsCheckBoxSelected());
99 return true;
100 }
101
102 bool JavaScriptAppModalDialogViews::Accept() {
103 parent_->OnAccept(message_box_view_->GetInputText(),
104 message_box_view_->IsCheckBoxSelected());
105 return true;
106 }
107
108 void JavaScriptAppModalDialogViews::OnClosed() {
109 parent_->OnClose();
110 }
111
112 views::Widget* JavaScriptAppModalDialogViews::GetWidget() {
113 return message_box_view_->GetWidget();
114 }
115
116 const views::Widget* JavaScriptAppModalDialogViews::GetWidget() const {
117 return message_box_view_->GetWidget();
118 }
119
120 base::string16 JavaScriptAppModalDialogViews::GetDialogButtonLabel(
121 ui::DialogButton button) const {
122 if (parent_->is_before_unload_dialog()) {
123 if (button == ui::DIALOG_BUTTON_OK) {
124 return l10n_util::GetStringUTF16(
125 parent_->is_reload() ?
126 IDS_BEFORERELOAD_MESSAGEBOX_OK_BUTTON_LABEL :
127 IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL);
128 } else if (button == ui::DIALOG_BUTTON_CANCEL) {
129 return l10n_util::GetStringUTF16(
130 parent_->is_reload() ?
131 IDS_BEFORERELOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL :
132 IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL);
133 }
134 }
135 return DialogDelegate::GetDialogButtonLabel(button);
136 }
137
138 ///////////////////////////////////////////////////////////////////////////////
139 // JavaScriptAppModalDialogViews, views::WidgetDelegate implementation:
140
141 ui::ModalType JavaScriptAppModalDialogViews::GetModalType() const {
142 return ui::MODAL_TYPE_SYSTEM;
143 }
144
145 views::View* JavaScriptAppModalDialogViews::GetContentsView() {
146 return message_box_view_;
147 }
148
149 views::View* JavaScriptAppModalDialogViews::GetInitiallyFocusedView() {
150 if (message_box_view_->text_box())
151 return message_box_view_->text_box();
152 return views::DialogDelegate::GetInitiallyFocusedView();
153 }
OLDNEW
« no previous file with comments | « components/app_modal_dialogs/views/javascript_app_modal_dialog_views.h ('k') | components/app_modal_dialogs_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698