• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_
12 #define MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_
13 
14 #include <memory>
15 
16 #include "modules/desktop_capture/desktop_capture_types.h"
17 #include "modules/desktop_capture/desktop_geometry.h"
18 #include "rtc_base/system/rtc_export.h"
19 
20 namespace webrtc {
21 
22 class DesktopCaptureOptions;
23 class DesktopFrame;
24 class MouseCursor;
25 
26 // Captures mouse shape and position.
27 class MouseCursorMonitor {
28  public:
29   // Deprecated: CursorState will not be provided.
30   enum CursorState {
31     // Cursor on top of the window including window decorations.
32     INSIDE,
33 
34     // Cursor is outside of the window.
35     OUTSIDE,
36   };
37 
38   enum Mode {
39     // Capture only shape of the mouse cursor, but not position.
40     SHAPE_ONLY,
41 
42     // Capture both, mouse cursor shape and position.
43     SHAPE_AND_POSITION,
44   };
45 
46   // Callback interface used to pass current mouse cursor position and shape.
47   class Callback {
48    public:
49     // Called in response to Capture() when the cursor shape has changed. Must
50     // take ownership of |cursor|.
51     virtual void OnMouseCursor(MouseCursor* cursor) = 0;
52 
53     // Called in response to Capture(). |position| indicates cursor position
54     // relative to the |window| specified in the constructor.
55     // Deprecated: use the following overload instead.
OnMouseCursorPosition(CursorState state,const DesktopVector & position)56     virtual void OnMouseCursorPosition(CursorState state,
57                                        const DesktopVector& position) {}
58 
59     // Called in response to Capture(). |position| indicates cursor absolute
60     // position on the system in fullscreen coordinate, i.e. the top-left
61     // monitor always starts from (0, 0).
62     // The coordinates of the position is controlled by OS, but it's always
63     // consistent with DesktopFrame.rect().top_left().
64     // TODO(zijiehe): Ensure all implementations return the absolute position.
65     // TODO(zijiehe): Current this overload works correctly only when capturing
66     // mouse cursor against fullscreen.
OnMouseCursorPosition(const DesktopVector & position)67     virtual void OnMouseCursorPosition(const DesktopVector& position) {}
68 
69    protected:
~Callback()70     virtual ~Callback() {}
71   };
72 
~MouseCursorMonitor()73   virtual ~MouseCursorMonitor() {}
74 
75   // Creates a capturer that notifies of mouse cursor events while the cursor is
76   // over the specified window.
77   //
78   // Deprecated: use Create() function.
79   static MouseCursorMonitor* CreateForWindow(
80       const DesktopCaptureOptions& options,
81       WindowId window);
82 
83   // Creates a capturer that monitors the mouse cursor shape and position over
84   // the specified screen.
85   //
86   // Deprecated: use Create() function.
87   static RTC_EXPORT MouseCursorMonitor* CreateForScreen(
88       const DesktopCaptureOptions& options,
89       ScreenId screen);
90 
91   // Creates a capturer that monitors the mouse cursor shape and position across
92   // the entire desktop. The capturer ensures that the top-left monitor starts
93   // from (0, 0).
94   static std::unique_ptr<MouseCursorMonitor> Create(
95       const DesktopCaptureOptions& options);
96 
97   // Initializes the monitor with the |callback|, which must remain valid until
98   // capturer is destroyed.
99   virtual void Init(Callback* callback, Mode mode) = 0;
100 
101   // Captures current cursor shape and position (depending on the |mode| passed
102   // to Init()). Calls Callback::OnMouseCursor() if cursor shape has
103   // changed since the last call (or when Capture() is called for the first
104   // time) and then Callback::OnMouseCursorPosition() if mode is set to
105   // SHAPE_AND_POSITION.
106   virtual void Capture() = 0;
107 };
108 
109 }  // namespace webrtc
110 
111 #endif  // MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_
112