File: fractional_input_filter.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (84 lines) | stat: -rw-r--r-- 3,694 bytes parent folder | download | duplicates (6)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_PROTOCOL_FRACTIONAL_INPUT_FILTER_H_
#define REMOTING_PROTOCOL_FRACTIONAL_INPUT_FILTER_H_

#include "remoting/proto/control.pb.h"
#include "remoting/protocol/input_filter.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"

namespace remoting::protocol {

// Filter which modifies each event's x,y values based on any fractional
// coordinates in the event. Events without fractional coordinates are
// passed through unmodified. The computed x,y values are suitable to be passed
// directly to the InputInjector.
//
// The fractional coordinates are expected to lie between 0 and 1. The
// calculated values are clamped to the monitor's area, to guard against
// unexpected behavior for out-of-range inputs.
//
// The client may send fractional coordinates without a `screen_id` property. In
// this case, the fallback geometry will be used for the scaling calculation.
//
// For MouseEvents with fractional coordinates, if the calculation fails, the
// event is discarded (as it is likely a broken or outdated event which should
// not be injected). Reasons for failure include:
// * A fractional-coordinate field (x or y) is not present.
// * The screen_id is present but is not found in the latest video-layout.
// * The screen_id is not present, and no fallback geometry has been set.
//
// For TouchEvents, these can have any number of TouchEventPoints. If any
// touch-point has a fractional-coordinate but the calculation fails,
// the whole TouchEvent is discarded.
//
// This filter may appear before or after MouseInputFilter in the input
// pipeline, since their actions are mutually-exclusive - MouseInputFilter
// passes through any event with fractional coordinates.
//
// Because this filter may modify the event's x,y values, it may change their
// meaning (from client-provided to host-calculated). Therefore, any other
// filter that cares about x,y values needs to be aware of this transformation.
class FractionalInputFilter : public InputFilter {
 public:
  FractionalInputFilter();
  explicit FractionalInputFilter(InputStub* input_stub);

  FractionalInputFilter(const FractionalInputFilter&) = delete;
  FractionalInputFilter& operator=(const FractionalInputFilter&) = delete;

  ~FractionalInputFilter() override;

  // Sets the video layout to be used to convert fractional coordinates for
  // injection.
  void set_video_layout(const VideoLayout& layout);

  // This method sets the fallback geometry to be used for fractional
  // coordinates which don't have `screen_id`. If no fallback is set (or has
  // empty size), no fallback will be used - events will be dropped if
  // their fractional coordinates don't include any screen_id.
  void set_fallback_geometry(webrtc::DesktopRect geometry);

  // InputStub overrides.
  void InjectMouseEvent(const MouseEvent& event) override;
  void InjectTouchEvent(const TouchEvent& event) override;

 private:
  // Attempts to use the event's fractional coordinates to compute new x,y
  // values for the event. Returns true if successful and new_x, new_y hold the
  // values. The event must be a protobuf type with x, y and
  // fractional_coordinate fields.
  bool ComputeXY(int& new_x, int& new_y, const auto& event);

  VideoLayout video_layout_;

  // webrtc::DesktopRect is a convenient choice because it uses 32-bit values
  // which match the proto definitions for VideoTrackLayout fields.
  webrtc::DesktopRect fallback_geometry_;
};

}  // namespace remoting::protocol

#endif  // REMOTING_PROTOCOL_FRACTIONAL_INPUT_FILTER_H_