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 // Sets the pointerType from the args. Returns false if there was any error from | |
dtapuska
2016/04/08 17:50:29
Assigns |pointerType| from the provided |args|.
Navid Zolghadr
2016/04/08 18:57:00
Done.
| |
71 // reading args. | |
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 // Sets the pointerType and pointerId from the args. It sets the default values | |
104 // If args doesn't have them. Returns false if there was any error from reading | |
105 // args or incosistency of the values. | |
106 bool getMousePenPointerTypeAndId(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 | |
dtapuska
2016/04/08 17:50:29
https://google.github.io/styleguide/cppguide.html#
Navid Zolghadr
2016/04/08 18:57:00
I guess I was following Blink style guide
https://
| |
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 | |
dtapuska
2016/04/08 17:50:29
period.
Navid Zolghadr
2016/04/08 18:56:59
Done.
| |
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_ && current_pointer_state_[kMousePointerId].pressed_button_ |
1241 != WebMouseEvent::ButtonNone) | |
1159 view_->mouseCaptureLost(); | 1242 view_->mouseCaptureLost(); |
1160 pressed_button_ = WebMouseEvent::ButtonNone; | 1243 current_pointer_state_.clear(); |
1161 current_buttons_ = 0; | |
1162 modifiers_ = 0; | |
1163 is_drag_mode_ = true; | 1244 is_drag_mode_ = true; |
1164 force_layout_on_events_ = true; | 1245 force_layout_on_events_ = true; |
1165 | 1246 |
1166 #if defined(OS_WIN) | 1247 #if defined(OS_WIN) |
1167 wm_key_down_ = WM_KEYDOWN; | 1248 wm_key_down_ = WM_KEYDOWN; |
1168 wm_key_up_ = WM_KEYUP; | 1249 wm_key_up_ = WM_KEYUP; |
1169 wm_char_ = WM_CHAR; | 1250 wm_char_ = WM_CHAR; |
1170 wm_dead_char_ = WM_DEADCHAR; | 1251 wm_dead_char_ = WM_DEADCHAR; |
1171 wm_sys_key_down_ = WM_SYSKEYDOWN; | 1252 wm_sys_key_down_ = WM_SYSKEYDOWN; |
1172 wm_sys_key_up_ = WM_SYSKEYUP; | 1253 wm_sys_key_up_ = WM_SYSKEYUP; |
1173 wm_sys_char_ = WM_SYSCHAR; | 1254 wm_sys_char_ = WM_SYSCHAR; |
1174 wm_sys_dead_char_ = WM_SYSDEADCHAR; | 1255 wm_sys_dead_char_ = WM_SYSDEADCHAR; |
1175 #endif | 1256 #endif |
1176 | 1257 |
1177 last_mouse_pos_ = WebPoint(0, 0); | |
1178 last_click_time_sec_ = 0; | 1258 last_click_time_sec_ = 0; |
1179 last_click_pos_ = WebPoint(0, 0); | 1259 last_click_pos_ = WebPoint(0, 0); |
1180 last_button_type_ = WebMouseEvent::ButtonNone; | 1260 last_button_type_ = WebMouseEvent::ButtonNone; |
1181 touch_points_.clear(); | 1261 touch_points_.clear(); |
1182 last_context_menu_data_.reset(); | 1262 last_context_menu_data_.reset(); |
1183 weak_factory_.InvalidateWeakPtrs(); | 1263 weak_factory_.InvalidateWeakPtrs(); |
1184 current_gesture_location_ = WebPoint(0, 0); | 1264 current_gesture_location_ = WebPoint(0, 0); |
1185 mouse_event_queue_.clear(); | 1265 mouse_event_queue_.clear(); |
1186 | 1266 |
1187 time_offset_ms_ = 0; | 1267 time_offset_ms_ = 0; |
(...skipping 17 matching lines...) Expand all Loading... | |
1205 } | 1285 } |
1206 | 1286 |
1207 void EventSender::SetContextMenuData(const WebContextMenuData& data) { | 1287 void EventSender::SetContextMenuData(const WebContextMenuData& data) { |
1208 last_context_menu_data_.reset(new WebContextMenuData(data)); | 1288 last_context_menu_data_.reset(new WebContextMenuData(data)); |
1209 } | 1289 } |
1210 | 1290 |
1211 void EventSender::DoDragDrop(const WebDragData& drag_data, | 1291 void EventSender::DoDragDrop(const WebDragData& drag_data, |
1212 WebDragOperationsMask mask) { | 1292 WebDragOperationsMask mask) { |
1213 WebMouseEvent event; | 1293 WebMouseEvent event; |
1214 InitMouseEvent(WebInputEvent::MouseDown, | 1294 InitMouseEvent(WebInputEvent::MouseDown, |
1215 pressed_button_, | 1295 current_pointer_state_[kMousePointerId].pressed_button_, |
1216 current_buttons_, | 1296 current_pointer_state_[kMousePointerId].current_buttons_, |
1217 last_mouse_pos_, | 1297 current_pointer_state_[kMousePointerId].last_pos_, |
1218 GetCurrentEventTimeSec(), | 1298 GetCurrentEventTimeSec(), |
1219 click_count_, | 1299 click_count_, |
1220 modifiers_, | 1300 current_pointer_state_[kMousePointerId].modifiers_, |
1301 blink::WebPointerProperties::PointerType::Mouse, | |
1302 0, | |
1221 &event); | 1303 &event); |
1222 WebPoint client_point(event.x, event.y); | 1304 WebPoint client_point(event.x, event.y); |
1223 WebPoint screen_point(event.globalX, event.globalY); | 1305 WebPoint screen_point(event.globalX, event.globalY); |
1224 current_drag_data_ = drag_data; | 1306 current_drag_data_ = drag_data; |
1225 current_drag_effects_allowed_ = mask; | 1307 current_drag_effects_allowed_ = mask; |
1226 current_drag_effect_ = view_->dragTargetDragEnter( | 1308 current_drag_effect_ = view_->dragTargetDragEnter( |
1227 drag_data, | 1309 drag_data, |
1228 client_point, | 1310 client_point, |
1229 screen_point, | 1311 screen_point, |
1230 current_drag_effects_allowed_, | 1312 current_drag_effects_allowed_, |
1231 modifiersWithButtons(modifiers_, current_buttons_)); | 1313 modifiersWithButtons(current_pointer_state_[kMousePointerId].modifiers_, |
1314 current_pointer_state_[kMousePointerId].current_buttons_)); | |
1232 | 1315 |
1233 // Finish processing events. | 1316 // Finish processing events. |
1234 ReplaySavedEvents(); | 1317 ReplaySavedEvents(); |
1235 } | 1318 } |
1236 | 1319 |
1237 void EventSender::MouseDown(int button_number, int modifiers) { | 1320 void EventSender::MouseDown(int button_number, int modifiers) { |
1321 PointerDown(button_number, modifiers, | |
1322 blink::WebPointerProperties::PointerType::Mouse, kMousePointerId); | |
1323 } | |
1324 | |
1325 void EventSender::MouseUp(int button_number, int modifiers) { | |
1326 PointerUp(button_number, modifiers, | |
1327 blink::WebPointerProperties::PointerType::Mouse, kMousePointerId); | |
1328 } | |
1329 | |
1330 void EventSender::PointerDown(int button_number, int modifiers, | |
1331 blink::WebPointerProperties::PointerType pointerType, int pointerId) { | |
1238 if (force_layout_on_events_) | 1332 if (force_layout_on_events_) |
1239 view_->updateAllLifecyclePhases(); | 1333 view_->updateAllLifecyclePhases(); |
1240 | 1334 |
1241 DCHECK_NE(-1, button_number); | 1335 DCHECK_NE(-1, button_number); |
1242 | 1336 |
1243 WebMouseEvent::Button button_type = | 1337 WebMouseEvent::Button button_type = |
1244 GetButtonTypeFromButtonNumber(button_number); | 1338 GetButtonTypeFromButtonNumber(button_number); |
1245 | 1339 |
1246 UpdateClickCountForButton(button_type); | 1340 WebMouseEvent event; |
1341 int click_count = 0; | |
1342 current_pointer_state_[pointerId].pressed_button_ = button_type; | |
1343 current_pointer_state_[pointerId].current_buttons_ |= | |
1344 GetWebMouseEventModifierForButton(button_type); | |
1345 current_pointer_state_[pointerId].modifiers_ = modifiers; | |
1247 | 1346 |
1248 pressed_button_ = button_type; | 1347 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) { |
1249 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 1348 UpdateClickCountForButton(button_type); |
1250 modifiers_ = modifiers; | 1349 click_count = click_count_; |
1350 } | |
1351 InitMouseEvent(WebInputEvent::MouseDown, | |
1352 current_pointer_state_[pointerId].pressed_button_, | |
1353 current_pointer_state_[pointerId].current_buttons_, | |
1354 current_pointer_state_[pointerId].last_pos_, | |
1355 GetCurrentEventTimeSec(), | |
1356 click_count, | |
1357 current_pointer_state_[pointerId].modifiers_, | |
1358 pointerType, | |
1359 pointerId, | |
1360 &event); | |
1251 | 1361 |
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); | 1362 HandleInputEventOnViewOrPopup(event); |
1262 } | 1363 } |
1263 | 1364 |
1264 void EventSender::MouseUp(int button_number, int modifiers) { | 1365 void EventSender::PointerUp(int button_number, int modifiers, |
1366 blink::WebPointerProperties::PointerType pointerType, int pointerId) { | |
1265 if (force_layout_on_events_) | 1367 if (force_layout_on_events_) |
1266 view_->updateAllLifecyclePhases(); | 1368 view_->updateAllLifecyclePhases(); |
1267 | 1369 |
1268 DCHECK_NE(-1, button_number); | 1370 DCHECK_NE(-1, button_number); |
1269 | 1371 |
1270 WebMouseEvent::Button button_type = | 1372 WebMouseEvent::Button button_type = |
1271 GetButtonTypeFromButtonNumber(button_number); | 1373 GetButtonTypeFromButtonNumber(button_number); |
1272 | 1374 |
1273 if (is_drag_mode_ && !replaying_saved_events_) { | 1375 if (pointerType == blink::WebPointerProperties::PointerType::Mouse |
1376 && is_drag_mode_ && !replaying_saved_events_) { | |
dtapuska
2016/04/08 17:50:28
https://google.github.io/styleguide/cppguide.html#
Navid Zolghadr
2016/04/08 18:57:00
Done.
| |
1274 SavedEvent saved_event; | 1377 SavedEvent saved_event; |
1275 saved_event.type = SavedEvent::TYPE_MOUSE_UP; | 1378 saved_event.type = SavedEvent::TYPE_MOUSE_UP; |
1276 saved_event.button_type = button_type; | 1379 saved_event.button_type = button_type; |
1277 saved_event.modifiers = modifiers; | 1380 saved_event.modifiers = modifiers; |
1278 mouse_event_queue_.push_back(saved_event); | 1381 mouse_event_queue_.push_back(saved_event); |
1279 ReplaySavedEvents(); | 1382 ReplaySavedEvents(); |
1280 } else { | 1383 } else { |
1281 current_buttons_ &= ~GetWebMouseEventModifierForButton(button_type); | 1384 current_pointer_state_[pointerId].current_buttons_ &= |
1282 pressed_button_ = WebMouseEvent::ButtonNone; | 1385 ~GetWebMouseEventModifierForButton(button_type); |
1386 current_pointer_state_[pointerId].pressed_button_ = | |
1387 WebMouseEvent::ButtonNone; | |
1283 | 1388 |
1284 WebMouseEvent event; | 1389 WebMouseEvent event; |
1285 InitMouseEvent(WebInputEvent::MouseUp, | 1390 InitMouseEvent(WebInputEvent::MouseUp, |
1286 button_type, | 1391 button_type, |
1287 current_buttons_, | 1392 current_pointer_state_[pointerId].current_buttons_, |
1288 last_mouse_pos_, | 1393 current_pointer_state_[pointerId].last_pos_, |
1289 GetCurrentEventTimeSec(), | 1394 GetCurrentEventTimeSec(), |
1290 click_count_, | 1395 pointerType == |
1396 blink::WebPointerProperties::PointerType::Mouse | |
1397 ? click_count_ : 0, | |
1291 modifiers, | 1398 modifiers, |
1399 pointerType, | |
1400 pointerId, | |
1292 &event); | 1401 &event); |
1293 DoMouseUp(event); | 1402 HandleInputEventOnViewOrPopup(event); |
1403 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) | |
1404 DoDragAfterMouseUp(event); | |
1294 } | 1405 } |
1295 } | 1406 } |
1296 | 1407 |
1297 void EventSender::SetMouseButtonState(int button_number, int modifiers) { | 1408 void EventSender::SetMouseButtonState(int button_number, int modifiers) { |
1298 pressed_button_ = GetButtonTypeFromButtonNumber(button_number); | 1409 current_pointer_state_[kMousePointerId].pressed_button_ = |
1299 current_buttons_ = (modifiers == -1) ? | 1410 GetButtonTypeFromButtonNumber(button_number); |
1300 GetWebMouseEventModifierForButton(pressed_button_) : | 1411 current_pointer_state_[kMousePointerId].current_buttons_ = (modifiers == -1) ? |
1412 GetWebMouseEventModifierForButton( | |
1413 current_pointer_state_[kMousePointerId].pressed_button_) : | |
1301 modifiers & kButtonsInModifiers; | 1414 modifiers & kButtonsInModifiers; |
1302 } | 1415 } |
1303 | 1416 |
1304 void EventSender::KeyDown(const std::string& code_str, | 1417 void EventSender::KeyDown(const std::string& code_str, |
1305 int modifiers, | 1418 int modifiers, |
1306 KeyLocationCode location) { | 1419 KeyLocationCode location) { |
1307 // FIXME: I'm not exactly sure how we should convert the string to a key | 1420 // 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. | 1421 // event. This seems to work in the cases I tested. |
1309 // FIXME: Should we also generate a KEY_UP? | 1422 // FIXME: Should we also generate a KEY_UP? |
1310 | 1423 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1491 // We just simulate the same behavior here. | 1604 // We just simulate the same behavior here. |
1492 std::string edit_command; | 1605 std::string edit_command; |
1493 if (GetEditCommand(event_down, &edit_command)) | 1606 if (GetEditCommand(event_down, &edit_command)) |
1494 delegate_->SetEditCommand(edit_command, ""); | 1607 delegate_->SetEditCommand(edit_command, ""); |
1495 | 1608 |
1496 HandleInputEventOnViewOrPopup(event_down); | 1609 HandleInputEventOnViewOrPopup(event_down); |
1497 | 1610 |
1498 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { | 1611 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { |
1499 WebMouseEvent event; | 1612 WebMouseEvent event; |
1500 InitMouseEvent(WebInputEvent::MouseDown, | 1613 InitMouseEvent(WebInputEvent::MouseDown, |
1501 pressed_button_, | 1614 current_pointer_state_[kMousePointerId].pressed_button_, |
1502 current_buttons_, | 1615 current_pointer_state_[kMousePointerId].current_buttons_, |
1503 last_mouse_pos_, | 1616 current_pointer_state_[kMousePointerId].last_pos_, |
1504 GetCurrentEventTimeSec(), | 1617 GetCurrentEventTimeSec(), |
1505 click_count_, | 1618 click_count_, |
1506 0, | 1619 0, |
1620 blink::WebPointerProperties::PointerType::Mouse, | |
1621 0, | |
1507 &event); | 1622 &event); |
1508 FinishDragAndDrop(event, blink::WebDragOperationNone); | 1623 FinishDragAndDrop(event, blink::WebDragOperationNone); |
1509 } | 1624 } |
1510 | 1625 |
1511 delegate_->ClearEditCommand(); | 1626 delegate_->ClearEditCommand(); |
1512 | 1627 |
1513 if (generate_char) { | 1628 if (generate_char) { |
1514 WebKeyboardEvent event_char = event_up; | 1629 WebKeyboardEvent event_char = event_up; |
1515 event_char.type = WebInputEvent::Char; | 1630 event_char.type = WebInputEvent::Char; |
1516 // keyIdentifier is an empty string, unless the Enter key was pressed. | 1631 // 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. | 1656 // be requested after following mouse events. |
1542 last_context_menu_data_.reset(); | 1657 last_context_menu_data_.reset(); |
1543 | 1658 |
1544 // Generate right mouse down and up. | 1659 // Generate right mouse down and up. |
1545 WebMouseEvent event; | 1660 WebMouseEvent event; |
1546 // This is a hack to work around only allowing a single pressed button since | 1661 // 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 | 1662 // we want to test the case where both the left and right mouse buttons are |
1548 // pressed. | 1663 // pressed. |
1549 // TODO(mustaq): This hack seems unused here! But do we need this hack at all | 1664 // TODO(mustaq): This hack seems unused here! But do we need this hack at all |
1550 // after adding current_buttons_. | 1665 // after adding current_buttons_. |
1551 if (pressed_button_ == WebMouseEvent::ButtonNone) { | 1666 if (current_pointer_state_[kMousePointerId].pressed_button_ |
1552 pressed_button_ = WebMouseEvent::ButtonRight; | 1667 == WebMouseEvent::ButtonNone) { |
1553 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 1668 current_pointer_state_[kMousePointerId].pressed_button_ = |
1669 WebMouseEvent::ButtonRight; | |
1670 current_pointer_state_[kMousePointerId].current_buttons_ |= | |
1671 GetWebMouseEventModifierForButton( | |
1672 current_pointer_state_[kMousePointerId].pressed_button_); | |
1554 } | 1673 } |
1555 InitMouseEvent(WebInputEvent::MouseDown, | 1674 InitMouseEvent(WebInputEvent::MouseDown, |
1556 WebMouseEvent::ButtonRight, | 1675 WebMouseEvent::ButtonRight, |
1557 current_buttons_, | 1676 current_pointer_state_[kMousePointerId].current_buttons_, |
1558 last_mouse_pos_, | 1677 current_pointer_state_[kMousePointerId].last_pos_, |
1559 GetCurrentEventTimeSec(), | 1678 GetCurrentEventTimeSec(), |
1560 click_count_, | 1679 click_count_, |
1561 0, | 1680 0, |
1681 blink::WebPointerProperties::PointerType::Mouse, | |
1682 0, | |
1562 &event); | 1683 &event); |
1563 HandleInputEventOnViewOrPopup(event); | 1684 HandleInputEventOnViewOrPopup(event); |
1564 | 1685 |
1565 #if defined(OS_WIN) | 1686 #if defined(OS_WIN) |
1566 current_buttons_ &= | 1687 current_pointer_state_[kMousePointerId].current_buttons_ &= |
1567 ~GetWebMouseEventModifierForButton(WebMouseEvent::ButtonRight); | 1688 ~GetWebMouseEventModifierForButton(WebMouseEvent::ButtonRight); |
1568 pressed_button_ = WebMouseEvent::ButtonNone; | 1689 current_pointer_state_[kMousePointerId].pressed_button_ = |
1690 WebMouseEvent::ButtonNone; | |
1569 | 1691 |
1570 InitMouseEvent(WebInputEvent::MouseUp, | 1692 InitMouseEvent(WebInputEvent::MouseUp, |
1571 WebMouseEvent::ButtonRight, | 1693 WebMouseEvent::ButtonRight, |
1572 current_buttons_, | 1694 current_pointer_state_[kMousePointerId].current_buttons_, |
1573 last_mouse_pos_, | 1695 current_pointer_state_[kMousePointerId].last_pos_, |
1574 GetCurrentEventTimeSec(), | 1696 GetCurrentEventTimeSec(), |
1575 click_count_, | 1697 click_count_, |
1576 0, | 1698 0, |
1699 blink::WebPointerProperties::PointerType::Mouse, | |
1700 0, | |
1577 &event); | 1701 &event); |
1578 HandleInputEventOnViewOrPopup(event); | 1702 HandleInputEventOnViewOrPopup(event); |
1579 #endif | 1703 #endif |
1580 | 1704 |
1581 std::vector<std::string> menu_items = | 1705 std::vector<std::string> menu_items = |
1582 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate_); | 1706 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate_); |
1583 last_context_menu_data_.reset(); | 1707 last_context_menu_data_.reset(); |
1584 return menu_items; | 1708 return menu_items; |
1585 } | 1709 } |
1586 | 1710 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1773 | 1897 |
1774 void EventSender::TouchCancel() { | 1898 void EventSender::TouchCancel() { |
1775 SendCurrentTouchEvent(WebInputEvent::TouchCancel, false); | 1899 SendCurrentTouchEvent(WebInputEvent::TouchCancel, false); |
1776 } | 1900 } |
1777 | 1901 |
1778 void EventSender::TouchEnd() { | 1902 void EventSender::TouchEnd() { |
1779 SendCurrentTouchEvent(WebInputEvent::TouchEnd, false); | 1903 SendCurrentTouchEvent(WebInputEvent::TouchEnd, false); |
1780 } | 1904 } |
1781 | 1905 |
1782 void EventSender::LeapForward(int milliseconds) { | 1906 void EventSender::LeapForward(int milliseconds) { |
1783 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && | 1907 if (is_drag_mode_ && current_pointer_state_[kMousePointerId].pressed_button_ |
1908 == WebMouseEvent::ButtonLeft && | |
1784 !replaying_saved_events_) { | 1909 !replaying_saved_events_) { |
1785 SavedEvent saved_event; | 1910 SavedEvent saved_event; |
1786 saved_event.type = SavedEvent::TYPE_LEAP_FORWARD; | 1911 saved_event.type = SavedEvent::TYPE_LEAP_FORWARD; |
1787 saved_event.milliseconds = milliseconds; | 1912 saved_event.milliseconds = milliseconds; |
1788 mouse_event_queue_.push_back(saved_event); | 1913 mouse_event_queue_.push_back(saved_event); |
1789 } else { | 1914 } else { |
1790 DoLeapForward(milliseconds); | 1915 DoLeapForward(milliseconds); |
1791 } | 1916 } |
1792 } | 1917 } |
1793 | 1918 |
(...skipping 16 matching lines...) Expand all Loading... | |
1810 item.filenameData = delegate_->GetAbsoluteWebStringFromUTF8Path(files[i]); | 1935 item.filenameData = delegate_->GetAbsoluteWebStringFromUTF8Path(files[i]); |
1811 current_drag_data_.addItem(item); | 1936 current_drag_data_.addItem(item); |
1812 absolute_filenames[i] = item.filenameData; | 1937 absolute_filenames[i] = item.filenameData; |
1813 } | 1938 } |
1814 current_drag_data_.setFilesystemId( | 1939 current_drag_data_.setFilesystemId( |
1815 delegate_->RegisterIsolatedFileSystem(absolute_filenames)); | 1940 delegate_->RegisterIsolatedFileSystem(absolute_filenames)); |
1816 current_drag_effects_allowed_ = blink::WebDragOperationCopy; | 1941 current_drag_effects_allowed_ = blink::WebDragOperationCopy; |
1817 | 1942 |
1818 // Provide a drag source. | 1943 // Provide a drag source. |
1819 view_->dragTargetDragEnter(current_drag_data_, | 1944 view_->dragTargetDragEnter(current_drag_data_, |
1820 last_mouse_pos_, | 1945 current_pointer_state_[kMousePointerId].last_pos_, |
1821 last_mouse_pos_, | 1946 current_pointer_state_[kMousePointerId].last_pos_, |
1822 current_drag_effects_allowed_, | 1947 current_drag_effects_allowed_, |
1823 0); | 1948 0); |
1824 // |is_drag_mode_| saves events and then replays them later. We don't | 1949 // |is_drag_mode_| saves events and then replays them later. We don't |
1825 // need/want that. | 1950 // need/want that. |
1826 is_drag_mode_ = false; | 1951 is_drag_mode_ = false; |
1827 | 1952 |
1828 // Make the rest of eventSender think a drag is in progress. | 1953 // Make the rest of eventSender think a drag is in progress. |
1829 pressed_button_ = WebMouseEvent::ButtonLeft; | 1954 current_pointer_state_[kMousePointerId].pressed_button_ = |
1830 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_); | 1955 WebMouseEvent::ButtonLeft; |
1956 current_pointer_state_[kMousePointerId].current_buttons_ |= | |
1957 GetWebMouseEventModifierForButton( | |
1958 current_pointer_state_[kMousePointerId].pressed_button_); | |
1831 } | 1959 } |
1832 | 1960 |
1833 void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) { | 1961 void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) { |
1834 WebTouchPoint touch_point; | 1962 WebTouchPoint touch_point; |
1835 touch_point.pointerType = WebPointerProperties::PointerType::Touch; | 1963 touch_point.pointerType = WebPointerProperties::PointerType::Touch; |
1836 touch_point.state = WebTouchPoint::StatePressed; | 1964 touch_point.state = WebTouchPoint::StatePressed; |
1837 touch_point.position = WebFloatPoint(x, y); | 1965 touch_point.position = WebFloatPoint(x, y); |
1838 touch_point.screenPosition = touch_point.position; | 1966 touch_point.screenPosition = touch_point.position; |
1839 | 1967 |
1840 int highest_id = -1; | 1968 int highest_id = -1; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1920 SendGesturesForMouseWheelEvent(wheel_event); | 2048 SendGesturesForMouseWheelEvent(wheel_event); |
1921 } | 2049 } |
1922 } | 2050 } |
1923 | 2051 |
1924 void EventSender::MouseMoveTo(gin::Arguments* args) { | 2052 void EventSender::MouseMoveTo(gin::Arguments* args) { |
1925 if (force_layout_on_events_) | 2053 if (force_layout_on_events_) |
1926 view_->updateAllLifecyclePhases(); | 2054 view_->updateAllLifecyclePhases(); |
1927 | 2055 |
1928 double x; | 2056 double x; |
1929 double y; | 2057 double y; |
2058 blink::WebPointerProperties::PointerType pointerType = | |
2059 blink::WebPointerProperties::PointerType::Mouse; | |
2060 int pointerId = 0; | |
1930 if (!args->GetNext(&x) || !args->GetNext(&y)) { | 2061 if (!args->GetNext(&x) || !args->GetNext(&y)) { |
1931 args->ThrowError(); | 2062 args->ThrowError(); |
1932 return; | 2063 return; |
1933 } | 2064 } |
1934 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); | 2065 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); |
1935 | 2066 |
1936 int modifiers = 0; | 2067 int modifiers = 0; |
1937 if (!args->PeekNext().IsEmpty()) | 2068 if (!args->PeekNext().IsEmpty()) { |
1938 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); | 2069 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
2070 args->Skip(); | |
2071 } | |
1939 | 2072 |
1940 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && | 2073 if (!getMousePenPointerTypeAndId(args, pointerType, pointerId)) |
1941 !replaying_saved_events_) { | 2074 return; |
2075 | |
2076 if (pointerType == blink::WebPointerProperties::PointerType::Mouse | |
2077 && is_drag_mode_ && !replaying_saved_events_ | |
2078 && current_pointer_state_[kMousePointerId].pressed_button_ | |
2079 == WebMouseEvent::ButtonLeft) { | |
1942 SavedEvent saved_event; | 2080 SavedEvent saved_event; |
1943 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; | 2081 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; |
1944 saved_event.pos = mouse_pos; | 2082 saved_event.pos = mouse_pos; |
1945 saved_event.modifiers = modifiers; | 2083 saved_event.modifiers = modifiers; |
1946 mouse_event_queue_.push_back(saved_event); | 2084 mouse_event_queue_.push_back(saved_event); |
1947 } else { | 2085 } else { |
2086 current_pointer_state_[pointerId].last_pos_ = mouse_pos; | |
1948 WebMouseEvent event; | 2087 WebMouseEvent event; |
1949 InitMouseEvent(WebInputEvent::MouseMove, | 2088 InitMouseEvent(WebInputEvent::MouseMove, |
1950 pressed_button_, | 2089 current_pointer_state_[kMousePointerId].pressed_button_, |
1951 current_buttons_, | 2090 current_pointer_state_[kMousePointerId].current_buttons_, |
1952 mouse_pos, | 2091 mouse_pos, |
1953 GetCurrentEventTimeSec(), | 2092 GetCurrentEventTimeSec(), |
1954 click_count_, | 2093 pointerType == |
2094 blink::WebPointerProperties::PointerType::Mouse | |
2095 ? click_count_ : 0, | |
1955 modifiers, | 2096 modifiers, |
2097 pointerType, | |
2098 pointerId, | |
1956 &event); | 2099 &event); |
1957 DoMouseMove(event); | 2100 HandleInputEventOnViewOrPopup(event); |
2101 if (pointerType == blink::WebPointerProperties::PointerType::Mouse) | |
2102 DoDragAfterMouseMove(event); | |
1958 } | 2103 } |
1959 } | 2104 } |
1960 | 2105 |
1961 void EventSender::MouseLeave() { | 2106 void EventSender::MouseLeave() { |
1962 if (force_layout_on_events_) | 2107 if (force_layout_on_events_) |
1963 view_->updateAllLifecyclePhases(); | 2108 view_->updateAllLifecyclePhases(); |
1964 | 2109 |
1965 WebMouseEvent event; | 2110 WebMouseEvent event; |
1966 InitMouseEvent(WebInputEvent::MouseLeave, | 2111 InitMouseEvent(WebInputEvent::MouseLeave, |
1967 WebMouseEvent::ButtonNone, | 2112 WebMouseEvent::ButtonNone, |
1968 0, | 2113 0, |
1969 last_mouse_pos_, | 2114 current_pointer_state_[kMousePointerId].last_pos_, |
1970 GetCurrentEventTimeSec(), | 2115 GetCurrentEventTimeSec(), |
1971 click_count_, | 2116 click_count_, |
1972 0, | 2117 0, |
2118 blink::WebPointerProperties::PointerType::Mouse, | |
2119 0, | |
1973 &event); | 2120 &event); |
1974 HandleInputEventOnViewOrPopup(event); | 2121 HandleInputEventOnViewOrPopup(event); |
1975 } | 2122 } |
1976 | 2123 |
1977 | 2124 |
1978 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { | 2125 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { |
1979 delegate_->PostTask(new WebCallbackTask( | 2126 delegate_->PostTask(new WebCallbackTask( |
1980 base::Bind(&EventSender::MouseDown, weak_factory_.GetWeakPtr(), | 2127 base::Bind(&EventSender::MouseDown, weak_factory_.GetWeakPtr(), |
1981 button_number, modifiers))); | 2128 button_number, modifiers))); |
1982 delegate_->PostTask(new WebCallbackTask( | 2129 delegate_->PostTask(new WebCallbackTask( |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2280 | 2427 |
2281 if (force_layout_on_events_) | 2428 if (force_layout_on_events_) |
2282 view_->updateAllLifecyclePhases(); | 2429 view_->updateAllLifecyclePhases(); |
2283 | 2430 |
2284 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); | 2431 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); |
2285 | 2432 |
2286 // Long press might start a drag drop session. Complete it if so. | 2433 // Long press might start a drag drop session. Complete it if so. |
2287 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { | 2434 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { |
2288 WebMouseEvent mouse_event; | 2435 WebMouseEvent mouse_event; |
2289 InitMouseEvent(WebInputEvent::MouseDown, | 2436 InitMouseEvent(WebInputEvent::MouseDown, |
2290 pressed_button_, | 2437 current_pointer_state_[kMousePointerId].pressed_button_, |
2291 current_buttons_, | 2438 current_pointer_state_[kMousePointerId].current_buttons_, |
2292 WebPoint(x, y), | 2439 WebPoint(x, y), |
2293 GetCurrentEventTimeSec(), | 2440 GetCurrentEventTimeSec(), |
2294 click_count_, | 2441 click_count_, |
2295 modifiers_, | 2442 current_pointer_state_[kMousePointerId].modifiers_, |
2443 blink::WebPointerProperties::PointerType::Mouse, | |
2444 0, | |
2296 &mouse_event); | 2445 &mouse_event); |
2297 | 2446 |
2298 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); | 2447 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); |
2299 } | 2448 } |
2300 args->Return(result != WebInputEventResult::NotHandled); | 2449 args->Return(result != WebInputEventResult::NotHandled); |
2301 } | 2450 } |
2302 | 2451 |
2303 void EventSender::UpdateClickCountForButton( | 2452 void EventSender::UpdateClickCountForButton( |
2304 WebMouseEvent::Button button_type) { | 2453 WebMouseEvent::Button button_type) { |
2305 if ((GetCurrentEventTimeSec() - last_click_time_sec_ < | 2454 if ((GetCurrentEventTimeSec() - last_click_time_sec_ < |
2306 kMultipleClickTimeSec) && | 2455 kMultipleClickTimeSec) && |
2307 (!OutsideMultiClickRadius(last_mouse_pos_, last_click_pos_)) && | 2456 (!OutsideMultiClickRadius( |
2308 (button_type == last_button_type_)) { | 2457 current_pointer_state_[kMousePointerId].last_pos_, last_click_pos_)) |
2458 && (button_type == last_button_type_)) { | |
2309 ++click_count_; | 2459 ++click_count_; |
2310 } else { | 2460 } else { |
2311 click_count_ = 1; | 2461 click_count_ = 1; |
2312 last_button_type_ = button_type; | 2462 last_button_type_ = button_type; |
2313 } | 2463 } |
2314 } | 2464 } |
2315 | 2465 |
2316 void EventSender::InitMouseWheelEvent(gin::Arguments* args, | 2466 void EventSender::InitMouseWheelEvent(gin::Arguments* args, |
2317 MouseScrollType scroll_type, | 2467 MouseScrollType scroll_type, |
2318 WebMouseWheelEvent* event, | 2468 WebMouseWheelEvent* event, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2351 } | 2501 } |
2352 } | 2502 } |
2353 } | 2503 } |
2354 } | 2504 } |
2355 if (can_scroll && send_wheel_gestures_) { | 2505 if (can_scroll && send_wheel_gestures_) { |
2356 can_scroll = false; | 2506 can_scroll = false; |
2357 *send_gestures = true; | 2507 *send_gestures = true; |
2358 } | 2508 } |
2359 | 2509 |
2360 InitMouseEvent(WebInputEvent::MouseWheel, | 2510 InitMouseEvent(WebInputEvent::MouseWheel, |
2361 pressed_button_, | 2511 current_pointer_state_[kMousePointerId].pressed_button_, |
2362 current_buttons_, | 2512 current_pointer_state_[kMousePointerId].current_buttons_, |
2363 last_mouse_pos_, | 2513 current_pointer_state_[kMousePointerId].last_pos_, |
2364 GetCurrentEventTimeSec(), | 2514 GetCurrentEventTimeSec(), |
2365 click_count_, | 2515 click_count_, |
2366 modifiers, | 2516 modifiers, |
2517 blink::WebPointerProperties::PointerType::Mouse, | |
2518 0, | |
2367 event); | 2519 event); |
2368 event->wheelTicksX = static_cast<float>(horizontal); | 2520 event->wheelTicksX = static_cast<float>(horizontal); |
2369 event->wheelTicksY = static_cast<float>(vertical); | 2521 event->wheelTicksY = static_cast<float>(vertical); |
2370 event->deltaX = event->wheelTicksX; | 2522 event->deltaX = event->wheelTicksX; |
2371 event->deltaY = event->wheelTicksY; | 2523 event->deltaY = event->wheelTicksY; |
2372 event->scrollByPage = paged; | 2524 event->scrollByPage = paged; |
2373 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; | 2525 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas; |
2374 event->canScroll = can_scroll; | 2526 event->canScroll = can_scroll; |
2375 if (scroll_type == MouseScrollType::PIXEL) { | 2527 if (scroll_type == MouseScrollType::PIXEL) { |
2376 event->wheelTicksX /= kScrollbarPixelsPerTick; | 2528 event->wheelTicksX /= kScrollbarPixelsPerTick; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2419 if (!args->PeekNext().IsEmpty()) { | 2571 if (!args->PeekNext().IsEmpty()) { |
2420 int tiltX, tiltY; | 2572 int tiltX, tiltY; |
2421 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) { | 2573 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) { |
2422 args->ThrowError(); | 2574 args->ThrowError(); |
2423 return; | 2575 return; |
2424 } | 2576 } |
2425 e->tiltX = tiltX; | 2577 e->tiltX = tiltX; |
2426 e->tiltY = tiltY; | 2578 e->tiltY = tiltY; |
2427 } | 2579 } |
2428 | 2580 |
2429 if (!args->PeekNext().IsEmpty()) { | 2581 if (!getPointerType(args, false, e->pointerType)) |
2430 std::string pointer_type_string; | 2582 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 } | 2583 } |
2449 | 2584 |
2450 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, | 2585 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, |
2451 blink::WebDragOperation drag_effect) { | 2586 blink::WebDragOperation drag_effect) { |
2452 WebPoint client_point(e.x, e.y); | 2587 WebPoint client_point(e.x, e.y); |
2453 WebPoint screen_point(e.globalX, e.globalY); | 2588 WebPoint screen_point(e.globalX, e.globalY); |
2454 current_drag_effect_ = drag_effect; | 2589 current_drag_effect_ = drag_effect; |
2455 if (current_drag_effect_) { | 2590 if (current_drag_effect_) { |
2456 // Specifically pass any keyboard modifiers to the drop method. This allows | 2591 // Specifically pass any keyboard modifiers to the drop method. This allows |
2457 // tests to control the drop type (i.e. copy or move). | 2592 // tests to control the drop type (i.e. copy or move). |
2458 view_->dragTargetDrop(client_point, screen_point, e.modifiers); | 2593 view_->dragTargetDrop(client_point, screen_point, e.modifiers); |
2459 } else { | 2594 } else { |
2460 view_->dragTargetDragLeave(); | 2595 view_->dragTargetDragLeave(); |
2461 } | 2596 } |
2462 view_->dragSourceEndedAt(client_point, screen_point, current_drag_effect_); | 2597 view_->dragSourceEndedAt(client_point, screen_point, current_drag_effect_); |
2463 view_->dragSourceSystemDragEnded(); | 2598 view_->dragSourceSystemDragEnded(); |
2464 | 2599 |
2465 current_drag_data_.reset(); | 2600 current_drag_data_.reset(); |
2466 } | 2601 } |
2467 | 2602 |
2468 void EventSender::DoMouseUp(const WebMouseEvent& e) { | 2603 void EventSender::DoDragAfterMouseUp(const WebMouseEvent& e) { |
2469 HandleInputEventOnViewOrPopup(e); | |
2470 | |
2471 last_click_time_sec_ = e.timeStampSeconds; | 2604 last_click_time_sec_ = e.timeStampSeconds; |
2472 last_click_pos_ = last_mouse_pos_; | 2605 last_click_pos_ = current_pointer_state_[kMousePointerId].last_pos_; |
2473 | 2606 |
2474 // If we're in a drag operation, complete it. | 2607 // If we're in a drag operation, complete it. |
2475 if (current_drag_data_.isNull()) | 2608 if (current_drag_data_.isNull()) |
2476 return; | 2609 return; |
2477 | 2610 |
2478 WebPoint client_point(e.x, e.y); | 2611 WebPoint client_point(e.x, e.y); |
2479 WebPoint screen_point(e.globalX, e.globalY); | 2612 WebPoint screen_point(e.globalX, e.globalY); |
2480 blink::WebDragOperation drag_effect = view_->dragTargetDragOver( | 2613 blink::WebDragOperation drag_effect = view_->dragTargetDragOver( |
2481 client_point, | 2614 client_point, |
2482 screen_point, | 2615 screen_point, |
2483 current_drag_effects_allowed_, | 2616 current_drag_effects_allowed_, |
2484 e.modifiers); | 2617 e.modifiers); |
2485 | 2618 |
2486 // Bail if dragover caused cancellation. | 2619 // Bail if dragover caused cancellation. |
2487 if (current_drag_data_.isNull()) | 2620 if (current_drag_data_.isNull()) |
2488 return; | 2621 return; |
2489 | 2622 |
2490 FinishDragAndDrop(e, drag_effect); | 2623 FinishDragAndDrop(e, drag_effect); |
2491 } | 2624 } |
2492 | 2625 |
2493 void EventSender::DoMouseMove(const WebMouseEvent& e) { | 2626 void EventSender::DoDragAfterMouseMove(const WebMouseEvent& e) { |
2494 last_mouse_pos_ = WebPoint(e.x, e.y); | 2627 if (current_pointer_state_[kMousePointerId].pressed_button_ |
2495 | 2628 == WebMouseEvent::ButtonNone |
2496 HandleInputEventOnViewOrPopup(e); | 2629 || current_drag_data_.isNull()) { |
2497 | |
2498 if (pressed_button_ == WebMouseEvent::ButtonNone || | |
2499 current_drag_data_.isNull()) { | |
2500 return; | 2630 return; |
2501 } | 2631 } |
2502 | 2632 |
2503 WebPoint client_point(e.x, e.y); | 2633 WebPoint client_point(e.x, e.y); |
2504 WebPoint screen_point(e.globalX, e.globalY); | 2634 WebPoint screen_point(e.globalX, e.globalY); |
2505 current_drag_effect_ = view_->dragTargetDragOver( | 2635 current_drag_effect_ = view_->dragTargetDragOver( |
2506 client_point, screen_point, current_drag_effects_allowed_, e.modifiers); | 2636 client_point, screen_point, current_drag_effects_allowed_, e.modifiers); |
2507 } | 2637 } |
2508 | 2638 |
2509 void EventSender::ReplaySavedEvents() { | 2639 void EventSender::ReplaySavedEvents() { |
2510 replaying_saved_events_ = true; | 2640 replaying_saved_events_ = true; |
2511 while (!mouse_event_queue_.empty()) { | 2641 while (!mouse_event_queue_.empty()) { |
2512 SavedEvent e = mouse_event_queue_.front(); | 2642 SavedEvent e = mouse_event_queue_.front(); |
2513 mouse_event_queue_.pop_front(); | 2643 mouse_event_queue_.pop_front(); |
2514 | 2644 |
2515 switch (e.type) { | 2645 switch (e.type) { |
2516 case SavedEvent::TYPE_MOUSE_MOVE: { | 2646 case SavedEvent::TYPE_MOUSE_MOVE: { |
2517 WebMouseEvent event; | 2647 WebMouseEvent event; |
2518 InitMouseEvent(WebInputEvent::MouseMove, | 2648 InitMouseEvent(WebInputEvent::MouseMove, |
2519 pressed_button_, | 2649 current_pointer_state_[kMousePointerId].pressed_button_, |
2520 current_buttons_, | 2650 current_pointer_state_[kMousePointerId].current_buttons_, |
2521 e.pos, | 2651 e.pos, |
2522 GetCurrentEventTimeSec(), | 2652 GetCurrentEventTimeSec(), |
2523 click_count_, | 2653 click_count_, |
2524 e.modifiers, | 2654 e.modifiers, |
2655 blink::WebPointerProperties::PointerType::Mouse, | |
2656 0, | |
2525 &event); | 2657 &event); |
2526 DoMouseMove(event); | 2658 current_pointer_state_[kMousePointerId].last_pos_ = |
2659 WebPoint(event.x, event.y); | |
2660 HandleInputEventOnViewOrPopup(event); | |
2661 DoDragAfterMouseMove(event); | |
2527 break; | 2662 break; |
2528 } | 2663 } |
2529 case SavedEvent::TYPE_LEAP_FORWARD: | 2664 case SavedEvent::TYPE_LEAP_FORWARD: |
2530 DoLeapForward(e.milliseconds); | 2665 DoLeapForward(e.milliseconds); |
2531 break; | 2666 break; |
2532 case SavedEvent::TYPE_MOUSE_UP: { | 2667 case SavedEvent::TYPE_MOUSE_UP: { |
2533 current_buttons_ &= ~GetWebMouseEventModifierForButton(e.button_type); | 2668 current_pointer_state_[kMousePointerId].current_buttons_ &= |
2534 pressed_button_ = WebMouseEvent::ButtonNone; | 2669 ~GetWebMouseEventModifierForButton(e.button_type); |
2670 current_pointer_state_[kMousePointerId].pressed_button_ = | |
2671 WebMouseEvent::ButtonNone; | |
2535 | 2672 |
2536 WebMouseEvent event; | 2673 WebMouseEvent event; |
2537 InitMouseEvent(WebInputEvent::MouseUp, | 2674 InitMouseEvent(WebInputEvent::MouseUp, |
2538 e.button_type, | 2675 e.button_type, |
2539 current_buttons_, | 2676 current_pointer_state_[kMousePointerId].current_buttons_, |
2540 last_mouse_pos_, | 2677 current_pointer_state_[kMousePointerId].last_pos_, |
2541 GetCurrentEventTimeSec(), | 2678 GetCurrentEventTimeSec(), |
2542 click_count_, | 2679 click_count_, |
2543 e.modifiers, | 2680 e.modifiers, |
2681 blink::WebPointerProperties::PointerType::Mouse, | |
2682 0, | |
2544 &event); | 2683 &event); |
2545 DoMouseUp(event); | 2684 HandleInputEventOnViewOrPopup(event); |
2685 DoDragAfterMouseUp(event); | |
2546 break; | 2686 break; |
2547 } | 2687 } |
2548 default: | 2688 default: |
2549 NOTREACHED(); | 2689 NOTREACHED(); |
2550 } | 2690 } |
2551 } | 2691 } |
2552 | 2692 |
2553 replaying_saved_events_ = false; | 2693 replaying_saved_events_ = false; |
2554 } | 2694 } |
2555 | 2695 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2615 &end_event); | 2755 &end_event); |
2616 end_event.data.scrollEnd.deltaUnits = | 2756 end_event.data.scrollEnd.deltaUnits = |
2617 begin_event.data.scrollBegin.deltaHintUnits; | 2757 begin_event.data.scrollBegin.deltaHintUnits; |
2618 | 2758 |
2619 if (force_layout_on_events_) | 2759 if (force_layout_on_events_) |
2620 view_->updateAllLifecyclePhases(); | 2760 view_->updateAllLifecyclePhases(); |
2621 HandleInputEventOnViewOrPopup(end_event); | 2761 HandleInputEventOnViewOrPopup(end_event); |
2622 } | 2762 } |
2623 | 2763 |
2624 } // namespace test_runner | 2764 } // namespace test_runner |
OLD | NEW |