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_aura.h" | 5 #include "extensions/shell/browser/shell_desktop_controller_aura.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "extensions/browser/app_window/app_window.h" | 17 #include "extensions/browser/app_window/app_window.h" |
18 #include "extensions/browser/app_window/native_app_window.h" | 18 #include "extensions/browser/app_window/native_app_window.h" |
19 #include "extensions/shell/browser/input_method_event_handler.h" | |
19 #include "extensions/shell/browser/shell_app_delegate.h" | 20 #include "extensions/shell/browser/shell_app_delegate.h" |
20 #include "extensions/shell/browser/shell_app_window_client.h" | 21 #include "extensions/shell/browser/shell_app_window_client.h" |
21 #include "extensions/shell/browser/shell_screen.h" | 22 #include "extensions/shell/browser/shell_screen.h" |
22 #include "extensions/shell/common/switches.h" | 23 #include "extensions/shell/common/switches.h" |
23 #include "ui/aura/client/cursor_client.h" | 24 #include "ui/aura/client/cursor_client.h" |
24 #include "ui/aura/client/default_capture_client.h" | 25 #include "ui/aura/client/default_capture_client.h" |
25 #include "ui/aura/layout_manager.h" | 26 #include "ui/aura/layout_manager.h" |
26 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
27 #include "ui/aura/window_event_dispatcher.h" | |
28 #include "ui/aura/window_tree_host.h" | 28 #include "ui/aura/window_tree_host.h" |
29 #include "ui/base/cursor/cursor.h" | 29 #include "ui/base/cursor/cursor.h" |
30 #include "ui/base/cursor/image_cursors.h" | 30 #include "ui/base/cursor/image_cursors.h" |
31 #include "ui/base/ime/input_method_initializer.h" | 31 #include "ui/base/ime/input_method.h" |
32 #include "ui/base/user_activity/user_activity_detector.h" | 32 #include "ui/base/user_activity/user_activity_detector.h" |
33 #include "ui/display/screen.h" | 33 #include "ui/display/screen.h" |
34 #include "ui/events/event_processor.h" | |
34 #include "ui/gfx/geometry/size.h" | 35 #include "ui/gfx/geometry/size.h" |
35 #include "ui/gfx/native_widget_types.h" | 36 #include "ui/gfx/native_widget_types.h" |
36 #include "ui/wm/core/base_focus_rules.h" | 37 #include "ui/wm/core/base_focus_rules.h" |
37 #include "ui/wm/core/compound_event_filter.h" | 38 #include "ui/wm/core/compound_event_filter.h" |
38 #include "ui/wm/core/cursor_manager.h" | 39 #include "ui/wm/core/cursor_manager.h" |
39 #include "ui/wm/core/focus_controller.h" | 40 #include "ui/wm/core/focus_controller.h" |
40 #include "ui/wm/core/native_cursor_manager.h" | 41 #include "ui/wm/core/native_cursor_manager.h" |
41 #include "ui/wm/core/native_cursor_manager_delegate.h" | 42 #include "ui/wm/core/native_cursor_manager_delegate.h" |
42 | 43 |
43 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 #endif | 265 #endif |
265 | 266 |
266 void ShellDesktopControllerAura::OnHostCloseRequested( | 267 void ShellDesktopControllerAura::OnHostCloseRequested( |
267 const aura::WindowTreeHost* host) { | 268 const aura::WindowTreeHost* host) { |
268 DCHECK_EQ(host_.get(), host); | 269 DCHECK_EQ(host_.get(), host); |
269 CloseAppWindows(); | 270 CloseAppWindows(); |
270 base::ThreadTaskRunnerHandle::Get()->PostTask( | 271 base::ThreadTaskRunnerHandle::Get()->PostTask( |
271 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 272 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
272 } | 273 } |
273 | 274 |
275 ui::EventDispatchDetails ShellDesktopControllerAura::DispatchKeyEventPostIME( | |
276 ui::KeyEvent* key_event) { | |
277 // The input method has processed this event, so prevent the handler from | |
278 // dispatching it again. | |
279 input_method_event_handler_->set_post_ime(true); | |
280 | |
281 // Send the event on to the host. | |
282 ui::EventDispatchDetails details = | |
283 host_->event_processor()->OnEventFromSource(key_event); | |
284 | |
285 // Clear the handler's PostIME flag for the next event. | |
286 if (!details.dispatcher_destroyed) | |
287 input_method_event_handler_->set_post_ime(false); | |
288 | |
289 return details; | |
290 } | |
291 | |
274 void ShellDesktopControllerAura::InitWindowManager() { | 292 void ShellDesktopControllerAura::InitWindowManager() { |
275 wm::FocusController* focus_controller = | 293 wm::FocusController* focus_controller = |
276 new wm::FocusController(new AppsFocusRules()); | 294 new wm::FocusController(new AppsFocusRules()); |
277 aura::client::SetFocusClient(host_->window(), focus_controller); | 295 aura::client::SetFocusClient(host_->window(), focus_controller); |
278 host_->window()->AddPreTargetHandler(focus_controller); | 296 host_->window()->AddPreTargetHandler(focus_controller); |
279 aura::client::SetActivationClient(host_->window(), focus_controller); | 297 aura::client::SetActivationClient(host_->window(), focus_controller); |
280 focus_client_.reset(focus_controller); | 298 focus_client_.reset(focus_controller); |
281 | 299 |
282 capture_client_.reset( | 300 capture_client_.reset( |
283 new aura::client::DefaultCaptureClient(host_->window())); | 301 new aura::client::DefaultCaptureClient(host_->window())); |
(...skipping 27 matching lines...) Expand all Loading... | |
311 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); | 329 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); |
312 size = gfx::Size(width, height); | 330 size = gfx::Size(width, height); |
313 } else { | 331 } else { |
314 size = GetPrimaryDisplaySize(); | 332 size = GetPrimaryDisplaySize(); |
315 } | 333 } |
316 if (size.IsEmpty()) | 334 if (size.IsEmpty()) |
317 size = gfx::Size(1920, 1080); | 335 size = gfx::Size(1920, 1080); |
318 | 336 |
319 screen_.reset(new ShellScreen(size)); | 337 screen_.reset(new ShellScreen(size)); |
320 display::Screen::SetScreenInstance(screen_.get()); | 338 display::Screen::SetScreenInstance(screen_.get()); |
321 // TODO(mukai): Set up input method. | |
322 | 339 |
323 host_.reset(screen_->CreateHostForPrimaryDisplay()); | 340 host_.reset(screen_->CreateHostForPrimaryDisplay()); |
324 aura::client::SetWindowParentingClient(host_->window(), this); | 341 aura::client::SetWindowParentingClient(host_->window(), this); |
325 root_window_event_filter_.reset(new wm::CompoundEventFilter); | 342 root_window_event_filter_.reset(new wm::CompoundEventFilter); |
326 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); | 343 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); |
344 | |
345 // Trigger creation of an input method and become its delegate. | |
346 ui::InputMethod* input_method = host_->GetInputMethod(); | |
347 input_method->SetDelegate(this); | |
348 input_method_event_handler_.reset(new InputMethodEventHandler(input_method)); | |
349 host_->window()->AddPreTargetHandler(input_method_event_handler_.get()); | |
350 | |
327 InitWindowManager(); | 351 InitWindowManager(); |
328 | 352 |
329 host_->AddObserver(this); | 353 host_->AddObserver(this); |
330 | 354 |
331 // Ensure the X window gets mapped. | 355 // Ensure the X window gets mapped. |
332 host_->Show(); | 356 host_->Show(); |
333 } | 357 } |
334 | 358 |
335 void ShellDesktopControllerAura::DestroyRootWindow() { | 359 void ShellDesktopControllerAura::DestroyRootWindow() { |
336 host_->RemoveObserver(this); | 360 host_->RemoveObserver(this); |
337 wm::FocusController* focus_controller = | 361 wm::FocusController* focus_controller = |
338 static_cast<wm::FocusController*>(focus_client_.get()); | 362 static_cast<wm::FocusController*>(focus_client_.get()); |
339 if (focus_controller) { | 363 if (focus_controller) { |
340 host_->window()->RemovePreTargetHandler(focus_controller); | 364 host_->window()->RemovePreTargetHandler(focus_controller); |
341 aura::client::SetActivationClient(host_->window(), NULL); | 365 aura::client::SetActivationClient(host_->window(), NULL); |
342 } | 366 } |
367 | |
368 host_->window()->RemovePreTargetHandler(input_method_event_handler_.get()); | |
369 input_method_event_handler_.reset(); | |
370 | |
371 host_->window()->RemovePreTargetHandler(root_window_event_filter_.get()); | |
343 root_window_event_filter_.reset(); | 372 root_window_event_filter_.reset(); |
373 | |
344 capture_client_.reset(); | 374 capture_client_.reset(); |
345 focus_client_.reset(); | 375 focus_client_.reset(); |
346 cursor_manager_.reset(); | 376 cursor_manager_.reset(); |
347 #if defined(OS_CHROMEOS) | 377 #if defined(OS_CHROMEOS) |
348 user_activity_notifier_.reset(); | 378 user_activity_notifier_.reset(); |
349 #endif | 379 #endif |
350 user_activity_detector_.reset(); | 380 user_activity_detector_.reset(); |
351 host_.reset(); | 381 host_.reset(); |
352 screen_.reset(); | 382 screen_.reset(); |
383 display::Screen::SetScreenInstance(nullptr); | |
James Cook
2016/12/17 18:24:41
nit: do this before screen_.reset() -- if someone
michaelpg
2016/12/18 01:46:10
Done.
| |
353 } | 384 } |
354 | 385 |
355 gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() { | 386 gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() { |
356 #if defined(OS_CHROMEOS) | 387 #if defined(OS_CHROMEOS) |
357 const ui::DisplayConfigurator::DisplayStateList& displays = | 388 const ui::DisplayConfigurator::DisplayStateList& displays = |
358 display_configurator_->cached_displays(); | 389 display_configurator_->cached_displays(); |
359 if (displays.empty()) | 390 if (displays.empty()) |
360 return gfx::Size(); | 391 return gfx::Size(); |
361 const ui::DisplayMode* mode = displays[0]->current_mode(); | 392 const ui::DisplayMode* mode = displays[0]->current_mode(); |
362 return mode ? mode->size() : gfx::Size(); | 393 return mode ? mode->size() : gfx::Size(); |
363 #else | 394 #else |
364 return gfx::Size(); | 395 return gfx::Size(); |
365 #endif | 396 #endif |
366 } | 397 } |
367 | 398 |
368 } // namespace extensions | 399 } // namespace extensions |
OLD | NEW |