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