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

Unified Diff: ui/base/test/ui_controls_internal_win.cc

Issue 2939283002: Use wScan instead of wVk to ensure webpage can get correct DOM CodeString (Closed)
Patch Set: Include 2946103002 Created 3 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
« no previous file with comments | « chrome/test/data/keyboardevent_code_test.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/test/ui_controls_internal_win.cc
diff --git a/ui/base/test/ui_controls_internal_win.cc b/ui/base/test/ui_controls_internal_win.cc
index ade37c9375840cb879cb213f184ecc652d2e5cd7..c508ffcea92dcb46bf89306bc1eb6e08125ae0ef 100644
--- a/ui/base/test/ui_controls_internal_win.cc
+++ b/ui/base/test/ui_controls_internal_win.cc
@@ -139,14 +139,38 @@ void InputDispatcher::NotifyTask() {
// Private functions ----------------------------------------------------------
+// Whether scan code should be used for |key|.
+// When sending keyboard events by SendInput() function, Windows does not
+// "smartly" add scan code if virtual key-code is used. So these key events
+// won't have scan code or DOM UI Event code string.
+// But we cannot blindly send all events with scan code. For some layout
+// dependent keys, the Windows may not translate them to what they used to be,
+// because the test cases are usually running in headless environment with
+// default keyboard layout. So fall back to use virtual key code for these keys.
+bool ShouldSendThroughScanCode(ui::KeyboardCode key) {
+ const DWORD native_code = ui::WindowsKeyCodeForKeyboardCode(key);
+ const DWORD scan_code = MapVirtualKey(native_code, MAPVK_VK_TO_VSC);
+ return native_code == MapVirtualKey(scan_code, MAPVK_VSC_TO_VK);
+}
+
// Populate the INPUT structure with the appropriate keyboard event
// parameters required by SendInput
bool FillKeyboardInput(ui::KeyboardCode key, INPUT* input, bool key_up) {
memset(input, 0, sizeof(INPUT));
input->type = INPUT_KEYBOARD;
input->ki.wVk = ui::WindowsKeyCodeForKeyboardCode(key);
- input->ki.dwFlags = key_up ? KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP :
- KEYEVENTF_EXTENDEDKEY;
+ if (ShouldSendThroughScanCode(key)) {
+ input->ki.wScan = MapVirtualKey(input->ki.wVk, MAPVK_VK_TO_VSC);
+ // When KEYEVENTF_SCANCODE is used, ki.wVk is ignored, so we do not need to
+ // clear it.
+ input->ki.dwFlags = KEYEVENTF_SCANCODE;
+ if ((input->ki.wScan & 0xFF00) != 0) {
+ input->ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
+ }
+ }
+ if (key_up) {
sky 2017/06/21 14:56:04 no {}
Hzj_jie 2017/06/21 18:18:03 Done.
+ input->ki.dwFlags |= KEYEVENTF_KEYUP;
+ }
return true;
}
« no previous file with comments | « chrome/test/data/keyboardevent_code_test.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698