blob: 24dfe72dfa7b9ef59cab6d6c0ee76d13e682b06d [file] [log] [blame]
sergeyu@chromium.orgaf54d4b2013-10-16 02:42:38 +00001/*
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 WEBRTC_MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_
12#define WEBRTC_MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_
13
14#include "webrtc/modules/desktop_capture/desktop_capture_types.h"
15#include "webrtc/modules/desktop_capture/desktop_geometry.h"
16#include "webrtc/typedefs.h"
17
18namespace webrtc {
19
20class DesktopCaptureOptions;
21class DesktopFrame;
22class MouseCursor;
23
24// Captures mouse shape and position.
25class MouseCursorMonitor {
26 public:
27 enum CursorState {
28 // Cursor on top of the window including window decorations.
29 INSIDE,
30
31 // Cursor is outside of the window.
32 OUTSIDE,
33 };
34
35 enum Mode {
36 // Capture only shape of the mouse cursor, but not position.
37 SHAPE_ONLY,
38
39 // Capture both, mouse cursor shape and position.
40 SHAPE_AND_POSITION,
41 };
42
43 // Callback interface used to pass current mouse cursor position and shape.
44 class Callback {
45 public:
46 // Called in response to Capture() when the cursor shape has changed. Must
47 // take ownership of |cursor|.
48 virtual void OnMouseCursor(MouseCursor* cursor) = 0;
49
50 // Called in response to Capture(). |position| indicates cursor position
51 // relative to the |window| specified in the constructor.
52 virtual void OnMouseCursorPosition(CursorState state,
53 const DesktopVector& position) = 0;
54
55 protected:
56 virtual ~Callback() {}
57 };
58
59 virtual ~MouseCursorMonitor() {}
60
61 // Creates a capturer that notifies of mouse cursor events while the cursor is
62 // over the specified window.
63 static MouseCursorMonitor* CreateForWindow(
64 const DesktopCaptureOptions& options,
65 WindowId window);
66
67 // Creates a capturer that monitors the mouse cursor shape and position across
68 // the entire desktop.
69 //
70 // TODO(sergeyu): Provide a way to select a specific screen.
71 static MouseCursorMonitor* CreateForScreen(
jiayl@webrtc.orga2c26542014-01-14 18:26:37 +000072 const DesktopCaptureOptions& options,
73 ScreenId screen);
sergeyu@chromium.orgaf54d4b2013-10-16 02:42:38 +000074
75 // Initializes the monitor with the |callback|, which must remain valid until
76 // capturer is destroyed.
77 virtual void Init(Callback* callback, Mode mode) = 0;
78
79 // Captures current cursor shape and position (depending on the |mode| passed
80 // to Init()). Calls Callback::OnMouseCursor() if cursor shape has
81 // changed since the last call (or when Capture() is called for the first
82 // time) and then Callback::OnMouseCursorPosition() if mode is set to
83 // SHAPE_AND_POSITION.
84 virtual void Capture() = 0;
85};
86
87} // namespace webrtc
88
89#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_H_
90