| 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 "extensions/shell/browser/shell_desktop_controller.h" | 5 #include "extensions/shell/browser/shell_desktop_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/public/browser/context_factory.h" | 8 #include "content/public/browser/context_factory.h" |
| 9 #include "extensions/shell/browser/shell_app_window_controller.h" | 9 #include "extensions/shell/browser/shell_app_window.h" |
| 10 #include "extensions/shell/common/switches.h" | 10 #include "extensions/shell/common/switches.h" |
| 11 #include "ui/aura/client/cursor_client.h" | 11 #include "ui/aura/client/cursor_client.h" |
| 12 #include "ui/aura/client/default_capture_client.h" | 12 #include "ui/aura/client/default_capture_client.h" |
| 13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 14 #include "ui/aura/layout_manager.h" | 14 #include "ui/aura/layout_manager.h" |
| 15 #include "ui/aura/test/test_screen.h" | 15 #include "ui/aura/test/test_screen.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_event_dispatcher.h" | 17 #include "ui/aura/window_event_dispatcher.h" |
| 18 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/base/cursor/cursor.h" | 19 #include "ui/base/cursor/cursor.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 virtual ~AppsFocusRules() {} | 145 virtual ~AppsFocusRules() {} |
| 146 | 146 |
| 147 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE { | 147 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE { |
| 148 return true; | 148 return true; |
| 149 } | 149 } |
| 150 | 150 |
| 151 private: | 151 private: |
| 152 DISALLOW_COPY_AND_ASSIGN(AppsFocusRules); | 152 DISALLOW_COPY_AND_ASSIGN(AppsFocusRules); |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 ShellDesktopController* g_instance = NULL; | |
| 156 | |
| 157 } // namespace | 155 } // namespace |
| 158 | 156 |
| 159 ShellDesktopController::ShellDesktopController() { | 157 ShellDesktopController::ShellDesktopController() { |
| 160 #if defined(OS_CHROMEOS) | 158 #if defined(OS_CHROMEOS) |
| 161 display_configurator_.reset(new ui::DisplayConfigurator); | 159 display_configurator_.reset(new ui::DisplayConfigurator); |
| 162 display_configurator_->Init(false); | 160 display_configurator_->Init(false); |
| 163 display_configurator_->ForceInitialConfigure(0); | 161 display_configurator_->ForceInitialConfigure(0); |
| 164 display_configurator_->AddObserver(this); | 162 display_configurator_->AddObserver(this); |
| 165 #endif | 163 #endif |
| 166 aura::Env::CreateInstance(true); | 164 aura::Env::CreateInstance(true); |
| 167 aura::Env::GetInstance()->set_context_factory(content::GetContextFactory()); | 165 aura::Env::GetInstance()->set_context_factory(content::GetContextFactory()); |
| 168 | |
| 169 g_instance = this; | |
| 170 } | 166 } |
| 171 | 167 |
| 172 ShellDesktopController::~ShellDesktopController() { | 168 ShellDesktopController::~ShellDesktopController() { |
| 173 app_window_controller_.reset(); | |
| 174 g_instance = NULL; | |
| 175 DestroyRootWindow(); | 169 DestroyRootWindow(); |
| 176 aura::Env::DeleteInstance(); | 170 aura::Env::DeleteInstance(); |
| 177 } | 171 } |
| 178 | 172 |
| 179 // static | 173 aura::WindowTreeHost* ShellDesktopController::GetHost() { |
| 180 ShellDesktopController* ShellDesktopController::instance() { | 174 return host_.get(); |
| 181 return g_instance; | |
| 182 } | |
| 183 | |
| 184 void ShellDesktopController::SetAppWindowController( | |
| 185 ShellAppWindowController* app_window_controller) { | |
| 186 app_window_controller_.reset(app_window_controller); | |
| 187 } | 175 } |
| 188 | 176 |
| 189 ShellAppWindow* ShellDesktopController::CreateAppWindow( | 177 ShellAppWindow* ShellDesktopController::CreateAppWindow( |
| 190 content::BrowserContext* context) { | 178 content::BrowserContext* context) { |
| 191 return app_window_controller_->CreateAppWindow(context); | 179 aura::Window* root_window = GetHost()->window(); |
| 180 |
| 181 app_window_.reset(new ShellAppWindow); |
| 182 app_window_->Init(context, root_window->bounds().size()); |
| 183 |
| 184 // Attach the web contents view to our window hierarchy. |
| 185 aura::Window* content = app_window_->GetNativeWindow(); |
| 186 root_window->AddChild(content); |
| 187 content->Show(); |
| 188 |
| 189 return app_window_.get(); |
| 192 } | 190 } |
| 193 | 191 |
| 194 void ShellDesktopController::CloseAppWindows() { | 192 void ShellDesktopController::CloseAppWindows() { |
| 195 if (app_window_controller_) | 193 app_window_.reset(); |
| 196 app_window_controller_->CloseAppWindows(); | |
| 197 } | |
| 198 | |
| 199 void ShellDesktopController::SetDisplayWorkAreaInsets( | |
| 200 const gfx::Insets& insets) { | |
| 201 test_screen_->SetWorkAreaInsets(insets); | |
| 202 } | 194 } |
| 203 | 195 |
| 204 aura::Window* ShellDesktopController::GetDefaultParent( | 196 aura::Window* ShellDesktopController::GetDefaultParent( |
| 205 aura::Window* context, | 197 aura::Window* context, |
| 206 aura::Window* window, | 198 aura::Window* window, |
| 207 const gfx::Rect& bounds) { | 199 const gfx::Rect& bounds) { |
| 208 return host_->window(); | 200 return host_->window(); |
| 209 } | 201 } |
| 210 | 202 |
| 211 #if defined(OS_CHROMEOS) | 203 #if defined(OS_CHROMEOS) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 InitWindowManager(); | 246 InitWindowManager(); |
| 255 | 247 |
| 256 host_->AddObserver(this); | 248 host_->AddObserver(this); |
| 257 | 249 |
| 258 // Ensure the X window gets mapped. | 250 // Ensure the X window gets mapped. |
| 259 host_->Show(); | 251 host_->Show(); |
| 260 } | 252 } |
| 261 | 253 |
| 262 void ShellDesktopController::InitWindowManager() { | 254 void ShellDesktopController::InitWindowManager() { |
| 263 wm::FocusController* focus_controller = | 255 wm::FocusController* focus_controller = |
| 264 new wm::FocusController(CreateFocusRules()); | 256 new wm::FocusController(new AppsFocusRules()); |
| 265 aura::client::SetFocusClient(host_->window(), focus_controller); | 257 aura::client::SetFocusClient(host_->window(), focus_controller); |
| 266 host_->window()->AddPreTargetHandler(focus_controller); | 258 host_->window()->AddPreTargetHandler(focus_controller); |
| 267 aura::client::SetActivationClient(host_->window(), focus_controller); | 259 aura::client::SetActivationClient(host_->window(), focus_controller); |
| 268 focus_client_.reset(focus_controller); | 260 focus_client_.reset(focus_controller); |
| 269 | 261 |
| 270 input_method_filter_.reset( | 262 input_method_filter_.reset( |
| 271 new wm::InputMethodEventFilter(host_->GetAcceleratedWidget())); | 263 new wm::InputMethodEventFilter(host_->GetAcceleratedWidget())); |
| 272 input_method_filter_->SetInputMethodPropertyInRootWindow(host_->window()); | 264 input_method_filter_->SetInputMethodPropertyInRootWindow(host_->window()); |
| 273 root_window_event_filter_->AddHandler(input_method_filter_.get()); | 265 root_window_event_filter_->AddHandler(input_method_filter_.get()); |
| 274 | 266 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 288 | 280 |
| 289 user_activity_detector_.reset(new wm::UserActivityDetector); | 281 user_activity_detector_.reset(new wm::UserActivityDetector); |
| 290 host_->event_processor()->GetRootTarget()->AddPreTargetHandler( | 282 host_->event_processor()->GetRootTarget()->AddPreTargetHandler( |
| 291 user_activity_detector_.get()); | 283 user_activity_detector_.get()); |
| 292 #if defined(OS_CHROMEOS) | 284 #if defined(OS_CHROMEOS) |
| 293 user_activity_notifier_.reset( | 285 user_activity_notifier_.reset( |
| 294 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); | 286 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); |
| 295 #endif | 287 #endif |
| 296 } | 288 } |
| 297 | 289 |
| 298 wm::FocusRules* ShellDesktopController::CreateFocusRules() { | |
| 299 return new AppsFocusRules(); | |
| 300 } | |
| 301 | |
| 302 void ShellDesktopController::DestroyRootWindow() { | 290 void ShellDesktopController::DestroyRootWindow() { |
| 303 host_->RemoveObserver(this); | 291 host_->RemoveObserver(this); |
| 304 if (input_method_filter_) | 292 if (input_method_filter_) |
| 305 root_window_event_filter_->RemoveHandler(input_method_filter_.get()); | 293 root_window_event_filter_->RemoveHandler(input_method_filter_.get()); |
| 306 if (user_activity_detector_) { | 294 if (user_activity_detector_) { |
| 307 host_->event_processor()->GetRootTarget()->RemovePreTargetHandler( | 295 host_->event_processor()->GetRootTarget()->RemovePreTargetHandler( |
| 308 user_activity_detector_.get()); | 296 user_activity_detector_.get()); |
| 309 } | 297 } |
| 310 wm::FocusController* focus_controller = | 298 wm::FocusController* focus_controller = |
| 311 static_cast<wm::FocusController*>(focus_client_.get()); | 299 static_cast<wm::FocusController*>(focus_client_.get()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 332 if (displays.empty()) | 320 if (displays.empty()) |
| 333 return gfx::Size(); | 321 return gfx::Size(); |
| 334 const ui::DisplayMode* mode = displays[0].display->current_mode(); | 322 const ui::DisplayMode* mode = displays[0].display->current_mode(); |
| 335 return mode ? mode->size() : gfx::Size(); | 323 return mode ? mode->size() : gfx::Size(); |
| 336 #else | 324 #else |
| 337 return gfx::Size(); | 325 return gfx::Size(); |
| 338 #endif | 326 #endif |
| 339 } | 327 } |
| 340 | 328 |
| 341 } // namespace extensions | 329 } // namespace extensions |
| OLD | NEW |