| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura_shell/shell.h" | 5 #include "ui/aura_shell/shell.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "ui/aura/aura_switches.h" | 11 #include "ui/aura/aura_switches.h" |
| 12 #include "ui/aura/client/aura_constants.h" | 12 #include "ui/aura/client/aura_constants.h" |
| 13 #include "ui/aura/client/drag_drop_client.h" | 13 #include "ui/aura/client/drag_drop_client.h" |
| 14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/aura/layout_manager.h" | 15 #include "ui/aura/layout_manager.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_types.h" | 17 #include "ui/aura/window_types.h" |
| 18 #include "ui/aura_shell/activation_controller.h" | 18 #include "ui/aura_shell/activation_controller.h" |
| 19 #include "ui/aura_shell/app_list.h" | 19 #include "ui/aura_shell/app_list.h" |
| 20 #include "ui/aura_shell/default_container_event_filter.h" | 20 #include "ui/aura_shell/default_container_event_filter.h" |
| 21 #include "ui/aura_shell/default_container_layout_manager.h" | 21 #include "ui/aura_shell/default_container_layout_manager.h" |
| 22 #include "ui/aura_shell/root_window_event_filter.h" | 22 #include "ui/aura_shell/root_window_event_filter.h" |
| 23 #include "ui/aura_shell/root_window_layout_manager.h" | 23 #include "ui/aura_shell/root_window_layout_manager.h" |
| 24 #include "ui/aura_shell/drag_drop_controller.h" | 24 #include "ui/aura_shell/drag_drop_controller.h" |
| 25 #include "ui/aura_shell/laptop_mode_layout_manager.h" |
| 25 #include "ui/aura_shell/launcher/launcher.h" | 26 #include "ui/aura_shell/launcher/launcher.h" |
| 26 #include "ui/aura_shell/modal_container_layout_manager.h" | 27 #include "ui/aura_shell/modal_container_layout_manager.h" |
| 27 #include "ui/aura_shell/shadow_controller.h" | 28 #include "ui/aura_shell/shadow_controller.h" |
| 28 #include "ui/aura_shell/shelf_layout_manager.h" | 29 #include "ui/aura_shell/shelf_layout_manager.h" |
| 29 #include "ui/aura_shell/shell_accelerator_controller.h" | 30 #include "ui/aura_shell/shell_accelerator_controller.h" |
| 30 #include "ui/aura_shell/shell_accelerator_filter.h" | 31 #include "ui/aura_shell/shell_accelerator_filter.h" |
| 31 #include "ui/aura_shell/shell_delegate.h" | 32 #include "ui/aura_shell/shell_delegate.h" |
| 32 #include "ui/aura_shell/shell_factory.h" | 33 #include "ui/aura_shell/shell_factory.h" |
| 33 #include "ui/aura_shell/shell_tooltip_manager.h" | 34 #include "ui/aura_shell/shell_tooltip_manager.h" |
| 34 #include "ui/aura_shell/shell_window_ids.h" | 35 #include "ui/aura_shell/shell_window_ids.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 51 // Creates each of the special window containers that holds windows of various | 52 // Creates each of the special window containers that holds windows of various |
| 52 // types in the shell UI. They are added to |containers| from back to front in | 53 // types in the shell UI. They are added to |containers| from back to front in |
| 53 // the z-index. | 54 // the z-index. |
| 54 void CreateSpecialContainers(aura::Window::Windows* containers) { | 55 void CreateSpecialContainers(aura::Window::Windows* containers) { |
| 55 aura::Window* background_container = new aura::Window(NULL); | 56 aura::Window* background_container = new aura::Window(NULL); |
| 56 background_container->set_id( | 57 background_container->set_id( |
| 57 internal::kShellWindowId_DesktopBackgroundContainer); | 58 internal::kShellWindowId_DesktopBackgroundContainer); |
| 58 containers->push_back(background_container); | 59 containers->push_back(background_container); |
| 59 | 60 |
| 60 aura::Window* default_container = new aura::Window(NULL); | 61 aura::Window* default_container = new aura::Window(NULL); |
| 61 default_container->SetEventFilter( | 62 // Primary windows in laptop mode don't allow drag, so don't use the filter. |
| 62 new ToplevelWindowEventFilter(default_container)); | 63 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraLaptopMode)) { |
| 64 default_container->SetEventFilter( |
| 65 new ToplevelWindowEventFilter(default_container)); |
| 66 } |
| 63 default_container->set_id(internal::kShellWindowId_DefaultContainer); | 67 default_container->set_id(internal::kShellWindowId_DefaultContainer); |
| 64 containers->push_back(default_container); | 68 containers->push_back(default_container); |
| 65 | 69 |
| 66 aura::Window* always_on_top_container = new aura::Window(NULL); | 70 aura::Window* always_on_top_container = new aura::Window(NULL); |
| 67 always_on_top_container->SetEventFilter( | 71 always_on_top_container->SetEventFilter( |
| 68 new ToplevelWindowEventFilter(always_on_top_container)); | 72 new ToplevelWindowEventFilter(always_on_top_container)); |
| 69 always_on_top_container->set_id( | 73 always_on_top_container->set_id( |
| 70 internal::kShellWindowId_AlwaysOnTopContainer); | 74 internal::kShellWindowId_AlwaysOnTopContainer); |
| 71 containers->push_back(always_on_top_container); | 75 containers->push_back(always_on_top_container); |
| 72 | 76 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 (*i)->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 194 (*i)->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); |
| 191 root_window->AddChild(*i); | 195 root_window->AddChild(*i); |
| 192 (*i)->Show(); | 196 (*i)->Show(); |
| 193 } | 197 } |
| 194 | 198 |
| 195 internal::StackingController* stacking_controller = | 199 internal::StackingController* stacking_controller = |
| 196 static_cast<internal::StackingController*>( | 200 static_cast<internal::StackingController*>( |
| 197 root_window->stacking_client()); | 201 root_window->stacking_client()); |
| 198 stacking_controller->Init(); | 202 stacking_controller->Init(); |
| 199 | 203 |
| 200 internal::RootWindowLayoutManager* root_window_layout = | 204 InitLayoutManagers(root_window); |
| 201 new internal::RootWindowLayoutManager(root_window); | |
| 202 root_window->SetLayoutManager(root_window_layout); | |
| 203 | |
| 204 root_window_layout->set_background_widget( | |
| 205 internal::CreateDesktopBackground()); | |
| 206 aura::Window* default_container = | |
| 207 GetContainer(internal::kShellWindowId_DefaultContainer); | |
| 208 launcher_.reset(new Launcher(default_container)); | |
| 209 | |
| 210 views::Widget* status_widget = NULL; | |
| 211 if (delegate_.get()) | |
| 212 status_widget = delegate_->CreateStatusArea(); | |
| 213 if (!status_widget) | |
| 214 status_widget = internal::CreateStatusArea(); | |
| 215 | |
| 216 internal::ShelfLayoutManager* shelf_layout_manager = | |
| 217 new internal::ShelfLayoutManager(launcher_->widget(), status_widget); | |
| 218 GetContainer(aura_shell::internal::kShellWindowId_LauncherContainer)-> | |
| 219 SetLayoutManager(shelf_layout_manager); | |
| 220 | |
| 221 internal::StatusAreaLayoutManager* status_area_layout_manager = | |
| 222 new internal::StatusAreaLayoutManager(shelf_layout_manager); | |
| 223 GetContainer(aura_shell::internal::kShellWindowId_StatusContainer)-> | |
| 224 SetLayoutManager(status_area_layout_manager); | |
| 225 | 205 |
| 226 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 206 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 227 if (!command_line->HasSwitch(switches::kAuraNoShadows)) | 207 if (!command_line->HasSwitch(switches::kAuraNoShadows)) |
| 228 shadow_controller_.reset(new internal::ShadowController()); | 208 shadow_controller_.reset(new internal::ShadowController()); |
| 229 | 209 |
| 230 if (command_line->HasSwitch(switches::kAuraWorkspaceManager)) { | |
| 231 EnableWorkspaceManager(); | |
| 232 } else { | |
| 233 internal::ToplevelLayoutManager* toplevel_layout_manager = | |
| 234 new internal::ToplevelLayoutManager(); | |
| 235 default_container->SetLayoutManager(toplevel_layout_manager); | |
| 236 toplevel_layout_manager->set_shelf(shelf_layout_manager); | |
| 237 } | |
| 238 | |
| 239 // Force a layout. | 210 // Force a layout. |
| 240 root_window_layout->OnWindowResized(); | 211 root_window->layout_manager()->OnWindowResized(); |
| 241 | 212 |
| 242 // Initialize ShellAcceleratorFilter | 213 // Initialize ShellAcceleratorFilter |
| 243 accelerator_filter_.reset(new internal::ShellAcceleratorFilter); | 214 accelerator_filter_.reset(new internal::ShellAcceleratorFilter); |
| 244 AddRootWindowEventFilter(accelerator_filter_.get()); | 215 AddRootWindowEventFilter(accelerator_filter_.get()); |
| 245 | 216 |
| 246 // Initialize ShellTooltipManager | 217 // Initialize ShellTooltipManager |
| 247 tooltip_manager_.reset(new ShellTooltipManager); | 218 tooltip_manager_.reset(new ShellTooltipManager); |
| 248 aura::RootWindow::GetInstance()->SetProperty( | 219 aura::RootWindow::GetInstance()->SetProperty( |
| 249 aura::kRootWindowTooltipClientKey, | 220 aura::kRootWindowTooltipClientKey, |
| 250 static_cast<aura::TooltipClient*>(tooltip_manager_.get())); | 221 static_cast<aura::TooltipClient*>(tooltip_manager_.get())); |
| 251 AddRootWindowEventFilter(tooltip_manager_.get()); | 222 AddRootWindowEventFilter(tooltip_manager_.get()); |
| 252 | 223 |
| 253 // Initialize drag drop controller. | 224 // Initialize drag drop controller. |
| 254 drag_drop_controller_.reset(new internal::DragDropController); | 225 drag_drop_controller_.reset(new internal::DragDropController); |
| 255 aura::RootWindow::GetInstance()->SetProperty( | 226 aura::RootWindow::GetInstance()->SetProperty( |
| 256 aura::kRootWindowDragDropClientKey, | 227 aura::kRootWindowDragDropClientKey, |
| 257 static_cast<aura::DragDropClient*>(drag_drop_controller_.get())); | 228 static_cast<aura::DragDropClient*>(drag_drop_controller_.get())); |
| 258 } | 229 } |
| 259 | 230 |
| 231 void Shell::InitLayoutManagers(aura::RootWindow* root_window) { |
| 232 internal::RootWindowLayoutManager* root_window_layout = |
| 233 new internal::RootWindowLayoutManager(root_window); |
| 234 root_window->SetLayoutManager(root_window_layout); |
| 235 |
| 236 views::Widget* status_widget = NULL; |
| 237 if (delegate_.get()) |
| 238 status_widget = delegate_->CreateStatusArea(); |
| 239 if (!status_widget) |
| 240 status_widget = internal::CreateStatusArea(); |
| 241 |
| 242 aura::Window* default_container = |
| 243 GetContainer(internal::kShellWindowId_DefaultContainer); |
| 244 |
| 245 // Laptop mode has a simplified layout manager and doesn't use the launcher, |
| 246 // desktop background, shelf, etc. |
| 247 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraLaptopMode)) { |
| 248 default_container->SetLayoutManager( |
| 249 new internal::LaptopModeLayoutManager()); |
| 250 // TODO(jamescook): Adjust status area layout. |
| 251 return; |
| 252 } |
| 253 |
| 254 root_window_layout->set_background_widget( |
| 255 internal::CreateDesktopBackground()); |
| 256 launcher_.reset(new Launcher(default_container)); |
| 257 |
| 258 internal::ShelfLayoutManager* shelf_layout_manager = |
| 259 new internal::ShelfLayoutManager(launcher_->widget(), status_widget); |
| 260 GetContainer(aura_shell::internal::kShellWindowId_LauncherContainer)-> |
| 261 SetLayoutManager(shelf_layout_manager); |
| 262 |
| 263 internal::StatusAreaLayoutManager* status_area_layout_manager = |
| 264 new internal::StatusAreaLayoutManager(shelf_layout_manager); |
| 265 GetContainer(aura_shell::internal::kShellWindowId_StatusContainer)-> |
| 266 SetLayoutManager(status_area_layout_manager); |
| 267 |
| 268 // Workspace manager has its own layout managers. |
| 269 if (CommandLine::ForCurrentProcess()-> |
| 270 HasSwitch(switches::kAuraWorkspaceManager)) { |
| 271 EnableWorkspaceManager(); |
| 272 return; |
| 273 } |
| 274 |
| 275 // Default layout manager. |
| 276 internal::ToplevelLayoutManager* toplevel_layout_manager = |
| 277 new internal::ToplevelLayoutManager(); |
| 278 default_container->SetLayoutManager(toplevel_layout_manager); |
| 279 toplevel_layout_manager->set_shelf(shelf_layout_manager); |
| 280 } |
| 281 |
| 260 aura::Window* Shell::GetContainer(int container_id) { | 282 aura::Window* Shell::GetContainer(int container_id) { |
| 261 return const_cast<aura::Window*>( | 283 return const_cast<aura::Window*>( |
| 262 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); | 284 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); |
| 263 } | 285 } |
| 264 | 286 |
| 265 const aura::Window* Shell::GetContainer(int container_id) const { | 287 const aura::Window* Shell::GetContainer(int container_id) const { |
| 266 return aura::RootWindow::GetInstance()->GetChildById(container_id); | 288 return aura::RootWindow::GetInstance()->GetChildById(container_id); |
| 267 } | 289 } |
| 268 | 290 |
| 269 void Shell::AddRootWindowEventFilter(aura::EventFilter* filter) { | 291 void Shell::AddRootWindowEventFilter(aura::EventFilter* filter) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 new internal::WorkspaceController(default_container)); | 335 new internal::WorkspaceController(default_container)); |
| 314 workspace_controller_->SetLauncherModel(launcher_->model()); | 336 workspace_controller_->SetLauncherModel(launcher_->model()); |
| 315 default_container->SetEventFilter( | 337 default_container->SetEventFilter( |
| 316 new internal::DefaultContainerEventFilter(default_container)); | 338 new internal::DefaultContainerEventFilter(default_container)); |
| 317 default_container->SetLayoutManager( | 339 default_container->SetLayoutManager( |
| 318 new internal::DefaultContainerLayoutManager( | 340 new internal::DefaultContainerLayoutManager( |
| 319 workspace_controller_->workspace_manager())); | 341 workspace_controller_->workspace_manager())); |
| 320 } | 342 } |
| 321 | 343 |
| 322 } // namespace aura_shell | 344 } // namespace aura_shell |
| OLD | NEW |