Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: content/browser/media/capture/cursor_renderer.h

Issue 2553763002: Fix cursor missing in tabCapture on OSX Sierra (Closed)
Patch Set: implement CursorRenderer Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_ 5 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_
6 #define CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_ 6 #define CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/time/default_tick_clock.h"
12 #include "base/time/tick_clock.h"
11 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
12 #include "media/base/video_frame.h" 14 #include "media/base/video_frame.h"
15 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "ui/base/cursor/cursor.h"
13 #include "ui/gfx/native_widget_types.h" 17 #include "ui/gfx/native_widget_types.h"
14 18
15 namespace content { 19 namespace content {
16 20
21 // Setting to control cursor display based on either mouse movement or always
22 // forced to be enabled.
23 enum CursorDisplaySetting {
24 kCursorAlwaysEnabled,
25 kCursorEnabledOnMouseMovement
26 };
27
17 // CursorRenderer is an interface that can be implememented to do cursor 28 // CursorRenderer is an interface that can be implememented to do cursor
miu 2016/12/27 23:21:03 This class comment needs to be updated, since this
braveyao 2017/01/04 01:57:49 Done.
18 // rendering on a video frame. 29 // rendering on a video frame.
19 // 30 //
20 // In order to track the cursor, the platform-specific implementation 31 // In order to track the cursor, the platform-specific implementation
21 // will listen to mouse events. 32 // will listen to mouse events.
22 class CONTENT_EXPORT CursorRenderer { 33 class CONTENT_EXPORT CursorRenderer {
23 public: 34 public:
24 static std::unique_ptr<CursorRenderer> Create(gfx::NativeView view); 35 static std::unique_ptr<CursorRenderer> Create(gfx::NativeView view);
25 36
26 virtual ~CursorRenderer() {} 37 CursorRenderer(gfx::NativeView captured_view,
38 CursorDisplaySetting cursor_display);
39
40 virtual ~CursorRenderer();
27 41
28 // Clears the cursor state being tracked. Called when there is a need to 42 // Clears the cursor state being tracked. Called when there is a need to
29 // reset the state. 43 // reset the state.
30 virtual void Clear() = 0; 44 void Clear();
31 45
32 // Takes a snapshot of the current cursor state and determines whether 46 // Takes a snapshot of the current cursor state and determines whether
33 // the cursor will be rendered, which cursor image to render, and at what 47 // the cursor will be rendered, which cursor image to render, and at what
34 // location within |region_in_frame| to render it. Returns true if cursor 48 // location within |region_in_frame| to render it. Returns true if cursor
35 // needs to be rendered. 49 // needs to be rendered.
36 virtual bool SnapshotCursorState(const gfx::Rect& region_in_frame) = 0; 50 bool SnapshotCursorState(const gfx::Rect& region_in_frame);
37 51
38 // Renders cursor on the |target| video frame. 52 // Renders cursor on the |target| video frame.
39 virtual void RenderOnVideoFrame( 53 void RenderOnVideoFrame(const scoped_refptr<media::VideoFrame>& target) const;
miu 2016/12/27 23:21:03 style nit (per smart pointer guidelines): The old
braveyao 2017/01/04 01:57:49 Done.
40 const scoped_refptr<media::VideoFrame>& target) const = 0;
41 54
42 // Returns a weak pointer. 55 // Returns a weak pointer.
43 virtual base::WeakPtr<CursorRenderer> GetWeakPtr() = 0; 56 base::WeakPtr<CursorRenderer> GetWeakPtr();
44 57
45 protected: 58 protected:
46 enum { 59 enum {
47 // Minium movement before cursor is rendered on frame. 60 // Minium movement before cursor is rendered on frame.
48 MIN_MOVEMENT_PIXELS = 15, 61 MIN_MOVEMENT_PIXELS = 15,
49 // Maximum idle time allowed before we stop rendering the cursor 62 // Maximum idle time allowed before we stop rendering the cursor on frame.
50 // on frame.
51 MAX_IDLE_TIME_SECONDS = 2 63 MAX_IDLE_TIME_SECONDS = 2
52 }; 64 };
65
66 // Returns true if the captured view is a part of an active application
67 // window.
68 virtual bool IsCapturedViewActive() = 0;
69
70 // Returns the size of the captured view (view coordinates).
71 virtual gfx::Size GetCapturedViewSize() = 0;
72
73 // Returns the cursor's position within the captured view (view coordinates).
74 virtual gfx::Point GetCursorPositionInView() = 0;
75
76 // Returns the last-known mouse cursor.
77 virtual gfx::NativeCursor GetLastKnownCursor() = 0;
78
79 // Returns the image of the last-known mouse cursor.
80 virtual SkBitmap GetLastKnownCursorImage() = 0;
81
82 // Returns the hot point (in the cursor image) of the last-known mouse cursor.
83 virtual gfx::Point GetLastKnownCursorHotPoint() = 0;
84
85 // Called by subclasses to report mouse events within the captured view.
86 void OnMouseMoved(const gfx::Point& location, base::TimeTicks timestamp);
87 void OnMouseClicked(const gfx::Point& location, base::TimeTicks timestamp);
88
89 private:
90 friend class CursorRendererAuraTest;
91
92 gfx::NativeView captured_view_;
miu 2016/12/27 23:21:03 nit: Use const since this member doesn't change af
braveyao 2017/01/04 01:57:49 Done.
93
94 // Snapshot of cursor, source size, position, and cursor bitmap; as of the
95 // last call to SnapshotCursorState.
96 gfx::NativeCursor last_cursor_;
97 gfx::Point cursor_position_in_frame_;
98 gfx::Point last_cursor_hot_point_;
99 gfx::Size window_size_when_cursor_last_updated_;
miu 2016/12/27 23:21:03 naming nit: How about |view_size_when_cursor_last_
braveyao 2017/01/04 01:57:49 Done.
100 SkBitmap scaled_cursor_bitmap_;
101
102 // Updated in mouse event listener and used to make a decision on
103 // when the cursor is rendered.
104 base::TimeTicks last_mouse_movement_timestamp_;
105 float last_mouse_position_x_;
106 float last_mouse_position_y_;
107 bool cursor_displayed_;
108
109 // Controls whether cursor is displayed based on active mouse movement.
110 CursorDisplaySetting cursor_display_setting_;
111
112 // Allows tests to replace the clock.
113 base::DefaultTickClock default_tick_clock_;
114 base::TickClock* tick_clock_;
115
116 base::WeakPtrFactory<CursorRenderer> weak_factory_;
117 DISALLOW_COPY_AND_ASSIGN(CursorRenderer);
miu 2016/12/27 23:21:03 nit: Please add a blank line above this line.
braveyao 2017/01/04 01:57:49 Done.
53 }; 118 };
54 119
55 } // namespace content 120 } // namespace content
56 121
57 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_ 122 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_CURSOR_RENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698