| 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" | |
| 8 #include "ash/session/session_state_delegate.h" | |
| 9 #include "ash/shell.h" | |
| 10 #include "ash/shell_window_ids.h" | |
| 11 #include "ash/wm/aura/wm_window_aura.h" | 7 #include "ash/wm/aura/wm_window_aura.h" |
| 12 #include "ash/wm/common/always_on_top_controller.h" | 8 #include "ash/wm/common/container_finder.h" |
| 13 #include "ash/wm/common/root_window_finder.h" | |
| 14 #include "ash/wm/common/window_state.h" | |
| 15 #include "ash/wm/window_state_aura.h" | |
| 16 #include "ui/aura/client/aura_constants.h" | |
| 17 #include "ui/aura/window.h" | |
| 18 #include "ui/aura/window_event_dispatcher.h" | |
| 19 #include "ui/base/ui_base_types.h" | |
| 20 #include "ui/wm/core/window_util.h" | |
| 21 | 9 |
| 22 namespace ash { | 10 namespace ash { |
| 23 namespace { | |
| 24 | |
| 25 // Find a root window that matches the |bounds|. If the virtual screen | |
| 26 // coordinates is enabled and the bounds is specified, the root window | |
| 27 // that matches the window's bound will be used. Otherwise, it'll | |
| 28 // return the active root window. | |
| 29 aura::Window* FindContainerRoot(const gfx::Rect& bounds) { | |
| 30 if (bounds.x() == 0 && bounds.y() == 0 && bounds.IsEmpty()) | |
| 31 return Shell::GetTargetRootWindow(); | |
| 32 return wm::WmWindowAura::GetAuraWindow(wm::GetRootWindowMatching(bounds)); | |
| 33 } | |
| 34 | |
| 35 aura::Window* GetContainerById(aura::Window* root, int id) { | |
| 36 return Shell::GetContainer(root, id); | |
| 37 } | |
| 38 | |
| 39 bool IsSystemModal(aura::Window* window) { | |
| 40 return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM; | |
| 41 } | |
| 42 | |
| 43 bool HasTransientParentWindow(const aura::Window* window) { | |
| 44 return ::wm::GetTransientParent(window) && | |
| 45 ::wm::GetTransientParent(window)->type() != | |
| 46 ui::wm::WINDOW_TYPE_UNKNOWN; | |
| 47 } | |
| 48 | |
| 49 AlwaysOnTopController* GetAlwaysOnTopController(aura::Window* root_window) { | |
| 50 return GetRootWindowController(root_window)->always_on_top_controller(); | |
| 51 } | |
| 52 | |
| 53 aura::Window* GetContainerFromAlwaysOnTopController(aura::Window* root, | |
| 54 aura::Window* window) { | |
| 55 return wm::WmWindowAura::GetAuraWindow( | |
| 56 GetAlwaysOnTopController(root)->GetContainer( | |
| 57 wm::WmWindowAura::Get(window))); | |
| 58 } | |
| 59 | |
| 60 } // namespace | |
| 61 | 11 |
| 62 //////////////////////////////////////////////////////////////////////////////// | 12 //////////////////////////////////////////////////////////////////////////////// |
| 63 // StackingController, public: | 13 // StackingController, public: |
| 64 | 14 |
| 65 StackingController::StackingController() { | 15 StackingController::StackingController() {} |
| 66 } | |
| 67 | 16 |
| 68 StackingController::~StackingController() { | 17 StackingController::~StackingController() {} |
| 69 } | |
| 70 | 18 |
| 71 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
| 72 // StackingController, aura::client::WindowTreeClient implementation: | 20 // StackingController, aura::client::WindowTreeClient implementation: |
| 73 | 21 |
| 74 aura::Window* StackingController::GetDefaultParent(aura::Window* context, | 22 aura::Window* StackingController::GetDefaultParent(aura::Window* context, |
| 75 aura::Window* window, | 23 aura::Window* window, |
| 76 const gfx::Rect& bounds) { | 24 const gfx::Rect& bounds) { |
| 77 aura::Window* target_root = NULL; | 25 return wm::WmWindowAura::GetAuraWindow(wm::GetDefaultParent( |
| 78 aura::Window* transient_parent = ::wm::GetTransientParent(window); | 26 wm::WmWindowAura::Get(context), wm::WmWindowAura::Get(window), bounds)); |
| 79 if (transient_parent) { | |
| 80 // Transient window should use the same root as its transient parent. | |
| 81 target_root = transient_parent->GetRootWindow(); | |
| 82 } else { | |
| 83 target_root = FindContainerRoot(bounds); | |
| 84 } | |
| 85 | |
| 86 switch (window->type()) { | |
| 87 case ui::wm::WINDOW_TYPE_NORMAL: | |
| 88 case ui::wm::WINDOW_TYPE_POPUP: | |
| 89 if (IsSystemModal(window)) | |
| 90 return GetSystemModalContainer(target_root, window); | |
| 91 else if (HasTransientParentWindow(window)) | |
| 92 return RootWindowController::GetContainerForWindow( | |
| 93 ::wm::GetTransientParent(window)); | |
| 94 return GetContainerFromAlwaysOnTopController(target_root, window); | |
| 95 case ui::wm::WINDOW_TYPE_CONTROL: | |
| 96 return GetContainerById(target_root, | |
| 97 kShellWindowId_UnparentedControlContainer); | |
| 98 case ui::wm::WINDOW_TYPE_PANEL: | |
| 99 if (wm::GetWindowState(window)->panel_attached()) | |
| 100 return GetContainerById(target_root, kShellWindowId_PanelContainer); | |
| 101 else | |
| 102 return GetContainerFromAlwaysOnTopController(target_root, window); | |
| 103 case ui::wm::WINDOW_TYPE_MENU: | |
| 104 return GetContainerById(target_root, kShellWindowId_MenuContainer); | |
| 105 case ui::wm::WINDOW_TYPE_TOOLTIP: | |
| 106 return GetContainerById(target_root, | |
| 107 kShellWindowId_DragImageAndTooltipContainer); | |
| 108 default: | |
| 109 NOTREACHED() << "Window " << window->id() | |
| 110 << " has unhandled type " << window->type(); | |
| 111 break; | |
| 112 } | |
| 113 return NULL; | |
| 114 } | |
| 115 | |
| 116 //////////////////////////////////////////////////////////////////////////////// | |
| 117 // StackingController, private: | |
| 118 | |
| 119 aura::Window* StackingController::GetSystemModalContainer( | |
| 120 aura::Window* root, | |
| 121 aura::Window* window) const { | |
| 122 DCHECK(IsSystemModal(window)); | |
| 123 | |
| 124 // If screen lock is not active and user session is active, | |
| 125 // all modal windows are placed into the normal modal container. | |
| 126 // In case of missing transient parent (it could happen for alerts from | |
| 127 // background pages) assume that the window belongs to user session. | |
| 128 SessionStateDelegate* session_state_delegate = | |
| 129 Shell::GetInstance()->session_state_delegate(); | |
| 130 if (!session_state_delegate->IsUserSessionBlocked() || | |
| 131 !::wm::GetTransientParent(window)) { | |
| 132 return GetContainerById(root, kShellWindowId_SystemModalContainer); | |
| 133 } | |
| 134 | |
| 135 // Otherwise those that originate from LockScreen container and above are | |
| 136 // placed in the screen lock modal container. | |
| 137 int window_container_id = | |
| 138 ::wm::GetTransientParent(window)->parent()->id(); | |
| 139 aura::Window* container = NULL; | |
| 140 if (window_container_id < kShellWindowId_LockScreenContainer) { | |
| 141 container = GetContainerById(root, kShellWindowId_SystemModalContainer); | |
| 142 } else { | |
| 143 container = GetContainerById(root, kShellWindowId_LockSystemModalContainer); | |
| 144 } | |
| 145 | |
| 146 return container; | |
| 147 } | 27 } |
| 148 | 28 |
| 149 } // namespace ash | 29 } // namespace ash |
| OLD | NEW |