OLD | NEW |
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 Loading... |
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 if (key_up) |
| 171 input->ki.dwFlags |= KEYEVENTF_KEYUP; |
150 | 172 |
151 return true; | 173 return true; |
152 } | 174 } |
153 | 175 |
154 } // namespace | 176 } // namespace |
155 | 177 |
156 namespace ui_controls { | 178 namespace ui_controls { |
157 namespace internal { | 179 namespace internal { |
158 | 180 |
159 bool SendKeyPressImpl(HWND window, | 181 bool SendKeyPressImpl(HWND window, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 return false; | 347 return false; |
326 | 348 |
327 if (dispatcher.get()) | 349 if (dispatcher.get()) |
328 dispatcher->AddRef(); | 350 dispatcher->AddRef(); |
329 | 351 |
330 return true; | 352 return true; |
331 } | 353 } |
332 | 354 |
333 } // namespace internal | 355 } // namespace internal |
334 } // namespace ui_controls | 356 } // namespace ui_controls |
OLD | NEW |