dgozman | 1137e62 | 2017-04-17 19:49:12 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EYE_DROPPER_H_ |
| 6 | #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EYE_DROPPER_H_ |
| 7 | |
Yuri Wiitala | fc5fe70 | 2018-06-20 06:14:00 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
dgozman | 1137e62 | 2017-04-17 19:49:12 | [diff] [blame] | 10 | #include "base/callback.h" |
| 11 | #include "base/macros.h" |
Saman Sami | d2dc25f | 2018-05-24 20:41:07 | [diff] [blame] | 12 | #include "components/viz/host/client_frame_sink_video_capturer.h" |
dgozman | 1137e62 | 2017-04-17 19:49:12 | [diff] [blame] | 13 | #include "content/public/browser/render_widget_host.h" |
| 14 | #include "content/public/browser/web_contents_observer.h" |
| 15 | #include "third_party/skia/include/core/SkBitmap.h" |
| 16 | |
| 17 | namespace blink { |
| 18 | class WebMouseEvent; |
| 19 | } |
| 20 | |
Saman Sami | 2acabd1 | 2018-03-10 00:51:09 | [diff] [blame] | 21 | class DevToolsEyeDropper : public content::WebContentsObserver, |
| 22 | public viz::mojom::FrameSinkVideoConsumer { |
dgozman | 1137e62 | 2017-04-17 19:49:12 | [diff] [blame] | 23 | public: |
| 24 | typedef base::Callback<void(int, int, int, int)> EyeDropperCallback; |
| 25 | |
| 26 | DevToolsEyeDropper(content::WebContents* web_contents, |
| 27 | EyeDropperCallback callback); |
| 28 | ~DevToolsEyeDropper() override; |
| 29 | |
| 30 | private: |
| 31 | void AttachToHost(content::RenderWidgetHost* host); |
| 32 | void DetachFromHost(); |
| 33 | |
| 34 | // content::WebContentsObserver. |
dgozman | 1137e62 | 2017-04-17 19:49:12 | [diff] [blame] | 35 | void RenderViewCreated(content::RenderViewHost* host) override; |
| 36 | void RenderViewDeleted(content::RenderViewHost* host) override; |
| 37 | void RenderViewHostChanged(content::RenderViewHost* old_host, |
| 38 | content::RenderViewHost* new_host) override; |
| 39 | |
dgozman | 1137e62 | 2017-04-17 19:49:12 | [diff] [blame] | 40 | void ResetFrame(); |
Yuri Wiitala | 6a4443f0 | 2018-02-27 22:29:27 | [diff] [blame] | 41 | void FrameUpdated(const SkBitmap&); |
dgozman | 1137e62 | 2017-04-17 19:49:12 | [diff] [blame] | 42 | bool HandleMouseEvent(const blink::WebMouseEvent& event); |
| 43 | void UpdateCursor(); |
| 44 | |
Saman Sami | 2acabd1 | 2018-03-10 00:51:09 | [diff] [blame] | 45 | // viz::mojom::FrameSinkVideoConsumer implementation. |
| 46 | void OnFrameCaptured( |
Yuri Wiitala | 4a74fb0 | 2018-08-29 06:09:35 | [diff] [blame] | 47 | base::ReadOnlySharedMemoryRegion data, |
Saman Sami | 2acabd1 | 2018-03-10 00:51:09 | [diff] [blame] | 48 | ::media::mojom::VideoFrameInfoPtr info, |
Saman Sami | 2acabd1 | 2018-03-10 00:51:09 | [diff] [blame] | 49 | const gfx::Rect& content_rect, |
| 50 | viz::mojom::FrameSinkVideoConsumerFrameCallbacksPtr callbacks) override; |
Saman Sami | 2acabd1 | 2018-03-10 00:51:09 | [diff] [blame] | 51 | void OnStopped() override; |
| 52 | |
dgozman | 1137e62 | 2017-04-17 19:49:12 | [diff] [blame] | 53 | EyeDropperCallback callback_; |
| 54 | SkBitmap frame_; |
| 55 | int last_cursor_x_; |
| 56 | int last_cursor_y_; |
| 57 | content::RenderWidgetHost::MouseEventCallback mouse_event_callback_; |
| 58 | content::RenderWidgetHost* host_; |
Saman Sami | d2dc25f | 2018-05-24 20:41:07 | [diff] [blame] | 59 | std::unique_ptr<viz::ClientFrameSinkVideoCapturer> video_capturer_; |
Jeremy Roman | 495db68 | 2019-07-12 16:03:24 | [diff] [blame] | 60 | base::WeakPtrFactory<DevToolsEyeDropper> weak_factory_{this}; |
dgozman | 1137e62 | 2017-04-17 19:49:12 | [diff] [blame] | 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(DevToolsEyeDropper); |
| 63 | }; |
| 64 | |
| 65 | #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EYE_DROPPER_H_ |