diff options
author | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-27 02:18:57 +0000 |
---|---|---|
committer | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-27 02:18:57 +0000 |
commit | 000216bf8f9e65726df376d6cec16ab87f725fe0 (patch) | |
tree | fc410cc775afd396dab5541c5000085044fac025 /chrome/browser/extensions/extension_input_api.cc | |
parent | 54edcea75724b0cf2d883768c247ac448f2b408e (diff) | |
download | chromium_src-000216bf8f9e65726df376d6cec16ab87f725fe0.zip chromium_src-000216bf8f9e65726df376d6cec16ab87f725fe0.tar.gz chromium_src-000216bf8f9e65726df376d6cec16ab87f725fe0.tar.bz2 |
Add Unicode character support to chrome.input.sendKeyboardEvent.
Currently, the API can fabricate a key event which is supported by src/ui/base/keycodes/keyboard_codes_posix.h. This means the API only supports ASCII characters (<= 0x7f).
However, since some i18n virtual keyboards need to call the API to generate a key event which is not supported by the header, it'd be better to relax the limitation. For example, French virtual keyboard might call the API with U+00E1 (LATIN SMALL LETTER A WITH ACUTE), Russian one might do it with U+0410 (CYRILLIC CAPITAL LETTER A).
BUG=chromium-os:18048
TEST=run browser_tests
Review URL: http://codereview.chromium.org/7473025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94236 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_input_api.cc')
-rw-r--r-- | chrome/browser/extensions/extension_input_api.cc | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_input_api.cc b/chrome/browser/extensions/extension_input_api.cc index 503bea3..7916a5f 100644 --- a/chrome/browser/extensions/extension_input_api.cc +++ b/chrome/browser/extensions/extension_input_api.cc @@ -6,6 +6,7 @@ #include <string> +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/values.h" #include "chrome/browser/extensions/key_identifier_conversion_views.h" @@ -58,6 +59,20 @@ ui::EventType GetTypeFromString(const std::string& type) { return ui::ET_UNKNOWN; } +// Converts a hex string "U+NNNN" to uint16. Returns 0 on error. +uint16 UnicodeIdentifierStringToInt(const std::string& key_identifier) { + int character = 0; + if ((key_identifier.length() == 6) && + (key_identifier.substr(0, 2) == "U+") && + (key_identifier.substr(2).find_first_not_of("0123456789abcdefABCDEF") == + std::string::npos)) { + const bool result = + base::HexStringToInt(key_identifier.substr(2), &character); + DCHECK(result) << key_identifier; + } + return character; +} + } // namespace void InputFunction::Run() { @@ -109,13 +124,20 @@ bool SendKeyboardEventInputFunction::RunImpl() { const views::KeyEvent& prototype_event = KeyEventFromKeyIdentifier(identifier); + uint16 character = 0; if (prototype_event.key_code() == ui::VKEY_UNKNOWN) { - error_ = kUnknownOrUnsupportedKeyIdentiferError; - return false; + // Check if |identifier| is "U+NNNN" format. + character = UnicodeIdentifierStringToInt(identifier); + if (!character) { + error_ = kUnknownOrUnsupportedKeyIdentiferError; + return false; + } } bool flag = false; - int flags = prototype_event.flags(); + int flags = 0; + if (prototype_event.key_code() != ui::VKEY_UNKNOWN) + flags = prototype_event.flags(); flags |= (args->GetBoolean(kAlt, &flag) && flag) ? ui::EF_ALT_DOWN : 0; flags |= (args->GetBoolean(kCtrl, &flag) && flag) ? ui::EF_CONTROL_DOWN : 0; flags |= (args->GetBoolean(kShift, &flag) && flag) ? ui::EF_SHIFT_DOWN : 0; @@ -132,6 +154,11 @@ bool SendKeyboardEventInputFunction::RunImpl() { } views::KeyEvent event(type, prototype_event.key_code(), flags); + if (character) { + event.set_character(character); + event.set_unmodified_character(character); + } + views::InputMethod* ime = widget->GetInputMethod(); if (ime) { ime->DispatchKeyEvent(event); |