This source file includes following definitions.
- expect_local_echo_
- LocalMouseMoved
- SetExpectLocalEcho
- InjectKeyEvent
- InjectTextEvent
- InjectMouseEvent
- ShouldIgnoreInput
#include "remoting/host/remote_input_filter.h"
#include "base/logging.h"
#include "remoting/proto/event.pb.h"
namespace {
const unsigned int kNumRemoteMousePositions = 50;
const int64 kRemoteBlockTimeoutMillis = 2000;
}
namespace remoting {
RemoteInputFilter::RemoteInputFilter(protocol::InputEventTracker* event_tracker)
: event_tracker_(event_tracker),
expect_local_echo_(true) {
}
RemoteInputFilter::~RemoteInputFilter() {
}
void RemoteInputFilter::LocalMouseMoved(
const webrtc::DesktopVector& mouse_pos) {
if (expect_local_echo_) {
std::list<webrtc::DesktopVector>::iterator found_position =
injected_mouse_positions_.begin();
while (found_position != injected_mouse_positions_.end() &&
!mouse_pos.equals(*found_position)) {
++found_position;
}
if (found_position != injected_mouse_positions_.end()) {
injected_mouse_positions_.erase(injected_mouse_positions_.begin(),
++found_position);
return;
}
}
event_tracker_->ReleaseAll();
latest_local_input_time_ = base::TimeTicks::Now();
}
void RemoteInputFilter::SetExpectLocalEcho(bool expect_local_echo) {
expect_local_echo_ = expect_local_echo;
if (!expect_local_echo_)
injected_mouse_positions_.clear();
}
void RemoteInputFilter::InjectKeyEvent(const protocol::KeyEvent& event) {
if (ShouldIgnoreInput())
return;
event_tracker_->InjectKeyEvent(event);
}
void RemoteInputFilter::InjectTextEvent(const protocol::TextEvent& event) {
if (ShouldIgnoreInput())
return;
event_tracker_->InjectTextEvent(event);
}
void RemoteInputFilter::InjectMouseEvent(const protocol::MouseEvent& event) {
if (ShouldIgnoreInput())
return;
if (expect_local_echo_ && event.has_x() && event.has_y()) {
injected_mouse_positions_.push_back(
webrtc::DesktopVector(event.x(), event.y()));
if (injected_mouse_positions_.size() > kNumRemoteMousePositions) {
VLOG(1) << "Injected mouse positions queue full.";
injected_mouse_positions_.pop_front();
}
}
event_tracker_->InjectMouseEvent(event);
}
bool RemoteInputFilter::ShouldIgnoreInput() const {
int64 millis =
(base::TimeTicks::Now() - latest_local_input_time_).InMilliseconds();
if (millis < kRemoteBlockTimeoutMillis)
return true;
return false;
}
}