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

Unified Diff: ash/accelerators/ash_menu_event_filter_delegate.cc

Issue 1138523006: Enable keyboard accelerators while a menu is open (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed tests errors. Created 5 years, 4 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: ash/accelerators/ash_menu_event_filter_delegate.cc
diff --git a/ash/accelerators/ash_menu_event_filter_delegate.cc b/ash/accelerators/ash_menu_event_filter_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..015f390778f271b7fc0970f3477105707d654cb1
--- /dev/null
+++ b/ash/accelerators/ash_menu_event_filter_delegate.cc
@@ -0,0 +1,65 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/accelerators/ash_menu_event_filter_delegate.h"
+
+#include "ash/accelerators/accelerator_controller.h"
+#include "ash/shell.h"
+#include "ash/wm/window_util.h"
+#include "ui/aura/window.h"
+#include "ui/views/controls/menu/menu_event_filter.h"
+#include "ui/views/focus/focus_manager.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+
+AshMenuEventFilterDelegate::AshMenuEventFilterDelegate(
+ ui::AcceleratorHistory* history)
+ : accelerator_history_(history) {
+ DCHECK(history);
+}
+
+AshMenuEventFilterDelegate::~AshMenuEventFilterDelegate() {}
+
+void AshMenuEventFilterDelegate::StoreInHistory(
+ const ui::Accelerator& accelerator) {
+ accelerator_history_->StoreCurrentAccelerator(accelerator);
+}
+
+views::MenuEventFilter::Delegate::Result
+AshMenuEventFilterDelegate::ProcessAccelerator(
+ const ui::Accelerator& accelerator) {
+ ash::AcceleratorController* accelerator_controller =
+ ash::Shell::GetInstance()->accelerator_controller();
+ if (accelerator_controller->ShouldMenuBeKeptOpenForAccelerator(accelerator)) {
+ // Menu will be kept open and accelerator will be handled now.
+ ProcessAcceleratorNow(accelerator);
+ return views::MenuEventFilter::Delegate::RESULT_PROCESSED;
+ }
+
+ // Menu should be closed and the accelerator should be reposted for processing
+ // later by the MenuEventFilter after the menu's nested runloop exits.
+ return views::MenuEventFilter::Delegate::RESULT_PROCESS_LATER;
+}
+
+void AshMenuEventFilterDelegate::ProcessAcceleratorNow(
+ const ui::Accelerator& accelerator) {
+ aura::Window* active_window = ash::wm::GetActiveWindow();
+ if (active_window) {
+ views::Widget* widget =
+ views::Widget::GetWidgetForNativeWindow(active_window);
+ if (widget) {
+ views::FocusManager* focus_manager = widget->GetFocusManager();
+ DCHECK(focus_manager);
+ if (focus_manager->ProcessAccelerator(accelerator))
pkotwicz 2015/08/26 01:26:54 What's the thinking behind calling FocusManager::P
afakhry 2015/08/26 18:39:21 Exactly. I did this after a discussion with Oshima
oshima 2015/09/02 17:08:21 The whole point of this work is that an accelerato
+ return;
+ }
+ }
+
+ ash::AcceleratorController* accelerator_controller =
+ ash::Shell::GetInstance()->accelerator_controller();
+ accelerator_controller->Process(accelerator);
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698