OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/root_window_controller.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ash/shell_factory.h" |
| 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/wm/base_layout_manager.h" |
| 11 #include "ash/wm/event_client_impl.h" |
| 12 #include "ash/wm/property_util.h" |
| 13 #include "ash/wm/root_window_layout_manager.h" |
| 14 #include "ash/wm/screen_dimmer.h" |
| 15 #include "ash/wm/system_modal_container_layout_manager.h" |
| 16 #include "ash/wm/toplevel_window_event_filter.h" |
| 17 #include "ash/wm/visibility_controller.h" |
| 18 #include "ash/wm/workspace/workspace_manager.h" |
| 19 #include "ash/wm/workspace_controller.h" |
| 20 #include "ui/aura/client/tooltip_client.h" |
| 21 #include "ui/aura/root_window.h" |
| 22 |
| 23 namespace ash { |
| 24 namespace { |
| 25 |
| 26 // Creates a new window for use as a container. |
| 27 aura::Window* CreateContainer(int window_id, |
| 28 const char* name, |
| 29 aura::Window* parent) { |
| 30 aura::Window* container = new aura::Window(NULL); |
| 31 container->set_id(window_id); |
| 32 container->SetName(name); |
| 33 container->Init(ui::LAYER_NOT_DRAWN); |
| 34 parent->AddChild(container); |
| 35 if (window_id != internal::kShellWindowId_UnparentedControlContainer) |
| 36 container->Show(); |
| 37 return container; |
| 38 } |
| 39 |
| 40 // Creates each of the special window containers that holds windows of various |
| 41 // types in the shell UI. |
| 42 void CreateContainersInRootWindow(aura::RootWindow* root_window) { |
| 43 // These containers are just used by PowerButtonController to animate groups |
| 44 // of containers simultaneously without messing up the current transformations |
| 45 // on those containers. These are direct children of the root window; all of |
| 46 // the other containers are their children. |
| 47 aura::Window* non_lock_screen_containers = CreateContainer( |
| 48 internal::kShellWindowId_NonLockScreenContainersContainer, |
| 49 "NonLockScreenContainersContainer", |
| 50 root_window); |
| 51 aura::Window* lock_screen_containers = CreateContainer( |
| 52 internal::kShellWindowId_LockScreenContainersContainer, |
| 53 "LockScreenContainersContainer", |
| 54 root_window); |
| 55 aura::Window* lock_screen_related_containers = CreateContainer( |
| 56 internal::kShellWindowId_LockScreenRelatedContainersContainer, |
| 57 "LockScreenRelatedContainersContainer", |
| 58 root_window); |
| 59 |
| 60 CreateContainer(internal::kShellWindowId_UnparentedControlContainer, |
| 61 "UnparentedControlContainer", |
| 62 non_lock_screen_containers); |
| 63 |
| 64 aura::Window* desktop_background_containers = CreateContainer( |
| 65 internal::kShellWindowId_DesktopBackgroundContainer, |
| 66 "DesktopBackgroundContainer", |
| 67 non_lock_screen_containers); |
| 68 SetChildWindowVisibilityChangesAnimated(desktop_background_containers); |
| 69 |
| 70 aura::Window* default_container = CreateContainer( |
| 71 internal::kShellWindowId_DefaultContainer, |
| 72 "DefaultContainer", |
| 73 non_lock_screen_containers); |
| 74 default_container->SetEventFilter( |
| 75 new ToplevelWindowEventFilter(default_container)); |
| 76 SetChildWindowVisibilityChangesAnimated(default_container); |
| 77 |
| 78 aura::Window* always_on_top_container = CreateContainer( |
| 79 internal::kShellWindowId_AlwaysOnTopContainer, |
| 80 "AlwaysOnTopContainer", |
| 81 non_lock_screen_containers); |
| 82 always_on_top_container->SetEventFilter( |
| 83 new ToplevelWindowEventFilter(always_on_top_container)); |
| 84 SetChildWindowVisibilityChangesAnimated(always_on_top_container); |
| 85 |
| 86 CreateContainer(internal::kShellWindowId_PanelContainer, |
| 87 "PanelContainer", |
| 88 non_lock_screen_containers); |
| 89 |
| 90 CreateContainer(internal::kShellWindowId_LauncherContainer, |
| 91 "LauncherContainer", |
| 92 non_lock_screen_containers); |
| 93 |
| 94 CreateContainer(internal::kShellWindowId_AppListContainer, |
| 95 "AppListContainer", |
| 96 non_lock_screen_containers); |
| 97 |
| 98 aura::Window* modal_container = CreateContainer( |
| 99 internal::kShellWindowId_SystemModalContainer, |
| 100 "SystemModalContainer", |
| 101 non_lock_screen_containers); |
| 102 modal_container->SetEventFilter( |
| 103 new ToplevelWindowEventFilter(modal_container)); |
| 104 modal_container->SetLayoutManager( |
| 105 new internal::SystemModalContainerLayoutManager(modal_container)); |
| 106 SetChildWindowVisibilityChangesAnimated(modal_container); |
| 107 |
| 108 // TODO(beng): Figure out if we can make this use |
| 109 // SystemModalContainerEventFilter instead of stops_event_propagation. |
| 110 aura::Window* lock_container = CreateContainer( |
| 111 internal::kShellWindowId_LockScreenContainer, |
| 112 "LockScreenContainer", |
| 113 lock_screen_containers); |
| 114 lock_container->SetLayoutManager( |
| 115 new internal::BaseLayoutManager(root_window)); |
| 116 // TODO(beng): stopsevents |
| 117 |
| 118 aura::Window* lock_modal_container = CreateContainer( |
| 119 internal::kShellWindowId_LockSystemModalContainer, |
| 120 "LockSystemModalContainer", |
| 121 lock_screen_containers); |
| 122 lock_modal_container->SetEventFilter( |
| 123 new ToplevelWindowEventFilter(lock_modal_container)); |
| 124 lock_modal_container->SetLayoutManager( |
| 125 new internal::SystemModalContainerLayoutManager(lock_modal_container)); |
| 126 SetChildWindowVisibilityChangesAnimated(lock_modal_container); |
| 127 |
| 128 CreateContainer(internal::kShellWindowId_StatusContainer, |
| 129 "StatusContainer", |
| 130 lock_screen_related_containers); |
| 131 |
| 132 aura::Window* settings_bubble_container = CreateContainer( |
| 133 internal::kShellWindowId_SettingBubbleContainer, |
| 134 "SettingBubbleContainer", |
| 135 lock_screen_related_containers); |
| 136 SetChildWindowVisibilityChangesAnimated(settings_bubble_container); |
| 137 |
| 138 aura::Window* menu_container = CreateContainer( |
| 139 internal::kShellWindowId_MenuContainer, |
| 140 "MenuContainer", |
| 141 lock_screen_related_containers); |
| 142 SetChildWindowVisibilityChangesAnimated(menu_container); |
| 143 |
| 144 aura::Window* drag_drop_container = CreateContainer( |
| 145 internal::kShellWindowId_DragImageAndTooltipContainer, |
| 146 "DragImageAndTooltipContainer", |
| 147 lock_screen_related_containers); |
| 148 SetChildWindowVisibilityChangesAnimated(drag_drop_container); |
| 149 |
| 150 CreateContainer(internal::kShellWindowId_OverlayContainer, |
| 151 "OverlayContainer", |
| 152 lock_screen_related_containers); |
| 153 } |
| 154 |
| 155 } // namespace |
| 156 |
| 157 namespace internal { |
| 158 |
| 159 RootWindowController::RootWindowController(aura::RootWindow* root_window) |
| 160 : root_window_(root_window) { |
| 161 SetRootWindowController(root_window, this); |
| 162 |
| 163 event_client_.reset(new internal::EventClientImpl(root_window)); |
| 164 screen_dimmer_.reset(new internal::ScreenDimmer(root_window)); |
| 165 } |
| 166 |
| 167 RootWindowController::~RootWindowController() { |
| 168 SetRootWindowController(root_window_.get(), NULL); |
| 169 event_client_.reset(); |
| 170 screen_dimmer_.reset(); |
| 171 workspace_controller_.reset(); |
| 172 root_window_.reset(); |
| 173 } |
| 174 |
| 175 aura::Window* RootWindowController::GetContainer(int container_id) { |
| 176 return root_window_->GetChildById(container_id); |
| 177 } |
| 178 |
| 179 void RootWindowController::InitLayoutManagers() { |
| 180 root_window_layout_ = |
| 181 new internal::RootWindowLayoutManager(root_window_.get()); |
| 182 root_window_->SetLayoutManager(root_window_layout_); |
| 183 |
| 184 aura::Window* default_container = |
| 185 GetContainer(internal::kShellWindowId_DefaultContainer); |
| 186 // Workspace manager has its own layout managers. |
| 187 workspace_controller_.reset( |
| 188 new internal::WorkspaceController(default_container)); |
| 189 |
| 190 aura::Window* always_on_top_container = |
| 191 GetContainer(internal::kShellWindowId_AlwaysOnTopContainer); |
| 192 always_on_top_container->SetLayoutManager( |
| 193 new internal::BaseLayoutManager( |
| 194 always_on_top_container->GetRootWindow())); |
| 195 } |
| 196 |
| 197 void RootWindowController::CreateContainers() { |
| 198 CreateContainersInRootWindow(root_window_.get()); |
| 199 } |
| 200 |
| 201 void RootWindowController::CloseChildWindows() { |
| 202 // Close background widget first as it depends on tooltip. |
| 203 root_window_layout_->SetBackgroundWidget(NULL); |
| 204 workspace_controller_.reset(); |
| 205 aura::client::SetTooltipClient(root_window_.get(), NULL); |
| 206 |
| 207 while (!root_window_->children().empty()) { |
| 208 aura::Window* child = root_window_->children()[0]; |
| 209 delete child; |
| 210 } |
| 211 } |
| 212 |
| 213 bool RootWindowController::IsInMaximizedMode() const { |
| 214 return workspace_controller_->workspace_manager()->IsInMaximizedMode(); |
| 215 } |
| 216 |
| 217 } // namespace internal |
| 218 } // namespace ash |
OLD | NEW |