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