| 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 "components/test_runner/event_sender.h" | 5 #include "components/test_runner/event_sender.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 weak_factory_.InvalidateWeakPtrs(); | 1322 weak_factory_.InvalidateWeakPtrs(); |
| 1323 current_gesture_location_ = WebPoint(0, 0); | 1323 current_gesture_location_ = WebPoint(0, 0); |
| 1324 mouse_event_queue_.clear(); | 1324 mouse_event_queue_.clear(); |
| 1325 | 1325 |
| 1326 time_offset_ms_ = 0; | 1326 time_offset_ms_ = 0; |
| 1327 click_count_ = 0; | 1327 click_count_ = 0; |
| 1328 | 1328 |
| 1329 touch_modifiers_ = 0; | 1329 touch_modifiers_ = 0; |
| 1330 touch_cancelable_ = true; | 1330 touch_cancelable_ = true; |
| 1331 touch_points_.clear(); | 1331 touch_points_.clear(); |
| 1332 |
| 1333 if (delegate()) |
| 1334 delegate()->SetMockMonotonicTimeFunction(base::Callback<double()>()); |
| 1332 } | 1335 } |
| 1333 | 1336 |
| 1334 void EventSender::Install(WebLocalFrame* frame) { | 1337 void EventSender::Install(WebLocalFrame* frame) { |
| 1338 delegate()->SetMockMonotonicTimeFunction( |
| 1339 base::Bind(&EventSender::GetMockTimeSeconds, base::Unretained(this))); |
| 1335 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame); | 1340 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame); |
| 1336 } | 1341 } |
| 1337 | 1342 |
| 1338 void EventSender::SetContextMenuData(const WebContextMenuData& data) { | 1343 void EventSender::SetContextMenuData(const WebContextMenuData& data) { |
| 1339 last_context_menu_data_.reset(new WebContextMenuData(data)); | 1344 last_context_menu_data_.reset(new WebContextMenuData(data)); |
| 1340 } | 1345 } |
| 1341 | 1346 |
| 1342 void EventSender::DoDragDrop(const WebDragData& drag_data, | 1347 void EventSender::DoDragDrop(const WebDragData& drag_data, |
| 1343 WebDragOperationsMask mask) { | 1348 WebDragOperationsMask mask) { |
| 1344 WebMouseEvent unscaled_event; | 1349 WebMouseEvent unscaled_event; |
| 1345 InitMouseEvent(WebInputEvent::MouseDown, | 1350 InitMouseEvent(WebInputEvent::MouseDown, |
| 1346 current_pointer_state_[kRawMousePointerId].pressed_button_, | 1351 current_pointer_state_[kRawMousePointerId].pressed_button_, |
| 1347 current_pointer_state_[kRawMousePointerId].current_buttons_, | 1352 current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 1348 current_pointer_state_[kRawMousePointerId].last_pos_, | 1353 current_pointer_state_[kRawMousePointerId].last_pos_, |
| 1349 GetCurrentEventTimeSec(), click_count_, | 1354 GetMockTimeSeconds(), click_count_, |
| 1350 current_pointer_state_[kRawMousePointerId].modifiers_, | 1355 current_pointer_state_[kRawMousePointerId].modifiers_, |
| 1351 &unscaled_event); | 1356 &unscaled_event); |
| 1352 | 1357 |
| 1353 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); | 1358 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); |
| 1354 const WebMouseEvent* event = | 1359 const WebMouseEvent* event = |
| 1355 scaled_event.get() ? static_cast<WebMouseEvent*>(scaled_event.get()) | 1360 scaled_event.get() ? static_cast<WebMouseEvent*>(scaled_event.get()) |
| 1356 : &unscaled_event; | 1361 : &unscaled_event; |
| 1357 | 1362 |
| 1358 WebPoint client_point(event->x, event->y); | 1363 WebPoint client_point(event->x, event->y); |
| 1359 WebPoint screen_point(event->globalX, event->globalY); | 1364 WebPoint screen_point(event->globalX, event->globalY); |
| 1365 |
| 1360 current_drag_data_ = drag_data; | 1366 current_drag_data_ = drag_data; |
| 1361 current_drag_effects_allowed_ = mask; | 1367 current_drag_effects_allowed_ = mask; |
| 1362 current_drag_effect_ = view()->dragTargetDragEnter( | 1368 current_drag_effect_ = view()->dragTargetDragEnter( |
| 1363 drag_data, client_point, screen_point, current_drag_effects_allowed_, | 1369 drag_data, client_point, screen_point, current_drag_effects_allowed_, |
| 1364 modifiersWithButtons( | 1370 modifiersWithButtons( |
| 1365 current_pointer_state_[kRawMousePointerId].modifiers_, | 1371 current_pointer_state_[kRawMousePointerId].modifiers_, |
| 1366 current_pointer_state_[kRawMousePointerId].current_buttons_)); | 1372 current_pointer_state_[kRawMousePointerId].current_buttons_)); |
| 1367 | 1373 |
| 1368 // Finish processing events. | 1374 // Finish processing events. |
| 1369 ReplaySavedEvents(); | 1375 ReplaySavedEvents(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 current_pointer_state_[pointerId].modifiers_ = modifiers; | 1409 current_pointer_state_[pointerId].modifiers_ = modifiers; |
| 1404 | 1410 |
| 1405 if (pointerType == WebPointerProperties::PointerType::Mouse) { | 1411 if (pointerType == WebPointerProperties::PointerType::Mouse) { |
| 1406 UpdateClickCountForButton(button_type); | 1412 UpdateClickCountForButton(button_type); |
| 1407 click_count = click_count_; | 1413 click_count = click_count_; |
| 1408 } | 1414 } |
| 1409 InitMouseEventGeneric(WebInputEvent::MouseDown, | 1415 InitMouseEventGeneric(WebInputEvent::MouseDown, |
| 1410 current_pointer_state_[pointerId].pressed_button_, | 1416 current_pointer_state_[pointerId].pressed_button_, |
| 1411 current_pointer_state_[pointerId].current_buttons_, | 1417 current_pointer_state_[pointerId].current_buttons_, |
| 1412 current_pointer_state_[pointerId].last_pos_, | 1418 current_pointer_state_[pointerId].last_pos_, |
| 1413 GetCurrentEventTimeSec(), click_count, | 1419 GetMockTimeSeconds(), click_count, |
| 1414 current_pointer_state_[pointerId].modifiers_, | 1420 current_pointer_state_[pointerId].modifiers_, |
| 1415 pointerType, pointerId, pressure, tiltX, tiltY, &event); | 1421 pointerType, pointerId, pressure, tiltX, tiltY, &event); |
| 1416 | 1422 |
| 1417 HandleInputEventOnViewOrPopup(event); | 1423 HandleInputEventOnViewOrPopup(event); |
| 1418 } | 1424 } |
| 1419 | 1425 |
| 1420 void EventSender::PointerUp(int button_number, | 1426 void EventSender::PointerUp(int button_number, |
| 1421 int modifiers, | 1427 int modifiers, |
| 1422 WebPointerProperties::PointerType pointerType, | 1428 WebPointerProperties::PointerType pointerType, |
| 1423 int pointerId, | 1429 int pointerId, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1446 current_pointer_state_[pointerId].pressed_button_ = | 1452 current_pointer_state_[pointerId].pressed_button_ = |
| 1447 WebMouseEvent::Button::NoButton; | 1453 WebMouseEvent::Button::NoButton; |
| 1448 | 1454 |
| 1449 WebMouseEvent event; | 1455 WebMouseEvent event; |
| 1450 int click_count = pointerType == WebPointerProperties::PointerType::Mouse | 1456 int click_count = pointerType == WebPointerProperties::PointerType::Mouse |
| 1451 ? click_count_ | 1457 ? click_count_ |
| 1452 : 0; | 1458 : 0; |
| 1453 InitMouseEventGeneric(WebInputEvent::MouseUp, button_type, | 1459 InitMouseEventGeneric(WebInputEvent::MouseUp, button_type, |
| 1454 current_pointer_state_[pointerId].current_buttons_, | 1460 current_pointer_state_[pointerId].current_buttons_, |
| 1455 current_pointer_state_[pointerId].last_pos_, | 1461 current_pointer_state_[pointerId].last_pos_, |
| 1456 GetCurrentEventTimeSec(), click_count, modifiers, | 1462 GetMockTimeSeconds(), click_count, modifiers, |
| 1457 pointerType, pointerId, pressure, tiltX, tiltY, | 1463 pointerType, pointerId, pressure, tiltX, tiltY, |
| 1458 &event); | 1464 &event); |
| 1459 HandleInputEventOnViewOrPopup(event); | 1465 HandleInputEventOnViewOrPopup(event); |
| 1460 if (pointerType == WebPointerProperties::PointerType::Mouse) | 1466 if (pointerType == WebPointerProperties::PointerType::Mouse) |
| 1461 DoDragAfterMouseUp(event); | 1467 DoDragAfterMouseUp(event); |
| 1462 } | 1468 } |
| 1463 } | 1469 } |
| 1464 | 1470 |
| 1465 void EventSender::SetMouseButtonState(int button_number, int modifiers) { | 1471 void EventSender::SetMouseButtonState(int button_number, int modifiers) { |
| 1466 current_pointer_state_[kRawMousePointerId].pressed_button_ = | 1472 current_pointer_state_[kRawMousePointerId].pressed_button_ = |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 domCodeString.assign("Digit9"); | 1652 domCodeString.assign("Digit9"); |
| 1647 } | 1653 } |
| 1648 } | 1654 } |
| 1649 | 1655 |
| 1650 // For one generated keyboard event, we need to generate a keyDown/keyUp | 1656 // For one generated keyboard event, we need to generate a keyDown/keyUp |
| 1651 // pair; | 1657 // pair; |
| 1652 // On Windows, we might also need to generate a char event to mimic the | 1658 // On Windows, we might also need to generate a char event to mimic the |
| 1653 // Windows event flow; on other platforms we create a merged event and test | 1659 // Windows event flow; on other platforms we create a merged event and test |
| 1654 // the event flow that that platform provides. | 1660 // the event flow that that platform provides. |
| 1655 WebKeyboardEvent event_down; | 1661 WebKeyboardEvent event_down; |
| 1656 event_down.timeStampSeconds = GetCurrentEventTimeSec(); | 1662 event_down.timeStampSeconds = GetMockTimeSeconds(); |
| 1657 event_down.type = WebInputEvent::RawKeyDown; | 1663 event_down.type = WebInputEvent::RawKeyDown; |
| 1658 event_down.modifiers = modifiers; | 1664 event_down.modifiers = modifiers; |
| 1659 event_down.windowsKeyCode = code; | 1665 event_down.windowsKeyCode = code; |
| 1660 event_down.domKey = static_cast<int>( | 1666 event_down.domKey = static_cast<int>( |
| 1661 ui::KeycodeConverter::KeyStringToDomKey(domKeyString)); | 1667 ui::KeycodeConverter::KeyStringToDomKey(domKeyString)); |
| 1662 event_down.domCode = static_cast<int>( | 1668 event_down.domCode = static_cast<int>( |
| 1663 ui::KeycodeConverter::CodeStringToDomCode(domCodeString)); | 1669 ui::KeycodeConverter::CodeStringToDomCode(domCodeString)); |
| 1664 | 1670 |
| 1665 if (generate_char) { | 1671 if (generate_char) { |
| 1666 event_down.text[0] = text; | 1672 event_down.text[0] = text; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1706 delegate()->SetEditCommand(edit_command, ""); | 1712 delegate()->SetEditCommand(edit_command, ""); |
| 1707 | 1713 |
| 1708 HandleInputEventOnViewOrPopup(event_down); | 1714 HandleInputEventOnViewOrPopup(event_down); |
| 1709 | 1715 |
| 1710 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { | 1716 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { |
| 1711 WebMouseEvent event; | 1717 WebMouseEvent event; |
| 1712 InitMouseEvent(WebInputEvent::MouseDown, | 1718 InitMouseEvent(WebInputEvent::MouseDown, |
| 1713 current_pointer_state_[kRawMousePointerId].pressed_button_, | 1719 current_pointer_state_[kRawMousePointerId].pressed_button_, |
| 1714 current_pointer_state_[kRawMousePointerId].current_buttons_, | 1720 current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 1715 current_pointer_state_[kRawMousePointerId].last_pos_, | 1721 current_pointer_state_[kRawMousePointerId].last_pos_, |
| 1716 GetCurrentEventTimeSec(), click_count_, 0, &event); | 1722 GetMockTimeSeconds(), click_count_, 0, &event); |
| 1717 FinishDragAndDrop(event, blink::WebDragOperationNone); | 1723 FinishDragAndDrop(event, blink::WebDragOperationNone); |
| 1718 } | 1724 } |
| 1719 | 1725 |
| 1720 delegate()->ClearEditCommand(); | 1726 delegate()->ClearEditCommand(); |
| 1721 | 1727 |
| 1722 if (generate_char) { | 1728 if (generate_char) { |
| 1723 WebKeyboardEvent event_char = event_up; | 1729 WebKeyboardEvent event_char = event_up; |
| 1724 event_char.type = WebInputEvent::Char; | 1730 event_char.type = WebInputEvent::Char; |
| 1725 HandleInputEventOnViewOrPopup(event_char); | 1731 HandleInputEventOnViewOrPopup(event_char); |
| 1726 } | 1732 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1756 WebMouseEvent::Button::NoButton) { | 1762 WebMouseEvent::Button::NoButton) { |
| 1757 current_pointer_state_[kRawMousePointerId].pressed_button_ = | 1763 current_pointer_state_[kRawMousePointerId].pressed_button_ = |
| 1758 WebMouseEvent::Button::Right; | 1764 WebMouseEvent::Button::Right; |
| 1759 current_pointer_state_[kRawMousePointerId].current_buttons_ |= | 1765 current_pointer_state_[kRawMousePointerId].current_buttons_ |= |
| 1760 GetWebMouseEventModifierForButton( | 1766 GetWebMouseEventModifierForButton( |
| 1761 current_pointer_state_[kRawMousePointerId].pressed_button_); | 1767 current_pointer_state_[kRawMousePointerId].pressed_button_); |
| 1762 } | 1768 } |
| 1763 InitMouseEvent(WebInputEvent::MouseDown, WebMouseEvent::Button::Right, | 1769 InitMouseEvent(WebInputEvent::MouseDown, WebMouseEvent::Button::Right, |
| 1764 current_pointer_state_[kRawMousePointerId].current_buttons_, | 1770 current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 1765 current_pointer_state_[kRawMousePointerId].last_pos_, | 1771 current_pointer_state_[kRawMousePointerId].last_pos_, |
| 1766 GetCurrentEventTimeSec(), click_count_, 0, &event); | 1772 GetMockTimeSeconds(), click_count_, 0, &event); |
| 1767 HandleInputEventOnViewOrPopup(event); | 1773 HandleInputEventOnViewOrPopup(event); |
| 1768 | 1774 |
| 1769 #if defined(OS_WIN) | 1775 #if defined(OS_WIN) |
| 1770 current_pointer_state_[kRawMousePointerId].current_buttons_ &= | 1776 current_pointer_state_[kRawMousePointerId].current_buttons_ &= |
| 1771 ~GetWebMouseEventModifierForButton(WebMouseEvent::Button::Right); | 1777 ~GetWebMouseEventModifierForButton(WebMouseEvent::Button::Right); |
| 1772 current_pointer_state_[kRawMousePointerId].pressed_button_ = | 1778 current_pointer_state_[kRawMousePointerId].pressed_button_ = |
| 1773 WebMouseEvent::Button::NoButton; | 1779 WebMouseEvent::Button::NoButton; |
| 1774 | 1780 |
| 1775 InitMouseEvent(WebInputEvent::MouseUp, WebMouseEvent::Button::Right, | 1781 InitMouseEvent(WebInputEvent::MouseUp, WebMouseEvent::Button::Right, |
| 1776 current_pointer_state_[kRawMousePointerId].current_buttons_, | 1782 current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 1777 current_pointer_state_[kRawMousePointerId].last_pos_, | 1783 current_pointer_state_[kRawMousePointerId].last_pos_, |
| 1778 GetCurrentEventTimeSec(), click_count_, 0, &event); | 1784 GetMockTimeSeconds(), click_count_, 0, &event); |
| 1779 HandleInputEventOnViewOrPopup(event); | 1785 HandleInputEventOnViewOrPopup(event); |
| 1780 #endif | 1786 #endif |
| 1781 | 1787 |
| 1782 std::vector<std::string> menu_items = | 1788 std::vector<std::string> menu_items = |
| 1783 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate()); | 1789 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate()); |
| 1784 last_context_menu_data_.reset(); | 1790 last_context_menu_data_.reset(); |
| 1785 return menu_items; | 1791 return menu_items; |
| 1786 } | 1792 } |
| 1787 | 1793 |
| 1788 void EventSender::TextZoomIn() { | 1794 void EventSender::TextZoomIn() { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1901 filename.utf8().data() + "\n"); | 1907 filename.utf8().data() + "\n"); |
| 1902 } | 1908 } |
| 1903 | 1909 |
| 1904 void EventSender::GestureFlingCancel() { | 1910 void EventSender::GestureFlingCancel() { |
| 1905 WebGestureEvent event; | 1911 WebGestureEvent event; |
| 1906 event.type = WebInputEvent::GestureFlingCancel; | 1912 event.type = WebInputEvent::GestureFlingCancel; |
| 1907 // Generally it won't matter what device we use here, and since it might | 1913 // Generally it won't matter what device we use here, and since it might |
| 1908 // be cumbersome to expect all callers to specify a device, we'll just | 1914 // be cumbersome to expect all callers to specify a device, we'll just |
| 1909 // choose Touchpad here. | 1915 // choose Touchpad here. |
| 1910 event.sourceDevice = blink::WebGestureDeviceTouchpad; | 1916 event.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 1911 event.timeStampSeconds = GetCurrentEventTimeSec(); | 1917 event.timeStampSeconds = GetMockTimeSeconds(); |
| 1912 | 1918 |
| 1913 if (force_layout_on_events_) | 1919 if (force_layout_on_events_) |
| 1914 view()->updateAllLifecyclePhases(); | 1920 view()->updateAllLifecyclePhases(); |
| 1915 | 1921 |
| 1916 HandleInputEventOnViewOrPopup(event); | 1922 HandleInputEventOnViewOrPopup(event); |
| 1917 } | 1923 } |
| 1918 | 1924 |
| 1919 void EventSender::GestureFlingStart(float x, | 1925 void EventSender::GestureFlingStart(float x, |
| 1920 float y, | 1926 float y, |
| 1921 float velocity_x, | 1927 float velocity_x, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1945 return; | 1951 return; |
| 1946 } | 1952 } |
| 1947 | 1953 |
| 1948 event.x = x; | 1954 event.x = x; |
| 1949 event.y = y; | 1955 event.y = y; |
| 1950 event.globalX = event.x; | 1956 event.globalX = event.x; |
| 1951 event.globalY = event.y; | 1957 event.globalY = event.y; |
| 1952 | 1958 |
| 1953 event.data.flingStart.velocityX = velocity_x; | 1959 event.data.flingStart.velocityX = velocity_x; |
| 1954 event.data.flingStart.velocityY = velocity_y; | 1960 event.data.flingStart.velocityY = velocity_y; |
| 1955 event.timeStampSeconds = GetCurrentEventTimeSec(); | 1961 event.timeStampSeconds = GetMockTimeSeconds(); |
| 1956 | 1962 |
| 1957 if (force_layout_on_events_) | 1963 if (force_layout_on_events_) |
| 1958 view()->updateAllLifecyclePhases(); | 1964 view()->updateAllLifecyclePhases(); |
| 1959 | 1965 |
| 1960 HandleInputEventOnViewOrPopup(event); | 1966 HandleInputEventOnViewOrPopup(event); |
| 1961 } | 1967 } |
| 1962 | 1968 |
| 1963 bool EventSender::IsFlinging() const { | 1969 bool EventSender::IsFlinging() const { |
| 1964 return view()->isFlinging(); | 1970 return view()->isFlinging(); |
| 1965 } | 1971 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2180 } else { | 2186 } else { |
| 2181 current_pointer_state_[pointerId].last_pos_ = mouse_pos; | 2187 current_pointer_state_[pointerId].last_pos_ = mouse_pos; |
| 2182 WebMouseEvent event; | 2188 WebMouseEvent event; |
| 2183 int click_count = pointerType == WebPointerProperties::PointerType::Mouse | 2189 int click_count = pointerType == WebPointerProperties::PointerType::Mouse |
| 2184 ? click_count_ | 2190 ? click_count_ |
| 2185 : 0; | 2191 : 0; |
| 2186 InitMouseEventGeneric( | 2192 InitMouseEventGeneric( |
| 2187 WebInputEvent::MouseMove, | 2193 WebInputEvent::MouseMove, |
| 2188 current_pointer_state_[kRawMousePointerId].pressed_button_, | 2194 current_pointer_state_[kRawMousePointerId].pressed_button_, |
| 2189 current_pointer_state_[kRawMousePointerId].current_buttons_, mouse_pos, | 2195 current_pointer_state_[kRawMousePointerId].current_buttons_, mouse_pos, |
| 2190 GetCurrentEventTimeSec(), click_count, modifiers, pointerType, | 2196 GetMockTimeSeconds(), click_count, modifiers, pointerType, |
| 2191 pointerId, pressure, tiltX, tiltY, &event); | 2197 pointerId, pressure, tiltX, tiltY, &event); |
| 2192 HandleInputEventOnViewOrPopup(event); | 2198 HandleInputEventOnViewOrPopup(event); |
| 2193 if (pointerType == WebPointerProperties::PointerType::Mouse) | 2199 if (pointerType == WebPointerProperties::PointerType::Mouse) |
| 2194 DoDragAfterMouseMove(event); | 2200 DoDragAfterMouseMove(event); |
| 2195 } | 2201 } |
| 2196 } | 2202 } |
| 2197 | 2203 |
| 2198 void EventSender::MouseLeave() { | 2204 void EventSender::MouseLeave() { |
| 2199 if (force_layout_on_events_) | 2205 if (force_layout_on_events_) |
| 2200 view()->updateAllLifecyclePhases(); | 2206 view()->updateAllLifecyclePhases(); |
| 2201 | 2207 |
| 2202 WebMouseEvent event; | 2208 WebMouseEvent event; |
| 2203 InitMouseEvent(WebInputEvent::MouseLeave, WebMouseEvent::Button::NoButton, 0, | 2209 InitMouseEvent(WebInputEvent::MouseLeave, WebMouseEvent::Button::NoButton, 0, |
| 2204 current_pointer_state_[kRawMousePointerId].last_pos_, | 2210 current_pointer_state_[kRawMousePointerId].last_pos_, |
| 2205 GetCurrentEventTimeSec(), click_count_, 0, &event); | 2211 GetMockTimeSeconds(), click_count_, 0, &event); |
| 2206 HandleInputEventOnViewOrPopup(event); | 2212 HandleInputEventOnViewOrPopup(event); |
| 2207 } | 2213 } |
| 2208 | 2214 |
| 2209 | 2215 |
| 2210 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { | 2216 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { |
| 2211 delegate()->PostTask(new WebCallbackTask( | 2217 delegate()->PostTask(new WebCallbackTask( |
| 2212 base::Bind(&EventSender::MouseDown, weak_factory_.GetWeakPtr(), | 2218 base::Bind(&EventSender::MouseDown, weak_factory_.GetWeakPtr(), |
| 2213 button_number, modifiers))); | 2219 button_number, modifiers))); |
| 2214 delegate()->PostTask(new WebCallbackTask( | 2220 delegate()->PostTask(new WebCallbackTask( |
| 2215 base::Bind(&EventSender::MouseUp, weak_factory_.GetWeakPtr(), | 2221 base::Bind(&EventSender::MouseUp, weak_factory_.GetWeakPtr(), |
| 2216 button_number, modifiers))); | 2222 button_number, modifiers))); |
| 2217 } | 2223 } |
| 2218 | 2224 |
| 2219 void EventSender::ScheduleAsynchronousKeyDown(const std::string& code_str, | 2225 void EventSender::ScheduleAsynchronousKeyDown(const std::string& code_str, |
| 2220 int modifiers, | 2226 int modifiers, |
| 2221 KeyLocationCode location) { | 2227 KeyLocationCode location) { |
| 2222 delegate()->PostTask(new WebCallbackTask( | 2228 delegate()->PostTask(new WebCallbackTask( |
| 2223 base::Bind(&EventSender::KeyDown, weak_factory_.GetWeakPtr(), code_str, | 2229 base::Bind(&EventSender::KeyDown, weak_factory_.GetWeakPtr(), code_str, |
| 2224 modifiers, location))); | 2230 modifiers, location))); |
| 2225 } | 2231 } |
| 2226 | 2232 |
| 2227 double EventSender::GetCurrentEventTimeSec() { | 2233 double EventSender::GetMockTimeSeconds() { |
| 2228 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF() + | 2234 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF() + |
| 2229 time_offset_ms_ / 1000.0; | 2235 time_offset_ms_ / 1000.0; |
| 2230 } | 2236 } |
| 2231 | 2237 |
| 2232 void EventSender::DoLeapForward(int milliseconds) { | 2238 void EventSender::DoLeapForward(int milliseconds) { |
| 2233 time_offset_ms_ += milliseconds; | 2239 time_offset_ms_ += milliseconds; |
| 2234 } | 2240 } |
| 2235 | 2241 |
| 2236 void EventSender::GetOptionalTouchArgs(gin::Arguments* args, | 2242 void EventSender::GetOptionalTouchArgs(gin::Arguments* args, |
| 2237 bool& moved_beyond_slop_region, | 2243 bool& moved_beyond_slop_region, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2267 touch_points_.size()); | 2273 touch_points_.size()); |
| 2268 if (force_layout_on_events_) | 2274 if (force_layout_on_events_) |
| 2269 view()->updateAllLifecyclePhases(); | 2275 view()->updateAllLifecyclePhases(); |
| 2270 | 2276 |
| 2271 WebTouchEvent touch_event; | 2277 WebTouchEvent touch_event; |
| 2272 touch_event.type = type; | 2278 touch_event.type = type; |
| 2273 touch_event.modifiers = touch_modifiers_; | 2279 touch_event.modifiers = touch_modifiers_; |
| 2274 touch_event.dispatchType = touch_cancelable_ | 2280 touch_event.dispatchType = touch_cancelable_ |
| 2275 ? WebInputEvent::Blocking | 2281 ? WebInputEvent::Blocking |
| 2276 : WebInputEvent::EventNonBlocking; | 2282 : WebInputEvent::EventNonBlocking; |
| 2277 touch_event.timeStampSeconds = GetCurrentEventTimeSec(); | 2283 touch_event.timeStampSeconds = GetMockTimeSeconds(); |
| 2278 touch_event.movedBeyondSlopRegion = moved_beyond_slop_region; | 2284 touch_event.movedBeyondSlopRegion = moved_beyond_slop_region; |
| 2279 touch_event.uniqueTouchEventId = unique_touch_event_id; | 2285 touch_event.uniqueTouchEventId = unique_touch_event_id; |
| 2280 touch_event.touchesLength = touch_points_.size(); | 2286 touch_event.touchesLength = touch_points_.size(); |
| 2281 for (size_t i = 0; i < touch_points_.size(); ++i) | 2287 for (size_t i = 0; i < touch_points_.size(); ++i) |
| 2282 touch_event.touches[i] = touch_points_[i]; | 2288 touch_event.touches[i] = touch_points_[i]; |
| 2283 HandleInputEventOnViewOrPopup(touch_event); | 2289 HandleInputEventOnViewOrPopup(touch_event); |
| 2284 | 2290 |
| 2285 for (size_t i = 0; i < touch_points_.size(); ++i) { | 2291 for (size_t i = 0; i < touch_points_.size(); ++i) { |
| 2286 WebTouchPoint* touch_point = &touch_points_[i]; | 2292 WebTouchPoint* touch_point = &touch_points_[i]; |
| 2287 if (touch_point->state == WebTouchPoint::StateReleased | 2293 if (touch_point->state == WebTouchPoint::StateReleased |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2515 } | 2521 } |
| 2516 break; | 2522 break; |
| 2517 default: | 2523 default: |
| 2518 NOTREACHED(); | 2524 NOTREACHED(); |
| 2519 } | 2525 } |
| 2520 | 2526 |
| 2521 event.uniqueTouchEventId = GetUniqueTouchEventId(args); | 2527 event.uniqueTouchEventId = GetUniqueTouchEventId(args); |
| 2522 | 2528 |
| 2523 event.globalX = event.x; | 2529 event.globalX = event.x; |
| 2524 event.globalY = event.y; | 2530 event.globalY = event.y; |
| 2525 event.timeStampSeconds = GetCurrentEventTimeSec(); | 2531 event.timeStampSeconds = GetMockTimeSeconds(); |
| 2526 | 2532 |
| 2527 if (force_layout_on_events_) | 2533 if (force_layout_on_events_) |
| 2528 view()->updateAllLifecyclePhases(); | 2534 view()->updateAllLifecyclePhases(); |
| 2529 | 2535 |
| 2530 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); | 2536 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); |
| 2531 | 2537 |
| 2532 // Long press might start a drag drop session. Complete it if so. | 2538 // Long press might start a drag drop session. Complete it if so. |
| 2533 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { | 2539 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { |
| 2534 WebMouseEvent mouse_event; | 2540 WebMouseEvent mouse_event; |
| 2535 InitMouseEvent(WebInputEvent::MouseDown, | 2541 InitMouseEvent(WebInputEvent::MouseDown, |
| 2536 current_pointer_state_[kRawMousePointerId].pressed_button_, | 2542 current_pointer_state_[kRawMousePointerId].pressed_button_, |
| 2537 current_pointer_state_[kRawMousePointerId].current_buttons_, | 2543 current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 2538 WebPoint(x, y), GetCurrentEventTimeSec(), click_count_, | 2544 WebPoint(x, y), GetMockTimeSeconds(), click_count_, |
| 2539 current_pointer_state_[kRawMousePointerId].modifiers_, | 2545 current_pointer_state_[kRawMousePointerId].modifiers_, |
| 2540 &mouse_event); | 2546 &mouse_event); |
| 2541 | 2547 |
| 2542 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); | 2548 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); |
| 2543 } | 2549 } |
| 2544 args->Return(result != WebInputEventResult::NotHandled); | 2550 args->Return(result != WebInputEventResult::NotHandled); |
| 2545 } | 2551 } |
| 2546 | 2552 |
| 2547 void EventSender::UpdateClickCountForButton( | 2553 void EventSender::UpdateClickCountForButton( |
| 2548 WebMouseEvent::Button button_type) { | 2554 WebMouseEvent::Button button_type) { |
| 2549 if ((GetCurrentEventTimeSec() - last_click_time_sec_ < | 2555 if ((GetMockTimeSeconds() - last_click_time_sec_ < |
| 2550 kMultipleClickTimeSec) && | 2556 kMultipleClickTimeSec) && |
| 2551 (!OutsideMultiClickRadius( | 2557 (!OutsideMultiClickRadius( |
| 2552 current_pointer_state_[kRawMousePointerId].last_pos_, | 2558 current_pointer_state_[kRawMousePointerId].last_pos_, |
| 2553 last_click_pos_)) && | 2559 last_click_pos_)) && |
| 2554 (button_type == last_button_type_)) { | 2560 (button_type == last_button_type_)) { |
| 2555 ++click_count_; | 2561 ++click_count_; |
| 2556 } else { | 2562 } else { |
| 2557 click_count_ = 1; | 2563 click_count_ = 1; |
| 2558 last_button_type_ = button_type; | 2564 last_button_type_ = button_type; |
| 2559 } | 2565 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2601 } | 2607 } |
| 2602 } | 2608 } |
| 2603 } | 2609 } |
| 2604 } | 2610 } |
| 2605 } | 2611 } |
| 2606 | 2612 |
| 2607 InitMouseEvent(WebInputEvent::MouseWheel, | 2613 InitMouseEvent(WebInputEvent::MouseWheel, |
| 2608 current_pointer_state_[kRawMousePointerId].pressed_button_, | 2614 current_pointer_state_[kRawMousePointerId].pressed_button_, |
| 2609 current_pointer_state_[kRawMousePointerId].current_buttons_, | 2615 current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 2610 current_pointer_state_[kRawMousePointerId].last_pos_, | 2616 current_pointer_state_[kRawMousePointerId].last_pos_, |
| 2611 GetCurrentEventTimeSec(), click_count_, modifiers, event); | 2617 GetMockTimeSeconds(), click_count_, modifiers, event); |
| 2612 event->wheelTicksX = static_cast<float>(horizontal); | 2618 event->wheelTicksX = static_cast<float>(horizontal); |
| 2613 event->wheelTicksY = static_cast<float>(vertical); | 2619 event->wheelTicksY = static_cast<float>(vertical); |
| 2614 event->deltaX = event->wheelTicksX; | 2620 event->deltaX = event->wheelTicksX; |
| 2615 event->deltaY = event->wheelTicksY; | 2621 event->deltaY = event->wheelTicksY; |
| 2616 event->scrollByPage = paged; | 2622 event->scrollByPage = paged; |
| 2617 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; | 2623 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; |
| 2618 event->phase = phase; | 2624 event->phase = phase; |
| 2619 if (scroll_type == MouseScrollType::PIXEL) { | 2625 if (scroll_type == MouseScrollType::PIXEL) { |
| 2620 event->wheelTicksX /= kScrollbarPixelsPerTick; | 2626 event->wheelTicksX /= kScrollbarPixelsPerTick; |
| 2621 event->wheelTicksY /= kScrollbarPixelsPerTick; | 2627 event->wheelTicksY /= kScrollbarPixelsPerTick; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2748 SavedEvent e = mouse_event_queue_.front(); | 2754 SavedEvent e = mouse_event_queue_.front(); |
| 2749 mouse_event_queue_.pop_front(); | 2755 mouse_event_queue_.pop_front(); |
| 2750 | 2756 |
| 2751 switch (e.type) { | 2757 switch (e.type) { |
| 2752 case SavedEvent::TYPE_MOUSE_MOVE: { | 2758 case SavedEvent::TYPE_MOUSE_MOVE: { |
| 2753 WebMouseEvent event; | 2759 WebMouseEvent event; |
| 2754 InitMouseEvent( | 2760 InitMouseEvent( |
| 2755 WebInputEvent::MouseMove, | 2761 WebInputEvent::MouseMove, |
| 2756 current_pointer_state_[kRawMousePointerId].pressed_button_, | 2762 current_pointer_state_[kRawMousePointerId].pressed_button_, |
| 2757 current_pointer_state_[kRawMousePointerId].current_buttons_, e.pos, | 2763 current_pointer_state_[kRawMousePointerId].current_buttons_, e.pos, |
| 2758 GetCurrentEventTimeSec(), click_count_, e.modifiers, &event); | 2764 GetMockTimeSeconds(), click_count_, e.modifiers, &event); |
| 2759 current_pointer_state_[kRawMousePointerId].last_pos_ = | 2765 current_pointer_state_[kRawMousePointerId].last_pos_ = |
| 2760 WebPoint(event.x, event.y); | 2766 WebPoint(event.x, event.y); |
| 2761 HandleInputEventOnViewOrPopup(event); | 2767 HandleInputEventOnViewOrPopup(event); |
| 2762 DoDragAfterMouseMove(event); | 2768 DoDragAfterMouseMove(event); |
| 2763 break; | 2769 break; |
| 2764 } | 2770 } |
| 2765 case SavedEvent::TYPE_LEAP_FORWARD: | 2771 case SavedEvent::TYPE_LEAP_FORWARD: |
| 2766 DoLeapForward(e.milliseconds); | 2772 DoLeapForward(e.milliseconds); |
| 2767 break; | 2773 break; |
| 2768 case SavedEvent::TYPE_MOUSE_UP: { | 2774 case SavedEvent::TYPE_MOUSE_UP: { |
| 2769 current_pointer_state_[kRawMousePointerId].current_buttons_ &= | 2775 current_pointer_state_[kRawMousePointerId].current_buttons_ &= |
| 2770 ~GetWebMouseEventModifierForButton(e.button_type); | 2776 ~GetWebMouseEventModifierForButton(e.button_type); |
| 2771 current_pointer_state_[kRawMousePointerId].pressed_button_ = | 2777 current_pointer_state_[kRawMousePointerId].pressed_button_ = |
| 2772 WebMouseEvent::Button::NoButton; | 2778 WebMouseEvent::Button::NoButton; |
| 2773 | 2779 |
| 2774 WebMouseEvent event; | 2780 WebMouseEvent event; |
| 2775 InitMouseEvent( | 2781 InitMouseEvent( |
| 2776 WebInputEvent::MouseUp, e.button_type, | 2782 WebInputEvent::MouseUp, e.button_type, |
| 2777 current_pointer_state_[kRawMousePointerId].current_buttons_, | 2783 current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 2778 current_pointer_state_[kRawMousePointerId].last_pos_, | 2784 current_pointer_state_[kRawMousePointerId].last_pos_, |
| 2779 GetCurrentEventTimeSec(), click_count_, e.modifiers, &event); | 2785 GetMockTimeSeconds(), click_count_, e.modifiers, &event); |
| 2780 HandleInputEventOnViewOrPopup(event); | 2786 HandleInputEventOnViewOrPopup(event); |
| 2781 DoDragAfterMouseUp(event); | 2787 DoDragAfterMouseUp(event); |
| 2782 break; | 2788 break; |
| 2783 } | 2789 } |
| 2784 default: | 2790 default: |
| 2785 NOTREACHED(); | 2791 NOTREACHED(); |
| 2786 } | 2792 } |
| 2787 } | 2793 } |
| 2788 | 2794 |
| 2789 replaying_saved_events_ = false; | 2795 replaying_saved_events_ = false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2801 if (!WebInputEvent::isKeyboardEventType(event->type)) | 2807 if (!WebInputEvent::isKeyboardEventType(event->type)) |
| 2802 return popup->handleInputEvent(*event); | 2808 return popup->handleInputEvent(*event); |
| 2803 } | 2809 } |
| 2804 return view()->handleInputEvent(*event); | 2810 return view()->handleInputEvent(*event); |
| 2805 } | 2811 } |
| 2806 | 2812 |
| 2807 void EventSender::SendGesturesForMouseWheelEvent( | 2813 void EventSender::SendGesturesForMouseWheelEvent( |
| 2808 const WebMouseWheelEvent wheel_event) { | 2814 const WebMouseWheelEvent wheel_event) { |
| 2809 WebGestureEvent begin_event; | 2815 WebGestureEvent begin_event; |
| 2810 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollBegin, | 2816 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollBegin, |
| 2811 GetCurrentEventTimeSec(), wheel_event, | 2817 GetMockTimeSeconds(), wheel_event, |
| 2812 &begin_event); | 2818 &begin_event); |
| 2813 begin_event.data.scrollBegin.deltaXHint = wheel_event.deltaX; | 2819 begin_event.data.scrollBegin.deltaXHint = wheel_event.deltaX; |
| 2814 begin_event.data.scrollBegin.deltaYHint = wheel_event.deltaY; | 2820 begin_event.data.scrollBegin.deltaYHint = wheel_event.deltaY; |
| 2815 if (wheel_event.scrollByPage) { | 2821 if (wheel_event.scrollByPage) { |
| 2816 begin_event.data.scrollBegin.deltaHintUnits = blink::WebGestureEvent::Page; | 2822 begin_event.data.scrollBegin.deltaHintUnits = blink::WebGestureEvent::Page; |
| 2817 if (begin_event.data.scrollBegin.deltaXHint) { | 2823 if (begin_event.data.scrollBegin.deltaXHint) { |
| 2818 begin_event.data.scrollBegin.deltaXHint = | 2824 begin_event.data.scrollBegin.deltaXHint = |
| 2819 begin_event.data.scrollBegin.deltaXHint > 0 ? 1 : -1; | 2825 begin_event.data.scrollBegin.deltaXHint > 0 ? 1 : -1; |
| 2820 } | 2826 } |
| 2821 if (begin_event.data.scrollBegin.deltaYHint) { | 2827 if (begin_event.data.scrollBegin.deltaYHint) { |
| 2822 begin_event.data.scrollBegin.deltaYHint = | 2828 begin_event.data.scrollBegin.deltaYHint = |
| 2823 begin_event.data.scrollBegin.deltaYHint > 0 ? 1 : -1; | 2829 begin_event.data.scrollBegin.deltaYHint > 0 ? 1 : -1; |
| 2824 } | 2830 } |
| 2825 } else { | 2831 } else { |
| 2826 begin_event.data.scrollBegin.deltaHintUnits = | 2832 begin_event.data.scrollBegin.deltaHintUnits = |
| 2827 wheel_event.hasPreciseScrollingDeltas | 2833 wheel_event.hasPreciseScrollingDeltas |
| 2828 ? blink::WebGestureEvent::PrecisePixels | 2834 ? blink::WebGestureEvent::PrecisePixels |
| 2829 : blink::WebGestureEvent::Pixels; | 2835 : blink::WebGestureEvent::Pixels; |
| 2830 } | 2836 } |
| 2831 | 2837 |
| 2832 if (force_layout_on_events_) | 2838 if (force_layout_on_events_) |
| 2833 view()->updateAllLifecyclePhases(); | 2839 view()->updateAllLifecyclePhases(); |
| 2834 | 2840 |
| 2835 HandleInputEventOnViewOrPopup(begin_event); | 2841 HandleInputEventOnViewOrPopup(begin_event); |
| 2836 | 2842 |
| 2837 WebGestureEvent update_event; | 2843 WebGestureEvent update_event; |
| 2838 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollUpdate, | 2844 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollUpdate, |
| 2839 GetCurrentEventTimeSec(), wheel_event, | 2845 GetMockTimeSeconds(), wheel_event, |
| 2840 &update_event); | 2846 &update_event); |
| 2841 update_event.data.scrollUpdate.deltaX = | 2847 update_event.data.scrollUpdate.deltaX = |
| 2842 begin_event.data.scrollBegin.deltaXHint; | 2848 begin_event.data.scrollBegin.deltaXHint; |
| 2843 update_event.data.scrollUpdate.deltaY = | 2849 update_event.data.scrollUpdate.deltaY = |
| 2844 begin_event.data.scrollBegin.deltaYHint; | 2850 begin_event.data.scrollBegin.deltaYHint; |
| 2845 update_event.data.scrollUpdate.deltaUnits = | 2851 update_event.data.scrollUpdate.deltaUnits = |
| 2846 begin_event.data.scrollBegin.deltaHintUnits; | 2852 begin_event.data.scrollBegin.deltaHintUnits; |
| 2847 | 2853 |
| 2848 if (force_layout_on_events_) | 2854 if (force_layout_on_events_) |
| 2849 view()->updateAllLifecyclePhases(); | 2855 view()->updateAllLifecyclePhases(); |
| 2850 HandleInputEventOnViewOrPopup(update_event); | 2856 HandleInputEventOnViewOrPopup(update_event); |
| 2851 | 2857 |
| 2852 WebGestureEvent end_event; | 2858 WebGestureEvent end_event; |
| 2853 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollEnd, | 2859 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollEnd, |
| 2854 GetCurrentEventTimeSec(), wheel_event, | 2860 GetMockTimeSeconds(), wheel_event, |
| 2855 &end_event); | 2861 &end_event); |
| 2856 end_event.data.scrollEnd.deltaUnits = | 2862 end_event.data.scrollEnd.deltaUnits = |
| 2857 begin_event.data.scrollBegin.deltaHintUnits; | 2863 begin_event.data.scrollBegin.deltaHintUnits; |
| 2858 | 2864 |
| 2859 if (force_layout_on_events_) | 2865 if (force_layout_on_events_) |
| 2860 view()->updateAllLifecyclePhases(); | 2866 view()->updateAllLifecyclePhases(); |
| 2861 HandleInputEventOnViewOrPopup(end_event); | 2867 HandleInputEventOnViewOrPopup(end_event); |
| 2862 } | 2868 } |
| 2863 | 2869 |
| 2864 TestInterfaces* EventSender::interfaces() { | 2870 TestInterfaces* EventSender::interfaces() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2878 } | 2884 } |
| 2879 | 2885 |
| 2880 std::unique_ptr<WebInputEvent> EventSender::ScaleEvent( | 2886 std::unique_ptr<WebInputEvent> EventSender::ScaleEvent( |
| 2881 const WebInputEvent& event) { | 2887 const WebInputEvent& event) { |
| 2882 // ui::ScaleWebInputEvent returns nullptr when the scale is 1.0f as the event | 2888 // ui::ScaleWebInputEvent returns nullptr when the scale is 1.0f as the event |
| 2883 // does not have to be converted. | 2889 // does not have to be converted. |
| 2884 return ui::ScaleWebInputEvent(event, delegate()->GetWindowToViewportScale()); | 2890 return ui::ScaleWebInputEvent(event, delegate()->GetWindowToViewportScale()); |
| 2885 } | 2891 } |
| 2886 | 2892 |
| 2887 } // namespace test_runner | 2893 } // namespace test_runner |
| OLD | NEW |