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
|
// 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 "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/platform_window/platform_window_delegate.h"
#include "ui/views/mus/window_manager_connection.h"
namespace views {
PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate,
mus::Window* mus_window)
: delegate_(delegate),
mus_window_(mus_window),
show_state_(mus::mojom::SHOW_STATE_RESTORED),
has_capture_(false) {
DCHECK(delegate_);
DCHECK(mus_window_);
mus_window_->AddObserver(this);
delegate_->OnAcceleratedWidgetAvailable(
gfx::kNullAcceleratedWidget,
mus_window_->viewport_metrics().device_pixel_ratio);
}
PlatformWindowMus::~PlatformWindowMus() {
if (!mus_window_)
return;
mus_window_->RemoveObserver(this);
mus_window_->Destroy();
}
void PlatformWindowMus::Activate() {
mus_window_->SetFocus();
}
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() {
// TODO(sky): this is wrong, need real capture api.
has_capture_ = true;
NOTIMPLEMENTED();
}
void PlatformWindowMus::ReleaseCapture() {
// TODO(sky): this is wrong, need real capture api.
has_capture_ = false;
NOTIMPLEMENTED();
}
void PlatformWindowMus::ToggleFullscreen() {
NOTIMPLEMENTED();
}
void PlatformWindowMus::Maximize() {
SetShowState(mus::mojom::SHOW_STATE_MAXIMIZED);
}
void PlatformWindowMus::Minimize() {
SetShowState(mus::mojom::SHOW_STATE_MINIMIZED);
}
void PlatformWindowMus::Restore() {
SetShowState(mus::mojom::SHOW_STATE_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, show_state);
}
void PlatformWindowMus::OnWindowDestroyed(mus::Window* window) {
DCHECK_EQ(mus_window_, window);
delegate_->OnClosed();
mus_window_ = nullptr;
}
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::OnWindowInputEvent(mus::Window* view,
const mus::mojom::EventPtr& event) {
scoped_ptr<ui::Event> ui_event(event.To<scoped_ptr<ui::Event>>());
delegate_->DispatchEvent(ui_event.get());
}
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::SHOW_STATE_MINIMIZED:
state = ui::PLATFORM_WINDOW_STATE_MINIMIZED;
break;
case mus::mojom::SHOW_STATE_MAXIMIZED:
state = ui::PLATFORM_WINDOW_STATE_MAXIMIZED;
break;
case mus::mojom::SHOW_STATE_RESTORED:
state = ui::PLATFORM_WINDOW_STATE_NORMAL;
break;
case mus::mojom::SHOW_STATE_IMMERSIVE:
case mus::mojom::SHOW_STATE_PRESENTATION:
// This may not be sufficient.
state = ui::PLATFORM_WINDOW_STATE_FULLSCREEN;
break;
}
delegate_->OnWindowStateChanged(state);
}
} // namespace views
|