OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This file contains the definition for EventSendingController. | 5 // This file contains the definition for EventSendingController. |
6 // | 6 // |
7 // Some notes about drag and drop handling: | 7 // Some notes about drag and drop handling: |
8 // Windows drag and drop goes through a system call to DoDragDrop. At that | 8 // Windows drag and drop goes through a system call to DoDragDrop. At that |
9 // point, program control is given to Windows which then periodically makes | 9 // point, program control is given to Windows which then periodically makes |
10 // callbacks into the webview. This won't work for layout tests, so instead, | 10 // callbacks into the webview. This won't work for layout tests, so instead, |
(...skipping 11 matching lines...) Expand all Loading... |
22 // directly like this!! | 22 // directly like this!! |
23 #include "config.h" | 23 #include "config.h" |
24 #include "KeyboardCodes.h" | 24 #include "KeyboardCodes.h" |
25 | 25 |
26 #include "base/compiler_specific.h" | 26 #include "base/compiler_specific.h" |
27 #include "base/logging.h" | 27 #include "base/logging.h" |
28 #include "base/message_loop.h" | 28 #include "base/message_loop.h" |
29 #include "base/ref_counted.h" | 29 #include "base/ref_counted.h" |
30 #include "base/string_util.h" | 30 #include "base/string_util.h" |
31 #include "base/time.h" | 31 #include "base/time.h" |
| 32 #include "webkit/glue/webinputevent_util.h" |
32 #include "webkit/glue/webview.h" | 33 #include "webkit/glue/webview.h" |
33 #include "webkit/tools/test_shell/test_shell.h" | 34 #include "webkit/tools/test_shell/test_shell.h" |
34 | 35 |
35 // TODO(mpcomplete): layout before each event? | 36 // TODO(mpcomplete): layout before each event? |
36 // TODO(mpcomplete): do we need modifiers for mouse events? | 37 // TODO(mpcomplete): do we need modifiers for mouse events? |
37 | 38 |
38 using base::Time; | 39 using base::Time; |
39 using base::TimeTicks; | 40 using base::TimeTicks; |
40 | 41 |
41 TestShell* EventSendingController::shell_ = NULL; | 42 TestShell* EventSendingController::shell_ = NULL; |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 code = WebCore::VKEY_PRIOR; | 371 code = WebCore::VKEY_PRIOR; |
371 } else if (L"pageDown" == code_str) { | 372 } else if (L"pageDown" == code_str) { |
372 code = WebCore::VKEY_NEXT; | 373 code = WebCore::VKEY_NEXT; |
373 } else { | 374 } else { |
374 DCHECK(code_str.length() == 1); | 375 DCHECK(code_str.length() == 1); |
375 code = code_str[0]; | 376 code = code_str[0]; |
376 needs_shift_key_modifier = NeedsShiftModifer(code); | 377 needs_shift_key_modifier = NeedsShiftModifer(code); |
377 generate_char = true; | 378 generate_char = true; |
378 } | 379 } |
379 | 380 |
380 // NOTE(jnd):For one keydown event, we need to generate | 381 // For one generated keyboard event, we need to generate a keyDown/keyUp |
381 // keyDown/keyUp pair, refer EventSender.cpp in | 382 // pair; refer to EventSender.cpp in WebKit/WebKitTools/DumpRenderTree/win. |
382 // WebKit/WebKitTools/DumpRenderTree/win. We may also need | 383 // On Windows, we might also need to generate a char event to mimic the |
383 // to generate a keyChar event in certain cases. | 384 // Windows event flow; on other platforms we create a merged event and test |
| 385 // the event flow that that platform provides. |
384 WebKeyboardEvent event_down, event_up; | 386 WebKeyboardEvent event_down, event_up; |
| 387 #if defined(OS_WIN) |
| 388 event_down.type = WebInputEvent::RAW_KEY_DOWN; |
| 389 #else |
385 event_down.type = WebInputEvent::KEY_DOWN; | 390 event_down.type = WebInputEvent::KEY_DOWN; |
| 391 #endif |
386 event_down.modifiers = 0; | 392 event_down.modifiers = 0; |
387 event_down.key_code = code; | 393 event_down.windows_key_code = code; |
388 #if defined(OS_LINUX) | 394 event_down.text[0] = code; |
389 // TODO(deanm): This code is a confusing mix of different platform key | 395 event_down.unmodified_text[0] = code; |
390 // codes. Since we're not working with a GDK event, we can't use our | 396 std::string key_identifier_str = |
391 // GDK -> WebKit converter, which means the Linux specific extra |text| | 397 webkit_glue::GetKeyIdentifierForWindowsKeyCode(code); |
392 // field goes uninitialized. I don't know how to correctly calculate this | 398 |
393 // field, but for now we will at least initialize it, even if it's wrong. | 399 base::strlcpy(event_down.key_identifier, key_identifier_str.c_str(), |
394 event_down.text = code; | 400 kIdentifierLengthCap); |
395 #endif | |
396 | 401 |
397 if (args.size() >= 2 && (args[1].isObject() || args[1].isString())) | 402 if (args.size() >= 2 && (args[1].isObject() || args[1].isString())) |
398 ApplyKeyModifiers(&(args[1]), &event_down); | 403 ApplyKeyModifiers(&(args[1]), &event_down); |
399 | 404 |
400 if (needs_shift_key_modifier) | 405 if (needs_shift_key_modifier) |
401 event_down.modifiers |= WebInputEvent::SHIFT_KEY; | 406 event_down.modifiers |= WebInputEvent::SHIFT_KEY; |
402 | 407 |
403 event_up = event_down; | 408 event_up = event_down; |
404 event_up.type = WebInputEvent::KEY_UP; | 409 event_up.type = WebInputEvent::KEY_UP; |
405 // EventSendingController.m forces a layout here, with at least one | 410 // EventSendingController.m forces a layout here, with at least one |
406 // test (fast\forms\focus-control-to-page.html) relying on this. | 411 // test (fast\forms\focus-control-to-page.html) relying on this. |
407 webview()->Layout(); | 412 webview()->Layout(); |
408 | 413 |
409 webview()->HandleInputEvent(&event_down); | 414 webview()->HandleInputEvent(&event_down); |
410 | 415 |
| 416 #if defined(OS_WIN) |
411 if (generate_char) { | 417 if (generate_char) { |
412 WebKeyboardEvent event_char = event_down; | 418 WebKeyboardEvent event_char = event_down; |
413 event_char.type = WebInputEvent::CHAR; | 419 event_char.type = WebInputEvent::CHAR; |
| 420 event_char.key_identifier[0] = '\0'; |
414 webview()->HandleInputEvent(&event_char); | 421 webview()->HandleInputEvent(&event_char); |
415 } | 422 } |
| 423 #endif |
416 | 424 |
417 webview()->HandleInputEvent(&event_up); | 425 webview()->HandleInputEvent(&event_up); |
418 } | 426 } |
419 } | 427 } |
420 | 428 |
421 void EventSendingController::dispatchMessage( | 429 void EventSendingController::dispatchMessage( |
422 const CppArgumentList& args, CppVariant* result) { | 430 const CppArgumentList& args, CppVariant* result) { |
423 result->SetNull(); | 431 result->SetNull(); |
424 | 432 |
425 #if defined(OS_WIN) | 433 #if defined(OS_WIN) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 void EventSendingController::fireKeyboardEventsToElement( | 558 void EventSendingController::fireKeyboardEventsToElement( |
551 const CppArgumentList& args, CppVariant* result) { | 559 const CppArgumentList& args, CppVariant* result) { |
552 result->SetNull(); | 560 result->SetNull(); |
553 } | 561 } |
554 | 562 |
555 void EventSendingController::clearKillRing( | 563 void EventSendingController::clearKillRing( |
556 const CppArgumentList& args, CppVariant* result) { | 564 const CppArgumentList& args, CppVariant* result) { |
557 result->SetNull(); | 565 result->SetNull(); |
558 } | 566 } |
559 | 567 |
OLD | NEW |