OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/test_runner/event_sender.h" | 5 #include "components/test_runner/event_sender.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 using blink::WebString; | 54 using blink::WebString; |
55 using blink::WebTouchEvent; | 55 using blink::WebTouchEvent; |
56 using blink::WebTouchPoint; | 56 using blink::WebTouchPoint; |
57 using blink::WebVector; | 57 using blink::WebVector; |
58 using blink::WebView; | 58 using blink::WebView; |
59 | 59 |
60 namespace test_runner { | 60 namespace test_runner { |
61 | 61 |
62 namespace { | 62 namespace { |
63 | 63 |
| 64 const int kMousePointerId = -1; |
| 65 const char* kPointerTypeStringUnknown = ""; |
| 66 const char* kPointerTypeStringMouse = "mouse"; |
| 67 const char* kPointerTypeStringPen = "pen"; |
| 68 const char* kPointerTypeStringTouch = "touch"; |
| 69 |
| 70 // Assigns |pointerType| from the provided |args|. Returns false if there was |
| 71 // any error. |
| 72 bool getPointerType(gin::Arguments* args, |
| 73 bool isOnlyMouseAndPenAllowed, |
| 74 blink::WebPointerProperties::PointerType& pointerType) { |
| 75 if (args->PeekNext().IsEmpty()) |
| 76 return true; |
| 77 std::string pointer_type_string; |
| 78 if (!args->GetNext(&pointer_type_string)) { |
| 79 args->ThrowError(); |
| 80 return false; |
| 81 } |
| 82 if (isOnlyMouseAndPenAllowed && |
| 83 (pointer_type_string == kPointerTypeStringUnknown || |
| 84 pointer_type_string == kPointerTypeStringTouch)) { |
| 85 args->ThrowError(); |
| 86 return false; |
| 87 } |
| 88 if (pointer_type_string == kPointerTypeStringUnknown) { |
| 89 pointerType = WebMouseEvent::PointerType::Unknown; |
| 90 } else if (pointer_type_string == kPointerTypeStringMouse) { |
| 91 pointerType = WebMouseEvent::PointerType::Mouse; |
| 92 } else if (pointer_type_string == kPointerTypeStringPen) { |
| 93 pointerType = WebMouseEvent::PointerType::Pen; |
| 94 } else if (pointer_type_string == kPointerTypeStringTouch) { |
| 95 pointerType = WebMouseEvent::PointerType::Touch; |
| 96 } else { |
| 97 args->ThrowError(); |
| 98 return false; |
| 99 } |
| 100 return true; |
| 101 } |
| 102 |
| 103 // Assigns |pointerType| and |pointerId| from the provided |args|. Returns |
| 104 // false if there was any error. |
| 105 bool getMousePenPointerTypeAndId( |
| 106 gin::Arguments* args, |
| 107 blink::WebPointerProperties::PointerType& pointerType, |
| 108 int& pointerId) { |
| 109 pointerType = blink::WebPointerProperties::PointerType::Mouse; |
| 110 pointerId = kMousePointerId; |
| 111 // Only allow pen or mouse through this API. |
| 112 if (!getPointerType(args, false, pointerType)) |
| 113 return false; |
| 114 if (!args->PeekNext().IsEmpty()) { |
| 115 if (!args->GetNext(&pointerId)) { |
| 116 args->ThrowError(); |
| 117 return false; |
| 118 } |
| 119 if (pointerType != blink::WebPointerProperties::PointerType::Mouse && |
| 120 pointerId == kMousePointerId) { |
| 121 args->ThrowError(); |
| 122 return false; |
| 123 } |
| 124 } else if (pointerType == blink::WebPointerProperties::PointerType::Pen) { |
| 125 pointerId = 1; // A default value for the id of the pen. |
| 126 } |
| 127 return true; |
| 128 } |
| 129 |
64 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { | 130 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { |
65 switch (button_code) { | 131 switch (button_code) { |
66 case -1: | 132 case -1: |
67 return WebMouseEvent::ButtonNone; | 133 return WebMouseEvent::ButtonNone; |
68 case 0: | 134 case 0: |
69 return WebMouseEvent::ButtonLeft; | 135 return WebMouseEvent::ButtonLeft; |
70 case 1: | 136 case 1: |
71 return WebMouseEvent::ButtonMiddle; | 137 return WebMouseEvent::ButtonMiddle; |
72 case 2: | 138 case 2: |
73 return WebMouseEvent::ButtonRight; | 139 return WebMouseEvent::ButtonRight; |
(...skipping 25 matching lines...) Expand all Loading... |
99 | (buttons & kButtonsInModifiers); | 165 | (buttons & kButtonsInModifiers); |
100 } | 166 } |
101 | 167 |
102 void InitMouseEvent(WebInputEvent::Type t, | 168 void InitMouseEvent(WebInputEvent::Type t, |
103 WebMouseEvent::Button b, | 169 WebMouseEvent::Button b, |
104 int current_buttons, | 170 int current_buttons, |
105 const WebPoint& pos, | 171 const WebPoint& pos, |
106 double time_stamp, | 172 double time_stamp, |
107 int click_count, | 173 int click_count, |
108 int modifiers, | 174 int modifiers, |
| 175 blink::WebPointerProperties::PointerType pointerType, |
| 176 int pointerId, |
109 WebMouseEvent* e) { | 177 WebMouseEvent* e) { |
110 e->type = t; | 178 e->type = t; |
111 e->button = b; | 179 e->button = b; |
112 e->modifiers = modifiersWithButtons(modifiers, current_buttons); | 180 e->modifiers = modifiersWithButtons(modifiers, current_buttons); |
113 e->x = pos.x; | 181 e->x = pos.x; |
114 e->y = pos.y; | 182 e->y = pos.y; |
115 e->globalX = pos.x; | 183 e->globalX = pos.x; |
116 e->globalY = pos.y; | 184 e->globalY = pos.y; |
117 e->pointerType = blink::WebPointerProperties::PointerType::Mouse; | 185 e->pointerType = pointerType; |
| 186 e->id = pointerId; |
118 e->timeStampSeconds = time_stamp; | 187 e->timeStampSeconds = time_stamp; |
119 e->clickCount = click_count; | 188 e->clickCount = click_count; |
120 } | 189 } |
121 | 190 |
122 void InitGestureEventFromMouseWheel(WebInputEvent::Type type, | 191 void InitGestureEventFromMouseWheel(WebInputEvent::Type type, |
123 double time_stamp, | 192 double time_stamp, |
124 const WebMouseWheelEvent& wheel_event, | 193 const WebMouseWheelEvent& wheel_event, |
125 WebGestureEvent* gesture_event) { | 194 WebGestureEvent* gesture_event) { |
126 gesture_event->type = type; | 195 gesture_event->type = type; |
127 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad; | 196 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 471 } |
403 } else { | 472 } else { |
404 *units = WebGestureEvent::PrecisePixels; | 473 *units = WebGestureEvent::PrecisePixels; |
405 return true; | 474 return true; |
406 } | 475 } |
407 } | 476 } |
408 | 477 |
409 const char* kSourceDeviceStringTouchpad = "touchpad"; | 478 const char* kSourceDeviceStringTouchpad = "touchpad"; |
410 const char* kSourceDeviceStringTouchscreen = "touchscreen"; | 479 const char* kSourceDeviceStringTouchscreen = "touchscreen"; |
411 | 480 |
412 const char* kPointerTypeStringUnknown = ""; | |
413 const char* kPointerTypeStringMouse = "mouse"; | |
414 const char* kPointerTypeStringPen = "pen"; | |
415 const char* kPointerTypeStringTouch = "touch"; | |
416 | |
417 } // namespace | 481 } // namespace |
418 | 482 |
419 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { | 483 class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { |
420 public: | 484 public: |
421 static gin::WrapperInfo kWrapperInfo; | 485 static gin::WrapperInfo kWrapperInfo; |
422 | 486 |
423 static void Install(base::WeakPtr<EventSender> sender, | 487 static void Install(base::WeakPtr<EventSender> sender, |
424 blink::WebFrame* frame); | 488 blink::WebFrame* frame); |
425 | 489 |
426 private: | 490 private: |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 sender_->ScheduleAsynchronousKeyDown(code_str, modifiers, | 989 sender_->ScheduleAsynchronousKeyDown(code_str, modifiers, |
926 static_cast<KeyLocationCode>(location)); | 990 static_cast<KeyLocationCode>(location)); |
927 } | 991 } |
928 | 992 |
929 void EventSenderBindings::MouseDown(gin::Arguments* args) { | 993 void EventSenderBindings::MouseDown(gin::Arguments* args) { |
930 if (!sender_) | 994 if (!sender_) |
931 return; | 995 return; |
932 | 996 |
933 int button_number = 0; | 997 int button_number = 0; |
934 int modifiers = 0; | 998 int modifiers = 0; |
| 999 blink::WebPointerProperties::PointerType pointerType = |
| 1000 blink::WebPointerProperties::PointerType::Mouse; |
| 1001 int pointerId = 0; |
935 if (!args->PeekNext().IsEmpty()) { | 1002 if (!args->PeekNext().IsEmpty()) { |
936 args->GetNext(&button_number); | 1003 if (!args->GetNext(&button_number)) { |
937 if (!args->PeekNext().IsEmpty()) | 1004 args->ThrowError(); |
| 1005 return; |
| 1006 } |
| 1007 if (!args->PeekNext().IsEmpty()) { |
938 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); | 1008 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
| 1009 args->Skip(); |
| 1010 } |
939 } | 1011 } |
940 sender_->MouseDown(button_number, modifiers); | 1012 |
| 1013 if (!getMousePenPointerTypeAndId(args, pointerType, pointerId)) |
| 1014 return; |
| 1015 |
| 1016 sender_->PointerDown(button_number, modifiers, pointerType, pointerId); |
941 } | 1017 } |
942 | 1018 |
943 void EventSenderBindings::MouseUp(gin::Arguments* args) { | 1019 void EventSenderBindings::MouseUp(gin::Arguments* args) { |
944 if (!sender_) | 1020 if (!sender_) |
945 return; | 1021 return; |
946 | 1022 |
947 int button_number = 0; | 1023 int button_number = 0; |
948 int modifiers = 0; | 1024 int modifiers = 0; |
| 1025 blink::WebPointerProperties::PointerType pointerType = |
| 1026 blink::WebPointerProperties::PointerType::Mouse; |
| 1027 int pointerId = 0; |
949 if (!args->PeekNext().IsEmpty()) { | 1028 if (!args->PeekNext().IsEmpty()) { |
950 args->GetNext(&button_number); | 1029 if (!args->GetNext(&button_number)) { |
951 if (!args->PeekNext().IsEmpty()) | 1030 args->ThrowError(); |
| 1031 return; |
| 1032 } |
| 1033 if (!args->PeekNext().IsEmpty()) { |
952 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); | 1034 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
| 1035 args->Skip(); |
| 1036 } |
953 } | 1037 } |
954 sender_->MouseUp(button_number, modifiers); | 1038 |
| 1039 if (!getMousePenPointerTypeAndId(args, pointerType, pointerId)) |
| 1040 return; |
| 1041 |
| 1042 sender_->PointerUp(button_number, modifiers, pointerType, pointerId); |
955 } | 1043 } |
956 | 1044 |
957 void EventSenderBindings::SetMouseButtonState(gin::Arguments* args) { | 1045 void EventSenderBindings::SetMouseButtonState(gin::Arguments* args) { |
958 if (!sender_) | 1046 if (!sender_) |
959 return; | 1047 return; |
960 | 1048 |
961 int button_number; | 1049 int button_number; |
962 if (!args->GetNext(&button_number)) { | 1050 if (!args->GetNext(&button_number)) { |
963 args->ThrowError(); | 1051 args->ThrowError(); |
964 return; | 1052 return; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 } | 1185 } |
1098 | 1186 |
1099 void EventSenderBindings::SetWmSysDeadChar(int sys_dead_char) { | 1187 void EventSenderBindings::SetWmSysDeadChar(int sys_dead_char) { |
1100 if (sender_) | 1188 if (sender_) |
1101 sender_->set_wm_sys_dead_char(sys_dead_char); | 1189 sender_->set_wm_sys_dead_char(sys_dead_char); |
1102 } | 1190 } |
1103 #endif | 1191 #endif |
1104 | 1192 |
1105 // EventSender ----------------------------------------------------------------- | 1193 // EventSender ----------------------------------------------------------------- |
1106 | 1194 |
1107 WebMouseEvent::Button EventSender::pressed_button_ = WebMouseEvent::ButtonNone; | |
1108 int EventSender::current_buttons_ = 0; | |
1109 int EventSender::modifiers_ = 0; | |
1110 | |
1111 WebPoint EventSender::last_mouse_pos_; | |
1112 | |
1113 WebMouseEvent::Button EventSender::last_button_type_ = | 1195 WebMouseEvent::Button EventSender::last_button_type_ = |
1114 WebMouseEvent::ButtonNone; | 1196 WebMouseEvent::ButtonNone; |
1115 | 1197 |
1116 EventSender::SavedEvent::SavedEvent() | 1198 EventSender::SavedEvent::SavedEvent() |
1117 : type(TYPE_UNSPECIFIED), | 1199 : type(TYPE_UNSPECIFIED), |
1118 button_type(WebMouseEvent::ButtonNone), | 1200 button_type(WebMouseEvent::ButtonNone), |
1119 milliseconds(0), | 1201 milliseconds(0), |
1120 modifiers(0) {} | 1202 modifiers(0) {} |
1121 | 1203 |
1122 EventSender::EventSender(TestInterfaces* interfaces) | 1204 EventSender::EventSender(TestInterfaces* interfaces) |
(...skipping 25 matching lines...) Expand all Loading... |
1148 weak_factory_(this) { | 1230 weak_factory_(this) { |
1149 } | 1231 } |
1150 | 1232 |
1151 EventSender::~EventSender() {} | 1233 EventSender::~EventSender() {} |
1152 | 1234 |
1153 void EventSender::Reset() { | 1235 void EventSender::Reset() { |
1154 DCHECK(current_drag_data_.isNull()); | 1236 DCHECK(current_drag_data_.isNull()); |
1155 current_drag_data_.reset(); | 1237 current_drag_data_.reset(); |
1156 current_drag_effect_ = blink::WebDragOperationNone; | 1238 current_drag_effect_ = blink::WebDragOperationNone; |
1157 current_drag_effects_allowed_ = blink::WebDragOperationNone; | 1239 current_drag_effects_allowed_ = blink::WebDragOperationNone; |
1158 if (view_ && pressed_button_ != WebMouseEvent::ButtonNone) | 1240 if (view_ && |
| 1241 current_pointer_state_[kMousePointerId].pressed_button_ != |
| 1242 WebMouseEvent::ButtonNone) |
1159 view_->mouseCaptureLost(); | 1243 view_->mouseCaptureLost(); |
1160 pressed_button_ = WebMouseEvent::ButtonNone; | 1244 current_pointer_state_.clear(); |
1161 current_buttons_ = 0; | |
1162 modifiers_ = 0; | |
1163 is_drag_mode_ = true; | 1245 is_drag_mode_ = true; |
1164 force_layout_on_events_ = true; | 1246 force_layout_on_events_ = true; |
1165 | 1247 |
1166 #if defined(OS_WIN) | 1248 #if defined(OS_WIN) |
1167 wm_key_down_ = WM_KEYDOWN; | 1249 wm_key_down_ = WM_KEYDOWN; |
1168 wm_key_up_ = WM_KEYUP; | 1250 wm_key_up_ = WM_KEYUP; |
1169 wm_char_ = WM_CHAR; | 1251 wm_char_ = WM_CHAR; |
1170 wm_dead_char_ = WM_DEADCHAR; | 1252 wm_dead_char_ = WM_DEADCHAR; |
1171 wm_sys_key_down_ = WM_SYSKEYDOWN; | 1253 wm_sys_key_down_ = WM_SYSKEYDOWN; |
1172 wm_sys_key_up_ = WM_SYSKEYUP; | 1254 wm_sys_key_up_ = WM_SYSKEYUP; |
1173 wm_sys_char_ = WM_SYSCHAR; | 1255 wm_sys_char_ = WM_SYSCHAR; |
1174 wm_sys_dead_char_ = WM_SYSDEADCHAR; | 1256 wm_sys_dead_char_ = WM_SYSDEADCHAR; |
1175 #endif | 1257 #endif |
1176 | 1258 |
1177 last_mouse_pos_ = WebPoint(0, 0); | |
1178 last_click_time_sec_ = 0; | 1259 last_click_time_sec_ = 0; |
1179 last_click_pos_ = WebPoint(0, 0); | 1260 last_click_pos_ = WebPoint(0, 0); |
1180 last_button_type_ = WebMouseEvent::ButtonNone; | 1261 last_button_type_ = WebMouseEvent::ButtonNone; |
1181 touch_points_.clear(); | 1262 touch_points_.clear(); |
1182 last_context_menu_data_.reset(); | 1263 last_context_menu_data_.reset(); |
1183 weak_factory_.InvalidateWeakPtrs(); | 1264 weak_factory_.InvalidateWeakPtrs(); |
1184 current_gesture_location_ = WebPoint(0, 0); | 1265 current_gesture_location_ = WebPoint(0, 0); |
1185 mouse_event_queue_.clear(); | 1266 mouse_event_queue_.clear(); |
1186 | 1267 |
1187 time_offset_ms_ = 0; | 1268 time_offset_ms_ = 0; |
(...skipping 17 matching lines...) Expand all Loading... |
1205 } | 1286 } |
1206 | 1287 |
1207 void EventSender::SetContextMenuData(const WebContextMenuData& data) { | 1288 void EventSender::SetContextMenuData(const WebContextMenuData& data) { |
1208 last_context_menu_data_.reset(new WebContextMenuData(data)); | 1289 last_context_menu_data_.reset(new WebContextMenuData(data)); |
1209 } | 1290 } |
1210 | 1291 |
1211 void EventSender::DoDragDrop(const WebDragData& drag_data, | 1292 void EventSender::DoDragDrop(const WebDragData& drag_data, |
1212 WebDragOperationsMask mask) { | 1293 WebDragOperationsMask mask) { |
1213 WebMouseEvent event; | 1294 WebMouseEvent event; |
1214 InitMouseEvent(WebInputEvent::MouseDown, | 1295 InitMouseEvent(WebInputEvent::MouseDown, |
1215 pressed_button_, | 1296 current_pointer_state_[kMousePointerId].pressed_button_, |
1216 current_buttons_, | 1297 current_pointer_state_[kMousePointerId].current_buttons_, |
1217 last_mouse_pos_, | 1298 current_pointer_state_[kMousePointerId].last_pos_, |
1218 GetCurrentEventTimeSec(), | 1299 GetCurrentEventTimeSec(), |
1219 click_count_, | 1300 click_count_, |
1220 modifiers_, | 1301 current_pointer_state_[kMousePointerId].modifiers_, |
| 1302 blink::WebPointerProperties::PointerType::Mouse, |
| 1303 0, |
1221 &event); | 1304 &event); |
1222 WebPoint client_point(event.x, event.y); | 1305 WebPoint client_point(event.x, event.y); |
1223 WebPoint screen_point(event.globalX, event.globalY); | 1306 WebPoint screen_point(event.globalX, event.globalY); |
1224 current_drag_data_ = drag_data; | 1307 current_drag_data_ = drag_data; |
1225 current_drag_effects_allowed_ = mask; | 1308 current_drag_effects_allowed_ = mask; |
1226 current_drag_effect_ = view_->dragTargetDragEnter( | 1309 current_drag_effect_ = view_->dragTargetDragEnter( |
1227 drag_data, | 1310 drag_data, |
1228 client_point, | 1311 client_point, |
1229 screen_point, | 1312 screen_point, |
1230 current_drag_effects_allowed_, | 1313 current_drag_effects_allowed_, |
1231 modifiersWithButtons(modifiers_, current_buttons_)); | 1314 modifiersWithButtons( |
| 1315 current_pointer_state_[kMousePointerId].modifiers_, |
| 1316 current_pointer_state_[kMousePointerId].current_buttons_)); |
1232 | 1317 |
1233 // Finish processing events. | 1318 // Finish processing events. |
1234 ReplaySavedEvents(); | 1319 ReplaySavedEvents(); |
1235 } | 1320 } |
1236 | 1321 |
1237 void EventSender::MouseDown(int button_number, int modifiers) { | 1322 void EventSender::MouseDown(int button_number, int modifiers) { |
| 1323 PointerDown(button_number, modifiers, |
| 1324 blink::WebPointerProperties::PointerType::Mouse, kMousePointerId); |
| 1325 } |
| 1326 |
| 1327 void EventSender::MouseUp(int button_number, int modifiers) { |
| 1328 PointerUp(button_number, modifiers, |
| 1329 blink::WebPointerProperties::PointerType::Mouse, kMousePointerId); |
| 1330 } |
| 1331 |
| 1332 void EventSender::PointerDown( |
| 1333 int button_number, |
| 1334 int modifiers, |
| 1335 blink::WebPointerProperties::PointerType pointerType, |
| 1336 int pointerId) { |
1238 if (force_layout_on_events_) | 1337 if (force_layout_on_events_) |
1239 view_->updateAllLifecyclePhases(); | 1338 view_->updateAllLifecyclePhases(); |
1240 | 1339 |
1241 DCHECK_NE(-1, button_number); | 1340 DCHECK_NE(-1, button_number); |
1242 | 1341 |
1243 WebMouseEvent::Button button_type = | 1342 WebMouseEvent::Button button_type = |
1244 GetButtonTypeFromButtonNumber(button_number); | 1343 GetButtonTypeFromButtonNumber(button_number); |
1245 | 1344 |
1246 UpdateClickCountForButton(button_type); | 1345 WebMouseEvent event; |
| 1346 int click_count = 0; |
| 1347 current_pointer_state_[pointerId].pressed_button_ = button_type; |
| 1348 current_pointer_state_[pointerId].current_buttons_ |= |
| 1349 GetWebMouseEventModifierForButton(button_type); |
| 1350 current_pointer_state_[pointerId].modifiers_ = modifiers; |
1247 | 1351 |
1248 pressed_button_ = button_type; | 1352 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) { |
1249 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 1353 UpdateClickCountForButton(button_type); |
1250 modifiers_ = modifiers; | 1354 click_count = click_count_; |
| 1355 } |
| 1356 InitMouseEvent(WebInputEvent::MouseDown, |
| 1357 current_pointer_state_[pointerId].pressed_button_, |
| 1358 current_pointer_state_[pointerId].current_buttons_, |
| 1359 current_pointer_state_[pointerId].last_pos_, |
| 1360 GetCurrentEventTimeSec(), |
| 1361 click_count, |
| 1362 current_pointer_state_[pointerId].modifiers_, |
| 1363 pointerType, |
| 1364 pointerId, |
| 1365 &event); |
1251 | 1366 |
1252 WebMouseEvent event; | |
1253 InitMouseEvent(WebInputEvent::MouseDown, | |
1254 pressed_button_, | |
1255 current_buttons_, | |
1256 last_mouse_pos_, | |
1257 GetCurrentEventTimeSec(), | |
1258 click_count_, | |
1259 modifiers_, | |
1260 &event); | |
1261 HandleInputEventOnViewOrPopup(event); | 1367 HandleInputEventOnViewOrPopup(event); |
1262 } | 1368 } |
1263 | 1369 |
1264 void EventSender::MouseUp(int button_number, int modifiers) { | 1370 void EventSender::PointerUp( |
| 1371 int button_number, |
| 1372 int modifiers, |
| 1373 blink::WebPointerProperties::PointerType pointerType, |
| 1374 int pointerId) { |
1265 if (force_layout_on_events_) | 1375 if (force_layout_on_events_) |
1266 view_->updateAllLifecyclePhases(); | 1376 view_->updateAllLifecyclePhases(); |
1267 | 1377 |
1268 DCHECK_NE(-1, button_number); | 1378 DCHECK_NE(-1, button_number); |
1269 | 1379 |
1270 WebMouseEvent::Button button_type = | 1380 WebMouseEvent::Button button_type = |
1271 GetButtonTypeFromButtonNumber(button_number); | 1381 GetButtonTypeFromButtonNumber(button_number); |
1272 | 1382 |
1273 if (is_drag_mode_ && !replaying_saved_events_) { | 1383 if (pointerType == blink::WebPointerProperties::PointerType::Mouse && |
| 1384 is_drag_mode_ && !replaying_saved_events_) { |
1274 SavedEvent saved_event; | 1385 SavedEvent saved_event; |
1275 saved_event.type = SavedEvent::TYPE_MOUSE_UP; | 1386 saved_event.type = SavedEvent::TYPE_MOUSE_UP; |
1276 saved_event.button_type = button_type; | 1387 saved_event.button_type = button_type; |
1277 saved_event.modifiers = modifiers; | 1388 saved_event.modifiers = modifiers; |
1278 mouse_event_queue_.push_back(saved_event); | 1389 mouse_event_queue_.push_back(saved_event); |
1279 ReplaySavedEvents(); | 1390 ReplaySavedEvents(); |
1280 } else { | 1391 } else { |
1281 current_buttons_ &= ~GetWebMouseEventModifierForButton(button_type); | 1392 current_pointer_state_[pointerId].current_buttons_ &= |
1282 pressed_button_ = WebMouseEvent::ButtonNone; | 1393 ~GetWebMouseEventModifierForButton(button_type); |
| 1394 current_pointer_state_[pointerId].pressed_button_ = |
| 1395 WebMouseEvent::ButtonNone; |
1283 | 1396 |
1284 WebMouseEvent event; | 1397 WebMouseEvent event; |
1285 InitMouseEvent(WebInputEvent::MouseUp, | 1398 InitMouseEvent( |
1286 button_type, | 1399 WebInputEvent::MouseUp, button_type, |
1287 current_buttons_, | 1400 current_pointer_state_[pointerId].current_buttons_, |
1288 last_mouse_pos_, | 1401 current_pointer_state_[pointerId].last_pos_, GetCurrentEventTimeSec(), |
1289 GetCurrentEventTimeSec(), | 1402 pointerType == blink::WebPointerProperties::PointerType::Mouse |
1290 click_count_, | 1403 ? click_count_ |
1291 modifiers, | 1404 : 0, |
1292 &event); | 1405 modifiers, pointerType, pointerId, &event); |
1293 DoMouseUp(event); | 1406 HandleInputEventOnViewOrPopup(event); |
| 1407 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) |
| 1408 DoDragAfterMouseUp(event); |
1294 } | 1409 } |
1295 } | 1410 } |
1296 | 1411 |
1297 void EventSender::SetMouseButtonState(int button_number, int modifiers) { | 1412 void EventSender::SetMouseButtonState(int button_number, int modifiers) { |
1298 pressed_button_ = GetButtonTypeFromButtonNumber(button_number); | 1413 current_pointer_state_[kMousePointerId].pressed_button_ = |
1299 current_buttons_ = (modifiers == -1) ? | 1414 GetButtonTypeFromButtonNumber(button_number); |
1300 GetWebMouseEventModifierForButton(pressed_button_) : | 1415 current_pointer_state_[kMousePointerId].current_buttons_ = |
1301 modifiers & kButtonsInModifiers; | 1416 (modifiers == -1) |
| 1417 ? GetWebMouseEventModifierForButton( |
| 1418 current_pointer_state_[kMousePointerId].pressed_button_) |
| 1419 : modifiers & kButtonsInModifiers; |
1302 } | 1420 } |
1303 | 1421 |
1304 void EventSender::KeyDown(const std::string& code_str, | 1422 void EventSender::KeyDown(const std::string& code_str, |
1305 int modifiers, | 1423 int modifiers, |
1306 KeyLocationCode location) { | 1424 KeyLocationCode location) { |
1307 // FIXME: I'm not exactly sure how we should convert the string to a key | 1425 // FIXME: I'm not exactly sure how we should convert the string to a key |
1308 // event. This seems to work in the cases I tested. | 1426 // event. This seems to work in the cases I tested. |
1309 // FIXME: Should we also generate a KEY_UP? | 1427 // FIXME: Should we also generate a KEY_UP? |
1310 | 1428 |
1311 bool generate_char = false; | 1429 bool generate_char = false; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 // We just simulate the same behavior here. | 1609 // We just simulate the same behavior here. |
1492 std::string edit_command; | 1610 std::string edit_command; |
1493 if (GetEditCommand(event_down, &edit_command)) | 1611 if (GetEditCommand(event_down, &edit_command)) |
1494 delegate_->SetEditCommand(edit_command, ""); | 1612 delegate_->SetEditCommand(edit_command, ""); |
1495 | 1613 |
1496 HandleInputEventOnViewOrPopup(event_down); | 1614 HandleInputEventOnViewOrPopup(event_down); |
1497 | 1615 |
1498 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { | 1616 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { |
1499 WebMouseEvent event; | 1617 WebMouseEvent event; |
1500 InitMouseEvent(WebInputEvent::MouseDown, | 1618 InitMouseEvent(WebInputEvent::MouseDown, |
1501 pressed_button_, | 1619 current_pointer_state_[kMousePointerId].pressed_button_, |
1502 current_buttons_, | 1620 current_pointer_state_[kMousePointerId].current_buttons_, |
1503 last_mouse_pos_, | 1621 current_pointer_state_[kMousePointerId].last_pos_, |
1504 GetCurrentEventTimeSec(), | 1622 GetCurrentEventTimeSec(), |
1505 click_count_, | 1623 click_count_, |
1506 0, | 1624 0, |
| 1625 blink::WebPointerProperties::PointerType::Mouse, |
| 1626 0, |
1507 &event); | 1627 &event); |
1508 FinishDragAndDrop(event, blink::WebDragOperationNone); | 1628 FinishDragAndDrop(event, blink::WebDragOperationNone); |
1509 } | 1629 } |
1510 | 1630 |
1511 delegate_->ClearEditCommand(); | 1631 delegate_->ClearEditCommand(); |
1512 | 1632 |
1513 if (generate_char) { | 1633 if (generate_char) { |
1514 WebKeyboardEvent event_char = event_up; | 1634 WebKeyboardEvent event_char = event_up; |
1515 event_char.type = WebInputEvent::Char; | 1635 event_char.type = WebInputEvent::Char; |
1516 // keyIdentifier is an empty string, unless the Enter key was pressed. | 1636 // keyIdentifier is an empty string, unless the Enter key was pressed. |
(...skipping 24 matching lines...) Expand all Loading... |
1541 // be requested after following mouse events. | 1661 // be requested after following mouse events. |
1542 last_context_menu_data_.reset(); | 1662 last_context_menu_data_.reset(); |
1543 | 1663 |
1544 // Generate right mouse down and up. | 1664 // Generate right mouse down and up. |
1545 WebMouseEvent event; | 1665 WebMouseEvent event; |
1546 // This is a hack to work around only allowing a single pressed button since | 1666 // This is a hack to work around only allowing a single pressed button since |
1547 // we want to test the case where both the left and right mouse buttons are | 1667 // we want to test the case where both the left and right mouse buttons are |
1548 // pressed. | 1668 // pressed. |
1549 // TODO(mustaq): This hack seems unused here! But do we need this hack at all | 1669 // TODO(mustaq): This hack seems unused here! But do we need this hack at all |
1550 // after adding current_buttons_. | 1670 // after adding current_buttons_. |
1551 if (pressed_button_ == WebMouseEvent::ButtonNone) { | 1671 if (current_pointer_state_[kMousePointerId].pressed_button_ == |
1552 pressed_button_ = WebMouseEvent::ButtonRight; | 1672 WebMouseEvent::ButtonNone) { |
1553 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 1673 current_pointer_state_[kMousePointerId].pressed_button_ = |
| 1674 WebMouseEvent::ButtonRight; |
| 1675 current_pointer_state_[kMousePointerId].current_buttons_ |= |
| 1676 GetWebMouseEventModifierForButton( |
| 1677 current_pointer_state_[kMousePointerId].pressed_button_); |
1554 } | 1678 } |
1555 InitMouseEvent(WebInputEvent::MouseDown, | 1679 InitMouseEvent(WebInputEvent::MouseDown, |
1556 WebMouseEvent::ButtonRight, | 1680 WebMouseEvent::ButtonRight, |
1557 current_buttons_, | 1681 current_pointer_state_[kMousePointerId].current_buttons_, |
1558 last_mouse_pos_, | 1682 current_pointer_state_[kMousePointerId].last_pos_, |
1559 GetCurrentEventTimeSec(), | 1683 GetCurrentEventTimeSec(), |
1560 click_count_, | 1684 click_count_, |
1561 0, | 1685 0, |
| 1686 blink::WebPointerProperties::PointerType::Mouse, |
| 1687 0, |
1562 &event); | 1688 &event); |
1563 HandleInputEventOnViewOrPopup(event); | 1689 HandleInputEventOnViewOrPopup(event); |
1564 | 1690 |
1565 #if defined(OS_WIN) | 1691 #if defined(OS_WIN) |
1566 current_buttons_ &= | 1692 current_pointer_state_[kMousePointerId].current_buttons_ &= |
1567 ~GetWebMouseEventModifierForButton(WebMouseEvent::ButtonRight); | 1693 ~GetWebMouseEventModifierForButton(WebMouseEvent::ButtonRight); |
1568 pressed_button_ = WebMouseEvent::ButtonNone; | 1694 current_pointer_state_[kMousePointerId].pressed_button_ = |
| 1695 WebMouseEvent::ButtonNone; |
1569 | 1696 |
1570 InitMouseEvent(WebInputEvent::MouseUp, | 1697 InitMouseEvent(WebInputEvent::MouseUp, |
1571 WebMouseEvent::ButtonRight, | 1698 WebMouseEvent::ButtonRight, |
1572 current_buttons_, | 1699 current_pointer_state_[kMousePointerId].current_buttons_, |
1573 last_mouse_pos_, | 1700 current_pointer_state_[kMousePointerId].last_pos_, |
1574 GetCurrentEventTimeSec(), | 1701 GetCurrentEventTimeSec(), |
1575 click_count_, | 1702 click_count_, |
1576 0, | 1703 0, |
| 1704 blink::WebPointerProperties::PointerType::Mouse, |
| 1705 0, |
1577 &event); | 1706 &event); |
1578 HandleInputEventOnViewOrPopup(event); | 1707 HandleInputEventOnViewOrPopup(event); |
1579 #endif | 1708 #endif |
1580 | 1709 |
1581 std::vector<std::string> menu_items = | 1710 std::vector<std::string> menu_items = |
1582 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate_); | 1711 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate_); |
1583 last_context_menu_data_.reset(); | 1712 last_context_menu_data_.reset(); |
1584 return menu_items; | 1713 return menu_items; |
1585 } | 1714 } |
1586 | 1715 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 | 1902 |
1774 void EventSender::TouchCancel() { | 1903 void EventSender::TouchCancel() { |
1775 SendCurrentTouchEvent(WebInputEvent::TouchCancel, false); | 1904 SendCurrentTouchEvent(WebInputEvent::TouchCancel, false); |
1776 } | 1905 } |
1777 | 1906 |
1778 void EventSender::TouchEnd() { | 1907 void EventSender::TouchEnd() { |
1779 SendCurrentTouchEvent(WebInputEvent::TouchEnd, false); | 1908 SendCurrentTouchEvent(WebInputEvent::TouchEnd, false); |
1780 } | 1909 } |
1781 | 1910 |
1782 void EventSender::LeapForward(int milliseconds) { | 1911 void EventSender::LeapForward(int milliseconds) { |
1783 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && | 1912 if (is_drag_mode_ && |
| 1913 current_pointer_state_[kMousePointerId].pressed_button_ == |
| 1914 WebMouseEvent::ButtonLeft && |
1784 !replaying_saved_events_) { | 1915 !replaying_saved_events_) { |
1785 SavedEvent saved_event; | 1916 SavedEvent saved_event; |
1786 saved_event.type = SavedEvent::TYPE_LEAP_FORWARD; | 1917 saved_event.type = SavedEvent::TYPE_LEAP_FORWARD; |
1787 saved_event.milliseconds = milliseconds; | 1918 saved_event.milliseconds = milliseconds; |
1788 mouse_event_queue_.push_back(saved_event); | 1919 mouse_event_queue_.push_back(saved_event); |
1789 } else { | 1920 } else { |
1790 DoLeapForward(milliseconds); | 1921 DoLeapForward(milliseconds); |
1791 } | 1922 } |
1792 } | 1923 } |
1793 | 1924 |
(...skipping 16 matching lines...) Expand all Loading... |
1810 item.filenameData = delegate_->GetAbsoluteWebStringFromUTF8Path(files[i]); | 1941 item.filenameData = delegate_->GetAbsoluteWebStringFromUTF8Path(files[i]); |
1811 current_drag_data_.addItem(item); | 1942 current_drag_data_.addItem(item); |
1812 absolute_filenames[i] = item.filenameData; | 1943 absolute_filenames[i] = item.filenameData; |
1813 } | 1944 } |
1814 current_drag_data_.setFilesystemId( | 1945 current_drag_data_.setFilesystemId( |
1815 delegate_->RegisterIsolatedFileSystem(absolute_filenames)); | 1946 delegate_->RegisterIsolatedFileSystem(absolute_filenames)); |
1816 current_drag_effects_allowed_ = blink::WebDragOperationCopy; | 1947 current_drag_effects_allowed_ = blink::WebDragOperationCopy; |
1817 | 1948 |
1818 // Provide a drag source. | 1949 // Provide a drag source. |
1819 view_->dragTargetDragEnter(current_drag_data_, | 1950 view_->dragTargetDragEnter(current_drag_data_, |
1820 last_mouse_pos_, | 1951 current_pointer_state_[kMousePointerId].last_pos_, |
1821 last_mouse_pos_, | 1952 current_pointer_state_[kMousePointerId].last_pos_, |
1822 current_drag_effects_allowed_, | 1953 current_drag_effects_allowed_, |
1823 0); | 1954 0); |
1824 // |is_drag_mode_| saves events and then replays them later. We don't | 1955 // |is_drag_mode_| saves events and then replays them later. We don't |
1825 // need/want that. | 1956 // need/want that. |
1826 is_drag_mode_ = false; | 1957 is_drag_mode_ = false; |
1827 | 1958 |
1828 // Make the rest of eventSender think a drag is in progress. | 1959 // Make the rest of eventSender think a drag is in progress. |
1829 pressed_button_ = WebMouseEvent::ButtonLeft; | 1960 current_pointer_state_[kMousePointerId].pressed_button_ = |
1830 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 1961 WebMouseEvent::ButtonLeft; |
| 1962 current_pointer_state_[kMousePointerId].current_buttons_ |= |
| 1963 GetWebMouseEventModifierForButton( |
| 1964 current_pointer_state_[kMousePointerId].pressed_button_); |
1831 } | 1965 } |
1832 | 1966 |
1833 void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) { | 1967 void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) { |
1834 WebTouchPoint touch_point; | 1968 WebTouchPoint touch_point; |
1835 touch_point.pointerType = WebPointerProperties::PointerType::Touch; | 1969 touch_point.pointerType = WebPointerProperties::PointerType::Touch; |
1836 touch_point.state = WebTouchPoint::StatePressed; | 1970 touch_point.state = WebTouchPoint::StatePressed; |
1837 touch_point.position = WebFloatPoint(x, y); | 1971 touch_point.position = WebFloatPoint(x, y); |
1838 touch_point.screenPosition = touch_point.position; | 1972 touch_point.screenPosition = touch_point.position; |
1839 | 1973 |
1840 int highest_id = -1; | 1974 int highest_id = -1; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1920 SendGesturesForMouseWheelEvent(wheel_event); | 2054 SendGesturesForMouseWheelEvent(wheel_event); |
1921 } | 2055 } |
1922 } | 2056 } |
1923 | 2057 |
1924 void EventSender::MouseMoveTo(gin::Arguments* args) { | 2058 void EventSender::MouseMoveTo(gin::Arguments* args) { |
1925 if (force_layout_on_events_) | 2059 if (force_layout_on_events_) |
1926 view_->updateAllLifecyclePhases(); | 2060 view_->updateAllLifecyclePhases(); |
1927 | 2061 |
1928 double x; | 2062 double x; |
1929 double y; | 2063 double y; |
| 2064 blink::WebPointerProperties::PointerType pointerType = |
| 2065 blink::WebPointerProperties::PointerType::Mouse; |
| 2066 int pointerId = 0; |
1930 if (!args->GetNext(&x) || !args->GetNext(&y)) { | 2067 if (!args->GetNext(&x) || !args->GetNext(&y)) { |
1931 args->ThrowError(); | 2068 args->ThrowError(); |
1932 return; | 2069 return; |
1933 } | 2070 } |
1934 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); | 2071 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); |
1935 | 2072 |
1936 int modifiers = 0; | 2073 int modifiers = 0; |
1937 if (!args->PeekNext().IsEmpty()) | 2074 if (!args->PeekNext().IsEmpty()) { |
1938 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); | 2075 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
| 2076 args->Skip(); |
| 2077 } |
1939 | 2078 |
1940 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && | 2079 if (!getMousePenPointerTypeAndId(args, pointerType, pointerId)) |
1941 !replaying_saved_events_) { | 2080 return; |
| 2081 |
| 2082 if (pointerType == blink::WebPointerProperties::PointerType::Mouse && |
| 2083 is_drag_mode_ && !replaying_saved_events_ && |
| 2084 current_pointer_state_[kMousePointerId].pressed_button_ == |
| 2085 WebMouseEvent::ButtonLeft) { |
1942 SavedEvent saved_event; | 2086 SavedEvent saved_event; |
1943 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; | 2087 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; |
1944 saved_event.pos = mouse_pos; | 2088 saved_event.pos = mouse_pos; |
1945 saved_event.modifiers = modifiers; | 2089 saved_event.modifiers = modifiers; |
1946 mouse_event_queue_.push_back(saved_event); | 2090 mouse_event_queue_.push_back(saved_event); |
1947 } else { | 2091 } else { |
| 2092 current_pointer_state_[pointerId].last_pos_ = mouse_pos; |
1948 WebMouseEvent event; | 2093 WebMouseEvent event; |
1949 InitMouseEvent(WebInputEvent::MouseMove, | 2094 InitMouseEvent( |
1950 pressed_button_, | 2095 WebInputEvent::MouseMove, |
1951 current_buttons_, | 2096 current_pointer_state_[kMousePointerId].pressed_button_, |
1952 mouse_pos, | 2097 current_pointer_state_[kMousePointerId].current_buttons_, |
1953 GetCurrentEventTimeSec(), | 2098 mouse_pos, |
1954 click_count_, | 2099 GetCurrentEventTimeSec(), |
1955 modifiers, | 2100 pointerType == blink::WebPointerProperties::PointerType::Mouse |
1956 &event); | 2101 ? click_count_ |
1957 DoMouseMove(event); | 2102 : 0, |
| 2103 modifiers, |
| 2104 pointerType, |
| 2105 pointerId, |
| 2106 &event); |
| 2107 HandleInputEventOnViewOrPopup(event); |
| 2108 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) |
| 2109 DoDragAfterMouseMove(event); |
1958 } | 2110 } |
1959 } | 2111 } |
1960 | 2112 |
1961 void EventSender::MouseLeave() { | 2113 void EventSender::MouseLeave() { |
1962 if (force_layout_on_events_) | 2114 if (force_layout_on_events_) |
1963 view_->updateAllLifecyclePhases(); | 2115 view_->updateAllLifecyclePhases(); |
1964 | 2116 |
1965 WebMouseEvent event; | 2117 WebMouseEvent event; |
1966 InitMouseEvent(WebInputEvent::MouseLeave, | 2118 InitMouseEvent(WebInputEvent::MouseLeave, |
1967 WebMouseEvent::ButtonNone, | 2119 WebMouseEvent::ButtonNone, |
1968 0, | 2120 0, |
1969 last_mouse_pos_, | 2121 current_pointer_state_[kMousePointerId].last_pos_, |
1970 GetCurrentEventTimeSec(), | 2122 GetCurrentEventTimeSec(), |
1971 click_count_, | 2123 click_count_, |
1972 0, | 2124 0, |
| 2125 blink::WebPointerProperties::PointerType::Mouse, |
| 2126 0, |
1973 &event); | 2127 &event); |
1974 HandleInputEventOnViewOrPopup(event); | 2128 HandleInputEventOnViewOrPopup(event); |
1975 } | 2129 } |
1976 | 2130 |
1977 | 2131 |
1978 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { | 2132 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { |
1979 delegate_->PostTask(new WebCallbackTask( | 2133 delegate_->PostTask(new WebCallbackTask( |
1980 base::Bind(&EventSender::MouseDown, weak_factory_.GetWeakPtr(), | 2134 base::Bind(&EventSender::MouseDown, weak_factory_.GetWeakPtr(), |
1981 button_number, modifiers))); | 2135 button_number, modifiers))); |
1982 delegate_->PostTask(new WebCallbackTask( | 2136 delegate_->PostTask(new WebCallbackTask( |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2280 | 2434 |
2281 if (force_layout_on_events_) | 2435 if (force_layout_on_events_) |
2282 view_->updateAllLifecyclePhases(); | 2436 view_->updateAllLifecyclePhases(); |
2283 | 2437 |
2284 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); | 2438 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); |
2285 | 2439 |
2286 // Long press might start a drag drop session. Complete it if so. | 2440 // Long press might start a drag drop session. Complete it if so. |
2287 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { | 2441 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { |
2288 WebMouseEvent mouse_event; | 2442 WebMouseEvent mouse_event; |
2289 InitMouseEvent(WebInputEvent::MouseDown, | 2443 InitMouseEvent(WebInputEvent::MouseDown, |
2290 pressed_button_, | 2444 current_pointer_state_[kMousePointerId].pressed_button_, |
2291 current_buttons_, | 2445 current_pointer_state_[kMousePointerId].current_buttons_, |
2292 WebPoint(x, y), | 2446 WebPoint(x, y), GetCurrentEventTimeSec(), |
2293 GetCurrentEventTimeSec(), | |
2294 click_count_, | 2447 click_count_, |
2295 modifiers_, | 2448 current_pointer_state_[kMousePointerId].modifiers_, |
| 2449 blink::WebPointerProperties::PointerType::Mouse, |
| 2450 0, |
2296 &mouse_event); | 2451 &mouse_event); |
2297 | 2452 |
2298 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); | 2453 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); |
2299 } | 2454 } |
2300 args->Return(result != WebInputEventResult::NotHandled); | 2455 args->Return(result != WebInputEventResult::NotHandled); |
2301 } | 2456 } |
2302 | 2457 |
2303 void EventSender::UpdateClickCountForButton( | 2458 void EventSender::UpdateClickCountForButton( |
2304 WebMouseEvent::Button button_type) { | 2459 WebMouseEvent::Button button_type) { |
2305 if ((GetCurrentEventTimeSec() - last_click_time_sec_ < | 2460 if ((GetCurrentEventTimeSec() - last_click_time_sec_ < |
2306 kMultipleClickTimeSec) && | 2461 kMultipleClickTimeSec) && |
2307 (!OutsideMultiClickRadius(last_mouse_pos_, last_click_pos_)) && | 2462 (!OutsideMultiClickRadius( |
| 2463 current_pointer_state_[kMousePointerId].last_pos_, |
| 2464 last_click_pos_)) && |
2308 (button_type == last_button_type_)) { | 2465 (button_type == last_button_type_)) { |
2309 ++click_count_; | 2466 ++click_count_; |
2310 } else { | 2467 } else { |
2311 click_count_ = 1; | 2468 click_count_ = 1; |
2312 last_button_type_ = button_type; | 2469 last_button_type_ = button_type; |
2313 } | 2470 } |
2314 } | 2471 } |
2315 | 2472 |
2316 void EventSender::InitMouseWheelEvent(gin::Arguments* args, | 2473 void EventSender::InitMouseWheelEvent(gin::Arguments* args, |
2317 MouseScrollType scroll_type, | 2474 MouseScrollType scroll_type, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 } | 2508 } |
2352 } | 2509 } |
2353 } | 2510 } |
2354 } | 2511 } |
2355 if (can_scroll && send_wheel_gestures_) { | 2512 if (can_scroll && send_wheel_gestures_) { |
2356 can_scroll = false; | 2513 can_scroll = false; |
2357 *send_gestures = true; | 2514 *send_gestures = true; |
2358 } | 2515 } |
2359 | 2516 |
2360 InitMouseEvent(WebInputEvent::MouseWheel, | 2517 InitMouseEvent(WebInputEvent::MouseWheel, |
2361 pressed_button_, | 2518 current_pointer_state_[kMousePointerId].pressed_button_, |
2362 current_buttons_, | 2519 current_pointer_state_[kMousePointerId].current_buttons_, |
2363 last_mouse_pos_, | 2520 current_pointer_state_[kMousePointerId].last_pos_, |
2364 GetCurrentEventTimeSec(), | 2521 GetCurrentEventTimeSec(), |
2365 click_count_, | 2522 click_count_, |
2366 modifiers, | 2523 modifiers, |
| 2524 blink::WebPointerProperties::PointerType::Mouse, |
| 2525 0, |
2367 event); | 2526 event); |
2368 event->wheelTicksX = static_cast<float>(horizontal); | 2527 event->wheelTicksX = static_cast<float>(horizontal); |
2369 event->wheelTicksY = static_cast<float>(vertical); | 2528 event->wheelTicksY = static_cast<float>(vertical); |
2370 event->deltaX = event->wheelTicksX; | 2529 event->deltaX = event->wheelTicksX; |
2371 event->deltaY = event->wheelTicksY; | 2530 event->deltaY = event->wheelTicksY; |
2372 event->scrollByPage = paged; | 2531 event->scrollByPage = paged; |
2373 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; | 2532 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; |
2374 event->canScroll = can_scroll; | 2533 event->canScroll = can_scroll; |
2375 if (scroll_type == MouseScrollType::PIXEL) { | 2534 if (scroll_type == MouseScrollType::PIXEL) { |
2376 event->wheelTicksX /= kScrollbarPixelsPerTick; | 2535 event->wheelTicksX /= kScrollbarPixelsPerTick; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 if (!args->PeekNext().IsEmpty()) { | 2578 if (!args->PeekNext().IsEmpty()) { |
2420 int tiltX, tiltY; | 2579 int tiltX, tiltY; |
2421 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) { | 2580 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) { |
2422 args->ThrowError(); | 2581 args->ThrowError(); |
2423 return; | 2582 return; |
2424 } | 2583 } |
2425 e->tiltX = tiltX; | 2584 e->tiltX = tiltX; |
2426 e->tiltY = tiltY; | 2585 e->tiltY = tiltY; |
2427 } | 2586 } |
2428 | 2587 |
2429 if (!args->PeekNext().IsEmpty()) { | 2588 if (!getPointerType(args, false, e->pointerType)) |
2430 std::string pointer_type_string; | 2589 return; |
2431 if (!args->GetNext(&pointer_type_string)) { | |
2432 args->ThrowError(); | |
2433 return; | |
2434 } | |
2435 if (pointer_type_string == kPointerTypeStringUnknown) { | |
2436 e->pointerType = WebMouseEvent::PointerType::Unknown; | |
2437 } else if (pointer_type_string == kPointerTypeStringMouse) { | |
2438 e->pointerType = WebMouseEvent::PointerType::Mouse; | |
2439 } else if (pointer_type_string == kPointerTypeStringPen) { | |
2440 e->pointerType = WebMouseEvent::PointerType::Pen; | |
2441 } else if (pointer_type_string == kPointerTypeStringTouch) { | |
2442 e->pointerType = WebMouseEvent::PointerType::Touch; | |
2443 } else { | |
2444 args->ThrowError(); | |
2445 return; | |
2446 } | |
2447 } | |
2448 } | 2590 } |
2449 | 2591 |
2450 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, | 2592 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, |
2451 blink::WebDragOperation drag_effect) { | 2593 blink::WebDragOperation drag_effect) { |
2452 WebPoint client_point(e.x, e.y); | 2594 WebPoint client_point(e.x, e.y); |
2453 WebPoint screen_point(e.globalX, e.globalY); | 2595 WebPoint screen_point(e.globalX, e.globalY); |
2454 current_drag_effect_ = drag_effect; | 2596 current_drag_effect_ = drag_effect; |
2455 if (current_drag_effect_) { | 2597 if (current_drag_effect_) { |
2456 // Specifically pass any keyboard modifiers to the drop method. This allows | 2598 // Specifically pass any keyboard modifiers to the drop method. This allows |
2457 // tests to control the drop type (i.e. copy or move). | 2599 // tests to control the drop type (i.e. copy or move). |
2458 view_->dragTargetDrop(client_point, screen_point, e.modifiers); | 2600 view_->dragTargetDrop(client_point, screen_point, e.modifiers); |
2459 } else { | 2601 } else { |
2460 view_->dragTargetDragLeave(); | 2602 view_->dragTargetDragLeave(); |
2461 } | 2603 } |
2462 view_->dragSourceEndedAt(client_point, screen_point, current_drag_effect_); | 2604 view_->dragSourceEndedAt(client_point, screen_point, current_drag_effect_); |
2463 view_->dragSourceSystemDragEnded(); | 2605 view_->dragSourceSystemDragEnded(); |
2464 | 2606 |
2465 current_drag_data_.reset(); | 2607 current_drag_data_.reset(); |
2466 } | 2608 } |
2467 | 2609 |
2468 void EventSender::DoMouseUp(const WebMouseEvent& e) { | 2610 void EventSender::DoDragAfterMouseUp(const WebMouseEvent& e) { |
2469 HandleInputEventOnViewOrPopup(e); | |
2470 | |
2471 last_click_time_sec_ = e.timeStampSeconds; | 2611 last_click_time_sec_ = e.timeStampSeconds; |
2472 last_click_pos_ = last_mouse_pos_; | 2612 last_click_pos_ = current_pointer_state_[kMousePointerId].last_pos_; |
2473 | 2613 |
2474 // If we're in a drag operation, complete it. | 2614 // If we're in a drag operation, complete it. |
2475 if (current_drag_data_.isNull()) | 2615 if (current_drag_data_.isNull()) |
2476 return; | 2616 return; |
2477 | 2617 |
2478 WebPoint client_point(e.x, e.y); | 2618 WebPoint client_point(e.x, e.y); |
2479 WebPoint screen_point(e.globalX, e.globalY); | 2619 WebPoint screen_point(e.globalX, e.globalY); |
2480 blink::WebDragOperation drag_effect = view_->dragTargetDragOver( | 2620 blink::WebDragOperation drag_effect = view_->dragTargetDragOver( |
2481 client_point, | 2621 client_point, |
2482 screen_point, | 2622 screen_point, |
2483 current_drag_effects_allowed_, | 2623 current_drag_effects_allowed_, |
2484 e.modifiers); | 2624 e.modifiers); |
2485 | 2625 |
2486 // Bail if dragover caused cancellation. | 2626 // Bail if dragover caused cancellation. |
2487 if (current_drag_data_.isNull()) | 2627 if (current_drag_data_.isNull()) |
2488 return; | 2628 return; |
2489 | 2629 |
2490 FinishDragAndDrop(e, drag_effect); | 2630 FinishDragAndDrop(e, drag_effect); |
2491 } | 2631 } |
2492 | 2632 |
2493 void EventSender::DoMouseMove(const WebMouseEvent& e) { | 2633 void EventSender::DoDragAfterMouseMove(const WebMouseEvent& e) { |
2494 last_mouse_pos_ = WebPoint(e.x, e.y); | 2634 if (current_pointer_state_[kMousePointerId].pressed_button_ == |
2495 | 2635 WebMouseEvent::ButtonNone || |
2496 HandleInputEventOnViewOrPopup(e); | |
2497 | |
2498 if (pressed_button_ == WebMouseEvent::ButtonNone || | |
2499 current_drag_data_.isNull()) { | 2636 current_drag_data_.isNull()) { |
2500 return; | 2637 return; |
2501 } | 2638 } |
2502 | 2639 |
2503 WebPoint client_point(e.x, e.y); | 2640 WebPoint client_point(e.x, e.y); |
2504 WebPoint screen_point(e.globalX, e.globalY); | 2641 WebPoint screen_point(e.globalX, e.globalY); |
2505 current_drag_effect_ = view_->dragTargetDragOver( | 2642 current_drag_effect_ = view_->dragTargetDragOver( |
2506 client_point, screen_point, current_drag_effects_allowed_, e.modifiers); | 2643 client_point, screen_point, current_drag_effects_allowed_, e.modifiers); |
2507 } | 2644 } |
2508 | 2645 |
2509 void EventSender::ReplaySavedEvents() { | 2646 void EventSender::ReplaySavedEvents() { |
2510 replaying_saved_events_ = true; | 2647 replaying_saved_events_ = true; |
2511 while (!mouse_event_queue_.empty()) { | 2648 while (!mouse_event_queue_.empty()) { |
2512 SavedEvent e = mouse_event_queue_.front(); | 2649 SavedEvent e = mouse_event_queue_.front(); |
2513 mouse_event_queue_.pop_front(); | 2650 mouse_event_queue_.pop_front(); |
2514 | 2651 |
2515 switch (e.type) { | 2652 switch (e.type) { |
2516 case SavedEvent::TYPE_MOUSE_MOVE: { | 2653 case SavedEvent::TYPE_MOUSE_MOVE: { |
2517 WebMouseEvent event; | 2654 WebMouseEvent event; |
2518 InitMouseEvent(WebInputEvent::MouseMove, | 2655 InitMouseEvent( |
2519 pressed_button_, | 2656 WebInputEvent::MouseMove, |
2520 current_buttons_, | 2657 current_pointer_state_[kMousePointerId].pressed_button_, |
2521 e.pos, | 2658 current_pointer_state_[kMousePointerId].current_buttons_, |
2522 GetCurrentEventTimeSec(), | 2659 e.pos, |
2523 click_count_, | 2660 GetCurrentEventTimeSec(), |
2524 e.modifiers, | 2661 click_count_, |
2525 &event); | 2662 e.modifiers, |
2526 DoMouseMove(event); | 2663 blink::WebPointerProperties::PointerType::Mouse, |
| 2664 0, |
| 2665 &event); |
| 2666 current_pointer_state_[kMousePointerId].last_pos_ = |
| 2667 WebPoint(event.x, event.y); |
| 2668 HandleInputEventOnViewOrPopup(event); |
| 2669 DoDragAfterMouseMove(event); |
2527 break; | 2670 break; |
2528 } | 2671 } |
2529 case SavedEvent::TYPE_LEAP_FORWARD: | 2672 case SavedEvent::TYPE_LEAP_FORWARD: |
2530 DoLeapForward(e.milliseconds); | 2673 DoLeapForward(e.milliseconds); |
2531 break; | 2674 break; |
2532 case SavedEvent::TYPE_MOUSE_UP: { | 2675 case SavedEvent::TYPE_MOUSE_UP: { |
2533 current_buttons_ &= ~GetWebMouseEventModifierForButton(e.button_type); | 2676 current_pointer_state_[kMousePointerId].current_buttons_ &= |
2534 pressed_button_ = WebMouseEvent::ButtonNone; | 2677 ~GetWebMouseEventModifierForButton(e.button_type); |
| 2678 current_pointer_state_[kMousePointerId].pressed_button_ = |
| 2679 WebMouseEvent::ButtonNone; |
2535 | 2680 |
2536 WebMouseEvent event; | 2681 WebMouseEvent event; |
2537 InitMouseEvent(WebInputEvent::MouseUp, | 2682 InitMouseEvent(WebInputEvent::MouseUp, |
2538 e.button_type, | 2683 e.button_type, |
2539 current_buttons_, | 2684 current_pointer_state_[kMousePointerId].current_buttons_, |
2540 last_mouse_pos_, | 2685 current_pointer_state_[kMousePointerId].last_pos_, |
2541 GetCurrentEventTimeSec(), | 2686 GetCurrentEventTimeSec(), |
2542 click_count_, | 2687 click_count_, |
2543 e.modifiers, | 2688 e.modifiers, |
| 2689 blink::WebPointerProperties::PointerType::Mouse, |
| 2690 0, |
2544 &event); | 2691 &event); |
2545 DoMouseUp(event); | 2692 HandleInputEventOnViewOrPopup(event); |
| 2693 DoDragAfterMouseUp(event); |
2546 break; | 2694 break; |
2547 } | 2695 } |
2548 default: | 2696 default: |
2549 NOTREACHED(); | 2697 NOTREACHED(); |
2550 } | 2698 } |
2551 } | 2699 } |
2552 | 2700 |
2553 replaying_saved_events_ = false; | 2701 replaying_saved_events_ = false; |
2554 } | 2702 } |
2555 | 2703 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2615 &end_event); | 2763 &end_event); |
2616 end_event.data.scrollEnd.deltaUnits = | 2764 end_event.data.scrollEnd.deltaUnits = |
2617 begin_event.data.scrollBegin.deltaHintUnits; | 2765 begin_event.data.scrollBegin.deltaHintUnits; |
2618 | 2766 |
2619 if (force_layout_on_events_) | 2767 if (force_layout_on_events_) |
2620 view_->updateAllLifecyclePhases(); | 2768 view_->updateAllLifecyclePhases(); |
2621 HandleInputEventOnViewOrPopup(end_event); | 2769 HandleInputEventOnViewOrPopup(end_event); |
2622 } | 2770 } |
2623 | 2771 |
2624 } // namespace test_runner | 2772 } // namespace test_runner |
OLD | NEW |