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
headless / lib / browser / headless_window_tree_host.cc [blame]
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "headless/lib/browser/headless_window_tree_host.h"
#include <memory>
#include "base/containers/flat_set.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "headless/lib/browser/headless_focus_client.h"
#include "headless/lib/browser/headless_window_parenting_client.h"
#include "ui/aura/window.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/gfx/icc_profile.h"
namespace headless {
HeadlessWindowTreeHost::HeadlessWindowTreeHost(
bool use_external_begin_frame_control) {
CreateCompositor(false, use_external_begin_frame_control);
OnAcceleratedWidgetAvailable();
focus_client_ = std::make_unique<HeadlessFocusClient>();
aura::client::SetFocusClient(window(), focus_client_.get());
}
HeadlessWindowTreeHost::~HeadlessWindowTreeHost() {
window_parenting_client_.reset();
DestroyCompositor();
DestroyDispatcher();
}
void HeadlessWindowTreeHost::SetParentWindow(gfx::NativeWindow window) {
window_parenting_client_ =
std::make_unique<HeadlessWindowParentingClient>(window);
}
bool HeadlessWindowTreeHost::CanDispatchEvent(const ui::PlatformEvent& event) {
return false;
}
uint32_t HeadlessWindowTreeHost::DispatchEvent(const ui::PlatformEvent& event) {
return 0;
}
ui::EventSource* HeadlessWindowTreeHost::GetEventSource() {
return this;
}
gfx::AcceleratedWidget HeadlessWindowTreeHost::GetAcceleratedWidget() {
return gfx::AcceleratedWidget();
}
gfx::Rect HeadlessWindowTreeHost::GetBoundsInPixels() const {
return bounds_;
}
void HeadlessWindowTreeHost::SetBoundsInPixels(const gfx::Rect& bounds) {
if (bounds_ == bounds) {
return;
}
bool origin_changed = bounds_.origin() != bounds.origin();
bounds_ = bounds;
if (origin_changed) {
OnHostMovedInPixels();
}
// Report host size even if it is not changing to ensure the compositor layers
// are updated. Optimizing this away causes Page.captureScreenshot() to hang
// indefinitely. See https://crbug.com/40571433.
OnHostResizedInPixels(bounds.size());
}
void HeadlessWindowTreeHost::ShowImpl() {}
void HeadlessWindowTreeHost::HideImpl() {}
gfx::Point HeadlessWindowTreeHost::GetLocationOnScreenInPixels() const {
return bounds_.origin();
}
void HeadlessWindowTreeHost::SetCapture() {}
void HeadlessWindowTreeHost::ReleaseCapture() {}
bool HeadlessWindowTreeHost::CaptureSystemKeyEventsImpl(
std::optional<base::flat_set<ui::DomCode>> codes) {
return false;
}
void HeadlessWindowTreeHost::ReleaseSystemKeyEventCapture() {}
bool HeadlessWindowTreeHost::IsKeyLocked(ui::DomCode dom_code) {
return false;
}
base::flat_map<std::string, std::string>
HeadlessWindowTreeHost::GetKeyboardLayoutMap() {
NOTIMPLEMENTED();
return {};
}
void HeadlessWindowTreeHost::SetCursorNative(gfx::NativeCursor cursor_type) {}
void HeadlessWindowTreeHost::MoveCursorToScreenLocationInPixels(
const gfx::Point& location) {}
void HeadlessWindowTreeHost::OnCursorVisibilityChangedNative(bool show) {}
#if BUILDFLAG(IS_CHROMEOS_LACROS)
std::string HeadlessWindowTreeHost::GetUniqueId() const {
// Headless does not have a unique ID
NOTIMPLEMENTED_LOG_ONCE();
return std::string();
}
#endif
} // namespace headless