Chromium Code Reviews| 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. | |
| 28 views::Widget* widget = | |
| 29 CreateDialogWidget(this, /* delegate */ | |
| 30 nullptr /* parent window*/, nullptr /* parent view */); | |
| 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 if (button == ui::DIALOG_BUTTON_OK) { | |
|
dcaiafa
2014/10/31 18:05:49
Please use a switch statement here instead.
kelvinp
2014/10/31 21:12:53
Done.
| |
| 68 return ok_label_; | |
| 69 } else if (button == ui::DIALOG_BUTTON_CANCEL) { | |
| 70 return cancel_label_; | |
| 71 } | |
| 72 NOTREACHED(); | |
| 73 return base::string16(); | |
| 74 } | |
| 75 | |
| 76 void MessageBox::DeleteDelegate() { | |
| 77 Release(); | |
| 78 } | |
| 79 | |
| 80 } // namespace remoting | |
| OLD | NEW |