OLD | NEW |
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 26 matching lines...) Expand all Loading... |
37 // EF_COMMAND_DOWN, | 37 // EF_COMMAND_DOWN, |
38 EF_ALTGR_DOWN, | 38 EF_ALTGR_DOWN, |
39 // EF_NUM_LOCK_ON, | 39 // EF_NUM_LOCK_ON, |
40 EF_CAPS_LOCK_ON, | 40 EF_CAPS_LOCK_ON, |
41 // EF_SCROLL_LOCK_ON | 41 // EF_SCROLL_LOCK_ON |
42 }; | 42 }; |
43 const int kModifierFlagsCombinations = (1 << arraysize(modifier_flags)) - 1; | 43 const int kModifierFlagsCombinations = (1 << arraysize(modifier_flags)) - 1; |
44 | 44 |
45 int GetModifierFlags(int combination) { | 45 int GetModifierFlags(int combination) { |
46 int flags = EF_NONE; | 46 int flags = EF_NONE; |
47 for (int i = 0; i < arraysize(modifier_flags); ++i) { | 47 for (size_t i = 0; i < arraysize(modifier_flags); ++i) { |
48 if (combination & (1 << i)) | 48 if (combination & (1 << i)) |
49 flags |= modifier_flags[i]; | 49 flags |= modifier_flags[i]; |
50 } | 50 } |
51 return flags; | 51 return flags; |
52 } | 52 } |
53 | 53 |
54 void SetModifierState(BYTE* keyboard_state, int flags) { | 54 void SetModifierState(BYTE* keyboard_state, int flags) { |
55 // According to MSDN GetKeyState(): | 55 // According to MSDN GetKeyState(): |
56 // 1. If the high-order bit is 1, the key is down; otherwise, it is up. | 56 // 1. If the high-order bit is 1, the key is down; otherwise, it is up. |
57 // 2. If the low-order bit is 1, the key is toggled. A key, such as the | 57 // 2. If the low-order bit is 1, the key is toggled. A key, such as the |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 g_platform_key_map_tls_lazy = LAZY_INSTANCE_INITIALIZER; | 106 g_platform_key_map_tls_lazy = LAZY_INSTANCE_INITIALIZER; |
107 | 107 |
108 } // anonymous namespace | 108 } // anonymous namespace |
109 | 109 |
110 PlatformKeyMap::PlatformKeyMap() {} | 110 PlatformKeyMap::PlatformKeyMap() {} |
111 | 111 |
112 PlatformKeyMap::PlatformKeyMap(HKL layout) { | 112 PlatformKeyMap::PlatformKeyMap(HKL layout) { |
113 UpdateLayout(layout); | 113 UpdateLayout(layout); |
114 } | 114 } |
115 | 115 |
| 116 PlatformKeyMap::~PlatformKeyMap() {} |
| 117 |
116 DomKey PlatformKeyMap::DomCodeAndFlagsToDomKey(DomCode code, int flags) const { | 118 DomKey PlatformKeyMap::DomCodeAndFlagsToDomKey(DomCode code, int flags) const { |
117 const int flags_to_try[] = { | 119 const int flags_to_try[] = { |
118 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. | 120 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. |
119 // If the combination doesn't produce a printable character, the key value | 121 // If the combination doesn't produce a printable character, the key value |
120 // should be the key with no modifiers except for Shift and AltGr. | 122 // should be the key with no modifiers except for Shift and AltGr. |
121 // See https://w3c.github.io/uievents/#keys-guidelines | 123 // See https://w3c.github.io/uievents/#keys-guidelines |
122 flags, | 124 flags, |
123 flags & (EF_SHIFT_DOWN | EF_ALTGR_DOWN | EF_CAPS_LOCK_ON), | 125 flags & (EF_SHIFT_DOWN | EF_ALTGR_DOWN | EF_CAPS_LOCK_ON), |
124 flags & (EF_SHIFT_DOWN | EF_CAPS_LOCK_ON), | 126 flags & (EF_SHIFT_DOWN | EF_CAPS_LOCK_ON), |
125 EF_NONE, | 127 EF_NONE, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 209 } |
208 } else { | 210 } else { |
209 // TODO(chongz): Handle rv <= -2 and rv >= 2. | 211 // TODO(chongz): Handle rv <= -2 and rv >= 2. |
210 } | 212 } |
211 } | 213 } |
212 } | 214 } |
213 ::SetKeyboardState(keyboard_state_to_restore); | 215 ::SetKeyboardState(keyboard_state_to_restore); |
214 } | 216 } |
215 | 217 |
216 } // namespace ui | 218 } // namespace ui |
OLD | NEW |