Chromium Code Reviews| 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" | |
| 9 #include "extensions/shell/browser/shell_app_window_controller.h" | 8 #include "extensions/shell/browser/shell_app_window_controller.h" |
| 10 #include "extensions/shell/common/switches.h" | 9 #include "extensions/shell/common/switches.h" |
| 11 #include "ui/aura/client/cursor_client.h" | 10 #include "ui/aura/client/cursor_client.h" |
| 12 #include "ui/aura/client/default_capture_client.h" | 11 #include "ui/aura/client/default_capture_client.h" |
| 13 #include "ui/aura/env.h" | |
| 14 #include "ui/aura/layout_manager.h" | 12 #include "ui/aura/layout_manager.h" |
| 15 #include "ui/aura/test/test_screen.h" | 13 #include "ui/aura/test/test_screen.h" |
| 16 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
| 18 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/base/cursor/cursor.h" | 17 #include "ui/base/cursor/cursor.h" |
| 20 #include "ui/base/cursor/image_cursors.h" | 18 #include "ui/base/cursor/image_cursors.h" |
| 21 #include "ui/base/ime/input_method_initializer.h" | 19 #include "ui/base/ime/input_method_initializer.h" |
| 22 #include "ui/gfx/native_widget_types.h" | 20 #include "ui/gfx/native_widget_types.h" |
| 23 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
| 24 #include "ui/wm/core/base_focus_rules.h" | 22 #include "ui/wm/core/base_focus_rules.h" |
| 25 #include "ui/wm/core/compound_event_filter.h" | 23 #include "ui/wm/core/compound_event_filter.h" |
| 26 #include "ui/wm/core/cursor_manager.h" | 24 #include "ui/wm/core/cursor_manager.h" |
| 27 #include "ui/wm/core/focus_controller.h" | 25 #include "ui/wm/core/focus_controller.h" |
| 28 #include "ui/wm/core/input_method_event_filter.h" | 26 #include "ui/wm/core/input_method_event_filter.h" |
| 29 #include "ui/wm/core/native_cursor_manager.h" | 27 #include "ui/wm/core/native_cursor_manager.h" |
| 30 #include "ui/wm/core/native_cursor_manager_delegate.h" | 28 #include "ui/wm/core/native_cursor_manager_delegate.h" |
| 31 #include "ui/wm/core/user_activity_detector.h" | 29 #include "ui/wm/core/user_activity_detector.h" |
| 32 | 30 |
| 33 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
| 32 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 34 #include "ui/chromeos/user_activity_power_manager_notifier.h" | 33 #include "ui/chromeos/user_activity_power_manager_notifier.h" |
| 35 #include "ui/display/types/chromeos/display_mode.h" | 34 #include "ui/display/types/chromeos/display_mode.h" |
| 36 #include "ui/display/types/chromeos/display_snapshot.h" | 35 #include "ui/display/types/chromeos/display_snapshot.h" |
| 37 #endif | 36 #endif |
| 38 | 37 |
| 39 namespace extensions { | 38 namespace extensions { |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| 42 // A simple layout manager that makes each new window fill its parent. | 41 // A simple layout manager that makes each new window fill its parent. |
| 43 class FillLayout : public aura::LayoutManager { | 42 class FillLayout : public aura::LayoutManager { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 | 149 |
| 151 private: | 150 private: |
| 152 DISALLOW_COPY_AND_ASSIGN(AppsFocusRules); | 151 DISALLOW_COPY_AND_ASSIGN(AppsFocusRules); |
| 153 }; | 152 }; |
| 154 | 153 |
| 155 ShellDesktopController* g_instance = NULL; | 154 ShellDesktopController* g_instance = NULL; |
| 156 | 155 |
| 157 } // namespace | 156 } // namespace |
| 158 | 157 |
| 159 ShellDesktopController::ShellDesktopController() { | 158 ShellDesktopController::ShellDesktopController() { |
| 159 CHECK(!g_instance) << "ShellDesktopController already exists"; | |
| 160 | |
| 160 #if defined(OS_CHROMEOS) | 161 #if defined(OS_CHROMEOS) |
| 162 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
| 163 AddObserver(this); | |
| 161 display_configurator_.reset(new ui::DisplayConfigurator); | 164 display_configurator_.reset(new ui::DisplayConfigurator); |
| 162 display_configurator_->Init(false); | 165 display_configurator_->Init(false); |
| 163 display_configurator_->ForceInitialConfigure(0); | 166 display_configurator_->ForceInitialConfigure(0); |
| 164 display_configurator_->AddObserver(this); | 167 display_configurator_->AddObserver(this); |
| 165 #endif | 168 #endif |
| 166 aura::Env::CreateInstance(true); | 169 |
|
oshima
2014/08/22 21:15:33
where Create/Delete Instance are called now?
Daniel Erat
2014/08/22 21:26:13
content::BrowserMainLoop::InitializeToolkit() call
| |
| 167 aura::Env::GetInstance()->set_context_factory(content::GetContextFactory()); | 170 CreateRootWindow(); |
| 168 | 171 |
| 169 g_instance = this; | 172 g_instance = this; |
| 170 } | 173 } |
| 171 | 174 |
| 172 ShellDesktopController::~ShellDesktopController() { | 175 ShellDesktopController::~ShellDesktopController() { |
| 173 app_window_controller_.reset(); | 176 app_window_controller_.reset(); |
| 174 g_instance = NULL; | 177 g_instance = NULL; |
| 175 DestroyRootWindow(); | 178 DestroyRootWindow(); |
| 176 aura::Env::DeleteInstance(); | 179 #if defined(OS_CHROMEOS) |
| 180 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
| 181 RemoveObserver(this); | |
| 182 #endif | |
| 177 } | 183 } |
| 178 | 184 |
| 179 // static | 185 // static |
| 180 ShellDesktopController* ShellDesktopController::instance() { | 186 ShellDesktopController* ShellDesktopController::instance() { |
| 181 return g_instance; | 187 return g_instance; |
| 182 } | 188 } |
| 183 | 189 |
| 184 void ShellDesktopController::SetAppWindowController( | 190 void ShellDesktopController::SetAppWindowController( |
| 185 ShellAppWindowController* app_window_controller) { | 191 ShellAppWindowController* app_window_controller) { |
| 186 app_window_controller_.reset(app_window_controller); | 192 app_window_controller_.reset(app_window_controller); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 202 } | 208 } |
| 203 | 209 |
| 204 aura::Window* ShellDesktopController::GetDefaultParent( | 210 aura::Window* ShellDesktopController::GetDefaultParent( |
| 205 aura::Window* context, | 211 aura::Window* context, |
| 206 aura::Window* window, | 212 aura::Window* window, |
| 207 const gfx::Rect& bounds) { | 213 const gfx::Rect& bounds) { |
| 208 return host_->window(); | 214 return host_->window(); |
| 209 } | 215 } |
| 210 | 216 |
| 211 #if defined(OS_CHROMEOS) | 217 #if defined(OS_CHROMEOS) |
| 218 void ShellDesktopController::PowerButtonEventReceived( | |
| 219 bool down, | |
| 220 const base::TimeTicks& timestamp) { | |
| 221 if (down) { | |
| 222 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
| 223 RequestShutdown(); | |
| 224 } | |
| 225 } | |
| 226 | |
| 212 void ShellDesktopController::OnDisplayModeChanged( | 227 void ShellDesktopController::OnDisplayModeChanged( |
| 213 const std::vector<ui::DisplayConfigurator::DisplayState>& displays) { | 228 const std::vector<ui::DisplayConfigurator::DisplayState>& displays) { |
| 214 gfx::Size size = GetPrimaryDisplaySize(); | 229 gfx::Size size = GetPrimaryDisplaySize(); |
| 215 if (!size.IsEmpty()) | 230 if (!size.IsEmpty()) |
| 216 host_->UpdateRootWindowSize(size); | 231 host_->UpdateRootWindowSize(size); |
| 217 } | 232 } |
| 218 #endif | 233 #endif |
| 219 | 234 |
| 220 void ShellDesktopController::OnHostCloseRequested( | 235 void ShellDesktopController::OnHostCloseRequested( |
| 221 const aura::WindowTreeHost* host) { | 236 const aura::WindowTreeHost* host) { |
| 222 DCHECK_EQ(host_.get(), host); | 237 DCHECK_EQ(host_.get(), host); |
| 223 CloseAppWindows(); | 238 CloseAppWindows(); |
| 224 base::MessageLoop::current()->PostTask(FROM_HERE, | 239 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 225 base::MessageLoop::QuitClosure()); | 240 base::MessageLoop::QuitClosure()); |
| 226 } | 241 } |
| 227 | 242 |
| 228 void ShellDesktopController::CreateRootWindow() { | |
| 229 // Set up basic pieces of ui::wm. | |
| 230 gfx::Size size; | |
| 231 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 232 if (command_line->HasSwitch(switches::kAppShellHostWindowBounds)) { | |
| 233 const std::string size_str = | |
| 234 command_line->GetSwitchValueASCII(switches::kAppShellHostWindowBounds); | |
| 235 int width, height; | |
| 236 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); | |
| 237 size = gfx::Size(width, height); | |
| 238 } else { | |
| 239 size = GetPrimaryDisplaySize(); | |
| 240 } | |
| 241 if (size.IsEmpty()) | |
| 242 size = gfx::Size(1280, 720); | |
| 243 | |
| 244 test_screen_.reset(aura::TestScreen::Create(size)); | |
| 245 // TODO(jamescook): Replace this with a real Screen implementation. | |
| 246 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); | |
| 247 // TODO(mukai): Set up input method. | |
| 248 | |
| 249 host_.reset(test_screen_->CreateHostForPrimaryDisplay()); | |
| 250 host_->InitHost(); | |
| 251 aura::client::SetWindowTreeClient(host_->window(), this); | |
| 252 root_window_event_filter_.reset(new wm::CompoundEventFilter); | |
| 253 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); | |
| 254 InitWindowManager(); | |
| 255 | |
| 256 host_->AddObserver(this); | |
| 257 | |
| 258 // Ensure the X window gets mapped. | |
| 259 host_->Show(); | |
| 260 } | |
| 261 | |
| 262 void ShellDesktopController::InitWindowManager() { | 243 void ShellDesktopController::InitWindowManager() { |
| 263 wm::FocusController* focus_controller = | 244 wm::FocusController* focus_controller = |
| 264 new wm::FocusController(CreateFocusRules()); | 245 new wm::FocusController(CreateFocusRules()); |
| 265 aura::client::SetFocusClient(host_->window(), focus_controller); | 246 aura::client::SetFocusClient(host_->window(), focus_controller); |
| 266 host_->window()->AddPreTargetHandler(focus_controller); | 247 host_->window()->AddPreTargetHandler(focus_controller); |
| 267 aura::client::SetActivationClient(host_->window(), focus_controller); | 248 aura::client::SetActivationClient(host_->window(), focus_controller); |
| 268 focus_client_.reset(focus_controller); | 249 focus_client_.reset(focus_controller); |
| 269 | 250 |
| 270 input_method_filter_.reset( | 251 input_method_filter_.reset( |
| 271 new wm::InputMethodEventFilter(host_->GetAcceleratedWidget())); | 252 new wm::InputMethodEventFilter(host_->GetAcceleratedWidget())); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 292 #if defined(OS_CHROMEOS) | 273 #if defined(OS_CHROMEOS) |
| 293 user_activity_notifier_.reset( | 274 user_activity_notifier_.reset( |
| 294 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); | 275 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get())); |
| 295 #endif | 276 #endif |
| 296 } | 277 } |
| 297 | 278 |
| 298 wm::FocusRules* ShellDesktopController::CreateFocusRules() { | 279 wm::FocusRules* ShellDesktopController::CreateFocusRules() { |
| 299 return new AppsFocusRules(); | 280 return new AppsFocusRules(); |
| 300 } | 281 } |
| 301 | 282 |
| 283 void ShellDesktopController::CreateRootWindow() { | |
|
Daniel Erat
2014/08/22 20:41:35
just moving this now that it's private
| |
| 284 // Set up basic pieces of ui::wm. | |
| 285 gfx::Size size; | |
| 286 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 287 if (command_line->HasSwitch(switches::kAppShellHostWindowBounds)) { | |
| 288 const std::string size_str = | |
| 289 command_line->GetSwitchValueASCII(switches::kAppShellHostWindowBounds); | |
| 290 int width, height; | |
| 291 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); | |
| 292 size = gfx::Size(width, height); | |
| 293 } else { | |
| 294 size = GetPrimaryDisplaySize(); | |
| 295 } | |
| 296 if (size.IsEmpty()) | |
| 297 size = gfx::Size(1280, 720); | |
| 298 | |
| 299 test_screen_.reset(aura::TestScreen::Create(size)); | |
| 300 // TODO(jamescook): Replace this with a real Screen implementation. | |
| 301 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); | |
| 302 // TODO(mukai): Set up input method. | |
| 303 | |
| 304 host_.reset(test_screen_->CreateHostForPrimaryDisplay()); | |
| 305 host_->InitHost(); | |
| 306 aura::client::SetWindowTreeClient(host_->window(), this); | |
| 307 root_window_event_filter_.reset(new wm::CompoundEventFilter); | |
| 308 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); | |
| 309 InitWindowManager(); | |
| 310 | |
| 311 host_->AddObserver(this); | |
| 312 | |
| 313 // Ensure the X window gets mapped. | |
| 314 host_->Show(); | |
| 315 } | |
| 316 | |
| 302 void ShellDesktopController::DestroyRootWindow() { | 317 void ShellDesktopController::DestroyRootWindow() { |
| 303 host_->RemoveObserver(this); | 318 host_->RemoveObserver(this); |
| 304 if (input_method_filter_) | 319 if (input_method_filter_) |
| 305 root_window_event_filter_->RemoveHandler(input_method_filter_.get()); | 320 root_window_event_filter_->RemoveHandler(input_method_filter_.get()); |
| 306 if (user_activity_detector_) { | 321 if (user_activity_detector_) { |
| 307 host_->event_processor()->GetRootTarget()->RemovePreTargetHandler( | 322 host_->event_processor()->GetRootTarget()->RemovePreTargetHandler( |
| 308 user_activity_detector_.get()); | 323 user_activity_detector_.get()); |
| 309 } | 324 } |
| 310 wm::FocusController* focus_controller = | 325 wm::FocusController* focus_controller = |
| 311 static_cast<wm::FocusController*>(focus_client_.get()); | 326 static_cast<wm::FocusController*>(focus_client_.get()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 332 if (displays.empty()) | 347 if (displays.empty()) |
| 333 return gfx::Size(); | 348 return gfx::Size(); |
| 334 const ui::DisplayMode* mode = displays[0].display->current_mode(); | 349 const ui::DisplayMode* mode = displays[0].display->current_mode(); |
| 335 return mode ? mode->size() : gfx::Size(); | 350 return mode ? mode->size() : gfx::Size(); |
| 336 #else | 351 #else |
| 337 return gfx::Size(); | 352 return gfx::Size(); |
| 338 #endif | 353 #endif |
| 339 } | 354 } |
| 340 | 355 |
| 341 } // namespace extensions | 356 } // namespace extensions |
| OLD | NEW |