Chromium Code Reviews| 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/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/ui/views/constrained_window_views.h" | 13 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
| 17 #include "ui/views/controls/message_box_view.h" | 17 #include "ui/views/controls/message_box_view.h" |
| 18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 19 #include "ui/views/window/dialog_delegate.h" | 19 #include "ui/views/window/dialog_delegate.h" |
| 20 | 20 |
| 21 #if defined(USE_AURA) | 21 #if defined(USE_AURA) |
| 22 #include "ui/aura/client/dispatcher_client.h" | 22 #include "ui/aura/client/dispatcher_client.h" |
| 23 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
| 24 #include "ui/aura/root_window.h" | 24 #include "ui/aura/root_window.h" |
| 25 #if defined(OS_WIN) | |
| 26 #include "ui/base/win/message_box_win.h" | |
| 27 #endif | |
| 25 #endif | 28 #endif |
| 26 | 29 |
| 27 namespace chrome { | 30 namespace chrome { |
| 28 | 31 |
| 29 namespace { | 32 namespace { |
| 30 | 33 |
| 31 // 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 |
| 32 // start a nested message-loop. However, these SimpleMessageBoxViews can be | 35 // start a nested message-loop. However, these SimpleMessageBoxViews can be |
| 33 // 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 |
| 34 // 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 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 | 170 |
| 168 SimpleMessageBoxViews::~SimpleMessageBoxViews() { | 171 SimpleMessageBoxViews::~SimpleMessageBoxViews() { |
| 169 } | 172 } |
| 170 | 173 |
| 171 } // namespace | 174 } // namespace |
| 172 | 175 |
| 173 MessageBoxResult ShowMessageBox(gfx::NativeWindow parent, | 176 MessageBoxResult ShowMessageBox(gfx::NativeWindow parent, |
| 174 const string16& title, | 177 const string16& title, |
| 175 const string16& message, | 178 const string16& message, |
| 176 MessageBoxType type) { | 179 MessageBoxType type) { |
| 180 #if defined(USE_AURA) && defined(OS_WIN) | |
|
sky
2013/08/19 16:56:12
Can you refactor simple_message_box_win.cc so that
| |
| 181 // If we're very early, we can't show a GPU-based dialog, so fallback to | |
| 182 // plain Windows MessageBox. | |
| 183 if (!ui::ContextFactory::GetInstance()) { | |
| 184 UINT flags = MB_SETFOREGROUND; | |
| 185 if (type == MESSAGE_BOX_TYPE_QUESTION) { | |
| 186 flags |= MB_YESNO; | |
| 187 } else if (type == MESSAGE_BOX_TYPE_OK_CANCEL) { | |
| 188 flags |= MB_OKCANCEL; | |
| 189 } else { | |
| 190 flags |= MB_OK; | |
| 191 } | |
| 192 flags |= ((type == MESSAGE_BOX_TYPE_INFORMATION) ? | |
| 193 MB_ICONINFORMATION : MB_ICONWARNING); | |
| 194 int result = ui::MessageBox(NULL, message, title, flags); | |
| 195 return (result == IDYES || result == IDOK) ? | |
| 196 MESSAGE_BOX_RESULT_YES : MESSAGE_BOX_RESULT_NO; | |
| 197 } | |
| 198 #endif | |
| 199 | |
| 177 scoped_refptr<SimpleMessageBoxViews> dialog( | 200 scoped_refptr<SimpleMessageBoxViews> dialog( |
| 178 new SimpleMessageBoxViews(title, message, type)); | 201 new SimpleMessageBoxViews(title, message, type)); |
| 179 CreateBrowserModalDialogViews(dialog.get(), parent)->Show(); | 202 CreateBrowserModalDialogViews(dialog.get(), parent)->Show(); |
| 180 | 203 |
| 181 #if defined(USE_AURA) | 204 #if defined(USE_AURA) |
| 182 // Use the widget's window itself so that the message loop | 205 // Use the widget's window itself so that the message loop |
| 183 // exists when the dialog is closed by some other means than | 206 // exists when the dialog is closed by some other means than |
| 184 // |Cancel| or |Accept|. | 207 // |Cancel| or |Accept|. |
| 185 aura::Window* anchor = parent ? | 208 aura::Window* anchor = parent ? |
| 186 parent : dialog->GetWidget()->GetNativeWindow(); | 209 parent : dialog->GetWidget()->GetNativeWindow(); |
| 187 aura::client::GetDispatcherClient(anchor->GetRootWindow()) | 210 aura::client::GetDispatcherClient(anchor->GetRootWindow()) |
| 188 ->RunWithDispatcher(dialog.get(), anchor, true); | 211 ->RunWithDispatcher(dialog.get(), anchor, true); |
| 189 #else | 212 #else |
| 190 { | 213 { |
| 191 base::MessageLoop::ScopedNestableTaskAllower allow( | 214 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 192 base::MessageLoopForUI::current()); | 215 base::MessageLoopForUI::current()); |
| 193 base::RunLoop run_loop(dialog); | 216 base::RunLoop run_loop(dialog); |
| 194 run_loop.Run(); | 217 run_loop.Run(); |
| 195 } | 218 } |
| 196 #endif | 219 #endif |
| 197 return dialog->result(); | 220 return dialog->result(); |
| 198 } | 221 } |
| 199 | 222 |
| 200 } // namespace chrome | 223 } // namespace chrome |
| OLD | NEW |