OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_HOST_LINUX_X11_KEY_MAPPER_H_ |
| 6 #define REMOTING_HOST_LINUX_X11_KEY_MAPPER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/macros.h" |
| 14 #include "base/time/time.h" |
| 15 |
| 16 namespace base { |
| 17 class TickClock; |
| 18 } // namespace base |
| 19 |
| 20 namespace remoting { |
| 21 |
| 22 class X11Keyboard; |
| 23 |
| 24 // This is a helper class for finding keycode for a character and assigning |
| 25 // unused keycode to the character when it is not mapped. |
| 26 // When the key mapper is destructed, all keycodes changed by the mapper will be |
| 27 // reset to map NoSymbol. |
| 28 // The key mapper must be used on single thread thread. |
| 29 class X11KeyMapper { |
| 30 public: |
| 31 struct MapResult { |
| 32 bool success; |
| 33 |
| 34 uint32_t keycode; |
| 35 uint32_t modifiers; |
| 36 |
| 37 // If success == false and |retry_after| is not zero, user may retry |
| 38 // AddNewCharacter() after |retry_after| has elapsed. |
| 39 base::TimeDelta retry_after; |
| 40 }; |
| 41 |
| 42 explicit X11KeyMapper(X11Keyboard* keyboard); |
| 43 ~X11KeyMapper(); |
| 44 |
| 45 // |code_point|: The Unicode code point for the character. |
| 46 // If the returned result indicates success, caller can use the returned |
| 47 // keycode and modifiers to simulate a key press that can generate the |
| 48 // character. |
| 49 // |
| 50 // Note that the returned result will expire after some amount of time so do |
| 51 // not store the result for later use. |
| 52 MapResult MapCharacter(uint32_t code_point); |
| 53 |
| 54 void SetClockForTesting(std::unique_ptr<base::TickClock> clock); |
| 55 |
| 56 private: |
| 57 struct KeyInfo; |
| 58 |
| 59 // Resets the expiration time of the KeyInfo in available_keycodes_[index] |
| 60 // to now + the expire duration constant. |
| 61 void ResetKeyInfoExpirationTime(std::vector<KeyInfo>::iterator position); |
| 62 |
| 63 X11Keyboard* keyboard_; |
| 64 std::unique_ptr<base::TickClock> clock_; |
| 65 |
| 66 // Sorted by ascending expiration time. |
| 67 std::vector<KeyInfo> available_keycodes_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(X11KeyMapper); |
| 70 }; |
| 71 |
| 72 } // namespace remoting |
| 73 |
| 74 #endif // REMOTING_HOST_LINUX_X11_KEY_MAPPER_H_ |
OLD | NEW |