Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: extensions/shell/browser/shell_desktop_controller_aura.cc

Issue 2580733002: AppShell: Create input method and handle key events (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_event_dispatcher.h"
28 #include "ui/aura/window_tree_host.h" 29 #include "ui/aura/window_tree_host.h"
29 #include "ui/base/cursor/cursor.h" 30 #include "ui/base/cursor/cursor.h"
30 #include "ui/base/cursor/image_cursors.h" 31 #include "ui/base/cursor/image_cursors.h"
31 #include "ui/base/ime/input_method_initializer.h" 32 #include "ui/base/ime/input_method.h"
33 #include "ui/base/ime/input_method_factory.h"
32 #include "ui/base/user_activity/user_activity_detector.h" 34 #include "ui/base/user_activity/user_activity_detector.h"
33 #include "ui/display/screen.h" 35 #include "ui/display/screen.h"
34 #include "ui/gfx/geometry/size.h" 36 #include "ui/gfx/geometry/size.h"
35 #include "ui/gfx/native_widget_types.h" 37 #include "ui/gfx/native_widget_types.h"
36 #include "ui/wm/core/base_focus_rules.h" 38 #include "ui/wm/core/base_focus_rules.h"
37 #include "ui/wm/core/compound_event_filter.h" 39 #include "ui/wm/core/compound_event_filter.h"
38 #include "ui/wm/core/cursor_manager.h" 40 #include "ui/wm/core/cursor_manager.h"
39 #include "ui/wm/core/focus_controller.h" 41 #include "ui/wm/core/focus_controller.h"
40 #include "ui/wm/core/native_cursor_manager.h" 42 #include "ui/wm/core/native_cursor_manager.h"
41 #include "ui/wm/core/native_cursor_manager_delegate.h" 43 #include "ui/wm/core/native_cursor_manager_delegate.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 #endif 266 #endif
265 267
266 void ShellDesktopControllerAura::OnHostCloseRequested( 268 void ShellDesktopControllerAura::OnHostCloseRequested(
267 const aura::WindowTreeHost* host) { 269 const aura::WindowTreeHost* host) {
268 DCHECK_EQ(host_.get(), host); 270 DCHECK_EQ(host_.get(), host);
269 CloseAppWindows(); 271 CloseAppWindows();
270 base::ThreadTaskRunnerHandle::Get()->PostTask( 272 base::ThreadTaskRunnerHandle::Get()->PostTask(
271 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 273 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
272 } 274 }
273 275
276 ui::EventDispatchDetails ShellDesktopControllerAura::DispatchKeyEventPostIME(
277 ui::KeyEvent* key_event) {
278 // The input method has processed this event, so prevent the handler from
279 // dispatching it again.
280 input_method_event_handler_->SetPostIME(true);
281
282 // Send the event on to the host.
283 ui::EventDispatchDetails details =
284 host_->event_processor()->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_->SetPostIME(false);
289
290 return details;
291 }
292
274 void ShellDesktopControllerAura::InitWindowManager() { 293 void ShellDesktopControllerAura::InitWindowManager() {
275 wm::FocusController* focus_controller = 294 wm::FocusController* focus_controller =
276 new wm::FocusController(new AppsFocusRules()); 295 new wm::FocusController(new AppsFocusRules());
277 aura::client::SetFocusClient(host_->window(), focus_controller); 296 aura::client::SetFocusClient(host_->window(), focus_controller);
278 host_->window()->AddPreTargetHandler(focus_controller); 297 host_->window()->AddPreTargetHandler(focus_controller);
279 aura::client::SetActivationClient(host_->window(), focus_controller); 298 aura::client::SetActivationClient(host_->window(), focus_controller);
280 focus_client_.reset(focus_controller); 299 focus_client_.reset(focus_controller);
281 300
282 capture_client_.reset( 301 capture_client_.reset(
283 new aura::client::DefaultCaptureClient(host_->window())); 302 new aura::client::DefaultCaptureClient(host_->window()));
(...skipping 27 matching lines...) Expand all
311 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); 330 CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height));
312 size = gfx::Size(width, height); 331 size = gfx::Size(width, height);
313 } else { 332 } else {
314 size = GetPrimaryDisplaySize(); 333 size = GetPrimaryDisplaySize();
315 } 334 }
316 if (size.IsEmpty()) 335 if (size.IsEmpty())
317 size = gfx::Size(1920, 1080); 336 size = gfx::Size(1920, 1080);
318 337
319 screen_.reset(new ShellScreen(size)); 338 screen_.reset(new ShellScreen(size));
320 display::Screen::SetScreenInstance(screen_.get()); 339 display::Screen::SetScreenInstance(screen_.get());
321 // TODO(mukai): Set up input method.
322 340
323 host_.reset(screen_->CreateHostForPrimaryDisplay()); 341 host_.reset(screen_->CreateHostForPrimaryDisplay());
324 aura::client::SetWindowParentingClient(host_->window(), this); 342 aura::client::SetWindowParentingClient(host_->window(), this);
325 root_window_event_filter_.reset(new wm::CompoundEventFilter); 343 root_window_event_filter_.reset(new wm::CompoundEventFilter);
326 host_->window()->AddPreTargetHandler(root_window_event_filter_.get()); 344 host_->window()->AddPreTargetHandler(root_window_event_filter_.get());
345
346 // Handle key events.
347 input_method_ = ui::CreateInputMethod(this, host_->GetAcceleratedWidget());
348 host_->SetSharedInputMethod(input_method_.get());
Rahul Chaturvedi 2016/12/15 22:42:46 When we're destructing, and input_method_ will no
michaelpg 2016/12/15 23:55:52 Ugh, good point, this isn't quite safe. shuchen, a
349 input_method_event_handler_.reset(
350 new InputMethodEventHandler(input_method_.get()));
351 host_->window()->AddPreTargetHandler(input_method_event_handler_.get());
352
327 InitWindowManager(); 353 InitWindowManager();
328 354
329 host_->AddObserver(this); 355 host_->AddObserver(this);
330 356
331 // Ensure the X window gets mapped. 357 // Ensure the X window gets mapped.
332 host_->Show(); 358 host_->Show();
333 } 359 }
334 360
335 void ShellDesktopControllerAura::DestroyRootWindow() { 361 void ShellDesktopControllerAura::DestroyRootWindow() {
336 host_->RemoveObserver(this); 362 host_->RemoveObserver(this);
337 wm::FocusController* focus_controller = 363 wm::FocusController* focus_controller =
338 static_cast<wm::FocusController*>(focus_client_.get()); 364 static_cast<wm::FocusController*>(focus_client_.get());
339 if (focus_controller) { 365 if (focus_controller) {
340 host_->window()->RemovePreTargetHandler(focus_controller); 366 host_->window()->RemovePreTargetHandler(focus_controller);
341 aura::client::SetActivationClient(host_->window(), NULL); 367 aura::client::SetActivationClient(host_->window(), NULL);
342 } 368 }
369
370 host_->window()->RemovePreTargetHandler(input_method_event_handler_.get());
371 input_method_event_handler_.reset();
372
373 host_->window()->RemovePreTargetHandler(root_window_event_filter_.get());
343 root_window_event_filter_.reset(); 374 root_window_event_filter_.reset();
375
344 capture_client_.reset(); 376 capture_client_.reset();
345 focus_client_.reset(); 377 focus_client_.reset();
346 cursor_manager_.reset(); 378 cursor_manager_.reset();
347 #if defined(OS_CHROMEOS) 379 #if defined(OS_CHROMEOS)
348 user_activity_notifier_.reset(); 380 user_activity_notifier_.reset();
349 #endif 381 #endif
350 user_activity_detector_.reset(); 382 user_activity_detector_.reset();
351 host_.reset(); 383 host_.reset();
352 screen_.reset(); 384 screen_.reset();
353 } 385 }
354 386
355 gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() { 387 gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() {
356 #if defined(OS_CHROMEOS) 388 #if defined(OS_CHROMEOS)
357 const ui::DisplayConfigurator::DisplayStateList& displays = 389 const ui::DisplayConfigurator::DisplayStateList& displays =
358 display_configurator_->cached_displays(); 390 display_configurator_->cached_displays();
359 if (displays.empty()) 391 if (displays.empty())
360 return gfx::Size(); 392 return gfx::Size();
361 const ui::DisplayMode* mode = displays[0]->current_mode(); 393 const ui::DisplayMode* mode = displays[0]->current_mode();
362 return mode ? mode->size() : gfx::Size(); 394 return mode ? mode->size() : gfx::Size();
363 #else 395 #else
364 return gfx::Size(); 396 return gfx::Size();
365 #endif 397 #endif
366 } 398 }
367 399
368 } // namespace extensions 400 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698