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

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

Issue 154203002: Remove unnecessary uses of aura::Env::GetDispatcher (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
« no previous file with comments | « chrome/browser/chrome_browser_main.cc ('k') | ui/aura/env.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
17 #include "ui/aura/env.h"
18 #include "ui/aura/root_window.h"
16 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/gfx/native_widget_types.h" 20 #include "ui/gfx/native_widget_types.h"
18 #include "ui/views/controls/message_box_view.h" 21 #include "ui/views/controls/message_box_view.h"
19 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
20 #include "ui/views/window/dialog_delegate.h" 23 #include "ui/views/window/dialog_delegate.h"
21 24
22 #if defined(USE_AURA)
23 #include "ui/aura/client/dispatcher_client.h"
24 #include "ui/aura/env.h"
25 #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
30 28
31 namespace chrome { 29 namespace chrome {
32 30
33 namespace { 31 namespace {
34 32
35 // Multiple SimpleMessageBoxViews can show up at the same time. Each of these 33 // Multiple SimpleMessageBoxViews can show up at the same time. Each of these
36 // start a nested message-loop. However, these SimpleMessageBoxViews can be 34 // 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 35 // 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 36 // 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. 37 // used so that the SimpleMessageBoxViews gets deleted at the right time.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 166
169 views::Widget* SimpleMessageBoxViews::GetWidget() { 167 views::Widget* SimpleMessageBoxViews::GetWidget() {
170 return message_box_view_->GetWidget(); 168 return message_box_view_->GetWidget();
171 } 169 }
172 170
173 const views::Widget* SimpleMessageBoxViews::GetWidget() const { 171 const views::Widget* SimpleMessageBoxViews::GetWidget() const {
174 return message_box_view_->GetWidget(); 172 return message_box_view_->GetWidget();
175 } 173 }
176 174
177 bool SimpleMessageBoxViews::Dispatch(const base::NativeEvent& event) { 175 bool SimpleMessageBoxViews::Dispatch(const base::NativeEvent& event) {
178 #if defined(OS_WIN) 176 #if defined(OS_WIN)
sky 2014/02/05 14:22:27 Can you remove these ifdefs entirely and go with 1
sadrul 2014/02/05 14:53:07 Nice. Done.
179 TranslateMessage(&event); 177 TranslateMessage(&event);
180 DispatchMessage(&event); 178 DispatchMessage(&event);
181 #elif defined(USE_AURA) 179 #else
182 aura::Env::GetInstance()->GetDispatcher()->Dispatch(event); 180 aura::Env::GetInstance()->GetDispatcher()->Dispatch(event);
183 #endif 181 #endif
184 return should_show_dialog_; 182 return should_show_dialog_;
185 } 183 }
186 184
187 //////////////////////////////////////////////////////////////////////////////// 185 ////////////////////////////////////////////////////////////////////////////////
188 // SimpleMessageBoxViews, private: 186 // SimpleMessageBoxViews, private:
189 187
190 SimpleMessageBoxViews::~SimpleMessageBoxViews() { 188 SimpleMessageBoxViews::~SimpleMessageBoxViews() {
191 } 189 }
192 190
193 MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent, 191 MessageBoxResult ShowMessageBoxImpl(gfx::NativeWindow parent,
194 const base::string16& title, 192 const base::string16& title,
195 const base::string16& message, 193 const base::string16& message,
196 MessageBoxType type, 194 MessageBoxType type,
197 const base::string16& yes_text, 195 const base::string16& yes_text,
198 const base::string16& no_text) { 196 const base::string16& no_text) {
199 197
200 #if defined(OS_WIN) 198 #if defined(OS_WIN)
201 // If we're very early, we can't show a GPU-based dialog, so fallback to 199 // If we're very early, we can't show a GPU-based dialog, so fallback to
202 // plain Windows MessageBox. 200 // plain Windows MessageBox.
203 if (!ui::ContextFactory::GetInstance()) 201 if (!ui::ContextFactory::GetInstance())
204 return NativeShowMessageBox(NULL, title, message, type); 202 return NativeShowMessageBox(NULL, title, message, type);
205 #endif 203 #endif
206 204
207 scoped_refptr<SimpleMessageBoxViews> dialog( 205 scoped_refptr<SimpleMessageBoxViews> dialog(
208 new SimpleMessageBoxViews(title, message, type, yes_text, no_text)); 206 new SimpleMessageBoxViews(title, message, type, yes_text, no_text));
209 CreateBrowserModalDialogViews(dialog.get(), parent)->Show(); 207 CreateBrowserModalDialogViews(dialog.get(), parent)->Show();
210 208
211 #if defined(USE_AURA)
212 aura::Window* anchor = parent; 209 aura::Window* anchor = parent;
213 aura::client::DispatcherClient* client = anchor ? 210 aura::client::DispatcherClient* client = anchor ?
214 aura::client::GetDispatcherClient(anchor->GetRootWindow()) : NULL; 211 aura::client::GetDispatcherClient(anchor->GetRootWindow()) : NULL;
215 if (!client) { 212 if (!client) {
216 // Use the widget's window itself so that the message loop 213 // Use the widget's window itself so that the message loop
217 // exists when the dialog is closed by some other means than 214 // exists when the dialog is closed by some other means than
218 // |Cancel| or |Accept|. 215 // |Cancel| or |Accept|.
219 anchor = dialog->GetWidget()->GetNativeWindow(); 216 anchor = dialog->GetWidget()->GetNativeWindow();
220 client = aura::client::GetDispatcherClient(anchor->GetRootWindow()); 217 client = aura::client::GetDispatcherClient(anchor->GetRootWindow());
221 } 218 }
222 client->RunWithDispatcher(dialog.get(), anchor, true); 219 client->RunWithDispatcher(dialog.get(), anchor, true);
223 #else
224 {
225 base::MessageLoop::ScopedNestableTaskAllower allow(
226 base::MessageLoopForUI::current());
227 base::RunLoop run_loop(dialog);
228 run_loop.Run();
229 }
230 #endif
231 return dialog->result(); 220 return dialog->result();
232 } 221 }
233 222
234 } // namespace 223 } // namespace
235 224
236 MessageBoxResult ShowMessageBox(gfx::NativeWindow parent, 225 MessageBoxResult ShowMessageBox(gfx::NativeWindow parent,
237 const base::string16& title, 226 const base::string16& title,
238 const base::string16& message, 227 const base::string16& message,
239 MessageBoxType type) { 228 MessageBoxType type) {
240 return ShowMessageBoxImpl( 229 return ShowMessageBoxImpl(
241 parent, title, message, type, base::string16(), base::string16()); 230 parent, title, message, type, base::string16(), base::string16());
242 } 231 }
243 232
244 #if defined(USE_AURA)
245 MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent, 233 MessageBoxResult ShowMessageBoxWithButtonText(gfx::NativeWindow parent,
246 const base::string16& title, 234 const base::string16& title,
247 const base::string16& message, 235 const base::string16& message,
248 const base::string16& yes_text, 236 const base::string16& yes_text,
249 const base::string16& no_text) { 237 const base::string16& no_text) {
250 return ShowMessageBoxImpl( 238 return ShowMessageBoxImpl(
251 parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text); 239 parent, title, message, MESSAGE_BOX_TYPE_QUESTION, yes_text, no_text);
252 } 240 }
253 #endif
254 241
255 } // namespace chrome 242 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/chrome_browser_main.cc ('k') | ui/aura/env.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698