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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « chrome/test/data/keyboardevent_code_test.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/test/ui_controls_internal_win.h" 5 #include "ui/base/test/ui_controls_internal_win.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 FROM_HERE, base::Bind(&InputDispatcher::NotifyTask, this)); 132 FROM_HERE, base::Bind(&InputDispatcher::NotifyTask, this));
133 } 133 }
134 134
135 void InputDispatcher::NotifyTask() { 135 void InputDispatcher::NotifyTask() {
136 task_.Run(); 136 task_.Run();
137 Release(); 137 Release();
138 } 138 }
139 139
140 // Private functions ---------------------------------------------------------- 140 // Private functions ----------------------------------------------------------
141 141
142 // Whether scan code should be used for |key|.
143 // When sending keyboard events by SendInput() function, Windows does not
144 // "smartly" add scan code if virtual key-code is used. So these key events
145 // won't have scan code or DOM UI Event code string.
146 // But we cannot blindly send all events with scan code. For some layout
147 // dependent keys, the Windows may not translate them to what they used to be,
148 // because the test cases are usually running in headless environment with
149 // default keyboard layout. So fall back to use virtual key code for these keys.
150 bool ShouldSendThroughScanCode(ui::KeyboardCode key) {
151 const DWORD native_code = ui::WindowsKeyCodeForKeyboardCode(key);
152 const DWORD scan_code = MapVirtualKey(native_code, MAPVK_VK_TO_VSC);
153 return native_code == MapVirtualKey(scan_code, MAPVK_VSC_TO_VK);
154 }
155
142 // Populate the INPUT structure with the appropriate keyboard event 156 // Populate the INPUT structure with the appropriate keyboard event
143 // parameters required by SendInput 157 // parameters required by SendInput
144 bool FillKeyboardInput(ui::KeyboardCode key, INPUT* input, bool key_up) { 158 bool FillKeyboardInput(ui::KeyboardCode key, INPUT* input, bool key_up) {
145 memset(input, 0, sizeof(INPUT)); 159 memset(input, 0, sizeof(INPUT));
146 input->type = INPUT_KEYBOARD; 160 input->type = INPUT_KEYBOARD;
147 input->ki.wVk = ui::WindowsKeyCodeForKeyboardCode(key); 161 input->ki.wVk = ui::WindowsKeyCodeForKeyboardCode(key);
148 input->ki.dwFlags = key_up ? KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP : 162 if (ShouldSendThroughScanCode(key)) {
149 KEYEVENTF_EXTENDEDKEY; 163 input->ki.wScan = MapVirtualKey(input->ki.wVk, MAPVK_VK_TO_VSC);
164 // When KEYEVENTF_SCANCODE is used, ki.wVk is ignored, so we do not need to
165 // clear it.
166 input->ki.dwFlags = KEYEVENTF_SCANCODE;
167 if ((input->ki.wScan & 0xFF00) != 0) {
168 input->ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
169 }
170 }
171 if (key_up) {
sky 2017/06/21 14:56:04 no {}
Hzj_jie 2017/06/21 18:18:03 Done.
172 input->ki.dwFlags |= KEYEVENTF_KEYUP;
173 }
150 174
151 return true; 175 return true;
152 } 176 }
153 177
154 } // namespace 178 } // namespace
155 179
156 namespace ui_controls { 180 namespace ui_controls {
157 namespace internal { 181 namespace internal {
158 182
159 bool SendKeyPressImpl(HWND window, 183 bool SendKeyPressImpl(HWND window,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return false; 349 return false;
326 350
327 if (dispatcher.get()) 351 if (dispatcher.get())
328 dispatcher->AddRef(); 352 dispatcher->AddRef();
329 353
330 return true; 354 return true;
331 } 355 }
332 356
333 } // namespace internal 357 } // namespace internal
334 } // namespace ui_controls 358 } // namespace ui_controls
OLDNEW
« 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