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

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: rebase 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"
32 #include "ui/base/user_activity/user_activity_detector.h" 33 #include "ui/base/user_activity/user_activity_detector.h"
33 #include "ui/display/screen.h" 34 #include "ui/display/screen.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"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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());
James Cook 2016/12/16 19:00:50 good catch
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();
353 } 383 }
354 384
355 gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() { 385 gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() {
356 #if defined(OS_CHROMEOS) 386 #if defined(OS_CHROMEOS)
357 const ui::DisplayConfigurator::DisplayStateList& displays = 387 const ui::DisplayConfigurator::DisplayStateList& displays =
358 display_configurator_->cached_displays(); 388 display_configurator_->cached_displays();
359 if (displays.empty()) 389 if (displays.empty())
360 return gfx::Size(); 390 return gfx::Size();
361 const ui::DisplayMode* mode = displays[0]->current_mode(); 391 const ui::DisplayMode* mode = displays[0]->current_mode();
362 return mode ? mode->size() : gfx::Size(); 392 return mode ? mode->size() : gfx::Size();
363 #else 393 #else
364 return gfx::Size(); 394 return gfx::Size();
365 #endif 395 #endif
366 } 396 }
367 397
368 } // namespace extensions 398 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698