| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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, |
| 11 // we queue up all the mouse move and mouse up events. When the test tries to | 11 // we queue up all the mouse move and mouse up events. When the test tries to |
| 12 // start a drag (by calling EvenSendingController::DoDragDrop), we take the | 12 // start a drag (by calling EvenSendingController::DoDragDrop), we take the |
| 13 // events in the queue and replay them. | 13 // events in the queue and replay them. |
| 14 // The behavior of queuing events and replaying them can be disabled by a | 14 // The behavior of queuing events and replaying them can be disabled by a |
| 15 // layout test by setting eventSender.dragMode to false. | 15 // layout test by setting eventSender.dragMode to false. |
| 16 | 16 |
| 17 #include "webkit/tools/test_shell/event_sending_controller.h" | 17 #include "webkit/tools/test_shell/event_sending_controller.h" |
| 18 | 18 |
| 19 #include <queue> | 19 #include <queue> |
| 20 #include <vector> | 20 #include <vector> |
| 21 | 21 |
| 22 #include "app/keyboard_codes.h" | |
| 23 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
| 24 #include "base/file_path.h" | 23 #include "base/file_path.h" |
| 25 #include "base/file_util.h" | 24 #include "base/file_util.h" |
| 26 #include "base/logging.h" | 25 #include "base/logging.h" |
| 27 #include "base/message_loop.h" | 26 #include "base/message_loop.h" |
| 28 #include "base/time.h" | 27 #include "base/time.h" |
| 29 #include "base/string_number_conversions.h" | 28 #include "base/string_number_conversions.h" |
| 30 #include "base/string_util.h" | 29 #include "base/string_util.h" |
| 31 #include "base/utf_string_conversions.h" | 30 #include "base/utf_string_conversions.h" |
| 32 #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" | 31 #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" |
| 33 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" | 32 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" |
| 34 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" | 33 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
| 35 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 34 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 36 #include "third_party/WebKit/WebKit/chromium/public/WebTouchPoint.h" | 35 #include "third_party/WebKit/WebKit/chromium/public/WebTouchPoint.h" |
| 37 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 36 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
| 38 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" | 37 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" |
| 38 #include "ui/base/keycodes/keyboard_codes.h" |
| 39 #include "webkit/glue/webkit_glue.h" | 39 #include "webkit/glue/webkit_glue.h" |
| 40 #include "webkit/tools/test_shell/test_shell.h" | 40 #include "webkit/tools/test_shell/test_shell.h" |
| 41 #include "webkit/tools/test_shell/test_webview_delegate.h" | 41 #include "webkit/tools/test_shell/test_webview_delegate.h" |
| 42 | 42 |
| 43 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
| 44 #include "third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h" | 44 #include "third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h" |
| 45 using WebKit::WebInputEventFactory; | 45 using WebKit::WebInputEventFactory; |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 // TODO(mpcomplete): layout before each event? | 48 // TODO(mpcomplete): layout before each event? |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // modifiers. These key events correspond to some special movement and | 208 // modifiers. These key events correspond to some special movement and |
| 209 // selection editor commands, and was supposed to be handled in | 209 // selection editor commands, and was supposed to be handled in |
| 210 // third_party/WebKit/WebKit/chromium/src/EditorClientImpl.cpp. But these keys | 210 // third_party/WebKit/WebKit/chromium/src/EditorClientImpl.cpp. But these keys |
| 211 // will be marked as system key, which prevents them from being handled. | 211 // will be marked as system key, which prevents them from being handled. |
| 212 // Thus they must be handled specially. | 212 // Thus they must be handled specially. |
| 213 if ((event.modifiers & ~WebKeyboardEvent::ShiftKey) != | 213 if ((event.modifiers & ~WebKeyboardEvent::ShiftKey) != |
| 214 WebKeyboardEvent::MetaKey) | 214 WebKeyboardEvent::MetaKey) |
| 215 return false; | 215 return false; |
| 216 | 216 |
| 217 switch (event.windowsKeyCode) { | 217 switch (event.windowsKeyCode) { |
| 218 case app::VKEY_LEFT: | 218 case ui::VKEY_LEFT: |
| 219 *name = "MoveToBeginningOfLine"; | 219 *name = "MoveToBeginningOfLine"; |
| 220 break; | 220 break; |
| 221 case app::VKEY_RIGHT: | 221 case ui::VKEY_RIGHT: |
| 222 *name = "MoveToEndOfLine"; | 222 *name = "MoveToEndOfLine"; |
| 223 break; | 223 break; |
| 224 case app::VKEY_UP: | 224 case ui::VKEY_UP: |
| 225 *name = "MoveToBeginningOfDocument"; | 225 *name = "MoveToBeginningOfDocument"; |
| 226 break; | 226 break; |
| 227 case app::VKEY_DOWN: | 227 case ui::VKEY_DOWN: |
| 228 *name = "MoveToEndOfDocument"; | 228 *name = "MoveToEndOfDocument"; |
| 229 break; | 229 break; |
| 230 default: | 230 default: |
| 231 return false; | 231 return false; |
| 232 } | 232 } |
| 233 | 233 |
| 234 if (event.modifiers & WebKeyboardEvent::ShiftKey) | 234 if (event.modifiers & WebKeyboardEvent::ShiftKey) |
| 235 name->append("AndModifySelection"); | 235 name->append("AndModifySelection"); |
| 236 | 236 |
| 237 return true; | 237 return true; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 // TODO(mpcomplete): Should we also generate a KEY_UP? | 528 // TODO(mpcomplete): Should we also generate a KEY_UP? |
| 529 std::wstring code_str = UTF8ToWide(args[0].ToString()); | 529 std::wstring code_str = UTF8ToWide(args[0].ToString()); |
| 530 | 530 |
| 531 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when | 531 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when |
| 532 // Windows uses \r for "Enter". | 532 // Windows uses \r for "Enter". |
| 533 int code = 0; | 533 int code = 0; |
| 534 int text = 0; | 534 int text = 0; |
| 535 bool needs_shift_key_modifier = false; | 535 bool needs_shift_key_modifier = false; |
| 536 if (L"\n" == code_str) { | 536 if (L"\n" == code_str) { |
| 537 generate_char = true; | 537 generate_char = true; |
| 538 text = code = app::VKEY_RETURN; | 538 text = code = ui::VKEY_RETURN; |
| 539 } else if (L"rightArrow" == code_str) { | 539 } else if (L"rightArrow" == code_str) { |
| 540 code = app::VKEY_RIGHT; | 540 code = ui::VKEY_RIGHT; |
| 541 } else if (L"downArrow" == code_str) { | 541 } else if (L"downArrow" == code_str) { |
| 542 code = app::VKEY_DOWN; | 542 code = ui::VKEY_DOWN; |
| 543 } else if (L"leftArrow" == code_str) { | 543 } else if (L"leftArrow" == code_str) { |
| 544 code = app::VKEY_LEFT; | 544 code = ui::VKEY_LEFT; |
| 545 } else if (L"upArrow" == code_str) { | 545 } else if (L"upArrow" == code_str) { |
| 546 code = app::VKEY_UP; | 546 code = ui::VKEY_UP; |
| 547 } else if (L"insert" == code_str) { | 547 } else if (L"insert" == code_str) { |
| 548 code = app::VKEY_INSERT; | 548 code = ui::VKEY_INSERT; |
| 549 } else if (L"delete" == code_str) { | 549 } else if (L"delete" == code_str) { |
| 550 code = app::VKEY_DELETE; | 550 code = ui::VKEY_DELETE; |
| 551 } else if (L"pageUp" == code_str) { | 551 } else if (L"pageUp" == code_str) { |
| 552 code = app::VKEY_PRIOR; | 552 code = ui::VKEY_PRIOR; |
| 553 } else if (L"pageDown" == code_str) { | 553 } else if (L"pageDown" == code_str) { |
| 554 code = app::VKEY_NEXT; | 554 code = ui::VKEY_NEXT; |
| 555 } else if (L"home" == code_str) { | 555 } else if (L"home" == code_str) { |
| 556 code = app::VKEY_HOME; | 556 code = ui::VKEY_HOME; |
| 557 } else if (L"end" == code_str) { | 557 } else if (L"end" == code_str) { |
| 558 code = app::VKEY_END; | 558 code = ui::VKEY_END; |
| 559 } else if (L"printScreen" == code_str) { | 559 } else if (L"printScreen" == code_str) { |
| 560 code = app::VKEY_SNAPSHOT; | 560 code = ui::VKEY_SNAPSHOT; |
| 561 } else { | 561 } else { |
| 562 // Compare the input string with the function-key names defined by the | 562 // Compare the input string with the function-key names defined by the |
| 563 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key | 563 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key |
| 564 // name, set its key code. | 564 // name, set its key code. |
| 565 for (int i = 1; i <= 24; ++i) { | 565 for (int i = 1; i <= 24; ++i) { |
| 566 std::wstring function_key_name; | 566 std::wstring function_key_name; |
| 567 function_key_name += L"F"; | 567 function_key_name += L"F"; |
| 568 function_key_name += UTF8ToWide(base::IntToString(i)); | 568 function_key_name += UTF8ToWide(base::IntToString(i)); |
| 569 if (function_key_name == code_str) { | 569 if (function_key_name == code_str) { |
| 570 code = app::VKEY_F1 + (i - 1); | 570 code = ui::VKEY_F1 + (i - 1); |
| 571 break; | 571 break; |
| 572 } | 572 } |
| 573 } | 573 } |
| 574 if (!code) { | 574 if (!code) { |
| 575 DCHECK(code_str.length() == 1); | 575 DCHECK(code_str.length() == 1); |
| 576 text = code = code_str[0]; | 576 text = code = code_str[0]; |
| 577 needs_shift_key_modifier = NeedsShiftModifier(code); | 577 needs_shift_key_modifier = NeedsShiftModifier(code); |
| 578 if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') | 578 if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') |
| 579 code -= 'a' - 'A'; | 579 code -= 'a' - 'A'; |
| 580 generate_char = true; | 580 generate_char = true; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 // changing the count based on flags also makes sense. This function | 776 // changing the count based on flags also makes sense. This function |
| 777 // is doing such for some flags. | 777 // is doing such for some flags. |
| 778 // - Some test even checks actual string content. So providing it | 778 // - Some test even checks actual string content. So providing it |
| 779 // would be also helpful. | 779 // would be also helpful. |
| 780 static std::vector<WebString> | 780 static std::vector<WebString> |
| 781 MakeMenuItemStringsFor(const WebKit::WebContextMenuData* context_menu, | 781 MakeMenuItemStringsFor(const WebKit::WebContextMenuData* context_menu, |
| 782 MockSpellCheck* spellcheck) { | 782 MockSpellCheck* spellcheck) { |
| 783 // These constants are based on Safari's context menu because tests | 783 // These constants are based on Safari's context menu because tests |
| 784 // are made for it. | 784 // are made for it. |
| 785 static const char* kNonEditableMenuStrings[] = { | 785 static const char* kNonEditableMenuStrings[] = { |
| 786 "Back", "Reload Page", "Open in Dashbaord", "<separator>", | 786 "Back", "Reload Page", "Open in Dashbaord", "<separator>", |
| 787 "View Source", "Save Page As", "Print Page", "Inspect Element", | 787 "View Source", "Save Page As", "Print Page", "Inspect Element", |
| 788 0 }; | 788 0 }; |
| 789 static const char* kEditableMenuStrings[] = { | 789 static const char* kEditableMenuStrings[] = { |
| 790 "Cut", "Copy", "<separator>", "Paste", "Spelling and Grammar", | 790 "Cut", "Copy", "<separator>", "Paste", "Spelling and Grammar", |
| 791 "Substitutions, Transformations", "Font", "Speech", | 791 "Substitutions, Transformations", "Font", "Speech", |
| 792 "Paragraph Direction", "<separator>", 0 }; | 792 "Paragraph Direction", "<separator>", 0 }; |
| 793 | 793 |
| 794 // This is possible because mouse events are cancelleable. | 794 // This is possible because mouse events are cancelleable. |
| 795 if (!context_menu) | 795 if (!context_menu) |
| 796 return std::vector<WebString>(); | 796 return std::vector<WebString>(); |
| 797 | 797 |
| 798 std::vector<WebString> strings; | 798 std::vector<WebString> strings; |
| 799 | 799 |
| 800 if (context_menu->isEditable) { | 800 if (context_menu->isEditable) { |
| 801 for (const char** item = kEditableMenuStrings; *item; ++item) | 801 for (const char** item = kEditableMenuStrings; *item; ++item) |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 | 1070 |
| 1071 void EventSendingController::fireKeyboardEventsToElement( | 1071 void EventSendingController::fireKeyboardEventsToElement( |
| 1072 const CppArgumentList& args, CppVariant* result) { | 1072 const CppArgumentList& args, CppVariant* result) { |
| 1073 result->SetNull(); | 1073 result->SetNull(); |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 void EventSendingController::clearKillRing( | 1076 void EventSendingController::clearKillRing( |
| 1077 const CppArgumentList& args, CppVariant* result) { | 1077 const CppArgumentList& args, CppVariant* result) { |
| 1078 result->SetNull(); | 1078 result->SetNull(); |
| 1079 } | 1079 } |
| OLD | NEW |