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

Unified Diff: ui/keyboard/keyboard_util.cc

Issue 20145004: Switch from text insertion to key press and release events on the virtual k… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with trunk. Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/keyboard/keyboard_util.h ('k') | ui/keyboard/resources/api_adapter.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/keyboard/keyboard_util.cc
diff --git a/ui/keyboard/keyboard_util.cc b/ui/keyboard/keyboard_util.cc
index 2054e6736ad52f8b662ecfb4ddae653d880d3ebb..9daabe2733bb9c3b23e2db6cf9e7db0e799c8855 100644
--- a/ui/keyboard/keyboard_util.cc
+++ b/ui/keyboard/keyboard_util.cc
@@ -17,6 +17,13 @@
#include "ui/base/ime/text_input_client.h"
#include "ui/keyboard/keyboard_switches.h"
+namespace {
+
+const char kKeyDown[] ="keydown";
+const char kKeyUp[] = "keyup";
+
+} // namespace
+
namespace keyboard {
bool IsKeyboardEnabled() {
@@ -28,28 +35,6 @@ bool InsertText(const base::string16& text, aura::RootWindow* root_window) {
if (!root_window)
return false;
- // Handle Backspace and Enter specially: using TextInputClient::InsertText is
- // very unreliable for these characters.
- // TODO(bryeung): remove this code once virtual keyboards are able to send
- // these events directly via the Input Injection API.
- if (text.length() == 1) {
- ui::KeyboardCode code = ui::VKEY_UNKNOWN;
- if (text[0] == L'\n')
- code = ui::VKEY_RETURN;
- else if (text[0] == L'\b')
- code = ui::VKEY_BACK;
-
- if (code != ui::VKEY_UNKNOWN) {
- ui::KeyEvent press_event(ui::ET_KEY_PRESSED, code, 0, 0);
- root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&press_event);
-
- ui::KeyEvent release_event(ui::ET_KEY_RELEASED, code, 0, 0);
- root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&release_event);
-
- return true;
- }
- }
-
ui::InputMethod* input_method = root_window->GetProperty(
aura::client::kRootWindowInputMethodKey);
if (!input_method)
@@ -103,6 +88,41 @@ bool MoveCursor(int swipe_direction,
return true;
}
+bool SendKeyEvent(const std::string type,
+ int key_value,
+ int key_code,
+ bool shift_modifier,
+ aura::RootWindow* root_window) {
+ ui::EventType event_type = ui::ET_UNKNOWN;
+ if (type == kKeyDown)
+ event_type = ui::ET_KEY_PRESSED;
+ else if (type == kKeyUp)
+ event_type = ui::ET_KEY_RELEASED;
+ if (event_type == ui::ET_UNKNOWN)
+ return false;
+
+ int flags = ui::EF_NONE;
+ if (shift_modifier)
+ flags = ui::EF_SHIFT_DOWN;
+
+ ui::KeyboardCode code = static_cast<ui::KeyboardCode>(key_code);
+
+ ui::KeyEvent event(event_type, code, flags, false);
+ event.set_character(key_value);
+ event.set_unmodified_character(key_value);
+
+ if (code != ui::VKEY_UNKNOWN) {
+ root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&event);
+ } else if (event_type == ui::ET_KEY_RELEASED) {
+ // TODO(kevers): Fix key handling to support key_value when code is
+ // VKEY_UNKNOWN.
+ base::string16 text;
+ text.push_back(static_cast<char16>(key_value));
+ InsertText(text, root_window);
+ }
+ return true;
+}
+
const GritResourceMap* GetKeyboardExtensionResources(size_t* size) {
// This looks a lot like the contents of a resource map; however it is
// necessary to have a custom path for the extension path, so the resource
« no previous file with comments | « ui/keyboard/keyboard_util.h ('k') | ui/keyboard/resources/api_adapter.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698