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/common/container_finder.h" | |
6 | |
7 #include "ash/wm/common/always_on_top_controller.h" | |
8 #include "ash/wm/common/root_window_finder.h" | |
9 #include "ash/wm/common/window_state.h" | |
10 #include "ash/wm/common/wm_globals.h" | |
11 #include "ash/wm/common/wm_root_window_controller.h" | |
12 #include "ash/wm/common/wm_shell_window_ids.h" | |
13 #include "ash/wm/common/wm_window.h" | |
14 #include "ui/gfx/geometry/rect.h" | |
15 | |
16 namespace ash { | |
17 namespace wm { | |
18 namespace { | |
19 | |
20 WmWindow* FindContainerRoot(WmGlobals* globals, const gfx::Rect& bounds) { | |
21 if (bounds == gfx::Rect()) | |
22 return globals->GetRootWindowForNewWindows(); | |
23 return GetRootWindowMatching(bounds); | |
24 } | |
25 | |
26 bool HasTransientParentWindow(const WmWindow* window) { | |
27 return window->GetTransientParent() && | |
28 window->GetTransientParent()->GetType() != ui::wm::WINDOW_TYPE_UNKNOWN; | |
29 } | |
30 | |
31 WmWindow* GetSystemModalContainer(WmWindow* root, WmWindow* window) { | |
32 DCHECK(window->IsSystemModal()); | |
33 | |
34 // If screen lock is not active and user session is active, | |
35 // all modal windows are placed into the normal modal container. | |
36 // In case of missing transient parent (it could happen for alerts from | |
37 // background pages) assume that the window belongs to user session. | |
38 if (!window->GetGlobals()->IsUserSessionBlocked() || | |
39 !window->GetTransientParent()) { | |
40 return root->GetChildByShellWindowId(kShellWindowId_SystemModalContainer); | |
41 } | |
42 | |
43 // Otherwise those that originate from LockScreen container and above are | |
44 // placed in the screen lock modal container. | |
45 int window_container_id = | |
46 window->GetTransientParent()->GetParent()->GetShellWindowId(); | |
47 if (window_container_id < kShellWindowId_LockScreenContainer) | |
48 return root->GetChildByShellWindowId(kShellWindowId_SystemModalContainer); | |
49 return root->GetChildByShellWindowId(kShellWindowId_LockSystemModalContainer); | |
50 } | |
51 | |
52 WmWindow* GetContainerFromAlwaysOnTopController(WmWindow* root, | |
53 WmWindow* window) { | |
54 return root->GetRootWindowController() | |
55 ->GetAlwaysOnTopController() | |
56 ->GetContainer(window); | |
57 } | |
58 | |
59 } // namespace | |
60 | |
61 WmWindow* GetContainerForWindow(WmWindow* window) { | |
62 WmWindow* container = window->GetParent(); | |
63 while (container && container->GetType() != ui::wm::WINDOW_TYPE_UNKNOWN) | |
64 container = container->GetParent(); | |
65 return container; | |
66 } | |
67 | |
68 WmWindow* GetDefaultParent(WmWindow* context, | |
69 WmWindow* window, | |
70 const gfx::Rect& bounds) { | |
71 WmWindow* target_root = nullptr; | |
72 WmWindow* transient_parent = window->GetTransientParent(); | |
73 if (transient_parent) { | |
74 // Transient window should use the same root as its transient parent. | |
75 target_root = transient_parent->GetRootWindow(); | |
76 } else { | |
77 target_root = FindContainerRoot(context->GetGlobals(), bounds); | |
78 } | |
79 | |
80 switch (window->GetType()) { | |
81 case ui::wm::WINDOW_TYPE_NORMAL: | |
82 case ui::wm::WINDOW_TYPE_POPUP: | |
83 if (window->IsSystemModal()) | |
84 return GetSystemModalContainer(target_root, window); | |
85 if (HasTransientParentWindow(window)) | |
86 return GetContainerForWindow(window->GetTransientParent()); | |
87 return GetContainerFromAlwaysOnTopController(target_root, window); | |
88 case ui::wm::WINDOW_TYPE_CONTROL: | |
89 return target_root->GetChildByShellWindowId( | |
90 kShellWindowId_UnparentedControlContainer); | |
91 case ui::wm::WINDOW_TYPE_PANEL: | |
92 if (window->GetWindowState()->panel_attached()) | |
93 return target_root->GetChildByShellWindowId( | |
94 kShellWindowId_PanelContainer); | |
95 return GetContainerFromAlwaysOnTopController(target_root, window); | |
96 case ui::wm::WINDOW_TYPE_MENU: | |
97 return target_root->GetChildByShellWindowId(kShellWindowId_MenuContainer); | |
98 case ui::wm::WINDOW_TYPE_TOOLTIP: | |
99 return target_root->GetChildByShellWindowId( | |
100 kShellWindowId_DragImageAndTooltipContainer); | |
101 default: | |
102 NOTREACHED() << "Window " << window->GetShellWindowId() | |
103 << " has unhandled type " << window->GetType(); | |
104 break; | |
105 } | |
106 return nullptr; | |
107 } | |
108 | |
109 } // namespace wm | |
110 } // namespace ash | |
OLD | NEW |