OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/stacking_controller.h" | 5 #include "ash/wm/stacking_controller.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/session_state_delegate.h" | 8 #include "ash/session_state_delegate.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
11 #include "ash/wm/always_on_top_controller.h" | 11 #include "ash/wm/always_on_top_controller.h" |
12 #include "ash/wm/coordinate_conversion.h" | 12 #include "ash/wm/coordinate_conversion.h" |
13 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
14 #include "ui/aura/client/aura_constants.h" | 14 #include "ui/aura/client/aura_constants.h" |
15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
17 #include "ui/base/ui_base_types.h" | 17 #include "ui/base/ui_base_types.h" |
| 18 #include "ui/views/corewm/window_util.h" |
18 | 19 |
19 namespace ash { | 20 namespace ash { |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Find a root window that matches the |bounds|. If the virtual screen | 23 // Find a root window that matches the |bounds|. If the virtual screen |
23 // coordinates is enabled and the bounds is specified, the root window | 24 // coordinates is enabled and the bounds is specified, the root window |
24 // that matches the window's bound will be used. Otherwise, it'll | 25 // that matches the window's bound will be used. Otherwise, it'll |
25 // return the active root window. | 26 // return the active root window. |
26 aura::Window* FindContainerRoot(const gfx::Rect& bounds) { | 27 aura::Window* FindContainerRoot(const gfx::Rect& bounds) { |
27 if (bounds.x() == 0 && bounds.y() == 0 && bounds.IsEmpty()) | 28 if (bounds.x() == 0 && bounds.y() == 0 && bounds.IsEmpty()) |
28 return Shell::GetTargetRootWindow(); | 29 return Shell::GetTargetRootWindow(); |
29 return wm::GetRootWindowMatching(bounds); | 30 return wm::GetRootWindowMatching(bounds); |
30 } | 31 } |
31 | 32 |
32 aura::Window* GetContainerById(aura::Window* root, int id) { | 33 aura::Window* GetContainerById(aura::Window* root, int id) { |
33 return Shell::GetContainer(root, id); | 34 return Shell::GetContainer(root, id); |
34 } | 35 } |
35 | 36 |
36 bool IsSystemModal(aura::Window* window) { | 37 bool IsSystemModal(aura::Window* window) { |
37 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM; | 38 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM; |
38 } | 39 } |
39 | 40 |
40 bool HasTransientParentWindow(aura::Window* window) { | 41 bool HasTransientParentWindow(const aura::Window* window) { |
41 return window->transient_parent() && | 42 return views::corewm::GetTransientParent(window) && |
42 window->transient_parent()->type() != ui::wm::WINDOW_TYPE_UNKNOWN; | 43 views::corewm::GetTransientParent(window)->type() != |
| 44 ui::wm::WINDOW_TYPE_UNKNOWN; |
43 } | 45 } |
44 | 46 |
45 internal::AlwaysOnTopController* | 47 internal::AlwaysOnTopController* |
46 GetAlwaysOnTopController(aura::Window* root_window) { | 48 GetAlwaysOnTopController(aura::Window* root_window) { |
47 return internal::GetRootWindowController(root_window)-> | 49 return internal::GetRootWindowController(root_window)-> |
48 always_on_top_controller(); | 50 always_on_top_controller(); |
49 } | 51 } |
50 | 52 |
51 } // namespace | 53 } // namespace |
52 | 54 |
53 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
54 // StackingController, public: | 56 // StackingController, public: |
55 | 57 |
56 StackingController::StackingController() { | 58 StackingController::StackingController() { |
57 } | 59 } |
58 | 60 |
59 StackingController::~StackingController() { | 61 StackingController::~StackingController() { |
60 } | 62 } |
61 | 63 |
62 //////////////////////////////////////////////////////////////////////////////// | 64 //////////////////////////////////////////////////////////////////////////////// |
63 // StackingController, aura::client::WindowTreeClient implementation: | 65 // StackingController, aura::client::WindowTreeClient implementation: |
64 | 66 |
65 aura::Window* StackingController::GetDefaultParent(aura::Window* context, | 67 aura::Window* StackingController::GetDefaultParent(aura::Window* context, |
66 aura::Window* window, | 68 aura::Window* window, |
67 const gfx::Rect& bounds) { | 69 const gfx::Rect& bounds) { |
68 aura::Window* target_root = NULL; | 70 aura::Window* target_root = NULL; |
69 if (window->transient_parent()) { | 71 aura::Window* transient_parent = views::corewm::GetTransientParent(window); |
| 72 if (transient_parent) { |
70 // Transient window should use the same root as its transient parent. | 73 // Transient window should use the same root as its transient parent. |
71 target_root = window->transient_parent()->GetRootWindow(); | 74 target_root = transient_parent->GetRootWindow(); |
72 } else { | 75 } else { |
73 target_root = FindContainerRoot(bounds); | 76 target_root = FindContainerRoot(bounds); |
74 } | 77 } |
75 | 78 |
76 switch (window->type()) { | 79 switch (window->type()) { |
77 case ui::wm::WINDOW_TYPE_NORMAL: | 80 case ui::wm::WINDOW_TYPE_NORMAL: |
78 case ui::wm::WINDOW_TYPE_POPUP: | 81 case ui::wm::WINDOW_TYPE_POPUP: |
79 if (IsSystemModal(window)) | 82 if (IsSystemModal(window)) |
80 return GetSystemModalContainer(target_root, window); | 83 return GetSystemModalContainer(target_root, window); |
81 else if (HasTransientParentWindow(window)) | 84 else if (HasTransientParentWindow(window)) |
82 return internal::RootWindowController::GetContainerForWindow( | 85 return internal::RootWindowController::GetContainerForWindow( |
83 window->transient_parent()); | 86 views::corewm::GetTransientParent(window)); |
84 return GetAlwaysOnTopController(target_root)->GetContainer(window); | 87 return GetAlwaysOnTopController(target_root)->GetContainer(window); |
85 case ui::wm::WINDOW_TYPE_CONTROL: | 88 case ui::wm::WINDOW_TYPE_CONTROL: |
86 return GetContainerById( | 89 return GetContainerById( |
87 target_root, internal::kShellWindowId_UnparentedControlContainer); | 90 target_root, internal::kShellWindowId_UnparentedControlContainer); |
88 case ui::wm::WINDOW_TYPE_PANEL: | 91 case ui::wm::WINDOW_TYPE_PANEL: |
89 if (wm::GetWindowState(window)->panel_attached()) | 92 if (wm::GetWindowState(window)->panel_attached()) |
90 return GetContainerById(target_root, | 93 return GetContainerById(target_root, |
91 internal::kShellWindowId_PanelContainer); | 94 internal::kShellWindowId_PanelContainer); |
92 else | 95 else |
93 return GetAlwaysOnTopController(target_root)->GetContainer(window); | 96 return GetAlwaysOnTopController(target_root)->GetContainer(window); |
(...skipping 19 matching lines...) Expand all Loading... |
113 aura::Window* window) const { | 116 aura::Window* window) const { |
114 DCHECK(IsSystemModal(window)); | 117 DCHECK(IsSystemModal(window)); |
115 | 118 |
116 // If screen lock is not active and user session is active, | 119 // If screen lock is not active and user session is active, |
117 // all modal windows are placed into the normal modal container. | 120 // all modal windows are placed into the normal modal container. |
118 // In case of missing transient parent (it could happen for alerts from | 121 // In case of missing transient parent (it could happen for alerts from |
119 // background pages) assume that the window belongs to user session. | 122 // background pages) assume that the window belongs to user session. |
120 SessionStateDelegate* session_state_delegate = | 123 SessionStateDelegate* session_state_delegate = |
121 Shell::GetInstance()->session_state_delegate(); | 124 Shell::GetInstance()->session_state_delegate(); |
122 if (!session_state_delegate->IsUserSessionBlocked() || | 125 if (!session_state_delegate->IsUserSessionBlocked() || |
123 !window->transient_parent()) { | 126 !views::corewm::GetTransientParent(window)) { |
124 return GetContainerById(root, | 127 return GetContainerById(root, |
125 internal::kShellWindowId_SystemModalContainer); | 128 internal::kShellWindowId_SystemModalContainer); |
126 } | 129 } |
127 | 130 |
128 // Otherwise those that originate from LockScreen container and above are | 131 // Otherwise those that originate from LockScreen container and above are |
129 // placed in the screen lock modal container. | 132 // placed in the screen lock modal container. |
130 int window_container_id = window->transient_parent()->parent()->id(); | 133 int window_container_id = |
| 134 views::corewm::GetTransientParent(window)->parent()->id(); |
131 aura::Window* container = NULL; | 135 aura::Window* container = NULL; |
132 if (window_container_id < internal::kShellWindowId_LockScreenContainer) { | 136 if (window_container_id < internal::kShellWindowId_LockScreenContainer) { |
133 container = GetContainerById( | 137 container = GetContainerById( |
134 root, internal::kShellWindowId_SystemModalContainer); | 138 root, internal::kShellWindowId_SystemModalContainer); |
135 } else { | 139 } else { |
136 container = GetContainerById( | 140 container = GetContainerById( |
137 root, internal::kShellWindowId_LockSystemModalContainer); | 141 root, internal::kShellWindowId_LockSystemModalContainer); |
138 } | 142 } |
139 | 143 |
140 return container; | 144 return container; |
141 } | 145 } |
142 | 146 |
143 } // namespace ash | 147 } // namespace ash |
OLD | NEW |