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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/message_loop/message_pump_dispatcher.h" |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/ui/views/constrained_window_views.h" | 14 #include "chrome/browser/ui/views/constrained_window_views.h" |
14 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
17 #include "ui/views/controls/message_box_view.h" | 18 #include "ui/views/controls/message_box_view.h" |
18 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
19 #include "ui/views/window/dialog_delegate.h" | 20 #include "ui/views/window/dialog_delegate.h" |
20 | 21 |
21 #if defined(USE_AURA) | 22 #if defined(USE_AURA) |
22 #include "ui/aura/client/dispatcher_client.h" | 23 #include "ui/aura/client/dispatcher_client.h" |
23 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
24 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
25 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
26 #include "chrome/browser/ui/views/simple_message_box_win.h" | 27 #include "chrome/browser/ui/views/simple_message_box_win.h" |
27 #endif | 28 #endif |
28 #endif | 29 #endif |
29 | 30 |
30 namespace chrome { | 31 namespace chrome { |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // Multiple SimpleMessageBoxViews can show up at the same time. Each of these | 35 // Multiple SimpleMessageBoxViews can show up at the same time. Each of these |
35 // start a nested message-loop. However, these SimpleMessageBoxViews can be | 36 // start a nested message-loop. However, these SimpleMessageBoxViews can be |
36 // deleted in any order. This creates problems if a box in an inner-loop gets | 37 // deleted in any order. This creates problems if a box in an inner-loop gets |
37 // destroyed before a box in an outer-loop. So to avoid this, ref-counting is | 38 // destroyed before a box in an outer-loop. So to avoid this, ref-counting is |
38 // used so that the SimpleMessageBoxViews gets deleted at the right time. | 39 // used so that the SimpleMessageBoxViews gets deleted at the right time. |
39 class SimpleMessageBoxViews : public views::DialogDelegate, | 40 class SimpleMessageBoxViews : public views::DialogDelegate, |
40 public base::MessageLoop::Dispatcher, | 41 public base::MessagePumpDispatcher, |
41 public base::RefCounted<SimpleMessageBoxViews> { | 42 public base::RefCounted<SimpleMessageBoxViews> { |
42 public: | 43 public: |
43 SimpleMessageBoxViews(const base::string16& title, | 44 SimpleMessageBoxViews(const base::string16& title, |
44 const base::string16& message, | 45 const base::string16& message, |
45 MessageBoxType type, | 46 MessageBoxType type, |
46 const base::string16& yes_text, | 47 const base::string16& yes_text, |
47 const base::string16& no_text); | 48 const base::string16& no_text); |
48 | 49 |
49 MessageBoxResult result() const { return result_; } | 50 MessageBoxResult result() const { return result_; } |
50 | 51 |
51 // Overridden from views::DialogDelegate: | 52 // Overridden from views::DialogDelegate: |
52 virtual int GetDialogButtons() const OVERRIDE; | 53 virtual int GetDialogButtons() const OVERRIDE; |
53 virtual base::string16 GetDialogButtonLabel( | 54 virtual base::string16 GetDialogButtonLabel( |
54 ui::DialogButton button) const OVERRIDE; | 55 ui::DialogButton button) const OVERRIDE; |
55 virtual bool Cancel() OVERRIDE; | 56 virtual bool Cancel() OVERRIDE; |
56 virtual bool Accept() OVERRIDE; | 57 virtual bool Accept() OVERRIDE; |
57 | 58 |
58 // Overridden from views::WidgetDelegate: | 59 // Overridden from views::WidgetDelegate: |
59 virtual base::string16 GetWindowTitle() const OVERRIDE; | 60 virtual base::string16 GetWindowTitle() const OVERRIDE; |
60 virtual void DeleteDelegate() OVERRIDE; | 61 virtual void DeleteDelegate() OVERRIDE; |
61 virtual ui::ModalType GetModalType() const OVERRIDE; | 62 virtual ui::ModalType GetModalType() const OVERRIDE; |
62 virtual views::View* GetContentsView() OVERRIDE; | 63 virtual views::View* GetContentsView() OVERRIDE; |
63 virtual views::Widget* GetWidget() OVERRIDE; | 64 virtual views::Widget* GetWidget() OVERRIDE; |
64 virtual const views::Widget* GetWidget() const OVERRIDE; | 65 virtual const views::Widget* GetWidget() const OVERRIDE; |
65 | 66 |
66 // Overridden from MessageLoop::Dispatcher: | 67 // Overridden from MessagePumpDispatcher: |
67 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; | 68 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; |
68 | 69 |
69 private: | 70 private: |
70 friend class base::RefCounted<SimpleMessageBoxViews>; | 71 friend class base::RefCounted<SimpleMessageBoxViews>; |
71 virtual ~SimpleMessageBoxViews(); | 72 virtual ~SimpleMessageBoxViews(); |
72 | 73 |
73 const base::string16 window_title_; | 74 const base::string16 window_title_; |
74 const MessageBoxType type_; | 75 const MessageBoxType type_; |
75 base::string16 yes_text_; | 76 base::string16 yes_text_; |
76 base::string16 no_text_; | 77 base::string16 no_text_; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 const base::string16& title, | 246 const base::string16& title, |
246 const base::string16& message, | 247 const base::string16& message, |
247 const base::string16& yes_text, | 248 const base::string16& yes_text, |
248 const base::string16& no_text) { | 249 const base::string16& no_text) { |
249 return ShowMessageBoxImpl( | 250 return ShowMessageBoxImpl( |
250 parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text); | 251 parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text); |
251 } | 252 } |
252 #endif | 253 #endif |
253 | 254 |
254 } // namespace chrome | 255 } // namespace chrome |
OLD | NEW |