Chromium Code Reviews| Index: components/test_runner/event_sender.cc |
| diff --git a/components/test_runner/event_sender.cc b/components/test_runner/event_sender.cc |
| index c78d03972ca4f494195eeb964a3f7bf3a21008dc..0dbd65afbb3b6b43ce26ec69fa76b8eed9d7a5ff 100644 |
| --- a/components/test_runner/event_sender.cc |
| +++ b/components/test_runner/event_sender.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/basictypes.h" |
| #include "base/logging.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "components/test_runner/mock_spell_check.h" |
| @@ -22,7 +23,10 @@ |
| #include "third_party/WebKit/public/web/WebKit.h" |
| #include "third_party/WebKit/public/web/WebPagePopup.h" |
| #include "third_party/WebKit/public/web/WebView.h" |
| +#include "ui/events/event_constants.h" |
| +#include "ui/events/keycodes/dom/dom_key.h" |
| #include "ui/events/keycodes/dom/keycode_converter.h" |
| +#include "ui/events/keycodes/keyboard_code_conversion.h" |
| #include "ui/events/keycodes/keyboard_codes.h" |
| #include "v8/include/v8.h" |
| @@ -1241,7 +1245,7 @@ void EventSender::MouseUp(int button_number, int modifiers) { |
| } |
| } |
| -void EventSender::KeyDown(const std::string& code_str, |
| +void EventSender::KeyDown(const std::string& key_code_str, |
| int modifiers, |
| KeyLocationCode location) { |
| // FIXME: I'm not exactly sure how we should convert the string to a key |
| @@ -1252,123 +1256,104 @@ void EventSender::KeyDown(const std::string& code_str, |
| // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when |
| // Windows uses \r for "Enter". |
| - int code = 0; |
| + int key_code = 0; |
| int text = 0; |
| bool needs_shift_key_modifier = false; |
| - std::string domString; |
| - if ("\n" == code_str) { |
| + if ("\n" == key_code_str) { |
| generate_char = true; |
| - text = code = ui::VKEY_RETURN; |
| - domString.assign("Enter"); |
| - } else if ("rightArrow" == code_str) { |
| - code = ui::VKEY_RIGHT; |
| - domString.assign("ArrowRight"); |
| - } else if ("downArrow" == code_str) { |
| - code = ui::VKEY_DOWN; |
| - domString.assign("ArrowDown"); |
| - } else if ("leftArrow" == code_str) { |
| - code = ui::VKEY_LEFT; |
| - domString.assign("ArrowLeft"); |
| - } else if ("upArrow" == code_str) { |
| - code = ui::VKEY_UP; |
| - domString.assign("ArrowUp"); |
| - } else if ("insert" == code_str) { |
| - code = ui::VKEY_INSERT; |
| - domString.assign("Insert"); |
| - } else if ("delete" == code_str) { |
| - code = ui::VKEY_DELETE; |
| - domString.assign("Delete"); |
| - } else if ("pageUp" == code_str) { |
| - code = ui::VKEY_PRIOR; |
| - domString.assign("PageUp"); |
| - } else if ("pageDown" == code_str) { |
| - code = ui::VKEY_NEXT; |
| - domString.assign("PageDown"); |
| - } else if ("home" == code_str) { |
| - code = ui::VKEY_HOME; |
| - domString.assign("Home"); |
| - } else if ("end" == code_str) { |
| - code = ui::VKEY_END; |
| - domString.assign("End"); |
| - } else if ("printScreen" == code_str) { |
| - code = ui::VKEY_SNAPSHOT; |
| - domString.assign("PrintScreen"); |
| - } else if ("menu" == code_str) { |
| - code = ui::VKEY_APPS; |
| - domString.assign("ContextMenu"); |
| - } else if ("leftControl" == code_str) { |
| - code = ui::VKEY_LCONTROL; |
| - domString.assign("ControlLeft"); |
| - } else if ("rightControl" == code_str) { |
| - code = ui::VKEY_RCONTROL; |
| - domString.assign("ControlRight"); |
| - } else if ("leftShift" == code_str) { |
| - code = ui::VKEY_LSHIFT; |
| - domString.assign("ShiftLeft"); |
| - } else if ("rightShift" == code_str) { |
| - code = ui::VKEY_RSHIFT; |
| - domString.assign("ShiftRight"); |
| - } else if ("leftAlt" == code_str) { |
| - code = ui::VKEY_LMENU; |
| - domString.assign("AltLeft"); |
| - } else if ("rightAlt" == code_str) { |
| - code = ui::VKEY_RMENU; |
| - domString.assign("AltRight"); |
| - } else if ("numLock" == code_str) { |
| - code = ui::VKEY_NUMLOCK; |
| - domString.assign("NumLock"); |
| - } else if ("backspace" == code_str) { |
| - code = ui::VKEY_BACK; |
| - domString.assign("Backspace"); |
| - } else if ("escape" == code_str) { |
| - code = ui::VKEY_ESCAPE; |
| - domString.assign("Escape"); |
| + text = key_code = ui::VKEY_RETURN; |
| + } else if ("rightArrow" == key_code_str) { |
| + key_code = ui::VKEY_RIGHT; |
| + } else if ("downArrow" == key_code_str) { |
| + key_code = ui::VKEY_DOWN; |
| + } else if ("leftArrow" == key_code_str) { |
| + key_code = ui::VKEY_LEFT; |
| + } else if ("upArrow" == key_code_str) { |
| + key_code = ui::VKEY_UP; |
| + } else if ("insert" == key_code_str) { |
| + key_code = ui::VKEY_INSERT; |
| + } else if ("delete" == key_code_str) { |
| + key_code = ui::VKEY_DELETE; |
| + } else if ("pageUp" == key_code_str) { |
| + key_code = ui::VKEY_PRIOR; |
| + } else if ("pageDown" == key_code_str) { |
| + key_code = ui::VKEY_NEXT; |
| + } else if ("home" == key_code_str) { |
| + key_code = ui::VKEY_HOME; |
| + } else if ("end" == key_code_str) { |
| + key_code = ui::VKEY_END; |
| + } else if ("printScreen" == key_code_str) { |
| + key_code = ui::VKEY_SNAPSHOT; |
| + } else if ("menu" == key_code_str) { |
| + key_code = ui::VKEY_APPS; |
| + } else if ("leftControl" == key_code_str) { |
| + key_code = ui::VKEY_LCONTROL; |
| + } else if ("rightControl" == key_code_str) { |
| + key_code = ui::VKEY_RCONTROL; |
| + } else if ("leftShift" == key_code_str) { |
| + key_code = ui::VKEY_LSHIFT; |
| + } else if ("rightShift" == key_code_str) { |
| + key_code = ui::VKEY_RSHIFT; |
| + } else if ("leftAlt" == key_code_str) { |
| + key_code = ui::VKEY_LMENU; |
| + } else if ("rightAlt" == key_code_str) { |
| + key_code = ui::VKEY_RMENU; |
| + } else if ("numLock" == key_code_str) { |
| + key_code = ui::VKEY_NUMLOCK; |
| + } else if ("backspace" == key_code_str) { |
| + key_code = ui::VKEY_BACK; |
| + } else if ("escape" == key_code_str) { |
| + key_code = ui::VKEY_ESCAPE; |
| } else { |
| // Compare the input string with the function-key names defined by the |
| // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key |
| // name, set its key code. |
| for (int i = 1; i <= 24; ++i) { |
| std::string function_key_name = base::StringPrintf("F%d", i); |
| - if (function_key_name == code_str) { |
| - code = ui::VKEY_F1 + (i - 1); |
| - domString = function_key_name; |
| + if (function_key_name == key_code_str) { |
| + key_code = ui::VKEY_F1 + (i - 1); |
| break; |
| } |
| } |
| - if (!code) { |
| + if (!key_code) { |
| WebString web_code_str = |
| - WebString::fromUTF8(code_str.data(), code_str.size()); |
| + WebString::fromUTF8(key_code_str.data(), key_code_str.size()); |
| if (web_code_str.length() != 1u) { |
| v8::Isolate* isolate = blink::mainThreadIsolate(); |
| isolate->ThrowException(v8::Exception::TypeError( |
| gin::StringToV8(isolate, "Invalid web code."))); |
| return; |
| } |
| - text = code = web_code_str.at(0); |
| - needs_shift_key_modifier = NeedsShiftModifier(code); |
| - if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') |
| - code -= 'a' - 'A'; |
| - if ((code >= 'A' && code <= 'Z') || (code >= 'a' && code <= 'z')) { |
| - domString.assign("Key"); |
| - domString.push_back(base::ToUpperASCII(code)); |
| - } else if (code >= '0' && code <= '9') { |
| - domString.assign("Digit"); |
| - domString.push_back(code); |
| - } else if (code == ' ') { |
| - domString.assign("Space"); |
| - } else if (code == 9) { |
| - domString.assign("Tab"); |
| - } |
| + text = key_code = web_code_str.at(0); |
| + needs_shift_key_modifier = NeedsShiftModifier(key_code); |
| + if ((key_code & 0xFF) >= 'a' && (key_code & 0xFF) <= 'z') |
| + key_code -= 'a' - 'A'; |
| generate_char = true; |
| } |
| - if ("(" == code_str) { |
| - code = '9'; |
| + if ("(" == key_code_str) { |
| + key_code = '9'; |
| needs_shift_key_modifier = true; |
| } |
| } |
| + ui::KeyboardCode codex = ui::VKEY_UNKNOWN; |
|
Wez
2015/06/25 10:40:21
nit: Why "codex"?
Habib Virji
2015/06/26 17:35:38
Removed.
|
| + ui::DomCode dom_code = ui::UsLayoutKeyboardCodeToDomCode( |
| + static_cast<ui::KeyboardCode>(key_code)); |
| + ui::DomKey dom_key; |
| + base::char16 dom_key_char = 0; |
| + if (!DomCodeToUsLayoutMeaning(dom_code, ui::EF_NONE, &dom_key, &dom_key_char, |
| + &codex)) { |
|
Wez
2015/06/25 10:40:21
In principle the output KeyboardCode should be the
Habib Virji
2015/06/26 17:35:38
The reason was key_code was not KeyboardCode, to p
|
| + dom_key = ui::DomKey::NONE; |
| + } |
| + |
| + int dom_key_int; |
| + if (dom_key == ui::DomKey::CHARACTER) |
| + dom_key_int = static_cast<int>(dom_key_char); |
| + else |
| + dom_key_int = DOM_KEY_PRINT_NON_DIFF + static_cast<int>(dom_key); |
| + |
| // For one generated keyboard event, we need to generate a keyDown/keyUp |
| // pair; |
| // On Windows, we might also need to generate a char event to mimic the |
| @@ -1377,9 +1362,9 @@ void EventSender::KeyDown(const std::string& code_str, |
| WebKeyboardEvent event_down; |
| event_down.type = WebInputEvent::RawKeyDown; |
| event_down.modifiers = modifiers; |
| - event_down.windowsKeyCode = code; |
| - event_down.domCode = static_cast<int>( |
| - ui::KeycodeConverter::CodeStringToDomCode(domString.c_str())); |
| + event_down.windowsKeyCode = key_code; |
| + event_down.domCode = static_cast<int>(dom_code); |
| + event_down.domKey = dom_key_int; |
| if (generate_char) { |
| event_down.text[0] = text; |
| @@ -1417,7 +1402,7 @@ void EventSender::KeyDown(const std::string& code_str, |
| HandleInputEventOnViewOrPopup(event_down); |
| - if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { |
| + if (key_code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { |
| WebMouseEvent event; |
| InitMouseEvent(WebInputEvent::MouseDown, |
| pressed_button_, |
| @@ -1437,7 +1422,7 @@ void EventSender::KeyDown(const std::string& code_str, |
| // keyIdentifier is an empty string, unless the Enter key was pressed. |
| // This behavior is not standard (keyIdentifier itself is not even a |
| // standard any more), but it matches the actual behavior in Blink. |
| - if (code != ui::VKEY_RETURN) |
| + if (key_code != ui::VKEY_RETURN) |
| event_char.keyIdentifier[0] = '\0'; |
| HandleInputEventOnViewOrPopup(event_char); |
| } |