File: mouse_input_filter.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (54 lines) | stat: -rw-r--r-- 1,703 bytes parent folder | download | duplicates (3)
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
// Copyright (c) 2012 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/protocol/mouse_input_filter.h"

#include "remoting/proto/event.pb.h"

namespace remoting {
namespace protocol {

MouseInputFilter::MouseInputFilter() {
}

MouseInputFilter::MouseInputFilter(InputStub* input_stub)
    : InputFilter(input_stub) {
}

MouseInputFilter::~MouseInputFilter() {
}

void MouseInputFilter::InjectMouseEvent(const MouseEvent& event) {
  if (input_max_.is_empty() || output_max_.is_empty())
    return;

  // We scale based on the maximum input & output coordinates, rather than the
  // input and output sizes, so that it's possible to reach the edge of the
  // output when up-scaling.  We also take care to round up or down correctly,
  // which is important when down-scaling.
  MouseEvent out_event(event);
  if (out_event.has_x()) {
    int x = out_event.x() * output_max_.width();
    x = (x + input_max_.width() / 2) / input_max_.width();
    out_event.set_x(std::max(0, std::min(output_max_.width(), x)));
  }
  if (out_event.has_y()) {
    int y = out_event.y() * output_max_.height();
    y = (y + input_max_.height() / 2) / input_max_.height();
    out_event.set_y(std::max(0, std::min(output_max_.height(), y)));
  }

  InputFilter::InjectMouseEvent(out_event);
}

void MouseInputFilter::set_input_size(const webrtc::DesktopSize& size) {
  input_max_.set(size.width() - 1, size.height() - 1);
}

void MouseInputFilter::set_output_size(const webrtc::DesktopSize& size) {
  output_max_.set(size.width() - 1, size.height() - 1);
}

}  // namespace protocol
}  // namespace remoting