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

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: comments addressed. 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 ui::EventType event_type = ui::ET_UNKNOWN; 275 ui::EventType event_type = ui::ET_UNKNOWN;
278 if (type == kKeyDown) 276 if (type == kKeyDown)
279 event_type = ui::ET_KEY_PRESSED; 277 event_type = ui::ET_KEY_PRESSED;
280 else if (type == kKeyUp) 278 else if (type == kKeyUp)
281 event_type = ui::ET_KEY_RELEASED; 279 event_type = ui::ET_KEY_RELEASED;
282 if (event_type == ui::ET_UNKNOWN) 280 if (event_type == ui::ET_UNKNOWN)
283 return false; 281 return false;
284 282
285 ui::KeyboardCode code = static_cast<ui::KeyboardCode>(key_code); 283 ui::KeyboardCode code = static_cast<ui::KeyboardCode>(key_code);
286 284
285 ui::InputMethod* input_method = host->GetInputMethod();
sky 2015/06/04 13:40:28 How about moving this to where it's needed, eg 326
Shu Chen 2015/06/04 15:59:26 line 293 also needs it.
287 if (code == ui::VKEY_UNKNOWN) { 286 if (code == ui::VKEY_UNKNOWN) {
288 // Handling of special printable characters (e.g. accented characters) for 287 // Handling of special printable characters (e.g. accented characters) for
289 // which there is no key code. 288 // which there is no key code.
290 if (event_type == ui::ET_KEY_RELEASED) { 289 if (event_type == ui::ET_KEY_RELEASED) {
291 ui::InputMethod* input_method = host->window()->GetProperty(
292 aura::client::kRootWindowInputMethodKey);
293 if (!input_method) 290 if (!input_method)
294 return false; 291 return false;
295 292
296 ui::TextInputClient* tic = input_method->GetTextInputClient(); 293 ui::TextInputClient* tic = input_method->GetTextInputClient();
297 294
298 SendProcessKeyEvent(ui::ET_KEY_PRESSED, host); 295 SendProcessKeyEvent(ui::ET_KEY_PRESSED, host);
299 tic->InsertChar(static_cast<uint16>(key_value), ui::EF_NONE); 296 tic->InsertChar(static_cast<uint16>(key_value), ui::EF_NONE);
300 SendProcessKeyEvent(ui::ET_KEY_RELEASED, host); 297 SendProcessKeyEvent(ui::ET_KEY_RELEASED, host);
301 } 298 }
302 } else { 299 } else {
(...skipping 16 matching lines...) Expand all
319 if (!key_name.empty()) 316 if (!key_name.empty())
320 dom_code = ui::KeycodeConverter::CodeStringToDomCode(key_name.c_str()); 317 dom_code = ui::KeycodeConverter::CodeStringToDomCode(key_name.c_str());
321 if (dom_code == ui::DomCode::NONE) 318 if (dom_code == ui::DomCode::NONE)
322 dom_code = ui::UsLayoutKeyboardCodeToDomCode(code); 319 dom_code = ui::UsLayoutKeyboardCodeToDomCode(code);
323 CHECK(dom_code != ui::DomCode::NONE); 320 CHECK(dom_code != ui::DomCode::NONE);
324 ui::KeyEvent event( 321 ui::KeyEvent event(
325 event_type, 322 event_type,
326 code, 323 code,
327 dom_code, 324 dom_code,
328 modifiers); 325 modifiers);
329 ui::EventDispatchDetails details = 326 if (input_method) {
330 host->event_processor()->OnEventFromSource(&event); 327 input_method->DispatchKeyEvent(event);
331 CHECK(!details.dispatcher_destroyed); 328 } else {
329 ui::EventDispatchDetails details =
330 host->event_processor()->OnEventFromSource(&event);
331 CHECK(!details.dispatcher_destroyed);
332 }
332 } 333 }
333 return true; 334 return true;
334 } 335 }
335 336
336 void MarkKeyboardLoadStarted() { 337 void MarkKeyboardLoadStarted() {
337 if (!g_keyboard_load_time_start.Get().ToInternalValue()) 338 if (!g_keyboard_load_time_start.Get().ToInternalValue())
338 g_keyboard_load_time_start.Get() = base::Time::Now(); 339 g_keyboard_load_time_start.Get() = base::Time::Now();
339 } 340 }
340 341
341 void MarkKeyboardLoadFinished() { 342 void MarkKeyboardLoadFinished() {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 } 443 }
443 444
444 void LogKeyboardControlEvent(KeyboardControlEvent event) { 445 void LogKeyboardControlEvent(KeyboardControlEvent event) {
445 UMA_HISTOGRAM_ENUMERATION( 446 UMA_HISTOGRAM_ENUMERATION(
446 "VirtualKeyboard.KeyboardControlEvent", 447 "VirtualKeyboard.KeyboardControlEvent",
447 event, 448 event,
448 keyboard::KEYBOARD_CONTROL_MAX); 449 keyboard::KEYBOARD_CONTROL_MAX);
449 } 450 }
450 451
451 } // namespace keyboard 452 } // namespace keyboard
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698