Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(924)

Side by Side Diff: components/test_runner/event_sender.cc

Issue 2569273002: Add constructors to WebInputEvents and setters so we can work at cleaning up these public structs. (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 9 #include <memory>
10 10
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 193 }
194 194
195 const int kButtonsInModifiers = WebMouseEvent::LeftButtonDown 195 const int kButtonsInModifiers = WebMouseEvent::LeftButtonDown
196 | WebMouseEvent::MiddleButtonDown | WebMouseEvent::RightButtonDown; 196 | WebMouseEvent::MiddleButtonDown | WebMouseEvent::RightButtonDown;
197 197
198 int modifiersWithButtons(int modifiers, int buttons) { 198 int modifiersWithButtons(int modifiers, int buttons) {
199 return (modifiers & ~kButtonsInModifiers) 199 return (modifiers & ~kButtonsInModifiers)
200 | (buttons & kButtonsInModifiers); 200 | (buttons & kButtonsInModifiers);
201 } 201 }
202 202
203 void InitMouseEventGeneric(WebInputEvent::Type t, 203 void InitMouseEventGeneric(WebMouseEvent::Button b,
204 WebMouseEvent::Button b,
205 int current_buttons, 204 int current_buttons,
206 const WebPoint& pos, 205 const WebPoint& pos,
207 double time_stamp,
208 int click_count, 206 int click_count,
209 int modifiers,
210 WebPointerProperties::PointerType pointerType, 207 WebPointerProperties::PointerType pointerType,
211 int pointerId, 208 int pointerId,
212 float pressure, 209 float pressure,
213 int tiltX, 210 int tiltX,
214 int tiltY, 211 int tiltY,
215 WebMouseEvent* e) { 212 WebMouseEvent* e) {
216 e->type = t;
217 e->button = b; 213 e->button = b;
218 e->modifiers = modifiersWithButtons(modifiers, current_buttons);
219 e->x = pos.x; 214 e->x = pos.x;
220 e->y = pos.y; 215 e->y = pos.y;
221 e->globalX = pos.x; 216 e->globalX = pos.x;
222 e->globalY = pos.y; 217 e->globalY = pos.y;
223 e->pointerType = pointerType; 218 e->pointerType = pointerType;
224 e->id = pointerId; 219 e->id = pointerId;
225 e->force = pressure; 220 e->force = pressure;
226 e->tiltX = tiltX; 221 e->tiltX = tiltX;
227 e->tiltY = tiltY; 222 e->tiltY = tiltY;
228 e->timeStampSeconds = time_stamp;
229 e->clickCount = click_count; 223 e->clickCount = click_count;
230 } 224 }
231 225
232 void InitMouseEvent(WebInputEvent::Type t, 226 void InitMouseEvent(WebMouseEvent::Button b,
233 WebMouseEvent::Button b,
234 int current_buttons, 227 int current_buttons,
235 const WebPoint& pos, 228 const WebPoint& pos,
236 double time_stamp,
237 int click_count, 229 int click_count,
238 int modifiers,
239 WebMouseEvent* e) { 230 WebMouseEvent* e) {
240 InitMouseEventGeneric(t, b, current_buttons, pos, time_stamp, click_count, 231 InitMouseEventGeneric(b, current_buttons, pos, click_count,
241 modifiers, WebPointerProperties::PointerType::Mouse, 0, 232 WebPointerProperties::PointerType::Mouse, 0, 0.0, 0, 0,
242 0.0, 0, 0, e); 233 e);
243 } 234 }
244 235
245 void InitGestureEventFromMouseWheel(WebInputEvent::Type type, 236 void InitGestureEventFromMouseWheel(const WebMouseWheelEvent& wheel_event,
246 double time_stamp,
247 const WebMouseWheelEvent& wheel_event,
248 WebGestureEvent* gesture_event) { 237 WebGestureEvent* gesture_event) {
249 gesture_event->type = type;
250 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad; 238 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad;
251 gesture_event->x = wheel_event.x; 239 gesture_event->x = wheel_event.x;
252 gesture_event->y = wheel_event.y; 240 gesture_event->y = wheel_event.y;
253 gesture_event->globalX = wheel_event.globalX; 241 gesture_event->globalX = wheel_event.globalX;
254 gesture_event->globalY = wheel_event.globalY; 242 gesture_event->globalY = wheel_event.globalY;
255 gesture_event->timeStampSeconds = time_stamp;
256 } 243 }
257 244
258 int GetKeyModifier(const std::string& modifier_name) { 245 int GetKeyModifier(const std::string& modifier_name) {
259 const char* characters = modifier_name.c_str(); 246 const char* characters = modifier_name.c_str();
260 if (!strcmp(characters, "ctrlKey") 247 if (!strcmp(characters, "ctrlKey")
261 #ifndef __APPLE__ 248 #ifndef __APPLE__
262 || !strcmp(characters, "addSelectionKey") 249 || !strcmp(characters, "addSelectionKey")
263 #endif 250 #endif
264 ) { 251 ) {
265 return WebInputEvent::ControlKey; 252 return WebInputEvent::ControlKey;
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 } 1324 }
1338 1325
1339 void EventSender::Install(WebLocalFrame* frame) { 1326 void EventSender::Install(WebLocalFrame* frame) {
1340 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame); 1327 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame);
1341 } 1328 }
1342 1329
1343 void EventSender::SetContextMenuData(const WebContextMenuData& data) { 1330 void EventSender::SetContextMenuData(const WebContextMenuData& data) {
1344 last_context_menu_data_.reset(new WebContextMenuData(data)); 1331 last_context_menu_data_.reset(new WebContextMenuData(data));
1345 } 1332 }
1346 1333
1334 int EventSender::ModifiersForPointer(int pointer_id) {
1335 return modifiersWithButtons(
1336 current_pointer_state_[pointer_id].modifiers_,
1337 current_pointer_state_[pointer_id].current_buttons_);
1338 }
1339
1347 void EventSender::DoDragDrop(const WebDragData& drag_data, 1340 void EventSender::DoDragDrop(const WebDragData& drag_data,
1348 WebDragOperationsMask mask) { 1341 WebDragOperationsMask mask) {
1349 WebMouseEvent raw_event; 1342 WebMouseEvent raw_event(WebInputEvent::MouseDown,
1350 InitMouseEvent(WebInputEvent::MouseDown, 1343 ModifiersForPointer(kRawMousePointerId),
1351 current_pointer_state_[kRawMousePointerId].pressed_button_, 1344 GetCurrentEventTimeSec());
1345 InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_,
1352 current_pointer_state_[kRawMousePointerId].current_buttons_, 1346 current_pointer_state_[kRawMousePointerId].current_buttons_,
1353 current_pointer_state_[kRawMousePointerId].last_pos_, 1347 current_pointer_state_[kRawMousePointerId].last_pos_,
1354 GetCurrentEventTimeSec(), click_count_, 1348 click_count_, &raw_event);
1355 current_pointer_state_[kRawMousePointerId].modifiers_,
1356 &raw_event);
1357 1349
1358 std::unique_ptr<WebInputEvent> widget_event = 1350 std::unique_ptr<WebInputEvent> widget_event =
1359 TransformScreenToWidgetCoordinates(raw_event); 1351 TransformScreenToWidgetCoordinates(raw_event);
1360 const WebMouseEvent* event = 1352 const WebMouseEvent* event =
1361 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) 1353 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
1362 : &raw_event; 1354 : &raw_event;
1363 1355
1364 WebPoint client_point(event->x, event->y); 1356 WebPoint client_point(event->x, event->y);
1365 WebPoint screen_point(event->globalX, event->globalY); 1357 WebPoint screen_point(event->globalX, event->globalY);
1366 current_drag_data_ = drag_data; 1358 current_drag_data_ = drag_data;
(...skipping 27 matching lines...) Expand all
1394 int tiltX, 1386 int tiltX,
1395 int tiltY) { 1387 int tiltY) {
1396 if (force_layout_on_events_) 1388 if (force_layout_on_events_)
1397 widget()->updateAllLifecyclePhases(); 1389 widget()->updateAllLifecyclePhases();
1398 1390
1399 DCHECK_NE(-1, button_number); 1391 DCHECK_NE(-1, button_number);
1400 1392
1401 WebMouseEvent::Button button_type = 1393 WebMouseEvent::Button button_type =
1402 GetButtonTypeFromButtonNumber(button_number); 1394 GetButtonTypeFromButtonNumber(button_number);
1403 1395
1404 WebMouseEvent event;
1405 int click_count = 0; 1396 int click_count = 0;
1406 current_pointer_state_[pointerId].pressed_button_ = button_type; 1397 current_pointer_state_[pointerId].pressed_button_ = button_type;
1407 current_pointer_state_[pointerId].current_buttons_ |= 1398 current_pointer_state_[pointerId].current_buttons_ |=
1408 GetWebMouseEventModifierForButton(button_type); 1399 GetWebMouseEventModifierForButton(button_type);
1409 current_pointer_state_[pointerId].modifiers_ = modifiers; 1400 current_pointer_state_[pointerId].modifiers_ = modifiers;
1410 1401
1411 if (pointerType == WebPointerProperties::PointerType::Mouse) { 1402 if (pointerType == WebPointerProperties::PointerType::Mouse) {
1412 UpdateClickCountForButton(button_type); 1403 UpdateClickCountForButton(button_type);
1413 click_count = click_count_; 1404 click_count = click_count_;
1414 } 1405 }
1415 InitMouseEventGeneric(WebInputEvent::MouseDown, 1406 WebMouseEvent event(WebInputEvent::MouseDown, ModifiersForPointer(pointerId),
1416 current_pointer_state_[pointerId].pressed_button_, 1407 GetCurrentEventTimeSec());
1408 InitMouseEventGeneric(current_pointer_state_[pointerId].pressed_button_,
1417 current_pointer_state_[pointerId].current_buttons_, 1409 current_pointer_state_[pointerId].current_buttons_,
1418 current_pointer_state_[pointerId].last_pos_, 1410 current_pointer_state_[pointerId].last_pos_,
1419 GetCurrentEventTimeSec(), click_count, 1411 click_count, pointerType, pointerId, pressure, tiltX,
1420 current_pointer_state_[pointerId].modifiers_, 1412 tiltY, &event);
1421 pointerType, pointerId, pressure, tiltX, tiltY, &event);
1422 1413
1423 HandleInputEventOnViewOrPopup(event); 1414 HandleInputEventOnViewOrPopup(event);
1424 } 1415 }
1425 1416
1426 void EventSender::PointerUp(int button_number, 1417 void EventSender::PointerUp(int button_number,
1427 int modifiers, 1418 int modifiers,
1428 WebPointerProperties::PointerType pointerType, 1419 WebPointerProperties::PointerType pointerType,
1429 int pointerId, 1420 int pointerId,
1430 float pressure, 1421 float pressure,
1431 int tiltX, 1422 int tiltX,
1432 int tiltY) { 1423 int tiltY) {
1433 if (force_layout_on_events_) 1424 if (force_layout_on_events_)
1434 widget()->updateAllLifecyclePhases(); 1425 widget()->updateAllLifecyclePhases();
1435 1426
1436 DCHECK_NE(-1, button_number); 1427 DCHECK_NE(-1, button_number);
1437 1428
1438 WebMouseEvent::Button button_type = 1429 WebMouseEvent::Button button_type =
1439 GetButtonTypeFromButtonNumber(button_number); 1430 GetButtonTypeFromButtonNumber(button_number);
1440 1431
1441 if (pointerType == WebPointerProperties::PointerType::Mouse && 1432 if (pointerType == WebPointerProperties::PointerType::Mouse &&
1442 is_drag_mode_ && !replaying_saved_events_) { 1433 is_drag_mode_ && !replaying_saved_events_) {
1443 SavedEvent saved_event; 1434 SavedEvent saved_event;
1444 saved_event.type = SavedEvent::TYPE_MOUSE_UP; 1435 saved_event.type = SavedEvent::TYPE_MOUSE_UP;
1445 saved_event.button_type = button_type; 1436 saved_event.button_type = button_type;
1446 saved_event.modifiers = modifiers; 1437 saved_event.modifiers = modifiers;
1447 mouse_event_queue_.push_back(saved_event); 1438 mouse_event_queue_.push_back(saved_event);
1448 ReplaySavedEvents(); 1439 ReplaySavedEvents();
1449 } else { 1440 } else {
1441 current_pointer_state_[pointerId].modifiers_ = modifiers;
1450 current_pointer_state_[pointerId].current_buttons_ &= 1442 current_pointer_state_[pointerId].current_buttons_ &=
1451 ~GetWebMouseEventModifierForButton(button_type); 1443 ~GetWebMouseEventModifierForButton(button_type);
1452 current_pointer_state_[pointerId].pressed_button_ = 1444 current_pointer_state_[pointerId].pressed_button_ =
1453 WebMouseEvent::Button::NoButton; 1445 WebMouseEvent::Button::NoButton;
1454 1446
1455 WebMouseEvent event; 1447 WebMouseEvent event(WebInputEvent::MouseUp, ModifiersForPointer(pointerId),
1448 GetCurrentEventTimeSec());
1456 int click_count = pointerType == WebPointerProperties::PointerType::Mouse 1449 int click_count = pointerType == WebPointerProperties::PointerType::Mouse
1457 ? click_count_ 1450 ? click_count_
1458 : 0; 1451 : 0;
1459 InitMouseEventGeneric(WebInputEvent::MouseUp, button_type, 1452 InitMouseEventGeneric(
1460 current_pointer_state_[pointerId].current_buttons_, 1453 button_type, current_pointer_state_[pointerId].current_buttons_,
1461 current_pointer_state_[pointerId].last_pos_, 1454 current_pointer_state_[pointerId].last_pos_, click_count, pointerType,
1462 GetCurrentEventTimeSec(), click_count, modifiers, 1455 pointerId, pressure, tiltX, tiltY, &event);
1463 pointerType, pointerId, pressure, tiltX, tiltY,
1464 &event);
1465 HandleInputEventOnViewOrPopup(event); 1456 HandleInputEventOnViewOrPopup(event);
1466 if (pointerType == WebPointerProperties::PointerType::Mouse) 1457 if (pointerType == WebPointerProperties::PointerType::Mouse)
1467 DoDragAfterMouseUp(event); 1458 DoDragAfterMouseUp(event);
1468 } 1459 }
1469 } 1460 }
1470 1461
1471 void EventSender::SetMouseButtonState(int button_number, int modifiers) { 1462 void EventSender::SetMouseButtonState(int button_number, int modifiers) {
1472 current_pointer_state_[kRawMousePointerId].pressed_button_ = 1463 current_pointer_state_[kRawMousePointerId].pressed_button_ =
1473 GetButtonTypeFromButtonNumber(button_number); 1464 GetButtonTypeFromButtonNumber(button_number);
1474 current_pointer_state_[kRawMousePointerId].current_buttons_ = 1465 current_pointer_state_[kRawMousePointerId].current_buttons_ =
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 } 1637 }
1647 1638
1648 if ("(" == code_str) { 1639 if ("(" == code_str) {
1649 code = '9'; 1640 code = '9';
1650 needs_shift_key_modifier = true; 1641 needs_shift_key_modifier = true;
1651 domKeyString.assign("("); 1642 domKeyString.assign("(");
1652 domCodeString.assign("Digit9"); 1643 domCodeString.assign("Digit9");
1653 } 1644 }
1654 } 1645 }
1655 1646
1647 if (needs_shift_key_modifier)
1648 modifiers |= WebInputEvent::ShiftKey;
1649
1650 // See if KeyLocation argument is given.
1651 switch (location) {
1652 case DOMKeyLocationStandard:
1653 break;
1654 case DOMKeyLocationLeft:
1655 modifiers |= WebInputEvent::IsLeft;
1656 break;
1657 case DOMKeyLocationRight:
1658 modifiers |= WebInputEvent::IsRight;
1659 break;
1660 case DOMKeyLocationNumpad:
1661 modifiers |= WebInputEvent::IsKeyPad;
1662 break;
1663 }
1664
1656 // For one generated keyboard event, we need to generate a keyDown/keyUp 1665 // For one generated keyboard event, we need to generate a keyDown/keyUp
1657 // pair; 1666 // pair;
1658 // On Windows, we might also need to generate a char event to mimic the 1667 // On Windows, we might also need to generate a char event to mimic the
1659 // Windows event flow; on other platforms we create a merged event and test 1668 // Windows event flow; on other platforms we create a merged event and test
1660 // the event flow that that platform provides. 1669 // the event flow that that platform provides.
1661 WebKeyboardEvent event_down; 1670 WebKeyboardEvent event_down(WebInputEvent::RawKeyDown, modifiers,
1662 event_down.timeStampSeconds = GetCurrentEventTimeSec(); 1671 GetCurrentEventTimeSec());
1663 event_down.type = WebInputEvent::RawKeyDown;
1664 event_down.modifiers = modifiers;
1665 event_down.windowsKeyCode = code; 1672 event_down.windowsKeyCode = code;
1666 event_down.domKey = static_cast<int>( 1673 event_down.domKey = static_cast<int>(
1667 ui::KeycodeConverter::KeyStringToDomKey(domKeyString)); 1674 ui::KeycodeConverter::KeyStringToDomKey(domKeyString));
1668 event_down.domCode = static_cast<int>( 1675 event_down.domCode = static_cast<int>(
1669 ui::KeycodeConverter::CodeStringToDomCode(domCodeString)); 1676 ui::KeycodeConverter::CodeStringToDomCode(domCodeString));
1670 1677
1671 if (generate_char) { 1678 if (generate_char) {
1672 event_down.text[0] = text; 1679 event_down.text[0] = text;
1673 event_down.unmodifiedText[0] = text; 1680 event_down.unmodifiedText[0] = text;
1674 } 1681 }
1675 1682
1676 if (event_down.modifiers != 0) 1683 if (event_down.modifiers != 0)
1677 event_down.isSystemKey = IsSystemKeyEvent(event_down); 1684 event_down.isSystemKey = IsSystemKeyEvent(event_down);
1678 1685
1679 if (needs_shift_key_modifier) 1686 WebKeyboardEvent event_up = event_down;
1680 event_down.modifiers |= WebInputEvent::ShiftKey; 1687 event_up.setType(WebInputEvent::KeyUp);
1681
1682 // See if KeyLocation argument is given.
1683 switch (location) {
1684 case DOMKeyLocationStandard:
1685 break;
1686 case DOMKeyLocationLeft:
1687 event_down.modifiers |= WebInputEvent::IsLeft;
1688 break;
1689 case DOMKeyLocationRight:
1690 event_down.modifiers |= WebInputEvent::IsRight;
1691 break;
1692 case DOMKeyLocationNumpad:
1693 event_down.modifiers |= WebInputEvent::IsKeyPad;
1694 break;
1695 }
1696
1697 WebKeyboardEvent event_up;
1698 event_up = event_down;
1699 event_up.type = WebInputEvent::KeyUp;
1700 // EventSender.m forces a layout here, with at least one 1688 // EventSender.m forces a layout here, with at least one
1701 // test (fast/forms/focus-control-to-page.html) relying on this. 1689 // test (fast/forms/focus-control-to-page.html) relying on this.
1702 if (force_layout_on_events_) 1690 if (force_layout_on_events_)
1703 widget()->updateAllLifecyclePhases(); 1691 widget()->updateAllLifecyclePhases();
1704 1692
1705 // In the browser, if a keyboard event corresponds to an editor command, 1693 // In the browser, if a keyboard event corresponds to an editor command,
1706 // the command will be dispatched to the renderer just before dispatching 1694 // the command will be dispatched to the renderer just before dispatching
1707 // the keyboard event, and then it will be executed in the 1695 // the keyboard event, and then it will be executed in the
1708 // RenderView::handleCurrentKeyboardEvent() method. 1696 // RenderView::handleCurrentKeyboardEvent() method.
1709 // We just simulate the same behavior here. 1697 // We just simulate the same behavior here.
1710 std::string edit_command; 1698 std::string edit_command;
1711 if (GetEditCommand(event_down, &edit_command)) 1699 if (GetEditCommand(event_down, &edit_command))
1712 delegate()->SetEditCommand(edit_command, ""); 1700 delegate()->SetEditCommand(edit_command, "");
1713 1701
1714 HandleInputEventOnViewOrPopup(event_down); 1702 HandleInputEventOnViewOrPopup(event_down);
1715 1703
1716 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { 1704 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) {
1717 WebMouseEvent event; 1705 WebMouseEvent event(WebInputEvent::MouseDown,
1718 InitMouseEvent(WebInputEvent::MouseDown, 1706 ModifiersForPointer(kRawMousePointerId),
1719 current_pointer_state_[kRawMousePointerId].pressed_button_, 1707 GetCurrentEventTimeSec());
1708 InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_,
1720 current_pointer_state_[kRawMousePointerId].current_buttons_, 1709 current_pointer_state_[kRawMousePointerId].current_buttons_,
1721 current_pointer_state_[kRawMousePointerId].last_pos_, 1710 current_pointer_state_[kRawMousePointerId].last_pos_,
1722 GetCurrentEventTimeSec(), click_count_, 0, &event); 1711 click_count_, &event);
1723 FinishDragAndDrop(event, blink::WebDragOperationNone); 1712 FinishDragAndDrop(event, blink::WebDragOperationNone);
1724 } 1713 }
1725 1714
1726 delegate()->ClearEditCommand(); 1715 delegate()->ClearEditCommand();
1727 1716
1728 if (generate_char) { 1717 if (generate_char) {
1729 WebKeyboardEvent event_char = event_up; 1718 WebKeyboardEvent event_char = event_up;
1730 event_char.type = WebInputEvent::Char; 1719 event_char.setType(WebInputEvent::Char);
1731 HandleInputEventOnViewOrPopup(event_char); 1720 HandleInputEventOnViewOrPopup(event_char);
1732 } 1721 }
1733 1722
1734 HandleInputEventOnViewOrPopup(event_up); 1723 HandleInputEventOnViewOrPopup(event_up);
1735 } 1724 }
1736 1725
1737 void EventSender::EnableDOMUIEventLogging() {} 1726 void EventSender::EnableDOMUIEventLogging() {}
1738 1727
1739 void EventSender::FireKeyboardEventsToElement() {} 1728 void EventSender::FireKeyboardEventsToElement() {}
1740 1729
1741 void EventSender::ClearKillRing() {} 1730 void EventSender::ClearKillRing() {}
1742 1731
1743 std::vector<std::string> EventSender::ContextClick() { 1732 std::vector<std::string> EventSender::ContextClick() {
1744 if (force_layout_on_events_) 1733 if (force_layout_on_events_)
1745 widget()->updateAllLifecyclePhases(); 1734 widget()->updateAllLifecyclePhases();
1746 1735
1747 UpdateClickCountForButton(WebMouseEvent::Button::Right); 1736 UpdateClickCountForButton(WebMouseEvent::Button::Right);
1748 1737
1749 // Clears last context menu data because we need to know if the context menu 1738 // Clears last context menu data because we need to know if the context menu
1750 // be requested after following mouse events. 1739 // be requested after following mouse events.
1751 last_context_menu_data_.reset(); 1740 last_context_menu_data_.reset();
1752 1741
1753 // Generate right mouse down and up. 1742 // Generate right mouse down and up.
1754 WebMouseEvent event;
1755 // This is a hack to work around only allowing a single pressed button since 1743 // This is a hack to work around only allowing a single pressed button since
1756 // we want to test the case where both the left and right mouse buttons are 1744 // we want to test the case where both the left and right mouse buttons are
1757 // pressed. 1745 // pressed.
1758 // TODO(mustaq): This hack seems unused here! But do we need this hack at all 1746 // TODO(mustaq): This hack seems unused here! But do we need this hack at all
1759 // after adding current_buttons_. 1747 // after adding current_buttons_.
1760 if (current_pointer_state_[kRawMousePointerId].pressed_button_ == 1748 if (current_pointer_state_[kRawMousePointerId].pressed_button_ ==
1761 WebMouseEvent::Button::NoButton) { 1749 WebMouseEvent::Button::NoButton) {
1762 current_pointer_state_[kRawMousePointerId].pressed_button_ = 1750 current_pointer_state_[kRawMousePointerId].pressed_button_ =
1763 WebMouseEvent::Button::Right; 1751 WebMouseEvent::Button::Right;
1764 current_pointer_state_[kRawMousePointerId].current_buttons_ |= 1752 current_pointer_state_[kRawMousePointerId].current_buttons_ |=
1765 GetWebMouseEventModifierForButton( 1753 GetWebMouseEventModifierForButton(
1766 current_pointer_state_[kRawMousePointerId].pressed_button_); 1754 current_pointer_state_[kRawMousePointerId].pressed_button_);
1767 } 1755 }
1768 InitMouseEvent(WebInputEvent::MouseDown, WebMouseEvent::Button::Right, 1756 WebMouseEvent event(WebInputEvent::MouseDown,
1757 ModifiersForPointer(kRawMousePointerId),
1758 GetCurrentEventTimeSec());
1759 InitMouseEvent(WebMouseEvent::Button::Right,
1769 current_pointer_state_[kRawMousePointerId].current_buttons_, 1760 current_pointer_state_[kRawMousePointerId].current_buttons_,
1770 current_pointer_state_[kRawMousePointerId].last_pos_, 1761 current_pointer_state_[kRawMousePointerId].last_pos_,
1771 GetCurrentEventTimeSec(), click_count_, 0, &event); 1762 click_count_, &event);
1772 HandleInputEventOnViewOrPopup(event); 1763 HandleInputEventOnViewOrPopup(event);
1773 1764
1774 #if defined(OS_WIN) 1765 #if defined(OS_WIN)
1775 current_pointer_state_[kRawMousePointerId].current_buttons_ &= 1766 current_pointer_state_[kRawMousePointerId].current_buttons_ &=
1776 ~GetWebMouseEventModifierForButton(WebMouseEvent::Button::Right); 1767 ~GetWebMouseEventModifierForButton(WebMouseEvent::Button::Right);
1777 current_pointer_state_[kRawMousePointerId].pressed_button_ = 1768 current_pointer_state_[kRawMousePointerId].pressed_button_ =
1778 WebMouseEvent::Button::NoButton; 1769 WebMouseEvent::Button::NoButton;
1779 1770
1780 InitMouseEvent(WebInputEvent::MouseUp, WebMouseEvent::Button::Right, 1771 WebMouseEvent mouseUpEvent(WebInputEvent::MouseUp,
1772 ModifiersForPointer(kRawMousePointerId),
1773 GetCurrentEventTimeSec());
1774 InitMouseEvent(WebMouseEvent::Button::Right,
1781 current_pointer_state_[kRawMousePointerId].current_buttons_, 1775 current_pointer_state_[kRawMousePointerId].current_buttons_,
1782 current_pointer_state_[kRawMousePointerId].last_pos_, 1776 current_pointer_state_[kRawMousePointerId].last_pos_,
1783 GetCurrentEventTimeSec(), click_count_, 0, &event); 1777 click_count_, &mouseUpEvent);
1784 HandleInputEventOnViewOrPopup(event); 1778 HandleInputEventOnViewOrPopup(mouseUpEvent);
1785 #endif 1779 #endif
1786 1780
1787 std::vector<std::string> menu_items = 1781 std::vector<std::string> menu_items =
1788 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate()); 1782 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate());
1789 last_context_menu_data_.reset(); 1783 last_context_menu_data_.reset();
1790 return menu_items; 1784 return menu_items;
1791 } 1785 }
1792 1786
1793 void EventSender::TextZoomIn() { 1787 void EventSender::TextZoomIn() {
1794 view()->setTextZoomFactor(view()->textZoomFactor() * 1.2f); 1788 view()->setTextZoomFactor(view()->textZoomFactor() * 1.2f);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 if (items[i].storageType == WebDragData::Item::StorageTypeBinaryData) { 1894 if (items[i].storageType == WebDragData::Item::StorageTypeBinaryData) {
1901 filename = items[i].title; 1895 filename = items[i].title;
1902 break; 1896 break;
1903 } 1897 }
1904 } 1898 }
1905 delegate()->PrintMessage(std::string("Filename being dragged: ") + 1899 delegate()->PrintMessage(std::string("Filename being dragged: ") +
1906 filename.utf8().data() + "\n"); 1900 filename.utf8().data() + "\n");
1907 } 1901 }
1908 1902
1909 void EventSender::GestureFlingCancel() { 1903 void EventSender::GestureFlingCancel() {
1910 WebGestureEvent event; 1904 WebGestureEvent event(WebInputEvent::GestureFlingCancel,
1911 event.type = WebInputEvent::GestureFlingCancel; 1905 WebInputEvent::NoModifiers, GetCurrentEventTimeSec());
1912 // Generally it won't matter what device we use here, and since it might 1906 // Generally it won't matter what device we use here, and since it might
1913 // be cumbersome to expect all callers to specify a device, we'll just 1907 // be cumbersome to expect all callers to specify a device, we'll just
1914 // choose Touchpad here. 1908 // choose Touchpad here.
1915 event.sourceDevice = blink::WebGestureDeviceTouchpad; 1909 event.sourceDevice = blink::WebGestureDeviceTouchpad;
1916 event.timeStampSeconds = GetCurrentEventTimeSec();
1917 1910
1918 if (force_layout_on_events_) 1911 if (force_layout_on_events_)
1919 widget()->updateAllLifecyclePhases(); 1912 widget()->updateAllLifecyclePhases();
1920 1913
1921 HandleInputEventOnViewOrPopup(event); 1914 HandleInputEventOnViewOrPopup(event);
1922 } 1915 }
1923 1916
1924 void EventSender::GestureFlingStart(float x, 1917 void EventSender::GestureFlingStart(float x,
1925 float y, 1918 float y,
1926 float velocity_x, 1919 float velocity_x,
1927 float velocity_y, 1920 float velocity_y,
1928 gin::Arguments* args) { 1921 gin::Arguments* args) {
1929 WebGestureEvent event; 1922 WebGestureEvent event(WebInputEvent::GestureFlingStart,
1930 event.type = WebInputEvent::GestureFlingStart; 1923 WebInputEvent::NoModifiers, GetCurrentEventTimeSec());
1931 1924
1932 std::string device_string; 1925 std::string device_string;
1933 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) 1926 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString())
1934 args->GetNext(&device_string); 1927 args->GetNext(&device_string);
1935 1928
1936 if (device_string == kSourceDeviceStringTouchpad) { 1929 if (device_string == kSourceDeviceStringTouchpad) {
1937 event.sourceDevice = blink::WebGestureDeviceTouchpad; 1930 event.sourceDevice = blink::WebGestureDeviceTouchpad;
1938 } else if (device_string == kSourceDeviceStringTouchscreen) { 1931 } else if (device_string == kSourceDeviceStringTouchscreen) {
1939 event.sourceDevice = blink::WebGestureDeviceTouchscreen; 1932 event.sourceDevice = blink::WebGestureDeviceTouchscreen;
1940 } else { 1933 } else {
1941 args->ThrowError(); 1934 args->ThrowError();
1942 return; 1935 return;
1943 } 1936 }
1944 1937
1945 float max_start_velocity = std::max(fabs(velocity_x), fabs(velocity_y)); 1938 float max_start_velocity = std::max(fabs(velocity_x), fabs(velocity_y));
1946 if (!max_start_velocity) { 1939 if (!max_start_velocity) {
1947 v8::Isolate* isolate = blink::mainThreadIsolate(); 1940 v8::Isolate* isolate = blink::mainThreadIsolate();
1948 isolate->ThrowException(v8::Exception::TypeError( 1941 isolate->ThrowException(v8::Exception::TypeError(
1949 gin::StringToV8(isolate, "Invalid max start velocity."))); 1942 gin::StringToV8(isolate, "Invalid max start velocity.")));
1950 return; 1943 return;
1951 } 1944 }
1952 1945
1953 event.x = x; 1946 event.x = x;
1954 event.y = y; 1947 event.y = y;
1955 event.globalX = event.x; 1948 event.globalX = event.x;
1956 event.globalY = event.y; 1949 event.globalY = event.y;
1957 1950
1958 event.data.flingStart.velocityX = velocity_x; 1951 event.data.flingStart.velocityX = velocity_x;
1959 event.data.flingStart.velocityY = velocity_y; 1952 event.data.flingStart.velocityY = velocity_y;
1960 event.timeStampSeconds = GetCurrentEventTimeSec();
1961 1953
1962 if (force_layout_on_events_) 1954 if (force_layout_on_events_)
1963 widget()->updateAllLifecyclePhases(); 1955 widget()->updateAllLifecyclePhases();
1964 1956
1965 HandleInputEventOnViewOrPopup(event); 1957 HandleInputEventOnViewOrPopup(event);
1966 } 1958 }
1967 1959
1968 bool EventSender::IsFlinging() const { 1960 bool EventSender::IsFlinging() const {
1969 return view()->isFlinging(); 1961 return view()->isFlinging();
1970 } 1962 }
(...skipping 12 matching lines...) Expand all
1983 1975
1984 void EventSender::TouchCancel(gin::Arguments* args) { 1976 void EventSender::TouchCancel(gin::Arguments* args) {
1985 SendCurrentTouchEvent(WebInputEvent::TouchCancel, args); 1977 SendCurrentTouchEvent(WebInputEvent::TouchCancel, args);
1986 } 1978 }
1987 1979
1988 void EventSender::TouchEnd(gin::Arguments* args) { 1980 void EventSender::TouchEnd(gin::Arguments* args) {
1989 SendCurrentTouchEvent(WebInputEvent::TouchEnd, args); 1981 SendCurrentTouchEvent(WebInputEvent::TouchEnd, args);
1990 } 1982 }
1991 1983
1992 void EventSender::NotifyStartOfTouchScroll() { 1984 void EventSender::NotifyStartOfTouchScroll() {
1993 WebTouchEvent event; 1985 WebTouchEvent event(WebInputEvent::TouchScrollStarted,
1994 event.type = WebInputEvent::TouchScrollStarted; 1986 WebInputEvent::NoModifiers, GetCurrentEventTimeSec());
1995 HandleInputEventOnViewOrPopup(event); 1987 HandleInputEventOnViewOrPopup(event);
1996 } 1988 }
1997 1989
1998 void EventSender::LeapForward(int milliseconds) { 1990 void EventSender::LeapForward(int milliseconds) {
1999 if (is_drag_mode_ && 1991 if (is_drag_mode_ &&
2000 current_pointer_state_[kRawMousePointerId].pressed_button_ == 1992 current_pointer_state_[kRawMousePointerId].pressed_button_ ==
2001 WebMouseEvent::Button::Left && 1993 WebMouseEvent::Button::Left &&
2002 !replaying_saved_events_) { 1994 !replaying_saved_events_) {
2003 SavedEvent saved_event; 1995 SavedEvent saved_event;
2004 saved_event.type = SavedEvent::TYPE_LEAP_FORWARD; 1996 saved_event.type = SavedEvent::TYPE_LEAP_FORWARD;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 void EventSender::GestureLongTap(gin::Arguments* args) { 2117 void EventSender::GestureLongTap(gin::Arguments* args) {
2126 GestureEvent(WebInputEvent::GestureLongTap, args); 2118 GestureEvent(WebInputEvent::GestureLongTap, args);
2127 } 2119 }
2128 2120
2129 void EventSender::GestureTwoFingerTap(gin::Arguments* args) { 2121 void EventSender::GestureTwoFingerTap(gin::Arguments* args) {
2130 GestureEvent(WebInputEvent::GestureTwoFingerTap, args); 2122 GestureEvent(WebInputEvent::GestureTwoFingerTap, args);
2131 } 2123 }
2132 2124
2133 void EventSender::MouseScrollBy(gin::Arguments* args, 2125 void EventSender::MouseScrollBy(gin::Arguments* args,
2134 MouseScrollType scroll_type) { 2126 MouseScrollType scroll_type) {
2135 WebMouseWheelEvent wheel_event;
2136 // TODO(dtapuska): Gestures really should be sent by the MouseWheelEventQueue 2127 // TODO(dtapuska): Gestures really should be sent by the MouseWheelEventQueue
2137 // class in the browser. But since the event doesn't propogate up into 2128 // class in the browser. But since the event doesn't propogate up into
2138 // the browser generate the events here. See crbug.com/596095. 2129 // the browser generate the events here. See crbug.com/596095.
2139 bool send_gestures = true; 2130 bool send_gestures = true;
2140 InitMouseWheelEvent(args, scroll_type, &wheel_event, &send_gestures); 2131 WebMouseWheelEvent wheel_event =
2141 if (HandleInputEventOnViewOrPopup(wheel_event) == 2132 GetMouseWheelEvent(args, scroll_type, &send_gestures);
2133 if (wheel_event.type != WebInputEvent::Undefined &&
2134 HandleInputEventOnViewOrPopup(wheel_event) ==
2142 WebInputEventResult::NotHandled && 2135 WebInputEventResult::NotHandled &&
2143 send_gestures) { 2136 send_gestures) {
2144 SendGesturesForMouseWheelEvent(wheel_event); 2137 SendGesturesForMouseWheelEvent(wheel_event);
2145 } 2138 }
2146 } 2139 }
2147 2140
2148 void EventSender::MouseMoveTo(gin::Arguments* args) { 2141 void EventSender::MouseMoveTo(gin::Arguments* args) {
2149 if (force_layout_on_events_) 2142 if (force_layout_on_events_)
2150 widget()->updateAllLifecyclePhases(); 2143 widget()->updateAllLifecyclePhases();
2151 2144
(...skipping 25 matching lines...) Expand all
2177 is_drag_mode_ && !replaying_saved_events_ && 2170 is_drag_mode_ && !replaying_saved_events_ &&
2178 current_pointer_state_[kRawMousePointerId].pressed_button_ == 2171 current_pointer_state_[kRawMousePointerId].pressed_button_ ==
2179 WebMouseEvent::Button::Left) { 2172 WebMouseEvent::Button::Left) {
2180 SavedEvent saved_event; 2173 SavedEvent saved_event;
2181 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; 2174 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE;
2182 saved_event.pos = mouse_pos; 2175 saved_event.pos = mouse_pos;
2183 saved_event.modifiers = modifiers; 2176 saved_event.modifiers = modifiers;
2184 mouse_event_queue_.push_back(saved_event); 2177 mouse_event_queue_.push_back(saved_event);
2185 } else { 2178 } else {
2186 current_pointer_state_[pointerId].last_pos_ = mouse_pos; 2179 current_pointer_state_[pointerId].last_pos_ = mouse_pos;
2187 WebMouseEvent event; 2180 current_pointer_state_[pointerId].modifiers_ = modifiers;
2181 WebMouseEvent event(WebInputEvent::MouseMove,
2182 ModifiersForPointer(pointerId),
2183 GetCurrentEventTimeSec());
2188 int click_count = pointerType == WebPointerProperties::PointerType::Mouse 2184 int click_count = pointerType == WebPointerProperties::PointerType::Mouse
2189 ? click_count_ 2185 ? click_count_
2190 : 0; 2186 : 0;
2191 InitMouseEventGeneric( 2187 InitMouseEventGeneric(
2192 WebInputEvent::MouseMove,
2193 current_pointer_state_[kRawMousePointerId].pressed_button_, 2188 current_pointer_state_[kRawMousePointerId].pressed_button_,
2194 current_pointer_state_[kRawMousePointerId].current_buttons_, mouse_pos, 2189 current_pointer_state_[kRawMousePointerId].current_buttons_, mouse_pos,
2195 GetCurrentEventTimeSec(), click_count, modifiers, pointerType, 2190 click_count, pointerType, pointerId, pressure, tiltX, tiltY, &event);
2196 pointerId, pressure, tiltX, tiltY, &event);
2197 HandleInputEventOnViewOrPopup(event); 2191 HandleInputEventOnViewOrPopup(event);
2198 if (pointerType == WebPointerProperties::PointerType::Mouse) 2192 if (pointerType == WebPointerProperties::PointerType::Mouse)
2199 DoDragAfterMouseMove(event); 2193 DoDragAfterMouseMove(event);
2200 } 2194 }
2201 } 2195 }
2202 2196
2203 void EventSender::MouseLeave() { 2197 void EventSender::MouseLeave() {
2204 if (force_layout_on_events_) 2198 if (force_layout_on_events_)
2205 widget()->updateAllLifecyclePhases(); 2199 widget()->updateAllLifecyclePhases();
2206 2200
2207 WebMouseEvent event; 2201 WebMouseEvent event(WebInputEvent::MouseLeave,
2208 InitMouseEvent(WebInputEvent::MouseLeave, WebMouseEvent::Button::NoButton, 0, 2202 ModifiersForPointer(kRawMousePointerId),
2203 GetCurrentEventTimeSec());
2204 InitMouseEvent(WebMouseEvent::Button::NoButton, 0,
2209 current_pointer_state_[kRawMousePointerId].last_pos_, 2205 current_pointer_state_[kRawMousePointerId].last_pos_,
2210 GetCurrentEventTimeSec(), click_count_, 0, &event); 2206 click_count_, &event);
2211 HandleInputEventOnViewOrPopup(event); 2207 HandleInputEventOnViewOrPopup(event);
2212 } 2208 }
2213 2209
2214 2210
2215 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { 2211 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) {
2216 delegate()->PostTask(base::Bind(&EventSender::MouseDown, 2212 delegate()->PostTask(base::Bind(&EventSender::MouseDown,
2217 weak_factory_.GetWeakPtr(), button_number, 2213 weak_factory_.GetWeakPtr(), button_number,
2218 modifiers)); 2214 modifiers));
2219 delegate()->PostTask(base::Bind(&EventSender::MouseUp, 2215 delegate()->PostTask(base::Bind(&EventSender::MouseUp,
2220 weak_factory_.GetWeakPtr(), button_number, 2216 weak_factory_.GetWeakPtr(), button_number,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2266 gin::Arguments* args) { 2262 gin::Arguments* args) {
2267 bool moved_beyond_slop_region; 2263 bool moved_beyond_slop_region;
2268 uint32_t unique_touch_event_id; 2264 uint32_t unique_touch_event_id;
2269 GetOptionalTouchArgs(args, moved_beyond_slop_region, unique_touch_event_id); 2265 GetOptionalTouchArgs(args, moved_beyond_slop_region, unique_touch_event_id);
2270 2266
2271 DCHECK_GT(static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap), 2267 DCHECK_GT(static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap),
2272 touch_points_.size()); 2268 touch_points_.size());
2273 if (force_layout_on_events_) 2269 if (force_layout_on_events_)
2274 widget()->updateAllLifecyclePhases(); 2270 widget()->updateAllLifecyclePhases();
2275 2271
2276 WebTouchEvent touch_event; 2272 WebTouchEvent touch_event(type, touch_modifiers_, GetCurrentEventTimeSec());
2277 touch_event.type = type;
2278 touch_event.modifiers = touch_modifiers_;
2279 touch_event.dispatchType = touch_cancelable_ 2273 touch_event.dispatchType = touch_cancelable_
2280 ? WebInputEvent::Blocking 2274 ? WebInputEvent::Blocking
2281 : WebInputEvent::EventNonBlocking; 2275 : WebInputEvent::EventNonBlocking;
2282 touch_event.timeStampSeconds = GetCurrentEventTimeSec();
2283 touch_event.movedBeyondSlopRegion = moved_beyond_slop_region; 2276 touch_event.movedBeyondSlopRegion = moved_beyond_slop_region;
2284 touch_event.uniqueTouchEventId = unique_touch_event_id; 2277 touch_event.uniqueTouchEventId = unique_touch_event_id;
2285 touch_event.touchesLength = touch_points_.size(); 2278 touch_event.touchesLength = touch_points_.size();
2286 for (size_t i = 0; i < touch_points_.size(); ++i) 2279 for (size_t i = 0; i < touch_points_.size(); ++i)
2287 touch_event.touches[i] = touch_points_[i]; 2280 touch_event.touches[i] = touch_points_[i];
2288 HandleInputEventOnViewOrPopup(touch_event); 2281 HandleInputEventOnViewOrPopup(touch_event);
2289 2282
2290 for (size_t i = 0; i < touch_points_.size(); ++i) { 2283 for (size_t i = 0; i < touch_points_.size(); ++i) {
2291 WebTouchPoint* touch_point = &touch_points_[i]; 2284 WebTouchPoint* touch_point = &touch_points_[i];
2292 if (touch_point->state == WebTouchPoint::StateReleased 2285 if (touch_point->state == WebTouchPoint::StateReleased
2293 || touch_point->state == WebTouchPoint::StateCancelled) { 2286 || touch_point->state == WebTouchPoint::StateCancelled) {
2294 touch_points_.erase(touch_points_.begin() + i); 2287 touch_points_.erase(touch_points_.begin() + i);
2295 --i; 2288 --i;
2296 } else { 2289 } else {
2297 touch_point->state = WebTouchPoint::StateStationary; 2290 touch_point->state = WebTouchPoint::StateStationary;
2298 } 2291 }
2299 } 2292 }
2300 } 2293 }
2301 2294
2302 void EventSender::GestureEvent(WebInputEvent::Type type, 2295 void EventSender::GestureEvent(WebInputEvent::Type type,
2303 gin::Arguments* args) { 2296 gin::Arguments* args) {
2304 WebGestureEvent event; 2297 WebGestureEvent event(type, WebInputEvent::NoModifiers,
2305 event.type = type; 2298 GetCurrentEventTimeSec());
2306 2299
2307 // If the first argument is a string, it is to specify the device, otherwise 2300 // If the first argument is a string, it is to specify the device, otherwise
2308 // the device is assumed to be a touchscreen (since most tests were written 2301 // the device is assumed to be a touchscreen (since most tests were written
2309 // assuming this). 2302 // assuming this).
2310 event.sourceDevice = blink::WebGestureDeviceTouchscreen; 2303 event.sourceDevice = blink::WebGestureDeviceTouchscreen;
2311 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) { 2304 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) {
2312 std::string device_string; 2305 std::string device_string;
2313 if (!args->GetNext(&device_string)) { 2306 if (!args->GetNext(&device_string)) {
2314 args->ThrowError(); 2307 args->ThrowError();
2315 return; 2308 return;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 } 2513 }
2521 break; 2514 break;
2522 default: 2515 default:
2523 NOTREACHED(); 2516 NOTREACHED();
2524 } 2517 }
2525 2518
2526 event.uniqueTouchEventId = GetUniqueTouchEventId(args); 2519 event.uniqueTouchEventId = GetUniqueTouchEventId(args);
2527 2520
2528 event.globalX = event.x; 2521 event.globalX = event.x;
2529 event.globalY = event.y; 2522 event.globalY = event.y;
2530 event.timeStampSeconds = GetCurrentEventTimeSec();
2531 2523
2532 if (force_layout_on_events_) 2524 if (force_layout_on_events_)
2533 widget()->updateAllLifecyclePhases(); 2525 widget()->updateAllLifecyclePhases();
2534 2526
2535 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); 2527 WebInputEventResult result = HandleInputEventOnViewOrPopup(event);
2536 2528
2537 // Long press might start a drag drop session. Complete it if so. 2529 // Long press might start a drag drop session. Complete it if so.
2538 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { 2530 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) {
2539 WebMouseEvent mouse_event; 2531 WebMouseEvent mouse_event(WebInputEvent::MouseDown,
2540 InitMouseEvent(WebInputEvent::MouseDown, 2532 ModifiersForPointer(kRawMousePointerId),
2541 current_pointer_state_[kRawMousePointerId].pressed_button_, 2533 GetCurrentEventTimeSec());
2534
2535 InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_,
2542 current_pointer_state_[kRawMousePointerId].current_buttons_, 2536 current_pointer_state_[kRawMousePointerId].current_buttons_,
2543 WebPoint(x, y), GetCurrentEventTimeSec(), click_count_, 2537 WebPoint(x, y), click_count_, &mouse_event);
2544 current_pointer_state_[kRawMousePointerId].modifiers_,
2545 &mouse_event);
2546 2538
2547 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); 2539 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone);
2548 } 2540 }
2549 args->Return(result != WebInputEventResult::NotHandled); 2541 args->Return(result != WebInputEventResult::NotHandled);
2550 } 2542 }
2551 2543
2552 void EventSender::UpdateClickCountForButton( 2544 void EventSender::UpdateClickCountForButton(
2553 WebMouseEvent::Button button_type) { 2545 WebMouseEvent::Button button_type) {
2554 if ((GetCurrentEventTimeSec() - last_click_time_sec_ < 2546 if ((GetCurrentEventTimeSec() - last_click_time_sec_ <
2555 kMultipleClickTimeSec) && 2547 kMultipleClickTimeSec) &&
2556 (!OutsideMultiClickRadius( 2548 (!OutsideMultiClickRadius(
2557 current_pointer_state_[kRawMousePointerId].last_pos_, 2549 current_pointer_state_[kRawMousePointerId].last_pos_,
2558 last_click_pos_)) && 2550 last_click_pos_)) &&
2559 (button_type == last_button_type_)) { 2551 (button_type == last_button_type_)) {
2560 ++click_count_; 2552 ++click_count_;
2561 } else { 2553 } else {
2562 click_count_ = 1; 2554 click_count_ = 1;
2563 last_button_type_ = button_type; 2555 last_button_type_ = button_type;
2564 } 2556 }
2565 } 2557 }
2566 2558
2567 void EventSender::InitMouseWheelEvent(gin::Arguments* args, 2559 WebMouseWheelEvent EventSender::GetMouseWheelEvent(gin::Arguments* args,
2568 MouseScrollType scroll_type, 2560 MouseScrollType scroll_type,
2569 WebMouseWheelEvent* event, 2561 bool* send_gestures) {
2570 bool* send_gestures) {
2571 // Force a layout here just to make sure every position has been 2562 // Force a layout here just to make sure every position has been
2572 // determined before we send events (as well as all the other methods 2563 // determined before we send events (as well as all the other methods
2573 // that send an event do). 2564 // that send an event do).
2574 if (force_layout_on_events_) 2565 if (force_layout_on_events_)
2575 widget()->updateAllLifecyclePhases(); 2566 widget()->updateAllLifecyclePhases();
2576 2567
2577 double horizontal; 2568 double horizontal;
2578 if (!args->GetNext(&horizontal)) { 2569 double vertical;
2570 if (!args->GetNext(&horizontal) || !args->GetNext(&vertical)) {
2579 args->ThrowError(); 2571 args->ThrowError();
2580 return; 2572 return WebMouseWheelEvent();
2581 }
2582 double vertical;
2583 if (!args->GetNext(&vertical)) {
2584 args->ThrowError();
2585 return;
2586 } 2573 }
2587 2574
2588 bool paged = false; 2575 bool paged = false;
2589 bool has_precise_scrolling_deltas = false; 2576 bool has_precise_scrolling_deltas = false;
2590 int modifiers = 0; 2577 int modifiers = 0;
2591 WebMouseWheelEvent::Phase phase = WebMouseWheelEvent::PhaseNone; 2578 WebMouseWheelEvent::Phase phase = WebMouseWheelEvent::PhaseNone;
2592 if (!args->PeekNext().IsEmpty()) { 2579 if (!args->PeekNext().IsEmpty()) {
2593 args->GetNext(&paged); 2580 args->GetNext(&paged);
2594 if (!args->PeekNext().IsEmpty()) { 2581 if (!args->PeekNext().IsEmpty()) {
2595 args->GetNext(&has_precise_scrolling_deltas); 2582 args->GetNext(&has_precise_scrolling_deltas);
2596 if (!args->PeekNext().IsEmpty()) { 2583 if (!args->PeekNext().IsEmpty()) {
2597 v8::Local<v8::Value> value; 2584 v8::Local<v8::Value> value;
2598 args->GetNext(&value); 2585 args->GetNext(&value);
2599 modifiers = GetKeyModifiersFromV8(args->isolate(), value); 2586 modifiers = GetKeyModifiersFromV8(args->isolate(), value);
2600 if (!args->PeekNext().IsEmpty()) { 2587 if (!args->PeekNext().IsEmpty()) {
2601 args->GetNext(send_gestures); 2588 args->GetNext(send_gestures);
2602 if (!args->PeekNext().IsEmpty()) { 2589 if (!args->PeekNext().IsEmpty()) {
2603 v8::Local<v8::Value> phase_value; 2590 v8::Local<v8::Value> phase_value;
2604 args->GetNext(&phase_value); 2591 args->GetNext(&phase_value);
2605 phase = GetMouseWheelEventPhaseFromV8(phase_value); 2592 phase = GetMouseWheelEventPhaseFromV8(phase_value);
2606 } 2593 }
2607 } 2594 }
2608 } 2595 }
2609 } 2596 }
2610 } 2597 }
2611 2598
2612 InitMouseEvent(WebInputEvent::MouseWheel, 2599 current_pointer_state_[kRawMousePointerId].modifiers_ = modifiers;
2613 current_pointer_state_[kRawMousePointerId].pressed_button_, 2600 WebMouseWheelEvent event(WebInputEvent::MouseWheel,
2601 ModifiersForPointer(kRawMousePointerId),
2602 GetCurrentEventTimeSec());
2603 InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_,
2614 current_pointer_state_[kRawMousePointerId].current_buttons_, 2604 current_pointer_state_[kRawMousePointerId].current_buttons_,
2615 current_pointer_state_[kRawMousePointerId].last_pos_, 2605 current_pointer_state_[kRawMousePointerId].last_pos_,
2616 GetCurrentEventTimeSec(), click_count_, modifiers, event); 2606 click_count_, &event);
2617 event->wheelTicksX = static_cast<float>(horizontal); 2607 event.wheelTicksX = static_cast<float>(horizontal);
2618 event->wheelTicksY = static_cast<float>(vertical); 2608 event.wheelTicksY = static_cast<float>(vertical);
2619 event->deltaX = event->wheelTicksX; 2609 event.deltaX = event.wheelTicksX;
2620 event->deltaY = event->wheelTicksY; 2610 event.deltaY = event.wheelTicksY;
2621 event->scrollByPage = paged; 2611 event.scrollByPage = paged;
2622 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; 2612 event.hasPreciseScrollingDeltas = has_precise_scrolling_deltas;
2623 event->phase = phase; 2613 event.phase = phase;
2624 if (scroll_type == MouseScrollType::PIXEL) { 2614 if (scroll_type == MouseScrollType::PIXEL) {
2625 event->wheelTicksX /= kScrollbarPixelsPerTick; 2615 event.wheelTicksX /= kScrollbarPixelsPerTick;
2626 event->wheelTicksY /= kScrollbarPixelsPerTick; 2616 event.wheelTicksY /= kScrollbarPixelsPerTick;
2627 } else { 2617 } else {
2628 event->deltaX *= kScrollbarPixelsPerTick; 2618 event.deltaX *= kScrollbarPixelsPerTick;
2629 event->deltaY *= kScrollbarPixelsPerTick; 2619 event.deltaY *= kScrollbarPixelsPerTick;
2630 } 2620 }
2621 return event;
2631 } 2622 }
2632 2623
2633 // Radius fields radius_x and radius_y should eventually be moved to 2624 // Radius fields radius_x and radius_y should eventually be moved to
2634 // WebPointerProperties. 2625 // WebPointerProperties.
2635 // TODO(e_hakkinen): Drop radius_{x,y}_pointer parameters once that happens. 2626 // TODO(e_hakkinen): Drop radius_{x,y}_pointer parameters once that happens.
2636 void EventSender::InitPointerProperties(gin::Arguments* args, 2627 void EventSender::InitPointerProperties(gin::Arguments* args,
2637 WebPointerProperties* e, 2628 WebPointerProperties* e,
2638 float* radius_x_pointer, 2629 float* radius_x_pointer,
2639 float* radius_y_pointer) { 2630 float* radius_y_pointer) {
2640 if (!args->PeekNext().IsEmpty()) { 2631 if (!args->PeekNext().IsEmpty()) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
2752 } 2743 }
2753 2744
2754 void EventSender::ReplaySavedEvents() { 2745 void EventSender::ReplaySavedEvents() {
2755 replaying_saved_events_ = true; 2746 replaying_saved_events_ = true;
2756 while (!mouse_event_queue_.empty()) { 2747 while (!mouse_event_queue_.empty()) {
2757 SavedEvent e = mouse_event_queue_.front(); 2748 SavedEvent e = mouse_event_queue_.front();
2758 mouse_event_queue_.pop_front(); 2749 mouse_event_queue_.pop_front();
2759 2750
2760 switch (e.type) { 2751 switch (e.type) {
2761 case SavedEvent::TYPE_MOUSE_MOVE: { 2752 case SavedEvent::TYPE_MOUSE_MOVE: {
2762 WebMouseEvent event; 2753 current_pointer_state_[kRawMousePointerId].modifiers_ = e.modifiers;
2754 WebMouseEvent event(WebInputEvent::MouseMove,
2755 ModifiersForPointer(kRawMousePointerId),
2756 GetCurrentEventTimeSec());
2763 InitMouseEvent( 2757 InitMouseEvent(
2764 WebInputEvent::MouseMove,
2765 current_pointer_state_[kRawMousePointerId].pressed_button_, 2758 current_pointer_state_[kRawMousePointerId].pressed_button_,
2766 current_pointer_state_[kRawMousePointerId].current_buttons_, e.pos, 2759 current_pointer_state_[kRawMousePointerId].current_buttons_, e.pos,
2767 GetCurrentEventTimeSec(), click_count_, e.modifiers, &event); 2760 click_count_, &event);
2768 current_pointer_state_[kRawMousePointerId].last_pos_ = 2761 current_pointer_state_[kRawMousePointerId].last_pos_ =
2769 WebPoint(event.x, event.y); 2762 WebPoint(event.x, event.y);
2770 HandleInputEventOnViewOrPopup(event); 2763 HandleInputEventOnViewOrPopup(event);
2771 DoDragAfterMouseMove(event); 2764 DoDragAfterMouseMove(event);
2772 break; 2765 break;
2773 } 2766 }
2774 case SavedEvent::TYPE_LEAP_FORWARD: 2767 case SavedEvent::TYPE_LEAP_FORWARD:
2775 DoLeapForward(e.milliseconds); 2768 DoLeapForward(e.milliseconds);
2776 break; 2769 break;
2777 case SavedEvent::TYPE_MOUSE_UP: { 2770 case SavedEvent::TYPE_MOUSE_UP: {
2778 current_pointer_state_[kRawMousePointerId].current_buttons_ &= 2771 current_pointer_state_[kRawMousePointerId].current_buttons_ &=
2779 ~GetWebMouseEventModifierForButton(e.button_type); 2772 ~GetWebMouseEventModifierForButton(e.button_type);
2780 current_pointer_state_[kRawMousePointerId].pressed_button_ = 2773 current_pointer_state_[kRawMousePointerId].pressed_button_ =
2781 WebMouseEvent::Button::NoButton; 2774 WebMouseEvent::Button::NoButton;
2775 current_pointer_state_[kRawMousePointerId].modifiers_ = e.modifiers;
2782 2776
2783 WebMouseEvent event; 2777 WebMouseEvent event(WebInputEvent::MouseUp,
2778 ModifiersForPointer(kRawMousePointerId),
2779 GetCurrentEventTimeSec());
2784 InitMouseEvent( 2780 InitMouseEvent(
2785 WebInputEvent::MouseUp, e.button_type, 2781 e.button_type,
2786 current_pointer_state_[kRawMousePointerId].current_buttons_, 2782 current_pointer_state_[kRawMousePointerId].current_buttons_,
2787 current_pointer_state_[kRawMousePointerId].last_pos_, 2783 current_pointer_state_[kRawMousePointerId].last_pos_, click_count_,
2788 GetCurrentEventTimeSec(), click_count_, e.modifiers, &event); 2784 &event);
2789 HandleInputEventOnViewOrPopup(event); 2785 HandleInputEventOnViewOrPopup(event);
2790 DoDragAfterMouseUp(event); 2786 DoDragAfterMouseUp(event);
2791 break; 2787 break;
2792 } 2788 }
2793 default: 2789 default:
2794 NOTREACHED(); 2790 NOTREACHED();
2795 } 2791 }
2796 } 2792 }
2797 2793
2798 replaying_saved_events_ = false; 2794 replaying_saved_events_ = false;
(...skipping 17 matching lines...) Expand all
2816 std::unique_ptr<WebInputEvent> widget_event = 2812 std::unique_ptr<WebInputEvent> widget_event =
2817 TransformScreenToWidgetCoordinates(raw_event); 2813 TransformScreenToWidgetCoordinates(raw_event);
2818 const WebInputEvent* event = 2814 const WebInputEvent* event =
2819 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) 2815 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2820 : &raw_event; 2816 : &raw_event;
2821 return widget()->handleInputEvent(*event); 2817 return widget()->handleInputEvent(*event);
2822 } 2818 }
2823 2819
2824 void EventSender::SendGesturesForMouseWheelEvent( 2820 void EventSender::SendGesturesForMouseWheelEvent(
2825 const WebMouseWheelEvent wheel_event) { 2821 const WebMouseWheelEvent wheel_event) {
2826 WebGestureEvent begin_event; 2822 WebGestureEvent begin_event(WebInputEvent::GestureScrollBegin,
2827 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollBegin, 2823 wheel_event.modifiers, GetCurrentEventTimeSec());
2828 GetCurrentEventTimeSec(), wheel_event, 2824 InitGestureEventFromMouseWheel(wheel_event, &begin_event);
2829 &begin_event);
2830 begin_event.data.scrollBegin.deltaXHint = wheel_event.deltaX; 2825 begin_event.data.scrollBegin.deltaXHint = wheel_event.deltaX;
2831 begin_event.data.scrollBegin.deltaYHint = wheel_event.deltaY; 2826 begin_event.data.scrollBegin.deltaYHint = wheel_event.deltaY;
2832 if (wheel_event.scrollByPage) { 2827 if (wheel_event.scrollByPage) {
2833 begin_event.data.scrollBegin.deltaHintUnits = blink::WebGestureEvent::Page; 2828 begin_event.data.scrollBegin.deltaHintUnits = blink::WebGestureEvent::Page;
2834 if (begin_event.data.scrollBegin.deltaXHint) { 2829 if (begin_event.data.scrollBegin.deltaXHint) {
2835 begin_event.data.scrollBegin.deltaXHint = 2830 begin_event.data.scrollBegin.deltaXHint =
2836 begin_event.data.scrollBegin.deltaXHint > 0 ? 1 : -1; 2831 begin_event.data.scrollBegin.deltaXHint > 0 ? 1 : -1;
2837 } 2832 }
2838 if (begin_event.data.scrollBegin.deltaYHint) { 2833 if (begin_event.data.scrollBegin.deltaYHint) {
2839 begin_event.data.scrollBegin.deltaYHint = 2834 begin_event.data.scrollBegin.deltaYHint =
2840 begin_event.data.scrollBegin.deltaYHint > 0 ? 1 : -1; 2835 begin_event.data.scrollBegin.deltaYHint > 0 ? 1 : -1;
2841 } 2836 }
2842 } else { 2837 } else {
2843 begin_event.data.scrollBegin.deltaHintUnits = 2838 begin_event.data.scrollBegin.deltaHintUnits =
2844 wheel_event.hasPreciseScrollingDeltas 2839 wheel_event.hasPreciseScrollingDeltas
2845 ? blink::WebGestureEvent::PrecisePixels 2840 ? blink::WebGestureEvent::PrecisePixels
2846 : blink::WebGestureEvent::Pixels; 2841 : blink::WebGestureEvent::Pixels;
2847 } 2842 }
2848 2843
2849 if (force_layout_on_events_) 2844 if (force_layout_on_events_)
2850 widget()->updateAllLifecyclePhases(); 2845 widget()->updateAllLifecyclePhases();
2851 2846
2852 HandleInputEventOnViewOrPopup(begin_event); 2847 HandleInputEventOnViewOrPopup(begin_event);
2853 2848
2854 WebGestureEvent update_event; 2849 WebGestureEvent update_event(WebInputEvent::GestureScrollUpdate,
2855 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollUpdate, 2850 wheel_event.modifiers, GetCurrentEventTimeSec());
2856 GetCurrentEventTimeSec(), wheel_event, 2851 InitGestureEventFromMouseWheel(wheel_event, &update_event);
2857 &update_event);
2858 update_event.data.scrollUpdate.deltaX = 2852 update_event.data.scrollUpdate.deltaX =
2859 begin_event.data.scrollBegin.deltaXHint; 2853 begin_event.data.scrollBegin.deltaXHint;
2860 update_event.data.scrollUpdate.deltaY = 2854 update_event.data.scrollUpdate.deltaY =
2861 begin_event.data.scrollBegin.deltaYHint; 2855 begin_event.data.scrollBegin.deltaYHint;
2862 update_event.data.scrollUpdate.deltaUnits = 2856 update_event.data.scrollUpdate.deltaUnits =
2863 begin_event.data.scrollBegin.deltaHintUnits; 2857 begin_event.data.scrollBegin.deltaHintUnits;
2864 2858
2865 if (force_layout_on_events_) 2859 if (force_layout_on_events_)
2866 widget()->updateAllLifecyclePhases(); 2860 widget()->updateAllLifecyclePhases();
2867 HandleInputEventOnViewOrPopup(update_event); 2861 HandleInputEventOnViewOrPopup(update_event);
2868 2862
2869 WebGestureEvent end_event; 2863 WebGestureEvent end_event(WebInputEvent::GestureScrollEnd,
2870 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollEnd, 2864 wheel_event.modifiers, GetCurrentEventTimeSec());
2871 GetCurrentEventTimeSec(), wheel_event, 2865 InitGestureEventFromMouseWheel(wheel_event, &end_event);
2872 &end_event);
2873 end_event.data.scrollEnd.deltaUnits = 2866 end_event.data.scrollEnd.deltaUnits =
2874 begin_event.data.scrollBegin.deltaHintUnits; 2867 begin_event.data.scrollBegin.deltaHintUnits;
2875 2868
2876 if (force_layout_on_events_) 2869 if (force_layout_on_events_)
2877 widget()->updateAllLifecyclePhases(); 2870 widget()->updateAllLifecyclePhases();
2878 HandleInputEventOnViewOrPopup(end_event); 2871 HandleInputEventOnViewOrPopup(end_event);
2879 } 2872 }
2880 2873
2881 TestInterfaces* EventSender::interfaces() { 2874 TestInterfaces* EventSender::interfaces() {
2882 return web_widget_test_proxy_base_->web_view_test_proxy_base() 2875 return web_widget_test_proxy_base_->web_view_test_proxy_base()
(...skipping 20 matching lines...) Expand all
2903 return view()->mainFrame()->toWebLocalFrame()->frameWidget(); 2896 return view()->mainFrame()->toWebLocalFrame()->frameWidget();
2904 } 2897 }
2905 2898
2906 std::unique_ptr<WebInputEvent> EventSender::TransformScreenToWidgetCoordinates( 2899 std::unique_ptr<WebInputEvent> EventSender::TransformScreenToWidgetCoordinates(
2907 const WebInputEvent& event) { 2900 const WebInputEvent& event) {
2908 return delegate()->TransformScreenToWidgetCoordinates( 2901 return delegate()->TransformScreenToWidgetCoordinates(
2909 web_widget_test_proxy_base_, event); 2902 web_widget_test_proxy_base_, event);
2910 } 2903 }
2911 2904
2912 } // namespace test_runner 2905 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698