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

Side by Side Diff: ui/views/controls/menu/menu_controller.cc

Issue 219743002: x11: Move X event handling out of the message-pump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-r261267 Created 6 years, 8 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 "ui/views/controls/menu/menu_controller.h" 5 #include "ui/views/controls/menu/menu_controller.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windowsx.h> 8 #include <windowsx.h>
9 #endif 9 #endif
10 10
11 #include "base/i18n/case_conversion.h" 11 #include "base/i18n/case_conversion.h"
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "ui/aura/env.h" 16 #include "ui/aura/env.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/aura/window_event_dispatcher.h" 18 #include "ui/aura/window_event_dispatcher.h"
19 #include "ui/base/dragdrop/drag_utils.h" 19 #include "ui/base/dragdrop/drag_utils.h"
20 #include "ui/base/dragdrop/os_exchange_data.h" 20 #include "ui/base/dragdrop/os_exchange_data.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/events/event_constants.h" 22 #include "ui/events/event_constants.h"
23 #include "ui/events/event_utils.h" 23 #include "ui/events/event_utils.h"
24 #include "ui/events/platform/platform_event_source.h"
25 #include "ui/events/platform/scoped_event_dispatcher.h"
24 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/native_widget_types.h" 27 #include "ui/gfx/native_widget_types.h"
26 #include "ui/gfx/screen.h" 28 #include "ui/gfx/screen.h"
27 #include "ui/gfx/vector2d.h" 29 #include "ui/gfx/vector2d.h"
28 #include "ui/native_theme/native_theme.h" 30 #include "ui/native_theme/native_theme.h"
29 #include "ui/views/controls/button/menu_button.h" 31 #include "ui/views/controls/button/menu_button.h"
30 #include "ui/views/controls/menu/menu_config.h" 32 #include "ui/views/controls/menu/menu_config.h"
31 #include "ui/views/controls/menu/menu_controller_delegate.h" 33 #include "ui/views/controls/menu/menu_controller_delegate.h"
32 #include "ui/views/controls/menu/menu_host_root_view.h" 34 #include "ui/views/controls/menu/menu_host_root_view.h"
33 #include "ui/views/controls/menu/menu_message_pump_dispatcher.h"
34 #include "ui/views/controls/menu/menu_scroll_view_container.h" 35 #include "ui/views/controls/menu/menu_scroll_view_container.h"
35 #include "ui/views/controls/menu/submenu_view.h" 36 #include "ui/views/controls/menu/submenu_view.h"
36 #include "ui/views/drag_utils.h" 37 #include "ui/views/drag_utils.h"
37 #include "ui/views/event_utils.h" 38 #include "ui/views/event_utils.h"
38 #include "ui/views/focus/view_storage.h" 39 #include "ui/views/focus/view_storage.h"
39 #include "ui/views/mouse_constants.h" 40 #include "ui/views/mouse_constants.h"
40 #include "ui/views/view_constants.h" 41 #include "ui/views/view_constants.h"
41 #include "ui/views/views_delegate.h" 42 #include "ui/views/views_delegate.h"
42 #include "ui/views/widget/root_view.h" 43 #include "ui/views/widget/root_view.h"
43 #include "ui/views/widget/tooltip_manager.h" 44 #include "ui/views/widget/tooltip_manager.h"
44 #include "ui/views/widget/widget.h" 45 #include "ui/views/widget/widget.h"
45 #include "ui/wm/public/activation_change_observer.h" 46 #include "ui/wm/public/activation_change_observer.h"
46 #include "ui/wm/public/activation_client.h" 47 #include "ui/wm/public/activation_client.h"
47 #include "ui/wm/public/dispatcher_client.h" 48 #include "ui/wm/public/dispatcher_client.h"
48 #include "ui/wm/public/drag_drop_client.h" 49 #include "ui/wm/public/drag_drop_client.h"
49 50
50 #if defined(OS_WIN) 51 #if defined(OS_WIN)
51 #include "ui/base/win/internal_constants.h" 52 #include "ui/base/win/internal_constants.h"
53 #include "ui/views/controls/menu/menu_message_pump_dispatcher_win.h"
52 #include "ui/views/win/hwnd_util.h" 54 #include "ui/views/win/hwnd_util.h"
55 #else
56 #include "ui/views/controls/menu/menu_event_dispatcher_linux.h"
53 #endif 57 #endif
54 58
55 using base::Time; 59 using base::Time;
56 using base::TimeDelta; 60 using base::TimeDelta;
57 using ui::OSExchangeData; 61 using ui::OSExchangeData;
58 62
59 // Period of the scroll timer (in milliseconds). 63 // Period of the scroll timer (in milliseconds).
60 static const int kScrollTimerMS = 30; 64 static const int kScrollTimerMS = 30;
61 65
62 // Amount of time from when the drop exits the menu and the menu is hidden. 66 // Amount of time from when the drop exits the menu and the menu is hidden.
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 MenuController::~MenuController() { 1168 MenuController::~MenuController() {
1165 DCHECK(!showing_); 1169 DCHECK(!showing_);
1166 if (owner_) 1170 if (owner_)
1167 owner_->RemoveObserver(this); 1171 owner_->RemoveObserver(this);
1168 if (active_instance_ == this) 1172 if (active_instance_ == this)
1169 active_instance_ = NULL; 1173 active_instance_ = NULL;
1170 StopShowTimer(); 1174 StopShowTimer();
1171 StopCancelAllTimer(); 1175 StopCancelAllTimer();
1172 } 1176 }
1173 1177
1178 #if defined(OS_WIN)
1174 void MenuController::RunMessageLoop(bool nested_menu) { 1179 void MenuController::RunMessageLoop(bool nested_menu) {
1175 internal::MenuMessagePumpDispatcher nested_dispatcher(this); 1180 internal::MenuMessagePumpDispatcher nested_dispatcher(this);
1176 1181
1177 // |owner_| may be NULL. 1182 // |owner_| may be NULL.
1178 aura::Window* root = GetOwnerRootWindow(owner_); 1183 aura::Window* root = GetOwnerRootWindow(owner_);
1179 if (root) { 1184 if (root) {
1180 scoped_ptr<ActivationChangeObserverImpl> observer; 1185 scoped_ptr<ActivationChangeObserverImpl> observer;
1181 if (!nested_menu) 1186 if (!nested_menu)
1182 observer.reset(new ActivationChangeObserverImpl(this, root)); 1187 observer.reset(new ActivationChangeObserverImpl(this, root));
1183 aura::client::GetDispatcherClient(root) 1188 aura::client::GetDispatcherClient(root)
1184 ->RunWithDispatcher(&nested_dispatcher); 1189 ->RunWithDispatcher(&nested_dispatcher);
1185 } else { 1190 } else {
1186 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); 1191 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
1187 base::MessageLoop::ScopedNestableTaskAllower allow(loop); 1192 base::MessageLoop::ScopedNestableTaskAllower allow(loop);
1188 base::RunLoop run_loop(&nested_dispatcher); 1193 base::RunLoop run_loop(&nested_dispatcher);
1189 run_loop.Run(); 1194 run_loop.Run();
1190 } 1195 }
1191 } 1196 }
1197 #else
1198 void MenuController::RunMessageLoop(bool nested_menu) {
1199 internal::MenuEventDispatcher event_dispatcher(this);
1200 scoped_ptr<ui::ScopedEventDispatcher> old_dispatcher =
1201 nested_dispatcher_.Pass();
1202 if (ui::PlatformEventSource::GetInstance()) {
1203 nested_dispatcher_ =
1204 ui::PlatformEventSource::GetInstance()->OverrideDispatcher(
1205 &event_dispatcher);
1206 }
1207 // |owner_| may be NULL.
1208 aura::Window* root = GetOwnerRootWindow(owner_);
1209 if (root) {
1210 scoped_ptr<ActivationChangeObserverImpl> observer;
1211 if (!nested_menu)
1212 observer.reset(new ActivationChangeObserverImpl(this, root));
1213 aura::client::GetDispatcherClient(root)->RunWithDispatcher(NULL);
1214 } else {
1215 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
1216 base::MessageLoop::ScopedNestableTaskAllower allow(loop);
1217 base::RunLoop run_loop;
1218 run_loop.Run();
1219 }
1220 nested_dispatcher_ = old_dispatcher.Pass();
1221 }
1222 #endif
1192 1223
1193 MenuController::SendAcceleratorResultType 1224 MenuController::SendAcceleratorResultType
1194 MenuController::SendAcceleratorToHotTrackedView() { 1225 MenuController::SendAcceleratorToHotTrackedView() {
1195 CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item); 1226 CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item);
1196 if (!hot_view) 1227 if (!hot_view)
1197 return ACCELERATOR_NOT_PROCESSED; 1228 return ACCELERATOR_NOT_PROCESSED;
1198 1229
1199 ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE); 1230 ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE);
1200 hot_view->AcceleratorPressed(accelerator); 1231 hot_view->AcceleratorPressed(accelerator);
1201 CustomButton* button = static_cast<CustomButton*>(hot_view); 1232 CustomButton* button = static_cast<CustomButton*>(hot_view);
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
2296 bool quit_now = ShouldQuitNow() && exit_type_ != EXIT_NONE && 2327 bool quit_now = ShouldQuitNow() && exit_type_ != EXIT_NONE &&
2297 message_loop_depth_; 2328 message_loop_depth_;
2298 2329
2299 if (quit_now) { 2330 if (quit_now) {
2300 if (owner_) { 2331 if (owner_) {
2301 aura::Window* root = owner_->GetNativeWindow()->GetRootWindow(); 2332 aura::Window* root = owner_->GetNativeWindow()->GetRootWindow();
2302 aura::client::GetDispatcherClient(root)->QuitNestedMessageLoop(); 2333 aura::client::GetDispatcherClient(root)->QuitNestedMessageLoop();
2303 } else { 2334 } else {
2304 base::MessageLoop::current()->QuitNow(); 2335 base::MessageLoop::current()->QuitNow();
2305 } 2336 }
2337 // Restore the previous dispatcher.
2338 nested_dispatcher_.reset();
2306 } 2339 }
2307 } 2340 }
2308 2341
2309 bool MenuController::ShouldQuitNow() const { 2342 bool MenuController::ShouldQuitNow() const {
2310 aura::Window* root = GetOwnerRootWindow(owner_); 2343 aura::Window* root = GetOwnerRootWindow(owner_);
2311 return !aura::client::GetDragDropClient(root) || 2344 return !aura::client::GetDragDropClient(root) ||
2312 !aura::client::GetDragDropClient(root)->IsDragDropInProgress(); 2345 !aura::client::GetDragDropClient(root)->IsDragDropInProgress();
2313 } 2346 }
2314 2347
2315 void MenuController::HandleMouseLocation(SubmenuView* source, 2348 void MenuController::HandleMouseLocation(SubmenuView* source,
(...skipping 28 matching lines...) Expand all
2344 } 2377 }
2345 } 2378 }
2346 2379
2347 gfx::Screen* MenuController::GetScreen() { 2380 gfx::Screen* MenuController::GetScreen() {
2348 aura::Window* root = GetOwnerRootWindow(owner_); 2381 aura::Window* root = GetOwnerRootWindow(owner_);
2349 return root ? gfx::Screen::GetScreenFor(root) 2382 return root ? gfx::Screen::GetScreenFor(root)
2350 : gfx::Screen::GetNativeScreen(); 2383 : gfx::Screen::GetNativeScreen();
2351 } 2384 }
2352 2385
2353 } // namespace views 2386 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_event_dispatcher_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698