summaryrefslogtreecommitdiffstats
path: root/remoting/client/input_handler.cc
blob: c203f54fb4962830e8b014a01d54280a4aaece3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "remoting/client/input_handler.h"

#include "remoting/client/chromoting_view.h"
#include "remoting/proto/event.pb.h"
#include "remoting/protocol/connection_to_host.h"

namespace remoting {

using protocol::KeyEvent;
using protocol::MouseEvent;

InputHandler::InputHandler(ClientContext* context,
                           protocol::ConnectionToHost* connection,
                           ChromotingView* view)
    : context_(context),
      connection_(connection),
      view_(view) {
}

void InputHandler::SendKeyEvent(bool press, int keycode) {
  protocol::InputStub* stub = connection_->input_stub();
  if (stub) {
    KeyEvent* event = new KeyEvent();
    event->set_keycode(keycode);
    event->set_pressed(press);

    stub->InjectKeyEvent(event, new DeleteTask<KeyEvent>(event));
  }
}

void InputHandler::SendMouseMoveEvent(int x, int y) {
  protocol::InputStub* stub = connection_->input_stub();
  if (stub) {
    MouseEvent* event = new MouseEvent();
    event->set_x(x);
    event->set_y(y);

    stub->InjectMouseEvent(event, new DeleteTask<MouseEvent>(event));
  }
}

void InputHandler::SendMouseButtonEvent(bool button_down,
                                        MouseEvent::MouseButton button) {
  protocol::InputStub* stub = connection_->input_stub();
  if (stub) {
    MouseEvent* event = new MouseEvent();
    event->set_button(button);
    event->set_button_down(button_down);

    stub->InjectMouseEvent(event, new DeleteTask<MouseEvent>(event));
  }
}

}  // namespace remoting