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 int kMousePointerId = -1; | |
| 62 const char* kPointerTypeStringUnknown = ""; | |
| 63 const char* kPointerTypeStringMouse = "mouse"; | |
| 64 const char* kPointerTypeStringPen = "pen"; | |
| 65 const char* kPointerTypeStringTouch = "touch"; | |
| 66 | |
| 67 bool getPointerType(gin::Arguments* args, | |
| 68 blink::WebPointerProperties::PointerType &t, | |
|
dtapuska
2016/04/07 02:35:41
Should be PointerType& t. Both styles are allowed
Navid Zolghadr
2016/04/08 17:38:44
Done. I got rid of the default value and in that s
| |
| 69 bool isOnlyMouseAndPenAllowed = false) { | |
| 70 if (!args->PeekNext().IsEmpty()) { | |
| 71 std::string pointer_type_string; | |
| 72 if (!args->GetNext(&pointer_type_string)) { | |
| 73 args->ThrowError(); | |
| 74 return false; | |
| 75 } | |
| 76 if (pointer_type_string == kPointerTypeStringUnknown) { | |
| 77 if (isOnlyMouseAndPenAllowed) { | |
| 78 args->ThrowError(); | |
| 79 return false; | |
| 80 } | |
| 81 t = WebMouseEvent::PointerType::Unknown; | |
| 82 } else if (pointer_type_string == kPointerTypeStringMouse) { | |
| 83 t = WebMouseEvent::PointerType::Mouse; | |
| 84 } else if (pointer_type_string == kPointerTypeStringPen) { | |
| 85 t = WebMouseEvent::PointerType::Pen; | |
| 86 } else if (pointer_type_string == kPointerTypeStringTouch) { | |
| 87 if (isOnlyMouseAndPenAllowed) { | |
| 88 args->ThrowError(); | |
| 89 return false; | |
| 90 } | |
| 91 t = WebMouseEvent::PointerType::Touch; | |
| 92 } else { | |
| 93 args->ThrowError(); | |
| 94 return false; | |
| 95 } | |
| 96 } | |
| 97 return true; | |
|
mustaq
2016/04/07 19:30:02
Nit: Please avoid three levels of nested |if|s, by
Navid Zolghadr
2016/04/08 17:38:44
Done.
| |
| 98 } | |
| 99 | |
| 100 bool getMousePenPointerTypeAndId(gin::Arguments* args, | |
| 101 blink::WebPointerProperties::PointerType &t, | |
|
dtapuska
2016/04/07 02:35:41
ditto; comments as above.
Navid Zolghadr
2016/04/08 17:38:44
Done.
| |
| 102 int &id) { | |
| 103 t = blink::WebPointerProperties::PointerType::Mouse; | |
| 104 id = kMousePointerId; | |
| 105 // Only allow pen or mouse through this API. | |
| 106 if (!getPointerType(args, t, true)) | |
| 107 return false; | |
| 108 if (!args->PeekNext().IsEmpty()) { | |
| 109 if (!args->GetNext(&id)) { | |
| 110 args->ThrowError(); | |
| 111 return false; | |
| 112 } | |
| 113 if (t != blink::WebPointerProperties::PointerType::Mouse | |
| 114 && id == kMousePointerId) { | |
| 115 args->ThrowError(); | |
| 116 return false; | |
| 117 } | |
| 118 } else if (t == blink::WebPointerProperties::PointerType::Pen) { | |
| 119 id = 1; // A default value for the id of the pen | |
| 120 } | |
| 121 return true; | |
| 122 } | |
| 123 | |
| 61 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { | 124 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { |
| 62 switch (button_code) { | 125 switch (button_code) { |
| 63 case -1: | 126 case -1: |
| 64 return WebMouseEvent::ButtonNone; | 127 return WebMouseEvent::ButtonNone; |
| 65 case 0: | 128 case 0: |
| 66 return WebMouseEvent::ButtonLeft; | 129 return WebMouseEvent::ButtonLeft; |
| 67 case 1: | 130 case 1: |
| 68 return WebMouseEvent::ButtonMiddle; | 131 return WebMouseEvent::ButtonMiddle; |
| 69 case 2: | 132 case 2: |
| 70 return WebMouseEvent::ButtonRight; | 133 return WebMouseEvent::ButtonRight; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 96 | (buttons & kButtonsInModifiers); | 159 | (buttons & kButtonsInModifiers); |
| 97 } | 160 } |
| 98 | 161 |
| 99 void InitMouseEvent(WebInputEvent::Type t, | 162 void InitMouseEvent(WebInputEvent::Type t, |
| 100 WebMouseEvent::Button b, | 163 WebMouseEvent::Button b, |
| 101 int current_buttons, | 164 int current_buttons, |
| 102 const WebPoint& pos, | 165 const WebPoint& pos, |
| 103 double time_stamp, | 166 double time_stamp, |
| 104 int click_count, | 167 int click_count, |
| 105 int modifiers, | 168 int modifiers, |
| 169 blink::WebPointerProperties::PointerType pointerType, | |
| 170 int pointerId, | |
| 106 WebMouseEvent* e) { | 171 WebMouseEvent* e) { |
| 107 e->type = t; | 172 e->type = t; |
| 108 e->button = b; | 173 e->button = b; |
| 109 e->modifiers = modifiersWithButtons(modifiers, current_buttons); | 174 e->modifiers = modifiersWithButtons(modifiers, current_buttons); |
| 110 e->x = pos.x; | 175 e->x = pos.x; |
| 111 e->y = pos.y; | 176 e->y = pos.y; |
| 112 e->globalX = pos.x; | 177 e->globalX = pos.x; |
| 113 e->globalY = pos.y; | 178 e->globalY = pos.y; |
| 114 e->pointerType = blink::WebPointerProperties::PointerType::Mouse; | 179 e->pointerType = pointerType; |
| 180 if (pointerType != blink::WebPointerProperties::PointerType::Mouse) | |
|
mustaq
2016/04/07 19:30:02
I think it's better to allow any ids here. This wo
Navid Zolghadr
2016/04/08 17:38:44
Sure. Then here for mouse by default we are sendin
| |
| 181 e->id = pointerId; | |
| 115 e->timeStampSeconds = time_stamp; | 182 e->timeStampSeconds = time_stamp; |
| 116 e->clickCount = click_count; | 183 e->clickCount = click_count; |
| 117 } | 184 } |
| 118 | 185 |
| 119 void InitGestureEventFromMouseWheel(WebInputEvent::Type type, | 186 void InitGestureEventFromMouseWheel(WebInputEvent::Type type, |
| 120 double time_stamp, | 187 double time_stamp, |
| 121 const WebMouseWheelEvent& wheel_event, | 188 const WebMouseWheelEvent& wheel_event, |
| 122 WebGestureEvent* gesture_event) { | 189 WebGestureEvent* gesture_event) { |
| 123 gesture_event->type = type; | 190 gesture_event->type = type; |
| 124 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad; | 191 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 } | 515 } |
| 449 } else { | 516 } else { |
| 450 *units = WebGestureEvent::PrecisePixels; | 517 *units = WebGestureEvent::PrecisePixels; |
| 451 return true; | 518 return true; |
| 452 } | 519 } |
| 453 } | 520 } |
| 454 | 521 |
| 455 const char* kSourceDeviceStringTouchpad = "touchpad"; | 522 const char* kSourceDeviceStringTouchpad = "touchpad"; |
| 456 const char* kSourceDeviceStringTouchscreen = "touchscreen"; | 523 const char* kSourceDeviceStringTouchscreen = "touchscreen"; |
| 457 | 524 |
| 458 const char* kPointerTypeStringUnknown = ""; | |
| 459 const char* kPointerTypeStringMouse = "mouse"; | |
| 460 const char* kPointerTypeStringPen = "pen"; | |
| 461 const char* kPointerTypeStringTouch = "touch"; | |
| 462 | |
| 463 } // namespace | 525 } // namespace |
| 464 | 526 |
| 465 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { | 527 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { |
| 466 public: | 528 public: |
| 467 static gin::WrapperInfo kWrapperInfo; | 529 static gin::WrapperInfo kWrapperInfo; |
| 468 | 530 |
| 469 static void Install(base::WeakPtr<EventSender> sender, | 531 static void Install(base::WeakPtr<EventSender> sender, |
| 470 blink::WebFrame* frame); | 532 blink::WebFrame* frame); |
| 471 | 533 |
| 472 private: | 534 private: |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 971 sender_->ScheduleAsynchronousKeyDown(code_str, modifiers, | 1033 sender_->ScheduleAsynchronousKeyDown(code_str, modifiers, |
| 972 static_cast<KeyLocationCode>(location)); | 1034 static_cast<KeyLocationCode>(location)); |
| 973 } | 1035 } |
| 974 | 1036 |
| 975 void EventSenderBindings::MouseDown(gin::Arguments* args) { | 1037 void EventSenderBindings::MouseDown(gin::Arguments* args) { |
| 976 if (!sender_) | 1038 if (!sender_) |
| 977 return; | 1039 return; |
| 978 | 1040 |
| 979 int button_number = 0; | 1041 int button_number = 0; |
| 980 int modifiers = 0; | 1042 int modifiers = 0; |
| 1043 blink::WebPointerProperties::PointerType pointerType = | |
| 1044 blink::WebPointerProperties::PointerType::Mouse; | |
| 1045 int pointerId = 0; | |
| 981 if (!args->PeekNext().IsEmpty()) { | 1046 if (!args->PeekNext().IsEmpty()) { |
| 982 args->GetNext(&button_number); | 1047 if (!args->GetNext(&button_number)) { |
| 983 if (!args->PeekNext().IsEmpty()) | 1048 args->ThrowError(); |
| 1049 return; | |
| 1050 } | |
| 1051 if (!args->PeekNext().IsEmpty()) { | |
| 984 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); | 1052 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
| 1053 args->Skip(); | |
| 1054 } | |
| 985 } | 1055 } |
| 986 sender_->MouseDown(button_number, modifiers); | 1056 |
| 1057 if (!getMousePenPointerTypeAndId(args, pointerType, pointerId)) | |
| 1058 return; | |
| 1059 | |
| 1060 sender_->MouseDown(button_number, modifiers, pointerType, pointerId); | |
| 987 } | 1061 } |
| 988 | 1062 |
| 989 void EventSenderBindings::MouseUp(gin::Arguments* args) { | 1063 void EventSenderBindings::MouseUp(gin::Arguments* args) { |
| 990 if (!sender_) | 1064 if (!sender_) |
| 991 return; | 1065 return; |
| 992 | 1066 |
| 993 int button_number = 0; | 1067 int button_number = 0; |
| 994 int modifiers = 0; | 1068 int modifiers = 0; |
| 1069 blink::WebPointerProperties::PointerType pointerType = | |
| 1070 blink::WebPointerProperties::PointerType::Mouse; | |
| 1071 int pointerId = 0; | |
| 995 if (!args->PeekNext().IsEmpty()) { | 1072 if (!args->PeekNext().IsEmpty()) { |
| 996 args->GetNext(&button_number); | 1073 if (!args->GetNext(&button_number)) { |
| 997 if (!args->PeekNext().IsEmpty()) | 1074 args->ThrowError(); |
| 1075 return; | |
| 1076 } | |
| 1077 if (!args->PeekNext().IsEmpty()) { | |
| 998 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); | 1078 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
| 1079 args->Skip(); | |
| 1080 } | |
| 999 } | 1081 } |
| 1000 sender_->MouseUp(button_number, modifiers); | 1082 |
| 1083 if (!getMousePenPointerTypeAndId(args, pointerType, pointerId)) | |
| 1084 return; | |
| 1085 | |
| 1086 sender_->MouseUp(button_number, modifiers, pointerType, pointerId); | |
| 1001 } | 1087 } |
| 1002 | 1088 |
| 1003 void EventSenderBindings::SetMouseButtonState(gin::Arguments* args) { | 1089 void EventSenderBindings::SetMouseButtonState(gin::Arguments* args) { |
| 1004 if (!sender_) | 1090 if (!sender_) |
| 1005 return; | 1091 return; |
| 1006 | 1092 |
| 1007 int button_number; | 1093 int button_number; |
| 1008 if (!args->GetNext(&button_number)) { | 1094 if (!args->GetNext(&button_number)) { |
| 1009 args->ThrowError(); | 1095 args->ThrowError(); |
| 1010 return; | 1096 return; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1143 } | 1229 } |
| 1144 | 1230 |
| 1145 void EventSenderBindings::SetWmSysDeadChar(int sys_dead_char) { | 1231 void EventSenderBindings::SetWmSysDeadChar(int sys_dead_char) { |
| 1146 if (sender_) | 1232 if (sender_) |
| 1147 sender_->set_wm_sys_dead_char(sys_dead_char); | 1233 sender_->set_wm_sys_dead_char(sys_dead_char); |
| 1148 } | 1234 } |
| 1149 #endif | 1235 #endif |
| 1150 | 1236 |
| 1151 // EventSender ----------------------------------------------------------------- | 1237 // EventSender ----------------------------------------------------------------- |
| 1152 | 1238 |
| 1153 WebMouseEvent::Button EventSender::pressed_button_ = WebMouseEvent::ButtonNone; | |
| 1154 int EventSender::current_buttons_ = 0; | |
| 1155 int EventSender::modifiers_ = 0; | |
| 1156 | |
| 1157 WebPoint EventSender::last_mouse_pos_; | |
| 1158 | |
| 1159 WebMouseEvent::Button EventSender::last_button_type_ = | 1239 WebMouseEvent::Button EventSender::last_button_type_ = |
| 1160 WebMouseEvent::ButtonNone; | 1240 WebMouseEvent::ButtonNone; |
| 1161 | 1241 |
| 1162 EventSender::SavedEvent::SavedEvent() | 1242 EventSender::SavedEvent::SavedEvent() |
| 1163 : type(TYPE_UNSPECIFIED), | 1243 : type(TYPE_UNSPECIFIED), |
| 1164 button_type(WebMouseEvent::ButtonNone), | 1244 button_type(WebMouseEvent::ButtonNone), |
| 1165 milliseconds(0), | 1245 milliseconds(0), |
| 1166 modifiers(0) {} | 1246 modifiers(0) {} |
| 1167 | 1247 |
| 1168 EventSender::EventSender(TestInterfaces* interfaces) | 1248 EventSender::EventSender(TestInterfaces* interfaces) |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1194 weak_factory_(this) { | 1274 weak_factory_(this) { |
| 1195 } | 1275 } |
| 1196 | 1276 |
| 1197 EventSender::~EventSender() {} | 1277 EventSender::~EventSender() {} |
| 1198 | 1278 |
| 1199 void EventSender::Reset() { | 1279 void EventSender::Reset() { |
| 1200 DCHECK(current_drag_data_.isNull()); | 1280 DCHECK(current_drag_data_.isNull()); |
| 1201 current_drag_data_.reset(); | 1281 current_drag_data_.reset(); |
| 1202 current_drag_effect_ = blink::WebDragOperationNone; | 1282 current_drag_effect_ = blink::WebDragOperationNone; |
| 1203 current_drag_effects_allowed_ = blink::WebDragOperationNone; | 1283 current_drag_effects_allowed_ = blink::WebDragOperationNone; |
| 1204 if (view_ && pressed_button_ != WebMouseEvent::ButtonNone) | 1284 if (view_ && current_pointer_state_[kMousePointerId].pressed_button_ |
| 1285 != WebMouseEvent::ButtonNone) | |
| 1205 view_->mouseCaptureLost(); | 1286 view_->mouseCaptureLost(); |
| 1206 pressed_button_ = WebMouseEvent::ButtonNone; | 1287 current_pointer_state_.clear(); |
| 1207 current_buttons_ = 0; | |
| 1208 modifiers_ = 0; | |
| 1209 is_drag_mode_ = true; | 1288 is_drag_mode_ = true; |
| 1210 force_layout_on_events_ = true; | 1289 force_layout_on_events_ = true; |
| 1211 | 1290 |
| 1212 #if defined(OS_WIN) | 1291 #if defined(OS_WIN) |
| 1213 wm_key_down_ = WM_KEYDOWN; | 1292 wm_key_down_ = WM_KEYDOWN; |
| 1214 wm_key_up_ = WM_KEYUP; | 1293 wm_key_up_ = WM_KEYUP; |
| 1215 wm_char_ = WM_CHAR; | 1294 wm_char_ = WM_CHAR; |
| 1216 wm_dead_char_ = WM_DEADCHAR; | 1295 wm_dead_char_ = WM_DEADCHAR; |
| 1217 wm_sys_key_down_ = WM_SYSKEYDOWN; | 1296 wm_sys_key_down_ = WM_SYSKEYDOWN; |
| 1218 wm_sys_key_up_ = WM_SYSKEYUP; | 1297 wm_sys_key_up_ = WM_SYSKEYUP; |
| 1219 wm_sys_char_ = WM_SYSCHAR; | 1298 wm_sys_char_ = WM_SYSCHAR; |
| 1220 wm_sys_dead_char_ = WM_SYSDEADCHAR; | 1299 wm_sys_dead_char_ = WM_SYSDEADCHAR; |
| 1221 #endif | 1300 #endif |
| 1222 | 1301 |
| 1223 last_mouse_pos_ = WebPoint(0, 0); | |
| 1224 last_click_time_sec_ = 0; | 1302 last_click_time_sec_ = 0; |
| 1225 last_click_pos_ = WebPoint(0, 0); | 1303 last_click_pos_ = WebPoint(0, 0); |
| 1226 last_button_type_ = WebMouseEvent::ButtonNone; | 1304 last_button_type_ = WebMouseEvent::ButtonNone; |
| 1227 touch_points_.clear(); | 1305 touch_points_.clear(); |
| 1228 last_context_menu_data_.reset(); | 1306 last_context_menu_data_.reset(); |
| 1229 task_list_.RevokeAll(); | 1307 task_list_.RevokeAll(); |
| 1230 current_gesture_location_ = WebPoint(0, 0); | 1308 current_gesture_location_ = WebPoint(0, 0); |
| 1231 mouse_event_queue_.clear(); | 1309 mouse_event_queue_.clear(); |
| 1232 | 1310 |
| 1233 time_offset_ms_ = 0; | 1311 time_offset_ms_ = 0; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1251 } | 1329 } |
| 1252 | 1330 |
| 1253 void EventSender::SetContextMenuData(const WebContextMenuData& data) { | 1331 void EventSender::SetContextMenuData(const WebContextMenuData& data) { |
| 1254 last_context_menu_data_.reset(new WebContextMenuData(data)); | 1332 last_context_menu_data_.reset(new WebContextMenuData(data)); |
| 1255 } | 1333 } |
| 1256 | 1334 |
| 1257 void EventSender::DoDragDrop(const WebDragData& drag_data, | 1335 void EventSender::DoDragDrop(const WebDragData& drag_data, |
| 1258 WebDragOperationsMask mask) { | 1336 WebDragOperationsMask mask) { |
| 1259 WebMouseEvent event; | 1337 WebMouseEvent event; |
| 1260 InitMouseEvent(WebInputEvent::MouseDown, | 1338 InitMouseEvent(WebInputEvent::MouseDown, |
| 1261 pressed_button_, | 1339 current_pointer_state_[kMousePointerId].pressed_button_, |
| 1262 current_buttons_, | 1340 current_pointer_state_[kMousePointerId].current_buttons_, |
| 1263 last_mouse_pos_, | 1341 current_pointer_state_[kMousePointerId].last_pos_, |
| 1264 GetCurrentEventTimeSec(), | 1342 GetCurrentEventTimeSec(), |
| 1265 click_count_, | 1343 click_count_, |
| 1266 modifiers_, | 1344 current_pointer_state_[kMousePointerId].modifiers_, |
| 1345 blink::WebPointerProperties::PointerType::Mouse, | |
| 1346 0, | |
| 1267 &event); | 1347 &event); |
| 1268 WebPoint client_point(event.x, event.y); | 1348 WebPoint client_point(event.x, event.y); |
| 1269 WebPoint screen_point(event.globalX, event.globalY); | 1349 WebPoint screen_point(event.globalX, event.globalY); |
| 1270 current_drag_data_ = drag_data; | 1350 current_drag_data_ = drag_data; |
| 1271 current_drag_effects_allowed_ = mask; | 1351 current_drag_effects_allowed_ = mask; |
| 1272 current_drag_effect_ = view_->dragTargetDragEnter( | 1352 current_drag_effect_ = view_->dragTargetDragEnter( |
| 1273 drag_data, | 1353 drag_data, |
| 1274 client_point, | 1354 client_point, |
| 1275 screen_point, | 1355 screen_point, |
| 1276 current_drag_effects_allowed_, | 1356 current_drag_effects_allowed_, |
| 1277 modifiersWithButtons(modifiers_, current_buttons_)); | 1357 modifiersWithButtons(current_pointer_state_[kMousePointerId].modifiers_, |
| 1358 current_pointer_state_[kMousePointerId].current_buttons_)); | |
| 1278 | 1359 |
| 1279 // Finish processing events. | 1360 // Finish processing events. |
| 1280 ReplaySavedEvents(); | 1361 ReplaySavedEvents(); |
| 1281 } | 1362 } |
| 1282 | 1363 |
| 1283 void EventSender::MouseDown(int button_number, int modifiers) { | 1364 void EventSender::MouseDown(int button_number, int modifiers, |
| 1365 blink::WebPointerProperties::PointerType pointerType, int pointerId) { | |
| 1284 if (force_layout_on_events_) | 1366 if (force_layout_on_events_) |
| 1285 view_->updateAllLifecyclePhases(); | 1367 view_->updateAllLifecyclePhases(); |
| 1286 | 1368 |
| 1287 DCHECK_NE(-1, button_number); | 1369 DCHECK_NE(-1, button_number); |
| 1288 | 1370 |
| 1289 WebMouseEvent::Button button_type = | 1371 WebMouseEvent::Button button_type = |
| 1290 GetButtonTypeFromButtonNumber(button_number); | 1372 GetButtonTypeFromButtonNumber(button_number); |
| 1291 | 1373 |
| 1292 UpdateClickCountForButton(button_type); | 1374 WebMouseEvent event; |
| 1375 int click_count = 0; | |
| 1376 current_pointer_state_[pointerId].pressed_button_ = button_type; | |
| 1377 current_pointer_state_[pointerId].current_buttons_ |= | |
| 1378 GetWebMouseEventModifierForButton(button_type); | |
| 1379 current_pointer_state_[pointerId].modifiers_ = modifiers; | |
| 1293 | 1380 |
| 1294 pressed_button_ = button_type; | 1381 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) { |
| 1295 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 1382 UpdateClickCountForButton(button_type); |
| 1296 modifiers_ = modifiers; | 1383 click_count = click_count_; |
| 1384 } | |
| 1385 InitMouseEvent(WebInputEvent::MouseDown, | |
| 1386 current_pointer_state_[pointerId].pressed_button_, | |
| 1387 current_pointer_state_[pointerId].current_buttons_, | |
| 1388 current_pointer_state_[pointerId].last_pos_, | |
| 1389 GetCurrentEventTimeSec(), | |
| 1390 click_count, | |
| 1391 current_pointer_state_[pointerId].modifiers_, | |
| 1392 pointerType, | |
| 1393 pointerId, | |
|
dtapuska
2016/04/07 02:35:41
Do we need to be concerned we are passing -1 poten
Navid Zolghadr
2016/04/07 03:08:04
There is a check in InitMouseEvent which ignores t
mustaq
2016/04/07 19:30:02
I am fine with allowing unexpected values here, to
Navid Zolghadr
2016/04/08 17:38:44
I removed the check in InitMouseEvent to set any i
| |
| 1394 &event); | |
| 1297 | 1395 |
| 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); | 1396 HandleInputEventOnViewOrPopup(event); |
| 1308 } | 1397 } |
| 1309 | 1398 |
| 1310 void EventSender::MouseUp(int button_number, int modifiers) { | 1399 void EventSender::MouseUp(int button_number, int modifiers, |
| 1400 blink::WebPointerProperties::PointerType pointerType, int pointerId) { | |
| 1311 if (force_layout_on_events_) | 1401 if (force_layout_on_events_) |
| 1312 view_->updateAllLifecyclePhases(); | 1402 view_->updateAllLifecyclePhases(); |
| 1313 | 1403 |
| 1314 DCHECK_NE(-1, button_number); | 1404 DCHECK_NE(-1, button_number); |
| 1315 | 1405 |
| 1316 WebMouseEvent::Button button_type = | 1406 WebMouseEvent::Button button_type = |
| 1317 GetButtonTypeFromButtonNumber(button_number); | 1407 GetButtonTypeFromButtonNumber(button_number); |
| 1318 | 1408 |
| 1319 if (is_drag_mode_ && !replaying_saved_events_) { | 1409 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) { |
| 1320 SavedEvent saved_event; | 1410 if (is_drag_mode_ && !replaying_saved_events_) { |
| 1321 saved_event.type = SavedEvent::TYPE_MOUSE_UP; | 1411 SavedEvent saved_event; |
| 1322 saved_event.button_type = button_type; | 1412 saved_event.type = SavedEvent::TYPE_MOUSE_UP; |
| 1323 saved_event.modifiers = modifiers; | 1413 saved_event.button_type = button_type; |
| 1324 mouse_event_queue_.push_back(saved_event); | 1414 saved_event.modifiers = modifiers; |
| 1325 ReplaySavedEvents(); | 1415 mouse_event_queue_.push_back(saved_event); |
| 1416 ReplaySavedEvents(); | |
| 1417 } else { | |
| 1418 current_pointer_state_[kMousePointerId].current_buttons_ &= | |
| 1419 ~GetWebMouseEventModifierForButton(button_type); | |
| 1420 current_pointer_state_[kMousePointerId].pressed_button_ = | |
| 1421 WebMouseEvent::ButtonNone; | |
| 1422 | |
| 1423 WebMouseEvent event; | |
| 1424 InitMouseEvent(WebInputEvent::MouseUp, | |
| 1425 button_type, | |
| 1426 current_pointer_state_[kMousePointerId].current_buttons_, | |
| 1427 current_pointer_state_[kMousePointerId].last_pos_, | |
| 1428 GetCurrentEventTimeSec(), | |
| 1429 click_count_, | |
| 1430 modifiers, | |
| 1431 pointerType, | |
| 1432 0, | |
|
dtapuska
2016/04/07 02:35:41
Whereas we pass 0 in here for mouseup?
This code
Navid Zolghadr
2016/04/07 03:08:04
I was thinking of doing this similar to what I did
dtapuska
2016/04/07 03:15:24
Personally; I'd probably look at pulling the Handl
mustaq
2016/04/07 19:30:02
I agree, the two DoMouse* methods are doing local
Navid Zolghadr
2016/04/08 17:38:44
Done.
| |
| 1433 &event); | |
| 1434 DoMouseUp(event); | |
| 1435 } | |
| 1326 } else { | 1436 } else { |
| 1327 current_buttons_ &= ~GetWebMouseEventModifierForButton(button_type); | 1437 current_pointer_state_[pointerId].current_buttons_ &= |
| 1328 pressed_button_ = WebMouseEvent::ButtonNone; | 1438 ~GetWebMouseEventModifierForButton(button_type); |
| 1439 current_pointer_state_[pointerId].pressed_button_ = | |
| 1440 WebMouseEvent::ButtonNone; | |
| 1329 | 1441 |
| 1330 WebMouseEvent event; | 1442 WebMouseEvent event; |
| 1331 InitMouseEvent(WebInputEvent::MouseUp, | 1443 InitMouseEvent(WebInputEvent::MouseUp, |
| 1332 button_type, | 1444 button_type, |
| 1333 current_buttons_, | 1445 current_pointer_state_[pointerId].current_buttons_, |
| 1334 last_mouse_pos_, | 1446 current_pointer_state_[pointerId].last_pos_, |
| 1335 GetCurrentEventTimeSec(), | 1447 GetCurrentEventTimeSec(), |
| 1336 click_count_, | 1448 0, |
| 1337 modifiers, | 1449 modifiers, |
| 1338 &event); | 1450 pointerType, |
| 1339 DoMouseUp(event); | 1451 pointerId, |
| 1452 &event); | |
| 1453 HandleInputEventOnViewOrPopup(event); | |
| 1340 } | 1454 } |
| 1341 } | 1455 } |
| 1342 | 1456 |
| 1343 void EventSender::SetMouseButtonState(int button_number, int modifiers) { | 1457 void EventSender::SetMouseButtonState(int button_number, int modifiers) { |
| 1344 pressed_button_ = GetButtonTypeFromButtonNumber(button_number); | 1458 current_pointer_state_[kMousePointerId].pressed_button_ = |
| 1345 current_buttons_ = (modifiers == -1) ? | 1459 GetButtonTypeFromButtonNumber(button_number); |
| 1346 GetWebMouseEventModifierForButton(pressed_button_) : | 1460 current_pointer_state_[kMousePointerId].current_buttons_ = (modifiers == -1) ? |
| 1461 GetWebMouseEventModifierForButton( | |
| 1462 current_pointer_state_[kMousePointerId].pressed_button_) : | |
| 1347 modifiers & kButtonsInModifiers; | 1463 modifiers & kButtonsInModifiers; |
| 1348 } | 1464 } |
| 1349 | 1465 |
| 1350 void EventSender::KeyDown(const std::string& code_str, | 1466 void EventSender::KeyDown(const std::string& code_str, |
| 1351 int modifiers, | 1467 int modifiers, |
| 1352 KeyLocationCode location) { | 1468 KeyLocationCode location) { |
| 1353 // FIXME: I'm not exactly sure how we should convert the string to a key | 1469 // FIXME: I'm not exactly sure how we should convert the string to a key |
| 1354 // event. This seems to work in the cases I tested. | 1470 // event. This seems to work in the cases I tested. |
| 1355 // FIXME: Should we also generate a KEY_UP? | 1471 // FIXME: Should we also generate a KEY_UP? |
| 1356 | 1472 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1537 // We just simulate the same behavior here. | 1653 // We just simulate the same behavior here. |
| 1538 std::string edit_command; | 1654 std::string edit_command; |
| 1539 if (GetEditCommand(event_down, &edit_command)) | 1655 if (GetEditCommand(event_down, &edit_command)) |
| 1540 delegate_->SetEditCommand(edit_command, ""); | 1656 delegate_->SetEditCommand(edit_command, ""); |
| 1541 | 1657 |
| 1542 HandleInputEventOnViewOrPopup(event_down); | 1658 HandleInputEventOnViewOrPopup(event_down); |
| 1543 | 1659 |
| 1544 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { | 1660 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { |
| 1545 WebMouseEvent event; | 1661 WebMouseEvent event; |
| 1546 InitMouseEvent(WebInputEvent::MouseDown, | 1662 InitMouseEvent(WebInputEvent::MouseDown, |
| 1547 pressed_button_, | 1663 current_pointer_state_[kMousePointerId].pressed_button_, |
| 1548 current_buttons_, | 1664 current_pointer_state_[kMousePointerId].current_buttons_, |
| 1549 last_mouse_pos_, | 1665 current_pointer_state_[kMousePointerId].last_pos_, |
| 1550 GetCurrentEventTimeSec(), | 1666 GetCurrentEventTimeSec(), |
| 1551 click_count_, | 1667 click_count_, |
| 1552 0, | 1668 0, |
| 1669 blink::WebPointerProperties::PointerType::Mouse, | |
| 1670 0, | |
| 1553 &event); | 1671 &event); |
| 1554 FinishDragAndDrop(event, blink::WebDragOperationNone); | 1672 FinishDragAndDrop(event, blink::WebDragOperationNone); |
| 1555 } | 1673 } |
| 1556 | 1674 |
| 1557 delegate_->ClearEditCommand(); | 1675 delegate_->ClearEditCommand(); |
| 1558 | 1676 |
| 1559 if (generate_char) { | 1677 if (generate_char) { |
| 1560 WebKeyboardEvent event_char = event_up; | 1678 WebKeyboardEvent event_char = event_up; |
| 1561 event_char.type = WebInputEvent::Char; | 1679 event_char.type = WebInputEvent::Char; |
| 1562 // keyIdentifier is an empty string, unless the Enter key was pressed. | 1680 // keyIdentifier is an empty string, unless the Enter key was pressed. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1587 // be requested after following mouse events. | 1705 // be requested after following mouse events. |
| 1588 last_context_menu_data_.reset(); | 1706 last_context_menu_data_.reset(); |
| 1589 | 1707 |
| 1590 // Generate right mouse down and up. | 1708 // Generate right mouse down and up. |
| 1591 WebMouseEvent event; | 1709 WebMouseEvent event; |
| 1592 // This is a hack to work around only allowing a single pressed button since | 1710 // This is a hack to work around only allowing a single pressed button since |
| 1593 // we want to test the case where both the left and right mouse buttons are | 1711 // we want to test the case where both the left and right mouse buttons are |
| 1594 // pressed. | 1712 // pressed. |
| 1595 // TODO(mustaq): This hack seems unused here! But do we need this hack at all | 1713 // TODO(mustaq): This hack seems unused here! But do we need this hack at all |
| 1596 // after adding current_buttons_. | 1714 // after adding current_buttons_. |
| 1597 if (pressed_button_ == WebMouseEvent::ButtonNone) { | 1715 if (current_pointer_state_[kMousePointerId].pressed_button_ |
| 1598 pressed_button_ = WebMouseEvent::ButtonRight; | 1716 == WebMouseEvent::ButtonNone) { |
| 1599 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 1717 current_pointer_state_[kMousePointerId].pressed_button_ = |
| 1718 WebMouseEvent::ButtonRight; | |
| 1719 current_pointer_state_[kMousePointerId].current_buttons_ |= | |
| 1720 GetWebMouseEventModifierForButton( | |
| 1721 current_pointer_state_[kMousePointerId].pressed_button_); | |
| 1600 } | 1722 } |
| 1601 InitMouseEvent(WebInputEvent::MouseDown, | 1723 InitMouseEvent(WebInputEvent::MouseDown, |
| 1602 WebMouseEvent::ButtonRight, | 1724 WebMouseEvent::ButtonRight, |
| 1603 current_buttons_, | 1725 current_pointer_state_[kMousePointerId].current_buttons_, |
| 1604 last_mouse_pos_, | 1726 current_pointer_state_[kMousePointerId].last_pos_, |
| 1605 GetCurrentEventTimeSec(), | 1727 GetCurrentEventTimeSec(), |
| 1606 click_count_, | 1728 click_count_, |
| 1607 0, | 1729 0, |
| 1730 blink::WebPointerProperties::PointerType::Mouse, | |
| 1731 0, | |
| 1608 &event); | 1732 &event); |
| 1609 HandleInputEventOnViewOrPopup(event); | 1733 HandleInputEventOnViewOrPopup(event); |
| 1610 | 1734 |
| 1611 #if defined(OS_WIN) | 1735 #if defined(OS_WIN) |
| 1612 current_buttons_ &= | 1736 current_pointer_state_[kMousePointerId].current_buttons_ &= |
| 1613 ~GetWebMouseEventModifierForButton(WebMouseEvent::ButtonRight); | 1737 ~GetWebMouseEventModifierForButton(WebMouseEvent::ButtonRight); |
| 1614 pressed_button_ = WebMouseEvent::ButtonNone; | 1738 current_pointer_state_[kMousePointerId].pressed_button_ = |
| 1739 WebMouseEvent::ButtonNone; | |
| 1615 | 1740 |
| 1616 InitMouseEvent(WebInputEvent::MouseUp, | 1741 InitMouseEvent(WebInputEvent::MouseUp, |
| 1617 WebMouseEvent::ButtonRight, | 1742 WebMouseEvent::ButtonRight, |
| 1618 current_buttons_, | 1743 current_pointer_state_[kMousePointerId].current_buttons_, |
| 1619 last_mouse_pos_, | 1744 current_pointer_state_[kMousePointerId].last_pos_, |
| 1620 GetCurrentEventTimeSec(), | 1745 GetCurrentEventTimeSec(), |
| 1621 click_count_, | 1746 click_count_, |
| 1622 0, | 1747 0, |
| 1748 blink::WebPointerProperties::PointerType::Mouse, | |
| 1749 0, | |
| 1623 &event); | 1750 &event); |
| 1624 HandleInputEventOnViewOrPopup(event); | 1751 HandleInputEventOnViewOrPopup(event); |
| 1625 #endif | 1752 #endif |
| 1626 | 1753 |
| 1627 std::vector<std::string> menu_items = | 1754 std::vector<std::string> menu_items = |
| 1628 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate_); | 1755 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate_); |
| 1629 last_context_menu_data_.reset(); | 1756 last_context_menu_data_.reset(); |
| 1630 return menu_items; | 1757 return menu_items; |
| 1631 } | 1758 } |
| 1632 | 1759 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1819 | 1946 |
| 1820 void EventSender::TouchCancel() { | 1947 void EventSender::TouchCancel() { |
| 1821 SendCurrentTouchEvent(WebInputEvent::TouchCancel, false); | 1948 SendCurrentTouchEvent(WebInputEvent::TouchCancel, false); |
| 1822 } | 1949 } |
| 1823 | 1950 |
| 1824 void EventSender::TouchEnd() { | 1951 void EventSender::TouchEnd() { |
| 1825 SendCurrentTouchEvent(WebInputEvent::TouchEnd, false); | 1952 SendCurrentTouchEvent(WebInputEvent::TouchEnd, false); |
| 1826 } | 1953 } |
| 1827 | 1954 |
| 1828 void EventSender::LeapForward(int milliseconds) { | 1955 void EventSender::LeapForward(int milliseconds) { |
| 1829 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && | 1956 if (is_drag_mode_ && current_pointer_state_[kMousePointerId].pressed_button_ |
| 1957 == WebMouseEvent::ButtonLeft && | |
| 1830 !replaying_saved_events_) { | 1958 !replaying_saved_events_) { |
| 1831 SavedEvent saved_event; | 1959 SavedEvent saved_event; |
| 1832 saved_event.type = SavedEvent::TYPE_LEAP_FORWARD; | 1960 saved_event.type = SavedEvent::TYPE_LEAP_FORWARD; |
| 1833 saved_event.milliseconds = milliseconds; | 1961 saved_event.milliseconds = milliseconds; |
| 1834 mouse_event_queue_.push_back(saved_event); | 1962 mouse_event_queue_.push_back(saved_event); |
| 1835 } else { | 1963 } else { |
| 1836 DoLeapForward(milliseconds); | 1964 DoLeapForward(milliseconds); |
| 1837 } | 1965 } |
| 1838 } | 1966 } |
| 1839 | 1967 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1856 item.filenameData = delegate_->GetAbsoluteWebStringFromUTF8Path(files[i]); | 1984 item.filenameData = delegate_->GetAbsoluteWebStringFromUTF8Path(files[i]); |
| 1857 current_drag_data_.addItem(item); | 1985 current_drag_data_.addItem(item); |
| 1858 absolute_filenames[i] = item.filenameData; | 1986 absolute_filenames[i] = item.filenameData; |
| 1859 } | 1987 } |
| 1860 current_drag_data_.setFilesystemId( | 1988 current_drag_data_.setFilesystemId( |
| 1861 delegate_->RegisterIsolatedFileSystem(absolute_filenames)); | 1989 delegate_->RegisterIsolatedFileSystem(absolute_filenames)); |
| 1862 current_drag_effects_allowed_ = blink::WebDragOperationCopy; | 1990 current_drag_effects_allowed_ = blink::WebDragOperationCopy; |
| 1863 | 1991 |
| 1864 // Provide a drag source. | 1992 // Provide a drag source. |
| 1865 view_->dragTargetDragEnter(current_drag_data_, | 1993 view_->dragTargetDragEnter(current_drag_data_, |
| 1866 last_mouse_pos_, | 1994 current_pointer_state_[kMousePointerId].last_pos_, |
| 1867 last_mouse_pos_, | 1995 current_pointer_state_[kMousePointerId].last_pos_, |
| 1868 current_drag_effects_allowed_, | 1996 current_drag_effects_allowed_, |
| 1869 0); | 1997 0); |
| 1870 // |is_drag_mode_| saves events and then replays them later. We don't | 1998 // |is_drag_mode_| saves events and then replays them later. We don't |
| 1871 // need/want that. | 1999 // need/want that. |
| 1872 is_drag_mode_ = false; | 2000 is_drag_mode_ = false; |
| 1873 | 2001 |
| 1874 // Make the rest of eventSender think a drag is in progress. | 2002 // Make the rest of eventSender think a drag is in progress. |
| 1875 pressed_button_ = WebMouseEvent::ButtonLeft; | 2003 current_pointer_state_[kMousePointerId].pressed_button_ = |
| 1876 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 2004 WebMouseEvent::ButtonLeft; |
| 2005 current_pointer_state_[kMousePointerId].current_buttons_ |= | |
| 2006 GetWebMouseEventModifierForButton( | |
| 2007 current_pointer_state_[kMousePointerId].pressed_button_); | |
| 1877 } | 2008 } |
| 1878 | 2009 |
| 1879 void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) { | 2010 void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) { |
| 1880 WebTouchPoint touch_point; | 2011 WebTouchPoint touch_point; |
| 1881 touch_point.pointerType = WebPointerProperties::PointerType::Touch; | 2012 touch_point.pointerType = WebPointerProperties::PointerType::Touch; |
| 1882 touch_point.state = WebTouchPoint::StatePressed; | 2013 touch_point.state = WebTouchPoint::StatePressed; |
| 1883 touch_point.position = WebFloatPoint(x, y); | 2014 touch_point.position = WebFloatPoint(x, y); |
| 1884 touch_point.screenPosition = touch_point.position; | 2015 touch_point.screenPosition = touch_point.position; |
| 1885 | 2016 |
| 1886 int highest_id = -1; | 2017 int highest_id = -1; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1966 SendGesturesForMouseWheelEvent(wheel_event); | 2097 SendGesturesForMouseWheelEvent(wheel_event); |
| 1967 } | 2098 } |
| 1968 } | 2099 } |
| 1969 | 2100 |
| 1970 void EventSender::MouseMoveTo(gin::Arguments* args) { | 2101 void EventSender::MouseMoveTo(gin::Arguments* args) { |
| 1971 if (force_layout_on_events_) | 2102 if (force_layout_on_events_) |
| 1972 view_->updateAllLifecyclePhases(); | 2103 view_->updateAllLifecyclePhases(); |
| 1973 | 2104 |
| 1974 double x; | 2105 double x; |
| 1975 double y; | 2106 double y; |
| 2107 blink::WebPointerProperties::PointerType pointerType = | |
| 2108 blink::WebPointerProperties::PointerType::Mouse; | |
| 2109 int pointerId = 0; | |
| 1976 if (!args->GetNext(&x) || !args->GetNext(&y)) { | 2110 if (!args->GetNext(&x) || !args->GetNext(&y)) { |
| 1977 args->ThrowError(); | 2111 args->ThrowError(); |
| 1978 return; | 2112 return; |
| 1979 } | 2113 } |
| 1980 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); | 2114 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); |
| 1981 | 2115 |
| 1982 int modifiers = 0; | 2116 int modifiers = 0; |
| 1983 if (!args->PeekNext().IsEmpty()) | 2117 if (!args->PeekNext().IsEmpty()) { |
| 1984 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); | 2118 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
| 2119 args->Skip(); | |
| 2120 } | |
| 1985 | 2121 |
| 1986 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && | 2122 if (!getMousePenPointerTypeAndId(args, pointerType, pointerId)) |
| 1987 !replaying_saved_events_) { | 2123 return; |
| 1988 SavedEvent saved_event; | 2124 |
| 1989 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; | 2125 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) { |
| 1990 saved_event.pos = mouse_pos; | 2126 if (is_drag_mode_ && current_pointer_state_[kMousePointerId].pressed_button_ |
| 1991 saved_event.modifiers = modifiers; | 2127 == WebMouseEvent::ButtonLeft |
| 1992 mouse_event_queue_.push_back(saved_event); | 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 current_pointer_state_[kMousePointerId].pressed_button_, | |
| 2138 current_pointer_state_[kMousePointerId].current_buttons_, | |
| 2139 mouse_pos, | |
| 2140 GetCurrentEventTimeSec(), | |
| 2141 click_count_, | |
| 2142 modifiers, | |
| 2143 pointerType, | |
| 2144 0, | |
|
mustaq
2016/04/07 19:30:02
Same as before, don't worry about pointerId, and u
Navid Zolghadr
2016/04/08 17:38:44
Done.
| |
| 2145 &event); | |
| 2146 DoMouseMove(event); | |
| 2147 } | |
| 1993 } else { | 2148 } else { |
| 1994 WebMouseEvent event; | 2149 current_pointer_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_pointer_state_[pointerId].pressed_button_, |
| 1999 GetCurrentEventTimeSec(), | 2154 current_pointer_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 current_pointer_state_[kMousePointerId].last_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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2320 | 2481 |
| 2321 if (force_layout_on_events_) | 2482 if (force_layout_on_events_) |
| 2322 view_->updateAllLifecyclePhases(); | 2483 view_->updateAllLifecyclePhases(); |
| 2323 | 2484 |
| 2324 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); | 2485 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); |
| 2325 | 2486 |
| 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 current_pointer_state_[kMousePointerId].pressed_button_, |
| 2331 current_buttons_, | 2492 current_pointer_state_[kMousePointerId].current_buttons_, |
| 2332 WebPoint(x, y), | 2493 WebPoint(x, y), |
| 2333 GetCurrentEventTimeSec(), | 2494 GetCurrentEventTimeSec(), |
| 2334 click_count_, | 2495 click_count_, |
| 2335 modifiers_, | 2496 current_pointer_state_[kMousePointerId].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_ < |
| 2346 kMultipleClickTimeSec) && | 2509 kMultipleClickTimeSec) && |
| 2347 (!OutsideMultiClickRadius(last_mouse_pos_, last_click_pos_)) && | 2510 (!OutsideMultiClickRadius( |
| 2348 (button_type == last_button_type_)) { | 2511 current_pointer_state_[kMousePointerId].last_pos_, last_click_pos_)) |
| 2512 && (button_type == last_button_type_)) { | |
| 2349 ++click_count_; | 2513 ++click_count_; |
| 2350 } else { | 2514 } else { |
| 2351 click_count_ = 1; | 2515 click_count_ = 1; |
| 2352 last_button_type_ = button_type; | 2516 last_button_type_ = button_type; |
| 2353 } | 2517 } |
| 2354 } | 2518 } |
| 2355 | 2519 |
| 2356 void EventSender::InitMouseWheelEvent(gin::Arguments* args, | 2520 void EventSender::InitMouseWheelEvent(gin::Arguments* args, |
| 2357 MouseScrollType scroll_type, | 2521 MouseScrollType scroll_type, |
| 2358 WebMouseWheelEvent* event, | 2522 WebMouseWheelEvent* event, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2391 } | 2555 } |
| 2392 } | 2556 } |
| 2393 } | 2557 } |
| 2394 } | 2558 } |
| 2395 if (can_scroll && send_wheel_gestures_) { | 2559 if (can_scroll && send_wheel_gestures_) { |
| 2396 can_scroll = false; | 2560 can_scroll = false; |
| 2397 *send_gestures = true; | 2561 *send_gestures = true; |
| 2398 } | 2562 } |
| 2399 | 2563 |
| 2400 InitMouseEvent(WebInputEvent::MouseWheel, | 2564 InitMouseEvent(WebInputEvent::MouseWheel, |
| 2401 pressed_button_, | 2565 current_pointer_state_[kMousePointerId].pressed_button_, |
| 2402 current_buttons_, | 2566 current_pointer_state_[kMousePointerId].current_buttons_, |
| 2403 last_mouse_pos_, | 2567 current_pointer_state_[kMousePointerId].last_pos_, |
| 2404 GetCurrentEventTimeSec(), | 2568 GetCurrentEventTimeSec(), |
| 2405 click_count_, | 2569 click_count_, |
| 2406 modifiers, | 2570 modifiers, |
| 2571 blink::WebPointerProperties::PointerType::Mouse, | |
| 2572 0, | |
| 2407 event); | 2573 event); |
| 2408 event->wheelTicksX = static_cast<float>(horizontal); | 2574 event->wheelTicksX = static_cast<float>(horizontal); |
| 2409 event->wheelTicksY = static_cast<float>(vertical); | 2575 event->wheelTicksY = static_cast<float>(vertical); |
| 2410 event->deltaX = event->wheelTicksX; | 2576 event->deltaX = event->wheelTicksX; |
| 2411 event->deltaY = event->wheelTicksY; | 2577 event->deltaY = event->wheelTicksY; |
| 2412 event->scrollByPage = paged; | 2578 event->scrollByPage = paged; |
| 2413 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; | 2579 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; |
| 2414 event->canScroll = can_scroll; | 2580 event->canScroll = can_scroll; |
| 2415 if (scroll_type == MouseScrollType::PIXEL) { | 2581 if (scroll_type == MouseScrollType::PIXEL) { |
| 2416 event->wheelTicksX /= kScrollbarPixelsPerTick; | 2582 event->wheelTicksX /= kScrollbarPixelsPerTick; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2459 if (!args->PeekNext().IsEmpty()) { | 2625 if (!args->PeekNext().IsEmpty()) { |
| 2460 int tiltX, tiltY; | 2626 int tiltX, tiltY; |
| 2461 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) { | 2627 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) { |
| 2462 args->ThrowError(); | 2628 args->ThrowError(); |
| 2463 return; | 2629 return; |
| 2464 } | 2630 } |
| 2465 e->tiltX = tiltX; | 2631 e->tiltX = tiltX; |
| 2466 e->tiltY = tiltY; | 2632 e->tiltY = tiltY; |
| 2467 } | 2633 } |
| 2468 | 2634 |
| 2469 if (!args->PeekNext().IsEmpty()) { | 2635 if (!getPointerType(args, e->pointerType)) |
| 2470 std::string pointer_type_string; | 2636 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 } | 2637 } |
| 2489 | 2638 |
| 2490 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, | 2639 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, |
| 2491 blink::WebDragOperation drag_effect) { | 2640 blink::WebDragOperation drag_effect) { |
| 2492 WebPoint client_point(e.x, e.y); | 2641 WebPoint client_point(e.x, e.y); |
| 2493 WebPoint screen_point(e.globalX, e.globalY); | 2642 WebPoint screen_point(e.globalX, e.globalY); |
| 2494 current_drag_effect_ = drag_effect; | 2643 current_drag_effect_ = drag_effect; |
| 2495 if (current_drag_effect_) { | 2644 if (current_drag_effect_) { |
| 2496 // Specifically pass any keyboard modifiers to the drop method. This allows | 2645 // Specifically pass any keyboard modifiers to the drop method. This allows |
| 2497 // tests to control the drop type (i.e. copy or move). | 2646 // tests to control the drop type (i.e. copy or move). |
| 2498 view_->dragTargetDrop(client_point, screen_point, e.modifiers); | 2647 view_->dragTargetDrop(client_point, screen_point, e.modifiers); |
| 2499 } else { | 2648 } else { |
| 2500 view_->dragTargetDragLeave(); | 2649 view_->dragTargetDragLeave(); |
| 2501 } | 2650 } |
| 2502 view_->dragSourceEndedAt(client_point, screen_point, current_drag_effect_); | 2651 view_->dragSourceEndedAt(client_point, screen_point, current_drag_effect_); |
| 2503 view_->dragSourceSystemDragEnded(); | 2652 view_->dragSourceSystemDragEnded(); |
| 2504 | 2653 |
| 2505 current_drag_data_.reset(); | 2654 current_drag_data_.reset(); |
| 2506 } | 2655 } |
| 2507 | 2656 |
| 2508 void EventSender::DoMouseUp(const WebMouseEvent& e) { | 2657 void EventSender::DoMouseUp(const WebMouseEvent& e) { |
| 2509 HandleInputEventOnViewOrPopup(e); | 2658 HandleInputEventOnViewOrPopup(e); |
| 2510 | 2659 |
| 2511 last_click_time_sec_ = e.timeStampSeconds; | 2660 last_click_time_sec_ = e.timeStampSeconds; |
| 2512 last_click_pos_ = last_mouse_pos_; | 2661 last_click_pos_ = current_pointer_state_[kMousePointerId].last_pos_; |
| 2513 | 2662 |
| 2514 // If we're in a drag operation, complete it. | 2663 // If we're in a drag operation, complete it. |
| 2515 if (current_drag_data_.isNull()) | 2664 if (current_drag_data_.isNull()) |
| 2516 return; | 2665 return; |
| 2517 | 2666 |
| 2518 WebPoint client_point(e.x, e.y); | 2667 WebPoint client_point(e.x, e.y); |
| 2519 WebPoint screen_point(e.globalX, e.globalY); | 2668 WebPoint screen_point(e.globalX, e.globalY); |
| 2520 blink::WebDragOperation drag_effect = view_->dragTargetDragOver( | 2669 blink::WebDragOperation drag_effect = view_->dragTargetDragOver( |
| 2521 client_point, | 2670 client_point, |
| 2522 screen_point, | 2671 screen_point, |
| 2523 current_drag_effects_allowed_, | 2672 current_drag_effects_allowed_, |
| 2524 e.modifiers); | 2673 e.modifiers); |
| 2525 | 2674 |
| 2526 // Bail if dragover caused cancellation. | 2675 // Bail if dragover caused cancellation. |
| 2527 if (current_drag_data_.isNull()) | 2676 if (current_drag_data_.isNull()) |
| 2528 return; | 2677 return; |
| 2529 | 2678 |
| 2530 FinishDragAndDrop(e, drag_effect); | 2679 FinishDragAndDrop(e, drag_effect); |
| 2531 } | 2680 } |
| 2532 | 2681 |
| 2533 void EventSender::DoMouseMove(const WebMouseEvent& e) { | 2682 void EventSender::DoMouseMove(const WebMouseEvent& e) { |
| 2534 last_mouse_pos_ = WebPoint(e.x, e.y); | 2683 current_pointer_state_[kMousePointerId].last_pos_ = WebPoint(e.x, e.y); |
| 2535 | 2684 |
| 2536 HandleInputEventOnViewOrPopup(e); | 2685 HandleInputEventOnViewOrPopup(e); |
| 2537 | 2686 |
| 2538 if (pressed_button_ == WebMouseEvent::ButtonNone || | 2687 if (current_pointer_state_[kMousePointerId].pressed_button_ |
| 2539 current_drag_data_.isNull()) { | 2688 == WebMouseEvent::ButtonNone |
| 2689 || current_drag_data_.isNull()) { | |
| 2540 return; | 2690 return; |
| 2541 } | 2691 } |
| 2542 | 2692 |
| 2543 WebPoint client_point(e.x, e.y); | 2693 WebPoint client_point(e.x, e.y); |
| 2544 WebPoint screen_point(e.globalX, e.globalY); | 2694 WebPoint screen_point(e.globalX, e.globalY); |
| 2545 current_drag_effect_ = view_->dragTargetDragOver( | 2695 current_drag_effect_ = view_->dragTargetDragOver( |
| 2546 client_point, screen_point, current_drag_effects_allowed_, e.modifiers); | 2696 client_point, screen_point, current_drag_effects_allowed_, e.modifiers); |
| 2547 } | 2697 } |
| 2548 | 2698 |
| 2549 void EventSender::ReplaySavedEvents() { | 2699 void EventSender::ReplaySavedEvents() { |
| 2550 replaying_saved_events_ = true; | 2700 replaying_saved_events_ = true; |
| 2551 while (!mouse_event_queue_.empty()) { | 2701 while (!mouse_event_queue_.empty()) { |
| 2552 SavedEvent e = mouse_event_queue_.front(); | 2702 SavedEvent e = mouse_event_queue_.front(); |
| 2553 mouse_event_queue_.pop_front(); | 2703 mouse_event_queue_.pop_front(); |
| 2554 | 2704 |
| 2555 switch (e.type) { | 2705 switch (e.type) { |
| 2556 case SavedEvent::TYPE_MOUSE_MOVE: { | 2706 case SavedEvent::TYPE_MOUSE_MOVE: { |
| 2557 WebMouseEvent event; | 2707 WebMouseEvent event; |
| 2558 InitMouseEvent(WebInputEvent::MouseMove, | 2708 InitMouseEvent(WebInputEvent::MouseMove, |
| 2559 pressed_button_, | 2709 current_pointer_state_[kMousePointerId].pressed_button_, |
| 2560 current_buttons_, | 2710 current_pointer_state_[kMousePointerId].current_buttons_, |
| 2561 e.pos, | 2711 e.pos, |
| 2562 GetCurrentEventTimeSec(), | 2712 GetCurrentEventTimeSec(), |
| 2563 click_count_, | 2713 click_count_, |
| 2564 e.modifiers, | 2714 e.modifiers, |
| 2715 blink::WebPointerProperties::PointerType::Mouse, | |
| 2716 0, | |
| 2565 &event); | 2717 &event); |
| 2566 DoMouseMove(event); | 2718 DoMouseMove(event); |
| 2567 break; | 2719 break; |
| 2568 } | 2720 } |
| 2569 case SavedEvent::TYPE_LEAP_FORWARD: | 2721 case SavedEvent::TYPE_LEAP_FORWARD: |
| 2570 DoLeapForward(e.milliseconds); | 2722 DoLeapForward(e.milliseconds); |
| 2571 break; | 2723 break; |
| 2572 case SavedEvent::TYPE_MOUSE_UP: { | 2724 case SavedEvent::TYPE_MOUSE_UP: { |
| 2573 current_buttons_ &= ~GetWebMouseEventModifierForButton(e.button_type); | 2725 current_pointer_state_[kMousePointerId].current_buttons_ &= |
| 2574 pressed_button_ = WebMouseEvent::ButtonNone; | 2726 ~GetWebMouseEventModifierForButton(e.button_type); |
| 2727 current_pointer_state_[kMousePointerId].pressed_button_ = | |
| 2728 WebMouseEvent::ButtonNone; | |
| 2575 | 2729 |
| 2576 WebMouseEvent event; | 2730 WebMouseEvent event; |
| 2577 InitMouseEvent(WebInputEvent::MouseUp, | 2731 InitMouseEvent(WebInputEvent::MouseUp, |
| 2578 e.button_type, | 2732 e.button_type, |
| 2579 current_buttons_, | 2733 current_pointer_state_[kMousePointerId].current_buttons_, |
| 2580 last_mouse_pos_, | 2734 current_pointer_state_[kMousePointerId].last_pos_, |
| 2581 GetCurrentEventTimeSec(), | 2735 GetCurrentEventTimeSec(), |
| 2582 click_count_, | 2736 click_count_, |
| 2583 e.modifiers, | 2737 e.modifiers, |
| 2738 blink::WebPointerProperties::PointerType::Mouse, | |
| 2739 0, | |
| 2584 &event); | 2740 &event); |
| 2585 DoMouseUp(event); | 2741 DoMouseUp(event); |
| 2586 break; | 2742 break; |
| 2587 } | 2743 } |
| 2588 default: | 2744 default: |
| 2589 NOTREACHED(); | 2745 NOTREACHED(); |
| 2590 } | 2746 } |
| 2591 } | 2747 } |
| 2592 | 2748 |
| 2593 replaying_saved_events_ = false; | 2749 replaying_saved_events_ = false; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2655 &end_event); | 2811 &end_event); |
| 2656 end_event.data.scrollEnd.deltaUnits = | 2812 end_event.data.scrollEnd.deltaUnits = |
| 2657 begin_event.data.scrollBegin.deltaHintUnits; | 2813 begin_event.data.scrollBegin.deltaHintUnits; |
| 2658 | 2814 |
| 2659 if (force_layout_on_events_) | 2815 if (force_layout_on_events_) |
| 2660 view_->updateAllLifecyclePhases(); | 2816 view_->updateAllLifecyclePhases(); |
| 2661 HandleInputEventOnViewOrPopup(end_event); | 2817 HandleInputEventOnViewOrPopup(end_event); |
| 2662 } | 2818 } |
| 2663 | 2819 |
| 2664 } // namespace test_runner | 2820 } // namespace test_runner |
| OLD | NEW |