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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
// Copyright 2015 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.
#include "ui/views/mus/platform_window_mus.h"
#include "build/build_config.h"
#include "components/bitmap_uploader/bitmap_uploader.h"
#include "components/mus/public/cpp/property_type_converters.h"
#include "components/mus/public/cpp/window_property.h"
#include "components/mus/public/interfaces/window_manager.mojom.h"
#include "mojo/converters/input_events/input_events_type_converters.h"
#include "ui/base/view_prop.h"
#include "ui/platform_window/platform_window_delegate.h"
#include "ui/views/mus/window_manager_connection.h"
namespace views {
namespace {
static uint32_t accelerated_widget_count = 1;
} // namespace
PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate,
mojo::Connector* connector,
mus::Window* mus_window)
: delegate_(delegate),
mus_window_(mus_window),
show_state_(mus::mojom::ShowState::RESTORED),
last_cursor_(mus::mojom::Cursor::CURSOR_NULL),
mus_window_destroyed_(false) {
DCHECK(delegate_);
DCHECK(mus_window_);
mus_window_->AddObserver(this);
mus_window_->set_input_event_handler(this);
// We need accelerated widget numbers to be different for each
// window and fit in the smallest sizeof(AcceleratedWidget) uint32_t
// has this property.
#if defined(OS_WIN) || defined(OS_ANDROID)
gfx::AcceleratedWidget accelerated_widget =
reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++);
#else
gfx::AcceleratedWidget accelerated_widget =
static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++);
#endif
delegate_->OnAcceleratedWidgetAvailable(
accelerated_widget, mus_window_->viewport_metrics().device_pixel_ratio);
bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(mus_window_));
bitmap_uploader_->Init(connector);
prop_.reset(new ui::ViewProp(
accelerated_widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget,
bitmap_uploader_.get()));
}
PlatformWindowMus::~PlatformWindowMus() {
if (!mus_window_)
return;
mus_window_->RemoveObserver(this);
mus_window_->set_input_event_handler(nullptr);
if (!mus_window_destroyed_)
mus_window_->Destroy();
}
void PlatformWindowMus::Activate() {
mus_window_->SetFocus();
}
void PlatformWindowMus::SetCursorById(mus::mojom::Cursor cursor) {
if (last_cursor_ != cursor) {
// The ui::PlatformWindow interface uses ui::PlatformCursor at this level,
// instead of ui::Cursor. All of the cursor abstractions in ui right now are
// sort of leaky; despite being nominally cross platform, they all drop down
// to platform types almost immediately, which makes them unusable as
// transport types.
mus_window_->SetPredefinedCursor(cursor);
}
}
void PlatformWindowMus::Show() {
mus_window_->SetVisible(true);
}
void PlatformWindowMus::Hide() {
mus_window_->SetVisible(false);
}
void PlatformWindowMus::Close() {
NOTIMPLEMENTED();
}
void PlatformWindowMus::SetBounds(const gfx::Rect& bounds) {
mus_window_->SetBounds(bounds);
}
gfx::Rect PlatformWindowMus::GetBounds() {
return mus_window_->bounds();
}
void PlatformWindowMus::SetTitle(const base::string16& title) {
NOTIMPLEMENTED();
}
void PlatformWindowMus::SetCapture() {
mus_window_->SetCapture();
}
void PlatformWindowMus::ReleaseCapture() {
mus_window_->ReleaseCapture();
}
void PlatformWindowMus::ToggleFullscreen() {
NOTIMPLEMENTED();
}
void PlatformWindowMus::Maximize() {
SetShowState(mus::mojom::ShowState::MAXIMIZED);
}
void PlatformWindowMus::Minimize() {
SetShowState(mus::mojom::ShowState::MINIMIZED);
}
void PlatformWindowMus::Restore() {
SetShowState(mus::mojom::ShowState::RESTORED);
}
void PlatformWindowMus::SetCursor(ui::PlatformCursor cursor) {
NOTIMPLEMENTED();
}
void PlatformWindowMus::MoveCursorTo(const gfx::Point& location) {
NOTIMPLEMENTED();
}
void PlatformWindowMus::ConfineCursorToBounds(const gfx::Rect& bounds) {
NOTIMPLEMENTED();
}
ui::PlatformImeController* PlatformWindowMus::GetPlatformImeController() {
return nullptr;
}
void PlatformWindowMus::SetShowState(mus::mojom::ShowState show_state) {
mus_window_->SetSharedProperty<int32_t>(
mus::mojom::WindowManager::kShowState_Property,
static_cast<int32_t>(show_state));
}
void PlatformWindowMus::OnWindowDestroyed(mus::Window* window) {
DCHECK_EQ(mus_window_, window);
mus_window_destroyed_ = true;
#ifndef NDEBUG
weak_factory_.reset(new base::WeakPtrFactory<PlatformWindowMus>(this));
base::WeakPtr<PlatformWindowMus> weak_ptr = weak_factory_->GetWeakPtr();
#endif
delegate_->OnClosed();
// |this| has been destroyed at this point.
#ifndef NDEBUG
DCHECK(!weak_ptr);
#endif
}
void PlatformWindowMus::OnWindowBoundsChanged(mus::Window* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
delegate_->OnBoundsChanged(new_bounds);
}
void PlatformWindowMus::OnWindowFocusChanged(mus::Window* gained_focus,
mus::Window* lost_focus) {
if (gained_focus == mus_window_)
delegate_->OnActivationChanged(true);
else if (lost_focus == mus_window_)
delegate_->OnActivationChanged(false);
}
void PlatformWindowMus::OnWindowPredefinedCursorChanged(
mus::Window* window,
mus::mojom::Cursor cursor) {
DCHECK_EQ(window, mus_window_);
last_cursor_ = cursor;
}
void PlatformWindowMus::OnWindowSharedPropertyChanged(
mus::Window* window,
const std::string& name,
const std::vector<uint8_t>* old_data,
const std::vector<uint8_t>* new_data) {
if (name != mus::mojom::WindowManager::kShowState_Property)
return;
mus::mojom::ShowState show_state =
static_cast<mus::mojom::ShowState>(window->GetSharedProperty<int32_t>(
mus::mojom::WindowManager::kShowState_Property));
if (show_state == show_state_)
return;
show_state_ = show_state;
ui::PlatformWindowState state = ui::PLATFORM_WINDOW_STATE_UNKNOWN;
switch (show_state_) {
case mus::mojom::ShowState::MINIMIZED:
state = ui::PLATFORM_WINDOW_STATE_MINIMIZED;
break;
case mus::mojom::ShowState::MAXIMIZED:
state = ui::PLATFORM_WINDOW_STATE_MAXIMIZED;
break;
case mus::mojom::ShowState::RESTORED:
state = ui::PLATFORM_WINDOW_STATE_NORMAL;
break;
case mus::mojom::ShowState::IMMERSIVE:
case mus::mojom::ShowState::PRESENTATION:
// This may not be sufficient.
state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN;
break;
}
delegate_->OnWindowStateChanged(state);
}
void PlatformWindowMus::OnRequestClose(mus::Window* window) {
delegate_->OnCloseRequest();
}
void PlatformWindowMus::OnWindowInputEvent(
mus::Window* view,
const ui::Event& event,
scoped_ptr<base::Callback<void(bool)>>* ack_callback) {
// It's possible dispatching the event will spin a nested message loop. Ack
// the callback now, otherwise we appear unresponsive for the life of the
// nested message loop.
(*ack_callback)->Run(true);
ack_callback->reset();
// TODO(moshayedi): Avoid cloning after updating PlatformWindowDelegate to
// accept constant pointers.
delegate_->DispatchEvent(ui::Event::Clone(event).get());
}
} // namespace views
|