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
ash / wm / wm_event.cc [blame]
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/wm_event.h"
#include "ash/wm/window_positioning_utils.h"
#include "ash/wm/wm_metrics.h"
namespace ash {
std::ostream& operator<<(std::ostream& out, WMEventType type) {
switch (type) {
case WM_EVENT_NORMAL:
return out << "WM_EVENT_NORMAL";
case WM_EVENT_MAXIMIZE:
return out << "WM_EVENT_MAXIMIZE";
case WM_EVENT_MINIMIZE:
return out << "WM_EVENT_MINIMIZE";
case WM_EVENT_FULLSCREEN:
return out << "WM_EVENT_FULLSCREEN";
case WM_EVENT_SNAP_PRIMARY:
return out << "WM_EVENT_SNAP_PRIMARY";
case WM_EVENT_SNAP_SECONDARY:
return out << "WM_EVENT_SNAP_SECONDARY";
case WM_EVENT_RESTORE:
return out << "WM_EVENT_RESTORE";
case WM_EVENT_SET_BOUNDS:
return out << "WM_EVENT_SET_BOUNDS";
case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
return out << "WM_EVENT_TOGGLE_MAXIMIZE_CAPTION";
case WM_EVENT_TOGGLE_MAXIMIZE:
return out << "WM_EVENT_TOGGLE_MAXIMIZE";
case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
return out << "WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE";
case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
return out << "WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE";
case WM_EVENT_TOGGLE_FULLSCREEN:
return out << "WM_EVENT_TOGGLE_FULLSCREEN";
case WM_EVENT_CYCLE_SNAP_PRIMARY:
return out << "WM_EVENT_CYCLE_SNAP_PRIMARY";
case WM_EVENT_CYCLE_SNAP_SECONDARY:
return out << "WM_EVENT_CYCLE_SNAP_SECONDARY";
case WM_EVENT_SHOW_INACTIVE:
return out << "WM_EVENT_SHOW_INACTIVE";
case WM_EVENT_ADDED_TO_WORKSPACE:
return out << "WM_EVENT_ADDED_TO_WORKSPACE";
case WM_EVENT_DISPLAY_METRICS_CHANGED:
return out << "WM_EVENT_DISPLAY_METRICS_CHANGED";
case WM_EVENT_PIN:
return out << "WM_EVENT_PIN";
case WM_EVENT_PIP:
return out << "WM_EVENT_PIP";
case WM_EVENT_TRUSTED_PIN:
return out << "WM_EVENT_TRUSTED_PIN";
case WM_EVENT_FLOAT:
return out << "WM_EVENT_FLOAT";
}
}
WMEvent::WMEvent(WMEventType type) : type_(type) {
CHECK(IsWorkspaceEvent() || IsCompoundEvent() || IsBoundsEvent() ||
IsTransitionEvent());
}
WMEvent::~WMEvent() = default;
bool WMEvent::IsWorkspaceEvent() const {
switch (type_) {
case WM_EVENT_ADDED_TO_WORKSPACE:
case WM_EVENT_DISPLAY_METRICS_CHANGED:
return true;
default:
break;
}
return false;
}
bool WMEvent::IsCompoundEvent() const {
switch (type_) {
case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
case WM_EVENT_TOGGLE_MAXIMIZE:
case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
case WM_EVENT_TOGGLE_FULLSCREEN:
case WM_EVENT_CYCLE_SNAP_PRIMARY:
case WM_EVENT_CYCLE_SNAP_SECONDARY:
return true;
default:
break;
}
return false;
}
bool WMEvent::IsPinEvent() const {
switch (type_) {
case WM_EVENT_PIN:
case WM_EVENT_TRUSTED_PIN:
return true;
default:
break;
}
return false;
}
bool WMEvent::IsBoundsEvent() const {
return type_ == WM_EVENT_SET_BOUNDS;
}
bool WMEvent::IsTransitionEvent() const {
switch (type_) {
case WM_EVENT_NORMAL:
case WM_EVENT_MAXIMIZE:
case WM_EVENT_MINIMIZE:
case WM_EVENT_FULLSCREEN:
case WM_EVENT_SNAP_PRIMARY:
case WM_EVENT_SNAP_SECONDARY:
case WM_EVENT_RESTORE:
case WM_EVENT_SHOW_INACTIVE:
case WM_EVENT_PIN:
case WM_EVENT_TRUSTED_PIN:
case WM_EVENT_PIP:
case WM_EVENT_FLOAT:
return true;
default:
break;
}
return false;
}
bool WMEvent::IsSnapEvent() const {
switch (type_) {
case WM_EVENT_SNAP_PRIMARY:
case WM_EVENT_SNAP_SECONDARY:
case WM_EVENT_CYCLE_SNAP_PRIMARY:
case WM_EVENT_CYCLE_SNAP_SECONDARY:
return true;
default:
break;
}
return false;
}
const SetBoundsWMEvent* WMEvent::AsSetBoundsWMEvent() const {
return nullptr;
}
const DisplayMetricsChangedWMEvent* WMEvent::AsDisplayMetricsChangedWMEvent()
const {
CHECK_EQ(type(), WM_EVENT_DISPLAY_METRICS_CHANGED);
return static_cast<const DisplayMetricsChangedWMEvent*>(this);
}
const WindowFloatWMEvent* WMEvent::AsFloatEvent() const {
return nullptr;
}
const WindowSnapWMEvent* WMEvent::AsSnapEvent() const {
return nullptr;
}
SetBoundsWMEvent::SetBoundsWMEvent(const gfx::Rect& bounds,
bool animate,
base::TimeDelta duration)
: WMEvent(WM_EVENT_SET_BOUNDS),
requested_bounds_in_parent_(bounds),
animate_(animate),
duration_(duration) {}
SetBoundsWMEvent::SetBoundsWMEvent(const gfx::Rect& requested_bounds_in_parent,
int64_t display_id)
: WMEvent(WM_EVENT_SET_BOUNDS),
requested_bounds_in_parent_(requested_bounds_in_parent),
display_id_(display_id),
animate_(false) {}
SetBoundsWMEvent::~SetBoundsWMEvent() = default;
const SetBoundsWMEvent* SetBoundsWMEvent::AsSetBoundsWMEvent() const {
return this;
}
DisplayMetricsChangedWMEvent::DisplayMetricsChangedWMEvent(int changed_metrics)
: WMEvent(WM_EVENT_DISPLAY_METRICS_CHANGED),
changed_metrics_(changed_metrics) {}
DisplayMetricsChangedWMEvent::~DisplayMetricsChangedWMEvent() = default;
WindowFloatWMEvent::WindowFloatWMEvent(
chromeos::FloatStartLocation float_start_location)
: WMEvent(WM_EVENT_FLOAT), float_start_location_(float_start_location) {}
WindowFloatWMEvent::~WindowFloatWMEvent() = default;
const WindowFloatWMEvent* WindowFloatWMEvent::AsFloatEvent() const {
return this;
}
WindowSnapWMEvent::WindowSnapWMEvent(WMEventType type)
: WindowSnapWMEvent(type,
chromeos::kDefaultSnapRatio,
WindowSnapActionSource::kNotSpecified) {}
WindowSnapWMEvent::WindowSnapWMEvent(WMEventType type, float snap_ratio)
: WindowSnapWMEvent(type,
snap_ratio,
WindowSnapActionSource::kNotSpecified) {}
WindowSnapWMEvent::WindowSnapWMEvent(WMEventType type,
WindowSnapActionSource snap_action_source)
: WindowSnapWMEvent(type, chromeos::kDefaultSnapRatio, snap_action_source) {
}
WindowSnapWMEvent::WindowSnapWMEvent(WMEventType type,
float snap_ratio,
WindowSnapActionSource snap_action_source)
: WMEvent(type),
snap_ratio_(snap_ratio),
snap_action_source_(snap_action_source) {
CHECK(IsSnapEvent());
}
WindowSnapWMEvent::~WindowSnapWMEvent() = default;
const WindowSnapWMEvent* WindowSnapWMEvent::AsSnapEvent() const {
return this;
}
} // namespace ash