OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/simple_message_box.h" | 5 #include "chrome/browser/ui/simple_message_box.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/ui/views/constrained_window_views.h" | 10 #include "chrome/browser/ui/views/constrained_window_views.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 class SimpleMessageBoxViews : public views::DialogDelegate { | 29 class SimpleMessageBoxViews : public views::DialogDelegate { |
30 public: | 30 public: |
31 SimpleMessageBoxViews(const base::string16& title, | 31 SimpleMessageBoxViews(const base::string16& title, |
32 const base::string16& message, | 32 const base::string16& message, |
33 MessageBoxType type, | 33 MessageBoxType type, |
34 const base::string16& yes_text, | 34 const base::string16& yes_text, |
35 const base::string16& no_text, | 35 const base::string16& no_text, |
| 36 bool is_system_modal, |
36 MessageBoxResult* result); | 37 MessageBoxResult* result); |
37 virtual ~SimpleMessageBoxViews(); | 38 virtual ~SimpleMessageBoxViews(); |
38 | 39 |
39 // Overridden from views::DialogDelegate: | 40 // Overridden from views::DialogDelegate: |
40 virtual int GetDialogButtons() const OVERRIDE; | 41 virtual int GetDialogButtons() const OVERRIDE; |
41 virtual base::string16 GetDialogButtonLabel( | 42 virtual base::string16 GetDialogButtonLabel( |
42 ui::DialogButton button) const OVERRIDE; | 43 ui::DialogButton button) const OVERRIDE; |
43 virtual bool Cancel() OVERRIDE; | 44 virtual bool Cancel() OVERRIDE; |
44 virtual bool Accept() OVERRIDE; | 45 virtual bool Accept() OVERRIDE; |
45 | 46 |
46 // Overridden from views::WidgetDelegate: | 47 // Overridden from views::WidgetDelegate: |
47 virtual base::string16 GetWindowTitle() const OVERRIDE; | 48 virtual base::string16 GetWindowTitle() const OVERRIDE; |
48 virtual void DeleteDelegate() OVERRIDE; | 49 virtual void DeleteDelegate() OVERRIDE; |
49 virtual ui::ModalType GetModalType() const OVERRIDE; | 50 virtual ui::ModalType GetModalType() const OVERRIDE; |
50 virtual views::View* GetContentsView() OVERRIDE; | 51 virtual views::View* GetContentsView() OVERRIDE; |
51 virtual views::Widget* GetWidget() OVERRIDE; | 52 virtual views::Widget* GetWidget() OVERRIDE; |
52 virtual const views::Widget* GetWidget() const OVERRIDE; | 53 virtual const views::Widget* GetWidget() const OVERRIDE; |
53 | 54 |
54 private: | 55 private: |
55 | 56 |
56 // This terminates the nested message-loop. | 57 // This terminates the nested message-loop. |
57 void Done(); | 58 void Done(); |
58 | 59 |
59 const base::string16 window_title_; | 60 const base::string16 window_title_; |
60 const MessageBoxType type_; | 61 const MessageBoxType type_; |
61 base::string16 yes_text_; | 62 base::string16 yes_text_; |
62 base::string16 no_text_; | 63 base::string16 no_text_; |
63 MessageBoxResult* result_; | 64 MessageBoxResult* result_; |
| 65 bool is_system_modal_; |
64 views::MessageBoxView* message_box_view_; | 66 views::MessageBoxView* message_box_view_; |
65 | 67 |
66 DISALLOW_COPY_AND_ASSIGN(SimpleMessageBoxViews); | 68 DISALLOW_COPY_AND_ASSIGN(SimpleMessageBoxViews); |
67 }; | 69 }; |
68 | 70 |
69 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
70 // SimpleMessageBoxViews, public: | 72 // SimpleMessageBoxViews, public: |
71 | 73 |
72 SimpleMessageBoxViews::SimpleMessageBoxViews(const base::string16& title, | 74 SimpleMessageBoxViews::SimpleMessageBoxViews(const base::string16& title, |
73 const base::string16& message, | 75 const base::string16& message, |
74 MessageBoxType type, | 76 MessageBoxType type, |
75 const base::string16& yes_text, | 77 const base::string16& yes_text, |
76 const base::string16& no_text, | 78 const base::string16& no_text, |
| 79 bool is_system_modal, |
77 MessageBoxResult* result) | 80 MessageBoxResult* result) |
78 : window_title_(title), | 81 : window_title_(title), |
79 type_(type), | 82 type_(type), |
80 yes_text_(yes_text), | 83 yes_text_(yes_text), |
81 no_text_(no_text), | 84 no_text_(no_text), |
82 result_(result), | 85 result_(result), |
| 86 is_system_modal_(is_system_modal), |
83 message_box_view_(new views::MessageBoxView( | 87 message_box_view_(new views::MessageBoxView( |
84 views::MessageBoxView::InitParams(message))) { | 88 views::MessageBoxView::InitParams(message))) { |
85 CHECK(result_); | 89 CHECK(result_); |
86 if (yes_text_.empty()) { | 90 if (yes_text_.empty()) { |
87 if (type_ == MESSAGE_BOX_TYPE_QUESTION) | 91 if (type_ == MESSAGE_BOX_TYPE_QUESTION) |
88 yes_text_ = | 92 yes_text_ = |
89 l10n_util::GetStringUTF16(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); | 93 l10n_util::GetStringUTF16(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); |
90 else if (type_ == MESSAGE_BOX_TYPE_OK_CANCEL) | 94 else if (type_ == MESSAGE_BOX_TYPE_OK_CANCEL) |
91 yes_text_ = l10n_util::GetStringUTF16(IDS_OK); | 95 yes_text_ = l10n_util::GetStringUTF16(IDS_OK); |
92 else | 96 else |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 139 |
136 base::string16 SimpleMessageBoxViews::GetWindowTitle() const { | 140 base::string16 SimpleMessageBoxViews::GetWindowTitle() const { |
137 return window_title_; | 141 return window_title_; |
138 } | 142 } |
139 | 143 |
140 void SimpleMessageBoxViews::DeleteDelegate() { | 144 void SimpleMessageBoxViews::DeleteDelegate() { |
141 delete this; | 145 delete this; |
142 } | 146 } |
143 | 147 |
144 ui::ModalType SimpleMessageBoxViews::GetModalType() const { | 148 ui::ModalType SimpleMessageBoxViews::GetModalType() const { |
145 return ui::MODAL_TYPE_WINDOW; | 149 return is_system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_WINDOW; |
146 } | 150 } |
147 | 151 |
148 views::View* SimpleMessageBoxViews::GetContentsView() { | 152 views::View* SimpleMessageBoxViews::GetContentsView() { |
149 return message_box_view_; | 153 return message_box_view_; |
150 } | 154 } |
151 | 155 |
152 views::Widget* SimpleMessageBoxViews::GetWidget() { | 156 views::Widget* SimpleMessageBoxViews::GetWidget() { |
153 return message_box_view_->GetWidget(); | 157 return message_box_view_->GetWidget(); |
154 } | 158 } |
155 | 159 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 MESSAGE_BOX_RESULT_YES : MESSAGE_BOX_RESULT_NO; | 206 MESSAGE_BOX_RESULT_YES : MESSAGE_BOX_RESULT_NO; |
203 #else | 207 #else |
204 LOG(ERROR) << "Unable to show a dialog outside the UI thread message loop: " | 208 LOG(ERROR) << "Unable to show a dialog outside the UI thread message loop: " |
205 << title << " - " << message; | 209 << title << " - " << message; |
206 return MESSAGE_BOX_RESULT_NO; | 210 return MESSAGE_BOX_RESULT_NO; |
207 #endif | 211 #endif |
208 } | 212 } |
209 | 213 |
210 MessageBoxResult result = MESSAGE_BOX_RESULT_NO; | 214 MessageBoxResult result = MESSAGE_BOX_RESULT_NO; |
211 SimpleMessageBoxViews* dialog = new SimpleMessageBoxViews( | 215 SimpleMessageBoxViews* dialog = new SimpleMessageBoxViews( |
212 title, message, type, yes_text, no_text, &result); | 216 title, |
| 217 message, |
| 218 type, |
| 219 yes_text, |
| 220 no_text, |
| 221 parent == NULL, // is_system_modal |
| 222 &result); |
213 CreateBrowserModalDialogViews(dialog, parent)->Show(); | 223 CreateBrowserModalDialogViews(dialog, parent)->Show(); |
214 | 224 |
215 // Use the widget's window itself so that the message loop exists when the | 225 // Use the widget's window itself so that the message loop exists when the |
216 // dialog is closed by some other means than |Cancel| or |Accept|. | 226 // dialog is closed by some other means than |Cancel| or |Accept|. |
217 aura::Window* anchor = dialog->GetWidget()->GetNativeWindow(); | 227 aura::Window* anchor = dialog->GetWidget()->GetNativeWindow(); |
218 aura::client::DispatcherClient* client = | 228 aura::client::DispatcherClient* client = |
219 aura::client::GetDispatcherClient(anchor->GetRootWindow()); | 229 aura::client::GetDispatcherClient(anchor->GetRootWindow()); |
220 client->RunWithDispatcher(NULL); | 230 client->RunWithDispatcher(NULL); |
221 // NOTE: |dialog| will have been deleted by the time control returns here. | 231 // NOTE: |dialog| will have been deleted by the time control returns here. |
222 | 232 |
(...skipping 13 matching lines...) Expand all Loading... |
236 MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, | 246 MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, |
237 const base::string16& title, | 247 const base::string16& title, |
238 const base::string16& message, | 248 const base::string16& message, |
239 const base::string16& yes_text, | 249 const base::string16& yes_text, |
240 const base::string16& no_text) { | 250 const base::string16& no_text) { |
241 return ShowMessageBoxImpl( | 251 return ShowMessageBoxImpl( |
242 parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text); | 252 parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text); |
243 } | 253 } |
244 | 254 |
245 } // namespace chrome | 255 } // namespace chrome |
OLD | NEW |