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 #ifndef REMOTING_HOST_CHROMEOS_MESSAGE_BOX_H_ | |
6 #define REMOTING_HOST_CHROMEOS_MESSAGE_BOX_H_ | |
7 | |
8 #include "base/memory/ref_counted.h" | |
9 #include "ui/views/window/dialog_delegate.h" | |
10 | |
11 namespace remoting { | |
12 | |
13 // Overview: | |
14 // Shows a system modal message box with ok and cancel buttons. This class | |
15 // is not thread-safe. | |
dcaiafa
2014/10/31 18:05:49
Does it have to run in a specific thread?
kelvinp
2014/10/31 21:12:53
Comments added.
| |
16 // | |
17 // Implementation details: | |
18 // The MessageBox creates the dialog using the views::DialogWidget. The | |
19 // DialogWidget is created by the caller but its lifetime is managed by the | |
20 // NativeWidget. The DialogWidget communicates with the MessageBox using the | |
21 // DialogDelegateView interface. DialogDelegateView must remain valid until | |
22 // DeleteDelegate() is called, at which the DialogDelegateView deletes itself. | |
23 // To abstract this awkward ownership model, the MessageBox object is | |
24 // RefCounted. It calls AddRef() on itself when the widget is created and calls | |
25 // Release() when DeleteDelegate() is called. | |
26 class MessageBox : public views::DialogDelegateView, | |
27 public base::RefCounted<MessageBox> { | |
28 public: | |
29 enum Result { | |
30 OK, | |
31 CANCEL | |
32 }; | |
33 | |
34 // ResultCallback will be invoked with Result::Cancel if the user closes the | |
35 // MessageBox without clicking on any buttons. | |
36 typedef base::Callback<void(Result)> ResultCallback; | |
37 | |
38 MessageBox(const base::string16& message_label, | |
39 const base::string16& ok_label, | |
40 const base::string16& cancel_label, | |
41 ResultCallback result_callback); | |
42 | |
43 // Shows the message box. | |
44 void Show(); | |
45 // Hides the message box. | |
46 void Hide(); | |
47 | |
48 // views::DialogDelegateView interface. | |
49 bool Accept() override; | |
50 bool Cancel() override; | |
51 ui::ModalType GetModalType() const override; | |
52 base::string16 GetWindowTitle() const override; | |
53 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | |
54 void DeleteDelegate() override; | |
55 | |
56 private: | |
57 friend class base::RefCounted<MessageBox>; | |
58 ~MessageBox(); | |
dcaiafa
2014/10/31 18:05:49
~MessageBox() override;
kelvinp
2014/10/31 21:12:53
Done.
| |
59 | |
60 const base::string16 message_label_; | |
61 const base::string16 ok_label_; | |
62 const base::string16 cancel_label_; | |
63 ResultCallback result_callback_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(MessageBox); | |
66 }; | |
67 | |
68 } // namespace remoting | |
69 | |
70 #endif // REMOTING_HOST_CHROMEOS_MESSAGE_BOX_H_ | |
OLD | NEW |