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

Unified Diff: ui/views/controls/menu/menu_message_loop_aura.cc

Issue 1138523006: Enable keyboard accelerators while a menu is open (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handling oshima's comments Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/menu/menu_message_loop_aura.cc
diff --git a/ui/views/controls/menu/menu_message_loop_aura.cc b/ui/views/controls/menu/menu_message_loop_aura.cc
index 3ed33281aa6f43e8b99a301acb33af9aef39515f..4191d770bbb2eb30921d9b4c807878596be731a8 100644
--- a/ui/views/controls/menu/menu_message_loop_aura.cc
+++ b/ui/views/controls/menu/menu_message_loop_aura.cc
@@ -103,7 +103,9 @@ MenuMessageLoop* MenuMessageLoop::Create() {
return new MenuMessageLoopAura;
}
-MenuMessageLoopAura::MenuMessageLoopAura() : owner_(NULL) {
+MenuMessageLoopAura::MenuMessageLoopAura()
+ : owner_(NULL),
+ menu_event_filter_(new MenuEventFilter) {
}
MenuMessageLoopAura::~MenuMessageLoopAura() {
@@ -139,53 +141,43 @@ void MenuMessageLoopAura::Run(MenuController* controller,
base::AutoReset<base::Closure> reset_quit_closure(&message_loop_quit_,
base::Closure());
-#if defined(OS_WIN)
- internal::MenuMessagePumpDispatcher nested_dispatcher(controller);
+ scoped_ptr<ActivationChangeObserverImpl> observer;
if (root) {
- scoped_ptr<ActivationChangeObserverImpl> observer;
if (!nested_menu)
observer.reset(new ActivationChangeObserverImpl(controller, root));
- aura::client::DispatcherRunLoop run_loop(
- aura::client::GetDispatcherClient(root), &nested_dispatcher);
- message_loop_quit_ = run_loop.QuitClosure();
- run_loop.Run();
- } else {
- base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
- base::MessageLoop::ScopedNestableTaskAllower allow(loop);
- base::RunLoop run_loop(&nested_dispatcher);
- message_loop_quit_ = run_loop.QuitClosure();
- run_loop.Run();
+ MenuEventFilter::Delegate* filter_delegate =
+ MenuEventFilter::GetMenuEventFilterDelegate(root);
+ if (filter_delegate)
+ menu_event_filter_->SetDelegate(filter_delegate);
}
+
+ CHECK(menu_event_filter_.get());
+ aura::Env::GetInstanceDontCreate()->PrependPreTargetHandler(
+ menu_event_filter_.get());
+ base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
+ base::MessageLoop::ScopedNestableTaskAllower allow(loop);
+
+#if defined(OS_WIN)
+ // On Windows we need the following nested dispatcher to handle some
+ // Windows-specific events like WM_CONTEXTMENU and others that can't be
+ // captured by the MenuEventFilter.
+ internal::MenuMessagePumpDispatcher nested_dispatcher(controller);
+ base::RunLoop run_loop(&nested_dispatcher);
#else
- internal::MenuEventDispatcher event_dispatcher(controller);
- scoped_ptr<ui::ScopedEventDispatcher> dispatcher_override;
- if (ui::PlatformEventSource::GetInstance()) {
- dispatcher_override =
- ui::PlatformEventSource::GetInstance()->OverrideDispatcher(
- &event_dispatcher);
- }
- if (root) {
- scoped_ptr<ActivationChangeObserverImpl> observer;
- if (!nested_menu)
- observer.reset(new ActivationChangeObserverImpl(controller, root));
- aura::client::DispatcherRunLoop run_loop(
- aura::client::GetDispatcherClient(root), NULL);
- message_loop_quit_ = run_loop.QuitClosure();
- run_loop.Run();
- } else {
- base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
- base::MessageLoop::ScopedNestableTaskAllower allow(loop);
- base::RunLoop run_loop;
- message_loop_quit_ = run_loop.QuitClosure();
- run_loop.Run();
- }
-#endif
+ base::RunLoop run_loop;
+#endif // defined(OS_WIN)
+ message_loop_quit_ = run_loop.QuitClosure();
+ run_loop.Run();
}
void MenuMessageLoopAura::QuitNow() {
CHECK(!message_loop_quit_.is_null());
message_loop_quit_.Run();
+ aura::Env::GetInstanceDontCreate()->RemovePreTargetHandler(
+ menu_event_filter_.get());
+ menu_event_filter_->ClearDelegate();
+
#if !defined(OS_WIN)
// Ask PlatformEventSource to stop dispatching events in this message loop
// iteration. We want our menu's loop to return before the next event.

Powered by Google App Engine
This is Rietveld 408576698