| 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/desktop.h" | 10 #include "ui/aura/desktop.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace | 76 } // namespace |
| 77 | 77 |
| 78 // static | 78 // static |
| 79 Shell* Shell::instance_ = NULL; | 79 Shell* Shell::instance_ = NULL; |
| 80 | 80 |
| 81 //////////////////////////////////////////////////////////////////////////////// | 81 //////////////////////////////////////////////////////////////////////////////// |
| 82 // Shell, public: | 82 // Shell, public: |
| 83 | 83 |
| 84 Shell::Shell() | 84 Shell::Shell(ShellDelegate* delegate) |
| 85 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 85 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 86 delegate_(delegate) { |
| 86 aura::Desktop::GetInstance()->SetStackingClient(this); | 87 aura::Desktop::GetInstance()->SetStackingClient(this); |
| 87 } | 88 } |
| 88 | 89 |
| 89 Shell::~Shell() { | 90 Shell::~Shell() { |
| 90 // Make sure we delete WorkspaceController before launcher is | 91 // Make sure we delete WorkspaceController before launcher is |
| 91 // deleted as it has a reference to launcher model. | 92 // deleted as it has a reference to launcher model. |
| 92 workspace_controller_.reset(); | 93 workspace_controller_.reset(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 // static | 96 // static |
| 97 Shell* Shell::CreateInstance(ShellDelegate* delegate) { |
| 98 CHECK(!instance_); |
| 99 instance_ = new Shell(delegate); |
| 100 instance_->Init(); |
| 101 return instance_; |
| 102 } |
| 103 // static |
| 96 Shell* Shell::GetInstance() { | 104 Shell* Shell::GetInstance() { |
| 97 if (!instance_) { | 105 DCHECK(instance_); |
| 98 instance_ = new Shell; | |
| 99 instance_->Init(); | |
| 100 } | |
| 101 return instance_; | 106 return instance_; |
| 102 } | 107 } |
| 103 | 108 |
| 104 void Shell::Init() { | 109 void Shell::Init() { |
| 105 aura::Desktop* desktop_window = aura::Desktop::GetInstance(); | 110 aura::Desktop* desktop_window = aura::Desktop::GetInstance(); |
| 106 desktop_window->SetCursor(aura::kCursorPointer); | 111 desktop_window->SetCursor(aura::kCursorPointer); |
| 107 | 112 |
| 108 aura::Window::Windows containers; | 113 aura::Window::Windows containers; |
| 109 CreateSpecialContainers(&containers); | 114 CreateSpecialContainers(&containers); |
| 110 aura::Window::Windows::const_iterator i; | 115 aura::Window::Windows::const_iterator i; |
| 111 for (i = containers.begin(); i != containers.end(); ++i) { | 116 for (i = containers.begin(); i != containers.end(); ++i) { |
| 112 (*i)->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 117 (*i)->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); |
| 113 desktop_window->AddChild(*i); | 118 desktop_window->AddChild(*i); |
| 114 (*i)->Show(); | 119 (*i)->Show(); |
| 115 } | 120 } |
| 116 | 121 |
| 117 internal::DesktopLayoutManager* desktop_layout = | 122 internal::DesktopLayoutManager* desktop_layout = |
| 118 new internal::DesktopLayoutManager(desktop_window); | 123 new internal::DesktopLayoutManager(desktop_window); |
| 119 desktop_window->SetLayoutManager(desktop_layout); | 124 desktop_window->SetLayoutManager(desktop_layout); |
| 120 | 125 |
| 121 desktop_layout->set_background_widget(internal::CreateDesktopBackground()); | 126 desktop_layout->set_background_widget(internal::CreateDesktopBackground()); |
| 127 |
| 122 aura::ToplevelWindowContainer* toplevel_container = | 128 aura::ToplevelWindowContainer* toplevel_container = |
| 123 GetContainer(internal::kShellWindowId_DefaultContainer)-> | 129 GetContainer(internal::kShellWindowId_DefaultContainer)-> |
| 124 AsToplevelWindowContainer(); | 130 AsToplevelWindowContainer(); |
| 125 launcher_.reset(new Launcher(toplevel_container)); | 131 launcher_.reset(new Launcher(toplevel_container)); |
| 126 | 132 |
| 133 views::Widget* status_widget = NULL; |
| 134 if (delegate_.get()) |
| 135 status_widget = delegate_->CreateStatusArea(); |
| 136 if (!status_widget) |
| 137 status_widget = internal::CreateStatusArea(); |
| 138 |
| 127 shelf_layout_controller_.reset(new internal::ShelfLayoutController( | 139 shelf_layout_controller_.reset(new internal::ShelfLayoutController( |
| 128 launcher_->widget(), internal::CreateStatusArea())); | 140 launcher_->widget(), status_widget)); |
| 141 |
| 129 desktop_layout->set_shelf(shelf_layout_controller_.get()); | 142 desktop_layout->set_shelf(shelf_layout_controller_.get()); |
| 130 | 143 |
| 131 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraWindows)) { | 144 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraWindows)) { |
| 132 EnableWorkspaceManager(); | 145 EnableWorkspaceManager(); |
| 133 } else { | 146 } else { |
| 134 internal::ToplevelLayoutManager* toplevel_layout_manager = | 147 internal::ToplevelLayoutManager* toplevel_layout_manager = |
| 135 new internal::ToplevelLayoutManager(); | 148 new internal::ToplevelLayoutManager(); |
| 136 toplevel_container->SetLayoutManager(toplevel_layout_manager); | 149 toplevel_container->SetLayoutManager(toplevel_layout_manager); |
| 137 toplevel_layout_manager->set_shelf(shelf_layout_controller_.get()); | 150 toplevel_layout_manager->set_shelf(shelf_layout_controller_.get()); |
| 138 } | 151 } |
| 139 | 152 |
| 140 // Force a layout. | 153 // Force a layout. |
| 141 desktop_layout->OnWindowResized(); | 154 desktop_layout->OnWindowResized(); |
| 142 } | 155 } |
| 143 | 156 |
| 144 void Shell::SetDelegate(ShellDelegate* delegate) { | |
| 145 delegate_.reset(delegate); | |
| 146 } | |
| 147 | |
| 148 aura::Window* Shell::GetContainer(int container_id) { | 157 aura::Window* Shell::GetContainer(int container_id) { |
| 149 return const_cast<aura::Window*>( | 158 return const_cast<aura::Window*>( |
| 150 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); | 159 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); |
| 151 } | 160 } |
| 152 | 161 |
| 153 const aura::Window* Shell::GetContainer(int container_id) const { | 162 const aura::Window* Shell::GetContainer(int container_id) const { |
| 154 return aura::Desktop::GetInstance()->GetChildById(container_id); | 163 return aura::Desktop::GetInstance()->GetChildById(container_id); |
| 155 } | 164 } |
| 156 | 165 |
| 157 void Shell::ToggleOverview() { | 166 void Shell::ToggleOverview() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 208 } |
| 200 | 209 |
| 201 aura::Window* Shell::GetTopmostWindowToActivate(aura::Window* ignore) const { | 210 aura::Window* Shell::GetTopmostWindowToActivate(aura::Window* ignore) const { |
| 202 const aura::ToplevelWindowContainer* container = | 211 const aura::ToplevelWindowContainer* container = |
| 203 GetContainer(internal::kShellWindowId_DefaultContainer)-> | 212 GetContainer(internal::kShellWindowId_DefaultContainer)-> |
| 204 AsToplevelWindowContainer(); | 213 AsToplevelWindowContainer(); |
| 205 return container->GetTopmostWindowToActivate(ignore); | 214 return container->GetTopmostWindowToActivate(ignore); |
| 206 } | 215 } |
| 207 | 216 |
| 208 } // namespace aura_shell | 217 } // namespace aura_shell |
| OLD | NEW |