blob: 8d92d53c4e0044b7a4122d28fcfded70f3ac10a8 [file] [log] [blame]
dgozman1137e622017-04-17 19:49:121// 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
8#include "base/callback.h"
9#include "base/macros.h"
10#include "content/public/browser/readback_types.h"
11#include "content/public/browser/render_widget_host.h"
12#include "content/public/browser/web_contents_observer.h"
13#include "third_party/skia/include/core/SkBitmap.h"
14
15namespace blink {
16class WebMouseEvent;
17}
18
19class DevToolsEyeDropper : public content::WebContentsObserver {
20 public:
21 typedef base::Callback<void(int, int, int, int)> EyeDropperCallback;
22
23 DevToolsEyeDropper(content::WebContents* web_contents,
24 EyeDropperCallback callback);
25 ~DevToolsEyeDropper() override;
26
27 private:
28 void AttachToHost(content::RenderWidgetHost* host);
29 void DetachFromHost();
30
31 // content::WebContentsObserver.
32 void DidReceiveCompositorFrame() override;
33 void RenderViewCreated(content::RenderViewHost* host) override;
34 void RenderViewDeleted(content::RenderViewHost* host) override;
35 void RenderViewHostChanged(content::RenderViewHost* old_host,
36 content::RenderViewHost* new_host) override;
37
38 void UpdateFrame();
39 void ResetFrame();
40 void FrameUpdated(const SkBitmap&, content::ReadbackResponse);
41 bool HandleMouseEvent(const blink::WebMouseEvent& event);
42 void UpdateCursor();
43
44 EyeDropperCallback callback_;
45 SkBitmap frame_;
46 int last_cursor_x_;
47 int last_cursor_y_;
48 content::RenderWidgetHost::MouseEventCallback mouse_event_callback_;
49 content::RenderWidgetHost* host_;
50 base::WeakPtrFactory<DevToolsEyeDropper> weak_factory_;
51
52 DISALLOW_COPY_AND_ASSIGN(DevToolsEyeDropper);
53};
54
55#endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EYE_DROPPER_H_