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/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "extensions/browser/app_window/app_window.h" | 19 #include "extensions/browser/app_window/app_window.h" |
20 #include "extensions/browser/app_window/native_app_window.h" | 20 #include "extensions/browser/app_window/native_app_window.h" |
| 21 #include "extensions/shell/browser/input_method_event_handler.h" |
21 #include "extensions/shell/browser/shell_app_delegate.h" | 22 #include "extensions/shell/browser/shell_app_delegate.h" |
22 #include "extensions/shell/browser/shell_app_window_client.h" | 23 #include "extensions/shell/browser/shell_app_window_client.h" |
23 #include "extensions/shell/browser/shell_screen.h" | 24 #include "extensions/shell/browser/shell_screen.h" |
24 #include "extensions/shell/common/switches.h" | 25 #include "extensions/shell/common/switches.h" |
25 #include "ui/aura/client/cursor_client.h" | 26 #include "ui/aura/client/cursor_client.h" |
26 #include "ui/aura/client/default_capture_client.h" | 27 #include "ui/aura/client/default_capture_client.h" |
27 #include "ui/aura/layout_manager.h" | 28 #include "ui/aura/layout_manager.h" |
28 #include "ui/aura/window.h" | 29 #include "ui/aura/window.h" |
29 #include "ui/aura/window_tree_host.h" | 30 #include "ui/aura/window_tree_host.h" |
30 #include "ui/base/cursor/cursor.h" | 31 #include "ui/base/cursor/cursor.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 void ShellDesktopControllerAura::OnHostCloseRequested( | 268 void ShellDesktopControllerAura::OnHostCloseRequested( |
268 const aura::WindowTreeHost* host) { | 269 const aura::WindowTreeHost* host) { |
269 DCHECK_EQ(host_.get(), host); | 270 DCHECK_EQ(host_.get(), host); |
270 CloseAppWindows(); | 271 CloseAppWindows(); |
271 base::ThreadTaskRunnerHandle::Get()->PostTask( | 272 base::ThreadTaskRunnerHandle::Get()->PostTask( |
272 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 273 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
273 } | 274 } |
274 | 275 |
275 ui::EventDispatchDetails ShellDesktopControllerAura::DispatchKeyEventPostIME( | 276 ui::EventDispatchDetails ShellDesktopControllerAura::DispatchKeyEventPostIME( |
276 ui::KeyEvent* key_event) { | 277 ui::KeyEvent* key_event) { |
277 return host_->DispatchKeyEventPostIME(key_event); | 278 // The input method has processed this event, so prevent the handler from |
| 279 // dispatching it again. |
| 280 input_method_event_handler_->set_post_ime(true); |
| 281 |
| 282 // Send the event on to the host. |
| 283 ui::EventDispatchDetails details = |
| 284 host_->event_sink()->OnEventFromSource(key_event); |
| 285 |
| 286 // Clear the handler's PostIME flag for the next event. |
| 287 if (!details.dispatcher_destroyed) |
| 288 input_method_event_handler_->set_post_ime(false); |
| 289 |
| 290 return details; |
278 } | 291 } |
279 | 292 |
280 void ShellDesktopControllerAura::InitWindowManager() { | 293 void ShellDesktopControllerAura::InitWindowManager() { |
281 wm::FocusController* focus_controller = | 294 wm::FocusController* focus_controller = |
282 new wm::FocusController(new AppsFocusRules()); | 295 new wm::FocusController(new AppsFocusRules()); |
283 aura::client::SetFocusClient(host_->window(), focus_controller); | 296 aura::client::SetFocusClient(host_->window(), focus_controller); |
284 host_->window()->AddPreTargetHandler(focus_controller); | 297 host_->window()->AddPreTargetHandler(focus_controller); |
285 aura::client::SetActivationClient(host_->window(), focus_controller); | 298 aura::client::SetActivationClient(host_->window(), focus_controller); |
286 focus_client_.reset(focus_controller); | 299 focus_client_.reset(focus_controller); |
287 | 300 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 display::Screen::SetScreenInstance(screen_.get()); | 339 display::Screen::SetScreenInstance(screen_.get()); |
327 | 340 |
328 host_.reset(screen_->CreateHostForPrimaryDisplay()); | 341 host_.reset(screen_->CreateHostForPrimaryDisplay()); |
329 aura::client::SetWindowParentingClient(host_->window(), this); | 342 aura::client::SetWindowParentingClient(host_->window(), this); |
330 root_window_event_filter_.reset(new wm::CompoundEventFilter); | 343 root_window_event_filter_.reset(new wm::CompoundEventFilter); |
331 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); | 344 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); |
332 | 345 |
333 // Trigger creation of an input method and become its delegate. | 346 // Trigger creation of an input method and become its delegate. |
334 ui::InputMethod* input_method = host_->GetInputMethod(); | 347 ui::InputMethod* input_method = host_->GetInputMethod(); |
335 input_method->SetDelegate(this); | 348 input_method->SetDelegate(this); |
| 349 input_method_event_handler_.reset(new InputMethodEventHandler(input_method)); |
| 350 host_->window()->AddPreTargetHandler(input_method_event_handler_.get()); |
336 | 351 |
337 InitWindowManager(); | 352 InitWindowManager(); |
338 | 353 |
339 host_->AddObserver(this); | 354 host_->AddObserver(this); |
340 | 355 |
341 // Ensure the X window gets mapped. | 356 // Ensure the X window gets mapped. |
342 host_->Show(); | 357 host_->Show(); |
343 } | 358 } |
344 | 359 |
345 void ShellDesktopControllerAura::DestroyRootWindow() { | 360 void ShellDesktopControllerAura::DestroyRootWindow() { |
346 host_->RemoveObserver(this); | 361 host_->RemoveObserver(this); |
347 wm::FocusController* focus_controller = | 362 wm::FocusController* focus_controller = |
348 static_cast<wm::FocusController*>(focus_client_.get()); | 363 static_cast<wm::FocusController*>(focus_client_.get()); |
349 if (focus_controller) { | 364 if (focus_controller) { |
350 host_->window()->RemovePreTargetHandler(focus_controller); | 365 host_->window()->RemovePreTargetHandler(focus_controller); |
351 aura::client::SetActivationClient(host_->window(), NULL); | 366 aura::client::SetActivationClient(host_->window(), NULL); |
352 } | 367 } |
353 | 368 |
| 369 host_->window()->RemovePreTargetHandler(input_method_event_handler_.get()); |
| 370 input_method_event_handler_.reset(); |
| 371 |
354 host_->window()->RemovePreTargetHandler(root_window_event_filter_.get()); | 372 host_->window()->RemovePreTargetHandler(root_window_event_filter_.get()); |
355 root_window_event_filter_.reset(); | 373 root_window_event_filter_.reset(); |
356 | 374 |
357 capture_client_.reset(); | 375 capture_client_.reset(); |
358 focus_client_.reset(); | 376 focus_client_.reset(); |
359 cursor_manager_.reset(); | 377 cursor_manager_.reset(); |
360 #if defined(OS_CHROMEOS) | 378 #if defined(OS_CHROMEOS) |
361 user_activity_notifier_.reset(); | 379 user_activity_notifier_.reset(); |
362 #endif | 380 #endif |
363 user_activity_detector_.reset(); | 381 user_activity_detector_.reset(); |
364 host_.reset(); | 382 host_.reset(); |
365 display::Screen::SetScreenInstance(nullptr); | 383 display::Screen::SetScreenInstance(nullptr); |
366 screen_.reset(); | 384 screen_.reset(); |
367 } | 385 } |
368 | 386 |
369 gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() { | 387 gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() { |
370 #if defined(OS_CHROMEOS) | 388 #if defined(OS_CHROMEOS) |
371 const display::DisplayConfigurator::DisplayStateList& displays = | 389 const display::DisplayConfigurator::DisplayStateList& displays = |
372 display_configurator_->cached_displays(); | 390 display_configurator_->cached_displays(); |
373 if (displays.empty()) | 391 if (displays.empty()) |
374 return gfx::Size(); | 392 return gfx::Size(); |
375 const display::DisplayMode* mode = displays[0]->current_mode(); | 393 const display::DisplayMode* mode = displays[0]->current_mode(); |
376 return mode ? mode->size() : gfx::Size(); | 394 return mode ? mode->size() : gfx::Size(); |
377 #else | 395 #else |
378 return gfx::Size(); | 396 return gfx::Size(); |
379 #endif | 397 #endif |
380 } | 398 } |
381 | 399 |
382 } // namespace extensions | 400 } // namespace extensions |
OLD | NEW |