Chromium Code Reviews| 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/root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/desktop_background/desktop_background_widget_controller.h" | 9 #include "ash/desktop_background/desktop_background_widget_controller.h" |
| 10 #include "ash/display/display_controller.h" | 10 #include "ash/display/display_controller.h" |
| 11 #include "ash/display/multi_display_manager.h" | 11 #include "ash/display/multi_display_manager.h" |
| 12 #include "ash/focus_cycler.h" | |
| 12 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/shell_delegate.h" | |
| 13 #include "ash/shell_factory.h" | 15 #include "ash/shell_factory.h" |
| 14 #include "ash/shell_window_ids.h" | 16 #include "ash/shell_window_ids.h" |
| 17 #include "ash/system/status_area_widget.h" | |
| 15 #include "ash/wm/base_layout_manager.h" | 18 #include "ash/wm/base_layout_manager.h" |
| 19 #include "ash/wm/panel_layout_manager.h" | |
| 20 #include "ash/wm/panel_window_event_filter.h" | |
| 16 #include "ash/wm/property_util.h" | 21 #include "ash/wm/property_util.h" |
| 17 #include "ash/wm/root_window_layout_manager.h" | 22 #include "ash/wm/root_window_layout_manager.h" |
| 18 #include "ash/wm/screen_dimmer.h" | 23 #include "ash/wm/screen_dimmer.h" |
| 24 #include "ash/wm/shelf_layout_manager.h" | |
| 25 #include "ash/wm/shelf_types.h" | |
| 26 #include "ash/wm/status_area_layout_manager.h" | |
| 19 #include "ash/wm/system_modal_container_layout_manager.h" | 27 #include "ash/wm/system_modal_container_layout_manager.h" |
| 20 #include "ash/wm/toplevel_window_event_handler.h" | 28 #include "ash/wm/toplevel_window_event_handler.h" |
| 21 #include "ash/wm/visibility_controller.h" | 29 #include "ash/wm/visibility_controller.h" |
| 22 #include "ash/wm/window_properties.h" | 30 #include "ash/wm/window_properties.h" |
| 23 #include "ash/wm/workspace/system_background_controller.h" | 31 #include "ash/wm/workspace/system_background_controller.h" |
| 24 #include "ash/wm/workspace_controller.h" | 32 #include "ash/wm/workspace_controller.h" |
| 25 #include "ui/aura/client/activation_client.h" | 33 #include "ui/aura/client/activation_client.h" |
| 26 #include "ui/aura/client/aura_constants.h" | 34 #include "ui/aura/client/aura_constants.h" |
| 27 #include "ui/aura/client/capture_client.h" | 35 #include "ui/aura/client/capture_client.h" |
| 28 #include "ui/aura/client/tooltip_client.h" | 36 #include "ui/aura/client/tooltip_client.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 // use the virtual screeen coordinates instead of parent. | 142 // use the virtual screeen coordinates instead of parent. |
| 135 void SetUsesScreenCoordinates(aura::Window* container) { | 143 void SetUsesScreenCoordinates(aura::Window* container) { |
| 136 container->SetProperty(internal::kUsesScreenCoordinatesKey, true); | 144 container->SetProperty(internal::kUsesScreenCoordinatesKey, true); |
| 137 } | 145 } |
| 138 | 146 |
| 139 } // namespace | 147 } // namespace |
| 140 | 148 |
| 141 namespace internal { | 149 namespace internal { |
| 142 | 150 |
| 143 RootWindowController::RootWindowController(aura::RootWindow* root_window) | 151 RootWindowController::RootWindowController(aura::RootWindow* root_window) |
| 144 : root_window_(root_window) { | 152 : root_window_(root_window), |
| 153 root_window_layout_(NULL), | |
| 154 status_area_widget_(NULL), | |
| 155 shelf_(NULL), | |
| 156 panel_layout_manager_(NULL) { | |
| 145 SetRootWindowController(root_window, this); | 157 SetRootWindowController(root_window, this); |
| 146 screen_dimmer_.reset(new ScreenDimmer(root_window)); | 158 screen_dimmer_.reset(new ScreenDimmer(root_window)); |
| 147 } | 159 } |
| 148 | 160 |
| 149 RootWindowController::~RootWindowController() { | 161 RootWindowController::~RootWindowController() { |
| 150 Shutdown(); | 162 Shutdown(); |
| 151 root_window_.reset(); | 163 root_window_.reset(); |
| 152 } | 164 } |
| 153 | 165 |
| 154 void RootWindowController::Shutdown() { | 166 void RootWindowController::Shutdown() { |
| 155 CloseChildWindows(); | 167 CloseChildWindows(); |
| 156 if (Shell::GetActiveRootWindow() == root_window_.get()) { | 168 if (Shell::GetActiveRootWindow() == root_window_.get()) { |
| 157 Shell::GetInstance()->set_active_root_window( | 169 Shell::GetInstance()->set_active_root_window( |
| 158 Shell::GetPrimaryRootWindow() == root_window_.get() ? | 170 Shell::GetPrimaryRootWindow() == root_window_.get() ? |
| 159 NULL : Shell::GetPrimaryRootWindow()); | 171 NULL : Shell::GetPrimaryRootWindow()); |
| 160 } | 172 } |
| 161 SetRootWindowController(root_window_.get(), NULL); | 173 SetRootWindowController(root_window_.get(), NULL); |
| 162 screen_dimmer_.reset(); | 174 screen_dimmer_.reset(); |
| 163 workspace_controller_.reset(); | 175 workspace_controller_.reset(); |
| 164 // Forget with the display ID so that display lookup | 176 // Forget with the display ID so that display lookup |
| 165 // ends up with invalid display. | 177 // ends up with invalid display. |
| 166 root_window_->ClearProperty(kDisplayIdKey); | 178 root_window_->ClearProperty(kDisplayIdKey); |
| 167 // And this root window should no longer process events. | 179 // And this root window should no longer process events. |
| 168 root_window_->PrepareForShutdown(); | 180 root_window_->PrepareForShutdown(); |
| 181 | |
| 182 // Launcher widget has a InputMethodBridge that references to | |
|
sky
2012/10/11 16:38:25
a -> an
oshima
2012/10/11 20:19:51
Done.
| |
| 183 // input_method_filter_'s input_method_. So explicitly release launcher_ | |
|
sky
2012/10/11 16:38:25
|s around references to fields/params
oshima
2012/10/11 20:19:51
Done.
| |
| 184 // before input_method_filter_. And this needs to be after we delete all | |
| 185 // containers in case there are still live browser windows which access | |
| 186 // LauncherModel during close. | |
| 187 launcher_.reset(); | |
| 169 } | 188 } |
| 170 | 189 |
| 171 SystemModalContainerLayoutManager* | 190 SystemModalContainerLayoutManager* |
| 172 RootWindowController::GetSystemModalLayoutManager() { | 191 RootWindowController::GetSystemModalLayoutManager() { |
| 173 return static_cast<SystemModalContainerLayoutManager*>( | 192 return static_cast<SystemModalContainerLayoutManager*>( |
| 174 GetContainer(kShellWindowId_SystemModalContainer)->layout_manager()); | 193 GetContainer(kShellWindowId_SystemModalContainer)->layout_manager()); |
| 175 } | 194 } |
| 176 | 195 |
| 177 aura::Window* RootWindowController::GetContainer(int container_id) { | 196 aura::Window* RootWindowController::GetContainer(int container_id) { |
| 178 return root_window_->GetChildById(container_id); | 197 return root_window_->GetChildById(container_id); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 189 workspace_controller_.reset( | 208 workspace_controller_.reset( |
| 190 new WorkspaceController(default_container)); | 209 new WorkspaceController(default_container)); |
| 191 | 210 |
| 192 aura::Window* always_on_top_container = | 211 aura::Window* always_on_top_container = |
| 193 GetContainer(kShellWindowId_AlwaysOnTopContainer); | 212 GetContainer(kShellWindowId_AlwaysOnTopContainer); |
| 194 always_on_top_container->SetLayoutManager( | 213 always_on_top_container->SetLayoutManager( |
| 195 new BaseLayoutManager( | 214 new BaseLayoutManager( |
| 196 always_on_top_container->GetRootWindow())); | 215 always_on_top_container->GetRootWindow())); |
| 197 } | 216 } |
| 198 | 217 |
| 218 void RootWindowController::InitForPrimaryDisplay() { | |
| 219 DCHECK(!status_area_widget_); | |
| 220 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | |
| 221 | |
| 222 // Initialize Primary RootWindow specific items. | |
| 223 status_area_widget_ = new internal::StatusAreaWidget(); | |
| 224 status_area_widget_->CreateTrayViews(delegate); | |
| 225 // Login screen manages status area visibility by itself. | |
| 226 if (delegate && delegate->IsSessionStarted()) | |
| 227 status_area_widget_->Show(); | |
| 228 | |
| 229 Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_); | |
| 230 | |
| 231 internal::ShelfLayoutManager* shelf_layout_manager = | |
| 232 new internal::ShelfLayoutManager(status_area_widget_); | |
| 233 GetContainer(internal::kShellWindowId_LauncherContainer)-> | |
| 234 SetLayoutManager(shelf_layout_manager); | |
| 235 shelf_ = shelf_layout_manager; | |
| 236 | |
| 237 internal::StatusAreaLayoutManager* status_area_layout_manager = | |
| 238 new internal::StatusAreaLayoutManager(shelf_layout_manager); | |
| 239 GetContainer(internal::kShellWindowId_StatusContainer)-> | |
| 240 SetLayoutManager(status_area_layout_manager); | |
| 241 | |
| 242 shelf_layout_manager->set_workspace_controller( | |
| 243 workspace_controller()); | |
| 244 | |
| 245 workspace_controller()->SetShelf(shelf_); | |
| 246 | |
| 247 // Create Panel layout manager | |
| 248 aura::Window* panel_container = GetContainer( | |
| 249 internal::kShellWindowId_PanelContainer); | |
| 250 panel_layout_manager_ = | |
| 251 new internal::PanelLayoutManager(panel_container); | |
| 252 panel_container->SetEventFilter( | |
| 253 new internal::PanelWindowEventFilter( | |
| 254 panel_container, panel_layout_manager_)); | |
| 255 panel_container->SetLayoutManager(panel_layout_manager_); | |
| 256 | |
| 257 if (!delegate || delegate->IsUserLoggedIn()) | |
| 258 CreateLauncher(); | |
| 259 } | |
| 260 | |
| 199 void RootWindowController::CreateContainers() { | 261 void RootWindowController::CreateContainers() { |
| 200 CreateContainersInRootWindow(root_window_.get()); | 262 CreateContainersInRootWindow(root_window_.get()); |
| 201 } | 263 } |
| 202 | 264 |
| 203 void RootWindowController::CreateSystemBackground( | 265 void RootWindowController::CreateSystemBackground( |
| 204 bool is_first_run_after_boot) { | 266 bool is_first_run_after_boot) { |
| 205 SkColor color = SK_ColorBLACK; | 267 SkColor color = SK_ColorBLACK; |
| 206 #if defined(OS_CHROMEOS) | 268 #if defined(OS_CHROMEOS) |
| 207 if (is_first_run_after_boot) | 269 if (is_first_run_after_boot) |
| 208 color = kBootSystemBackgroundColor; | 270 color = kBootSystemBackgroundColor; |
| 209 #endif | 271 #endif |
| 210 background_.reset(new SystemBackgroundController(root_window_.get(), color)); | 272 background_.reset(new SystemBackgroundController(root_window_.get(), color)); |
| 211 } | 273 } |
| 212 | 274 |
| 275 void RootWindowController::CreateLauncher() { | |
| 276 if (launcher_.get()) | |
| 277 return; | |
| 278 | |
| 279 aura::Window* default_container = | |
| 280 GetContainer(internal::kShellWindowId_DefaultContainer); | |
| 281 launcher_.reset(new Launcher(default_container, shelf_)); | |
| 282 | |
| 283 launcher_->SetFocusCycler(Shell::GetInstance()->focus_cycler()); | |
| 284 shelf_->SetLauncher(launcher_.get()); | |
| 285 | |
| 286 if (panel_layout_manager_) | |
| 287 panel_layout_manager_->SetLauncher(launcher_.get()); | |
| 288 | |
| 289 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | |
| 290 if (delegate) | |
| 291 launcher_->SetVisible(delegate->IsSessionStarted()); | |
| 292 launcher_->widget()->Show(); | |
| 293 } | |
| 294 | |
| 295 void RootWindowController::ShowLauncher() { | |
| 296 if (!launcher_.get()) | |
| 297 return; | |
| 298 launcher_->SetVisible(true); | |
| 299 } | |
| 300 | |
| 213 void RootWindowController::HandleDesktopBackgroundVisible() { | 301 void RootWindowController::HandleDesktopBackgroundVisible() { |
| 214 if (background_.get()) | 302 if (background_.get()) |
| 215 background_->SetColor(SK_ColorBLACK); | 303 background_->SetColor(SK_ColorBLACK); |
| 216 } | 304 } |
| 217 | 305 |
| 218 void RootWindowController::CloseChildWindows() { | 306 void RootWindowController::CloseChildWindows() { |
| 307 // The status area needs to be shut down before the windows are destroyed. | |
| 308 if (status_area_widget_) | |
| 309 status_area_widget_->Shutdown(); | |
| 310 | |
| 311 // Closing the windows frees the workspace controller. | |
| 312 if (shelf_) | |
| 313 shelf_->set_workspace_controller(NULL); | |
| 314 | |
| 219 // Close background widget first as it depends on tooltip. | 315 // Close background widget first as it depends on tooltip. |
| 220 root_window_->SetProperty(kDesktopController, | 316 root_window_->SetProperty(kDesktopController, |
| 221 static_cast<DesktopBackgroundWidgetController*>(NULL)); | 317 static_cast<DesktopBackgroundWidgetController*>(NULL)); |
| 222 root_window_->SetProperty(kAnimatingDesktopController, | 318 root_window_->SetProperty(kAnimatingDesktopController, |
| 223 static_cast<AnimatingDesktopController*>(NULL)); | 319 static_cast<AnimatingDesktopController*>(NULL)); |
| 224 | 320 |
| 225 workspace_controller_.reset(); | 321 workspace_controller_.reset(); |
| 226 aura::client::SetTooltipClient(root_window_.get(), NULL); | 322 aura::client::SetTooltipClient(root_window_.get(), NULL); |
| 227 | 323 |
| 228 while (!root_window_->children().empty()) { | 324 while (!root_window_->children().empty()) { |
| 229 aura::Window* child = root_window_->children()[0]; | 325 aura::Window* child = root_window_->children()[0]; |
| 230 delete child; | 326 delete child; |
| 231 } | 327 } |
| 328 | |
| 329 // TODO(oshima): Closing window triggers access to status area widget | |
| 330 // in ShelfLayoutManager. We probably should disalb/remove shelf layout | |
| 331 // manager before destorying windows? | |
| 332 status_area_widget_ = NULL; | |
| 232 } | 333 } |
| 233 | 334 |
| 234 bool RootWindowController::IsInMaximizedMode() const { | 335 bool RootWindowController::IsInMaximizedMode() const { |
| 235 return workspace_controller_->IsInMaximizedMode(); | 336 return workspace_controller_->IsInMaximizedMode(); |
| 236 } | 337 } |
| 237 | 338 |
| 238 void RootWindowController::MoveWindowsTo(aura::RootWindow* dst) { | 339 void RootWindowController::MoveWindowsTo(aura::RootWindow* dst) { |
| 239 aura::Window* focused = dst->GetFocusManager()->GetFocusedWindow(); | 340 aura::Window* focused = dst->GetFocusManager()->GetFocusedWindow(); |
| 240 aura::WindowTracker tracker; | 341 aura::WindowTracker tracker; |
| 241 if (focused) | 342 if (focused) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 259 ReparentAllWindows(root_window_.get(), dst); | 360 ReparentAllWindows(root_window_.get(), dst); |
| 260 | 361 |
| 261 // Restore focused or active window if it's still alive. | 362 // Restore focused or active window if it's still alive. |
| 262 if (focused && tracker.Contains(focused) && dst->Contains(focused)) { | 363 if (focused && tracker.Contains(focused) && dst->Contains(focused)) { |
| 263 dst->GetFocusManager()->SetFocusedWindow(focused, NULL); | 364 dst->GetFocusManager()->SetFocusedWindow(focused, NULL); |
| 264 } else if (active && tracker.Contains(active) && dst->Contains(active)) { | 365 } else if (active && tracker.Contains(active) && dst->Contains(active)) { |
| 265 activation_client->ActivateWindow(active); | 366 activation_client->ActivateWindow(active); |
| 266 } | 367 } |
| 267 } | 368 } |
| 268 | 369 |
| 370 void RootWindowController::UpdateShelfVisibility() { | |
| 371 shelf_->UpdateVisibilityState(); | |
| 372 } | |
| 373 | |
| 374 void RootWindowController::SetShelfAutoHideBehavior( | |
| 375 ShelfAutoHideBehavior behavior) { | |
| 376 shelf_->SetAutoHideBehavior(behavior); | |
| 377 } | |
| 378 | |
| 379 ShelfAutoHideBehavior RootWindowController::GetShelfAutoHideBehavior() const { | |
| 380 return shelf_->auto_hide_behavior(); | |
| 381 } | |
| 382 | |
| 383 bool RootWindowController::SetShelfAlignment(ShelfAlignment alignment) { | |
| 384 return shelf_->SetAlignment(alignment); | |
| 385 } | |
| 386 | |
| 387 ShelfAlignment RootWindowController::GetShelfAlignment() { | |
| 388 return shelf_->alignment(); | |
| 389 } | |
| 390 | |
| 269 //////////////////////////////////////////////////////////////////////////////// | 391 //////////////////////////////////////////////////////////////////////////////// |
| 270 // RootWindowController, private: | 392 // RootWindowController, private: |
| 271 | 393 |
| 272 void RootWindowController::CreateContainersInRootWindow( | 394 void RootWindowController::CreateContainersInRootWindow( |
| 273 aura::RootWindow* root_window) { | 395 aura::RootWindow* root_window) { |
| 274 // These containers are just used by PowerButtonController to animate groups | 396 // These containers are just used by PowerButtonController to animate groups |
| 275 // of containers simultaneously without messing up the current transformations | 397 // of containers simultaneously without messing up the current transformations |
| 276 // on those containers. These are direct children of the root window; all of | 398 // on those containers. These are direct children of the root window; all of |
| 277 // the other containers are their children. | 399 // the other containers are their children. |
| 278 // Desktop and lock screen background containers are not part of the | 400 // Desktop and lock screen background containers are not part of the |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 | 542 |
| 421 aura::Window* overlay_container = CreateContainer( | 543 aura::Window* overlay_container = CreateContainer( |
| 422 kShellWindowId_OverlayContainer, | 544 kShellWindowId_OverlayContainer, |
| 423 "OverlayContainer", | 545 "OverlayContainer", |
| 424 lock_screen_related_containers); | 546 lock_screen_related_containers); |
| 425 SetUsesScreenCoordinates(overlay_container); | 547 SetUsesScreenCoordinates(overlay_container); |
| 426 } | 548 } |
| 427 | 549 |
| 428 } // namespace internal | 550 } // namespace internal |
| 429 } // namespace ash | 551 } // namespace ash |
| OLD | NEW |