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

Side by Side Diff: ui/keyboard/keyboard_util.cc

Issue 1155013005: Refactoring the ownership of ui::InputMethod. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed bot failure: cast_shell_linux Created 5 years, 6 months 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ui/keyboard/keyboard_util.h" 5 #include "ui/keyboard/keyboard_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "grit/keyboard_resources.h" 15 #include "grit/keyboard_resources.h"
16 #include "grit/keyboard_resources_map.h" 16 #include "grit/keyboard_resources_map.h"
17 #include "ui/aura/client/aura_constants.h"
18 #include "ui/aura/window_tree_host.h" 17 #include "ui/aura/window_tree_host.h"
19 #include "ui/base/ime/input_method.h" 18 #include "ui/base/ime/input_method.h"
20 #include "ui/base/ime/text_input_client.h" 19 #include "ui/base/ime/text_input_client.h"
21 #include "ui/events/event_processor.h" 20 #include "ui/events/event_processor.h"
22 #include "ui/events/event_utils.h" 21 #include "ui/events/event_utils.h"
23 #include "ui/events/keycodes/dom/dom_code.h" 22 #include "ui/events/keycodes/dom/dom_code.h"
24 #include "ui/events/keycodes/dom/dom_key.h" 23 #include "ui/events/keycodes/dom/dom_key.h"
25 #include "ui/events/keycodes/dom/keycode_converter.h" 24 #include "ui/events/keycodes/dom/keycode_converter.h"
26 #include "ui/events/keycodes/keyboard_code_conversion.h" 25 #include "ui/events/keycodes/keyboard_code_conversion.h"
27 #include "ui/keyboard/keyboard_controller.h" 26 #include "ui/keyboard/keyboard_controller.h"
28 #include "ui/keyboard/keyboard_controller_proxy.h" 27 #include "ui/keyboard/keyboard_controller_proxy.h"
29 #include "ui/keyboard/keyboard_switches.h" 28 #include "ui/keyboard/keyboard_switches.h"
30 #include "url/gurl.h" 29 #include "url/gurl.h"
31 30
32 namespace { 31 namespace {
33 32
34 const char kKeyDown[] ="keydown"; 33 const char kKeyDown[] ="keydown";
35 const char kKeyUp[] = "keyup"; 34 const char kKeyUp[] = "keyup";
36 35
37 void SendProcessKeyEvent(ui::EventType type, 36 void SendProcessKeyEvent(ui::EventType type,
38 aura::WindowTreeHost* host) { 37 aura::WindowTreeHost* host) {
39 ui::KeyEvent event(type, ui::VKEY_PROCESSKEY, ui::DomCode::NONE, ui::EF_NONE, 38 ui::KeyEvent event(type, ui::VKEY_PROCESSKEY, ui::DomCode::NONE, ui::EF_NONE,
40 ui::DomKey::PROCESS, 0, ui::EventTimeForNow()); 39 ui::DomKey::PROCESS, 0, ui::EventTimeForNow());
41 event.SetTranslated(true);
42 ui::EventDispatchDetails details = 40 ui::EventDispatchDetails details =
43 host->event_processor()->OnEventFromSource(&event); 41 host->event_processor()->OnEventFromSource(&event);
44 CHECK(!details.dispatcher_destroyed); 42 CHECK(!details.dispatcher_destroyed);
45 } 43 }
46 44
47 base::LazyInstance<base::Time> g_keyboard_load_time_start = 45 base::LazyInstance<base::Time> g_keyboard_load_time_start =
48 LAZY_INSTANCE_INITIALIZER; 46 LAZY_INSTANCE_INITIALIZER;
49 47
50 bool g_accessibility_keyboard_enabled = false; 48 bool g_accessibility_keyboard_enabled = false;
51 49
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 ui::EventType event_type = ui::ET_UNKNOWN; 282 ui::EventType event_type = ui::ET_UNKNOWN;
285 if (type == kKeyDown) 283 if (type == kKeyDown)
286 event_type = ui::ET_KEY_PRESSED; 284 event_type = ui::ET_KEY_PRESSED;
287 else if (type == kKeyUp) 285 else if (type == kKeyUp)
288 event_type = ui::ET_KEY_RELEASED; 286 event_type = ui::ET_KEY_RELEASED;
289 if (event_type == ui::ET_UNKNOWN) 287 if (event_type == ui::ET_UNKNOWN)
290 return false; 288 return false;
291 289
292 ui::KeyboardCode code = static_cast<ui::KeyboardCode>(key_code); 290 ui::KeyboardCode code = static_cast<ui::KeyboardCode>(key_code);
293 291
292 ui::InputMethod* input_method = host->GetInputMethod();
294 if (code == ui::VKEY_UNKNOWN) { 293 if (code == ui::VKEY_UNKNOWN) {
295 // Handling of special printable characters (e.g. accented characters) for 294 // Handling of special printable characters (e.g. accented characters) for
296 // which there is no key code. 295 // which there is no key code.
297 if (event_type == ui::ET_KEY_RELEASED) { 296 if (event_type == ui::ET_KEY_RELEASED) {
298 ui::InputMethod* input_method = host->window()->GetProperty(
299 aura::client::kRootWindowInputMethodKey);
300 if (!input_method) 297 if (!input_method)
301 return false; 298 return false;
302 299
303 ui::TextInputClient* tic = input_method->GetTextInputClient(); 300 ui::TextInputClient* tic = input_method->GetTextInputClient();
304 301
305 SendProcessKeyEvent(ui::ET_KEY_PRESSED, host); 302 SendProcessKeyEvent(ui::ET_KEY_PRESSED, host);
306 tic->InsertChar(static_cast<uint16>(key_value), ui::EF_NONE); 303 tic->InsertChar(static_cast<uint16>(key_value), ui::EF_NONE);
307 SendProcessKeyEvent(ui::ET_KEY_RELEASED, host); 304 SendProcessKeyEvent(ui::ET_KEY_RELEASED, host);
308 } 305 }
309 } else { 306 } else {
(...skipping 16 matching lines...) Expand all
326 if (!key_name.empty()) 323 if (!key_name.empty())
327 dom_code = ui::KeycodeConverter::CodeStringToDomCode(key_name.c_str()); 324 dom_code = ui::KeycodeConverter::CodeStringToDomCode(key_name.c_str());
328 if (dom_code == ui::DomCode::NONE) 325 if (dom_code == ui::DomCode::NONE)
329 dom_code = ui::UsLayoutKeyboardCodeToDomCode(code); 326 dom_code = ui::UsLayoutKeyboardCodeToDomCode(code);
330 CHECK(dom_code != ui::DomCode::NONE); 327 CHECK(dom_code != ui::DomCode::NONE);
331 ui::KeyEvent event( 328 ui::KeyEvent event(
332 event_type, 329 event_type,
333 code, 330 code,
334 dom_code, 331 dom_code,
335 modifiers); 332 modifiers);
336 ui::EventDispatchDetails details = 333 if (input_method) {
337 host->event_processor()->OnEventFromSource(&event); 334 input_method->DispatchKeyEvent(event);
338 CHECK(!details.dispatcher_destroyed); 335 } else {
336 ui::EventDispatchDetails details =
337 host->event_processor()->OnEventFromSource(&event);
338 CHECK(!details.dispatcher_destroyed);
339 }
339 } 340 }
340 return true; 341 return true;
341 } 342 }
342 343
343 void MarkKeyboardLoadStarted() { 344 void MarkKeyboardLoadStarted() {
344 if (!g_keyboard_load_time_start.Get().ToInternalValue()) 345 if (!g_keyboard_load_time_start.Get().ToInternalValue())
345 g_keyboard_load_time_start.Get() = base::Time::Now(); 346 g_keyboard_load_time_start.Get() = base::Time::Now();
346 } 347 }
347 348
348 void MarkKeyboardLoadFinished() { 349 void MarkKeyboardLoadFinished() {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 450 }
450 451
451 void LogKeyboardControlEvent(KeyboardControlEvent event) { 452 void LogKeyboardControlEvent(KeyboardControlEvent event) {
452 UMA_HISTOGRAM_ENUMERATION( 453 UMA_HISTOGRAM_ENUMERATION(
453 "VirtualKeyboard.KeyboardControlEvent", 454 "VirtualKeyboard.KeyboardControlEvent",
454 event, 455 event,
455 keyboard::KEYBOARD_CONTROL_MAX); 456 keyboard::KEYBOARD_CONTROL_MAX);
456 } 457 }
457 458
458 } // namespace keyboard 459 } // namespace keyboard
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698