Chromium Code Reviews| 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_CHARACTER_INJECTOR_H_ | |
| 6 #define REMOTING_HOST_LINUX_X11_CHARACTER_INJECTOR_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <queue> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 #include "base/timer/timer.h" | |
| 16 | |
| 17 namespace remoting { | |
| 18 | |
| 19 class X11Keyboard; | |
| 20 | |
| 21 // This is a helper class for injecting unicode characters to XWindow server. | |
| 22 // Characters will be queued up and sent when there is available resource. | |
| 23 class X11CharacterInjector { | |
| 24 public: | |
| 25 explicit X11CharacterInjector(std::unique_ptr<X11Keyboard> keyboard); | |
| 26 ~X11CharacterInjector(); | |
| 27 | |
| 28 void Inject(uint32_t code_point); | |
| 29 | |
| 30 private: | |
| 31 struct KeyInfo; | |
| 32 struct MapResult; | |
| 33 | |
| 34 // Ensures that Consume() will be called once at some point in the future not | |
| 35 // earlier than now + |delay|. It's a no-op when calling this function with a | |
| 36 // smaller |delay| after calling this with a larger delay while the scheduled | |
| 37 // Consume() has not been called yet. | |
| 38 void Schedule(base::TimeDelta delay); | |
| 39 void Consume(); | |
| 40 | |
| 41 // |code_point|: The Unicode code point for the character. | |
| 42 // If the returned result indicates success, caller can use the returned | |
| 43 // keycode and modifiers to simulate a key press that can generate the | |
| 44 // character. | |
| 45 // | |
| 46 // Note that the returned result will expire after some amount of time so do | |
| 47 // not store the result for later use. | |
| 48 MapResult MapCharacter(uint32_t code_point); | |
| 49 | |
| 50 // Resets the expiration time of the KeyInfo in available_keycodes_[index] | |
| 51 // to now + the expire duration constant. | |
| 52 void ResetKeyInfoExpirationTime(std::vector<KeyInfo>::iterator position); | |
| 53 | |
| 54 std::unique_ptr<X11Keyboard> keyboard_; | |
| 55 std::queue<uint32_t> characters_queue_; | |
| 56 base::OneShotTimer consume_timer_; | |
| 57 base::TimeTicks scheduled_consume_time_; | |
| 58 | |
| 59 // Sorted by ascending expiration time. | |
| 60 std::vector<KeyInfo> available_keycodes_; | |
| 61 | |
| 62 base::ThreadChecker thread_checker_; | |
| 63 | |
| 64 base::WeakPtrFactory<X11CharacterInjector> weak_factory_; | |
|
Sergey Ulanov
2016/09/27 18:40:48
weak_factory_ is not used anywhere. Remove it?
Yuwei
2016/09/28 18:45:55
Done.
| |
| 65 DISALLOW_COPY_AND_ASSIGN(X11CharacterInjector); | |
| 66 }; | |
| 67 | |
| 68 } // namespace remoting | |
| 69 | |
| 70 #endif // REMOTING_HOST_LINUX_X11_CHARACTER_INJECTOR_H_ | |
| OLD | NEW |