Commit 3e86f223 authored by samuong's avatar samuong Committed by Commit bot

Implement keycode text conversion functions for Ozone.

BUG=413075

Review URL: https://codereview.chromium.org/1135203005

Cr-Commit-Position: refs/heads/master@{#329693}
parent 5085101b
...@@ -1845,6 +1845,7 @@ ...@@ -1845,6 +1845,7 @@
'../third_party/zlib/google/zip.gyp:zip', '../third_party/zlib/google/zip.gyp:zip',
'../ui/base/ui_base.gyp:ui_base', '../ui/base/ui_base.gyp:ui_base',
'../ui/events/events.gyp:events_base', '../ui/events/events.gyp:events_base',
'../ui/events/ozone/events_ozone.gyp:events_ozone_layout',
'../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry', '../ui/gfx/gfx.gyp:gfx_geometry',
], ],
......
...@@ -3,25 +3,92 @@ ...@@ -3,25 +3,92 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/test/chromedriver/chrome/ui_events.h" #include "chrome/test/chromedriver/chrome/ui_events.h"
#include "chrome/test/chromedriver/keycode_text_conversion.h" #include "chrome/test/chromedriver/keycode_text_conversion.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/dom3/dom_code.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"
#include "ui/events/ozone/layout/keyboard_layout_engine.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
// TODO(arunprasadr) Implement these functions properly for ozone platforms. bool ConvertKeyCodeToText(ui::KeyboardCode key_code,
bool ConvertKeyCodeToText( int modifiers,
ui::KeyboardCode key_code, int modifiers, std::string* text, std::string* text,
std::string* error_msg) { std::string* error_msg) {
*text = std::string(); ui::KeyboardLayoutEngine* keyboard_layout_engine =
*error_msg = std::string("Not Implemented"); ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine();
NOTIMPLEMENTED(); ui::DomCode dom_code = ui::UsLayoutKeyboardCodeToDomCode(key_code);
return false; int event_flags = ui::EF_NONE;
// Chrome OS keyboards don't have meta or num lock keys, so these modifier
// masks are ignored. Only handle alt, ctrl and shift.
if (modifiers & kAltKeyModifierMask)
event_flags |= ui::EF_ALT_DOWN;
if (modifiers & kControlKeyModifierMask)
event_flags |= ui::EF_CONTROL_DOWN;
if (modifiers & kShiftKeyModifierMask)
event_flags |= ui::EF_SHIFT_DOWN;
ui::DomKey dom_key_ignored;
base::char16 str[2] = {'\0'};
ui::KeyboardCode key_code_ignored;
uint32 platform_keycode_ignored;
if (!keyboard_layout_engine->Lookup(dom_code, event_flags, &dom_key_ignored,
&str[0], &key_code_ignored,
&platform_keycode_ignored)) {
// Key codes like ui::VKEY_UNKNOWN need to be mapped to the empty string, so
// even if the lookup fails we still need to return true here.
*text = std::string();
return true;
}
if (!base::UTF16ToUTF8(str, base::c16len(str), text)) {
*error_msg = base::StringPrintf(
"unicode conversion failed for keycode %d with modifiers 0x%x",
key_code, modifiers);
return false;
}
return true;
} }
bool ConvertCharToKeyCode( bool ConvertCharToKeyCode(base::char16 key,
base::char16 key, ui::KeyboardCode* key_code, int *necessary_modifiers, ui::KeyboardCode* key_code,
std::string* error_msg) { int* necessary_modifiers,
*error_msg = std::string("Not Implemented"); std::string* error_msg) {
*necessary_modifiers = 0; base::string16 key_string;
NOTIMPLEMENTED(); key_string.push_back(key);
return false; std::string key_string_utf8 = base::UTF16ToUTF8(key_string);
bool found_code = false;
*error_msg = std::string();
// There doesn't seem to be a way to get a CrOS key code for a given unicode
// character. So here we check every key code to see if it produces the
// right character, as we do on Mac (see keycode_text_conversion_mac.mm).
for (int i = 0; i < 256; ++i) {
ui::KeyboardCode code = static_cast<ui::KeyboardCode>(i);
// Skip the numpad keys.
if (code >= ui::VKEY_NUMPAD0 && code <= ui::VKEY_DIVIDE)
continue;
std::string key_string;
if (!ConvertKeyCodeToText(code, 0, &key_string, error_msg))
return false;
found_code = key_string_utf8 == key_string;
std::string key_string_utf8_tmp;
if (!ConvertKeyCodeToText(code, kShiftKeyModifierMask, &key_string_utf8_tmp,
error_msg))
return false;
if (!found_code && key_string_utf8 == key_string_utf8_tmp) {
*necessary_modifiers = kShiftKeyModifierMask;
found_code = true;
}
if (found_code) {
*key_code = code;
break;
}
}
return found_code;
} }
...@@ -60,7 +60,7 @@ std::string ConvertKeyCodeToTextNoError(ui::KeyboardCode key_code, ...@@ -60,7 +60,7 @@ std::string ConvertKeyCodeToTextNoError(ui::KeyboardCode key_code,
} // namespace } // namespace
#if defined(OS_LINUX) #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// Fails on bots: crbug.com/174962 // Fails on bots: crbug.com/174962
#define MAYBE_KeyCodeToText DISABLED_KeyCodeToText #define MAYBE_KeyCodeToText DISABLED_KeyCodeToText
#else #else
...@@ -93,7 +93,7 @@ TEST(KeycodeTextConversionTest, MAYBE_KeyCodeToText) { ...@@ -93,7 +93,7 @@ TEST(KeycodeTextConversionTest, MAYBE_KeyCodeToText) {
ConvertKeyCodeToTextNoError(ui::VKEY_SHIFT, kShiftKeyModifierMask)); ConvertKeyCodeToTextNoError(ui::VKEY_SHIFT, kShiftKeyModifierMask));
} }
#if defined(OS_LINUX) #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// Fails on bots: crbug.com/174962 // Fails on bots: crbug.com/174962
#define MAYBE_CharToKeyCode DISABLED_CharToKeyCode #define MAYBE_CharToKeyCode DISABLED_CharToKeyCode
#else #else
...@@ -117,7 +117,7 @@ TEST(KeycodeTextConversionTest, MAYBE_CharToKeyCode) { ...@@ -117,7 +117,7 @@ TEST(KeycodeTextConversionTest, MAYBE_CharToKeyCode) {
CheckCantConvertChar(L'\u2159'); CheckCantConvertChar(L'\u2159');
} }
#if defined(OS_LINUX) || defined(OS_MACOSX) #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX)
// Not implemented on Linux. // Not implemented on Linux.
// Fails if German layout is not installed on Mac. // Fails if German layout is not installed on Mac.
#define MAYBE_NonShiftModifiers DISABLED_NonShiftModifiers #define MAYBE_NonShiftModifiers DISABLED_NonShiftModifiers
...@@ -139,7 +139,7 @@ TEST(KeycodeTextConversionTest, MAYBE_NonShiftModifiers) { ...@@ -139,7 +139,7 @@ TEST(KeycodeTextConversionTest, MAYBE_NonShiftModifiers) {
#endif #endif
} }
#if defined(OS_LINUX) || defined(OS_MACOSX) #if (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX)
// Not implemented on Linux. // Not implemented on Linux.
// Fails if German layout is not installed on Mac. // Fails if German layout is not installed on Mac.
#define MAYBE_NonEnglish DISABLED_NonEnglish #define MAYBE_NonEnglish DISABLED_NonEnglish
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment