forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenshot_controller.h
142 lines (110 loc) · 4.6 KB
/
screenshot_controller.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_UTILITY_SCREENSHOT_CONTROLLER_H_
#define ASH_UTILITY_SCREENSHOT_CONTROLLER_H_
#include <stdint.h>
#include <map>
#include <memory>
#include "ash/ash_export.h"
#include "ash/common/shell_observer.h"
#include "base/callback.h"
#include "base/macros.h"
#include "ui/aura/window_observer.h"
#include "ui/display/display_observer.h"
#include "ui/events/event_handler.h"
#include "ui/gfx/geometry/point.h"
namespace aura {
class Window;
}
namespace ui {
class LocatedEvent;
struct PointerDetails;
}
namespace ash {
class ScreenshotDelegate;
// This class controls a session of taking partial/window screenshot, i.e.:
// drawing
// region rectangles during selection, and changing the mouse cursor to indicate
// the current mode.
// This class does not use aura::Window / views::Widget intentionally to avoid
class ASH_EXPORT ScreenshotController : public ui::EventHandler,
public display::DisplayObserver,
public aura::WindowObserver {
public:
ScreenshotController();
~ScreenshotController() override;
// Starts the UI for taking partial screenshot; dragging to select a region.
// ScreenshotController manage their own lifetime so caller must not
// delete the returned values. |draw_overlay_immediately| controls if the grey
// overlay will be drawn immediately. If false, then the overlay will be drawn
// only after the user has started creating the clipping rect for the
// screenshot.
void StartPartialScreenshotSession(ScreenshotDelegate* screenshot_delegate,
bool draw_overlay_immediately);
// Starts the UI for taking a window screenshot;
void StartWindowScreenshotSession(ScreenshotDelegate* screenshot_delegate);
// Cancels any active screenshot session.
void CancelScreenshotSession();
// Set a function that will be called when the current screenshot session has
// been completed or cancelled. This is reset after the screenshot session is
// done.
void set_on_screenshot_session_done(const base::Closure& on_done) {
on_screenshot_session_done_ = on_done;
}
// If set to true, then only events generated by a pen can be used to select
// the area to take a screenshot of. This is reset to false after a screenshot
// operation is completed.
void set_pen_events_only(bool pen_events_only) {
pen_events_only_ = pen_events_only;
}
bool pen_events_only() const { return pen_events_only_; }
private:
enum Mode {
NONE,
PARTIAL,
WINDOW,
};
friend class ScreenshotControllerTest;
class ScopedCursorSetter;
class ScreenshotLayer;
// Starts, ends, cancels, or updates the region selection.
void MaybeStart(const ui::LocatedEvent& event);
void CompleteWindowScreenshot();
void CompletePartialScreenshot();
void Update(const ui::LocatedEvent& event);
void UpdateSelectedWindow(ui::LocatedEvent* event);
void SetSelectedWindow(aura::Window* window);
// Returns true if the event should be processed.
bool ShouldProcessEvent(const ui::PointerDetails& pointer_details) const;
// ui::EventHandler:
void OnKeyEvent(ui::KeyEvent* event) override;
void OnMouseEvent(ui::MouseEvent* event) override;
void OnTouchEvent(ui::TouchEvent* event) override;
// display::DisplayObserver:
void OnDisplayAdded(const display::Display& new_display) override;
void OnDisplayRemoved(const display::Display& old_display) override;
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics) override;
// aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override;
Mode mode_;
// If true, then only pointer events will be used when selecting the
// screenshot region.
bool pen_events_only_ = false;
base::Closure on_screenshot_session_done_;
// The data to build the screenshot region.
gfx::Point start_position_;
aura::Window* root_window_;
// Currently selected window in WINDOW mode.
aura::Window* selected_;
// Layers to create the visual effect of region selection or selected window.
std::map<aura::Window*, std::unique_ptr<ScreenshotLayer>> layers_;
// The object to specify the crosshair cursor.
std::unique_ptr<ScopedCursorSetter> cursor_setter_;
// ScreenshotDelegate to take the actual screenshot. No ownership.
ScreenshotDelegate* screenshot_delegate_;
DISALLOW_COPY_AND_ASSIGN(ScreenshotController);
};
} // namespace ash
#endif // ASH_UTILITY_SCREENSHOT_CONTROLLER_H_