| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/container_finder.h" | 5 #include "ash/wm/container_finder.h" |
| 6 | 6 |
| 7 #include "ash/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
| 8 #include "ash/public/cpp/window_properties.h" | 8 #include "ash/public/cpp/window_properties.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/session/session_controller.h" | 10 #include "ash/session/session_controller.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/wm/always_on_top_controller.h" | 12 #include "ash/wm/always_on_top_controller.h" |
| 13 #include "ash/wm/root_window_finder.h" | 13 #include "ash/wm/root_window_finder.h" |
| 14 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
| 15 #include "ash/wm_window.h" | 15 #include "ash/wm_window.h" |
| 16 #include "ui/aura/client/aura_constants.h" |
| 16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 17 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/wm/core/window_util.h" |
| 18 | 20 |
| 19 namespace ash { | 21 namespace ash { |
| 20 namespace wm { | 22 namespace wm { |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 WmWindow* FindContainerRoot(const gfx::Rect& bounds) { | 25 aura::Window* FindContainerRoot(const gfx::Rect& bounds) { |
| 24 if (bounds == gfx::Rect()) | 26 if (bounds == gfx::Rect()) |
| 25 return Shell::GetWmRootWindowForNewWindows(); | 27 return Shell::GetRootWindowForNewWindows(); |
| 26 return GetRootWindowMatching(bounds); | 28 WmWindow* root = GetRootWindowMatching(bounds); |
| 29 return root ? root->aura_window() : nullptr; |
| 27 } | 30 } |
| 28 | 31 |
| 29 bool HasTransientParentWindow(const WmWindow* window) { | 32 bool HasTransientParentWindow(const aura::Window* window) { |
| 30 return window->GetTransientParent() && | 33 const aura::Window* transient_parent = ::wm::GetTransientParent(window); |
| 31 window->GetTransientParent()->GetType() != ui::wm::WINDOW_TYPE_UNKNOWN; | 34 return transient_parent && |
| 35 transient_parent->type() != ui::wm::WINDOW_TYPE_UNKNOWN; |
| 32 } | 36 } |
| 33 | 37 |
| 34 WmWindow* GetSystemModalContainer(WmWindow* root, WmWindow* window) { | 38 aura::Window* GetSystemModalContainer(aura::Window* root, |
| 35 DCHECK(window->IsSystemModal()); | 39 aura::Window* window) { |
| 40 aura::Window* transient_parent = ::wm::GetTransientParent(window); |
| 41 DCHECK_EQ(ui::MODAL_TYPE_SYSTEM, |
| 42 window->GetProperty(aura::client::kModalKey)); |
| 36 | 43 |
| 37 // If screen lock is not active and user session is active, | 44 // If screen lock is not active and user session is active, |
| 38 // all modal windows are placed into the normal modal container. | 45 // all modal windows are placed into the normal modal container. |
| 39 // In case of missing transient parent (it could happen for alerts from | 46 // In case of missing transient parent (it could happen for alerts from |
| 40 // background pages) assume that the window belongs to user session. | 47 // background pages) assume that the window belongs to user session. |
| 41 if (!Shell::Get()->session_controller()->IsUserSessionBlocked() || | 48 if (!Shell::Get()->session_controller()->IsUserSessionBlocked() || |
| 42 !window->GetTransientParent()) { | 49 !transient_parent) { |
| 43 return root->GetChildByShellWindowId(kShellWindowId_SystemModalContainer); | 50 return root->GetChildById(kShellWindowId_SystemModalContainer); |
| 44 } | 51 } |
| 45 | 52 |
| 46 // Otherwise those that originate from LockScreen container and above are | 53 // Otherwise those that originate from LockScreen container and above are |
| 47 // placed in the screen lock modal container. | 54 // placed in the screen lock modal container. |
| 48 int window_container_id = | 55 int window_container_id = transient_parent->parent()->id(); |
| 49 window->GetTransientParent()->GetParent()->aura_window()->id(); | |
| 50 if (window_container_id < kShellWindowId_LockScreenContainer) | 56 if (window_container_id < kShellWindowId_LockScreenContainer) |
| 51 return root->GetChildByShellWindowId(kShellWindowId_SystemModalContainer); | 57 return root->GetChildById(kShellWindowId_SystemModalContainer); |
| 52 return root->GetChildByShellWindowId(kShellWindowId_LockSystemModalContainer); | 58 return root->GetChildById(kShellWindowId_LockSystemModalContainer); |
| 53 } | 59 } |
| 54 | 60 |
| 55 WmWindow* GetContainerFromAlwaysOnTopController(WmWindow* root, | 61 aura::Window* GetContainerFromAlwaysOnTopController(aura::Window* root, |
| 56 WmWindow* window) { | 62 aura::Window* window) { |
| 57 return root->GetRootWindowController() | 63 WmWindow* result = RootWindowController::ForWindow(root) |
| 58 ->always_on_top_controller() | 64 ->always_on_top_controller() |
| 59 ->GetContainer(window); | 65 ->GetContainer(WmWindow::Get(window)); |
| 66 return result ? result->aura_window() : nullptr; |
| 60 } | 67 } |
| 61 | 68 |
| 62 } // namespace | 69 } // namespace |
| 63 | 70 |
| 64 WmWindow* GetContainerForWindow(WmWindow* window) { | 71 aura::Window* GetContainerForWindow(aura::Window* window) { |
| 65 WmWindow* parent = window->GetParent(); | 72 aura::Window* parent = window->parent(); |
| 66 // The first parent with an explicit shell window ID is the container. | 73 // The first parent with an explicit shell window ID is the container. |
| 67 while (parent && parent->aura_window()->id() == kShellWindowId_Invalid) | 74 while (parent && parent->id() == kShellWindowId_Invalid) |
| 68 parent = parent->GetParent(); | 75 parent = parent->parent(); |
| 69 return parent; | 76 return parent; |
| 70 } | 77 } |
| 71 | 78 |
| 72 WmWindow* GetDefaultParent(WmWindow* window, const gfx::Rect& bounds) { | 79 aura::Window* GetDefaultParent(aura::Window* window, const gfx::Rect& bounds) { |
| 73 WmWindow* target_root = nullptr; | 80 aura::Window* target_root = nullptr; |
| 74 WmWindow* transient_parent = window->GetTransientParent(); | 81 aura::Window* transient_parent = ::wm::GetTransientParent(window); |
| 75 if (transient_parent) { | 82 if (transient_parent) { |
| 76 // Transient window should use the same root as its transient parent. | 83 // Transient window should use the same root as its transient parent. |
| 77 target_root = transient_parent->GetRootWindow(); | 84 target_root = transient_parent->GetRootWindow(); |
| 78 } else { | 85 } else { |
| 79 target_root = FindContainerRoot(bounds); | 86 target_root = FindContainerRoot(bounds); |
| 80 } | 87 } |
| 81 | 88 |
| 82 switch (window->GetType()) { | 89 switch (window->type()) { |
| 83 case ui::wm::WINDOW_TYPE_NORMAL: | 90 case ui::wm::WINDOW_TYPE_NORMAL: |
| 84 case ui::wm::WINDOW_TYPE_POPUP: | 91 case ui::wm::WINDOW_TYPE_POPUP: |
| 85 if (window->IsSystemModal()) | 92 if (window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM) |
| 86 return GetSystemModalContainer(target_root, window); | 93 return GetSystemModalContainer(target_root, window); |
| 87 if (HasTransientParentWindow(window)) | 94 if (HasTransientParentWindow(window)) |
| 88 return GetContainerForWindow(window->GetTransientParent()); | 95 return GetContainerForWindow(transient_parent); |
| 89 return GetContainerFromAlwaysOnTopController(target_root, window); | 96 return GetContainerFromAlwaysOnTopController(target_root, window); |
| 90 case ui::wm::WINDOW_TYPE_CONTROL: | 97 case ui::wm::WINDOW_TYPE_CONTROL: |
| 91 return target_root->GetChildByShellWindowId( | 98 return target_root->GetChildById( |
| 92 kShellWindowId_UnparentedControlContainer); | 99 kShellWindowId_UnparentedControlContainer); |
| 93 case ui::wm::WINDOW_TYPE_PANEL: | 100 case ui::wm::WINDOW_TYPE_PANEL: |
| 94 if (window->aura_window()->GetProperty(kPanelAttachedKey)) | 101 if (window->GetProperty(kPanelAttachedKey)) |
| 95 return target_root->GetChildByShellWindowId( | 102 return target_root->GetChildById(kShellWindowId_PanelContainer); |
| 96 kShellWindowId_PanelContainer); | |
| 97 return GetContainerFromAlwaysOnTopController(target_root, window); | 103 return GetContainerFromAlwaysOnTopController(target_root, window); |
| 98 case ui::wm::WINDOW_TYPE_MENU: | 104 case ui::wm::WINDOW_TYPE_MENU: |
| 99 return target_root->GetChildByShellWindowId(kShellWindowId_MenuContainer); | 105 return target_root->GetChildById(kShellWindowId_MenuContainer); |
| 100 case ui::wm::WINDOW_TYPE_TOOLTIP: | 106 case ui::wm::WINDOW_TYPE_TOOLTIP: |
| 101 return target_root->GetChildByShellWindowId( | 107 return target_root->GetChildById( |
| 102 kShellWindowId_DragImageAndTooltipContainer); | 108 kShellWindowId_DragImageAndTooltipContainer); |
| 103 default: | 109 default: |
| 104 NOTREACHED() << "Window " << window->aura_window()->id() | 110 NOTREACHED() << "Window " << window->id() << " has unhandled type " |
| 105 << " has unhandled type " << window->GetType(); | 111 << window->type(); |
| 106 break; | 112 break; |
| 107 } | 113 } |
| 108 return nullptr; | 114 return nullptr; |
| 109 } | 115 } |
| 110 | 116 |
| 111 aura::Window::Windows GetContainersFromAllRootWindows( | 117 aura::Window::Windows GetContainersFromAllRootWindows( |
| 112 int container_id, | 118 int container_id, |
| 113 aura::Window* priority_root) { | 119 aura::Window* priority_root) { |
| 114 aura::Window::Windows containers; | 120 aura::Window::Windows containers; |
| 115 for (aura::Window* root : Shell::GetAllRootWindows()) { | 121 for (aura::Window* root : Shell::GetAllRootWindows()) { |
| 116 aura::Window* container = root->GetChildById(container_id); | 122 aura::Window* container = root->GetChildById(container_id); |
| 117 if (!container) | 123 if (!container) |
| 118 continue; | 124 continue; |
| 119 | 125 |
| 120 if (priority_root && priority_root->Contains(container)) | 126 if (priority_root && priority_root->Contains(container)) |
| 121 containers.insert(containers.begin(), container); | 127 containers.insert(containers.begin(), container); |
| 122 else | 128 else |
| 123 containers.push_back(container); | 129 containers.push_back(container); |
| 124 } | 130 } |
| 125 return containers; | 131 return containers; |
| 126 } | 132 } |
| 127 | 133 |
| 128 } // namespace wm | 134 } // namespace wm |
| 129 } // namespace ash | 135 } // namespace ash |
| OLD | NEW |