OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 bindMethod("gestureTap", &EventSender::gestureTap); | 297 bindMethod("gestureTap", &EventSender::gestureTap); |
298 bindMethod("gestureTapDown", &EventSender::gestureTapDown); | 298 bindMethod("gestureTapDown", &EventSender::gestureTapDown); |
299 bindMethod("gestureTapCancel", &EventSender::gestureTapCancel); | 299 bindMethod("gestureTapCancel", &EventSender::gestureTapCancel); |
300 bindMethod("gestureLongPress", &EventSender::gestureLongPress); | 300 bindMethod("gestureLongPress", &EventSender::gestureLongPress); |
301 bindMethod("gestureLongTap", &EventSender::gestureLongTap); | 301 bindMethod("gestureLongTap", &EventSender::gestureLongTap); |
302 bindMethod("gestureTwoFingerTap", &EventSender::gestureTwoFingerTap); | 302 bindMethod("gestureTwoFingerTap", &EventSender::gestureTwoFingerTap); |
303 bindMethod("zoomPageIn", &EventSender::zoomPageIn); | 303 bindMethod("zoomPageIn", &EventSender::zoomPageIn); |
304 bindMethod("zoomPageOut", &EventSender::zoomPageOut); | 304 bindMethod("zoomPageOut", &EventSender::zoomPageOut); |
305 bindMethod("scalePageBy", &EventSender::scalePageBy); | 305 bindMethod("scalePageBy", &EventSender::scalePageBy); |
306 | 306 |
307 bindProperty("forceLayoutOnEvents", &forceLayoutOnEvents); | |
308 | |
307 // When set to true (the default value), we batch mouse move and mouse up | 309 // When set to true (the default value), we batch mouse move and mouse up |
308 // events so we can simulate drag & drop. | 310 // events so we can simulate drag & drop. |
309 bindProperty("dragMode", &dragMode); | 311 bindProperty("dragMode", &dragMode); |
310 #ifdef WIN32 | 312 #ifdef WIN32 |
311 bindProperty("WM_KEYDOWN", &wmKeyDown); | 313 bindProperty("WM_KEYDOWN", &wmKeyDown); |
312 bindProperty("WM_KEYUP", &wmKeyUp); | 314 bindProperty("WM_KEYUP", &wmKeyUp); |
313 bindProperty("WM_CHAR", &wmChar); | 315 bindProperty("WM_CHAR", &wmChar); |
314 bindProperty("WM_DEADCHAR", &wmDeadChar); | 316 bindProperty("WM_DEADCHAR", &wmDeadChar); |
315 bindProperty("WM_SYSKEYDOWN", &wmSysKeyDown); | 317 bindProperty("WM_SYSKEYDOWN", &wmSysKeyDown); |
316 bindProperty("WM_SYSKEYUP", &wmSysKeyUp); | 318 bindProperty("WM_SYSKEYUP", &wmSysKeyUp); |
(...skipping 13 matching lines...) Expand all Loading... | |
330 | 332 |
331 void EventSender::reset() | 333 void EventSender::reset() |
332 { | 334 { |
333 // The test should have finished a drag and the mouse button state. | 335 // The test should have finished a drag and the mouse button state. |
334 WEBKIT_ASSERT(currentDragData.isNull()); | 336 WEBKIT_ASSERT(currentDragData.isNull()); |
335 currentDragData.reset(); | 337 currentDragData.reset(); |
336 currentDragEffect = WebKit::WebDragOperationNone; | 338 currentDragEffect = WebKit::WebDragOperationNone; |
337 currentDragEffectsAllowed = WebKit::WebDragOperationNone; | 339 currentDragEffectsAllowed = WebKit::WebDragOperationNone; |
338 pressedButton = WebMouseEvent::ButtonNone; | 340 pressedButton = WebMouseEvent::ButtonNone; |
339 dragMode.set(true); | 341 dragMode.set(true); |
342 forceLayoutOnEvents.set(false); | |
340 #ifdef WIN32 | 343 #ifdef WIN32 |
341 wmKeyDown.set(WM_KEYDOWN); | 344 wmKeyDown.set(WM_KEYDOWN); |
342 wmKeyUp.set(WM_KEYUP); | 345 wmKeyUp.set(WM_KEYUP); |
343 wmChar.set(WM_CHAR); | 346 wmChar.set(WM_CHAR); |
344 wmDeadChar.set(WM_DEADCHAR); | 347 wmDeadChar.set(WM_DEADCHAR); |
345 wmSysKeyDown.set(WM_SYSKEYDOWN); | 348 wmSysKeyDown.set(WM_SYSKEYDOWN); |
346 wmSysKeyUp.set(WM_SYSKEYUP); | 349 wmSysKeyUp.set(WM_SYSKEYUP); |
347 wmSysChar.set(WM_SYSCHAR); | 350 wmSysChar.set(WM_SYSCHAR); |
348 wmSysDeadChar.set(WM_SYSDEADCHAR); | 351 wmSysDeadChar.set(WM_SYSDEADCHAR); |
349 #endif | 352 #endif |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 | 420 |
418 // | 421 // |
419 // Implemented javascript methods. | 422 // Implemented javascript methods. |
420 // | 423 // |
421 | 424 |
422 void EventSender::mouseDown(const CppArgumentList& arguments, CppVariant* result ) | 425 void EventSender::mouseDown(const CppArgumentList& arguments, CppVariant* result ) |
423 { | 426 { |
424 if (result) // Could be 0 if invoked asynchronously. | 427 if (result) // Could be 0 if invoked asynchronously. |
425 result->setNull(); | 428 result->setNull(); |
426 | 429 |
430 if (shouldForceLayoutOnEvents()) | |
431 webview()->layout(); | |
ojan
2013/05/21 02:12:38
Nit: Could move this into a helper function, Event
| |
432 | |
427 int buttonNumber = getButtonNumberFromSingleArg(arguments); | 433 int buttonNumber = getButtonNumberFromSingleArg(arguments); |
428 WEBKIT_ASSERT(buttonNumber != -1); | 434 WEBKIT_ASSERT(buttonNumber != -1); |
429 | 435 |
430 WebMouseEvent::Button buttonType = getButtonTypeFromButtonNumber(buttonNumbe r); | 436 WebMouseEvent::Button buttonType = getButtonTypeFromButtonNumber(buttonNumbe r); |
431 | 437 |
432 updateClickCountForButton(buttonType); | 438 updateClickCountForButton(buttonType); |
433 | 439 |
434 WebMouseEvent event; | 440 WebMouseEvent event; |
435 pressedButton = buttonType; | 441 pressedButton = buttonType; |
436 initMouseEvent(WebInputEvent::MouseDown, buttonType, lastMousePos, &event, g etCurrentEventTimeSec(m_delegate)); | 442 initMouseEvent(WebInputEvent::MouseDown, buttonType, lastMousePos, &event, g etCurrentEventTimeSec(m_delegate)); |
437 if (arguments.size() >= 2 && (arguments[1].isObject() || arguments[1].isStri ng())) | 443 if (arguments.size() >= 2 && (arguments[1].isObject() || arguments[1].isStri ng())) |
438 applyKeyModifiers(&(arguments[1]), &event); | 444 applyKeyModifiers(&(arguments[1]), &event); |
439 webview()->handleInputEvent(event); | 445 webview()->handleInputEvent(event); |
440 } | 446 } |
441 | 447 |
442 void EventSender::mouseUp(const CppArgumentList& arguments, CppVariant* result) | 448 void EventSender::mouseUp(const CppArgumentList& arguments, CppVariant* result) |
443 { | 449 { |
444 if (result) // Could be 0 if invoked asynchronously. | 450 if (result) // Could be 0 if invoked asynchronously. |
445 result->setNull(); | 451 result->setNull(); |
446 | 452 |
453 if (shouldForceLayoutOnEvents()) | |
454 webview()->layout(); | |
455 | |
447 int buttonNumber = getButtonNumberFromSingleArg(arguments); | 456 int buttonNumber = getButtonNumberFromSingleArg(arguments); |
448 WEBKIT_ASSERT(buttonNumber != -1); | 457 WEBKIT_ASSERT(buttonNumber != -1); |
449 | 458 |
450 WebMouseEvent::Button buttonType = getButtonTypeFromButtonNumber(buttonNumbe r); | 459 WebMouseEvent::Button buttonType = getButtonTypeFromButtonNumber(buttonNumbe r); |
451 | 460 |
452 if (isDragMode() && !replayingSavedEvents) { | 461 if (isDragMode() && !replayingSavedEvents) { |
453 SavedEvent savedEvent; | 462 SavedEvent savedEvent; |
454 savedEvent.type = SavedEvent::MouseUp; | 463 savedEvent.type = SavedEvent::MouseUp; |
455 savedEvent.buttonType = buttonType; | 464 savedEvent.buttonType = buttonType; |
456 mouseEventQueue.push_back(savedEvent); | 465 mouseEventQueue.push_back(savedEvent); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 | 504 |
496 currentDragData.reset(); | 505 currentDragData.reset(); |
497 } | 506 } |
498 | 507 |
499 void EventSender::mouseMoveTo(const CppArgumentList& arguments, CppVariant* resu lt) | 508 void EventSender::mouseMoveTo(const CppArgumentList& arguments, CppVariant* resu lt) |
500 { | 509 { |
501 result->setNull(); | 510 result->setNull(); |
502 | 511 |
503 if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isNumb er()) | 512 if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isNumb er()) |
504 return; | 513 return; |
514 if (shouldForceLayoutOnEvents()) | |
515 webview()->layout(); | |
505 | 516 |
506 WebPoint mousePos(arguments[0].toInt32(), arguments[1].toInt32()); | 517 WebPoint mousePos(arguments[0].toInt32(), arguments[1].toInt32()); |
507 | 518 |
508 if (isDragMode() && pressedButton == WebMouseEvent::ButtonLeft && !replaying SavedEvents) { | 519 if (isDragMode() && pressedButton == WebMouseEvent::ButtonLeft && !replaying SavedEvents) { |
509 SavedEvent savedEvent; | 520 SavedEvent savedEvent; |
510 savedEvent.type = SavedEvent::MouseMove; | 521 savedEvent.type = SavedEvent::MouseMove; |
511 savedEvent.pos = mousePos; | 522 savedEvent.pos = mousePos; |
512 mouseEventQueue.push_back(savedEvent); | 523 mouseEventQueue.push_back(savedEvent); |
513 } else { | 524 } else { |
514 WebMouseEvent event; | 525 WebMouseEvent event; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
647 if (arguments.size() >= 3 && arguments[2].isNumber()) { | 658 if (arguments.size() >= 3 && arguments[2].isNumber()) { |
648 int location = arguments[2].toInt32(); | 659 int location = arguments[2].toInt32(); |
649 if (location == DOMKeyLocationNumpad) | 660 if (location == DOMKeyLocationNumpad) |
650 eventDown.modifiers |= WebInputEvent::IsKeyPad; | 661 eventDown.modifiers |= WebInputEvent::IsKeyPad; |
651 } | 662 } |
652 | 663 |
653 eventChar = eventUp = eventDown; | 664 eventChar = eventUp = eventDown; |
654 eventUp.type = WebInputEvent::KeyUp; | 665 eventUp.type = WebInputEvent::KeyUp; |
655 // EventSender.m forces a layout here, with at least one | 666 // EventSender.m forces a layout here, with at least one |
656 // test (fast/forms/focus-control-to-page.html) relying on this. | 667 // test (fast/forms/focus-control-to-page.html) relying on this. |
657 webview()->layout(); | 668 if (shouldForceLayoutOnEvents()) |
669 webview()->layout(); | |
658 | 670 |
659 // In the browser, if a keyboard event corresponds to an editor command, | 671 // In the browser, if a keyboard event corresponds to an editor command, |
660 // the command will be dispatched to the renderer just before dispatching | 672 // the command will be dispatched to the renderer just before dispatching |
661 // the keyboard event, and then it will be executed in the | 673 // the keyboard event, and then it will be executed in the |
662 // RenderView::handleCurrentKeyboardEvent() method, which is called from | 674 // RenderView::handleCurrentKeyboardEvent() method, which is called from |
663 // third_party/WebKit/Source/WebKit/chromium/src/EditorClientImpl.cpp. | 675 // third_party/WebKit/Source/WebKit/chromium/src/EditorClientImpl.cpp. |
664 // We just simulate the same behavior here. | 676 // We just simulate the same behavior here. |
665 string editCommand; | 677 string editCommand; |
666 if (getEditCommand(eventDown, &editCommand)) | 678 if (getEditCommand(eventDown, &editCommand)) |
667 m_delegate->setEditCommand(editCommand, ""); | 679 m_delegate->setEditCommand(editCommand, ""); |
(...skipping 25 matching lines...) Expand all Loading... | |
693 if (arguments.size() == 3) { | 705 if (arguments.size() == 3) { |
694 // Grab the message id to see if we need to dispatch it. | 706 // Grab the message id to see if we need to dispatch it. |
695 int msg = arguments[0].toInt32(); | 707 int msg = arguments[0].toInt32(); |
696 | 708 |
697 // WebKit's version of this function stuffs a MSG struct and uses | 709 // WebKit's version of this function stuffs a MSG struct and uses |
698 // TranslateMessage and DispatchMessage. We use a WebKeyboardEvent, whic h | 710 // TranslateMessage and DispatchMessage. We use a WebKeyboardEvent, whic h |
699 // doesn't need to receive the DeadChar and SysDeadChar messages. | 711 // doesn't need to receive the DeadChar and SysDeadChar messages. |
700 if (msg == WM_DEADCHAR || msg == WM_SYSDEADCHAR) | 712 if (msg == WM_DEADCHAR || msg == WM_SYSDEADCHAR) |
701 return; | 713 return; |
702 | 714 |
703 webview()->layout(); | 715 if (shouldForceLayoutOnEvents()) |
716 webview()->layout(); | |
704 | 717 |
705 unsigned long lparam = static_cast<unsigned long>(arguments[2].toDouble( )); | 718 unsigned long lparam = static_cast<unsigned long>(arguments[2].toDouble( )); |
706 webview()->handleInputEvent(WebInputEventFactory::keyboardEvent(0, msg, arguments[1].toInt32(), lparam)); | 719 webview()->handleInputEvent(WebInputEventFactory::keyboardEvent(0, msg, arguments[1].toInt32(), lparam)); |
707 } else | 720 } else |
708 WEBKIT_ASSERT_NOT_REACHED(); | 721 WEBKIT_ASSERT_NOT_REACHED(); |
709 #endif | 722 #endif |
710 } | 723 } |
711 | 724 |
712 bool EventSender::needsShiftModifier(int keyCode) | 725 bool EventSender::needsShiftModifier(int keyCode) |
713 { | 726 { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 } else { | 860 } else { |
848 for (const char** item = nonEditableMenuStrings; *item; ++item) | 861 for (const char** item = nonEditableMenuStrings; *item; ++item) |
849 strings.push_back(WebString::fromUTF8(*item)); | 862 strings.push_back(WebString::fromUTF8(*item)); |
850 } | 863 } |
851 | 864 |
852 return strings; | 865 return strings; |
853 } | 866 } |
854 | 867 |
855 void EventSender::contextClick(const CppArgumentList& arguments, CppVariant* res ult) | 868 void EventSender::contextClick(const CppArgumentList& arguments, CppVariant* res ult) |
856 { | 869 { |
857 webview()->layout(); | 870 if (shouldForceLayoutOnEvents()) |
871 webview()->layout(); | |
858 | 872 |
859 updateClickCountForButton(WebMouseEvent::ButtonRight); | 873 updateClickCountForButton(WebMouseEvent::ButtonRight); |
860 | 874 |
861 // Clears last context menu data because we need to know if the context menu be requested | 875 // Clears last context menu data because we need to know if the context menu be requested |
862 // after following mouse events. | 876 // after following mouse events. |
863 m_lastContextMenuData.reset(); | 877 m_lastContextMenuData.reset(); |
864 | 878 |
865 // Generate right mouse down and up. | 879 // Generate right mouse down and up. |
866 WebMouseEvent event; | 880 WebMouseEvent event; |
867 // This is a hack to work around only allowing a single pressed button since we want to | 881 // This is a hack to work around only allowing a single pressed button since we want to |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 const unsigned index = arguments[0].toInt32(); | 1042 const unsigned index = arguments[0].toInt32(); |
1029 WEBKIT_ASSERT(index < touchPoints.size()); | 1043 WEBKIT_ASSERT(index < touchPoints.size()); |
1030 | 1044 |
1031 WebTouchPoint* touchPoint = &touchPoints[index]; | 1045 WebTouchPoint* touchPoint = &touchPoints[index]; |
1032 touchPoint->state = WebTouchPoint::StateCancelled; | 1046 touchPoint->state = WebTouchPoint::StateCancelled; |
1033 } | 1047 } |
1034 | 1048 |
1035 void EventSender::sendCurrentTouchEvent(const WebInputEvent::Type type) | 1049 void EventSender::sendCurrentTouchEvent(const WebInputEvent::Type type) |
1036 { | 1050 { |
1037 WEBKIT_ASSERT(static_cast<unsigned>(WebTouchEvent::touchesLengthCap) > touch Points.size()); | 1051 WEBKIT_ASSERT(static_cast<unsigned>(WebTouchEvent::touchesLengthCap) > touch Points.size()); |
1038 webview()->layout(); | 1052 if (shouldForceLayoutOnEvents()) |
1053 webview()->layout(); | |
1039 | 1054 |
1040 WebTouchEvent touchEvent; | 1055 WebTouchEvent touchEvent; |
1041 touchEvent.type = type; | 1056 touchEvent.type = type; |
1042 touchEvent.modifiers = touchModifiers; | 1057 touchEvent.modifiers = touchModifiers; |
1043 touchEvent.timeStampSeconds = getCurrentEventTimeSec(m_delegate); | 1058 touchEvent.timeStampSeconds = getCurrentEventTimeSec(m_delegate); |
1044 touchEvent.touchesLength = touchPoints.size(); | 1059 touchEvent.touchesLength = touchPoints.size(); |
1045 for (unsigned i = 0; i < touchPoints.size(); ++i) | 1060 for (unsigned i = 0; i < touchPoints.size(); ++i) |
1046 touchEvent.touches[i] = touchPoints[i]; | 1061 touchEvent.touches[i] = touchPoints[i]; |
1047 webview()->handleInputEvent(touchEvent); | 1062 webview()->handleInputEvent(touchEvent); |
1048 | 1063 |
(...skipping 16 matching lines...) Expand all Loading... | |
1065 webview()->handleInputEvent(event); | 1080 webview()->handleInputEvent(event); |
1066 } | 1081 } |
1067 | 1082 |
1068 void EventSender::handleMouseWheel(const CppArgumentList& arguments, CppVariant* result, bool continuous) | 1083 void EventSender::handleMouseWheel(const CppArgumentList& arguments, CppVariant* result, bool continuous) |
1069 { | 1084 { |
1070 result->setNull(); | 1085 result->setNull(); |
1071 | 1086 |
1072 if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isNumb er()) | 1087 if (arguments.size() < 2 || !arguments[0].isNumber() || !arguments[1].isNumb er()) |
1073 return; | 1088 return; |
1074 | 1089 |
1090 // Force a layout here just to make sure every position has been | |
1091 // determined before we send events (as well as all the other methods | |
1092 // that send an event do). | |
1093 if (shouldForceLayoutOnEvents()) | |
1094 webview()->layout(); | |
1095 | |
1075 int horizontal = arguments[0].toInt32(); | 1096 int horizontal = arguments[0].toInt32(); |
1076 int vertical = arguments[1].toInt32(); | 1097 int vertical = arguments[1].toInt32(); |
1077 int paged = false; | 1098 int paged = false; |
1078 int hasPreciseScrollingDeltas = false; | 1099 int hasPreciseScrollingDeltas = false; |
1079 | 1100 |
1080 if (arguments.size() > 2 && arguments[2].isBool()) | 1101 if (arguments.size() > 2 && arguments[2].isBool()) |
1081 paged = arguments[2].toBoolean(); | 1102 paged = arguments[2].toBoolean(); |
1082 | 1103 |
1083 if (arguments.size() > 3 && arguments[3].isBool()) | 1104 if (arguments.size() > 3 && arguments[3].isBool()) |
1084 hasPreciseScrollingDeltas = arguments[3].toBoolean(); | 1105 hasPreciseScrollingDeltas = arguments[3].toBoolean(); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1342 { | 1363 { |
1343 result->setNull(); | 1364 result->setNull(); |
1344 } | 1365 } |
1345 | 1366 |
1346 void EventSender::clearKillRing(const CppArgumentList&, CppVariant* result) | 1367 void EventSender::clearKillRing(const CppArgumentList&, CppVariant* result) |
1347 { | 1368 { |
1348 result->setNull(); | 1369 result->setNull(); |
1349 } | 1370 } |
1350 | 1371 |
1351 } | 1372 } |
OLD | NEW |