summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-29 00:33:35 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-29 00:33:35 +0000
commitbc1407f95bae3d7472ee0c85ef83ee10610b3f1f (patch)
treeeeb1e01423fefc13afe5738d809df200b5e50623
parent62525634a6f5727216828f8e05a4f563be90dfeb (diff)
downloadchromium_src-bc1407f95bae3d7472ee0c85ef83ee10610b3f1f.zip
chromium_src-bc1407f95bae3d7472ee0c85ef83ee10610b3f1f.tar.gz
chromium_src-bc1407f95bae3d7472ee0c85ef83ee10610b3f1f.tar.bz2
Relanding keyboard code refactoring:
http://codereview.chromium.org/248010/show Changing the KeyboardEvent to use a KeyboardCode instead of a w_char. Led to several places where I had to switch from VK_ to VKEY_. Also cleaned-up the table view OnKeyDown method. Since TableView is a NativeControl it can use the NativeControl::OnKeyDown directly. BUG=None TEST=Make sure short-cuts works as expected, especially in the omnibox. Review URL: http://codereview.chromium.org/251020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27444 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xbase/keyboard_code_conversion_gtk.cc8
-rwxr-xr-xbase/keyboard_code_conversion_gtk.h4
-rw-r--r--base/win_util.cc8
-rw-r--r--base/win_util.h6
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc7
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc30
-rw-r--r--chrome/browser/automation/automation_provider.cc5
-rw-r--r--chrome/browser/automation/automation_provider.h2
-rw-r--r--chrome/browser/automation/automation_provider_win.cc3
-rw-r--r--chrome/browser/automation/ui_controls.h18
-rw-r--r--chrome/browser/automation/ui_controls_linux.cc15
-rw-r--r--chrome/browser/automation/ui_controls_win.cc36
-rw-r--r--chrome/browser/views/accelerator_table_gtk.h4
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc3
-rw-r--r--chrome/browser/views/find_bar_host_browsertest.cc3
-rw-r--r--chrome/browser/views/find_bar_host_interactive_uitest.cc3
-rw-r--r--chrome/browser/views/frame/browser_view.cc12
-rw-r--r--chrome/browser/views/fullscreen_exit_bubble.cc3
-rw-r--r--chrome/browser/views/info_bubble.cc3
-rw-r--r--chrome/browser/views/jsmessage_box_dialog.cc3
-rw-r--r--chrome/browser/views/location_bar_view.cc2
-rw-r--r--chrome/browser/views/star_toggle.cc4
-rw-r--r--chrome/browser/views/tab_contents/render_view_context_menu_win.cc14
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_view_gtk.cc7
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_view_win.cc5
-rw-r--r--chrome/browser/views/task_manager_view.cc5
-rw-r--r--chrome/browser/views/toolbar_view.cc8
-rw-r--r--chrome/browser/views/url_picker.cc3
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_tests.cc3
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_tests.h3
-rw-r--r--chrome/test/automation/automation_messages_internal.h4
-rw-r--r--chrome/test/automation/window_proxy.cc2
-rw-r--r--chrome/test/automation/window_proxy.h11
-rw-r--r--chrome/test/interactive_ui/npapi_interactive_test.cc3
-rw-r--r--chrome/test/ui/npapi_uitest.cc3
-rw-r--r--views/accelerator.h7
-rw-r--r--views/controls/button/custom_button.cc6
-rw-r--r--views/controls/button/menu_button.cc3
-rw-r--r--views/controls/button/native_button.cc10
-rw-r--r--views/controls/combobox/combobox.cc4
-rw-r--r--views/controls/link.cc8
-rw-r--r--views/controls/menu/menu_win.cc3
-rw-r--r--views/controls/menu/native_menu_gtk.cc3
-rw-r--r--views/controls/menu/native_menu_win.cc3
-rw-r--r--views/controls/native_control.cc5
-rw-r--r--views/controls/native_control.h3
-rw-r--r--views/controls/scrollbar/bitmap_scroll_bar.cc19
-rw-r--r--views/controls/scrollbar/native_scroll_bar_win.cc19
-rw-r--r--views/controls/table/group_table_view.cc25
-rw-r--r--views/controls/table/group_table_view.h2
-rw-r--r--views/controls/table/table_view.cc12
-rw-r--r--views/controls/table/table_view.h6
-rw-r--r--views/controls/table/table_view_observer.h2
-rw-r--r--views/controls/textfield/native_textfield_win.cc7
-rw-r--r--views/controls/textfield/textfield.cc9
-rw-r--r--views/controls/tree/tree_view.cc7
-rw-r--r--views/controls/tree/tree_view.h3
-rw-r--r--views/event.h12
-rw-r--r--views/event_gtk.cc2
-rw-r--r--views/event_win.cc7
-rw-r--r--views/focus/accelerator_handler_win.cc4
-rw-r--r--views/focus/focus_manager.cc6
-rw-r--r--views/view_unittest.cc6
-rw-r--r--views/widget/root_view.cc4
-rw-r--r--views/widget/widget_win.cc6
65 files changed, 265 insertions, 201 deletions
diff --git a/base/keyboard_code_conversion_gtk.cc b/base/keyboard_code_conversion_gtk.cc
index b280d40..b56461f 100755
--- a/base/keyboard_code_conversion_gtk.cc
+++ b/base/keyboard_code_conversion_gtk.cc
@@ -44,7 +44,7 @@
namespace base {
-int WindowsKeyCodeForGdkKeyCode(int keycode) {
+base::KeyboardCode WindowsKeyCodeForGdkKeyCode(int keycode) {
switch (keycode) {
case GDK_KP_0:
return VKEY_NUMPAD0; // (60) Numeric keypad 0 key
@@ -404,14 +404,14 @@ int WindowsKeyCodeForGdkKeyCode(int keycode) {
case GDK_F22:
case GDK_F23:
case GDK_F24:
- return VKEY_F1 + (keycode - GDK_F1);
+ return static_cast<base::KeyboardCode>(VKEY_F1 + (keycode - GDK_F1));
default:
- return 0;
+ return VKEY_UNKNOWN;
}
}
// TODO(jcampan): this method might be incomplete.
-int GdkKeyCodeForWindowsKeyCode(int keycode) {
+int GdkKeyCodeForWindowsKeyCode(base::KeyboardCode keycode) {
switch (keycode) {
case VKEY_NUMPAD0:
return GDK_KP_0;
diff --git a/base/keyboard_code_conversion_gtk.h b/base/keyboard_code_conversion_gtk.h
index 9fd3b11..1f1e3b6 100755
--- a/base/keyboard_code_conversion_gtk.h
+++ b/base/keyboard_code_conversion_gtk.h
@@ -40,9 +40,9 @@
namespace base {
-int WindowsKeyCodeForGdkKeyCode(int keycode);
+base::KeyboardCode WindowsKeyCodeForGdkKeyCode(int keycode);
-int GdkKeyCodeForWindowsKeyCode(int keycode);
+int GdkKeyCodeForWindowsKeyCode(base::KeyboardCode keycode);
} // namespace
diff --git a/base/win_util.cc b/base/win_util.cc
index 37fc1ae..4fa1df0 100644
--- a/base/win_util.cc
+++ b/base/win_util.cc
@@ -373,6 +373,14 @@ std::wstring FormatLastWin32Error() {
return FormatMessage(GetLastError());
}
+WORD KeyboardCodeToWin(base::KeyboardCode keycode) {
+ return static_cast<WORD>(keycode);
+}
+
+base::KeyboardCode WinToKeyboardCode(WORD keycode) {
+ return static_cast<base::KeyboardCode>(keycode);
+}
+
} // namespace win_util
#ifdef _MSC_VER
diff --git a/base/win_util.h b/base/win_util.h
index e628bd7..307eddb 100644
--- a/base/win_util.h
+++ b/base/win_util.h
@@ -10,6 +10,8 @@
#include <string>
+#include "base/keyboard_codes.h"
+
namespace win_util {
// NOTE: Keep these in order so callers can do things like
@@ -104,6 +106,10 @@ std::wstring FormatMessage(unsigned messageid);
// Uses the last Win32 error to generate a human readable message string.
std::wstring FormatLastWin32Error();
+// Methods to convert base::KeyboardCode/Windows virtual key type methods.
+WORD KeyboardCodeToWin(base::KeyboardCode keycode);
+base::KeyboardCode WinToKeyboardCode(WORD keycode);
+
} // namespace win_util
#endif // BASE_WIN_UTIL_H__
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc
index f6e4f13..e87ae0c 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc
@@ -121,7 +121,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest,
ASSERT_TRUE(*edit_view);
}
- void SendKey(wchar_t key, bool control, bool shift, bool alt) {
+ void SendKey(base::KeyboardCode key, bool control, bool shift, bool alt) {
gfx::NativeWindow window = NULL;
ASSERT_NO_FATAL_FAILURE(GetNativeWindow(&window));
ui_controls::SendKeyPressNotifyWhenDone(window, key, control, shift, alt,
@@ -131,7 +131,8 @@ class AutocompleteEditViewTest : public InProcessBrowserTest,
void SendKeySequence(const wchar_t* keys) {
for (; *keys; ++keys)
- ASSERT_NO_FATAL_FAILURE(SendKey(*keys, false, false, false));
+ ASSERT_NO_FATAL_FAILURE(SendKey(static_cast<base::KeyboardCode>(*keys),
+ false, false, false));
}
void WaitForTabOpenOrClose(int expected_tab_count) {
@@ -144,7 +145,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest,
(tab_count < expected_tab_count ?
NotificationType::TAB_PARENTED :
NotificationType::TAB_CLOSED),
- NotificationService::AllSources());
+ NotificationService::AllSources());
while (!HasFailure() && browser()->tab_count() != expected_tab_count)
ui_test_utils::RunMessageLoop();
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index 1fc89f4..91ea6b1 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -17,6 +17,7 @@
#include "base/basictypes.h"
#include "base/clipboard.h"
#include "base/iat_patch.h"
+#include "base/keyboard_codes.h"
#include "base/lazy_instance.h"
#include "base/ref_counted.h"
#include "base/scoped_clipboard_writer.h"
@@ -876,11 +877,11 @@ void AutocompleteEditViewWin::PasteAndGo(const std::wstring& text) {
bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing(
const views::KeyEvent& e) {
- int c = e.GetCharacter();
+ base::KeyboardCode key = e.GetKeyCode();
// We don't process ALT + numpad digit as accelerators, they are used for
// entering special characters. We do translate alt-home.
- if (e.IsAltDown() && (c != VK_HOME) &&
- win_util::IsNumPadDigit(c, e.IsExtendedKey()))
+ if (e.IsAltDown() && (key != base::VKEY_HOME) &&
+ win_util::IsNumPadDigit(key, e.IsExtendedKey()))
return true;
// Skip accelerators for key combinations omnibox wants to crack. This list
@@ -890,30 +891,29 @@ bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing(
// We cannot return true for all keys because we still need to handle some
// accelerators (e.g., F5 for reload the page should work even when the
// Omnibox gets focused).
- switch (c) {
- case VK_ESCAPE: {
+ switch (key) {
+ case base::VKEY_ESCAPE: {
ScopedFreeze freeze(this, GetTextObjectModel());
return model_->OnEscapeKeyPressed();
}
- case VK_RETURN:
+ case base::VKEY_RETURN:
return true;
- case VK_UP:
- case VK_DOWN:
+ case base::VKEY_UP:
+ case base::VKEY_DOWN:
return !e.IsAltDown();
- case VK_DELETE:
- case VK_INSERT:
+ case base::VKEY_DELETE:
+ case base::VKEY_INSERT:
return !e.IsAltDown() && e.IsShiftDown() && !e.IsControlDown();
- case 'X':
- case 'V':
+ case base::VKEY_X:
+ case base::VKEY_V:
return !e.IsAltDown() && e.IsControlDown();
- case VK_BACK:
- case 0xbb: // We don't use VK_OEM_PLUS in case the macro isn't defined.
- // (e.g., we don't have this symbol in embeded environment).
+ case base::VKEY_BACK:
+ case base::VKEY_OEM_PLUS:
return true;
default:
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index cdb7b6d..f93d39c 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -10,6 +10,7 @@
#include "app/message_box_flags.h"
#include "base/file_version_info.h"
#include "base/json_reader.h"
+#include "base/keyboard_codes.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/stl_util-inl.h"
@@ -828,14 +829,14 @@ void AutomationProvider::WindowSimulateClick(const IPC::Message& message,
void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message,
int handle,
- wchar_t key,
+ int key,
int flags) {
if (!window_tracker_->ContainsHandle(handle))
return;
gfx::NativeWindow window = window_tracker_->GetResource(handle);
// The key event is sent to whatever window is active.
- ui_controls::SendKeyPress(window, key,
+ ui_controls::SendKeyPress(window, static_cast<base::KeyboardCode>(key),
((flags & views::Event::EF_CONTROL_DOWN) ==
views::Event::EF_CONTROL_DOWN),
((flags & views::Event::EF_SHIFT_DOWN) ==
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index a376610..be11f91 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -174,7 +174,7 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
int flags);
void WindowSimulateKeyPress(const IPC::Message& message,
int handle,
- wchar_t key,
+ int key,
int flags);
void GetWindowBounds(int handle, gfx::Rect* bounds, bool* result);
void SetWindowBounds(int handle, const gfx::Rect& bounds, bool* result);
diff --git a/chrome/browser/automation/automation_provider_win.cc b/chrome/browser/automation/automation_provider_win.cc
index 9af097d..f226289 100644
--- a/chrome/browser/automation/automation_provider_win.cc
+++ b/chrome/browser/automation/automation_provider_win.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/automation/automation_provider.h"
+#include "base/keyboard_codes.h"
#include "chrome/browser/automation/ui_controls.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/external_tab_container.h"
@@ -233,7 +234,7 @@ void AutomationProvider::WindowSimulateDrag(int handle,
if (press_escape_en_route) {
// Press Escape.
- ui_controls::SendKeyPress(window, VK_ESCAPE,
+ ui_controls::SendKeyPress(window, base::VKEY_ESCAPE,
((flags & views::Event::EF_CONTROL_DOWN)
== views::Event::EF_CONTROL_DOWN),
((flags & views::Event::EF_SHIFT_DOWN) ==
diff --git a/chrome/browser/automation/ui_controls.h b/chrome/browser/automation/ui_controls.h
index 7a7a6d6..4613626 100644
--- a/chrome/browser/automation/ui_controls.h
+++ b/chrome/browser/automation/ui_controls.h
@@ -15,6 +15,7 @@
#include "base/gfx/native_widget_types.h"
#include "base/gfx/point.h"
+#include "base/keyboard_codes.h"
#if defined(TOOLKIT_VIEWS)
namespace views {
@@ -42,12 +43,17 @@ namespace ui_controls {
// these functions, so passing NULL is ok.
// Send a key press with/without modifier keys.
-// |key| should be a VKEY code as defined in base/keyboard_codes.h
-bool SendKeyPress(gfx::NativeWindow window, wchar_t key, bool control,
- bool shift, bool alt);
-bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, wchar_t key,
- bool control, bool shift,
- bool alt, Task* task);
+bool SendKeyPress(gfx::NativeWindow window,
+ base::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt);
+bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
+ base::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt,
+ Task* task);
// Simulate a mouse move. (x,y) are absolute screen coordinates.
bool SendMouseMove(long x, long y);
diff --git a/chrome/browser/automation/ui_controls_linux.cc b/chrome/browser/automation/ui_controls_linux.cc
index 738f566..544816b 100644
--- a/chrome/browser/automation/ui_controls_linux.cc
+++ b/chrome/browser/automation/ui_controls_linux.cc
@@ -150,7 +150,7 @@ void FakeAMouseMotionEvent(gint x, gint y) {
namespace ui_controls {
bool SendKeyPress(gfx::NativeWindow window,
- wchar_t key, bool control, bool shift, bool alt) {
+ base::KeyboardCode key, bool control, bool shift, bool alt) {
GdkWindow* event_window = NULL;
GtkWidget* grab_widget = gtk_grab_get_current();
if (grab_widget) {
@@ -197,9 +197,9 @@ bool SendKeyPress(gfx::NativeWindow window,
(shift ? GDK_SHIFT_MASK : 0) |
(alt ? GDK_MOD1_MASK : 0);
- key = base::GdkKeyCodeForWindowsKeyCode(key);
- rv = rv && SendKeyEvent(event_window, true, key, state);
- rv = rv && SendKeyEvent(event_window, false, key, state);
+ guint gdk_key = base::GdkKeyCodeForWindowsKeyCode(key);
+ rv = rv && SendKeyEvent(event_window, true, gdk_key, state);
+ rv = rv && SendKeyEvent(event_window, false, gdk_key, state);
if (alt) {
guint state = (control ? GDK_CONTROL_MASK : 0) |
@@ -218,9 +218,10 @@ bool SendKeyPress(gfx::NativeWindow window,
return rv;
}
-bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, wchar_t key,
- bool control, bool shift,
- bool alt, Task* task) {
+bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
+ base::KeyboardCode key,
+ bool control, bool shift, bool alt,
+ Task* task) {
int release_count = 1;
if (control)
release_count++;
diff --git a/chrome/browser/automation/ui_controls_win.cc b/chrome/browser/automation/ui_controls_win.cc
index 78b1acb..29ca089 100644
--- a/chrome/browser/automation/ui_controls_win.cc
+++ b/chrome/browser/automation/ui_controls_win.cc
@@ -4,8 +4,10 @@
#include "chrome/browser/automation/ui_controls.h"
+#include "base/keyboard_codes.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/win_util.h"
#include "base/ref_counted.h"
#include "base/task.h"
#include "views/view.h"
@@ -133,18 +135,18 @@ void InputDispatcher::NotifyTask() {
// Populate the INPUT structure with the appropriate keyboard event
// parameters required by SendInput
-bool FillKeyboardInput(wchar_t key, INPUT* input, bool key_up) {
+bool FillKeyboardInput(base::KeyboardCode key, INPUT* input, bool key_up) {
memset(input, 0, sizeof(INPUT));
input->type = INPUT_KEYBOARD;
- input->ki.wVk = static_cast<WORD>(key);
+ input->ki.wVk = win_util::KeyboardCodeToWin(key);
input->ki.dwFlags = key_up ? KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP :
- KEYEVENTF_EXTENDEDKEY;
+ KEYEVENTF_EXTENDEDKEY;
return true;
}
// Send a key event (up/down)
-bool SendKeyEvent(wchar_t key, bool up) {
+bool SendKeyEvent(base::KeyboardCode key, bool up) {
INPUT input = { 0 };
if (!FillKeyboardInput(key, &input, up))
@@ -156,7 +158,8 @@ bool SendKeyEvent(wchar_t key, bool up) {
return true;
}
-bool SendKeyPressImpl(wchar_t key, bool control, bool shift, bool alt,
+bool SendKeyPressImpl(base::KeyboardCode key,
+ bool control, bool shift, bool alt,
Task* task) {
scoped_refptr<InputDispatcher> dispatcher(
task ? new InputDispatcher(task, WM_KEYUP) : NULL);
@@ -165,19 +168,19 @@ bool SendKeyPressImpl(wchar_t key, bool control, bool shift, bool alt,
int i = 0;
if (control) {
- if (!FillKeyboardInput(VK_CONTROL, &input[i], false))
+ if (!FillKeyboardInput(base::VKEY_CONTROL, &input[i], false))
return false;
i++;
}
if (shift) {
- if (!FillKeyboardInput(VK_SHIFT, &input[i], false))
+ if (!FillKeyboardInput(base::VKEY_SHIFT, &input[i], false))
return false;
i++;
}
if (alt) {
- if (!FillKeyboardInput(VK_MENU, &input[i], false))
+ if (!FillKeyboardInput(base::VKEY_MENU, &input[i], false))
return false;
i++;
}
@@ -191,19 +194,19 @@ bool SendKeyPressImpl(wchar_t key, bool control, bool shift, bool alt,
i++;
if (alt) {
- if (!FillKeyboardInput(VK_MENU, &input[i], true))
+ if (!FillKeyboardInput(base::VKEY_MENU, &input[i], true))
return false;
i++;
}
if (shift) {
- if (!FillKeyboardInput(VK_SHIFT, &input[i], true))
+ if (!FillKeyboardInput(base::VKEY_SHIFT, &input[i], true))
return false;
i++;
}
if (control) {
- if (!FillKeyboardInput(VK_CONTROL, &input[i], true))
+ if (!FillKeyboardInput(base::VKEY_CONTROL, &input[i], true))
return false;
i++;
}
@@ -304,14 +307,15 @@ bool SendMouseEventsImpl(MouseButton type, int state, Task* task) {
// public functions -----------------------------------------------------------
-bool SendKeyPress(gfx::NativeWindow window, wchar_t key, bool control,
- bool shift, bool alt) {
+bool SendKeyPress(gfx::NativeWindow window, base::KeyboardCode key,
+ bool control, bool shift, bool alt) {
return SendKeyPressImpl(key, control, shift, alt, NULL);
}
-bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, wchar_t key,
- bool control, bool shift,
- bool alt, Task* task) {
+bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
+ base::KeyboardCode key,
+ bool control, bool shift, bool alt,
+ Task* task) {
return SendKeyPressImpl(key, control, shift, alt, task);
}
diff --git a/chrome/browser/views/accelerator_table_gtk.h b/chrome/browser/views/accelerator_table_gtk.h
index 29f7588..78e161f 100644
--- a/chrome/browser/views/accelerator_table_gtk.h
+++ b/chrome/browser/views/accelerator_table_gtk.h
@@ -7,12 +7,14 @@
#include <stdio.h>
+#include "base/keyboard_codes.h"
+
// This contains the list of accelerators for the Linux toolkit_view
// implementation.
namespace browser {
struct AcceleratorMapping {
- int keycode;
+ base::KeyboardCode keycode;
bool shift_pressed;
bool ctrl_pressed;
bool alt_pressed;
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index 313bc09..60ec1b9 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -9,6 +9,7 @@
#include "app/gfx/canvas.h"
#include "app/gfx/color_utils.h"
#include "app/l10n_util.h"
+#include "base/keyboard_codes.h"
#include "base/thread.h"
#include "chrome/browser/bookmarks/bookmark_folder_tree_model.h"
#include "chrome/browser/bookmarks/bookmark_html_writer.h"
@@ -225,7 +226,7 @@ BookmarkManagerView::BookmarkManagerView(Profile* profile)
layout->AddView(split_view_);
// Press Ctrl-W to close bookmark manager window.
- AddAccelerator(views::Accelerator('W', false, true, false));
+ AddAccelerator(views::Accelerator(base::VKEY_W, false, true, false));
BookmarkModel* bookmark_model = profile_->GetBookmarkModel();
if (!bookmark_model->IsLoaded())
diff --git a/chrome/browser/views/find_bar_host_browsertest.cc b/chrome/browser/views/find_bar_host_browsertest.cc
index 703a401..caed556 100644
--- a/chrome/browser/views/find_bar_host_browsertest.cc
+++ b/chrome/browser/views/find_bar_host_browsertest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/keyboard_codes.h"
#include "base/message_loop.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
@@ -590,7 +591,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) {
views::FocusManager::GetFocusManagerForNativeView(browser_view);
// See where Escape is registered.
- views::Accelerator escape(VK_ESCAPE, false, false, false);
+ views::Accelerator escape(base::VKEY_ESCAPE, false, false, false);
views::AcceleratorTarget* old_target =
focus_manager->GetCurrentTargetForAccelerator(escape);
EXPECT_TRUE(old_target != NULL);
diff --git a/chrome/browser/views/find_bar_host_interactive_uitest.cc b/chrome/browser/views/find_bar_host_interactive_uitest.cc
index 75f10d5..fe2cecd 100644
--- a/chrome/browser/views/find_bar_host_interactive_uitest.cc
+++ b/chrome/browser/views/find_bar_host_interactive_uitest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
+#include "base/keyboard_codes.h"
#include "chrome/browser/view_ids.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/window_proxy.h"
@@ -90,6 +91,6 @@ TEST_F(FindInPageTest, CrashEscHandlers) {
EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id);
// This used to crash until bug 1303709 was fixed.
- EXPECT_TRUE(window->SimulateOSKeyPress(VK_ESCAPE, 0));
+ EXPECT_TRUE(window->SimulateOSKeyPress(base::VKEY_ESCAPE, 0));
::Sleep(kActionDelayMs);
}
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index d4a0e8f..50fd3bd 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -10,6 +10,7 @@
#include "app/os_exchange_data.h"
#include "app/resource_bundle.h"
#include "base/command_line.h"
+#include "base/keyboard_codes.h"
#include "base/time.h"
#include "build/build_config.h"
#include "chrome/app/chrome_dll_resource.h"
@@ -585,13 +586,13 @@ bool BrowserView::GetAccelerator(int cmd_id, views::Accelerator* accelerator) {
// anywhere so we need to check for them explicitly here.
switch (cmd_id) {
case IDC_CUT:
- *accelerator = views::Accelerator(L'X', false, true, false);
+ *accelerator = views::Accelerator(base::VKEY_X, false, true, false);
return true;
case IDC_COPY:
- *accelerator = views::Accelerator(L'C', false, true, false);
+ *accelerator = views::Accelerator(base::VKEY_C, false, true, false);
return true;
case IDC_PASTE:
- *accelerator = views::Accelerator(L'V', false, true, false);
+ *accelerator = views::Accelerator(base::VKEY_V, false, true, false);
return true;
}
// Else, we retrieve the accelerator information from the accelerator table.
@@ -1993,8 +1994,9 @@ void BrowserView::LoadAccelerators() {
bool alt_down = (accelerators[i].fVirt & FALT) == FALT;
bool ctrl_down = (accelerators[i].fVirt & FCONTROL) == FCONTROL;
bool shift_down = (accelerators[i].fVirt & FSHIFT) == FSHIFT;
- views::Accelerator accelerator(accelerators[i].key, shift_down, ctrl_down,
- alt_down);
+ views::Accelerator accelerator(
+ static_cast<base::KeyboardCode>(accelerators[i].key),
+ shift_down, ctrl_down, alt_down);
accelerator_table_[accelerator] = accelerators[i].cmd;
// Also register with the focus manager.
diff --git a/chrome/browser/views/fullscreen_exit_bubble.cc b/chrome/browser/views/fullscreen_exit_bubble.cc
index 907a791..b7e5705 100644
--- a/chrome/browser/views/fullscreen_exit_bubble.cc
+++ b/chrome/browser/views/fullscreen_exit_bubble.cc
@@ -8,6 +8,7 @@
#include "app/l10n_util.h"
#include "app/l10n_util_win.h"
#include "app/resource_bundle.h"
+#include "base/keyboard_codes.h"
#include "chrome/app/chrome_dll_resource.h"
#include "grit/generated_resources.h"
#include "views/widget/root_view.h"
@@ -133,7 +134,7 @@ FullscreenExitBubble::FullscreenExitBubble(
size_animation_->Reset(1);
// Create the contents view.
- views::Accelerator accelerator(0, false, false, false);
+ views::Accelerator accelerator(base::VKEY_UNKNOWN, false, false, false);
bool got_accelerator = frame->GetAccelerator(IDC_FULLSCREEN, &accelerator);
DCHECK(got_accelerator);
view_ = new FullscreenExitView(this, popup_, accelerator.GetShortcutText());
diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc
index 40244ef..91a41a4 100644
--- a/chrome/browser/views/info_bubble.cc
+++ b/chrome/browser/views/info_bubble.cc
@@ -7,6 +7,7 @@
#include "app/gfx/canvas.h"
#include "app/gfx/color_utils.h"
#include "app/gfx/path.h"
+#include "base/keyboard_codes.h"
#include "chrome/browser/window_sizer.h"
#include "chrome/common/notification_service.h"
#include "third_party/skia/include/core/SkPaint.h"
@@ -278,7 +279,7 @@ void InfoBubble::Init(views::Window* parent,
#if defined(OS_WIN)
// Register the Escape accelerator for closing.
GetFocusManager()->RegisterAccelerator(
- views::Accelerator(VK_ESCAPE, false, false, false), this);
+ views::Accelerator(base::VKEY_ESCAPE, false, false, false), this);
#endif
// Done creating the bubble.
diff --git a/chrome/browser/views/jsmessage_box_dialog.cc b/chrome/browser/views/jsmessage_box_dialog.cc
index df60f0f9..3fb70e0 100644
--- a/chrome/browser/views/jsmessage_box_dialog.cc
+++ b/chrome/browser/views/jsmessage_box_dialog.cc
@@ -6,6 +6,7 @@
#include "app/l10n_util.h"
#include "app/message_box_flags.h"
+#include "base/keyboard_codes.h"
#include "chrome/browser/app_modal_dialog.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "grit/generated_resources.h"
@@ -25,7 +26,7 @@ JavascriptMessageBoxDialog::JavascriptMessageBoxDialog(
DCHECK(message_box_view_);
message_box_view_->AddAccelerator(
- views::Accelerator('C', false, true, false));
+ views::Accelerator(base::VKEY_C, false, true, false));
if (display_suppress_checkbox) {
message_box_view_->SetCheckBoxLabel(
l10n_util::GetString(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION));
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index 35503a0..ee8eb90 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -966,7 +966,7 @@ bool LocationBarView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
// it can be shared between Windows and Linux.
// For now, we just override back-space as it is the accelerator for back
// navigation.
- if (e.GetCharacter() == base::VKEY_BACK)
+ if (e.GetKeyCode() == base::VKEY_BACK)
return true;
return false;
#endif
diff --git a/chrome/browser/views/star_toggle.cc b/chrome/browser/views/star_toggle.cc
index 0e03f91..ebb67ac 100644
--- a/chrome/browser/views/star_toggle.cc
+++ b/chrome/browser/views/star_toggle.cc
@@ -6,6 +6,7 @@
#include "app/gfx/canvas.h"
#include "app/resource_bundle.h"
+#include "base/keyboard_codes.h"
#include "chrome/app/chrome_dll_resource.h"
#include "grit/theme_resources.h"
@@ -63,7 +64,8 @@ void StarToggle::OnMouseReleased(const views::MouseEvent& e,
}
bool StarToggle::OnKeyPressed(const views::KeyEvent& e) {
- if ((e.GetCharacter() == VK_SPACE) || (e.GetCharacter() == VK_RETURN)) {
+ if ((e.GetKeyCode() == base::VKEY_SPACE) ||
+ (e.GetKeyCode() == base::VKEY_RETURN)) {
SwitchState();
return true;
}
diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_win.cc b/chrome/browser/views/tab_contents/render_view_context_menu_win.cc
index 63bbca6..a46174a 100644
--- a/chrome/browser/views/tab_contents/render_view_context_menu_win.cc
+++ b/chrome/browser/views/tab_contents/render_view_context_menu_win.cc
@@ -6,6 +6,7 @@
#include "app/l10n_util.h"
#include "base/compiler_specific.h"
+#include "base/keyboard_codes.h"
#include "chrome/browser/profile.h"
#include "grit/generated_resources.h"
@@ -46,27 +47,28 @@ bool RenderViewContextMenuWin::GetAcceleratorForCommandId(
// that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do.
switch (command_id) {
case IDS_CONTENT_CONTEXT_UNDO:
- *accel = views::Accelerator(L'Z', false, true, false);
+ *accel = views::Accelerator(base::VKEY_Z, false, true, false);
return true;
case IDS_CONTENT_CONTEXT_REDO:
- *accel = views::Accelerator(L'Z', true, true, false);
+ // TODO(jcampan): should it be Ctrl-Y?
+ *accel = views::Accelerator(base::VKEY_Z, true, true, false);
return true;
case IDS_CONTENT_CONTEXT_CUT:
- *accel = views::Accelerator(L'X', false, true, false);
+ *accel = views::Accelerator(base::VKEY_X, false, true, false);
return true;
case IDS_CONTENT_CONTEXT_COPY:
- *accel = views::Accelerator(L'C', false, true, false);
+ *accel = views::Accelerator(base::VKEY_C, false, true, false);
return true;
case IDS_CONTENT_CONTEXT_PASTE:
- *accel = views::Accelerator(L'V', false, true, false);
+ *accel = views::Accelerator(base::VKEY_V, false, true, false);
return true;
case IDS_CONTENT_CONTEXT_SELECTALL:
- *accel = views::Accelerator(L'A', false, true, false);
+ *accel = views::Accelerator(base::VKEY_A, false, true, false);
return true;
default:
diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc
index dbc7c26..8212bcf 100644
--- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc
+++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc
@@ -310,10 +310,9 @@ void TabContentsViewGtk::HandleKeyboardEvent(
bool alt_pressed = (event.modifiers & WebInputEvent::AltKey) ==
WebInputEvent::AltKey;
- focus_manager->ProcessAccelerator(views::Accelerator(event.windowsKeyCode,
- shift_pressed,
- ctrl_pressed,
- alt_pressed));
+ focus_manager->ProcessAccelerator(
+ views::Accelerator(static_cast<base::KeyboardCode>(event.windowsKeyCode),
+ shift_pressed, ctrl_pressed, alt_pressed));
// DANGER: |this| could be deleted now!
// Note that we do not handle Gtk mnemonics/accelerators or binding set here
diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc
index 22a1552..7352951 100644
--- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc
+++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc
@@ -9,7 +9,9 @@
#include "app/gfx/canvas_paint.h"
#include "app/os_exchange_data.h"
#include "app/os_exchange_data_provider_win.h"
+#include "base/keyboard_codes.h"
#include "base/time.h"
+#include "base/win_util.h"
#include "chrome/browser/bookmarks/bookmark_drag_data.h"
#include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
#include "chrome/browser/browser_process.h"
@@ -403,7 +405,8 @@ void TabContentsViewWin::HandleKeyboardEvent(
// We may not have a focus_manager at this point (if the tab has been
// switched by the time this message returned).
if (focus_manager) {
- views::Accelerator accelerator(event.windowsKeyCode,
+ views::Accelerator accelerator(
+ win_util::WinToKeyboardCode(event.windowsKeyCode),
(event.modifiers & WebInputEvent::ShiftKey) ==
WebInputEvent::ShiftKey,
(event.modifiers & WebInputEvent::ControlKey) ==
diff --git a/chrome/browser/views/task_manager_view.cc b/chrome/browser/views/task_manager_view.cc
index 5256b03..b41fbe1 100644
--- a/chrome/browser/views/task_manager_view.cc
+++ b/chrome/browser/views/task_manager_view.cc
@@ -334,7 +334,8 @@ void TaskManagerView::Init() {
SetContextMenuController(this);
kill_button_ = new views::NativeButton(
this, l10n_util::GetString(IDS_TASK_MANAGER_KILL));
- kill_button_->AddAccelerator(views::Accelerator('E', false, false, false));
+ kill_button_->AddAccelerator(views::Accelerator(base::VKEY_E,
+ false, false, false));
kill_button_->SetAccessibleKeyboardShortcut(L"E");
about_memory_link_ = new views::Link(
l10n_util::GetString(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK));
@@ -535,7 +536,7 @@ void TaskManagerView::OnDoubleClick() {
}
void TaskManagerView::OnKeyDown(unsigned short virtual_keycode) {
- if (virtual_keycode == VK_RETURN)
+ if (virtual_keycode == base::VKEY_RETURN)
ActivateFocusedTab();
}
diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc
index bff1dc6..8ee898d 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -416,13 +416,13 @@ bool ToolbarView::GetAcceleratorForCommandId(int command_id,
// TODO(cpu) Bug 1109102. Query WebKit land for the actual bindings.
switch (command_id) {
case IDC_CUT:
- *accelerator = views::Accelerator(L'X', false, true, false);
+ *accelerator = views::Accelerator(base::VKEY_X, false, true, false);
return true;
case IDC_COPY:
- *accelerator = views::Accelerator(L'C', false, true, false);
+ *accelerator = views::Accelerator(base::VKEY_C, false, true, false);
return true;
case IDC_PASTE:
- *accelerator = views::Accelerator(L'V', false, true, false);
+ *accelerator = views::Accelerator(base::VKEY_V, false, true, false);
return true;
}
// Else, we retrieve the accelerator information from the frame.
@@ -639,7 +639,7 @@ bool ToolbarView::OnKeyPressed(const views::KeyEvent& e) {
int focused_view = GetChildIndex(acc_focused_view_);
int next_view = focused_view;
- switch (e.GetCharacter()) {
+ switch (e.GetKeyCode()) {
case base::VKEY_LEFT:
next_view = GetNextAccessibleViewIndex(focused_view, true);
break;
diff --git a/chrome/browser/views/url_picker.cc b/chrome/browser/views/url_picker.cc
index e9837ff..5232676 100644
--- a/chrome/browser/views/url_picker.cc
+++ b/chrome/browser/views/url_picker.cc
@@ -8,6 +8,7 @@
#include "app/resource_bundle.h"
#include "app/table_model.h"
#include "app/table_model_observer.h"
+#include "base/keyboard_codes.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "chrome/browser/net/url_fixer_upper.h"
@@ -130,7 +131,7 @@ UrlPicker::UrlPicker(UrlPickerDelegate* delegate,
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
- AddAccelerator(views::Accelerator(VK_RETURN, false, false, false));
+ AddAccelerator(views::Accelerator(base::VKEY_RETURN, false, false, false));
}
UrlPicker::~UrlPicker() {
diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc
index 252689c..fd22151 100644
--- a/chrome/test/automated_ui_tests/automated_ui_tests.cc
+++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc
@@ -607,7 +607,8 @@ bool AutomatedUITest::ForceCrash() {
return true;
}
-bool AutomatedUITest::SimulateKeyPressInActiveWindow(wchar_t key, int flags) {
+bool AutomatedUITest::SimulateKeyPressInActiveWindow(base::KeyboardCode key,
+ int flags) {
scoped_refptr<WindowProxy> window(automation()->GetActiveWindow());
if (window.get() == NULL) {
AddErrorAttribute("active_window_not_found");
diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.h b/chrome/test/automated_ui_tests/automated_ui_tests.h
index d370b70..286234a 100644
--- a/chrome/test/automated_ui_tests/automated_ui_tests.h
+++ b/chrome/test/automated_ui_tests/automated_ui_tests.h
@@ -102,6 +102,7 @@
#include <string>
+#include "base/keyboard_codes.h"
#include "chrome/test/automated_ui_tests/automated_ui_test_base.h"
#include "chrome/test/ui/ui_test.h"
@@ -293,7 +294,7 @@ class AutomatedUITest : public AutomatedUITestBase {
// Calls SimulateOSKeyPress on the active window. Simulates a key press at
// the OS level. |key| is the key pressed and |flags| specifies which
// modifiers keys are also pressed (as defined in chrome/views/event.h).
- bool SimulateKeyPressInActiveWindow(wchar_t key, int flags);
+ bool SimulateKeyPressInActiveWindow(base::KeyboardCode key, int flags);
// Opens init file, reads it into the reader, and closes the file.
// Returns false if there are any errors.
diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h
index e7016cf..89f90ff 100644
--- a/chrome/test/automation/automation_messages_internal.h
+++ b/chrome/test/automation/automation_messages_internal.h
@@ -415,10 +415,10 @@ IPC_BEGIN_MESSAGES(Automation)
// This message requests that a key press be performed.
// Request:
// int - the handle of the window that's the context for this click
- // wchar_t - char of the key that was pressed.
+ // int - the base::KeyboardCode of the key that was pressed.
// int - the flags which identify the modifiers (shift, ctrl, alt)
// associated for, as defined in chrome/views/event.h
- IPC_MESSAGE_ROUTED3(AutomationMsg_WindowKeyPress, int, wchar_t, int)
+ IPC_MESSAGE_ROUTED3(AutomationMsg_WindowKeyPress, int, int, int)
// This message notifies the AutomationProvider to create a tab which is
// hosted by an external process.
diff --git a/chrome/test/automation/window_proxy.cc b/chrome/test/automation/window_proxy.cc
index 5766259..5b08842 100644
--- a/chrome/test/automation/window_proxy.cc
+++ b/chrome/test/automation/window_proxy.cc
@@ -34,7 +34,7 @@ bool WindowProxy::GetWindowTitle(string16* text) {
return sender_->Send(new AutomationMsg_WindowTitle(0, handle_, text));
}
-bool WindowProxy::SimulateOSKeyPress(wchar_t key, int flags) {
+bool WindowProxy::SimulateOSKeyPress(base::KeyboardCode key, int flags) {
if (!is_valid()) return false;
return sender_->Send(
diff --git a/chrome/test/automation/window_proxy.h b/chrome/test/automation/window_proxy.h
index 539ac20..33a27c0 100644
--- a/chrome/test/automation/window_proxy.h
+++ b/chrome/test/automation/window_proxy.h
@@ -13,6 +13,7 @@
#include <string>
+#include "base/keyboard_codes.h"
#include "base/string16.h"
#include "base/thread.h"
#include "chrome/test/automation/automation_handle_tracker.h"
@@ -46,11 +47,11 @@ class WindowProxy : public AutomationResourceProxy {
// Get the title of the top level window.
bool GetWindowTitle(string16* text);
- // Simulates a key press at the OS level. |key| is the key pressed and
- // |flags| specifies which modifiers keys are also pressed (as defined in
- // chrome/views/event.h). Note that this actually sends the event to the
- // window that has focus.
- bool SimulateOSKeyPress(wchar_t key, int flags);
+ // Simulates a key press at the OS level. |key| is the virtual key code of the
+ // key pressed and |flags| specifies which modifiers keys are also pressed (as
+ // defined in chrome/views/event.h). Note that this actually sends the event
+ // to the window that has focus.
+ bool SimulateOSKeyPress(base::KeyboardCode key, int flags);
// Shows/hides the window and as a result makes it active/inactive.
// Returns true if the call was successful.
diff --git a/chrome/test/interactive_ui/npapi_interactive_test.cc b/chrome/test/interactive_ui/npapi_interactive_test.cc
index 49271a6..9610f39 100644
--- a/chrome/test/interactive_ui/npapi_interactive_test.cc
+++ b/chrome/test/interactive_ui/npapi_interactive_test.cc
@@ -32,6 +32,7 @@
//
#include "base/file_util.h"
+#include "base/keyboard_codes.h"
#include "chrome/browser/net/url_request_mock_http_job.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/automation/tab_proxy.h"
@@ -92,7 +93,7 @@ TEST_F(NPAPIVisiblePluginTester, GetURLRequest404Response) {
automation()->WaitForAppModalDialog(action_max_timeout_ms());
scoped_refptr<WindowProxy> window(automation()->GetActiveWindow());
ASSERT_TRUE(window.get());
- ASSERT_TRUE(window->SimulateOSKeyPress(VK_ESCAPE, 0));
+ ASSERT_TRUE(window->SimulateOSKeyPress(base::VKEY_ESCAPE, 0));
WaitForFinish("geturl_404_response", "1", url, kTestCompleteCookie,
kTestCompleteSuccess, kShortWaitTimeout);
diff --git a/chrome/test/ui/npapi_uitest.cc b/chrome/test/ui/npapi_uitest.cc
index 32139fa..ab43ca9 100644
--- a/chrome/test/ui/npapi_uitest.cc
+++ b/chrome/test/ui/npapi_uitest.cc
@@ -16,6 +16,7 @@
#include <ostream>
#include "base/file_util.h"
+#include "base/keyboard_codes.h"
#include "chrome/browser/net/url_request_mock_http_job.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/automation/tab_proxy.h"
@@ -138,7 +139,7 @@ TEST_F(NPAPITester, DISABLED_SelfDeletePluginInvokeAlert) {
automation()->WaitForAppModalDialog(5000);
scoped_refptr<WindowProxy> window(automation()->GetActiveWindow());
ASSERT_TRUE(window.get());
- ASSERT_TRUE(window->SimulateOSKeyPress(VK_ESCAPE, 0));
+ ASSERT_TRUE(window->SimulateOSKeyPress(base::VKEY_ESCAPE, 0));
WaitForFinish("self_delete_plugin_invoke_alert", "1", url,
kTestCompleteCookie, kTestCompleteSuccess,
diff --git a/views/accelerator.h b/views/accelerator.h
index bb8f91f..1848c98 100644
--- a/views/accelerator.h
+++ b/views/accelerator.h
@@ -13,13 +13,14 @@
#include <string>
+#include "base/keyboard_codes.h"
#include "views/event.h"
namespace views {
class Accelerator {
public:
- Accelerator(int keycode,
+ Accelerator(base::KeyboardCode keycode,
bool shift_pressed, bool ctrl_pressed, bool alt_pressed)
: key_code_(keycode) {
modifiers_ = 0;
@@ -74,7 +75,7 @@ class Accelerator {
return (modifiers_ & Event::EF_ALT_DOWN) == Event::EF_ALT_DOWN;
}
- int GetKeyCode() const {
+ base::KeyboardCode GetKeyCode() const {
return key_code_;
}
@@ -83,7 +84,7 @@ class Accelerator {
private:
// The window keycode (VK_...).
- int key_code_;
+ base::KeyboardCode key_code_;
// The state of the Shift/Ctrl/Alt keys (see event.h).
int modifiers_;
diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc
index e507d93..348e527 100644
--- a/views/controls/button/custom_button.cc
+++ b/views/controls/button/custom_button.cc
@@ -175,10 +175,10 @@ bool CustomButton::OnKeyPressed(const KeyEvent& e) {
// Space sets button state to pushed. Enter clicks the button. This matches
// the Windows native behavior of buttons, where Space clicks the button
// on KeyRelease and Enter clicks the button on KeyPressed.
- if (e.GetCharacter() == base::VKEY_SPACE) {
+ if (e.GetKeyCode() == base::VKEY_SPACE) {
SetState(BS_PUSHED);
return true;
- } else if (e.GetCharacter() == base::VKEY_RETURN) {
+ } else if (e.GetKeyCode() == base::VKEY_RETURN) {
SetState(BS_NORMAL);
NotifyClick(e);
return true;
@@ -189,7 +189,7 @@ bool CustomButton::OnKeyPressed(const KeyEvent& e) {
bool CustomButton::OnKeyReleased(const KeyEvent& e) {
if (state_ != BS_DISABLED) {
- if (e.GetCharacter() == base::VKEY_SPACE) {
+ if (e.GetKeyCode() == base::VKEY_SPACE) {
SetState(BS_NORMAL);
NotifyClick(e);
return true;
diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc
index 25a415d..5b353f3 100644
--- a/views/controls/button/menu_button.cc
+++ b/views/controls/button/menu_button.cc
@@ -214,7 +214,8 @@ void MenuButton::OnMouseReleased(const MouseEvent& e,
// When the space bar or the enter key is pressed we need to show the menu.
bool MenuButton::OnKeyReleased(const KeyEvent& e) {
#if defined(OS_WIN)
- if ((e.GetCharacter() == VK_SPACE) || (e.GetCharacter() == VK_RETURN)) {
+ if ((e.GetKeyCode() == base::VKEY_SPACE) ||
+ (e.GetKeyCode() == base::VKEY_RETURN)) {
return Activate();
}
#else
diff --git a/views/controls/button/native_button.cc b/views/controls/button/native_button.cc
index e36719c..811fb56 100644
--- a/views/controls/button/native_button.cc
+++ b/views/controls/button/native_button.cc
@@ -10,6 +10,7 @@
#endif
#include "app/l10n_util.h"
+#include "base/keyboard_codes.h"
#include "base/logging.h"
namespace views {
@@ -73,17 +74,12 @@ void NativeButton::SetLabel(const std::wstring& label) {
}
void NativeButton::SetIsDefault(bool is_default) {
-#if defined(OS_WIN)
- int return_code = VK_RETURN;
-#else
- int return_code = GDK_Return;
-#endif
if (is_default == is_default_)
return;
if (is_default)
- AddAccelerator(Accelerator(return_code, false, false, false));
+ AddAccelerator(Accelerator(base::VKEY_RETURN, false, false, false));
else
- RemoveAccelerator(Accelerator(return_code, false, false, false));
+ RemoveAccelerator(Accelerator(base::VKEY_RETURN, false, false, false));
SetAppearsAsDefault(is_default);
}
diff --git a/views/controls/combobox/combobox.cc b/views/controls/combobox/combobox.cc
index 5c5596f..e184dcb 100644
--- a/views/controls/combobox/combobox.cc
+++ b/views/controls/combobox/combobox.cc
@@ -69,10 +69,10 @@ void Combobox::SetEnabled(bool flag) {
native_wrapper_->UpdateEnabled();
}
-// VK_ESCAPE should be handled by this view when the drop down list is active.
+// VKEY_ESCAPE should be handled by this view when the drop down list is active.
// In other words, the list should be closed instead of the dialog.
bool Combobox::SkipDefaultKeyEventProcessing(const KeyEvent& e) {
- if (e.GetCharacter() != base::VKEY_ESCAPE ||
+ if (e.GetKeyCode() != base::VKEY_ESCAPE ||
e.IsShiftDown() || e.IsControlDown() || e.IsAltDown()) {
return false;
}
diff --git a/views/controls/link.cc b/views/controls/link.cc
index f2887e0..6619568 100644
--- a/views/controls/link.cc
+++ b/views/controls/link.cc
@@ -10,6 +10,7 @@
#include "app/gfx/color_utils.h"
#include "app/gfx/font.h"
+#include "base/keyboard_codes.h"
#include "base/logging.h"
#include "views/event.h"
@@ -123,8 +124,8 @@ void Link::OnMouseReleased(const MouseEvent& e, bool canceled) {
bool Link::OnKeyPressed(const KeyEvent& e) {
#if defined(OS_WIN)
- bool activate = ((e.GetCharacter() == VK_SPACE) ||
- (e.GetCharacter() == VK_RETURN));
+ bool activate = ((e.GetKeyCode() == base::VKEY_SPACE) ||
+ (e.GetKeyCode() == base::VKEY_RETURN));
#else
bool activate = false;
NOTIMPLEMENTED();
@@ -146,7 +147,8 @@ bool Link::OnKeyPressed(const KeyEvent& e) {
bool Link::SkipDefaultKeyEventProcessing(const KeyEvent& e) {
#if defined(OS_WIN)
// Make sure we don't process space or enter as accelerators.
- return (e.GetCharacter() == VK_SPACE) || (e.GetCharacter() == VK_RETURN);
+ return (e.GetKeyCode() == base::VKEY_SPACE) ||
+ (e.GetKeyCode() == base::VKEY_RETURN);
#else
NOTIMPLEMENTED();
return false;
diff --git a/views/controls/menu/menu_win.cc b/views/controls/menu/menu_win.cc
index 68cc8ff..852304f 100644
--- a/views/controls/menu/menu_win.cc
+++ b/views/controls/menu/menu_win.cc
@@ -11,6 +11,7 @@
#include "app/l10n_util.h"
#include "app/l10n_util_win.h"
#include "base/gfx/rect.h"
+#include "base/keyboard_codes.h"
#include "base/logging.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
@@ -441,7 +442,7 @@ void MenuWin::AddMenuItemInternal(int index,
delegate()->GetLabel(item_id) : label);
// Find out if there is a shortcut we need to append to the label.
- views::Accelerator accelerator(0, false, false, false);
+ views::Accelerator accelerator(base::VKEY_UNKNOWN, false, false, false);
if (delegate() && delegate()->GetAcceleratorInfo(item_id, &accelerator)) {
actual_label += L'\t';
actual_label += accelerator.GetShortcutText();
diff --git a/views/controls/menu/native_menu_gtk.cc b/views/controls/menu/native_menu_gtk.cc
index 55e10ae..7bcb7b9 100644
--- a/views/controls/menu/native_menu_gtk.cc
+++ b/views/controls/menu/native_menu_gtk.cc
@@ -7,6 +7,7 @@
#include <string>
#include "base/gfx/gtk_util.h"
+#include "base/keyboard_codes.h"
#include "base/string_util.h"
#include "base/time.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -162,7 +163,7 @@ void NativeMenuGtk::AddMenuItemAt(int index,
submenu->GetNativeMenu());
}
- views::Accelerator accelerator(0, false, false, false);
+ views::Accelerator accelerator(base::VKEY_UNKNOWN, false, false, false);
if (model_->GetAcceleratorAt(index, &accelerator)) {
// TODO(beng): accelerators w/gtk_widget_add_accelerator.
}
diff --git a/views/controls/menu/native_menu_win.cc b/views/controls/menu/native_menu_win.cc
index f078d71..0af8a9af 100644
--- a/views/controls/menu/native_menu_win.cc
+++ b/views/controls/menu/native_menu_win.cc
@@ -8,6 +8,7 @@
#include "app/gfx/font.h"
#include "app/l10n_util.h"
#include "app/l10n_util_win.h"
+#include "base/keyboard_codes.h"
#include "base/logging.h"
#include "base/stl_util-inl.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -458,7 +459,7 @@ void NativeMenuWin::UpdateMenuItemInfoForString(
Menu2Model::ItemType type = model_->GetTypeAt(model_index);
if (type != Menu2Model::TYPE_SUBMENU) {
// Add accelerator details to the label if provided.
- views::Accelerator accelerator(0, false, false, false);
+ views::Accelerator accelerator(base::VKEY_UNKNOWN, false, false, false);
if (model_->GetAcceleratorAt(model_index, &accelerator)) {
formatted += L"\t";
formatted += accelerator.GetShortcutText();
diff --git a/views/controls/native_control.cc b/views/controls/native_control.cc
index 0c89664..700da66 100644
--- a/views/controls/native_control.cc
+++ b/views/controls/native_control.cc
@@ -11,6 +11,7 @@
#include <atlmisc.h>
#include "app/l10n_util_win.h"
+#include "base/keyboard_codes.h"
#include "base/logging.h"
#include "base/win_util.h"
#include "views/background.h"
@@ -363,8 +364,8 @@ LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, UINT message,
DCHECK(native_control);
if (message == WM_KEYDOWN &&
- native_control->OnKeyDown(static_cast<int>(w_param))) {
- return 0;
+ native_control->OnKeyDown(win_util::WinToKeyboardCode(w_param))) {
+ return 0;
} else if (message == WM_SETFOCUS) {
// Let the focus manager know that the focus changed.
FocusManager* focus_manager = native_control->GetFocusManager();
diff --git a/views/controls/native_control.h b/views/controls/native_control.h
index 972ef36..ed565e6 100644
--- a/views/controls/native_control.h
+++ b/views/controls/native_control.h
@@ -7,6 +7,7 @@
#include <windows.h>
+#include "base/keyboard_codes.h"
#include "views/view.h"
namespace views {
@@ -79,7 +80,7 @@ class NativeControl : public View {
// Invoked when a key is pressed on the control.
// Should return true if the key message was processed, false otherwise.
- virtual bool OnKeyDown(int virtual_key_code) { return false; }
+ virtual bool OnKeyDown(base::KeyboardCode virtual_key_code) { return false; }
// Returns additional extended style flags. When subclasses call
// CreateWindowEx in order to create the underlying control, they must OR the
diff --git a/views/controls/scrollbar/bitmap_scroll_bar.cc b/views/controls/scrollbar/bitmap_scroll_bar.cc
index b04e0b0..98a95ff 100644
--- a/views/controls/scrollbar/bitmap_scroll_bar.cc
+++ b/views/controls/scrollbar/bitmap_scroll_bar.cc
@@ -11,6 +11,7 @@
#include "app/gfx/canvas.h"
#include "app/l10n_util.h"
#include "base/compiler_specific.h"
+#include "base/keyboard_codes.h"
#include "base/message_loop.h"
#include "grit/app_strings.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -494,33 +495,33 @@ bool BitmapScrollBar::OnMouseWheel(const MouseWheelEvent& event) {
bool BitmapScrollBar::OnKeyPressed(const KeyEvent& event) {
ScrollAmount amount = SCROLL_NONE;
- switch (event.GetCharacter()) {
- case VK_UP:
+ switch (event.GetKeyCode()) {
+ case base::VKEY_UP:
if (!IsHorizontal())
amount = SCROLL_PREV_LINE;
break;
- case VK_DOWN:
+ case base::VKEY_DOWN:
if (!IsHorizontal())
amount = SCROLL_NEXT_LINE;
break;
- case VK_LEFT:
+ case base::VKEY_LEFT:
if (IsHorizontal())
amount = SCROLL_PREV_LINE;
break;
- case VK_RIGHT:
+ case base::VKEY_RIGHT:
if (IsHorizontal())
amount = SCROLL_NEXT_LINE;
break;
- case VK_PRIOR:
+ case base::VKEY_PRIOR:
amount = SCROLL_PREV_PAGE;
break;
- case VK_NEXT:
+ case base::VKEY_NEXT:
amount = SCROLL_NEXT_PAGE;
break;
- case VK_HOME:
+ case base::VKEY_HOME:
amount = SCROLL_START;
break;
- case VK_END:
+ case base::VKEY_END:
amount = SCROLL_END;
break;
}
diff --git a/views/controls/scrollbar/native_scroll_bar_win.cc b/views/controls/scrollbar/native_scroll_bar_win.cc
index b15be33..00b3b8c 100644
--- a/views/controls/scrollbar/native_scroll_bar_win.cc
+++ b/views/controls/scrollbar/native_scroll_bar_win.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include <string>
+#include "base/keyboard_codes.h"
#include "base/message_loop.h"
#include "base/window_impl.h"
#include "views/controls/scrollbar/native_scroll_bar.h"
@@ -229,32 +230,32 @@ bool NativeScrollBarWin::OnKeyPressed(const KeyEvent& event) {
if (!sb_container_)
return false;
int code = -1;
- switch (event.GetCharacter()) {
- case VK_UP:
+ switch (event.GetKeyCode()) {
+ case base::VKEY_UP:
if (!native_scroll_bar_->IsHorizontal())
code = SB_LINEUP;
break;
- case VK_PRIOR:
+ case base::VKEY_PRIOR:
code = SB_PAGEUP;
break;
- case VK_NEXT:
+ case base::VKEY_NEXT:
code = SB_PAGEDOWN;
break;
- case VK_DOWN:
+ case base::VKEY_DOWN:
if (!native_scroll_bar_->IsHorizontal())
code = SB_LINEDOWN;
break;
- case VK_HOME:
+ case base::VKEY_HOME:
code = SB_TOP;
break;
- case VK_END:
+ case base::VKEY_END:
code = SB_BOTTOM;
break;
- case VK_LEFT:
+ case base::VKEY_LEFT:
if (native_scroll_bar_->IsHorizontal())
code = SB_LINELEFT;
break;
- case VK_RIGHT:
+ case base::VKEY_RIGHT:
if (native_scroll_bar_->IsHorizontal())
code = SB_LINERIGHT;
break;
diff --git a/views/controls/table/group_table_view.cc b/views/controls/table/group_table_view.cc
index 5f26756..a70515d 100644
--- a/views/controls/table/group_table_view.cc
+++ b/views/controls/table/group_table_view.cc
@@ -61,7 +61,7 @@ void GroupTableView::SyncSelection() {
}
}
-void GroupTableView::OnKeyDown(unsigned short virtual_keycode) {
+bool GroupTableView::OnKeyDown(base::KeyboardCode virtual_keycode) {
// In a list view, multiple items can be selected but only one item has the
// focus. This creates a problem when the arrow keys are used for navigating
// between items in the list view. An example will make this more clear:
@@ -87,9 +87,9 @@ void GroupTableView::OnKeyDown(unsigned short virtual_keycode) {
// detect that one of the arrow keys is pressed. Thus, when it comes time
// for the list view control to actually switch the focus, the right item
// will be selected.
- if ((virtual_keycode != VK_UP) && (virtual_keycode != VK_DOWN)) {
- TableView::OnKeyDown(virtual_keycode);
- return;
+ if ((virtual_keycode != base::VKEY_UP) &&
+ (virtual_keycode != base::VKEY_DOWN)) {
+ return TableView::OnKeyDown(virtual_keycode);
}
// We start by finding the index of the item with the focus. If no item
@@ -102,27 +102,28 @@ void GroupTableView::OnKeyDown(unsigned short virtual_keycode) {
}
}
- if (focused_index == row_count) {
- return;
- }
+ if (focused_index == row_count)
+ return false;
+
DCHECK_LT(focused_index, row_count);
// Nothing to do if the item which has the focus is not part of a group.
GroupRange group_range;
model_->GetGroupRangeForItem(focused_index, &group_range);
- if (group_range.length == 1) {
- return;
- }
+ if (group_range.length == 1)
+ return false;
// If the user pressed the UP key, then the focus should be set to the
// topmost element in the group. If the user pressed the DOWN key, the focus
// should be set to the bottommost element.
- if (virtual_keycode == VK_UP) {
+ if (virtual_keycode == base::VKEY_UP) {
SetFocusOnItem(group_range.start);
} else {
- DCHECK_EQ(virtual_keycode, VK_DOWN);
+ DCHECK_EQ(virtual_keycode, base::VKEY_DOWN);
SetFocusOnItem(group_range.start + group_range.length - 1);
}
+
+ return false;
}
void GroupTableView::PrepareForSort() {
diff --git a/views/controls/table/group_table_view.h b/views/controls/table/group_table_view.h
index 640776e..b137083 100644
--- a/views/controls/table/group_table_view.h
+++ b/views/controls/table/group_table_view.h
@@ -55,7 +55,7 @@ class GroupTableView : public TableView {
// keys), we must take action when an arrow key is pressed. The reason we
// need to process this message has to do with the manner in which the focus
// needs to be set on a group item when a group is selected.
- virtual void OnKeyDown(unsigned short virtual_keycode);
+ virtual bool OnKeyDown(base::KeyboardCode virtual_keycode);
// Overriden to make sure rows in the same group stay grouped together.
virtual int CompareRows(int model_row1, int model_row2);
diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc
index 303d458..114019f 100644
--- a/views/controls/table/table_view.cc
+++ b/views/controls/table/table_view.cc
@@ -1057,15 +1057,6 @@ LRESULT TableView::OnNotify(int w_param, LPNMHDR hdr) {
OnDoubleClick();
break;
- // If we see a key down message, we need to invoke the OnKeyDown handler
- // in order to give our class (or any subclass) and opportunity to perform
- // a key down triggered action, if such action is necessary.
- case LVN_KEYDOWN: {
- NMLVKEYDOWN* key_down_message = reinterpret_cast<NMLVKEYDOWN*>(hdr);
- OnKeyDown(key_down_message->wVKey);
- break;
- }
-
case LVN_COLUMNCLICK: {
const TableColumn& column = GetColumnAtPosition(
reinterpret_cast<NMLISTVIEW*>(hdr)->iSubItem);
@@ -1459,10 +1450,11 @@ void TableView::OnSelectedStateChanged() {
}
}
-void TableView::OnKeyDown(unsigned short virtual_keycode) {
+bool TableView::OnKeyDown(base::KeyboardCode virtual_keycode) {
if (!ignore_listview_change_ && table_view_observer_) {
table_view_observer_->OnKeyDown(virtual_keycode);
}
+ return false; // Let the key event be processed as ususal.
}
void TableView::OnCheckedStateChanged(int model_row, bool is_checked) {
diff --git a/views/controls/table/table_view.h b/views/controls/table/table_view.h
index b8bda67..a1cce45d 100644
--- a/views/controls/table/table_view.h
+++ b/views/controls/table/table_view.h
@@ -16,6 +16,7 @@ typedef struct tagNMLVCUSTOMDRAW NMLVCUSTOMDRAW;
#include <vector>
#include "app/table_model_observer.h"
+#include "base/keyboard_codes.h"
#include "third_party/skia/include/core/SkColor.h"
#if defined(OS_WIN)
// TODO(port): remove the ifdef when native_control.h is ported.
@@ -250,9 +251,8 @@ class TableView : public NativeControl,
// Notification from the ListView that the user middle clicked the table.
virtual void OnMiddleClick();
- // Subclasses can implement this method if they need to be notified of a key
- // press event. Other wise, it appeals to table_view_observer_
- virtual void OnKeyDown(unsigned short virtual_keycode);
+ // Overridden from NativeControl. Notifies the observer.
+ virtual bool OnKeyDown(base::KeyboardCode virtual_keycode);
// Invoked to customize the colors or font at a particular cell. If you
// change the colors or font, return true. This is only invoked if
diff --git a/views/controls/table/table_view_observer.h b/views/controls/table/table_view_observer.h
index c88cb21..6b8bef2 100644
--- a/views/controls/table/table_view_observer.h
+++ b/views/controls/table/table_view_observer.h
@@ -24,7 +24,7 @@ class TableViewObserver {
virtual void OnMiddleClick() {}
// Optional method invoked when the user hits a key with the table in focus.
- virtual void OnKeyDown(unsigned short virtual_keycode) {}
+ virtual void OnKeyDown(base::KeyboardCode virtual_keycode) {}
// Invoked when the user presses the delete key.
virtual void OnTableViewDelete(TableView* table_view) {}
diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc
index 1872492..d027156 100644
--- a/views/controls/textfield/native_textfield_win.cc
+++ b/views/controls/textfield/native_textfield_win.cc
@@ -9,6 +9,7 @@
#include "app/win_util.h"
#include "base/clipboard.h"
#include "base/gfx/native_theme.h"
+#include "base/keyboard_codes.h"
#include "base/scoped_clipboard_writer.h"
#include "base/string_util.h"
#include "base/win_util.h"
@@ -252,13 +253,13 @@ bool NativeTextfieldWin::GetAcceleratorForCommandId(int command_id,
// anywhere so we need to check for them explicitly here.
switch (command_id) {
case IDS_APP_CUT:
- *accelerator = views::Accelerator(L'X', false, true, false);
+ *accelerator = views::Accelerator(base::VKEY_X, false, true, false);
return true;
case IDS_APP_COPY:
- *accelerator = views::Accelerator(L'C', false, true, false);
+ *accelerator = views::Accelerator(base::VKEY_C, false, true, false);
return true;
case IDS_APP_PASTE:
- *accelerator = views::Accelerator(L'V', false, true, false);
+ *accelerator = views::Accelerator(base::VKEY_V, false, true, false);
return true;
}
return container_view_->GetWidget()->GetAccelerator(command_id, accelerator);
diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc
index 368e7fd..bf12e42 100644
--- a/views/controls/textfield/textfield.cc
+++ b/views/controls/textfield/textfield.cc
@@ -14,6 +14,7 @@
#include "base/win_util.h"
#endif
+#include "base/keyboard_codes.h"
#include "base/string_util.h"
#include "views/controls/textfield/native_textfield_wrapper.h"
#include "views/widget/widget.h"
@@ -221,14 +222,14 @@ bool Textfield::SkipDefaultKeyEventProcessing(const KeyEvent& e) {
#if defined(OS_WIN)
// TODO(hamaji): Figure out which keyboard combinations we need to add here,
// similar to LocationBarView::SkipDefaultKeyEventProcessing.
- const int c = e.GetCharacter();
- if (c == VK_BACK)
+ base::KeyboardCode key = e.GetKeyCode();
+ if (key == base::VKEY_BACK)
return true; // We'll handle BackSpace ourselves.
// We don't translate accelerators for ALT + NumPad digit, they are used for
// entering special characters. We do translate alt-home.
- if (e.IsAltDown() && (c != VK_HOME) &&
- win_util::IsNumPadDigit(c, e.IsExtendedKey()))
+ if (e.IsAltDown() && (key != base::VKEY_HOME) &&
+ win_util::IsNumPadDigit(key, e.IsExtendedKey()))
return true;
#endif
return false;
diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc
index 196e773..c84ef8b 100644
--- a/views/controls/tree/tree_view.cc
+++ b/views/controls/tree/tree_view.cc
@@ -12,6 +12,7 @@
#include "app/l10n_util_win.h"
#include "app/resource_bundle.h"
#include "base/gfx/point.h"
+#include "base/keyboard_codes.h"
#include "base/stl_util-inl.h"
#include "base/win_util.h"
#include "grit/app_resources.h"
@@ -459,7 +460,7 @@ LRESULT TreeView::OnNotify(int w_param, LPNMHDR l_param) {
return 0;
}
-bool TreeView::OnKeyDown(int virtual_key_code) {
+bool TreeView::OnKeyDown(base::KeyboardCode virtual_key_code) {
if (virtual_key_code == VK_F2) {
if (!GetEditingNode()) {
TreeModelNode* selected_node = GetSelectedNode();
@@ -467,10 +468,10 @@ bool TreeView::OnKeyDown(int virtual_key_code) {
StartEditing(selected_node);
}
return true;
- } else if (virtual_key_code == VK_RETURN && !process_enter_) {
+ } else if (virtual_key_code == base::VKEY_RETURN && !process_enter_) {
Widget* widget = GetWidget();
DCHECK(widget);
- Accelerator accelerator(Accelerator(static_cast<int>(virtual_key_code),
+ Accelerator accelerator(Accelerator(virtual_key_code,
win_util::IsShiftPressed(),
win_util::IsCtrlPressed(),
win_util::IsAltPressed()));
diff --git a/views/controls/tree/tree_view.h b/views/controls/tree/tree_view.h
index 72667bf..0011835 100644
--- a/views/controls/tree/tree_view.h
+++ b/views/controls/tree/tree_view.h
@@ -12,6 +12,7 @@
#include "app/tree_model.h"
#include "base/basictypes.h"
+#include "base/keyboard_codes.h"
#include "base/logging.h"
#include "views/controls/native_control.h"
@@ -159,7 +160,7 @@ class TreeView : public NativeControl, TreeModelObserver {
// We pay attention to key down for two reasons: to circumvent VK_ENTER from
// toggling the expaned state when processes_enter_ is false, and to have F2
// start editting.
- virtual bool OnKeyDown(int virtual_key_code);
+ virtual bool OnKeyDown(base::KeyboardCode virtual_key_code);
virtual void OnContextMenu(const POINT& location);
diff --git a/views/event.h b/views/event.h
index 5a6efd9..138327d 100644
--- a/views/event.h
+++ b/views/event.h
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/gfx/point.h"
+#include "base/keyboard_codes.h"
#if defined(OS_LINUX)
typedef struct _GdkEventKey GdkEventKey;
@@ -242,7 +243,10 @@ class KeyEvent : public Event {
public:
#if defined(OS_WIN)
// Create a new key event
- KeyEvent(EventType type, int ch, int repeat_count, int message_flags);
+ KeyEvent(EventType type,
+ base::KeyboardCode key_code,
+ int repeat_count,
+ int message_flags);
#elif defined(OS_LINUX)
explicit KeyEvent(GdkEventKey* event);
#endif
@@ -251,8 +255,8 @@ class KeyEvent : public Event {
// the Windows value.
// On GTK, you can use the methods in keyboard_code_conversion_gtk.cc to
// convert this value back to a GDK value if needed.
- int GetCharacter() const {
- return character_;
+ base::KeyboardCode GetKeyCode() const {
+ return key_code_;
}
#if defined(OS_WIN)
@@ -268,7 +272,7 @@ class KeyEvent : public Event {
int GetKeyStateFlags() const;
#endif
- int character_;
+ base::KeyboardCode key_code_;
int repeat_count_;
int message_flags_;
diff --git a/views/event_gtk.cc b/views/event_gtk.cc
index 71fd056..c5970b7 100644
--- a/views/event_gtk.cc
+++ b/views/event_gtk.cc
@@ -18,7 +18,7 @@ KeyEvent::KeyEvent(GdkEventKey* event)
Event::ET_KEY_PRESSED : Event::ET_KEY_RELEASED,
GetFlagsFromGdkState(event->state)),
// TODO(erg): All these values are iffy.
- character_(base::WindowsKeyCodeForGdkKeyCode(event->keyval)),
+ key_code_(base::WindowsKeyCodeForGdkKeyCode(event->keyval)),
repeat_count_(0),
message_flags_(0) {
}
diff --git a/views/event_win.cc b/views/event_win.cc
index 28d1330..da6457e 100644
--- a/views/event_win.cc
+++ b/views/event_win.cc
@@ -37,12 +37,13 @@ int Event::ConvertWindowsFlags(UINT win_flags) {
return r;
}
-KeyEvent::KeyEvent(EventType type, int ch, int repeat_count, int message_flags)
+KeyEvent::KeyEvent(EventType type, base::KeyboardCode key_code,
+ int repeat_count, int message_flags)
: Event(type, GetKeyStateFlags()),
- character_(ch),
+ key_code_(key_code),
repeat_count_(repeat_count),
message_flags_(message_flags) {
- }
+}
int KeyEvent::GetKeyStateFlags() const {
// Windows Keyboard messages don't come with control key state as parameters
diff --git a/views/focus/accelerator_handler_win.cc b/views/focus/accelerator_handler_win.cc
index eb8bfb9..8363928 100644
--- a/views/focus/accelerator_handler_win.cc
+++ b/views/focus/accelerator_handler_win.cc
@@ -4,6 +4,8 @@
#include "views/focus/accelerator_handler.h"
+#include "base/keyboard_codes.h"
+#include "base/win_util.h"
#include "views/event.h"
#include "views/focus/focus_manager.h"
@@ -23,7 +25,7 @@ bool AcceleratorHandler::Dispatch(const MSG& msg) {
case WM_KEYDOWN:
case WM_SYSKEYDOWN: {
KeyEvent event(Event::ET_KEY_PRESSED,
- msg.wParam,
+ win_util::WinToKeyboardCode(msg.wParam),
msg.lParam & 0xFFFF,
(msg.lParam & 0xFFFF0000) >> 16);
process_message = focus_manager->OnKeyEvent(event);
diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc
index dffb392..aca418b 100644
--- a/views/focus/focus_manager.cc
+++ b/views/focus/focus_manager.cc
@@ -63,7 +63,7 @@ bool FocusManager::OnKeyEvent(const KeyEvent& event) {
#endif
// Intercept arrow key messages to switch between grouped views.
- int key_code = event.GetCharacter();
+ base::KeyboardCode key_code = event.GetKeyCode();
if (focused_view_ && focused_view_->GetGroup() != -1 &&
(key_code == base::VKEY_UP || key_code == base::VKEY_DOWN ||
key_code == base::VKEY_LEFT || key_code == base::VKEY_RIGHT)) {
@@ -89,7 +89,7 @@ bool FocusManager::OnKeyEvent(const KeyEvent& event) {
// Process keyboard accelerators.
// If the key combination matches an accelerator, the accelerator is
// triggered, otherwise the key event is proceed as usual.
- Accelerator accelerator(event.GetCharacter(),
+ Accelerator accelerator(event.GetKeyCode(),
event.IsShiftDown(),
event.IsControlDown(),
event.IsAltDown());
@@ -405,7 +405,7 @@ AcceleratorTarget* FocusManager::GetCurrentTargetForAccelerator(
// static
bool FocusManager::IsTabTraversalKeyEvent(const KeyEvent& key_event) {
- return key_event.GetCharacter() == base::VKEY_TAB &&
+ return key_event.GetKeyCode() == base::VKEY_TAB &&
!key_event.IsControlDown();
}
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index bad592b..b15b101 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -817,7 +817,7 @@ bool TestView::AcceleratorPressed(const Accelerator& accelerator) {
#if defined(OS_WIN)
TEST_F(ViewTest, ActivateAccelerator) {
// Register a keyboard accelerator before the view is added to a window.
- views::Accelerator return_accelerator(VK_RETURN, false, false, false);
+ views::Accelerator return_accelerator(base::VKEY_RETURN, false, false, false);
TestView* view = new TestView();
view->Reset();
view->AddAccelerator(return_accelerator);
@@ -841,7 +841,7 @@ TEST_F(ViewTest, ActivateAccelerator) {
EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1);
// Hit the escape key. Nothing should happen.
- views::Accelerator escape_accelerator(VK_ESCAPE, false, false, false);
+ views::Accelerator escape_accelerator(base::VKEY_ESCAPE, false, false, false);
EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator));
EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1);
EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 0);
@@ -1097,7 +1097,7 @@ class DefaultButtonTest : public ViewTest {
void SimularePressingEnterAndCheckDefaultButton(ButtonID button_id) {
#if defined(OS_WIN)
- KeyEvent event(Event::ET_KEY_PRESSED, VK_RETURN, 0, 0);
+ KeyEvent event(Event::ET_KEY_PRESSED, base::VKEY_RETURN, 0, 0);
focus_manager_->OnKeyEvent(event);
#else
// TODO(platform)
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc
index 8baca07..09c1909 100644
--- a/views/widget/root_view.cc
+++ b/views/widget/root_view.cc
@@ -782,8 +782,8 @@ bool RootView::ProcessKeyEvent(const KeyEvent& event) {
View* v = GetFocusedView();
// Special case to handle right-click context menus triggered by the
// keyboard.
- if (v && v->IsEnabled() && ((event.GetCharacter() == base::VKEY_APPS) ||
- (event.GetCharacter() == base::VKEY_F10 && event.IsShiftDown()))) {
+ if (v && v->IsEnabled() && ((event.GetKeyCode() == base::VKEY_APPS) ||
+ (event.GetKeyCode() == base::VKEY_F10 && event.IsShiftDown()))) {
gfx::Point screen_loc = v->GetKeyboardContextMenuLocation();
v->ShowContextMenu(screen_loc.x(), screen_loc.y(), false);
return true;
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index d975ef9..3017e05 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -571,12 +571,14 @@ void WidgetWin::OnInitMenuPopup(HMENU menu,
}
void WidgetWin::OnKeyDown(TCHAR c, UINT rep_cnt, UINT flags) {
- KeyEvent event(Event::ET_KEY_PRESSED, c, rep_cnt, flags);
+ KeyEvent event(Event::ET_KEY_PRESSED,
+ win_util::WinToKeyboardCode(c), rep_cnt, flags);
SetMsgHandled(root_view_->ProcessKeyEvent(event));
}
void WidgetWin::OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags) {
- KeyEvent event(Event::ET_KEY_RELEASED, c, rep_cnt, flags);
+ KeyEvent event(Event::ET_KEY_RELEASED,
+ win_util::WinToKeyboardCode(c), rep_cnt, flags);
SetMsgHandled(root_view_->ProcessKeyEvent(event));
}