OLD | NEW |
---|---|
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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "grit/keyboard_resources.h" | 12 #include "grit/keyboard_resources.h" |
13 #include "grit/keyboard_resources_map.h" | 13 #include "grit/keyboard_resources_map.h" |
14 #include "ui/aura/client/aura_constants.h" | 14 #include "ui/aura/client/aura_constants.h" |
15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
16 #include "ui/base/ime/input_method.h" | 16 #include "ui/base/ime/input_method.h" |
17 #include "ui/base/ime/text_input_client.h" | 17 #include "ui/base/ime/text_input_client.h" |
18 #include "ui/keyboard/keyboard_switches.h" | 18 #include "ui/keyboard/keyboard_switches.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char kKeyDown[] ="keydown"; | 22 const char kKeyDown[] ="keydown"; |
23 const char kKeyUp[] = "keyup"; | 23 const char kKeyUp[] = "keyup"; |
24 | 24 |
25 void sendProcessKeyEvent(ui::EventType type, aura::RootWindow* root_window) { | |
sadrul
2013/09/05 22:54:49
SendProcessKeyEvent
kevers
2013/09/06 00:48:25
Done.
| |
26 ui::TranslatedKeyEvent event(type == ui::ET_KEY_PRESSED, | |
27 ui::VKEY_PROCESSKEY, | |
28 ui::EF_NONE); | |
29 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&event); | |
30 } | |
31 | |
25 } // namespace | 32 } // namespace |
26 | 33 |
27 namespace keyboard { | 34 namespace keyboard { |
28 | 35 |
29 bool IsKeyboardEnabled() { | 36 bool IsKeyboardEnabled() { |
30 return CommandLine::ForCurrentProcess()->HasSwitch( | 37 return CommandLine::ForCurrentProcess()->HasSwitch( |
31 switches::kEnableVirtualKeyboard); | 38 switches::kEnableVirtualKeyboard); |
32 } | 39 } |
33 | 40 |
34 bool InsertText(const base::string16& text, aura::RootWindow* root_window) { | 41 bool InsertText(const base::string16& text, aura::RootWindow* root_window) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 event_type = ui::ET_KEY_RELEASED; | 107 event_type = ui::ET_KEY_RELEASED; |
101 if (event_type == ui::ET_UNKNOWN) | 108 if (event_type == ui::ET_UNKNOWN) |
102 return false; | 109 return false; |
103 | 110 |
104 int flags = ui::EF_NONE; | 111 int flags = ui::EF_NONE; |
105 if (shift_modifier) | 112 if (shift_modifier) |
106 flags = ui::EF_SHIFT_DOWN; | 113 flags = ui::EF_SHIFT_DOWN; |
107 | 114 |
108 ui::KeyboardCode code = static_cast<ui::KeyboardCode>(key_code); | 115 ui::KeyboardCode code = static_cast<ui::KeyboardCode>(key_code); |
109 | 116 |
110 ui::KeyEvent event(event_type, code, flags, false); | 117 if (code == ui::VKEY_UNKNOWN) { |
111 event.set_character(key_value); | 118 // Handling of special printable characters (e.g. accented characters) for |
112 event.set_unmodified_character(key_value); | 119 // which there is no key code. |
120 if (event_type == ui::ET_KEY_RELEASED) { | |
121 ui::InputMethod* input_method = root_window->GetProperty( | |
122 aura::client::kRootWindowInputMethodKey); | |
123 if (!input_method) | |
124 return false; | |
113 | 125 |
114 if (code != ui::VKEY_UNKNOWN) { | 126 ui::TextInputClient* tic = input_method->GetTextInputClient(); |
127 | |
128 sendProcessKeyEvent(ui::ET_KEY_PRESSED, root_window); | |
129 tic->InsertChar(static_cast<uint16>(key_value), ui::EF_NONE); | |
130 sendProcessKeyEvent(ui::ET_KEY_RELEASED, root_window); | |
sadrul
2013/09/05 22:54:49
I think it'd be simpler if you do:
SendProcessK
kevers
2013/09/06 00:48:25
InsertText does not work for web content as the te
sadrul
2013/09/06 05:52:38
Ah, I see. It feels a bit weird that InsertText()
| |
131 } | |
132 } else { | |
133 ui::KeyEvent event(event_type, code, flags, false); | |
115 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&event); | 134 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&event); |
116 } else if (event_type == ui::ET_KEY_RELEASED) { | |
117 // TODO(kevers): Fix key handling to support key_value when code is | |
118 // VKEY_UNKNOWN. | |
119 base::string16 text; | |
120 text.push_back(static_cast<char16>(key_value)); | |
121 InsertText(text, root_window); | |
122 } | 135 } |
123 return true; | 136 return true; |
124 } | 137 } |
125 | 138 |
126 const GritResourceMap* GetKeyboardExtensionResources(size_t* size) { | 139 const GritResourceMap* GetKeyboardExtensionResources(size_t* size) { |
127 // This looks a lot like the contents of a resource map; however it is | 140 // This looks a lot like the contents of a resource map; however it is |
128 // necessary to have a custom path for the extension path, so the resource | 141 // necessary to have a custom path for the extension path, so the resource |
129 // map cannot be used directly. | 142 // map cannot be used directly. |
130 static const GritResourceMap kKeyboardResources[] = { | 143 static const GritResourceMap kKeyboardResources[] = { |
131 {"keyboard/api_adapter.js", IDR_KEYBOARD_API_ADAPTER_JS}, | 144 {"keyboard/api_adapter.js", IDR_KEYBOARD_API_ADAPTER_JS}, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 {"keyboard/main.css", IDR_KEYBOARD_MAIN_CSS}, | 176 {"keyboard/main.css", IDR_KEYBOARD_MAIN_CSS}, |
164 {"keyboard/polymer.min.js", IDR_KEYBOARD_POLYMER}, | 177 {"keyboard/polymer.min.js", IDR_KEYBOARD_POLYMER}, |
165 {"keyboard/voice_input.js", IDR_KEYBOARD_VOICE_INPUT_JS}, | 178 {"keyboard/voice_input.js", IDR_KEYBOARD_VOICE_INPUT_JS}, |
166 }; | 179 }; |
167 static const size_t kKeyboardResourcesSize = arraysize(kKeyboardResources); | 180 static const size_t kKeyboardResourcesSize = arraysize(kKeyboardResources); |
168 *size = kKeyboardResourcesSize; | 181 *size = kKeyboardResourcesSize; |
169 return kKeyboardResources; | 182 return kKeyboardResources; |
170 } | 183 } |
171 | 184 |
172 } // namespace keyboard | 185 } // namespace keyboard |
OLD | NEW |