OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "apps/shell/browser/shell_desktop_controller.h" | 5 #include "apps/shell/browser/shell_desktop_controller.h" |
6 | 6 |
7 #include "apps/shell/browser/shell_app_window.h" | 7 #include "apps/shell/browser/shell_app_window_controller.h" |
8 #include "content/public/browser/context_factory.h" | 8 #include "content/public/browser/context_factory.h" |
9 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
10 #include "ui/aura/client/default_capture_client.h" | 10 #include "ui/aura/client/default_capture_client.h" |
11 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
12 #include "ui/aura/layout_manager.h" | 12 #include "ui/aura/layout_manager.h" |
13 #include "ui/aura/test/test_screen.h" | 13 #include "ui/aura/test/test_screen.h" |
14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
15 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
16 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
17 #include "ui/base/cursor/cursor.h" | 17 #include "ui/base/cursor/cursor.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 display_configurator_->ForceInitialConfigure(0); | 166 display_configurator_->ForceInitialConfigure(0); |
167 display_configurator_->AddObserver(this); | 167 display_configurator_->AddObserver(this); |
168 #endif | 168 #endif |
169 aura::Env::CreateInstance(true); | 169 aura::Env::CreateInstance(true); |
170 aura::Env::GetInstance()->set_context_factory(content::GetContextFactory()); | 170 aura::Env::GetInstance()->set_context_factory(content::GetContextFactory()); |
171 | 171 |
172 g_instance = this; | 172 g_instance = this; |
173 } | 173 } |
174 | 174 |
175 ShellDesktopController::~ShellDesktopController() { | 175 ShellDesktopController::~ShellDesktopController() { |
176 // The app window must be explicitly closed before desktop teardown. | 176 app_window_controller_.reset(); |
177 DCHECK(!app_window_); | |
178 g_instance = NULL; | 177 g_instance = NULL; |
179 DestroyRootWindow(); | 178 DestroyRootWindow(); |
180 aura::Env::DeleteInstance(); | 179 aura::Env::DeleteInstance(); |
181 } | 180 } |
182 | 181 |
183 // static | 182 // static |
184 ShellDesktopController* ShellDesktopController::instance() { | 183 ShellDesktopController* ShellDesktopController::instance() { |
185 return g_instance; | 184 return g_instance; |
186 } | 185 } |
187 | 186 |
187 void ShellDesktopController::SetAppWindowController( | |
188 ShellAppWindowController* app_window_controller) { | |
189 app_window_controller_.reset(app_window_controller); | |
190 } | |
191 | |
188 ShellAppWindow* ShellDesktopController::CreateAppWindow( | 192 ShellAppWindow* ShellDesktopController::CreateAppWindow( |
189 content::BrowserContext* context) { | 193 content::BrowserContext* context) { |
190 aura::Window* root_window = host_->window(); | 194 return app_window_controller_ |
oshima
2014/06/16 18:40:08
then you can remove NULL check?
Jun Mukai
2014/06/16 18:48:15
Removed, anyways app_window_controller_ needs to b
| |
191 | 195 ? app_window_controller_->CreateAppWindow(context) |
192 app_window_.reset(new ShellAppWindow); | 196 : NULL; |
193 app_window_->Init(context, root_window->bounds().size()); | |
194 | |
195 // Attach the web contents view to our window hierarchy. | |
196 aura::Window* content = app_window_->GetNativeWindow(); | |
197 root_window->AddChild(content); | |
198 content->Show(); | |
199 | |
200 return app_window_.get(); | |
201 } | 197 } |
202 | 198 |
203 void ShellDesktopController::CloseAppWindow() { app_window_.reset(); } | 199 void ShellDesktopController::CloseAppWindows() { |
200 if (app_window_controller_) | |
201 app_window_controller_->CloseAppWindows(); | |
202 } | |
204 | 203 |
205 aura::Window* ShellDesktopController::GetDefaultParent( | 204 aura::Window* ShellDesktopController::GetDefaultParent( |
206 aura::Window* context, | 205 aura::Window* context, |
207 aura::Window* window, | 206 aura::Window* window, |
208 const gfx::Rect& bounds) { | 207 const gfx::Rect& bounds) { |
209 return host_->window(); | 208 return host_->window(); |
210 } | 209 } |
211 | 210 |
212 #if defined(OS_CHROMEOS) | 211 #if defined(OS_CHROMEOS) |
213 void ShellDesktopController::OnDisplayModeChanged( | 212 void ShellDesktopController::OnDisplayModeChanged( |
214 const std::vector<ui::DisplayConfigurator::DisplayState>& displays) { | 213 const std::vector<ui::DisplayConfigurator::DisplayState>& displays) { |
215 gfx::Size size = GetPrimaryDisplaySize(); | 214 gfx::Size size = GetPrimaryDisplaySize(); |
216 if (!size.IsEmpty()) | 215 if (!size.IsEmpty()) |
217 host_->UpdateRootWindowSize(size); | 216 host_->UpdateRootWindowSize(size); |
218 } | 217 } |
219 #endif | 218 #endif |
220 | 219 |
221 void ShellDesktopController::OnHostCloseRequested( | 220 void ShellDesktopController::OnHostCloseRequested( |
222 const aura::WindowTreeHost* host) { | 221 const aura::WindowTreeHost* host) { |
223 DCHECK_EQ(host_.get(), host); | 222 DCHECK_EQ(host_.get(), host); |
224 CloseAppWindow(); | 223 CloseAppWindows(); |
225 base::MessageLoop::current()->PostTask(FROM_HERE, | 224 base::MessageLoop::current()->PostTask(FROM_HERE, |
226 base::MessageLoop::QuitClosure()); | 225 base::MessageLoop::QuitClosure()); |
227 } | 226 } |
228 | 227 |
229 void ShellDesktopController::CreateRootWindow() { | 228 void ShellDesktopController::CreateRootWindow() { |
230 test_screen_.reset(aura::TestScreen::Create()); | 229 test_screen_.reset(aura::TestScreen::Create()); |
231 // TODO(jamescook): Replace this with a real Screen implementation. | 230 // TODO(jamescook): Replace this with a real Screen implementation. |
232 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); | 231 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); |
233 // TODO(mukai): Set up input method. | 232 // TODO(mukai): Set up input method. |
234 | 233 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 if (displays.empty()) | 318 if (displays.empty()) |
320 return gfx::Size(); | 319 return gfx::Size(); |
321 const ui::DisplayMode* mode = displays[0].display->current_mode(); | 320 const ui::DisplayMode* mode = displays[0].display->current_mode(); |
322 return mode ? mode->size() : gfx::Size(); | 321 return mode ? mode->size() : gfx::Size(); |
323 #else | 322 #else |
324 return gfx::Size(); | 323 return gfx::Size(); |
325 #endif | 324 #endif |
326 } | 325 } |
327 | 326 |
328 } // namespace apps | 327 } // namespace apps |
OLD | NEW |