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