blob: 535c1b32718b011705bfbd076c70caa304c43e3b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/javascript_app_modal_dialog_views.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
#include "chrome/browser/ui/views/constrained_window_views.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/views/controls/message_box_view.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_client_view.h"
#if defined(USE_X11) && !defined(OS_CHROMEOS)
#include "chrome/browser/ui/views/javascript_app_modal_event_blocker_x11.h"
#endif
////////////////////////////////////////////////////////////////////////////////
// JavaScriptAppModalDialogViews, public:
JavaScriptAppModalDialogViews::JavaScriptAppModalDialogViews(
JavaScriptAppModalDialog* parent)
: parent_(parent) {
int options = views::MessageBoxView::DETECT_DIRECTIONALITY;
if (parent->javascript_message_type() ==
content::JAVASCRIPT_MESSAGE_TYPE_PROMPT)
options |= views::MessageBoxView::HAS_PROMPT_FIELD;
views::MessageBoxView::InitParams params(parent->message_text());
params.options = options;
params.default_prompt = parent->default_prompt_text();
message_box_view_ = new views::MessageBoxView(params);
DCHECK(message_box_view_);
message_box_view_->AddAccelerator(
ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN));
if (parent->display_suppress_checkbox()) {
message_box_view_->SetCheckBoxLabel(
l10n_util::GetStringUTF16(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION));
}
}
JavaScriptAppModalDialogViews::~JavaScriptAppModalDialogViews() {
}
////////////////////////////////////////////////////////////////////////////////
// JavaScriptAppModalDialogViews, NativeAppModalDialog implementation:
int JavaScriptAppModalDialogViews::GetAppModalDialogButtons() const {
return GetDialogButtons();
}
void JavaScriptAppModalDialogViews::ShowAppModalDialog() {
#if defined(USE_X11) && !defined(OS_CHROMEOS)
// BrowserView::CanActivate() ensures that other browser windows cannot be
// activated for long while the dialog is visible. Block events to other
// browser windows so that the user cannot interact with other browser windows
// in the short time that the other browser windows are active. This hack is
// unnecessary on Windows and Chrome OS.
// TODO(pkotwicz): Find a better way of doing this and remove this hack.
if (!event_blocker_x11_.get()) {
event_blocker_x11_.reset(
new JavascriptAppModalEventBlockerX11(GetWidget()->GetNativeView()));
}
#endif
GetWidget()->Show();
}
void JavaScriptAppModalDialogViews::ActivateAppModalDialog() {
GetWidget()->Show();
GetWidget()->Activate();
}
void JavaScriptAppModalDialogViews::CloseAppModalDialog() {
GetWidget()->Close();
}
void JavaScriptAppModalDialogViews::AcceptAppModalDialog() {
GetDialogClientView()->AcceptWindow();
}
void JavaScriptAppModalDialogViews::CancelAppModalDialog() {
GetDialogClientView()->CancelWindow();
}
//////////////////////////////////////////////////////////////////////////////
// JavaScriptAppModalDialogViews, views::DialogDelegate implementation:
int JavaScriptAppModalDialogViews::GetDefaultDialogButton() const {
return ui::DIALOG_BUTTON_OK;
}
int JavaScriptAppModalDialogViews::GetDialogButtons() const {
if (parent_->javascript_message_type() ==
content::JAVASCRIPT_MESSAGE_TYPE_ALERT)
return ui::DIALOG_BUTTON_OK;
return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
}
base::string16 JavaScriptAppModalDialogViews::GetWindowTitle() const {
return parent_->title();
}
void JavaScriptAppModalDialogViews::WindowClosing() {
#if defined(USE_X11) && !defined(OS_CHROMEOS)
event_blocker_x11_.reset();
#endif
}
void JavaScriptAppModalDialogViews::DeleteDelegate() {
delete this;
}
bool JavaScriptAppModalDialogViews::Cancel() {
parent_->OnCancel(message_box_view_->IsCheckBoxSelected());
return true;
}
bool JavaScriptAppModalDialogViews::Accept() {
parent_->OnAccept(message_box_view_->GetInputText(),
message_box_view_->IsCheckBoxSelected());
return true;
}
void JavaScriptAppModalDialogViews::OnClosed() {
parent_->OnClose();
}
views::Widget* JavaScriptAppModalDialogViews::GetWidget() {
return message_box_view_->GetWidget();
}
const views::Widget* JavaScriptAppModalDialogViews::GetWidget() const {
return message_box_view_->GetWidget();
}
base::string16 JavaScriptAppModalDialogViews::GetDialogButtonLabel(
ui::DialogButton button) const {
if (parent_->is_before_unload_dialog()) {
if (button == ui::DIALOG_BUTTON_OK) {
return l10n_util::GetStringUTF16(
parent_->is_reload() ?
IDS_BEFORERELOAD_MESSAGEBOX_OK_BUTTON_LABEL :
IDS_BEFOREUNLOAD_MESSAGEBOX_OK_BUTTON_LABEL);
} else if (button == ui::DIALOG_BUTTON_CANCEL) {
return l10n_util::GetStringUTF16(
parent_->is_reload() ?
IDS_BEFORERELOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL :
IDS_BEFOREUNLOAD_MESSAGEBOX_CANCEL_BUTTON_LABEL);
}
}
return DialogDelegate::GetDialogButtonLabel(button);
}
///////////////////////////////////////////////////////////////////////////////
// JavaScriptAppModalDialogViews, views::WidgetDelegate implementation:
ui::ModalType JavaScriptAppModalDialogViews::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
views::View* JavaScriptAppModalDialogViews::GetContentsView() {
return message_box_view_;
}
views::View* JavaScriptAppModalDialogViews::GetInitiallyFocusedView() {
if (message_box_view_->text_box())
return message_box_view_->text_box();
return views::DialogDelegate::GetInitiallyFocusedView();
}
////////////////////////////////////////////////////////////////////////////////
// NativeAppModalDialog, public:
// static
NativeAppModalDialog* NativeAppModalDialog::CreateNativeJavaScriptPrompt(
JavaScriptAppModalDialog* dialog,
gfx::NativeWindow parent_window) {
JavaScriptAppModalDialogViews* d = new JavaScriptAppModalDialogViews(dialog);
CreateBrowserModalDialogViews(d, parent_window);
return d;
}
|