OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "remoting/host/chromeos/message_box.h" | |
6 | |
7 #include "base/callback_helpers.h" | |
8 #include "ui/base/l10n/l10n_util.h" | |
9 #include "ui/views/widget/widget.h" | |
10 | |
11 namespace remoting { | |
12 | |
13 MessageBox::MessageBox(const base::string16& message_label, | |
14 const base::string16& ok_label, | |
15 const base::string16& cancel_label, | |
16 ResultCallback result_callback) | |
17 : message_label_(message_label), | |
18 ok_label_(ok_label), | |
19 cancel_label_(cancel_label), | |
20 result_callback_(result_callback) { | |
21 } | |
22 | |
23 MessageBox::~MessageBox() { | |
24 } | |
25 | |
26 void MessageBox::Show() { | |
27 // The widget is owned by the NativeWidget. See class comments for ownership. | |
Wez
2014/10/31 21:22:24
Which class comments?
kelvinp
2014/11/01 00:42:00
The comments in Widget.h
| |
28 views::Widget* widget = | |
29 CreateDialogWidget(this, /* delegate */ | |
30 nullptr /* parent window*/, nullptr /* parent view */); | |
Wez
2014/10/31 21:22:24
put these one-per-line so that the comments are mo
kelvinp
2014/11/01 00:42:00
Done.
| |
31 | |
32 if (widget) { | |
33 AddRef(); | |
34 widget->Show(); | |
35 } | |
36 } | |
37 | |
38 void MessageBox::Hide() { | |
39 if (GetWidget()) { | |
40 GetWidget()->Close(); | |
41 } | |
42 } | |
43 | |
44 bool MessageBox::Accept() { | |
45 DCHECK(!result_callback_.is_null()); | |
46 base::ResetAndReturn(&result_callback_).Run(OK); | |
47 return true /* close the window*/; | |
48 } | |
49 | |
50 bool MessageBox::Cancel() { | |
51 if (result_callback_.is_null()) { | |
52 return false; | |
53 } | |
54 base::ResetAndReturn(&result_callback_).Run(CANCEL); | |
55 return true /* close the window*/; | |
56 } | |
57 | |
58 ui::ModalType MessageBox::GetModalType() const { | |
59 return ui::MODAL_TYPE_SYSTEM; | |
60 } | |
61 | |
62 base::string16 MessageBox::GetWindowTitle() const { | |
63 return message_label_; | |
64 } | |
65 | |
66 base::string16 MessageBox::GetDialogButtonLabel(ui::DialogButton button) const { | |
67 switch (button) { | |
68 case ui::DIALOG_BUTTON_OK: | |
69 return ok_label_; | |
70 case ui::DIALOG_BUTTON_CANCEL: | |
71 return cancel_label_; | |
72 default: | |
73 NOTREACHED(); | |
74 return base::string16(); | |
75 } | |
76 } | |
77 | |
78 void MessageBox::DeleteDelegate() { | |
79 Release(); | |
80 } | |
81 | |
82 } // namespace remoting | |
OLD | NEW |