OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/wm_window.h" | |
6 | |
7 #include "ash/ash_constants.h" | |
8 #include "ash/public/cpp/config.h" | |
9 #include "ash/public/cpp/shell_window_ids.h" | |
10 #include "ash/public/cpp/window_properties.h" | |
11 #include "ash/root_window_controller.h" | |
12 #include "ash/shell.h" | |
13 #include "ash/wm/resize_handle_window_targeter.h" | |
14 #include "ash/wm/widget_finder.h" | |
15 #include "ash/wm/window_animations.h" | |
16 #include "ash/wm/window_properties.h" | |
17 #include "ash/wm/window_state.h" | |
18 #include "ash/wm/window_util.h" | |
19 #include "ash/wm_transient_window_observer.h" | |
20 #include "base/memory/ptr_util.h" | |
21 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | |
22 #include "ui/aura/client/aura_constants.h" | |
23 #include "ui/aura/client/focus_client.h" | |
24 #include "ui/aura/client/window_parenting_client.h" | |
25 #include "ui/aura/layout_manager.h" | |
26 #include "ui/aura/mus/window_manager_delegate.h" | |
27 #include "ui/aura/mus/window_mus.h" | |
28 #include "ui/aura/mus/window_tree_client.h" | |
29 #include "ui/aura/window.h" | |
30 #include "ui/aura/window_delegate.h" | |
31 #include "ui/aura/window_observer.h" | |
32 #include "ui/base/class_property.h" | |
33 #include "ui/base/hit_test.h" | |
34 #include "ui/compositor/layer_tree_owner.h" | |
35 #include "ui/compositor/scoped_layer_animation_settings.h" | |
36 #include "ui/display/screen.h" | |
37 #include "ui/gfx/geometry/insets.h" | |
38 #include "ui/views/widget/widget.h" | |
39 #include "ui/views/widget/widget_delegate.h" | |
40 #include "ui/wm/core/coordinate_conversion.h" | |
41 #include "ui/wm/core/easy_resize_window_targeter.h" | |
42 #include "ui/wm/core/ime_util_chromeos.h" | |
43 #include "ui/wm/core/transient_window_manager.h" | |
44 #include "ui/wm/core/visibility_controller.h" | |
45 #include "ui/wm/core/window_util.h" | |
46 | |
47 DECLARE_UI_CLASS_PROPERTY_TYPE(ash::WmWindow*); | |
48 | |
49 namespace ash { | |
50 namespace { | |
51 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(WmWindow, kWmWindowKey, nullptr); | |
52 | |
53 static_assert(aura::Window::kInitialId == kShellWindowId_Invalid, | |
54 "ids must match"); | |
55 | |
56 } // namespace | |
57 | |
58 WmWindow::~WmWindow() { | |
59 if (added_transient_observer_) | |
60 ::wm::TransientWindowManager::Get(window_)->RemoveObserver(this); | |
61 } | |
62 | |
63 // static | |
64 const WmWindow* WmWindow::Get(const aura::Window* window) { | |
65 if (!window) | |
66 return nullptr; | |
67 | |
68 const WmWindow* wm_window = window->GetProperty(kWmWindowKey); | |
69 if (wm_window) | |
70 return wm_window; | |
71 // WmWindow is owned by the aura::Window. | |
72 // TODO(sky): fix constness. | |
73 return new WmWindow(const_cast<aura::Window*>(window)); | |
74 } | |
75 | |
76 // static | |
77 std::vector<WmWindow*> WmWindow::FromAuraWindows( | |
78 const std::vector<aura::Window*>& aura_windows) { | |
79 std::vector<WmWindow*> result(aura_windows.size()); | |
80 for (size_t i = 0; i < aura_windows.size(); ++i) | |
81 result[i] = Get(aura_windows[i]); | |
82 return result; | |
83 } | |
84 | |
85 // static | |
86 std::vector<aura::Window*> WmWindow::ToAuraWindows( | |
87 const std::vector<WmWindow*>& windows) { | |
88 std::vector<aura::Window*> result(windows.size()); | |
89 for (size_t i = 0; i < windows.size(); ++i) | |
90 result[i] = WmWindow::GetAuraWindow(windows[i]); | |
91 return result; | |
92 } | |
93 | |
94 // static | |
95 const aura::Window* WmWindow::GetAuraWindow(const WmWindow* wm_window) { | |
96 return wm_window ? static_cast<const WmWindow*>(wm_window)->aura_window() | |
97 : nullptr; | |
98 } | |
99 | |
100 void WmWindow::Destroy() { | |
101 delete window_; | |
102 // WARNING: this has been deleted. | |
103 } | |
104 | |
105 const WmWindow* WmWindow::GetRootWindow() const { | |
106 return Get(window_->GetRootWindow()); | |
107 } | |
108 | |
109 RootWindowController* WmWindow::GetRootWindowController() { | |
110 aura::Window* root = window_->GetRootWindow(); | |
111 return root ? RootWindowController::ForWindow(root) : nullptr; | |
112 } | |
113 | |
114 aura::client::WindowType WmWindow::GetType() const { | |
115 return window_->type(); | |
116 } | |
117 | |
118 int WmWindow::GetAppType() const { | |
119 return window_->GetProperty(aura::client::kAppType); | |
120 } | |
121 | |
122 void WmWindow::SetAppType(int app_type) const { | |
123 window_->SetProperty(aura::client::kAppType, app_type); | |
124 } | |
125 | |
126 ui::Layer* WmWindow::GetLayer() { | |
127 return window_->layer(); | |
128 } | |
129 | |
130 bool WmWindow::GetLayerTargetVisibility() { | |
131 return GetLayer()->GetTargetVisibility(); | |
132 } | |
133 | |
134 bool WmWindow::GetLayerVisible() { | |
135 return GetLayer()->visible(); | |
136 } | |
137 | |
138 display::Display WmWindow::GetDisplayNearestWindow() { | |
139 return display::Screen::GetScreen()->GetDisplayNearestWindow(window_); | |
140 } | |
141 | |
142 bool WmWindow::HasNonClientArea() { | |
143 return window_->delegate() ? true : false; | |
144 } | |
145 | |
146 int WmWindow::GetNonClientComponent(const gfx::Point& location) { | |
147 return wm::GetNonClientComponent(window_, location); | |
148 } | |
149 | |
150 gfx::Point WmWindow::ConvertPointToTarget(const WmWindow* target, | |
151 const gfx::Point& point) const { | |
152 gfx::Point result(point); | |
153 aura::Window::ConvertPointToTarget(window_, GetAuraWindow(target), &result); | |
154 return result; | |
155 } | |
156 | |
157 gfx::Point WmWindow::ConvertPointToScreen(const gfx::Point& point) const { | |
158 gfx::Point result(point); | |
159 ::wm::ConvertPointToScreen(window_, &result); | |
160 return result; | |
161 } | |
162 | |
163 gfx::Point WmWindow::ConvertPointFromScreen(const gfx::Point& point) const { | |
164 gfx::Point result(point); | |
165 ::wm::ConvertPointFromScreen(window_, &result); | |
166 return result; | |
167 } | |
168 | |
169 gfx::Rect WmWindow::ConvertRectToScreen(const gfx::Rect& rect) const { | |
170 gfx::Rect result(rect); | |
171 ::wm::ConvertRectToScreen(window_, &result); | |
172 return result; | |
173 } | |
174 | |
175 gfx::Rect WmWindow::ConvertRectFromScreen(const gfx::Rect& rect) const { | |
176 gfx::Rect result(rect); | |
177 ::wm::ConvertRectFromScreen(window_, &result); | |
178 return result; | |
179 } | |
180 | |
181 gfx::Size WmWindow::GetMinimumSize() const { | |
182 return window_->delegate() ? window_->delegate()->GetMinimumSize() | |
183 : gfx::Size(); | |
184 } | |
185 | |
186 gfx::Size WmWindow::GetMaximumSize() const { | |
187 return window_->delegate() ? window_->delegate()->GetMaximumSize() | |
188 : gfx::Size(); | |
189 } | |
190 | |
191 bool WmWindow::GetTargetVisibility() const { | |
192 return window_->TargetVisibility(); | |
193 } | |
194 | |
195 bool WmWindow::IsVisible() const { | |
196 return window_->IsVisible(); | |
197 } | |
198 | |
199 void WmWindow::SetOpacity(float opacity) { | |
200 window_->layer()->SetOpacity(opacity); | |
201 } | |
202 | |
203 float WmWindow::GetTargetOpacity() const { | |
204 return window_->layer()->GetTargetOpacity(); | |
205 } | |
206 | |
207 gfx::Rect WmWindow::GetMinimizeAnimationTargetBoundsInScreen() const { | |
208 return ash::GetMinimizeAnimationTargetBoundsInScreen(window_); | |
209 } | |
210 | |
211 void WmWindow::SetTransform(const gfx::Transform& transform) { | |
212 window_->SetTransform(transform); | |
213 } | |
214 | |
215 gfx::Transform WmWindow::GetTargetTransform() const { | |
216 return window_->layer()->GetTargetTransform(); | |
217 } | |
218 | |
219 bool WmWindow::IsSystemModal() const { | |
220 return window_->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM; | |
221 } | |
222 | |
223 const wm::WindowState* WmWindow::GetWindowState() const { | |
224 return ash::wm::GetWindowState(window_); | |
225 } | |
226 | |
227 WmWindow* WmWindow::GetToplevelWindow() { | |
228 return Get(window_->GetToplevelWindow()); | |
229 } | |
230 | |
231 WmWindow* WmWindow::GetToplevelWindowForFocus() { | |
232 return Get(::wm::GetToplevelWindow(window_)); | |
233 } | |
234 | |
235 void WmWindow::SetParentUsingContext(WmWindow* context, | |
236 const gfx::Rect& screen_bounds) { | |
237 aura::client::ParentWindowWithContext(window_, GetAuraWindow(context), | |
238 screen_bounds); | |
239 } | |
240 | |
241 void WmWindow::AddChild(WmWindow* window) { | |
242 window_->AddChild(GetAuraWindow(window)); | |
243 } | |
244 | |
245 void WmWindow::RemoveChild(WmWindow* child) { | |
246 window_->RemoveChild(GetAuraWindow(child)); | |
247 } | |
248 | |
249 const WmWindow* WmWindow::GetParent() const { | |
250 return Get(window_->parent()); | |
251 } | |
252 | |
253 const WmWindow* WmWindow::GetTransientParent() const { | |
254 return Get(::wm::GetTransientParent(window_)); | |
255 } | |
256 | |
257 std::vector<WmWindow*> WmWindow::GetTransientChildren() { | |
258 return FromAuraWindows(::wm::GetTransientChildren(window_)); | |
259 } | |
260 | |
261 bool WmWindow::MoveToEventRoot(const ui::Event& event) { | |
262 return ash::wm::MoveWindowToEventRoot(window_, event); | |
263 } | |
264 | |
265 void WmWindow::SetVisibilityChangesAnimated() { | |
266 ::wm::SetWindowVisibilityChangesAnimated(window_); | |
267 } | |
268 | |
269 void WmWindow::SetVisibilityAnimationType(int type) { | |
270 ::wm::SetWindowVisibilityAnimationType(window_, type); | |
271 } | |
272 | |
273 void WmWindow::SetVisibilityAnimationDuration(base::TimeDelta delta) { | |
274 ::wm::SetWindowVisibilityAnimationDuration(window_, delta); | |
275 } | |
276 | |
277 void WmWindow::SetVisibilityAnimationTransition( | |
278 ::wm::WindowVisibilityAnimationTransition transition) { | |
279 ::wm::SetWindowVisibilityAnimationTransition(window_, transition); | |
280 } | |
281 | |
282 void WmWindow::Animate(::wm::WindowAnimationType type) { | |
283 ::wm::AnimateWindow(window_, type); | |
284 } | |
285 | |
286 void WmWindow::StopAnimatingProperty( | |
287 ui::LayerAnimationElement::AnimatableProperty property) { | |
288 window_->layer()->GetAnimator()->StopAnimatingProperty(property); | |
289 } | |
290 | |
291 void WmWindow::SetChildWindowVisibilityChangesAnimated() { | |
292 ::wm::SetChildWindowVisibilityChangesAnimated(window_); | |
293 } | |
294 | |
295 void WmWindow::SetMasksToBounds(bool value) { | |
296 window_->layer()->SetMasksToBounds(value); | |
297 } | |
298 | |
299 void WmWindow::SetBounds(const gfx::Rect& bounds) { | |
300 window_->SetBounds(bounds); | |
301 } | |
302 | |
303 void WmWindow::SetBoundsWithTransitionDelay(const gfx::Rect& bounds, | |
304 base::TimeDelta delta) { | |
305 if (::wm::WindowAnimationsDisabled(window_)) { | |
306 window_->SetBounds(bounds); | |
307 return; | |
308 } | |
309 | |
310 ui::ScopedLayerAnimationSettings settings(window_->layer()->GetAnimator()); | |
311 settings.SetTransitionDuration(delta); | |
312 window_->SetBounds(bounds); | |
313 } | |
314 | |
315 void WmWindow::SetBoundsInScreen(const gfx::Rect& bounds_in_screen, | |
316 const display::Display& dst_display) { | |
317 window_->SetBoundsInScreen(bounds_in_screen, dst_display); | |
318 } | |
319 | |
320 gfx::Rect WmWindow::GetBoundsInScreen() const { | |
321 return window_->GetBoundsInScreen(); | |
322 } | |
323 | |
324 const gfx::Rect& WmWindow::GetBounds() const { | |
325 return window_->bounds(); | |
326 } | |
327 | |
328 gfx::Rect WmWindow::GetTargetBounds() { | |
329 return window_->GetTargetBounds(); | |
330 } | |
331 | |
332 void WmWindow::ClearRestoreBounds() { | |
333 window_->ClearProperty(aura::client::kRestoreBoundsKey); | |
334 window_->ClearProperty(::wm::kVirtualKeyboardRestoreBoundsKey); | |
335 } | |
336 | |
337 void WmWindow::SetRestoreBoundsInScreen(const gfx::Rect& bounds) { | |
338 window_->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); | |
339 } | |
340 | |
341 gfx::Rect WmWindow::GetRestoreBoundsInScreen() const { | |
342 gfx::Rect* bounds = window_->GetProperty(aura::client::kRestoreBoundsKey); | |
343 return bounds ? *bounds : gfx::Rect(); | |
344 } | |
345 | |
346 bool WmWindow::Contains(const WmWindow* other) const { | |
347 return other ? window_->Contains(static_cast<const WmWindow*>(other)->window_) | |
348 : false; | |
349 } | |
350 | |
351 void WmWindow::SetShowState(ui::WindowShowState show_state) { | |
352 window_->SetProperty(aura::client::kShowStateKey, show_state); | |
353 } | |
354 | |
355 ui::WindowShowState WmWindow::GetShowState() const { | |
356 return window_->GetProperty(aura::client::kShowStateKey); | |
357 } | |
358 | |
359 void WmWindow::SetPreFullscreenShowState(ui::WindowShowState show_state) { | |
360 // We should never store the ui::SHOW_STATE_MINIMIZED as the show state before | |
361 // fullscreen. | |
362 DCHECK_NE(show_state, ui::SHOW_STATE_MINIMIZED); | |
363 window_->SetProperty(aura::client::kPreFullscreenShowStateKey, show_state); | |
364 } | |
365 | |
366 void WmWindow::SetLockedToRoot(bool value) { | |
367 window_->SetProperty(kLockedToRootKey, value); | |
368 } | |
369 | |
370 bool WmWindow::IsLockedToRoot() const { | |
371 return window_->GetProperty(kLockedToRootKey); | |
372 } | |
373 | |
374 void WmWindow::SetCapture() { | |
375 window_->SetCapture(); | |
376 } | |
377 | |
378 bool WmWindow::HasCapture() { | |
379 return window_->HasCapture(); | |
380 } | |
381 | |
382 void WmWindow::ReleaseCapture() { | |
383 window_->ReleaseCapture(); | |
384 } | |
385 | |
386 bool WmWindow::HasRestoreBounds() const { | |
387 return window_->GetProperty(aura::client::kRestoreBoundsKey) != nullptr; | |
388 } | |
389 | |
390 bool WmWindow::CanMaximize() const { | |
391 return (window_->GetProperty(aura::client::kResizeBehaviorKey) & | |
392 ui::mojom::kResizeBehaviorCanMaximize) != 0; | |
393 } | |
394 | |
395 bool WmWindow::CanMinimize() const { | |
396 return (window_->GetProperty(aura::client::kResizeBehaviorKey) & | |
397 ui::mojom::kResizeBehaviorCanMinimize) != 0; | |
398 } | |
399 | |
400 bool WmWindow::CanResize() const { | |
401 return (window_->GetProperty(aura::client::kResizeBehaviorKey) & | |
402 ui::mojom::kResizeBehaviorCanResize) != 0; | |
403 } | |
404 | |
405 bool WmWindow::CanActivate() const { | |
406 // TODO(sky): for aura-mus need to key off CanFocus() as well, which is not | |
407 // currently mirrored to ash. | |
408 return ::wm::CanActivateWindow(window_); | |
409 } | |
410 | |
411 void WmWindow::StackChildAtTop(WmWindow* child) { | |
412 window_->StackChildAtTop(GetAuraWindow(child)); | |
413 } | |
414 | |
415 void WmWindow::StackChildAtBottom(WmWindow* child) { | |
416 window_->StackChildAtBottom(GetAuraWindow(child)); | |
417 } | |
418 | |
419 void WmWindow::StackChildAbove(WmWindow* child, WmWindow* target) { | |
420 window_->StackChildAbove(GetAuraWindow(child), GetAuraWindow(target)); | |
421 } | |
422 | |
423 void WmWindow::StackChildBelow(WmWindow* child, WmWindow* target) { | |
424 window_->StackChildBelow(GetAuraWindow(child), GetAuraWindow(target)); | |
425 } | |
426 | |
427 void WmWindow::SetAlwaysOnTop(bool value) { | |
428 window_->SetProperty(aura::client::kAlwaysOnTopKey, value); | |
429 } | |
430 | |
431 bool WmWindow::IsAlwaysOnTop() const { | |
432 return window_->GetProperty(aura::client::kAlwaysOnTopKey); | |
433 } | |
434 | |
435 void WmWindow::Hide() { | |
436 window_->Hide(); | |
437 } | |
438 | |
439 void WmWindow::Show() { | |
440 window_->Show(); | |
441 } | |
442 | |
443 void WmWindow::SetFocused() { | |
444 aura::client::GetFocusClient(window_)->FocusWindow(window_); | |
445 } | |
446 | |
447 bool WmWindow::IsFocused() const { | |
448 return window_->HasFocus(); | |
449 } | |
450 | |
451 bool WmWindow::IsActive() const { | |
452 return wm::IsActiveWindow(window_); | |
453 } | |
454 | |
455 void WmWindow::Activate() { | |
456 wm::ActivateWindow(window_); | |
457 } | |
458 | |
459 void WmWindow::Deactivate() { | |
460 wm::DeactivateWindow(window_); | |
461 } | |
462 | |
463 void WmWindow::SetFullscreen(bool fullscreen) { | |
464 ::wm::SetWindowFullscreen(window_, fullscreen); | |
465 } | |
466 | |
467 void WmWindow::Maximize() { | |
468 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | |
469 } | |
470 | |
471 void WmWindow::Minimize() { | |
472 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | |
473 } | |
474 | |
475 void WmWindow::Unminimize() { | |
476 window_->SetProperty( | |
477 aura::client::kShowStateKey, | |
478 window_->GetProperty(aura::client::kPreMinimizedShowStateKey)); | |
479 window_->ClearProperty(aura::client::kPreMinimizedShowStateKey); | |
480 } | |
481 | |
482 std::vector<WmWindow*> WmWindow::GetChildren() { | |
483 return FromAuraWindows(window_->children()); | |
484 } | |
485 | |
486 WmWindow* WmWindow::GetChildByShellWindowId(int id) { | |
487 return Get(window_->GetChildById(id)); | |
488 } | |
489 | |
490 void WmWindow::SetBoundsInScreenBehaviorForChildren( | |
491 BoundsInScreenBehavior behavior) { | |
492 window_->SetProperty( | |
493 kUsesScreenCoordinatesKey, | |
494 behavior == BoundsInScreenBehavior::USE_SCREEN_COORDINATES); | |
495 } | |
496 | |
497 void WmWindow::SetSnapsChildrenToPhysicalPixelBoundary() { | |
498 wm::SetSnapsChildrenToPhysicalPixelBoundary(window_); | |
499 } | |
500 | |
501 void WmWindow::SnapToPixelBoundaryIfNecessary() { | |
502 wm::SnapWindowToPixelBoundary(window_); | |
503 } | |
504 | |
505 void WmWindow::AddTransientWindowObserver(WmTransientWindowObserver* observer) { | |
506 if (!added_transient_observer_) { | |
507 added_transient_observer_ = true; | |
508 ::wm::TransientWindowManager::Get(window_)->AddObserver(this); | |
509 } | |
510 transient_observers_.AddObserver(observer); | |
511 } | |
512 | |
513 void WmWindow::RemoveTransientWindowObserver( | |
514 WmTransientWindowObserver* observer) { | |
515 transient_observers_.RemoveObserver(observer); | |
516 if (added_transient_observer_ && | |
517 !transient_observers_.might_have_observers()) { | |
518 added_transient_observer_ = false; | |
519 ::wm::TransientWindowManager::Get(window_)->RemoveObserver(this); | |
520 } | |
521 } | |
522 | |
523 WmWindow::WmWindow(aura::Window* window) : window_(window) { | |
524 window_->SetProperty(kWmWindowKey, this); | |
525 } | |
526 | |
527 void WmWindow::OnTransientChildAdded(aura::Window* window, | |
528 aura::Window* transient) { | |
529 for (auto& observer : transient_observers_) | |
530 observer.OnTransientChildAdded(this, Get(transient)); | |
531 } | |
532 | |
533 void WmWindow::OnTransientChildRemoved(aura::Window* window, | |
534 aura::Window* transient) { | |
535 for (auto& observer : transient_observers_) | |
536 observer.OnTransientChildRemoved(this, Get(transient)); | |
537 } | |
538 | |
539 } // namespace ash | |
OLD | NEW |