summaryrefslogtreecommitdiffstats
path: root/views/focus
diff options
context:
space:
mode:
authordmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-24 18:36:03 +0000
committerdmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-24 18:36:03 +0000
commit84e8bdeaaf5c35c0e55dd9eca21422e7bfdc588f (patch)
treef6acb0420c94ea6a6990cedf68ef563bab0445a3 /views/focus
parent55098791c5380e4cc3a9be4de11c1b5fa23c8140 (diff)
downloadchromium_src-84e8bdeaaf5c35c0e55dd9eca21422e7bfdc588f.zip
chromium_src-84e8bdeaaf5c35c0e55dd9eca21422e7bfdc588f.tar.gz
chromium_src-84e8bdeaaf5c35c0e55dd9eca21422e7bfdc588f.tar.bz2
Keyboard accessibility for the page and app menus.
Works on Windows, and on Linux with toolkit_views. The goal is to make Chrome behave more like a standard Windows application, for users who rely on the keyboard and expect standard keyboard accelerators to work. Pressing F10, or pressing and releasing Alt, will set focus to the Page menu, as if it was the first item in a menu bar. Pressing enter, space, up arrow, or down arrow will open the focused menu. Once a menu is opened, pressing left and right arrows will switch between the two menus. Pressing escape will return focus to the title of the previously open menu. A new UI test attempts to select something from the menus using only the keyboard. It works on Linux (with toolkit_views) and on Windows. BUG=none TEST=New keyboard accessibility interactive ui test. Review URL: http://codereview.chromium.org/660323 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42498 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/focus')
-rw-r--r--views/focus/accelerator_handler_gtk.cc19
-rw-r--r--views/focus/focus_manager.h4
-rw-r--r--views/focus/focus_manager_gtk.cc6
-rw-r--r--views/focus/focus_manager_win.cc7
4 files changed, 35 insertions, 1 deletions
diff --git a/views/focus/accelerator_handler_gtk.cc b/views/focus/accelerator_handler_gtk.cc
index 1ff5d81..da7bd94 100644
--- a/views/focus/accelerator_handler_gtk.cc
+++ b/views/focus/accelerator_handler_gtk.cc
@@ -4,6 +4,9 @@
#include <gtk/gtk.h>
+#include "base/keyboard_code_conversion_gtk.h"
+#include "base/keyboard_codes.h"
+#include "views/accelerator.h"
#include "views/focus/accelerator_handler.h"
#include "views/focus/focus_manager.h"
#include "views/widget/widget_gtk.h"
@@ -48,6 +51,14 @@ bool AcceleratorHandler::Dispatch(GdkEvent* event) {
if (event->type == GDK_KEY_PRESS) {
KeyEvent view_key_event(key_event);
+
+ // If it's the Alt key, don't send it to the focus manager until release
+ // (to handle focusing the menu bar).
+ if (view_key_event.GetKeyCode() == base::VKEY_MENU) {
+ last_key_pressed_ = key_event->keyval;
+ return true;
+ }
+
// FocusManager::OnKeyPressed and OnKeyReleased return false if this
// message has been consumed and should not be propagated further.
if (!focus_manager->OnKeyEvent(view_key_event)) {
@@ -60,6 +71,14 @@ bool AcceleratorHandler::Dispatch(GdkEvent* event) {
// as accelerators to avoid unpaired key release.
if (event->type == GDK_KEY_RELEASE &&
key_event->keyval == last_key_pressed_) {
+ // Special case: the Alt key can trigger an accelerator on release
+ // rather than on press.
+ if (base::WindowsKeyCodeForGdkKeyCode(key_event->keyval) ==
+ base::VKEY_MENU) {
+ Accelerator accelerator(base::VKEY_MENU, false, false, false);
+ focus_manager->ProcessAccelerator(accelerator);
+ }
+
last_key_pressed_ = 0;
return true;
}
diff --git a/views/focus/focus_manager.h b/views/focus/focus_manager.h
index bad9dba..2150560 100644
--- a/views/focus/focus_manager.h
+++ b/views/focus/focus_manager.h
@@ -278,6 +278,10 @@ class FocusManager {
static FocusManager* GetFocusManagerForNativeView(
gfx::NativeView native_view);
+ // Retrieves the FocusManager associated with the passed native view.
+ static FocusManager* GetFocusManagerForNativeWindow(
+ gfx::NativeWindow native_window);
+
private:
// Returns the next focusable view.
View* GetNextFocusableView(View* starting_view, bool reverse, bool dont_loop);
diff --git a/views/focus/focus_manager_gtk.cc b/views/focus/focus_manager_gtk.cc
index 3038d93..a52a6d9 100644
--- a/views/focus/focus_manager_gtk.cc
+++ b/views/focus/focus_manager_gtk.cc
@@ -49,4 +49,10 @@ FocusManager* FocusManager::GetFocusManagerForNativeView(
return focus_manager;
}
+// static
+FocusManager* FocusManager::GetFocusManagerForNativeWindow(
+ gfx::NativeWindow native_window) {
+ return GetFocusManagerForNativeView(GTK_WIDGET(native_window));
+}
+
} // namespace views
diff --git a/views/focus/focus_manager_win.cc b/views/focus/focus_manager_win.cc
index fbccf7b..faf3815 100644
--- a/views/focus/focus_manager_win.cc
+++ b/views/focus/focus_manager_win.cc
@@ -27,5 +27,10 @@ FocusManager* FocusManager::GetFocusManagerForNativeView(
return widget ? widget->GetFocusManager() : NULL;
}
-} // namespace views
+// static
+FocusManager* FocusManager::GetFocusManagerForNativeWindow(
+ gfx::NativeWindow native_window) {
+ return GetFocusManagerForNativeView(native_window);
+}
+} // namespace views