| 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 #ifndef UI_EVENTS_KEYCODES_PLATFORM_KEY_MAP_WIN_H_ | 5 #ifndef UI_EVENTS_KEYCODES_PLATFORM_KEY_MAP_WIN_H_ |
| 6 #define UI_EVENTS_KEYCODES_PLATFORM_KEY_MAP_WIN_H_ | 6 #define UI_EVENTS_KEYCODES_PLATFORM_KEY_MAP_WIN_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include <unordered_map> | 10 #include <unordered_map> |
| 11 | 11 |
| 12 #include "base/event_types.h" |
| 12 #include "base/hash.h" | 13 #include "base/hash.h" |
| 13 #include "ui/events/events_base_export.h" | 14 #include "ui/events/events_export.h" |
| 14 #include "ui/events/keycodes/dom/dom_key.h" | 15 #include "ui/events/keycodes/dom/dom_key.h" |
| 15 #include "ui/events/keycodes/keyboard_codes_win.h" | 16 #include "ui/events/keycodes/keyboard_codes_win.h" |
| 16 | 17 |
| 17 namespace ui { | 18 namespace ui { |
| 18 | 19 |
| 19 enum class DomCode; | 20 enum class DomCode; |
| 20 | 21 |
| 21 class EVENTS_BASE_EXPORT PlatformKeyMap { | 22 class EVENTS_EXPORT PlatformKeyMap { |
| 22 public: | 23 public: |
| 23 // Create and load key map table with specified keyboard layout. | 24 // Create and load key map table with specified keyboard layout. |
| 25 // Visible for testing. |
| 24 explicit PlatformKeyMap(HKL layout); | 26 explicit PlatformKeyMap(HKL layout); |
| 25 ~PlatformKeyMap(); | 27 ~PlatformKeyMap(); |
| 26 | 28 |
| 29 // Returns the DOM KeyboardEvent key from a native event and the keyboard |
| 30 // layout of current thread. |
| 31 // Updates a per-thread key map cache whenever the layout changes. |
| 32 static DomKey DomKeyFromNative(const base::NativeEvent& native_event); |
| 33 |
| 34 private: |
| 35 friend class PlatformKeyMapTest; |
| 36 |
| 37 PlatformKeyMap(); |
| 38 |
| 39 // TODO(chongz): Expose this function when we need to access separate layout. |
| 27 // Returns the DomKey 'meaning' of |code| in the context of specified | 40 // Returns the DomKey 'meaning' of |code| in the context of specified |
| 28 // |ui_event_flags| and stored keyboard layout. | 41 // |ui_event_flags| and stored keyboard layout. |
| 29 DomKey DomCodeAndFlagsToDomKey(DomCode code, | 42 // |key_code| will only be used for NumPad. |
| 30 int ui_event_flags) const; | 43 DomKey DomKeyFromNativeImpl(DomCode code, |
| 31 | 44 KeyboardCode key_code, |
| 32 // Returns the DomKey 'meaning' of |code| in the context of specified | 45 int ui_event_flags) const; |
| 33 // |ui_event_flags| and the keyboard layout of current thread. | |
| 34 // Updates a per-thread key map cache whenever the layout changes. | |
| 35 static DomKey DomCodeAndFlagsToDomKeyStatic( | |
| 36 DomCode code, | |
| 37 int ui_event_flags); | |
| 38 | |
| 39 private: | |
| 40 PlatformKeyMap(); | |
| 41 | 46 |
| 42 // TODO(chongz): Expose this function in response to WM_INPUTLANGCHANGE. | 47 // TODO(chongz): Expose this function in response to WM_INPUTLANGCHANGE. |
| 43 void UpdateLayout(HKL layout); | 48 void UpdateLayout(HKL layout); |
| 44 | 49 |
| 45 HKL keyboard_layout_ = 0; | 50 HKL keyboard_layout_ = 0; |
| 46 | 51 |
| 47 // TODO(chongz): Change type to DomCode when we got a generic pair hash class. | 52 // TODO(chongz): Change type to DomCode when we got a generic pair hash class. |
| 48 typedef std::pair<int /*DomCode*/, int /*EventFlags*/> DomCodeEventFlagsPair; | 53 typedef std::pair<int /*DomCode*/, int /*EventFlags*/> DomCodeEventFlagsPair; |
| 49 typedef std::unordered_map<DomCodeEventFlagsPair, | 54 typedef std::unordered_map<DomCodeEventFlagsPair, |
| 50 DomKey, | 55 DomKey, |
| 51 base::IntPairHash<std::pair<int, int>>> | 56 base::IntPairHash<std::pair<int, int>>> |
| 52 DomCodeToKeyMap; | 57 DomCodeToKeyMap; |
| 53 DomCodeToKeyMap code_to_key_; | 58 DomCodeToKeyMap code_to_key_; |
| 54 | 59 |
| 55 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMap); | 60 DISALLOW_COPY_AND_ASSIGN(PlatformKeyMap); |
| 56 }; | 61 }; |
| 57 | 62 |
| 58 } // namespace ui | 63 } // namespace ui |
| 59 | 64 |
| 60 #endif // UI_EVENTS_KEYCODES_PLATFORM_KEY_MAP_WIN_H_ | 65 #endif // UI_EVENTS_KEYCODES_PLATFORM_KEY_MAP_WIN_H_ |
| OLD | NEW |