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

Side by Side Diff: ui/events/keycodes/platform_key_map_win.cc

Issue 1716913002: Add fail check for GetKeyboardState() in Windows KeyMap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | 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 (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/events/keycodes/platform_key_map_win.h" 5 #include "ui/events/keycodes/platform_key_map_win.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 HKL current_layout = ::GetKeyboardLayout(0); 157 HKL current_layout = ::GetKeyboardLayout(0);
158 platform_key_map->UpdateLayout(current_layout); 158 platform_key_map->UpdateLayout(current_layout);
159 return platform_key_map->DomCodeAndFlagsToDomKey(code, flags); 159 return platform_key_map->DomCodeAndFlagsToDomKey(code, flags);
160 } 160 }
161 161
162 void PlatformKeyMap::UpdateLayout(HKL layout) { 162 void PlatformKeyMap::UpdateLayout(HKL layout) {
163 if (layout == keyboard_layout_) 163 if (layout == keyboard_layout_)
164 return; 164 return;
165 165
166 BYTE keyboard_state_to_restore[256];
167 if (!::GetKeyboardState(keyboard_state_to_restore))
168 return;
169
166 // TODO(chongz): Optimize layout switching (see crbug.com/587147). 170 // TODO(chongz): Optimize layout switching (see crbug.com/587147).
167 keyboard_layout_ = layout; 171 keyboard_layout_ = layout;
168 code_to_key_.clear(); 172 code_to_key_.clear();
169 // Map size for some sample keyboard layouts: 173 // Map size for some sample keyboard layouts:
170 // US: 428, French: 554, Persian: 434, Vietnamese: 1388 174 // US: 428, French: 554, Persian: 434, Vietnamese: 1388
171 code_to_key_.reserve(500); 175 code_to_key_.reserve(500);
172 176
173 BYTE keyboard_state_to_restore[256];
174 ::GetKeyboardState(keyboard_state_to_restore);
175
176 for (int eindex = 0; eindex <= kModifierFlagsCombinations; ++eindex) { 177 for (int eindex = 0; eindex <= kModifierFlagsCombinations; ++eindex) {
177 BYTE keyboard_state[256]; 178 BYTE keyboard_state[256];
178 memset(keyboard_state, 0, sizeof(keyboard_state)); 179 memset(keyboard_state, 0, sizeof(keyboard_state));
179 int flags = GetModifierFlags(eindex); 180 int flags = GetModifierFlags(eindex);
180 SetModifierState(keyboard_state, flags); 181 SetModifierState(keyboard_state, flags);
181 for (const auto& dom_code_entry : supported_dom_code_list) { 182 for (const auto& dom_code_entry : supported_dom_code_list) {
182 wchar_t translated_chars[5]; 183 wchar_t translated_chars[5];
183 int key_code = ::MapVirtualKeyEx(dom_code_entry.scan_code, 184 int key_code = ::MapVirtualKeyEx(dom_code_entry.scan_code,
184 MAPVK_VSC_TO_VK, keyboard_layout_); 185 MAPVK_VSC_TO_VK, keyboard_layout_);
185 int rv = ::ToUnicodeEx(key_code, 0, keyboard_state, translated_chars, 186 int rv = ::ToUnicodeEx(key_code, 0, keyboard_state, translated_chars,
(...skipping 23 matching lines...) Expand all
209 } 210 }
210 } else { 211 } else {
211 // TODO(chongz): Handle rv <= -2 and rv >= 2. 212 // TODO(chongz): Handle rv <= -2 and rv >= 2.
212 } 213 }
213 } 214 }
214 } 215 }
215 ::SetKeyboardState(keyboard_state_to_restore); 216 ::SetKeyboardState(keyboard_state_to_restore);
216 } 217 }
217 218
218 } // namespace ui 219 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698