OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/shell/renderer/test_runner/event_sender.h" | 5 #include "content/shell/renderer/test_runner/event_sender.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 int modifiers, | 1282 int modifiers, |
1283 KeyLocationCode location) { | 1283 KeyLocationCode location) { |
1284 // FIXME: I'm not exactly sure how we should convert the string to a key | 1284 // FIXME: I'm not exactly sure how we should convert the string to a key |
1285 // event. This seems to work in the cases I tested. | 1285 // event. This seems to work in the cases I tested. |
1286 // FIXME: Should we also generate a KEY_UP? | 1286 // FIXME: Should we also generate a KEY_UP? |
1287 | 1287 |
1288 bool generate_char = false; | 1288 bool generate_char = false; |
1289 | 1289 |
1290 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when | 1290 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when |
1291 // Windows uses \r for "Enter". | 1291 // Windows uses \r for "Enter". |
1292 int code = 0; | 1292 int keyCode = 0; |
1293 int text = 0; | 1293 int text = 0; |
1294 bool needs_shift_key_modifier = false; | 1294 bool needs_shift_key_modifier = false; |
1295 std::string domString; | 1295 std::string domCode; |
| 1296 std::string domKey; |
1296 | 1297 |
1297 if ("\n" == code_str) { | 1298 if ("\n" == code_str) { |
1298 generate_char = true; | 1299 generate_char = true; |
1299 text = code = ui::VKEY_RETURN; | 1300 text = keyCode = ui::VKEY_RETURN; |
1300 domString.assign("Enter"); | 1301 domCode.assign("Enter"); |
1301 } else if ("rightArrow" == code_str) { | 1302 } else if ("rightArrow" == code_str) { |
1302 code = ui::VKEY_RIGHT; | 1303 keyCode = ui::VKEY_RIGHT; |
1303 domString.assign("ArrowRight"); | 1304 domCode.assign("ArrowRight"); |
1304 } else if ("downArrow" == code_str) { | 1305 } else if ("downArrow" == code_str) { |
1305 code = ui::VKEY_DOWN; | 1306 keyCode = ui::VKEY_DOWN; |
1306 domString.assign("ArrowDown"); | 1307 domCode.assign("ArrowDown"); |
1307 } else if ("leftArrow" == code_str) { | 1308 } else if ("leftArrow" == code_str) { |
1308 code = ui::VKEY_LEFT; | 1309 keyCode = ui::VKEY_LEFT; |
1309 domString.assign("ArrowLeft"); | 1310 domCode.assign("ArrowLeft"); |
1310 } else if ("upArrow" == code_str) { | 1311 } else if ("upArrow" == code_str) { |
1311 code = ui::VKEY_UP; | 1312 keyCode = ui::VKEY_UP; |
1312 domString.assign("ArrowUp"); | 1313 domCode.assign("ArrowUp"); |
1313 } else if ("insert" == code_str) { | 1314 } else if ("insert" == code_str) { |
1314 code = ui::VKEY_INSERT; | 1315 keyCode = ui::VKEY_INSERT; |
1315 domString.assign("Insert"); | 1316 domCode.assign("Insert"); |
1316 } else if ("delete" == code_str) { | 1317 } else if ("delete" == code_str) { |
1317 code = ui::VKEY_DELETE; | 1318 keyCode = ui::VKEY_DELETE; |
1318 domString.assign("Delete"); | 1319 domCode.assign("Delete"); |
1319 } else if ("pageUp" == code_str) { | 1320 } else if ("pageUp" == code_str) { |
1320 code = ui::VKEY_PRIOR; | 1321 keyCode = ui::VKEY_PRIOR; |
1321 domString.assign("PageUp"); | 1322 domCode.assign("PageUp"); |
1322 } else if ("pageDown" == code_str) { | 1323 } else if ("pageDown" == code_str) { |
1323 code = ui::VKEY_NEXT; | 1324 keyCode = ui::VKEY_NEXT; |
1324 domString.assign("PageDown"); | 1325 domCode.assign("PageDown"); |
1325 } else if ("home" == code_str) { | 1326 } else if ("home" == code_str) { |
1326 code = ui::VKEY_HOME; | 1327 keyCode = ui::VKEY_HOME; |
1327 domString.assign("Home"); | 1328 domCode.assign("Home"); |
1328 } else if ("end" == code_str) { | 1329 } else if ("end" == code_str) { |
1329 code = ui::VKEY_END; | 1330 keyCode = ui::VKEY_END; |
1330 domString.assign("End"); | 1331 domCode.assign("End"); |
1331 } else if ("printScreen" == code_str) { | 1332 } else if ("printScreen" == code_str) { |
1332 code = ui::VKEY_SNAPSHOT; | 1333 keyCode = ui::VKEY_SNAPSHOT; |
1333 domString.assign("PrintScreen"); | 1334 domCode.assign("PrintScreen"); |
1334 } else if ("menu" == code_str) { | 1335 } else if ("menu" == code_str) { |
1335 code = ui::VKEY_APPS; | 1336 keyCode = ui::VKEY_APPS; |
1336 domString.assign("ContextMenu"); | 1337 domCode.assign("ContextMenu"); |
| 1338 domKey.assign("MediaApps"); |
1337 } else if ("leftControl" == code_str) { | 1339 } else if ("leftControl" == code_str) { |
1338 code = ui::VKEY_LCONTROL; | 1340 keyCode = ui::VKEY_LCONTROL; |
1339 domString.assign("ControlLeft"); | 1341 domCode.assign("ControlLeft"); |
| 1342 domKey.assign("Control"); |
1340 } else if ("rightControl" == code_str) { | 1343 } else if ("rightControl" == code_str) { |
1341 code = ui::VKEY_RCONTROL; | 1344 keyCode = ui::VKEY_RCONTROL; |
1342 domString.assign("ControlRight"); | 1345 domCode.assign("ControlRight"); |
| 1346 domKey.assign("Control"); |
1343 } else if ("leftShift" == code_str) { | 1347 } else if ("leftShift" == code_str) { |
1344 code = ui::VKEY_LSHIFT; | 1348 keyCode = ui::VKEY_LSHIFT; |
1345 domString.assign("ShiftLeft"); | 1349 domCode.assign("ShiftLeft"); |
| 1350 domKey.assign("Shift"); |
1346 } else if ("rightShift" == code_str) { | 1351 } else if ("rightShift" == code_str) { |
1347 code = ui::VKEY_RSHIFT; | 1352 keyCode = ui::VKEY_RSHIFT; |
1348 domString.assign("ShiftRight"); | 1353 domCode.assign("ShiftRight"); |
| 1354 domKey.assign("Shift"); |
1349 } else if ("leftAlt" == code_str) { | 1355 } else if ("leftAlt" == code_str) { |
1350 code = ui::VKEY_LMENU; | 1356 keyCode = ui::VKEY_LMENU; |
1351 domString.assign("AltLeft"); | 1357 domCode.assign("AltLeft"); |
| 1358 domKey.assign("Alt"); |
1352 } else if ("rightAlt" == code_str) { | 1359 } else if ("rightAlt" == code_str) { |
1353 code = ui::VKEY_RMENU; | 1360 keyCode = ui::VKEY_RMENU; |
1354 domString.assign("AltRight"); | 1361 domCode.assign("AltRight"); |
| 1362 domKey.assign("AltGraph"); |
1355 } else if ("numLock" == code_str) { | 1363 } else if ("numLock" == code_str) { |
1356 code = ui::VKEY_NUMLOCK; | 1364 keyCode = ui::VKEY_NUMLOCK; |
1357 domString.assign("NumLock"); | 1365 domCode.assign("NumLock"); |
1358 } else if ("backspace" == code_str) { | 1366 } else if ("backspace" == code_str) { |
1359 code = ui::VKEY_BACK; | 1367 keyCode = ui::VKEY_BACK; |
1360 domString.assign("Backspace"); | 1368 domCode.assign("Backspace"); |
1361 } else if ("escape" == code_str) { | 1369 } else if ("escape" == code_str) { |
1362 code = ui::VKEY_ESCAPE; | 1370 keyCode = ui::VKEY_ESCAPE; |
1363 domString.assign("Escape"); | 1371 domCode.assign("Escape"); |
1364 } else { | 1372 } else { |
1365 // Compare the input string with the function-key names defined by the | 1373 // Compare the input string with the function-key names defined by the |
1366 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key | 1374 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key |
1367 // name, set its key code. | 1375 // name, set its key code. |
1368 for (int i = 1; i <= 24; ++i) { | 1376 for (int i = 1; i <= 24; ++i) { |
1369 std::string function_key_name = base::StringPrintf("F%d", i); | 1377 std::string function_key_name = base::StringPrintf("F%d", i); |
1370 if (function_key_name == code_str) { | 1378 if (function_key_name == code_str) { |
1371 code = ui::VKEY_F1 + (i - 1); | 1379 keyCode = ui::VKEY_F1 + (i - 1); |
1372 domString = function_key_name; | 1380 domCode = function_key_name; |
1373 break; | 1381 break; |
1374 } | 1382 } |
1375 } | 1383 } |
1376 if (!code) { | 1384 if (!keyCode) { |
1377 WebString web_code_str = | 1385 WebString web_code_str = |
1378 WebString::fromUTF8(code_str.data(), code_str.size()); | 1386 WebString::fromUTF8(code_str.data(), code_str.size()); |
1379 DCHECK_EQ(1u, web_code_str.length()); | 1387 DCHECK_EQ(1u, web_code_str.length()); |
1380 text = code = web_code_str.at(0); | 1388 text = keyCode = web_code_str.at(0); |
1381 needs_shift_key_modifier = NeedsShiftModifier(code); | 1389 needs_shift_key_modifier = NeedsShiftModifier(keyCode); |
1382 if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') | 1390 if ((keyCode & 0xFF) >= 'a' && (keyCode & 0xFF) <= 'z') |
1383 code -= 'a' - 'A'; | 1391 keyCode -= 'a' - 'A'; |
1384 if ((code >= 'A' && code <= 'Z') || (code >= 'a' && code <= 'z')) { | 1392 if ((keyCode >= 'A' && keyCode <= 'Z') || |
1385 domString.assign("Key"); | 1393 (keyCode >= 'a' && keyCode <= 'z')) { |
1386 domString.push_back(base::ToUpperASCII(code)); | 1394 domCode.assign("Key"); |
1387 } else if (code >= '0' && code <= '9') { | 1395 domCode.push_back(base::ToUpperASCII(keyCode)); |
1388 domString.assign("Digit"); | 1396 } else if (keyCode >= '0' && keyCode <= '9') { |
1389 domString.push_back(code); | 1397 domCode.assign("Digit"); |
1390 } else if (code == ' ') { | 1398 domCode.push_back(keyCode); |
1391 domString.assign("Space"); | 1399 } else if (keyCode == ' ') { |
1392 } else if (code == 9) { | 1400 domCode.assign("Space"); |
1393 domString.assign("Tab"); | 1401 } else if (keyCode == 9) { |
| 1402 domCode.assign("Tab"); |
1394 } | 1403 } |
1395 generate_char = true; | 1404 generate_char = true; |
1396 } | 1405 } |
1397 | 1406 |
1398 if ("(" == code_str) { | 1407 if ("(" == code_str) { |
1399 code = '9'; | 1408 keyCode = '9'; |
1400 needs_shift_key_modifier = true; | 1409 needs_shift_key_modifier = true; |
1401 } | 1410 } |
1402 } | 1411 } |
1403 | 1412 |
1404 // For one generated keyboard event, we need to generate a keyDown/keyUp | 1413 // For one generated keyboard event, we need to generate a keyDown/keyUp |
1405 // pair; | 1414 // pair; |
1406 // On Windows, we might also need to generate a char event to mimic the | 1415 // On Windows, we might also need to generate a char event to mimic the |
1407 // Windows event flow; on other platforms we create a merged event and test | 1416 // Windows event flow; on other platforms we create a merged event and test |
1408 // the event flow that that platform provides. | 1417 // the event flow that that platform provides. |
1409 WebKeyboardEvent event_down; | 1418 WebKeyboardEvent event_down; |
1410 event_down.type = WebInputEvent::RawKeyDown; | 1419 event_down.type = WebInputEvent::RawKeyDown; |
1411 event_down.modifiers = modifiers; | 1420 event_down.modifiers = modifiers; |
1412 event_down.windowsKeyCode = code; | 1421 event_down.windowsKeyCode = keyCode; |
1413 event_down.domCode = static_cast<int>( | 1422 event_down.domCode = static_cast<int>( |
1414 ui::KeycodeConverter::CodeStringToDomCode(domString.c_str())); | 1423 ui::KeycodeConverter::CodeStringToDomCode(domCode.c_str())); |
| 1424 if (domKey.empty()) |
| 1425 domKey = domCode; |
| 1426 event_down.domKey = static_cast<int>( |
| 1427 ui::KeycodeConverter::KeyStringToDomKey(domKey.c_str())); |
1415 | 1428 |
1416 if (generate_char) { | 1429 if (generate_char) { |
1417 event_down.text[0] = text; | 1430 event_down.text[0] = text; |
1418 event_down.unmodifiedText[0] = text; | 1431 event_down.unmodifiedText[0] = text; |
1419 } | 1432 } |
1420 | 1433 |
1421 event_down.setKeyIdentifierFromWindowsKeyCode(); | 1434 event_down.setKeyIdentifierFromWindowsKeyCode(); |
1422 | 1435 |
1423 if (event_down.modifiers != 0) | 1436 if (event_down.modifiers != 0) |
1424 event_down.isSystemKey = IsSystemKeyEvent(event_down); | 1437 event_down.isSystemKey = IsSystemKeyEvent(event_down); |
(...skipping 17 matching lines...) Expand all Loading... |
1442 // the command will be dispatched to the renderer just before dispatching | 1455 // the command will be dispatched to the renderer just before dispatching |
1443 // the keyboard event, and then it will be executed in the | 1456 // the keyboard event, and then it will be executed in the |
1444 // RenderView::handleCurrentKeyboardEvent() method. | 1457 // RenderView::handleCurrentKeyboardEvent() method. |
1445 // We just simulate the same behavior here. | 1458 // We just simulate the same behavior here. |
1446 std::string edit_command; | 1459 std::string edit_command; |
1447 if (GetEditCommand(event_down, &edit_command)) | 1460 if (GetEditCommand(event_down, &edit_command)) |
1448 delegate_->SetEditCommand(edit_command, ""); | 1461 delegate_->SetEditCommand(edit_command, ""); |
1449 | 1462 |
1450 HandleInputEventOnViewOrPopup(event_down); | 1463 HandleInputEventOnViewOrPopup(event_down); |
1451 | 1464 |
1452 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { | 1465 if (keyCode == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { |
1453 WebMouseEvent event; | 1466 WebMouseEvent event; |
1454 InitMouseEvent(WebInputEvent::MouseDown, | 1467 InitMouseEvent(WebInputEvent::MouseDown, |
1455 pressed_button_, | 1468 pressed_button_, |
1456 last_mouse_pos_, | 1469 last_mouse_pos_, |
1457 GetCurrentEventTimeSec(), | 1470 GetCurrentEventTimeSec(), |
1458 click_count_, | 1471 click_count_, |
1459 0, | 1472 0, |
1460 &event); | 1473 &event); |
1461 FinishDragAndDrop(event, blink::WebDragOperationNone); | 1474 FinishDragAndDrop(event, blink::WebDragOperationNone); |
1462 } | 1475 } |
1463 | 1476 |
1464 delegate_->ClearEditCommand(); | 1477 delegate_->ClearEditCommand(); |
1465 | 1478 |
1466 if (generate_char) { | 1479 if (generate_char) { |
1467 WebKeyboardEvent event_char = event_up; | 1480 WebKeyboardEvent event_char = event_up; |
1468 event_char.type = WebInputEvent::Char; | 1481 event_char.type = WebInputEvent::Char; |
1469 // keyIdentifier is an empty string, unless the Enter key was pressed. | 1482 // keyIdentifier is an empty string, unless the Enter key was pressed. |
1470 // This behavior is not standard (keyIdentifier itself is not even a | 1483 // This behavior is not standard (keyIdentifier itself is not even a |
1471 // standard any more), but it matches the actual behavior in Blink. | 1484 // standard any more), but it matches the actual behavior in Blink. |
1472 if (code != ui::VKEY_RETURN) | 1485 if (keyCode != ui::VKEY_RETURN) |
1473 event_char.keyIdentifier[0] = '\0'; | 1486 event_char.keyIdentifier[0] = '\0'; |
1474 HandleInputEventOnViewOrPopup(event_char); | 1487 HandleInputEventOnViewOrPopup(event_char); |
1475 } | 1488 } |
1476 | 1489 |
1477 HandleInputEventOnViewOrPopup(event_up); | 1490 HandleInputEventOnViewOrPopup(event_up); |
1478 } | 1491 } |
1479 | 1492 |
1480 void EventSender::EnableDOMUIEventLogging() {} | 1493 void EventSender::EnableDOMUIEventLogging() {} |
1481 | 1494 |
1482 void EventSender::FireKeyboardEventsToElement() {} | 1495 void EventSender::FireKeyboardEventsToElement() {} |
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2513 | 2526 |
2514 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { | 2527 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { |
2515 if (WebPagePopup* popup = view_->pagePopup()) { | 2528 if (WebPagePopup* popup = view_->pagePopup()) { |
2516 if (!WebInputEvent::isKeyboardEventType(event.type)) | 2529 if (!WebInputEvent::isKeyboardEventType(event.type)) |
2517 return popup->handleInputEvent(event); | 2530 return popup->handleInputEvent(event); |
2518 } | 2531 } |
2519 return view_->handleInputEvent(event); | 2532 return view_->handleInputEvent(event); |
2520 } | 2533 } |
2521 | 2534 |
2522 } // namespace content | 2535 } // namespace content |
OLD | NEW |