Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: chrome/browser/ui/views/simple_message_box_views.cc

Issue 172633004: Refactor Windows MessageBox fallback code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop/message_pump_dispatcher.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/ui/views/constrained_window_views.h" 14 #include "chrome/browser/ui/views/constrained_window_views.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 #include "ui/aura/client/dispatcher_client.h" 16 #include "ui/aura/client/dispatcher_client.h"
17 #include "ui/aura/env.h" 17 #include "ui/aura/env.h"
18 #include "ui/aura/root_window.h" 18 #include "ui/aura/root_window.h"
19 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/gfx/native_widget_types.h" 20 #include "ui/gfx/native_widget_types.h"
21 #include "ui/views/controls/message_box_view.h" 21 #include "ui/views/controls/message_box_view.h"
22 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
23 #include "ui/views/window/dialog_delegate.h" 23 #include "ui/views/window/dialog_delegate.h"
24 24
25 #if defined(OS_WIN) 25 #if defined(OS_WIN)
26 #include "chrome/browser/ui/views/simple_message_box_win.h" 26 #include "ui/base/win/message_box_win.h"
27 #include "ui/views/win/hwnd_util.h"
27 #endif 28 #endif
28 29
29 namespace chrome { 30 namespace chrome {
30 31
31 namespace { 32 namespace {
32 33
33 // 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
34 // start a nested message-loop. However, these SimpleMessageBoxViews can be 35 // start a nested message-loop. However, these SimpleMessageBoxViews can be
35 // 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
36 // 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 action |= POST_DISPATCH_QUIT_LOOP; 179 action |= POST_DISPATCH_QUIT_LOOP;
179 return action; 180 return action;
180 } 181 }
181 182
182 //////////////////////////////////////////////////////////////////////////////// 183 ////////////////////////////////////////////////////////////////////////////////
183 // SimpleMessageBoxViews, private: 184 // SimpleMessageBoxViews, private:
184 185
185 SimpleMessageBoxViews::~SimpleMessageBoxViews() { 186 SimpleMessageBoxViews::~SimpleMessageBoxViews() {
186 } 187 }
187 188
189 #if defined(OS_WIN)
190 UINT GetMessageBoxFlagsFromType(MessageBoxType type) {
191 UINT flags = MB_SETFOREGROUND;
192 switch (type) {
193 case MESSAGE_BOX_TYPE_INFORMATION:
194 return flags | MB_OK | MB_ICONINFORMATION;
195 case MESSAGE_BOX_TYPE_WARNING:
196 return flags | MB_OK | MB_ICONWARNING;
197 case MESSAGE_BOX_TYPE_QUESTION:
198 return flags | MB_YESNO | MB_ICONQUESTION;
199 case MESSAGE_BOX_TYPE_OK_CANCEL:
200 return flags | MB_OKCANCEL | MB_ICONWARNING;
201 }
202 NOTREACHED();
203 return flags | MB_OK | MB_ICONWARNING;
204 }
205 #endif
206
188 MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent, 207 MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent,
189 const base::string16& title, 208 const base::string16& title,
190 const base::string16& message, 209 const base::string16& message,
191 MessageBoxType type, 210 MessageBoxType type,
192 const base::string16& yes_text, 211 const base::string16& yes_text,
193 const base::string16& no_text) { 212 const base::string16& no_text) {
194
195 #if defined(OS_WIN) 213 #if defined(OS_WIN)
196 // If we're very early, we can't show a GPU-based dialog, so fallback to 214 // GPU-based dialogs can't be used early on; fallback to a Windows MessageBox.
197 // plain Windows MessageBox. 215 if (!ui::ContextFactory::GetInstance()) {
198 if (!ui::ContextFactory::GetInstance()) 216 int result = ui::MessageBox(views::HWNDForNativeWindow(parent), message,
199 return NativeShowMessageBox(NULL, title, message, type); 217 title, GetMessageBoxFlagsFromType(type));
218 return (result == IDYES || result == IDOK) ?
219 MESSAGE_BOX_RESULT_YES : MESSAGE_BOX_RESULT_NO;
220 }
200 #endif 221 #endif
201 222
202 scoped_refptr<SimpleMessageBoxViews> dialog( 223 scoped_refptr<SimpleMessageBoxViews> dialog(
203 new SimpleMessageBoxViews(title, message, type, yes_text, no_text)); 224 new SimpleMessageBoxViews(title, message, type, yes_text, no_text));
204 CreateBrowserModalDialogViews(dialog.get(), parent)->Show(); 225 CreateBrowserModalDialogViews(dialog.get(), parent)->Show();
205 226
206 aura::Window* anchor = parent; 227 aura::Window* anchor = parent;
207 aura::client::DispatcherClient* client = anchor ? 228 aura::client::DispatcherClient* client = anchor ?
208 aura::client::GetDispatcherClient(anchor->GetRootWindow()) : NULL; 229 aura::client::GetDispatcherClient(anchor->GetRootWindow()) : NULL;
209 if (!client) { 230 if (!client) {
(...skipping 20 matching lines...) Expand all
230 MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, 251 MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent,
231 const base::string16& title, 252 const base::string16& title,
232 const base::string16& message, 253 const base::string16& message,
233 const base::string16& yes_text, 254 const base::string16& yes_text,
234 const base::string16& no_text) { 255 const base::string16& no_text) {
235 return ShowMessageBoxImpl( 256 return ShowMessageBoxImpl(
236 parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text); 257 parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text);
237 } 258 }
238 259
239 } // namespace chrome 260 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/simple_message_box.h ('k') | chrome/browser/ui/views/simple_message_box_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698