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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 75 } |
76 | 76 |
77 } // namespace | 77 } // namespace |
78 | 78 |
79 // static | 79 // static |
80 Shell* Shell::instance_ = NULL; | 80 Shell* Shell::instance_ = NULL; |
81 | 81 |
82 //////////////////////////////////////////////////////////////////////////////// | 82 //////////////////////////////////////////////////////////////////////////////// |
83 // Shell, public: | 83 // Shell, public: |
84 | 84 |
85 Shell::Shell() | 85 Shell::Shell(ShellDelegate* delegate) |
86 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 86 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 87 delegate_(delegate) { |
87 aura::Desktop::GetInstance()->SetEventFilter( | 88 aura::Desktop::GetInstance()->SetEventFilter( |
88 new internal::DesktopEventFilter); | 89 new internal::DesktopEventFilter); |
89 aura::Desktop::GetInstance()->SetStackingClient( | 90 aura::Desktop::GetInstance()->SetStackingClient( |
90 new internal::StackingController); | 91 new internal::StackingController); |
91 } | 92 } |
92 | 93 |
93 Shell::~Shell() { | 94 Shell::~Shell() { |
94 // Make sure we delete WorkspaceController before launcher is | 95 // Make sure we delete WorkspaceController before launcher is |
95 // deleted as it has a reference to launcher model. | 96 // deleted as it has a reference to launcher model. |
96 workspace_controller_.reset(); | 97 workspace_controller_.reset(); |
97 } | 98 } |
98 | 99 |
99 // static | 100 // static |
| 101 Shell* Shell::CreateInstance(ShellDelegate* delegate) { |
| 102 CHECK(!instance_); |
| 103 instance_ = new Shell(delegate); |
| 104 instance_->Init(); |
| 105 return instance_; |
| 106 } |
| 107 |
| 108 // static |
100 Shell* Shell::GetInstance() { | 109 Shell* Shell::GetInstance() { |
101 if (!instance_) { | 110 DCHECK(instance_); |
102 instance_ = new Shell; | |
103 instance_->Init(); | |
104 } | |
105 return instance_; | 111 return instance_; |
106 } | 112 } |
107 | 113 |
108 // static | 114 // static |
109 void Shell::DeleteInstanceForTesting() { | 115 void Shell::DeleteInstanceForTesting() { |
110 delete instance_; | 116 delete instance_; |
111 instance_ = NULL; | 117 instance_ = NULL; |
112 } | 118 } |
113 | 119 |
114 void Shell::Init() { | 120 void Shell::Init() { |
(...skipping 11 matching lines...) Expand all Loading... |
126 | 132 |
127 internal::DesktopLayoutManager* desktop_layout = | 133 internal::DesktopLayoutManager* desktop_layout = |
128 new internal::DesktopLayoutManager(desktop_window); | 134 new internal::DesktopLayoutManager(desktop_window); |
129 desktop_window->SetLayoutManager(desktop_layout); | 135 desktop_window->SetLayoutManager(desktop_layout); |
130 | 136 |
131 desktop_layout->set_background_widget(internal::CreateDesktopBackground()); | 137 desktop_layout->set_background_widget(internal::CreateDesktopBackground()); |
132 aura::Window* default_container = | 138 aura::Window* default_container = |
133 GetContainer(internal::kShellWindowId_DefaultContainer); | 139 GetContainer(internal::kShellWindowId_DefaultContainer); |
134 launcher_.reset(new Launcher(default_container)); | 140 launcher_.reset(new Launcher(default_container)); |
135 | 141 |
| 142 views::Widget* status_widget = NULL; |
| 143 if (delegate_.get()) |
| 144 status_widget = delegate_->CreateStatusArea(); |
| 145 if (!status_widget) |
| 146 status_widget = internal::CreateStatusArea(); |
| 147 |
136 shelf_layout_controller_.reset(new internal::ShelfLayoutController( | 148 shelf_layout_controller_.reset(new internal::ShelfLayoutController( |
137 launcher_->widget(), internal::CreateStatusArea())); | 149 launcher_->widget(), status_widget)); |
| 150 |
138 desktop_layout->set_shelf(shelf_layout_controller_.get()); | 151 desktop_layout->set_shelf(shelf_layout_controller_.get()); |
139 | 152 |
140 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraWindows)) { | 153 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraWindows)) { |
141 EnableWorkspaceManager(); | 154 EnableWorkspaceManager(); |
142 } else { | 155 } else { |
143 internal::ToplevelLayoutManager* toplevel_layout_manager = | 156 internal::ToplevelLayoutManager* toplevel_layout_manager = |
144 new internal::ToplevelLayoutManager(); | 157 new internal::ToplevelLayoutManager(); |
145 default_container->SetLayoutManager(toplevel_layout_manager); | 158 default_container->SetLayoutManager(toplevel_layout_manager); |
146 toplevel_layout_manager->set_shelf(shelf_layout_controller_.get()); | 159 toplevel_layout_manager->set_shelf(shelf_layout_controller_.get()); |
147 } | 160 } |
148 | 161 |
149 // Force a layout. | 162 // Force a layout. |
150 desktop_layout->OnWindowResized(); | 163 desktop_layout->OnWindowResized(); |
151 } | 164 } |
152 | 165 |
153 void Shell::SetDelegate(ShellDelegate* delegate) { | |
154 delegate_.reset(delegate); | |
155 } | |
156 | |
157 aura::Window* Shell::GetContainer(int container_id) { | 166 aura::Window* Shell::GetContainer(int container_id) { |
158 return const_cast<aura::Window*>( | 167 return const_cast<aura::Window*>( |
159 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); | 168 const_cast<const aura_shell::Shell*>(this)->GetContainer(container_id)); |
160 } | 169 } |
161 | 170 |
162 const aura::Window* Shell::GetContainer(int container_id) const { | 171 const aura::Window* Shell::GetContainer(int container_id) const { |
163 return aura::Desktop::GetInstance()->GetChildById(container_id); | 172 return aura::Desktop::GetInstance()->GetChildById(container_id); |
164 } | 173 } |
165 | 174 |
166 void Shell::ToggleOverview() { | 175 void Shell::ToggleOverview() { |
(...skipping 12 matching lines...) Expand all Loading... |
179 new internal::WorkspaceController(default_container)); | 188 new internal::WorkspaceController(default_container)); |
180 workspace_controller_->SetLauncherModel(launcher_->model()); | 189 workspace_controller_->SetLauncherModel(launcher_->model()); |
181 default_container->SetEventFilter( | 190 default_container->SetEventFilter( |
182 new internal::DefaultContainerEventFilter(default_container)); | 191 new internal::DefaultContainerEventFilter(default_container)); |
183 default_container->SetLayoutManager( | 192 default_container->SetLayoutManager( |
184 new internal::DefaultContainerLayoutManager( | 193 new internal::DefaultContainerLayoutManager( |
185 workspace_controller_->workspace_manager())); | 194 workspace_controller_->workspace_manager())); |
186 } | 195 } |
187 | 196 |
188 } // namespace aura_shell | 197 } // namespace aura_shell |
OLD | NEW |