OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 #include "remoting/protocol/key_event_tracker.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "remoting/proto/event.pb.h" |
| 9 |
| 10 namespace remoting { |
| 11 namespace protocol { |
| 12 |
| 13 KeyEventTracker::KeyEventTracker(InputStub* input_stub) |
| 14 : input_stub_(input_stub) { |
| 15 } |
| 16 |
| 17 KeyEventTracker::~KeyEventTracker() { |
| 18 DCHECK(pressed_keys_.empty()); |
| 19 } |
| 20 |
| 21 void KeyEventTracker::InjectKeyEvent(const KeyEvent& event) { |
| 22 DCHECK(event.has_pressed()); |
| 23 DCHECK(event.has_keycode()); |
| 24 if (event.pressed()) { |
| 25 pressed_keys_.insert(event.keycode()); |
| 26 } else { |
| 27 pressed_keys_.erase(event.keycode()); |
| 28 } |
| 29 input_stub_->InjectKeyEvent(event); |
| 30 } |
| 31 |
| 32 void KeyEventTracker::InjectMouseEvent(const MouseEvent& event) { |
| 33 input_stub_->InjectMouseEvent(event); |
| 34 } |
| 35 |
| 36 void KeyEventTracker::ReleaseAllKeys() { |
| 37 std::set<int>::iterator i; |
| 38 for (i = pressed_keys_.begin(); i != pressed_keys_.end(); ++i) { |
| 39 KeyEvent event; |
| 40 event.set_keycode(*i); |
| 41 event.set_pressed(false); |
| 42 input_stub_->InjectKeyEvent(event); |
| 43 } |
| 44 pressed_keys_.clear(); |
| 45 } |
| 46 |
| 47 } // namespace protocol |
| 48 } // namespace remoting |
OLD | NEW |