Index: remoting/host/chromeos/message_box.cc |
diff --git a/remoting/host/chromeos/message_box.cc b/remoting/host/chromeos/message_box.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f811af80bed055ca6d05e1b13ddddf207c762474 |
--- /dev/null |
+++ b/remoting/host/chromeos/message_box.cc |
@@ -0,0 +1,82 @@ |
+// Copyright 2014 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 "remoting/host/chromeos/message_box.h" |
+ |
+#include "base/callback_helpers.h" |
+#include "ui/base/l10n/l10n_util.h" |
+#include "ui/views/widget/widget.h" |
+ |
+namespace remoting { |
+ |
+MessageBox::MessageBox(const base::string16& message_label, |
+ const base::string16& ok_label, |
+ const base::string16& cancel_label, |
+ ResultCallback result_callback) |
+ : message_label_(message_label), |
+ ok_label_(ok_label), |
+ cancel_label_(cancel_label), |
+ result_callback_(result_callback) { |
+} |
+ |
+MessageBox::~MessageBox() { |
+} |
+ |
+void MessageBox::Show() { |
+ // 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
|
+ views::Widget* widget = |
+ CreateDialogWidget(this, /* delegate */ |
+ 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.
|
+ |
+ if (widget) { |
+ AddRef(); |
+ widget->Show(); |
+ } |
+} |
+ |
+void MessageBox::Hide() { |
+ if (GetWidget()) { |
+ GetWidget()->Close(); |
+ } |
+} |
+ |
+bool MessageBox::Accept() { |
+ DCHECK(!result_callback_.is_null()); |
+ base::ResetAndReturn(&result_callback_).Run(OK); |
+ return true /* close the window*/; |
+} |
+ |
+bool MessageBox::Cancel() { |
+ if (result_callback_.is_null()) { |
+ return false; |
+ } |
+ base::ResetAndReturn(&result_callback_).Run(CANCEL); |
+ return true /* close the window*/; |
+} |
+ |
+ui::ModalType MessageBox::GetModalType() const { |
+ return ui::MODAL_TYPE_SYSTEM; |
+} |
+ |
+base::string16 MessageBox::GetWindowTitle() const { |
+ return message_label_; |
+} |
+ |
+base::string16 MessageBox::GetDialogButtonLabel(ui::DialogButton button) const { |
+ switch (button) { |
+ case ui::DIALOG_BUTTON_OK: |
+ return ok_label_; |
+ case ui::DIALOG_BUTTON_CANCEL: |
+ return cancel_label_; |
+ default: |
+ NOTREACHED(); |
+ return base::string16(); |
+ } |
+} |
+ |
+void MessageBox::DeleteDelegate() { |
+ Release(); |
+} |
+ |
+} // namespace remoting |