Chromium Code Reviews| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 using blink::WebString; | 51 using blink::WebString; |
| 52 using blink::WebTouchEvent; | 52 using blink::WebTouchEvent; |
| 53 using blink::WebTouchPoint; | 53 using blink::WebTouchPoint; |
| 54 using blink::WebVector; | 54 using blink::WebVector; |
| 55 using blink::WebView; | 55 using blink::WebView; |
| 56 | 56 |
| 57 namespace test_runner { | 57 namespace test_runner { |
| 58 | 58 |
| 59 namespace { | 59 namespace { |
| 60 | 60 |
| 61 const char* kPointerTypeStringUnknown = ""; | |
| 62 const char* kPointerTypeStringMouse = "mouse"; | |
| 63 const char* kPointerTypeStringPen = "pen"; | |
| 64 const char* kPointerTypeStringTouch = "touch"; | |
| 65 | |
|
dtapuska
2016/04/05 20:30:40
I'd invert the function to return false on failure
Navid Zolghadr
2016/04/06 15:27:10
Sure
| |
| 66 bool getPointerType(gin::Arguments* args, | |
| 67 blink::WebPointerProperties::PointerType &t, | |
| 68 bool isOnlyMouseAndPenAllowed = false) { | |
| 69 if (!args->PeekNext().IsEmpty()) { | |
| 70 std::string pointer_type_string; | |
| 71 if (!args->GetNext(&pointer_type_string)) { | |
| 72 args->ThrowError(); | |
| 73 return true; | |
| 74 } | |
| 75 if (pointer_type_string == kPointerTypeStringUnknown) { | |
| 76 if (isOnlyMouseAndPenAllowed) { | |
| 77 args->ThrowError(); | |
| 78 return true; | |
| 79 } | |
| 80 t = WebMouseEvent::PointerType::Unknown; | |
| 81 } else if (pointer_type_string == kPointerTypeStringMouse) { | |
| 82 t = WebMouseEvent::PointerType::Mouse; | |
| 83 } else if (pointer_type_string == kPointerTypeStringPen) { | |
| 84 t = WebMouseEvent::PointerType::Pen; | |
| 85 } else if (pointer_type_string == kPointerTypeStringTouch) { | |
| 86 if (isOnlyMouseAndPenAllowed) { | |
| 87 args->ThrowError(); | |
| 88 return true; | |
| 89 } | |
| 90 t = WebMouseEvent::PointerType::Touch; | |
| 91 } else { | |
| 92 args->ThrowError(); | |
| 93 return true; | |
| 94 } | |
| 95 } | |
| 96 return false; | |
| 97 } | |
| 98 | |
| 61 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { | 99 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { |
| 62 switch (button_code) { | 100 switch (button_code) { |
| 63 case -1: | 101 case -1: |
| 64 return WebMouseEvent::ButtonNone; | 102 return WebMouseEvent::ButtonNone; |
| 65 case 0: | 103 case 0: |
| 66 return WebMouseEvent::ButtonLeft; | 104 return WebMouseEvent::ButtonLeft; |
| 67 case 1: | 105 case 1: |
| 68 return WebMouseEvent::ButtonMiddle; | 106 return WebMouseEvent::ButtonMiddle; |
| 69 case 2: | 107 case 2: |
| 70 return WebMouseEvent::ButtonRight; | 108 return WebMouseEvent::ButtonRight; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 96 | (buttons & kButtonsInModifiers); | 134 | (buttons & kButtonsInModifiers); |
| 97 } | 135 } |
| 98 | 136 |
| 99 void InitMouseEvent(WebInputEvent::Type t, | 137 void InitMouseEvent(WebInputEvent::Type t, |
| 100 WebMouseEvent::Button b, | 138 WebMouseEvent::Button b, |
| 101 int current_buttons, | 139 int current_buttons, |
| 102 const WebPoint& pos, | 140 const WebPoint& pos, |
| 103 double time_stamp, | 141 double time_stamp, |
| 104 int click_count, | 142 int click_count, |
| 105 int modifiers, | 143 int modifiers, |
| 144 blink::WebPointerProperties::PointerType pointerType, | |
| 145 int pointerId, | |
| 106 WebMouseEvent* e) { | 146 WebMouseEvent* e) { |
| 107 e->type = t; | 147 e->type = t; |
| 108 e->button = b; | 148 e->button = b; |
| 109 e->modifiers = modifiersWithButtons(modifiers, current_buttons); | 149 e->modifiers = modifiersWithButtons(modifiers, current_buttons); |
| 110 e->x = pos.x; | 150 e->x = pos.x; |
| 111 e->y = pos.y; | 151 e->y = pos.y; |
| 112 e->globalX = pos.x; | 152 e->globalX = pos.x; |
| 113 e->globalY = pos.y; | 153 e->globalY = pos.y; |
| 114 e->pointerType = blink::WebPointerProperties::PointerType::Mouse; | 154 e->pointerType = pointerType; |
| 155 e->id = pointerId; | |
| 115 e->timeStampSeconds = time_stamp; | 156 e->timeStampSeconds = time_stamp; |
| 116 e->clickCount = click_count; | 157 e->clickCount = click_count; |
| 117 } | 158 } |
| 118 | 159 |
| 119 void InitGestureEventFromMouseWheel(WebInputEvent::Type type, | 160 void InitGestureEventFromMouseWheel(WebInputEvent::Type type, |
| 120 double time_stamp, | 161 double time_stamp, |
| 121 const WebMouseWheelEvent& wheel_event, | 162 const WebMouseWheelEvent& wheel_event, |
| 122 WebGestureEvent* gesture_event) { | 163 WebGestureEvent* gesture_event) { |
| 123 gesture_event->type = type; | 164 gesture_event->type = type; |
| 124 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad; | 165 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 } | 489 } |
| 449 } else { | 490 } else { |
| 450 *units = WebGestureEvent::PrecisePixels; | 491 *units = WebGestureEvent::PrecisePixels; |
| 451 return true; | 492 return true; |
| 452 } | 493 } |
| 453 } | 494 } |
| 454 | 495 |
| 455 const char* kSourceDeviceStringTouchpad = "touchpad"; | 496 const char* kSourceDeviceStringTouchpad = "touchpad"; |
| 456 const char* kSourceDeviceStringTouchscreen = "touchscreen"; | 497 const char* kSourceDeviceStringTouchscreen = "touchscreen"; |
| 457 | 498 |
| 458 const char* kPointerTypeStringUnknown = ""; | |
| 459 const char* kPointerTypeStringMouse = "mouse"; | |
| 460 const char* kPointerTypeStringPen = "pen"; | |
| 461 const char* kPointerTypeStringTouch = "touch"; | |
| 462 | |
| 463 } // namespace | 499 } // namespace |
| 464 | 500 |
| 465 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { | 501 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { |
| 466 public: | 502 public: |
| 467 static gin::WrapperInfo kWrapperInfo; | 503 static gin::WrapperInfo kWrapperInfo; |
| 468 | 504 |
| 469 static void Install(base::WeakPtr<EventSender> sender, | 505 static void Install(base::WeakPtr<EventSender> sender, |
| 470 blink::WebFrame* frame); | 506 blink::WebFrame* frame); |
| 471 | 507 |
| 472 private: | 508 private: |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 971 sender_->ScheduleAsynchronousKeyDown(code_str, modifiers, | 1007 sender_->ScheduleAsynchronousKeyDown(code_str, modifiers, |
| 972 static_cast<KeyLocationCode>(location)); | 1008 static_cast<KeyLocationCode>(location)); |
| 973 } | 1009 } |
| 974 | 1010 |
| 975 void EventSenderBindings::MouseDown(gin::Arguments* args) { | 1011 void EventSenderBindings::MouseDown(gin::Arguments* args) { |
| 976 if (!sender_) | 1012 if (!sender_) |
| 977 return; | 1013 return; |
| 978 | 1014 |
| 979 int button_number = 0; | 1015 int button_number = 0; |
| 980 int modifiers = 0; | 1016 int modifiers = 0; |
| 1017 blink::WebPointerProperties::PointerType pointerType = | |
| 1018 blink::WebPointerProperties::PointerType::Mouse; | |
| 1019 int pointerId = 0; | |
| 981 if (!args->PeekNext().IsEmpty()) { | 1020 if (!args->PeekNext().IsEmpty()) { |
| 982 args->GetNext(&button_number); | 1021 if (!args->GetNext(&button_number)) { |
| 983 if (!args->PeekNext().IsEmpty()) | 1022 args->ThrowError(); |
| 1023 return; | |
| 1024 } | |
| 1025 if (!args->PeekNext().IsEmpty()) { | |
| 984 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); | 1026 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
| 1027 args->Skip(); | |
| 1028 } | |
| 985 } | 1029 } |
| 986 sender_->MouseDown(button_number, modifiers); | 1030 |
| 1031 // Only allow pen or mouse through this API. | |
| 1032 if (getPointerType(args, pointerType, true)) | |
| 1033 return; | |
| 1034 if (!args->PeekNext().IsEmpty()) { | |
| 1035 if (!args->GetNext(&pointerId)) { | |
| 1036 args->ThrowError(); | |
| 1037 return; | |
| 1038 } | |
| 1039 } | |
| 1040 | |
| 1041 sender_->MouseDown(button_number, modifiers, pointerType, pointerId); | |
| 987 } | 1042 } |
| 988 | 1043 |
| 989 void EventSenderBindings::MouseUp(gin::Arguments* args) { | 1044 void EventSenderBindings::MouseUp(gin::Arguments* args) { |
| 990 if (!sender_) | 1045 if (!sender_) |
| 991 return; | 1046 return; |
| 992 | 1047 |
| 993 int button_number = 0; | 1048 int button_number = 0; |
| 994 int modifiers = 0; | 1049 int modifiers = 0; |
| 1050 blink::WebPointerProperties::PointerType pointerType = | |
| 1051 blink::WebPointerProperties::PointerType::Mouse; | |
| 1052 int pointerId = 0; | |
| 995 if (!args->PeekNext().IsEmpty()) { | 1053 if (!args->PeekNext().IsEmpty()) { |
| 996 args->GetNext(&button_number); | 1054 if (!args->GetNext(&button_number)) { |
| 997 if (!args->PeekNext().IsEmpty()) | 1055 args->ThrowError(); |
| 1056 return; | |
| 1057 } | |
| 1058 if (!args->PeekNext().IsEmpty()) { | |
| 998 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); | 1059 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
| 1060 args->Skip(); | |
| 1061 } | |
| 999 } | 1062 } |
| 1000 sender_->MouseUp(button_number, modifiers); | 1063 |
| 1064 // Only allow pen or mouse through this API. | |
| 1065 if (getPointerType(args, pointerType)) | |
| 1066 return; | |
| 1067 if (!args->PeekNext().IsEmpty()) { | |
| 1068 if (!args->GetNext(&pointerId)) { | |
| 1069 args->ThrowError(); | |
| 1070 return; | |
| 1071 } | |
| 1072 } | |
| 1073 | |
| 1074 sender_->MouseUp(button_number, modifiers, pointerType, pointerId); | |
| 1001 } | 1075 } |
| 1002 | 1076 |
| 1003 void EventSenderBindings::SetMouseButtonState(gin::Arguments* args) { | 1077 void EventSenderBindings::SetMouseButtonState(gin::Arguments* args) { |
| 1004 if (!sender_) | 1078 if (!sender_) |
| 1005 return; | 1079 return; |
| 1006 | 1080 |
| 1007 int button_number; | 1081 int button_number; |
| 1008 if (!args->GetNext(&button_number)) { | 1082 if (!args->GetNext(&button_number)) { |
| 1009 args->ThrowError(); | 1083 args->ThrowError(); |
| 1010 return; | 1084 return; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1196 | 1270 |
| 1197 EventSender::~EventSender() {} | 1271 EventSender::~EventSender() {} |
| 1198 | 1272 |
| 1199 void EventSender::Reset() { | 1273 void EventSender::Reset() { |
| 1200 DCHECK(current_drag_data_.isNull()); | 1274 DCHECK(current_drag_data_.isNull()); |
| 1201 current_drag_data_.reset(); | 1275 current_drag_data_.reset(); |
| 1202 current_drag_effect_ = blink::WebDragOperationNone; | 1276 current_drag_effect_ = blink::WebDragOperationNone; |
| 1203 current_drag_effects_allowed_ = blink::WebDragOperationNone; | 1277 current_drag_effects_allowed_ = blink::WebDragOperationNone; |
| 1204 if (view_ && pressed_button_ != WebMouseEvent::ButtonNone) | 1278 if (view_ && pressed_button_ != WebMouseEvent::ButtonNone) |
| 1205 view_->mouseCaptureLost(); | 1279 view_->mouseCaptureLost(); |
| 1280 current_pen_state_.clear(); | |
| 1206 pressed_button_ = WebMouseEvent::ButtonNone; | 1281 pressed_button_ = WebMouseEvent::ButtonNone; |
| 1207 current_buttons_ = 0; | 1282 current_buttons_ = 0; |
| 1208 modifiers_ = 0; | 1283 modifiers_ = 0; |
| 1209 is_drag_mode_ = true; | 1284 is_drag_mode_ = true; |
| 1210 force_layout_on_events_ = true; | 1285 force_layout_on_events_ = true; |
| 1211 | 1286 |
| 1212 #if defined(OS_WIN) | 1287 #if defined(OS_WIN) |
| 1213 wm_key_down_ = WM_KEYDOWN; | 1288 wm_key_down_ = WM_KEYDOWN; |
| 1214 wm_key_up_ = WM_KEYUP; | 1289 wm_key_up_ = WM_KEYUP; |
| 1215 wm_char_ = WM_CHAR; | 1290 wm_char_ = WM_CHAR; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1257 void EventSender::DoDragDrop(const WebDragData& drag_data, | 1332 void EventSender::DoDragDrop(const WebDragData& drag_data, |
| 1258 WebDragOperationsMask mask) { | 1333 WebDragOperationsMask mask) { |
| 1259 WebMouseEvent event; | 1334 WebMouseEvent event; |
| 1260 InitMouseEvent(WebInputEvent::MouseDown, | 1335 InitMouseEvent(WebInputEvent::MouseDown, |
| 1261 pressed_button_, | 1336 pressed_button_, |
| 1262 current_buttons_, | 1337 current_buttons_, |
| 1263 last_mouse_pos_, | 1338 last_mouse_pos_, |
| 1264 GetCurrentEventTimeSec(), | 1339 GetCurrentEventTimeSec(), |
| 1265 click_count_, | 1340 click_count_, |
| 1266 modifiers_, | 1341 modifiers_, |
| 1342 blink::WebPointerProperties::PointerType::Mouse, | |
| 1343 0, | |
| 1267 &event); | 1344 &event); |
| 1268 WebPoint client_point(event.x, event.y); | 1345 WebPoint client_point(event.x, event.y); |
| 1269 WebPoint screen_point(event.globalX, event.globalY); | 1346 WebPoint screen_point(event.globalX, event.globalY); |
| 1270 current_drag_data_ = drag_data; | 1347 current_drag_data_ = drag_data; |
| 1271 current_drag_effects_allowed_ = mask; | 1348 current_drag_effects_allowed_ = mask; |
| 1272 current_drag_effect_ = view_->dragTargetDragEnter( | 1349 current_drag_effect_ = view_->dragTargetDragEnter( |
| 1273 drag_data, | 1350 drag_data, |
| 1274 client_point, | 1351 client_point, |
| 1275 screen_point, | 1352 screen_point, |
| 1276 current_drag_effects_allowed_, | 1353 current_drag_effects_allowed_, |
| 1277 modifiersWithButtons(modifiers_, current_buttons_)); | 1354 modifiersWithButtons(modifiers_, current_buttons_)); |
| 1278 | 1355 |
| 1279 // Finish processing events. | 1356 // Finish processing events. |
| 1280 ReplaySavedEvents(); | 1357 ReplaySavedEvents(); |
| 1281 } | 1358 } |
| 1282 | 1359 |
| 1283 void EventSender::MouseDown(int button_number, int modifiers) { | 1360 void EventSender::MouseDown(int button_number, int modifiers, |
| 1361 blink::WebPointerProperties::PointerType pointerType, int pointerId) { | |
| 1284 if (force_layout_on_events_) | 1362 if (force_layout_on_events_) |
| 1285 view_->updateAllLifecyclePhases(); | 1363 view_->updateAllLifecyclePhases(); |
| 1286 | 1364 |
| 1287 DCHECK_NE(-1, button_number); | 1365 DCHECK_NE(-1, button_number); |
| 1288 | 1366 |
| 1289 WebMouseEvent::Button button_type = | 1367 WebMouseEvent::Button button_type = |
| 1290 GetButtonTypeFromButtonNumber(button_number); | 1368 GetButtonTypeFromButtonNumber(button_number); |
| 1291 | 1369 |
| 1292 UpdateClickCountForButton(button_type); | 1370 WebMouseEvent event; |
| 1371 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) { | |
| 1372 UpdateClickCountForButton(button_type); | |
| 1293 | 1373 |
| 1294 pressed_button_ = button_type; | 1374 pressed_button_ = button_type; |
| 1295 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 1375 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); |
| 1296 modifiers_ = modifiers; | 1376 modifiers_ = modifiers; |
| 1377 InitMouseEvent(WebInputEvent::MouseDown, | |
| 1378 pressed_button_, | |
| 1379 current_buttons_, | |
| 1380 last_mouse_pos_, | |
| 1381 GetCurrentEventTimeSec(), | |
| 1382 click_count_, | |
| 1383 modifiers_, | |
| 1384 pointerType, | |
| 1385 0, | |
| 1386 &event); | |
| 1387 } else { | |
| 1388 current_pen_state_[pointerId].pressed_button_ = button_type; | |
| 1389 current_pen_state_[pointerId].current_buttons_ |= | |
| 1390 GetWebMouseEventModifierForButton(pressed_button_); | |
| 1391 current_pen_state_[pointerId].modifiers_ = modifiers; | |
| 1392 InitMouseEvent(WebInputEvent::MouseDown, | |
| 1393 current_pen_state_[pointerId].pressed_button_, | |
| 1394 current_pen_state_[pointerId].current_buttons_, | |
| 1395 current_pen_state_[pointerId].last_pos_, | |
| 1396 GetCurrentEventTimeSec(), | |
| 1397 0, | |
| 1398 modifiers_, | |
| 1399 pointerType, | |
| 1400 pointerId, | |
| 1401 &event); | |
| 1402 } | |
| 1297 | 1403 |
| 1298 WebMouseEvent event; | |
| 1299 InitMouseEvent(WebInputEvent::MouseDown, | |
| 1300 pressed_button_, | |
| 1301 current_buttons_, | |
| 1302 last_mouse_pos_, | |
| 1303 GetCurrentEventTimeSec(), | |
| 1304 click_count_, | |
| 1305 modifiers_, | |
| 1306 &event); | |
| 1307 HandleInputEventOnViewOrPopup(event); | 1404 HandleInputEventOnViewOrPopup(event); |
| 1308 } | 1405 } |
| 1309 | 1406 |
| 1310 void EventSender::MouseUp(int button_number, int modifiers) { | 1407 void EventSender::MouseUp(int button_number, int modifiers, |
| 1408 blink::WebPointerProperties::PointerType pointerType, int pointerId) { | |
| 1311 if (force_layout_on_events_) | 1409 if (force_layout_on_events_) |
| 1312 view_->updateAllLifecyclePhases(); | 1410 view_->updateAllLifecyclePhases(); |
| 1313 | 1411 |
| 1314 DCHECK_NE(-1, button_number); | 1412 DCHECK_NE(-1, button_number); |
| 1315 | 1413 |
| 1316 WebMouseEvent::Button button_type = | 1414 WebMouseEvent::Button button_type = |
| 1317 GetButtonTypeFromButtonNumber(button_number); | 1415 GetButtonTypeFromButtonNumber(button_number); |
| 1318 | 1416 |
| 1319 if (is_drag_mode_ && !replaying_saved_events_) { | 1417 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) { |
| 1320 SavedEvent saved_event; | 1418 if (is_drag_mode_ && !replaying_saved_events_) { |
| 1321 saved_event.type = SavedEvent::TYPE_MOUSE_UP; | 1419 SavedEvent saved_event; |
| 1322 saved_event.button_type = button_type; | 1420 saved_event.type = SavedEvent::TYPE_MOUSE_UP; |
| 1323 saved_event.modifiers = modifiers; | 1421 saved_event.button_type = button_type; |
| 1324 mouse_event_queue_.push_back(saved_event); | 1422 saved_event.modifiers = modifiers; |
| 1325 ReplaySavedEvents(); | 1423 mouse_event_queue_.push_back(saved_event); |
| 1424 ReplaySavedEvents(); | |
| 1425 } else { | |
| 1426 current_buttons_ &= ~GetWebMouseEventModifierForButton(button_type); | |
| 1427 pressed_button_ = WebMouseEvent::ButtonNone; | |
| 1428 | |
| 1429 WebMouseEvent event; | |
| 1430 InitMouseEvent(WebInputEvent::MouseUp, | |
| 1431 button_type, | |
| 1432 current_buttons_, | |
| 1433 last_mouse_pos_, | |
| 1434 GetCurrentEventTimeSec(), | |
| 1435 click_count_, | |
| 1436 modifiers, | |
| 1437 pointerType, | |
| 1438 0, | |
| 1439 &event); | |
| 1440 DoMouseUp(event); | |
| 1441 } | |
| 1326 } else { | 1442 } else { |
| 1327 current_buttons_ &= ~GetWebMouseEventModifierForButton(button_type); | 1443 current_pen_state_[pointerId].current_buttons_ &= |
| 1328 pressed_button_ = WebMouseEvent::ButtonNone; | 1444 ~GetWebMouseEventModifierForButton(button_type); |
| 1445 current_pen_state_[pointerId].pressed_button_ = WebMouseEvent::ButtonNone; | |
| 1329 | 1446 |
| 1330 WebMouseEvent event; | 1447 WebMouseEvent event; |
| 1331 InitMouseEvent(WebInputEvent::MouseUp, | 1448 InitMouseEvent(WebInputEvent::MouseUp, |
| 1332 button_type, | 1449 button_type, |
| 1333 current_buttons_, | 1450 current_pen_state_[pointerId].current_buttons_, |
| 1334 last_mouse_pos_, | 1451 current_pen_state_[pointerId].last_pos_, |
| 1335 GetCurrentEventTimeSec(), | 1452 GetCurrentEventTimeSec(), |
| 1336 click_count_, | 1453 0, |
| 1337 modifiers, | 1454 modifiers, |
| 1338 &event); | 1455 pointerType, |
| 1339 DoMouseUp(event); | 1456 pointerId, |
| 1457 &event); | |
| 1458 HandleInputEventOnViewOrPopup(event); | |
| 1340 } | 1459 } |
| 1341 } | 1460 } |
| 1342 | 1461 |
| 1343 void EventSender::SetMouseButtonState(int button_number, int modifiers) { | 1462 void EventSender::SetMouseButtonState(int button_number, int modifiers) { |
| 1344 pressed_button_ = GetButtonTypeFromButtonNumber(button_number); | 1463 pressed_button_ = GetButtonTypeFromButtonNumber(button_number); |
| 1345 current_buttons_ = (modifiers == -1) ? | 1464 current_buttons_ = (modifiers == -1) ? |
| 1346 GetWebMouseEventModifierForButton(pressed_button_) : | 1465 GetWebMouseEventModifierForButton(pressed_button_) : |
| 1347 modifiers & kButtonsInModifiers; | 1466 modifiers & kButtonsInModifiers; |
| 1348 } | 1467 } |
| 1349 | 1468 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1543 | 1662 |
| 1544 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { | 1663 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { |
| 1545 WebMouseEvent event; | 1664 WebMouseEvent event; |
| 1546 InitMouseEvent(WebInputEvent::MouseDown, | 1665 InitMouseEvent(WebInputEvent::MouseDown, |
| 1547 pressed_button_, | 1666 pressed_button_, |
| 1548 current_buttons_, | 1667 current_buttons_, |
| 1549 last_mouse_pos_, | 1668 last_mouse_pos_, |
| 1550 GetCurrentEventTimeSec(), | 1669 GetCurrentEventTimeSec(), |
| 1551 click_count_, | 1670 click_count_, |
| 1552 0, | 1671 0, |
| 1672 blink::WebPointerProperties::PointerType::Mouse, | |
| 1673 0, | |
| 1553 &event); | 1674 &event); |
| 1554 FinishDragAndDrop(event, blink::WebDragOperationNone); | 1675 FinishDragAndDrop(event, blink::WebDragOperationNone); |
| 1555 } | 1676 } |
| 1556 | 1677 |
| 1557 delegate_->ClearEditCommand(); | 1678 delegate_->ClearEditCommand(); |
| 1558 | 1679 |
| 1559 if (generate_char) { | 1680 if (generate_char) { |
| 1560 WebKeyboardEvent event_char = event_up; | 1681 WebKeyboardEvent event_char = event_up; |
| 1561 event_char.type = WebInputEvent::Char; | 1682 event_char.type = WebInputEvent::Char; |
| 1562 // keyIdentifier is an empty string, unless the Enter key was pressed. | 1683 // keyIdentifier is an empty string, unless the Enter key was pressed. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1598 pressed_button_ = WebMouseEvent::ButtonRight; | 1719 pressed_button_ = WebMouseEvent::ButtonRight; |
| 1599 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 1720 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); |
| 1600 } | 1721 } |
| 1601 InitMouseEvent(WebInputEvent::MouseDown, | 1722 InitMouseEvent(WebInputEvent::MouseDown, |
| 1602 WebMouseEvent::ButtonRight, | 1723 WebMouseEvent::ButtonRight, |
| 1603 current_buttons_, | 1724 current_buttons_, |
| 1604 last_mouse_pos_, | 1725 last_mouse_pos_, |
| 1605 GetCurrentEventTimeSec(), | 1726 GetCurrentEventTimeSec(), |
| 1606 click_count_, | 1727 click_count_, |
| 1607 0, | 1728 0, |
| 1729 blink::WebPointerProperties::PointerType::Mouse, | |
| 1730 0, | |
| 1608 &event); | 1731 &event); |
| 1609 HandleInputEventOnViewOrPopup(event); | 1732 HandleInputEventOnViewOrPopup(event); |
| 1610 | 1733 |
| 1611 #if defined(OS_WIN) | 1734 #if defined(OS_WIN) |
| 1612 current_buttons_ &= | 1735 current_buttons_ &= |
| 1613 ~GetWebMouseEventModifierForButton(WebMouseEvent::ButtonRight); | 1736 ~GetWebMouseEventModifierForButton(WebMouseEvent::ButtonRight); |
| 1614 pressed_button_ = WebMouseEvent::ButtonNone; | 1737 pressed_button_ = WebMouseEvent::ButtonNone; |
| 1615 | 1738 |
| 1616 InitMouseEvent(WebInputEvent::MouseUp, | 1739 InitMouseEvent(WebInputEvent::MouseUp, |
| 1617 WebMouseEvent::ButtonRight, | 1740 WebMouseEvent::ButtonRight, |
| 1618 current_buttons_, | 1741 current_buttons_, |
| 1619 last_mouse_pos_, | 1742 last_mouse_pos_, |
| 1620 GetCurrentEventTimeSec(), | 1743 GetCurrentEventTimeSec(), |
| 1621 click_count_, | 1744 click_count_, |
| 1622 0, | 1745 0, |
| 1746 blink::WebPointerProperties::PointerType::Mouse, | |
| 1747 0, | |
| 1623 &event); | 1748 &event); |
| 1624 HandleInputEventOnViewOrPopup(event); | 1749 HandleInputEventOnViewOrPopup(event); |
| 1625 #endif | 1750 #endif |
| 1626 | 1751 |
| 1627 std::vector<std::string> menu_items = | 1752 std::vector<std::string> menu_items = |
| 1628 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate_); | 1753 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate_); |
| 1629 last_context_menu_data_.reset(); | 1754 last_context_menu_data_.reset(); |
| 1630 return menu_items; | 1755 return menu_items; |
| 1631 } | 1756 } |
| 1632 | 1757 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1966 SendGesturesForMouseWheelEvent(wheel_event); | 2091 SendGesturesForMouseWheelEvent(wheel_event); |
| 1967 } | 2092 } |
| 1968 } | 2093 } |
| 1969 | 2094 |
| 1970 void EventSender::MouseMoveTo(gin::Arguments* args) { | 2095 void EventSender::MouseMoveTo(gin::Arguments* args) { |
| 1971 if (force_layout_on_events_) | 2096 if (force_layout_on_events_) |
| 1972 view_->updateAllLifecyclePhases(); | 2097 view_->updateAllLifecyclePhases(); |
| 1973 | 2098 |
| 1974 double x; | 2099 double x; |
| 1975 double y; | 2100 double y; |
| 2101 blink::WebPointerProperties::PointerType pointerType = | |
| 2102 blink::WebPointerProperties::PointerType::Mouse; | |
| 2103 int pointerId = 0; | |
| 1976 if (!args->GetNext(&x) || !args->GetNext(&y)) { | 2104 if (!args->GetNext(&x) || !args->GetNext(&y)) { |
| 1977 args->ThrowError(); | 2105 args->ThrowError(); |
| 1978 return; | 2106 return; |
| 1979 } | 2107 } |
| 1980 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); | 2108 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); |
| 1981 | 2109 |
| 1982 int modifiers = 0; | 2110 int modifiers = 0; |
| 1983 if (!args->PeekNext().IsEmpty()) | 2111 if (!args->PeekNext().IsEmpty()) { |
| 1984 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); | 2112 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
| 2113 args->Skip(); | |
| 2114 } | |
| 1985 | 2115 |
| 1986 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && | 2116 // Only allow pen or mouse through this API. |
| 1987 !replaying_saved_events_) { | 2117 if (getPointerType(args, pointerType, true)) |
| 1988 SavedEvent saved_event; | 2118 return; |
| 1989 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; | 2119 if (!args->PeekNext().IsEmpty()) { |
| 1990 saved_event.pos = mouse_pos; | 2120 if (!args->GetNext(&pointerId)) { |
| 1991 saved_event.modifiers = modifiers; | 2121 args->ThrowError(); |
| 1992 mouse_event_queue_.push_back(saved_event); | 2122 return; |
| 2123 } | |
| 2124 } | |
| 2125 | |
| 2126 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) { | |
| 2127 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && | |
| 2128 !replaying_saved_events_) { | |
| 2129 SavedEvent saved_event; | |
| 2130 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; | |
| 2131 saved_event.pos = mouse_pos; | |
| 2132 saved_event.modifiers = modifiers; | |
| 2133 mouse_event_queue_.push_back(saved_event); | |
| 2134 } else { | |
| 2135 WebMouseEvent event; | |
| 2136 InitMouseEvent(WebInputEvent::MouseMove, | |
| 2137 pressed_button_, | |
| 2138 current_buttons_, | |
| 2139 mouse_pos, | |
| 2140 GetCurrentEventTimeSec(), | |
| 2141 click_count_, | |
| 2142 modifiers, | |
| 2143 pointerType, | |
| 2144 0, | |
| 2145 &event); | |
| 2146 DoMouseMove(event); | |
| 2147 } | |
| 1993 } else { | 2148 } else { |
| 1994 WebMouseEvent event; | 2149 current_pen_state_[pointerId].last_pos_ = mouse_pos; |
| 1995 InitMouseEvent(WebInputEvent::MouseMove, | 2150 |
| 1996 pressed_button_, | 2151 WebMouseEvent event; |
| 1997 current_buttons_, | 2152 InitMouseEvent(WebInputEvent::MouseMove, |
| 1998 mouse_pos, | 2153 current_pen_state_[pointerId].pressed_button_, |
| 1999 GetCurrentEventTimeSec(), | 2154 current_pen_state_[pointerId].current_buttons_, |
| 2000 click_count_, | 2155 mouse_pos, |
| 2001 modifiers, | 2156 GetCurrentEventTimeSec(), |
| 2002 &event); | 2157 0, |
| 2003 DoMouseMove(event); | 2158 modifiers, |
| 2159 pointerType, | |
| 2160 pointerId, | |
| 2161 &event); | |
| 2162 HandleInputEventOnViewOrPopup(event); | |
| 2004 } | 2163 } |
| 2005 } | 2164 } |
| 2006 | 2165 |
| 2007 void EventSender::MouseLeave() { | 2166 void EventSender::MouseLeave() { |
| 2008 if (force_layout_on_events_) | 2167 if (force_layout_on_events_) |
| 2009 view_->updateAllLifecyclePhases(); | 2168 view_->updateAllLifecyclePhases(); |
| 2010 | 2169 |
| 2011 WebMouseEvent event; | 2170 WebMouseEvent event; |
| 2012 InitMouseEvent(WebInputEvent::MouseLeave, | 2171 InitMouseEvent(WebInputEvent::MouseLeave, |
| 2013 WebMouseEvent::ButtonNone, | 2172 WebMouseEvent::ButtonNone, |
| 2014 0, | 2173 0, |
| 2015 last_mouse_pos_, | 2174 last_mouse_pos_, |
| 2016 GetCurrentEventTimeSec(), | 2175 GetCurrentEventTimeSec(), |
| 2017 click_count_, | 2176 click_count_, |
| 2018 0, | 2177 0, |
| 2178 blink::WebPointerProperties::PointerType::Mouse, | |
| 2179 0, | |
| 2019 &event); | 2180 &event); |
| 2020 HandleInputEventOnViewOrPopup(event); | 2181 HandleInputEventOnViewOrPopup(event); |
| 2021 } | 2182 } |
| 2022 | 2183 |
| 2023 | 2184 |
| 2024 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { | 2185 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { |
| 2025 delegate_->PostTask(new MouseDownTask(this, button_number, modifiers)); | 2186 delegate_->PostTask(new MouseDownTask(this, button_number, modifiers)); |
| 2026 delegate_->PostTask(new MouseUpTask(this, button_number, modifiers)); | 2187 delegate_->PostTask(new MouseUpTask(this, button_number, modifiers)); |
| 2027 } | 2188 } |
| 2028 | 2189 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2326 // Long press might start a drag drop session. Complete it if so. | 2487 // Long press might start a drag drop session. Complete it if so. |
| 2327 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { | 2488 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { |
| 2328 WebMouseEvent mouse_event; | 2489 WebMouseEvent mouse_event; |
| 2329 InitMouseEvent(WebInputEvent::MouseDown, | 2490 InitMouseEvent(WebInputEvent::MouseDown, |
| 2330 pressed_button_, | 2491 pressed_button_, |
| 2331 current_buttons_, | 2492 current_buttons_, |
| 2332 WebPoint(x, y), | 2493 WebPoint(x, y), |
| 2333 GetCurrentEventTimeSec(), | 2494 GetCurrentEventTimeSec(), |
| 2334 click_count_, | 2495 click_count_, |
| 2335 modifiers_, | 2496 modifiers_, |
| 2497 blink::WebPointerProperties::PointerType::Mouse, | |
| 2498 0, | |
| 2336 &mouse_event); | 2499 &mouse_event); |
| 2337 | 2500 |
| 2338 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); | 2501 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); |
| 2339 } | 2502 } |
| 2340 args->Return(result != WebInputEventResult::NotHandled); | 2503 args->Return(result != WebInputEventResult::NotHandled); |
| 2341 } | 2504 } |
| 2342 | 2505 |
| 2343 void EventSender::UpdateClickCountForButton( | 2506 void EventSender::UpdateClickCountForButton( |
| 2344 WebMouseEvent::Button button_type) { | 2507 WebMouseEvent::Button button_type) { |
| 2345 if ((GetCurrentEventTimeSec() - last_click_time_sec_ < | 2508 if ((GetCurrentEventTimeSec() - last_click_time_sec_ < |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2397 *send_gestures = true; | 2560 *send_gestures = true; |
| 2398 } | 2561 } |
| 2399 | 2562 |
| 2400 InitMouseEvent(WebInputEvent::MouseWheel, | 2563 InitMouseEvent(WebInputEvent::MouseWheel, |
| 2401 pressed_button_, | 2564 pressed_button_, |
| 2402 current_buttons_, | 2565 current_buttons_, |
| 2403 last_mouse_pos_, | 2566 last_mouse_pos_, |
| 2404 GetCurrentEventTimeSec(), | 2567 GetCurrentEventTimeSec(), |
| 2405 click_count_, | 2568 click_count_, |
| 2406 modifiers, | 2569 modifiers, |
| 2570 blink::WebPointerProperties::PointerType::Mouse, | |
| 2571 0, | |
| 2407 event); | 2572 event); |
| 2408 event->wheelTicksX = static_cast<float>(horizontal); | 2573 event->wheelTicksX = static_cast<float>(horizontal); |
| 2409 event->wheelTicksY = static_cast<float>(vertical); | 2574 event->wheelTicksY = static_cast<float>(vertical); |
| 2410 event->deltaX = event->wheelTicksX; | 2575 event->deltaX = event->wheelTicksX; |
| 2411 event->deltaY = event->wheelTicksY; | 2576 event->deltaY = event->wheelTicksY; |
| 2412 event->scrollByPage = paged; | 2577 event->scrollByPage = paged; |
| 2413 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; | 2578 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; |
| 2414 event->canScroll = can_scroll; | 2579 event->canScroll = can_scroll; |
| 2415 if (scroll_type == MouseScrollType::PIXEL) { | 2580 if (scroll_type == MouseScrollType::PIXEL) { |
| 2416 event->wheelTicksX /= kScrollbarPixelsPerTick; | 2581 event->wheelTicksX /= kScrollbarPixelsPerTick; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2459 if (!args->PeekNext().IsEmpty()) { | 2624 if (!args->PeekNext().IsEmpty()) { |
| 2460 int tiltX, tiltY; | 2625 int tiltX, tiltY; |
| 2461 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) { | 2626 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) { |
| 2462 args->ThrowError(); | 2627 args->ThrowError(); |
| 2463 return; | 2628 return; |
| 2464 } | 2629 } |
| 2465 e->tiltX = tiltX; | 2630 e->tiltX = tiltX; |
| 2466 e->tiltY = tiltY; | 2631 e->tiltY = tiltY; |
| 2467 } | 2632 } |
| 2468 | 2633 |
| 2469 if (!args->PeekNext().IsEmpty()) { | 2634 if (getPointerType(args, e->pointerType)) |
| 2470 std::string pointer_type_string; | 2635 return; |
| 2471 if (!args->GetNext(&pointer_type_string)) { | |
| 2472 args->ThrowError(); | |
| 2473 return; | |
| 2474 } | |
| 2475 if (pointer_type_string == kPointerTypeStringUnknown) { | |
| 2476 e->pointerType = WebMouseEvent::PointerType::Unknown; | |
| 2477 } else if (pointer_type_string == kPointerTypeStringMouse) { | |
| 2478 e->pointerType = WebMouseEvent::PointerType::Mouse; | |
| 2479 } else if (pointer_type_string == kPointerTypeStringPen) { | |
| 2480 e->pointerType = WebMouseEvent::PointerType::Pen; | |
| 2481 } else if (pointer_type_string == kPointerTypeStringTouch) { | |
| 2482 e->pointerType = WebMouseEvent::PointerType::Touch; | |
| 2483 } else { | |
| 2484 args->ThrowError(); | |
| 2485 return; | |
| 2486 } | |
| 2487 } | |
| 2488 } | 2636 } |
| 2489 | 2637 |
| 2490 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, | 2638 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, |
| 2491 blink::WebDragOperation drag_effect) { | 2639 blink::WebDragOperation drag_effect) { |
| 2492 WebPoint client_point(e.x, e.y); | 2640 WebPoint client_point(e.x, e.y); |
| 2493 WebPoint screen_point(e.globalX, e.globalY); | 2641 WebPoint screen_point(e.globalX, e.globalY); |
| 2494 current_drag_effect_ = drag_effect; | 2642 current_drag_effect_ = drag_effect; |
| 2495 if (current_drag_effect_) { | 2643 if (current_drag_effect_) { |
| 2496 // Specifically pass any keyboard modifiers to the drop method. This allows | 2644 // Specifically pass any keyboard modifiers to the drop method. This allows |
| 2497 // tests to control the drop type (i.e. copy or move). | 2645 // tests to control the drop type (i.e. copy or move). |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2555 switch (e.type) { | 2703 switch (e.type) { |
| 2556 case SavedEvent::TYPE_MOUSE_MOVE: { | 2704 case SavedEvent::TYPE_MOUSE_MOVE: { |
| 2557 WebMouseEvent event; | 2705 WebMouseEvent event; |
| 2558 InitMouseEvent(WebInputEvent::MouseMove, | 2706 InitMouseEvent(WebInputEvent::MouseMove, |
| 2559 pressed_button_, | 2707 pressed_button_, |
| 2560 current_buttons_, | 2708 current_buttons_, |
| 2561 e.pos, | 2709 e.pos, |
| 2562 GetCurrentEventTimeSec(), | 2710 GetCurrentEventTimeSec(), |
| 2563 click_count_, | 2711 click_count_, |
| 2564 e.modifiers, | 2712 e.modifiers, |
| 2713 blink::WebPointerProperties::PointerType::Mouse, | |
| 2714 0, | |
| 2565 &event); | 2715 &event); |
| 2566 DoMouseMove(event); | 2716 DoMouseMove(event); |
| 2567 break; | 2717 break; |
| 2568 } | 2718 } |
| 2569 case SavedEvent::TYPE_LEAP_FORWARD: | 2719 case SavedEvent::TYPE_LEAP_FORWARD: |
| 2570 DoLeapForward(e.milliseconds); | 2720 DoLeapForward(e.milliseconds); |
| 2571 break; | 2721 break; |
| 2572 case SavedEvent::TYPE_MOUSE_UP: { | 2722 case SavedEvent::TYPE_MOUSE_UP: { |
| 2573 current_buttons_ &= ~GetWebMouseEventModifierForButton(e.button_type); | 2723 current_buttons_ &= ~GetWebMouseEventModifierForButton(e.button_type); |
| 2574 pressed_button_ = WebMouseEvent::ButtonNone; | 2724 pressed_button_ = WebMouseEvent::ButtonNone; |
| 2575 | 2725 |
| 2576 WebMouseEvent event; | 2726 WebMouseEvent event; |
| 2577 InitMouseEvent(WebInputEvent::MouseUp, | 2727 InitMouseEvent(WebInputEvent::MouseUp, |
| 2578 e.button_type, | 2728 e.button_type, |
| 2579 current_buttons_, | 2729 current_buttons_, |
| 2580 last_mouse_pos_, | 2730 last_mouse_pos_, |
| 2581 GetCurrentEventTimeSec(), | 2731 GetCurrentEventTimeSec(), |
| 2582 click_count_, | 2732 click_count_, |
| 2583 e.modifiers, | 2733 e.modifiers, |
| 2734 blink::WebPointerProperties::PointerType::Mouse, | |
| 2735 0, | |
| 2584 &event); | 2736 &event); |
| 2585 DoMouseUp(event); | 2737 DoMouseUp(event); |
| 2586 break; | 2738 break; |
| 2587 } | 2739 } |
| 2588 default: | 2740 default: |
| 2589 NOTREACHED(); | 2741 NOTREACHED(); |
| 2590 } | 2742 } |
| 2591 } | 2743 } |
| 2592 | 2744 |
| 2593 replaying_saved_events_ = false; | 2745 replaying_saved_events_ = false; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2655 &end_event); | 2807 &end_event); |
| 2656 end_event.data.scrollEnd.deltaUnits = | 2808 end_event.data.scrollEnd.deltaUnits = |
| 2657 begin_event.data.scrollBegin.deltaHintUnits; | 2809 begin_event.data.scrollBegin.deltaHintUnits; |
| 2658 | 2810 |
| 2659 if (force_layout_on_events_) | 2811 if (force_layout_on_events_) |
| 2660 view_->updateAllLifecyclePhases(); | 2812 view_->updateAllLifecyclePhases(); |
| 2661 HandleInputEventOnViewOrPopup(end_event); | 2813 HandleInputEventOnViewOrPopup(end_event); |
| 2662 } | 2814 } |
| 2663 | 2815 |
| 2664 } // namespace test_runner | 2816 } // namespace test_runner |
| OLD | NEW |