blob: 01f8a5e9e7d593961184f118d51b18e0decd777a [file] [log] [blame]
[email protected]3db130e2014-03-27 08:14:481// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
jochen73e711c2015-06-03 10:01:465#include "components/test_runner/event_sender.h"
[email protected]3db130e2014-03-27 08:14:486
avi5dd91f82015-12-25 22:30:467#include <stddef.h>
8
lukaszad322c5ca2016-10-07 00:32:349#include <memory>
10
lukaszac9358822016-04-07 14:43:4611#include "base/bind.h"
12#include "base/bind_helpers.h"
dtapuska43f18e9e2016-03-20 20:21:3013#include "base/command_line.h"
dcheng3dd85612017-02-08 10:46:2314#include "base/files/file_path.h"
[email protected]3db130e2014-03-27 08:14:4815#include "base/logging.h"
avi5dd91f82015-12-25 22:30:4616#include "base/macros.h"
esprehnd29ab802015-12-11 13:01:1917#include "base/strings/string16.h"
habib.virji565c80c2015-02-06 12:26:4318#include "base/strings/string_util.h"
[email protected]3db130e2014-03-27 08:14:4819#include "base/strings/stringprintf.h"
esprehnd29ab802015-12-11 13:01:1920#include "base/strings/utf_string_conversions.h"
avi5dd91f82015-12-25 22:30:4621#include "build/build_config.h"
jochen73e711c2015-06-03 10:01:4622#include "components/test_runner/mock_spell_check.h"
23#include "components/test_runner/test_interfaces.h"
24#include "components/test_runner/web_test_delegate.h"
lfg05e41372016-07-22 15:38:1025#include "components/test_runner/web_view_test_proxy.h"
lukaszad322c5ca2016-10-07 00:32:3426#include "components/test_runner/web_widget_test_proxy.h"
[email protected]3db130e2014-03-27 08:14:4827#include "gin/handle.h"
28#include "gin/object_template_builder.h"
29#include "gin/wrappable.h"
dcheng3dd85612017-02-08 10:46:2330#include "net/base/filename_util.h"
31#include "third_party/WebKit/public/platform/URLConversion.h"
nzolghadr5d8596502017-01-23 22:59:3532#include "third_party/WebKit/public/platform/WebCoalescedInputEvent.h"
dtapuska836e1f92016-11-15 00:38:0633#include "third_party/WebKit/public/platform/WebGestureEvent.h"
dtapuskaa64845d2017-01-20 21:20:4534#include "third_party/WebKit/public/platform/WebKeyboardEvent.h"
mustaqcc6220fa2016-03-09 22:07:5435#include "third_party/WebKit/public/platform/WebPointerProperties.h"
[email protected]3db130e2014-03-27 08:14:4836#include "third_party/WebKit/public/platform/WebString.h"
dtapuskaa64845d2017-01-20 21:20:4537#include "third_party/WebKit/public/platform/WebTouchEvent.h"
[email protected]3db130e2014-03-27 08:14:4838#include "third_party/WebKit/public/platform/WebVector.h"
39#include "third_party/WebKit/public/web/WebContextMenuData.h"
paulmeyer90f6c31d2016-11-12 00:17:5940#include "third_party/WebKit/public/web/WebFrameWidget.h"
[email protected]3db130e2014-03-27 08:14:4841#include "third_party/WebKit/public/web/WebKit.h"
lukasza335bb762016-04-22 16:44:0342#include "third_party/WebKit/public/web/WebLocalFrame.h"
tkent588765612014-11-28 01:07:4843#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]3db130e2014-03-27 08:14:4844#include "third_party/WebKit/public/web/WebView.h"
oshima76b6eeb2016-06-27 15:55:1245#include "ui/events/blink/blink_event_util.h"
kpschoedel3b0960a2015-05-11 17:52:1146#include "ui/events/keycodes/dom/keycode_converter.h"
[email protected]a731f1a92014-04-17 19:31:0647#include "ui/events/keycodes/keyboard_codes.h"
[email protected]3db130e2014-03-27 08:14:4848#include "v8/include/v8.h"
49
[email protected]3db130e2014-03-27 08:14:4850using blink::WebContextMenuData;
51using blink::WebDragData;
52using blink::WebDragOperationsMask;
53using blink::WebFloatPoint;
[email protected]3db130e2014-03-27 08:14:4854using blink::WebGestureEvent;
55using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:4956using blink::WebInputEventResult;
[email protected]3db130e2014-03-27 08:14:4857using blink::WebKeyboardEvent;
lukasza335bb762016-04-22 16:44:0358using blink::WebLocalFrame;
[email protected]f9634a82014-08-05 13:10:1959using blink::WebMenuItemInfo;
[email protected]3db130e2014-03-27 08:14:4860using blink::WebMouseEvent;
61using blink::WebMouseWheelEvent;
tkent588765612014-11-28 01:07:4862using blink::WebPagePopup;
[email protected]3db130e2014-03-27 08:14:4863using blink::WebPoint;
mustaqcc6220fa2016-03-09 22:07:5464using blink::WebPointerProperties;
[email protected]3db130e2014-03-27 08:14:4865using blink::WebString;
66using blink::WebTouchEvent;
67using blink::WebTouchPoint;
dcheng3dd85612017-02-08 10:46:2368using blink::WebURL;
[email protected]3db130e2014-03-27 08:14:4869using blink::WebVector;
70using blink::WebView;
71
jochenf5f31752015-06-03 12:06:3472namespace test_runner {
[email protected]3db130e2014-03-27 08:14:4873
74namespace {
75
mustaqabca6ff2016-06-09 17:29:5376const int kRawMousePointerId = -1;
mustaq758b1152016-09-02 22:06:4377const char* const kPointerTypeStringUnknown = "";
78const char* const kPointerTypeStringMouse = "mouse";
79const char* const kPointerTypeStringTouch = "touch";
80const char* const kPointerTypeStringPen = "pen";
81const char* const kPointerTypeStringEraser = "eraser";
nzolghadr43146032016-04-11 15:33:3882
83// Assigns |pointerType| from the provided |args|. Returns false if there was
84// any error.
85bool getPointerType(gin::Arguments* args,
86 bool isOnlyMouseAndPenAllowed,
mustaqabca6ff2016-06-09 17:29:5387 WebPointerProperties::PointerType& pointerType) {
nzolghadr43146032016-04-11 15:33:3888 if (args->PeekNext().IsEmpty())
89 return true;
90 std::string pointer_type_string;
91 if (!args->GetNext(&pointer_type_string)) {
92 args->ThrowError();
93 return false;
94 }
95 if (isOnlyMouseAndPenAllowed &&
96 (pointer_type_string == kPointerTypeStringUnknown ||
97 pointer_type_string == kPointerTypeStringTouch)) {
98 args->ThrowError();
99 return false;
100 }
101 if (pointer_type_string == kPointerTypeStringUnknown) {
102 pointerType = WebMouseEvent::PointerType::Unknown;
103 } else if (pointer_type_string == kPointerTypeStringMouse) {
104 pointerType = WebMouseEvent::PointerType::Mouse;
nzolghadr43146032016-04-11 15:33:38105 } else if (pointer_type_string == kPointerTypeStringTouch) {
106 pointerType = WebMouseEvent::PointerType::Touch;
mustaq758b1152016-09-02 22:06:43107 } else if (pointer_type_string == kPointerTypeStringPen) {
108 pointerType = WebMouseEvent::PointerType::Pen;
109 } else if (pointer_type_string == kPointerTypeStringEraser) {
110 pointerType = WebMouseEvent::PointerType::Eraser;
nzolghadr43146032016-04-11 15:33:38111 } else {
112 args->ThrowError();
113 return false;
114 }
115 return true;
116}
117
mustaqabca6ff2016-06-09 17:29:53118// Parses |pointerType|, |rawPointerId|, |pressure|, |tiltX| and |tiltY| from
119// the provided |args|. Returns false if there was any error, assuming the last
120// 3 of the five parsed parameters are optional.
121bool getMousePenPointerProperties(
nzolghadr43146032016-04-11 15:33:38122 gin::Arguments* args,
mustaqabca6ff2016-06-09 17:29:53123 WebPointerProperties::PointerType& pointerType,
124 int& rawPointerId,
125 float& pressure,
126 int& tiltX,
127 int& tiltY) {
128 pointerType = WebPointerProperties::PointerType::Mouse;
129 rawPointerId = kRawMousePointerId;
130 pressure = std::numeric_limits<float>::quiet_NaN();
131 tiltX = 0;
132 tiltY = 0;
133
nzolghadr43146032016-04-11 15:33:38134 // Only allow pen or mouse through this API.
135 if (!getPointerType(args, false, pointerType))
136 return false;
137 if (!args->PeekNext().IsEmpty()) {
mustaqabca6ff2016-06-09 17:29:53138 if (!args->GetNext(&rawPointerId)) {
nzolghadr43146032016-04-11 15:33:38139 args->ThrowError();
140 return false;
141 }
mustaqabca6ff2016-06-09 17:29:53142
143 // Parse optional params
144 if (!args->PeekNext().IsEmpty()) {
145 if (!args->GetNext(&pressure)) {
146 args->ThrowError();
147 return false;
148 }
149 if (!args->PeekNext().IsEmpty()) {
150 if (!args->GetNext(&tiltX)) {
151 args->ThrowError();
152 return false;
153 }
154 if (!args->PeekNext().IsEmpty()) {
155 if (!args->GetNext(&tiltY)) {
156 args->ThrowError();
157 return false;
158 }
159 }
160 }
nzolghadr43146032016-04-11 15:33:38161 }
nzolghadr43146032016-04-11 15:33:38162 }
mustaqabca6ff2016-06-09 17:29:53163
nzolghadr43146032016-04-11 15:33:38164 return true;
165}
166
mustaq8911f4e2015-10-27 18:10:22167WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) {
168 switch (button_code) {
169 case -1:
nzolghadr656569e2016-08-19 16:53:00170 return WebMouseEvent::Button::NoButton;
mustaq8911f4e2015-10-27 18:10:22171 case 0:
nzolghadr656569e2016-08-19 16:53:00172 return WebMouseEvent::Button::Left;
mustaq8911f4e2015-10-27 18:10:22173 case 1:
nzolghadr656569e2016-08-19 16:53:00174 return WebMouseEvent::Button::Middle;
mustaq8911f4e2015-10-27 18:10:22175 case 2:
nzolghadr656569e2016-08-19 16:53:00176 return WebMouseEvent::Button::Right;
mustaq8911f4e2015-10-27 18:10:22177 }
178 NOTREACHED();
nzolghadr656569e2016-08-19 16:53:00179 return WebMouseEvent::Button::NoButton;
mustaq8911f4e2015-10-27 18:10:22180}
181
mustaq21aed4e2015-12-15 21:47:21182int GetWebMouseEventModifierForButton(WebMouseEvent::Button button) {
183 switch (button) {
nzolghadr656569e2016-08-19 16:53:00184 case WebMouseEvent::Button::NoButton:
mustaq21aed4e2015-12-15 21:47:21185 return 0;
nzolghadr656569e2016-08-19 16:53:00186 case WebMouseEvent::Button::Left:
mustaq21aed4e2015-12-15 21:47:21187 return WebMouseEvent::LeftButtonDown;
nzolghadr656569e2016-08-19 16:53:00188 case WebMouseEvent::Button::Middle:
mustaq21aed4e2015-12-15 21:47:21189 return WebMouseEvent::MiddleButtonDown;
nzolghadr656569e2016-08-19 16:53:00190 case WebMouseEvent::Button::Right:
mustaq21aed4e2015-12-15 21:47:21191 return WebMouseEvent::RightButtonDown;
mustaq758b1152016-09-02 22:06:43192 case WebPointerProperties::Button::X1:
193 case WebPointerProperties::Button::X2:
194 case WebPointerProperties::Button::Eraser:
195 return 0; // Not implemented yet
mustaq21aed4e2015-12-15 21:47:21196 }
197 NOTREACHED();
198 return 0;
199}
200
201const int kButtonsInModifiers = WebMouseEvent::LeftButtonDown
202 | WebMouseEvent::MiddleButtonDown | WebMouseEvent::RightButtonDown;
203
nzolghadr65468b42016-01-19 14:03:58204int modifiersWithButtons(int modifiers, int buttons) {
205 return (modifiers & ~kButtonsInModifiers)
206 | (buttons & kButtonsInModifiers);
207}
208
dtapuska899ac222017-01-03 18:09:16209void InitMouseEventGeneric(WebMouseEvent::Button b,
mustaqabca6ff2016-06-09 17:29:53210 int current_buttons,
211 const WebPoint& pos,
mustaqabca6ff2016-06-09 17:29:53212 int click_count,
mustaqabca6ff2016-06-09 17:29:53213 WebPointerProperties::PointerType pointerType,
214 int pointerId,
215 float pressure,
216 int tiltX,
217 int tiltY,
218 WebMouseEvent* e) {
[email protected]3db130e2014-03-27 08:14:48219 e->button = b;
[email protected]3db130e2014-03-27 08:14:48220 e->x = pos.x;
221 e->y = pos.y;
222 e->globalX = pos.x;
223 e->globalY = pos.y;
nzolghadr43146032016-04-11 15:33:38224 e->pointerType = pointerType;
225 e->id = pointerId;
mustaqabca6ff2016-06-09 17:29:53226 e->force = pressure;
227 e->tiltX = tiltX;
228 e->tiltY = tiltY;
[email protected]3db130e2014-03-27 08:14:48229 e->clickCount = click_count;
230}
231
dtapuska899ac222017-01-03 18:09:16232void InitMouseEvent(WebMouseEvent::Button b,
mustaqabca6ff2016-06-09 17:29:53233 int current_buttons,
234 const WebPoint& pos,
mustaqabca6ff2016-06-09 17:29:53235 int click_count,
mustaqabca6ff2016-06-09 17:29:53236 WebMouseEvent* e) {
dtapuska899ac222017-01-03 18:09:16237 InitMouseEventGeneric(b, current_buttons, pos, click_count,
238 WebPointerProperties::PointerType::Mouse, 0, 0.0, 0, 0,
239 e);
mustaqabca6ff2016-06-09 17:29:53240}
241
dtapuska899ac222017-01-03 18:09:16242void InitGestureEventFromMouseWheel(const WebMouseWheelEvent& wheel_event,
dtapuska43f18e9e2016-03-20 20:21:30243 WebGestureEvent* gesture_event) {
dtapuska43f18e9e2016-03-20 20:21:30244 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad;
245 gesture_event->x = wheel_event.x;
246 gesture_event->y = wheel_event.y;
247 gesture_event->globalX = wheel_event.globalX;
248 gesture_event->globalY = wheel_event.globalY;
dtapuska43f18e9e2016-03-20 20:21:30249}
250
[email protected]3db130e2014-03-27 08:14:48251int GetKeyModifier(const std::string& modifier_name) {
252 const char* characters = modifier_name.c_str();
253 if (!strcmp(characters, "ctrlKey")
254#ifndef __APPLE__
255 || !strcmp(characters, "addSelectionKey")
256#endif
257 ) {
258 return WebInputEvent::ControlKey;
259 } else if (!strcmp(characters, "shiftKey") ||
260 !strcmp(characters, "rangeSelectionKey")) {
261 return WebInputEvent::ShiftKey;
262 } else if (!strcmp(characters, "altKey")) {
263 return WebInputEvent::AltKey;
264#ifdef __APPLE__
265 } else if (!strcmp(characters, "metaKey") ||
266 !strcmp(characters, "addSelectionKey")) {
267 return WebInputEvent::MetaKey;
268#else
269 } else if (!strcmp(characters, "metaKey")) {
270 return WebInputEvent::MetaKey;
271#endif
272 } else if (!strcmp(characters, "autoRepeat")) {
273 return WebInputEvent::IsAutoRepeat;
274 } else if (!strcmp(characters, "copyKey")) {
275#ifdef __APPLE__
276 return WebInputEvent::AltKey;
277#else
278 return WebInputEvent::ControlKey;
279#endif
tkentc8c0bc82015-10-15 22:43:48280 } else if (!strcmp(characters, "accessKey")) {
281#ifdef __APPLE__
282 return WebInputEvent::AltKey | WebInputEvent::ControlKey;
283#else
284 return WebInputEvent::AltKey;
285#endif
jinho.bangffc700e2014-11-17 04:05:26286 } else if (!strcmp(characters, "leftButton")) {
287 return WebInputEvent::LeftButtonDown;
288 } else if (!strcmp(characters, "middleButton")) {
289 return WebInputEvent::MiddleButtonDown;
290 } else if (!strcmp(characters, "rightButton")) {
291 return WebInputEvent::RightButtonDown;
dtapuska299efe12015-10-05 16:53:44292 } else if (!strcmp(characters, "capsLockOn")) {
293 return WebInputEvent::CapsLockOn;
294 } else if (!strcmp(characters, "numLockOn")) {
295 return WebInputEvent::NumLockOn;
296 } else if (!strcmp(characters, "locationLeft")) {
297 return WebInputEvent::IsLeft;
298 } else if (!strcmp(characters, "locationRight")) {
299 return WebInputEvent::IsRight;
300 } else if (!strcmp(characters, "locationNumpad")) {
301 return WebInputEvent::IsKeyPad;
302 } else if (!strcmp(characters, "isComposing")) {
303 return WebInputEvent::IsComposing;
304 } else if (!strcmp(characters, "altGraphKey")) {
305 return WebInputEvent::AltGrKey;
dtapuska299efe12015-10-05 16:53:44306 } else if (!strcmp(characters, "fnKey")) {
307 return WebInputEvent::FnKey;
308 } else if (!strcmp(characters, "symbolKey")) {
309 return WebInputEvent::SymbolKey;
310 } else if (!strcmp(characters, "scrollLockOn")) {
311 return WebInputEvent::ScrollLockOn;
[email protected]3db130e2014-03-27 08:14:48312 }
313
314 return 0;
315}
316
317int GetKeyModifiers(const std::vector<std::string>& modifier_names) {
318 int modifiers = 0;
319 for (std::vector<std::string>::const_iterator it = modifier_names.begin();
320 it != modifier_names.end(); ++it) {
321 modifiers |= GetKeyModifier(*it);
322 }
323 return modifiers;
324}
325
bashidbd2ef9bb2015-06-02 01:39:32326int GetKeyModifiersFromV8(v8::Isolate* isolate, v8::Local<v8::Value> value) {
[email protected]3db130e2014-03-27 08:14:48327 std::vector<std::string> modifier_names;
328 if (value->IsString()) {
329 modifier_names.push_back(gin::V8ToString(value));
330 } else if (value->IsArray()) {
331 gin::Converter<std::vector<std::string> >::FromV8(
bashidbd2ef9bb2015-06-02 01:39:32332 isolate, value, &modifier_names);
[email protected]3db130e2014-03-27 08:14:48333 }
334 return GetKeyModifiers(modifier_names);
335}
336
chongzb92d7112016-07-04 22:11:54337WebMouseWheelEvent::Phase GetMouseWheelEventPhase(
338 const std::string& phase_name) {
339 if (phase_name == "phaseNone") {
340 return WebMouseWheelEvent::PhaseNone;
341 } else if (phase_name == "phaseBegan") {
342 return WebMouseWheelEvent::PhaseBegan;
343 } else if (phase_name == "phaseStationary") {
344 return WebMouseWheelEvent::PhaseStationary;
345 } else if (phase_name == "phaseChanged") {
346 return WebMouseWheelEvent::PhaseChanged;
347 } else if (phase_name == "phaseEnded") {
348 return WebMouseWheelEvent::PhaseEnded;
349 } else if (phase_name == "phaseCancelled") {
350 return WebMouseWheelEvent::PhaseCancelled;
351 } else if (phase_name == "phaseMayBegin") {
352 return WebMouseWheelEvent::PhaseMayBegin;
353 }
354
355 return WebMouseWheelEvent::PhaseNone;
356}
357
358WebMouseWheelEvent::Phase GetMouseWheelEventPhaseFromV8(
359 v8::Local<v8::Value> value) {
360 if (value->IsString())
361 return GetMouseWheelEventPhase(gin::V8ToString(value));
362 return WebMouseWheelEvent::PhaseNone;
363}
364
[email protected]3db130e2014-03-27 08:14:48365// Maximum distance (in space and time) for a mouse click to register as a
366// double or triple click.
367const double kMultipleClickTimeSec = 1;
368const int kMultipleClickRadiusPixels = 5;
[email protected]f9634a82014-08-05 13:10:19369const char kSubMenuDepthIdentifier[] = "_";
370const char kSubMenuIdentifier[] = " >";
sanjoy.pal362c3252014-08-26 08:07:08371const char kSeparatorIdentifier[] = "---------";
sanjoy.pala62675e2014-11-27 00:47:29372const char kDisabledIdentifier[] = "#";
373const char kCheckedIdentifier[] = "*";
[email protected]3db130e2014-03-27 08:14:48374
375bool OutsideMultiClickRadius(const WebPoint& a, const WebPoint& b) {
376 return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) >
377 kMultipleClickRadiusPixels * kMultipleClickRadiusPixels;
378}
379
[email protected]f9634a82014-08-05 13:10:19380void PopulateCustomItems(const WebVector<WebMenuItemInfo>& customItems,
381 const std::string& prefix, std::vector<std::string>* strings) {
382 for (size_t i = 0; i < customItems.size(); ++i) {
sanjoy.pala62675e2014-11-27 00:47:29383 std::string prefixCopy = prefix;
384 if (!customItems[i].enabled)
385 prefixCopy = kDisabledIdentifier + prefix;
386 if (customItems[i].checked)
387 prefixCopy = kCheckedIdentifier + prefix;
sanjoy.pal362c3252014-08-26 08:07:08388 if (customItems[i].type == blink::WebMenuItemInfo::Separator) {
sanjoy.pala62675e2014-11-27 00:47:29389 strings->push_back(prefixCopy + kSeparatorIdentifier);
sanjoy.pal362c3252014-08-26 08:07:08390 } else if (customItems[i].type == blink::WebMenuItemInfo::SubMenu) {
sanjoy.pala62675e2014-11-27 00:47:29391 strings->push_back(prefixCopy + customItems[i].label.utf8() +
sanjoy.pal2adb5c52015-01-13 11:26:49392 customItems[i].icon.utf8() + kSubMenuIdentifier);
sanjoy.pala62675e2014-11-27 00:47:29393 PopulateCustomItems(customItems[i].subMenuItems, prefixCopy +
[email protected]f9634a82014-08-05 13:10:19394 kSubMenuDepthIdentifier, strings);
395 } else {
sanjoy.pal2adb5c52015-01-13 11:26:49396 strings->push_back(prefixCopy + customItems[i].label.utf8() +
397 customItems[i].icon.utf8());
[email protected]f9634a82014-08-05 13:10:19398 }
399 }
400}
401
[email protected]3db130e2014-03-27 08:14:48402// Because actual context menu is implemented by the browser side,
403// this function does only what LayoutTests are expecting:
404// - Many test checks the count of items. So returning non-zero value makes
405// sense.
406// - Some test compares the count before and after some action. So changing the
407// count based on flags also makes sense. This function is doing such for some
408// flags.
409// - Some test even checks actual string content. So providing it would be also
410// helpful.
411std::vector<std::string> MakeMenuItemStringsFor(
412 WebContextMenuData* context_menu,
[email protected]79ecada2014-05-04 05:16:16413 WebTestDelegate* delegate) {
[email protected]3db130e2014-03-27 08:14:48414 // These constants are based on Safari's context menu because tests are made
415 // for it.
416 static const char* kNonEditableMenuStrings[] = {
417 "Back",
418 "Reload Page",
419 "Open in Dashbaord",
420 "<separator>",
421 "View Source",
422 "Save Page As",
423 "Print Page",
424 "Inspect Element",
425 0
426 };
427 static const char* kEditableMenuStrings[] = {
428 "Cut",
429 "Copy",
430 "<separator>",
431 "Paste",
432 "Spelling and Grammar",
433 "Substitutions, Transformations",
434 "Font",
435 "Speech",
436 "Paragraph Direction",
437 "<separator>",
438 0
439 };
440
441 // This is possible because mouse events are cancelleable.
442 if (!context_menu)
443 return std::vector<std::string>();
444
445 std::vector<std::string> strings;
446
[email protected]f9634a82014-08-05 13:10:19447 // Populate custom menu items if provided by blink.
448 PopulateCustomItems(context_menu->customItems, "", &strings);
449
[email protected]3db130e2014-03-27 08:14:48450 if (context_menu->isEditable) {
451 for (const char** item = kEditableMenuStrings; *item; ++item) {
452 strings.push_back(*item);
453 }
454 WebVector<WebString> suggestions;
[email protected]f656a652014-07-25 12:19:52455 MockSpellCheck::FillSuggestionList(context_menu->misspelledWord,
456 &suggestions);
[email protected]3db130e2014-03-27 08:14:48457 for (size_t i = 0; i < suggestions.size(); ++i) {
458 strings.push_back(suggestions[i].utf8());
459 }
460 } else {
461 for (const char** item = kNonEditableMenuStrings; *item; ++item) {
462 strings.push_back(*item);
463 }
464 }
465
466 return strings;
467}
468
469// How much we should scroll per event - the value here is chosen to match the
470// WebKit impl and layout test results.
471const float kScrollbarPixelsPerTick = 40.0f;
472
[email protected]3db130e2014-03-27 08:14:48473// Get the edit command corresponding to a keyboard event.
474// Returns true if the specified event corresponds to an edit command, the name
475// of the edit command will be stored in |*name|.
476bool GetEditCommand(const WebKeyboardEvent& event, std::string* name) {
477#if defined(OS_MACOSX)
478// We only cares about Left,Right,Up,Down keys with Command or Command+Shift
479// modifiers. These key events correspond to some special movement and
480// selection editor commands. These keys will be marked as system key, which
481// prevents them from being handled. Thus they must be handled specially.
dtapuska8c4dae12017-01-13 00:23:06482 if ((event.modifiers() & ~WebKeyboardEvent::ShiftKey) !=
[email protected]3db130e2014-03-27 08:14:48483 WebKeyboardEvent::MetaKey)
484 return false;
485
486 switch (event.windowsKeyCode) {
[email protected]a731f1a92014-04-17 19:31:06487 case ui::VKEY_LEFT:
[email protected]3db130e2014-03-27 08:14:48488 *name = "MoveToBeginningOfLine";
489 break;
[email protected]a731f1a92014-04-17 19:31:06490 case ui::VKEY_RIGHT:
[email protected]3db130e2014-03-27 08:14:48491 *name = "MoveToEndOfLine";
492 break;
[email protected]a731f1a92014-04-17 19:31:06493 case ui::VKEY_UP:
[email protected]3db130e2014-03-27 08:14:48494 *name = "MoveToBeginningOfDocument";
495 break;
[email protected]a731f1a92014-04-17 19:31:06496 case ui::VKEY_DOWN:
[email protected]3db130e2014-03-27 08:14:48497 *name = "MoveToEndOfDocument";
498 break;
499 default:
500 return false;
501 }
502
dtapuska8c4dae12017-01-13 00:23:06503 if (event.modifiers() & WebKeyboardEvent::ShiftKey)
[email protected]3db130e2014-03-27 08:14:48504 name->append("AndModifySelection");
505
506 return true;
507#else
508 return false;
509#endif
510}
511
[email protected]a731f1a92014-04-17 19:31:06512bool IsSystemKeyEvent(const WebKeyboardEvent& event) {
513#if defined(OS_MACOSX)
dtapuska8c4dae12017-01-13 00:23:06514 return event.modifiers() & WebInputEvent::MetaKey &&
515 event.windowsKeyCode != ui::VKEY_B &&
516 event.windowsKeyCode != ui::VKEY_I;
[email protected]a731f1a92014-04-17 19:31:06517#else
dtapuska8c4dae12017-01-13 00:23:06518 return !!(event.modifiers() & WebInputEvent::AltKey);
[email protected]a731f1a92014-04-17 19:31:06519#endif
520}
521
dtapuskab1c5ece2016-01-18 18:18:02522bool GetScrollUnits(gin::Arguments* args, WebGestureEvent::ScrollUnits* units) {
523 std::string units_string;
524 if (!args->PeekNext().IsEmpty()) {
525 if (args->PeekNext()->IsString())
526 args->GetNext(&units_string);
527 if (units_string == "Page") {
528 *units = WebGestureEvent::Page;
529 return true;
530 } else if (units_string == "Pixels") {
531 *units = WebGestureEvent::Pixels;
532 return true;
533 } else if (units_string == "PrecisePixels") {
534 *units = WebGestureEvent::PrecisePixels;
535 return true;
536 } else {
537 args->ThrowError();
538 return false;
539 }
540 } else {
541 *units = WebGestureEvent::PrecisePixels;
542 return true;
543 }
544}
545
tdresser3a1c9722015-02-13 15:44:53546const char* kSourceDeviceStringTouchpad = "touchpad";
547const char* kSourceDeviceStringTouchscreen = "touchscreen";
548
[email protected]3db130e2014-03-27 08:14:48549} // namespace
550
551class EventSenderBindings : public gin::Wrappable<EventSenderBindings> {
552 public:
553 static gin::WrapperInfo kWrapperInfo;
554
555 static void Install(base::WeakPtr<EventSender> sender,
lukasza335bb762016-04-22 16:44:03556 blink::WebLocalFrame* frame);
[email protected]3db130e2014-03-27 08:14:48557
558 private:
559 explicit EventSenderBindings(base::WeakPtr<EventSender> sender);
dchenge933b3e2014-10-21 11:44:09560 ~EventSenderBindings() override;
[email protected]3db130e2014-03-27 08:14:48561
562 // gin::Wrappable:
dchenge933b3e2014-10-21 11:44:09563 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
anand.ratn449f39a42014-10-06 13:45:57564 v8::Isolate* isolate) override;
[email protected]3db130e2014-03-27 08:14:48565
566 // Bound methods:
567 void EnableDOMUIEventLogging();
568 void FireKeyboardEventsToElement();
569 void ClearKillRing();
570 std::vector<std::string> ContextClick();
571 void TextZoomIn();
572 void TextZoomOut();
573 void ZoomPageIn();
574 void ZoomPageOut();
[email protected]d160488f2014-05-06 17:03:01575 void SetPageZoomFactor(double factor);
[email protected]3db130e2014-03-27 08:14:48576 void ClearTouchPoints();
577 void ReleaseTouchPoint(unsigned index);
e.hakkinen80033922015-07-31 08:41:35578 void UpdateTouchPoint(unsigned index,
579 double x,
580 double y,
581 gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48582 void CancelTouchPoint(unsigned index);
583 void SetTouchModifier(const std::string& key_name, bool set_mask);
[email protected]ace1cd502014-04-24 21:05:30584 void SetTouchCancelable(bool cancelable);
[email protected]3db130e2014-03-27 08:14:48585 void DumpFilenameBeingDragged();
586 void GestureFlingCancel();
tdresser3a1c9722015-02-13 15:44:53587 void GestureFlingStart(float x,
588 float y,
589 float velocity_x,
590 float velocity_y,
591 gin::Arguments* args);
tdresserd7bba522016-02-19 22:40:13592 bool IsFlinging() const;
[email protected]3db130e2014-03-27 08:14:48593 void GestureScrollFirstPoint(int x, int y);
rbyers709aa1e2016-05-12 04:44:06594 void TouchStart(gin::Arguments* args);
595 void TouchMove(gin::Arguments* args);
596 void TouchCancel(gin::Arguments* args);
597 void TouchEnd(gin::Arguments* args);
mustaqb3c44a02016-04-19 18:49:05598 void NotifyStartOfTouchScroll();
[email protected]3db130e2014-03-27 08:14:48599 void LeapForward(int milliseconds);
majidvpbfabb0712015-10-02 16:30:00600 double LastEventTimestamp();
[email protected]3db130e2014-03-27 08:14:48601 void BeginDragWithFiles(const std::vector<std::string>& files);
e.hakkinen80033922015-07-31 08:41:35602 void AddTouchPoint(double x, double y, gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48603 void GestureScrollBegin(gin::Arguments* args);
604 void GestureScrollEnd(gin::Arguments* args);
605 void GestureScrollUpdate(gin::Arguments* args);
ccameronb81b8072015-01-30 00:54:49606 void GesturePinchBegin(gin::Arguments* args);
607 void GesturePinchEnd(gin::Arguments* args);
608 void GesturePinchUpdate(gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48609 void GestureTap(gin::Arguments* args);
610 void GestureTapDown(gin::Arguments* args);
611 void GestureShowPress(gin::Arguments* args);
612 void GestureTapCancel(gin::Arguments* args);
613 void GestureLongPress(gin::Arguments* args);
614 void GestureLongTap(gin::Arguments* args);
615 void GestureTwoFingerTap(gin::Arguments* args);
616 void ContinuousMouseScrollBy(gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48617 void MouseMoveTo(gin::Arguments* args);
myid.shin12c7fea22015-03-06 02:31:24618 void MouseLeave();
[email protected]3db130e2014-03-27 08:14:48619 void MouseScrollBy(gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48620 void ScheduleAsynchronousClick(gin::Arguments* args);
621 void ScheduleAsynchronousKeyDown(gin::Arguments* args);
622 void MouseDown(gin::Arguments* args);
623 void MouseUp(gin::Arguments* args);
mustaq21aed4e2015-12-15 21:47:21624 void SetMouseButtonState(gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48625 void KeyDown(gin::Arguments* args);
626
627 // Binding properties:
628 bool ForceLayoutOnEvents() const;
629 void SetForceLayoutOnEvents(bool force);
630 bool IsDragMode() const;
631 void SetIsDragMode(bool drag_mode);
632
633#if defined(OS_WIN)
634 int WmKeyDown() const;
635 void SetWmKeyDown(int key_down);
636
637 int WmKeyUp() const;
638 void SetWmKeyUp(int key_up);
639
640 int WmChar() const;
641 void SetWmChar(int wm_char);
642
643 int WmDeadChar() const;
644 void SetWmDeadChar(int dead_char);
645
646 int WmSysKeyDown() const;
647 void SetWmSysKeyDown(int key_down);
648
649 int WmSysKeyUp() const;
650 void SetWmSysKeyUp(int key_up);
651
652 int WmSysChar() const;
653 void SetWmSysChar(int sys_char);
654
655 int WmSysDeadChar() const;
656 void SetWmSysDeadChar(int sys_dead_char);
657#endif
658
659 base::WeakPtr<EventSender> sender_;
660
661 DISALLOW_COPY_AND_ASSIGN(EventSenderBindings);
662};
663
664gin::WrapperInfo EventSenderBindings::kWrapperInfo = {gin::kEmbedderNativeGin};
665
666EventSenderBindings::EventSenderBindings(base::WeakPtr<EventSender> sender)
667 : sender_(sender) {
668}
669
670EventSenderBindings::~EventSenderBindings() {}
671
672// static
673void EventSenderBindings::Install(base::WeakPtr<EventSender> sender,
lukasza335bb762016-04-22 16:44:03674 WebLocalFrame* frame) {
[email protected]3db130e2014-03-27 08:14:48675 v8::Isolate* isolate = blink::mainThreadIsolate();
676 v8::HandleScope handle_scope(isolate);
deepak.s750d68f2015-04-30 07:32:41677 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
[email protected]3db130e2014-03-27 08:14:48678 if (context.IsEmpty())
679 return;
680
681 v8::Context::Scope context_scope(context);
682
683 gin::Handle<EventSenderBindings> bindings =
684 gin::CreateHandle(isolate, new EventSenderBindings(sender));
[email protected]ad4d2032014-04-28 13:50:59685 if (bindings.IsEmpty())
686 return;
deepak.s750d68f2015-04-30 07:32:41687 v8::Local<v8::Object> global = context->Global();
[email protected]3db130e2014-03-27 08:14:48688 global->Set(gin::StringToV8(isolate, "eventSender"), bindings.ToV8());
689}
690
691gin::ObjectTemplateBuilder
692EventSenderBindings::GetObjectTemplateBuilder(v8::Isolate* isolate) {
693 return gin::Wrappable<EventSenderBindings>::GetObjectTemplateBuilder(isolate)
694 .SetMethod("enableDOMUIEventLogging",
695 &EventSenderBindings::EnableDOMUIEventLogging)
696 .SetMethod("fireKeyboardEventsToElement",
697 &EventSenderBindings::FireKeyboardEventsToElement)
698 .SetMethod("clearKillRing", &EventSenderBindings::ClearKillRing)
699 .SetMethod("contextClick", &EventSenderBindings::ContextClick)
700 .SetMethod("textZoomIn", &EventSenderBindings::TextZoomIn)
701 .SetMethod("textZoomOut", &EventSenderBindings::TextZoomOut)
702 .SetMethod("zoomPageIn", &EventSenderBindings::ZoomPageIn)
703 .SetMethod("zoomPageOut", &EventSenderBindings::ZoomPageOut)
[email protected]b32fe542014-04-30 08:42:06704 .SetMethod("setPageZoomFactor", &EventSenderBindings::SetPageZoomFactor)
[email protected]3db130e2014-03-27 08:14:48705 .SetMethod("clearTouchPoints", &EventSenderBindings::ClearTouchPoints)
706 .SetMethod("releaseTouchPoint", &EventSenderBindings::ReleaseTouchPoint)
707 .SetMethod("updateTouchPoint", &EventSenderBindings::UpdateTouchPoint)
708 .SetMethod("cancelTouchPoint", &EventSenderBindings::CancelTouchPoint)
709 .SetMethod("setTouchModifier", &EventSenderBindings::SetTouchModifier)
[email protected]ace1cd502014-04-24 21:05:30710 .SetMethod("setTouchCancelable", &EventSenderBindings::SetTouchCancelable)
[email protected]3db130e2014-03-27 08:14:48711 .SetMethod("dumpFilenameBeingDragged",
712 &EventSenderBindings::DumpFilenameBeingDragged)
713 .SetMethod("gestureFlingCancel", &EventSenderBindings::GestureFlingCancel)
714 .SetMethod("gestureFlingStart", &EventSenderBindings::GestureFlingStart)
tdresserd7bba522016-02-19 22:40:13715 .SetMethod("isFlinging", &EventSenderBindings::IsFlinging)
[email protected]3db130e2014-03-27 08:14:48716 .SetMethod("gestureScrollFirstPoint",
717 &EventSenderBindings::GestureScrollFirstPoint)
718 .SetMethod("touchStart", &EventSenderBindings::TouchStart)
719 .SetMethod("touchMove", &EventSenderBindings::TouchMove)
720 .SetMethod("touchCancel", &EventSenderBindings::TouchCancel)
721 .SetMethod("touchEnd", &EventSenderBindings::TouchEnd)
mustaqb3c44a02016-04-19 18:49:05722 .SetMethod("notifyStartOfTouchScroll",
723 &EventSenderBindings::NotifyStartOfTouchScroll)
[email protected]3db130e2014-03-27 08:14:48724 .SetMethod("leapForward", &EventSenderBindings::LeapForward)
majidvpbfabb0712015-10-02 16:30:00725 .SetMethod("lastEventTimestamp", &EventSenderBindings::LastEventTimestamp)
[email protected]3db130e2014-03-27 08:14:48726 .SetMethod("beginDragWithFiles", &EventSenderBindings::BeginDragWithFiles)
727 .SetMethod("addTouchPoint", &EventSenderBindings::AddTouchPoint)
[email protected]3db130e2014-03-27 08:14:48728 .SetMethod("gestureScrollBegin", &EventSenderBindings::GestureScrollBegin)
729 .SetMethod("gestureScrollEnd", &EventSenderBindings::GestureScrollEnd)
730 .SetMethod("gestureScrollUpdate",
731 &EventSenderBindings::GestureScrollUpdate)
ccameronb81b8072015-01-30 00:54:49732 .SetMethod("gesturePinchBegin", &EventSenderBindings::GesturePinchBegin)
733 .SetMethod("gesturePinchEnd", &EventSenderBindings::GesturePinchEnd)
734 .SetMethod("gesturePinchUpdate", &EventSenderBindings::GesturePinchUpdate)
[email protected]3db130e2014-03-27 08:14:48735 .SetMethod("gestureTap", &EventSenderBindings::GestureTap)
736 .SetMethod("gestureTapDown", &EventSenderBindings::GestureTapDown)
737 .SetMethod("gestureShowPress", &EventSenderBindings::GestureShowPress)
738 .SetMethod("gestureTapCancel", &EventSenderBindings::GestureTapCancel)
739 .SetMethod("gestureLongPress", &EventSenderBindings::GestureLongPress)
740 .SetMethod("gestureLongTap", &EventSenderBindings::GestureLongTap)
741 .SetMethod("gestureTwoFingerTap",
742 &EventSenderBindings::GestureTwoFingerTap)
743 .SetMethod("continuousMouseScrollBy",
744 &EventSenderBindings::ContinuousMouseScrollBy)
[email protected]3db130e2014-03-27 08:14:48745 .SetMethod("keyDown", &EventSenderBindings::KeyDown)
746 .SetMethod("mouseDown", &EventSenderBindings::MouseDown)
747 .SetMethod("mouseMoveTo", &EventSenderBindings::MouseMoveTo)
myid.shin12c7fea22015-03-06 02:31:24748 .SetMethod("mouseLeave", &EventSenderBindings::MouseLeave)
[email protected]3db130e2014-03-27 08:14:48749 .SetMethod("mouseScrollBy", &EventSenderBindings::MouseScrollBy)
750 .SetMethod("mouseUp", &EventSenderBindings::MouseUp)
mustaq21aed4e2015-12-15 21:47:21751 .SetMethod("setMouseButtonState",
752 &EventSenderBindings::SetMouseButtonState)
[email protected]3db130e2014-03-27 08:14:48753 .SetMethod("scheduleAsynchronousClick",
754 &EventSenderBindings::ScheduleAsynchronousClick)
755 .SetMethod("scheduleAsynchronousKeyDown",
756 &EventSenderBindings::ScheduleAsynchronousKeyDown)
757 .SetProperty("forceLayoutOnEvents",
758 &EventSenderBindings::ForceLayoutOnEvents,
759 &EventSenderBindings::SetForceLayoutOnEvents)
[email protected]3db130e2014-03-27 08:14:48760#if defined(OS_WIN)
mustaq96985f722015-06-30 21:41:53761 .SetProperty("WM_KEYDOWN", &EventSenderBindings::WmKeyDown,
[email protected]3db130e2014-03-27 08:14:48762 &EventSenderBindings::SetWmKeyDown)
mustaq96985f722015-06-30 21:41:53763 .SetProperty("WM_KEYUP", &EventSenderBindings::WmKeyUp,
[email protected]3db130e2014-03-27 08:14:48764 &EventSenderBindings::SetWmKeyUp)
mustaq96985f722015-06-30 21:41:53765 .SetProperty("WM_CHAR", &EventSenderBindings::WmChar,
[email protected]3db130e2014-03-27 08:14:48766 &EventSenderBindings::SetWmChar)
mustaq96985f722015-06-30 21:41:53767 .SetProperty("WM_DEADCHAR", &EventSenderBindings::WmDeadChar,
[email protected]3db130e2014-03-27 08:14:48768 &EventSenderBindings::SetWmDeadChar)
mustaq96985f722015-06-30 21:41:53769 .SetProperty("WM_SYSKEYDOWN", &EventSenderBindings::WmSysKeyDown,
[email protected]3db130e2014-03-27 08:14:48770 &EventSenderBindings::SetWmSysKeyDown)
mustaq96985f722015-06-30 21:41:53771 .SetProperty("WM_SYSKEYUP", &EventSenderBindings::WmSysKeyUp,
[email protected]3db130e2014-03-27 08:14:48772 &EventSenderBindings::SetWmSysKeyUp)
mustaq96985f722015-06-30 21:41:53773 .SetProperty("WM_SYSCHAR", &EventSenderBindings::WmSysChar,
[email protected]3db130e2014-03-27 08:14:48774 &EventSenderBindings::SetWmSysChar)
mustaq96985f722015-06-30 21:41:53775 .SetProperty("WM_SYSDEADCHAR", &EventSenderBindings::WmSysDeadChar,
thestigfd11ffe2015-12-30 19:25:45776 &EventSenderBindings::SetWmSysDeadChar)
[email protected]3db130e2014-03-27 08:14:48777#endif
thestigfd11ffe2015-12-30 19:25:45778 .SetProperty("dragMode", &EventSenderBindings::IsDragMode,
779 &EventSenderBindings::SetIsDragMode);
[email protected]3db130e2014-03-27 08:14:48780}
781
782void EventSenderBindings::EnableDOMUIEventLogging() {
783 if (sender_)
784 sender_->EnableDOMUIEventLogging();
785}
786
787void EventSenderBindings::FireKeyboardEventsToElement() {
788 if (sender_)
789 sender_->FireKeyboardEventsToElement();
790}
791
792void EventSenderBindings::ClearKillRing() {
793 if (sender_)
794 sender_->ClearKillRing();
795}
796
797std::vector<std::string> EventSenderBindings::ContextClick() {
798 if (sender_)
799 return sender_->ContextClick();
800 return std::vector<std::string>();
801}
802
803void EventSenderBindings::TextZoomIn() {
804 if (sender_)
805 sender_->TextZoomIn();
806}
807
808void EventSenderBindings::TextZoomOut() {
809 if (sender_)
810 sender_->TextZoomOut();
811}
812
813void EventSenderBindings::ZoomPageIn() {
814 if (sender_)
815 sender_->ZoomPageIn();
816}
817
818void EventSenderBindings::ZoomPageOut() {
819 if (sender_)
820 sender_->ZoomPageOut();
821}
822
[email protected]d160488f2014-05-06 17:03:01823void EventSenderBindings::SetPageZoomFactor(double factor) {
824 if (sender_)
825 sender_->SetPageZoomFactor(factor);
[email protected]b32fe542014-04-30 08:42:06826}
827
[email protected]3db130e2014-03-27 08:14:48828void EventSenderBindings::ClearTouchPoints() {
829 if (sender_)
830 sender_->ClearTouchPoints();
831}
832
833void EventSenderBindings::ReleaseTouchPoint(unsigned index) {
834 if (sender_)
835 sender_->ReleaseTouchPoint(index);
836}
837
e.hakkinen80033922015-07-31 08:41:35838void EventSenderBindings::UpdateTouchPoint(unsigned index,
839 double x,
840 double y,
841 gin::Arguments* args) {
jochen73e711c2015-06-03 10:01:46842 if (sender_) {
843 sender_->UpdateTouchPoint(index, static_cast<float>(x),
e.hakkinen80033922015-07-31 08:41:35844 static_cast<float>(y), args);
jochen73e711c2015-06-03 10:01:46845 }
[email protected]3db130e2014-03-27 08:14:48846}
847
848void EventSenderBindings::CancelTouchPoint(unsigned index) {
849 if (sender_)
850 sender_->CancelTouchPoint(index);
851}
852
853void EventSenderBindings::SetTouchModifier(const std::string& key_name,
854 bool set_mask) {
855 if (sender_)
856 sender_->SetTouchModifier(key_name, set_mask);
857}
858
[email protected]ace1cd502014-04-24 21:05:30859void EventSenderBindings::SetTouchCancelable(bool cancelable) {
860 if (sender_)
861 sender_->SetTouchCancelable(cancelable);
862}
863
[email protected]3db130e2014-03-27 08:14:48864void EventSenderBindings::DumpFilenameBeingDragged() {
865 if (sender_)
866 sender_->DumpFilenameBeingDragged();
867}
868
869void EventSenderBindings::GestureFlingCancel() {
870 if (sender_)
871 sender_->GestureFlingCancel();
872}
873
874void EventSenderBindings::GestureFlingStart(float x,
875 float y,
876 float velocity_x,
tdresser3a1c9722015-02-13 15:44:53877 float velocity_y,
878 gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:48879 if (sender_)
tdresser3a1c9722015-02-13 15:44:53880 sender_->GestureFlingStart(x, y, velocity_x, velocity_y, args);
[email protected]3db130e2014-03-27 08:14:48881}
882
tdresserd7bba522016-02-19 22:40:13883bool EventSenderBindings::IsFlinging() const {
884 if (sender_)
885 return sender_->IsFlinging();
886 return false;
887}
888
[email protected]3db130e2014-03-27 08:14:48889void EventSenderBindings::GestureScrollFirstPoint(int x, int y) {
890 if (sender_)
891 sender_->GestureScrollFirstPoint(x, y);
892}
893
rbyers709aa1e2016-05-12 04:44:06894void EventSenderBindings::TouchStart(gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:48895 if (sender_)
rbyers709aa1e2016-05-12 04:44:06896 sender_->TouchStart(args);
[email protected]3db130e2014-03-27 08:14:48897}
898
rbyers709aa1e2016-05-12 04:44:06899void EventSenderBindings::TouchMove(gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:48900 if (sender_)
rbyers709aa1e2016-05-12 04:44:06901 sender_->TouchMove(args);
[email protected]3db130e2014-03-27 08:14:48902}
903
rbyers709aa1e2016-05-12 04:44:06904void EventSenderBindings::TouchCancel(gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:48905 if (sender_)
rbyers709aa1e2016-05-12 04:44:06906 sender_->TouchCancel(args);
[email protected]3db130e2014-03-27 08:14:48907}
908
rbyers709aa1e2016-05-12 04:44:06909void EventSenderBindings::TouchEnd(gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:48910 if (sender_)
rbyers709aa1e2016-05-12 04:44:06911 sender_->TouchEnd(args);
[email protected]3db130e2014-03-27 08:14:48912}
913
mustaqb3c44a02016-04-19 18:49:05914void EventSenderBindings::NotifyStartOfTouchScroll() {
915 if (sender_)
916 sender_->NotifyStartOfTouchScroll();
917}
918
[email protected]3db130e2014-03-27 08:14:48919void EventSenderBindings::LeapForward(int milliseconds) {
920 if (sender_)
921 sender_->LeapForward(milliseconds);
922}
923
majidvpbfabb0712015-10-02 16:30:00924double EventSenderBindings::LastEventTimestamp() {
925 if (sender_)
926 return sender_->last_event_timestamp();
927 return 0;
928}
929
[email protected]3db130e2014-03-27 08:14:48930void EventSenderBindings::BeginDragWithFiles(
931 const std::vector<std::string>& files) {
932 if (sender_)
933 sender_->BeginDragWithFiles(files);
934}
935
e.hakkinen80033922015-07-31 08:41:35936void EventSenderBindings::AddTouchPoint(double x,
937 double y,
938 gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:48939 if (sender_)
e.hakkinen80033922015-07-31 08:41:35940 sender_->AddTouchPoint(static_cast<float>(x), static_cast<float>(y), args);
[email protected]3db130e2014-03-27 08:14:48941}
942
[email protected]3db130e2014-03-27 08:14:48943void EventSenderBindings::GestureScrollBegin(gin::Arguments* args) {
944 if (sender_)
945 sender_->GestureScrollBegin(args);
946}
947
948void EventSenderBindings::GestureScrollEnd(gin::Arguments* args) {
949 if (sender_)
950 sender_->GestureScrollEnd(args);
951}
952
953void EventSenderBindings::GestureScrollUpdate(gin::Arguments* args) {
954 if (sender_)
955 sender_->GestureScrollUpdate(args);
956}
957
ccameronb81b8072015-01-30 00:54:49958void EventSenderBindings::GesturePinchBegin(gin::Arguments* args) {
959 if (sender_)
960 sender_->GesturePinchBegin(args);
961}
962
963void EventSenderBindings::GesturePinchEnd(gin::Arguments* args) {
964 if (sender_)
965 sender_->GesturePinchEnd(args);
966}
967
968void EventSenderBindings::GesturePinchUpdate(gin::Arguments* args) {
969 if (sender_)
970 sender_->GesturePinchUpdate(args);
971}
972
[email protected]3db130e2014-03-27 08:14:48973void EventSenderBindings::GestureTap(gin::Arguments* args) {
974 if (sender_)
975 sender_->GestureTap(args);
976}
977
978void EventSenderBindings::GestureTapDown(gin::Arguments* args) {
979 if (sender_)
980 sender_->GestureTapDown(args);
981}
982
983void EventSenderBindings::GestureShowPress(gin::Arguments* args) {
984 if (sender_)
985 sender_->GestureShowPress(args);
986}
987
988void EventSenderBindings::GestureTapCancel(gin::Arguments* args) {
989 if (sender_)
990 sender_->GestureTapCancel(args);
991}
992
993void EventSenderBindings::GestureLongPress(gin::Arguments* args) {
994 if (sender_)
995 sender_->GestureLongPress(args);
996}
997
998void EventSenderBindings::GestureLongTap(gin::Arguments* args) {
999 if (sender_)
1000 sender_->GestureLongTap(args);
1001}
1002
1003void EventSenderBindings::GestureTwoFingerTap(gin::Arguments* args) {
1004 if (sender_)
1005 sender_->GestureTwoFingerTap(args);
1006}
1007
1008void EventSenderBindings::ContinuousMouseScrollBy(gin::Arguments* args) {
1009 if (sender_)
dtapuska43f18e9e2016-03-20 20:21:301010 sender_->MouseScrollBy(args, EventSender::MouseScrollType::PIXEL);
[email protected]3db130e2014-03-27 08:14:481011}
1012
[email protected]3db130e2014-03-27 08:14:481013void EventSenderBindings::MouseMoveTo(gin::Arguments* args) {
1014 if (sender_)
1015 sender_->MouseMoveTo(args);
1016}
1017
myid.shin12c7fea22015-03-06 02:31:241018void EventSenderBindings::MouseLeave() {
1019 if (sender_)
1020 sender_->MouseLeave();
1021}
1022
[email protected]3db130e2014-03-27 08:14:481023void EventSenderBindings::MouseScrollBy(gin::Arguments* args) {
1024 if (sender_)
dtapuska43f18e9e2016-03-20 20:21:301025 sender_->MouseScrollBy(args, EventSender::MouseScrollType::TICK);
[email protected]3db130e2014-03-27 08:14:481026}
1027
[email protected]3db130e2014-03-27 08:14:481028void EventSenderBindings::ScheduleAsynchronousClick(gin::Arguments* args) {
1029 if (!sender_)
1030 return;
1031
1032 int button_number = 0;
1033 int modifiers = 0;
1034 if (!args->PeekNext().IsEmpty()) {
1035 args->GetNext(&button_number);
1036 if (!args->PeekNext().IsEmpty())
bashidbd2ef9bb2015-06-02 01:39:321037 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
[email protected]3db130e2014-03-27 08:14:481038 }
1039 sender_->ScheduleAsynchronousClick(button_number, modifiers);
1040}
1041
1042void EventSenderBindings::ScheduleAsynchronousKeyDown(gin::Arguments* args) {
1043 if (!sender_)
1044 return;
1045
1046 std::string code_str;
1047 int modifiers = 0;
1048 int location = DOMKeyLocationStandard;
1049 args->GetNext(&code_str);
1050 if (!args->PeekNext().IsEmpty()) {
deepak.s750d68f2015-04-30 07:32:411051 v8::Local<v8::Value> value;
[email protected]3db130e2014-03-27 08:14:481052 args->GetNext(&value);
bashidbd2ef9bb2015-06-02 01:39:321053 modifiers = GetKeyModifiersFromV8(args->isolate(), value);
[email protected]3db130e2014-03-27 08:14:481054 if (!args->PeekNext().IsEmpty())
1055 args->GetNext(&location);
1056 }
1057 sender_->ScheduleAsynchronousKeyDown(code_str, modifiers,
1058 static_cast<KeyLocationCode>(location));
1059}
1060
1061void EventSenderBindings::MouseDown(gin::Arguments* args) {
1062 if (!sender_)
1063 return;
1064
1065 int button_number = 0;
1066 int modifiers = 0;
1067 if (!args->PeekNext().IsEmpty()) {
nzolghadr43146032016-04-11 15:33:381068 if (!args->GetNext(&button_number)) {
1069 args->ThrowError();
1070 return;
1071 }
1072 if (!args->PeekNext().IsEmpty()) {
bashidbd2ef9bb2015-06-02 01:39:321073 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
nzolghadr43146032016-04-11 15:33:381074 args->Skip();
1075 }
[email protected]3db130e2014-03-27 08:14:481076 }
nzolghadr43146032016-04-11 15:33:381077
mustaqabca6ff2016-06-09 17:29:531078 WebPointerProperties::PointerType pointerType =
1079 WebPointerProperties::PointerType::Mouse;
1080 int pointerId = 0;
1081 float pressure = 0;
1082 int tiltX = 0;
1083 int tiltY = 0;
1084 if (!getMousePenPointerProperties(args, pointerType, pointerId, pressure,
1085 tiltX, tiltY))
nzolghadr43146032016-04-11 15:33:381086 return;
1087
mustaqabca6ff2016-06-09 17:29:531088 sender_->PointerDown(button_number, modifiers, pointerType, pointerId,
1089 pressure, tiltX, tiltY);
[email protected]3db130e2014-03-27 08:14:481090}
1091
1092void EventSenderBindings::MouseUp(gin::Arguments* args) {
1093 if (!sender_)
1094 return;
1095
1096 int button_number = 0;
1097 int modifiers = 0;
1098 if (!args->PeekNext().IsEmpty()) {
nzolghadr43146032016-04-11 15:33:381099 if (!args->GetNext(&button_number)) {
1100 args->ThrowError();
1101 return;
1102 }
1103 if (!args->PeekNext().IsEmpty()) {
bashidbd2ef9bb2015-06-02 01:39:321104 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
nzolghadr43146032016-04-11 15:33:381105 args->Skip();
1106 }
[email protected]3db130e2014-03-27 08:14:481107 }
nzolghadr43146032016-04-11 15:33:381108
mustaqabca6ff2016-06-09 17:29:531109 WebPointerProperties::PointerType pointerType =
1110 WebPointerProperties::PointerType::Mouse;
1111 int pointerId = 0;
1112 float pressure = 0;
1113 int tiltX = 0;
1114 int tiltY = 0;
1115 if (!getMousePenPointerProperties(args, pointerType, pointerId, pressure,
1116 tiltX, tiltY))
nzolghadr43146032016-04-11 15:33:381117 return;
1118
mustaqabca6ff2016-06-09 17:29:531119 sender_->PointerUp(button_number, modifiers, pointerType, pointerId, pressure,
1120 tiltX, tiltY);
[email protected]3db130e2014-03-27 08:14:481121}
1122
mustaq21aed4e2015-12-15 21:47:211123void EventSenderBindings::SetMouseButtonState(gin::Arguments* args) {
1124 if (!sender_)
1125 return;
1126
1127 int button_number;
1128 if (!args->GetNext(&button_number)) {
1129 args->ThrowError();
1130 return;
1131 }
1132
thestigfd11ffe2015-12-30 19:25:451133 int modifiers = -1; // Default to the modifier implied by button_number
mustaq21aed4e2015-12-15 21:47:211134 if (!args->PeekNext().IsEmpty()) {
1135 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
1136 }
1137
1138 sender_->SetMouseButtonState(button_number, modifiers);
1139}
1140
[email protected]3db130e2014-03-27 08:14:481141void EventSenderBindings::KeyDown(gin::Arguments* args) {
1142 if (!sender_)
1143 return;
1144
1145 std::string code_str;
1146 int modifiers = 0;
1147 int location = DOMKeyLocationStandard;
1148 args->GetNext(&code_str);
1149 if (!args->PeekNext().IsEmpty()) {
deepak.s750d68f2015-04-30 07:32:411150 v8::Local<v8::Value> value;
[email protected]3db130e2014-03-27 08:14:481151 args->GetNext(&value);
bashidbd2ef9bb2015-06-02 01:39:321152 modifiers = GetKeyModifiersFromV8(args->isolate(), value);
[email protected]3db130e2014-03-27 08:14:481153 if (!args->PeekNext().IsEmpty())
1154 args->GetNext(&location);
1155 }
1156 sender_->KeyDown(code_str, modifiers, static_cast<KeyLocationCode>(location));
1157}
1158
1159bool EventSenderBindings::ForceLayoutOnEvents() const {
1160 if (sender_)
1161 return sender_->force_layout_on_events();
1162 return false;
1163}
1164
1165void EventSenderBindings::SetForceLayoutOnEvents(bool force) {
1166 if (sender_)
1167 sender_->set_force_layout_on_events(force);
1168}
1169
1170bool EventSenderBindings::IsDragMode() const {
1171 if (sender_)
1172 return sender_->is_drag_mode();
1173 return true;
1174}
1175
1176void EventSenderBindings::SetIsDragMode(bool drag_mode) {
1177 if (sender_)
1178 sender_->set_is_drag_mode(drag_mode);
1179}
1180
1181#if defined(OS_WIN)
1182int EventSenderBindings::WmKeyDown() const {
1183 if (sender_)
1184 return sender_->wm_key_down();
1185 return 0;
1186}
1187
1188void EventSenderBindings::SetWmKeyDown(int key_down) {
1189 if (sender_)
1190 sender_->set_wm_key_down(key_down);
1191}
1192
1193int EventSenderBindings::WmKeyUp() const {
1194 if (sender_)
1195 return sender_->wm_key_up();
1196 return 0;
1197}
1198
1199void EventSenderBindings::SetWmKeyUp(int key_up) {
1200 if (sender_)
1201 sender_->set_wm_key_up(key_up);
1202}
1203
1204int EventSenderBindings::WmChar() const {
1205 if (sender_)
1206 return sender_->wm_char();
1207 return 0;
1208}
1209
1210void EventSenderBindings::SetWmChar(int wm_char) {
1211 if (sender_)
1212 sender_->set_wm_char(wm_char);
1213}
1214
1215int EventSenderBindings::WmDeadChar() const {
1216 if (sender_)
1217 return sender_->wm_dead_char();
1218 return 0;
1219}
1220
1221void EventSenderBindings::SetWmDeadChar(int dead_char) {
1222 if (sender_)
1223 sender_->set_wm_dead_char(dead_char);
1224}
1225
1226int EventSenderBindings::WmSysKeyDown() const {
1227 if (sender_)
1228 return sender_->wm_sys_key_down();
1229 return 0;
1230}
1231
1232void EventSenderBindings::SetWmSysKeyDown(int key_down) {
1233 if (sender_)
1234 sender_->set_wm_sys_key_down(key_down);
1235}
1236
1237int EventSenderBindings::WmSysKeyUp() const {
1238 if (sender_)
1239 return sender_->wm_sys_key_up();
1240 return 0;
1241}
1242
1243void EventSenderBindings::SetWmSysKeyUp(int key_up) {
1244 if (sender_)
1245 sender_->set_wm_sys_key_up(key_up);
1246}
1247
1248int EventSenderBindings::WmSysChar() const {
1249 if (sender_)
1250 return sender_->wm_sys_char();
1251 return 0;
1252}
1253
1254void EventSenderBindings::SetWmSysChar(int sys_char) {
1255 if (sender_)
1256 sender_->set_wm_sys_char(sys_char);
1257}
1258
1259int EventSenderBindings::WmSysDeadChar() const {
1260 if (sender_)
1261 return sender_->wm_sys_dead_char();
1262 return 0;
1263}
1264
1265void EventSenderBindings::SetWmSysDeadChar(int sys_dead_char) {
1266 if (sender_)
1267 sender_->set_wm_sys_dead_char(sys_dead_char);
1268}
1269#endif
1270
1271// EventSender -----------------------------------------------------------------
1272
[email protected]3db130e2014-03-27 08:14:481273WebMouseEvent::Button EventSender::last_button_type_ =
nzolghadr656569e2016-08-19 16:53:001274 WebMouseEvent::Button::NoButton;
[email protected]3db130e2014-03-27 08:14:481275
1276EventSender::SavedEvent::SavedEvent()
1277 : type(TYPE_UNSPECIFIED),
nzolghadr656569e2016-08-19 16:53:001278 button_type(WebMouseEvent::Button::NoButton),
[email protected]3db130e2014-03-27 08:14:481279 milliseconds(0),
1280 modifiers(0) {}
1281
lukaszad322c5ca2016-10-07 00:32:341282EventSender::EventSender(WebWidgetTestProxyBase* web_widget_test_proxy_base)
1283 : web_widget_test_proxy_base_(web_widget_test_proxy_base),
[email protected]3db130e2014-03-27 08:14:481284 replaying_saved_events_(false),
sammc5648c852015-07-02 01:25:001285 weak_factory_(this) {
lukasza335bb762016-04-22 16:44:031286 Reset();
sammc5648c852015-07-02 01:25:001287}
[email protected]3db130e2014-03-27 08:14:481288
1289EventSender::~EventSender() {}
1290
1291void EventSender::Reset() {
1292 DCHECK(current_drag_data_.isNull());
1293 current_drag_data_.reset();
1294 current_drag_effect_ = blink::WebDragOperationNone;
1295 current_drag_effects_allowed_ = blink::WebDragOperationNone;
lukaszad322c5ca2016-10-07 00:32:341296 if (widget() &&
mustaqabca6ff2016-06-09 17:29:531297 current_pointer_state_[kRawMousePointerId].pressed_button_ !=
nzolghadr656569e2016-08-19 16:53:001298 WebMouseEvent::Button::NoButton)
lukaszad322c5ca2016-10-07 00:32:341299 widget()->mouseCaptureLost();
nzolghadr43146032016-04-11 15:33:381300 current_pointer_state_.clear();
[email protected]3db130e2014-03-27 08:14:481301 is_drag_mode_ = true;
1302 force_layout_on_events_ = true;
1303
1304#if defined(OS_WIN)
1305 wm_key_down_ = WM_KEYDOWN;
1306 wm_key_up_ = WM_KEYUP;
1307 wm_char_ = WM_CHAR;
1308 wm_dead_char_ = WM_DEADCHAR;
1309 wm_sys_key_down_ = WM_SYSKEYDOWN;
1310 wm_sys_key_up_ = WM_SYSKEYUP;
1311 wm_sys_char_ = WM_SYSCHAR;
1312 wm_sys_dead_char_ = WM_SYSDEADCHAR;
1313#endif
1314
[email protected]3db130e2014-03-27 08:14:481315 last_click_time_sec_ = 0;
1316 last_click_pos_ = WebPoint(0, 0);
nzolghadr656569e2016-08-19 16:53:001317 last_button_type_ = WebMouseEvent::Button::NoButton;
[email protected]3db130e2014-03-27 08:14:481318 touch_points_.clear();
[email protected]644616d2014-03-27 16:14:471319 last_context_menu_data_.reset();
lukaszac9358822016-04-07 14:43:461320 weak_factory_.InvalidateWeakPtrs();
[email protected]3db130e2014-03-27 08:14:481321 current_gesture_location_ = WebPoint(0, 0);
1322 mouse_event_queue_.clear();
1323
1324 time_offset_ms_ = 0;
1325 click_count_ = 0;
[email protected]ace1cd502014-04-24 21:05:301326
1327 touch_modifiers_ = 0;
1328 touch_cancelable_ = true;
1329 touch_points_.clear();
[email protected]3db130e2014-03-27 08:14:481330}
1331
lukasza335bb762016-04-22 16:44:031332void EventSender::Install(WebLocalFrame* frame) {
[email protected]3db130e2014-03-27 08:14:481333 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame);
1334}
1335
[email protected]3db130e2014-03-27 08:14:481336void EventSender::SetContextMenuData(const WebContextMenuData& data) {
1337 last_context_menu_data_.reset(new WebContextMenuData(data));
1338}
1339
dtapuska899ac222017-01-03 18:09:161340int EventSender::ModifiersForPointer(int pointer_id) {
1341 return modifiersWithButtons(
1342 current_pointer_state_[pointer_id].modifiers_,
1343 current_pointer_state_[pointer_id].current_buttons_);
1344}
1345
[email protected]3db130e2014-03-27 08:14:481346void EventSender::DoDragDrop(const WebDragData& drag_data,
1347 WebDragOperationsMask mask) {
dtapuska899ac222017-01-03 18:09:161348 WebMouseEvent raw_event(WebInputEvent::MouseDown,
1349 ModifiersForPointer(kRawMousePointerId),
1350 GetCurrentEventTimeSec());
1351 InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_,
mustaqabca6ff2016-06-09 17:29:531352 current_pointer_state_[kRawMousePointerId].current_buttons_,
1353 current_pointer_state_[kRawMousePointerId].last_pos_,
dtapuska899ac222017-01-03 18:09:161354 click_count_, &raw_event);
oshima76b6eeb2016-06-27 15:55:121355
lukaszad322c5ca2016-10-07 00:32:341356 std::unique_ptr<WebInputEvent> widget_event =
1357 TransformScreenToWidgetCoordinates(raw_event);
oshima76b6eeb2016-06-27 15:55:121358 const WebMouseEvent* event =
lukaszad322c5ca2016-10-07 00:32:341359 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
1360 : &raw_event;
oshima76b6eeb2016-06-27 15:55:121361
1362 WebPoint client_point(event->x, event->y);
1363 WebPoint screen_point(event->globalX, event->globalY);
[email protected]3db130e2014-03-27 08:14:481364 current_drag_data_ = drag_data;
1365 current_drag_effects_allowed_ = mask;
paulmeyer90f6c31d2016-11-12 00:17:591366 current_drag_effect_ = mainFrameWidget()->dragTargetDragEnter(
lukasza335bb762016-04-22 16:44:031367 drag_data, client_point, screen_point, current_drag_effects_allowed_,
nzolghadr43146032016-04-11 15:33:381368 modifiersWithButtons(
mustaqabca6ff2016-06-09 17:29:531369 current_pointer_state_[kRawMousePointerId].modifiers_,
1370 current_pointer_state_[kRawMousePointerId].current_buttons_));
[email protected]3db130e2014-03-27 08:14:481371
1372 // Finish processing events.
1373 ReplaySavedEvents();
1374}
1375
1376void EventSender::MouseDown(int button_number, int modifiers) {
nzolghadr43146032016-04-11 15:33:381377 PointerDown(button_number, modifiers,
mustaqabca6ff2016-06-09 17:29:531378 WebPointerProperties::PointerType::Mouse, kRawMousePointerId, 0.0,
1379 0, 0);
[email protected]3db130e2014-03-27 08:14:481380}
1381
1382void EventSender::MouseUp(int button_number, int modifiers) {
mustaqabca6ff2016-06-09 17:29:531383 PointerUp(button_number, modifiers, WebPointerProperties::PointerType::Mouse,
1384 kRawMousePointerId, 0.0, 0, 0);
nzolghadr43146032016-04-11 15:33:381385}
1386
mustaqabca6ff2016-06-09 17:29:531387void EventSender::PointerDown(int button_number,
1388 int modifiers,
1389 WebPointerProperties::PointerType pointerType,
1390 int pointerId,
1391 float pressure,
1392 int tiltX,
1393 int tiltY) {
[email protected]3db130e2014-03-27 08:14:481394 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:341395 widget()->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481396
1397 DCHECK_NE(-1, button_number);
1398
1399 WebMouseEvent::Button button_type =
1400 GetButtonTypeFromButtonNumber(button_number);
1401
nzolghadr43146032016-04-11 15:33:381402 int click_count = 0;
1403 current_pointer_state_[pointerId].pressed_button_ = button_type;
1404 current_pointer_state_[pointerId].current_buttons_ |=
1405 GetWebMouseEventModifierForButton(button_type);
1406 current_pointer_state_[pointerId].modifiers_ = modifiers;
1407
mustaqabca6ff2016-06-09 17:29:531408 if (pointerType == WebPointerProperties::PointerType::Mouse) {
nzolghadr43146032016-04-11 15:33:381409 UpdateClickCountForButton(button_type);
1410 click_count = click_count_;
1411 }
dtapuska899ac222017-01-03 18:09:161412 WebMouseEvent event(WebInputEvent::MouseDown, ModifiersForPointer(pointerId),
1413 GetCurrentEventTimeSec());
1414 InitMouseEventGeneric(current_pointer_state_[pointerId].pressed_button_,
mustaqabca6ff2016-06-09 17:29:531415 current_pointer_state_[pointerId].current_buttons_,
1416 current_pointer_state_[pointerId].last_pos_,
dtapuska899ac222017-01-03 18:09:161417 click_count, pointerType, pointerId, pressure, tiltX,
1418 tiltY, &event);
nzolghadr43146032016-04-11 15:33:381419
1420 HandleInputEventOnViewOrPopup(event);
1421}
1422
mustaqabca6ff2016-06-09 17:29:531423void EventSender::PointerUp(int button_number,
1424 int modifiers,
1425 WebPointerProperties::PointerType pointerType,
1426 int pointerId,
1427 float pressure,
1428 int tiltX,
1429 int tiltY) {
nzolghadr43146032016-04-11 15:33:381430 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:341431 widget()->updateAllLifecyclePhases();
nzolghadr43146032016-04-11 15:33:381432
1433 DCHECK_NE(-1, button_number);
1434
1435 WebMouseEvent::Button button_type =
1436 GetButtonTypeFromButtonNumber(button_number);
1437
mustaqabca6ff2016-06-09 17:29:531438 if (pointerType == WebPointerProperties::PointerType::Mouse &&
nzolghadr43146032016-04-11 15:33:381439 is_drag_mode_ && !replaying_saved_events_) {
[email protected]3db130e2014-03-27 08:14:481440 SavedEvent saved_event;
1441 saved_event.type = SavedEvent::TYPE_MOUSE_UP;
1442 saved_event.button_type = button_type;
1443 saved_event.modifiers = modifiers;
1444 mouse_event_queue_.push_back(saved_event);
1445 ReplaySavedEvents();
1446 } else {
dtapuska899ac222017-01-03 18:09:161447 current_pointer_state_[pointerId].modifiers_ = modifiers;
nzolghadr43146032016-04-11 15:33:381448 current_pointer_state_[pointerId].current_buttons_ &=
1449 ~GetWebMouseEventModifierForButton(button_type);
1450 current_pointer_state_[pointerId].pressed_button_ =
nzolghadr656569e2016-08-19 16:53:001451 WebMouseEvent::Button::NoButton;
mustaq21aed4e2015-12-15 21:47:211452
dtapuska899ac222017-01-03 18:09:161453 WebMouseEvent event(WebInputEvent::MouseUp, ModifiersForPointer(pointerId),
1454 GetCurrentEventTimeSec());
mustaqabca6ff2016-06-09 17:29:531455 int click_count = pointerType == WebPointerProperties::PointerType::Mouse
1456 ? click_count_
1457 : 0;
dtapuska899ac222017-01-03 18:09:161458 InitMouseEventGeneric(
1459 button_type, current_pointer_state_[pointerId].current_buttons_,
1460 current_pointer_state_[pointerId].last_pos_, click_count, pointerType,
1461 pointerId, pressure, tiltX, tiltY, &event);
nzolghadr43146032016-04-11 15:33:381462 HandleInputEventOnViewOrPopup(event);
mustaqabca6ff2016-06-09 17:29:531463 if (pointerType == WebPointerProperties::PointerType::Mouse)
nzolghadr43146032016-04-11 15:33:381464 DoDragAfterMouseUp(event);
[email protected]3db130e2014-03-27 08:14:481465 }
1466}
1467
mustaq21aed4e2015-12-15 21:47:211468void EventSender::SetMouseButtonState(int button_number, int modifiers) {
mustaqabca6ff2016-06-09 17:29:531469 current_pointer_state_[kRawMousePointerId].pressed_button_ =
nzolghadr43146032016-04-11 15:33:381470 GetButtonTypeFromButtonNumber(button_number);
mustaqabca6ff2016-06-09 17:29:531471 current_pointer_state_[kRawMousePointerId].current_buttons_ =
nzolghadr43146032016-04-11 15:33:381472 (modifiers == -1)
1473 ? GetWebMouseEventModifierForButton(
mustaqabca6ff2016-06-09 17:29:531474 current_pointer_state_[kRawMousePointerId].pressed_button_)
nzolghadr43146032016-04-11 15:33:381475 : modifiers & kButtonsInModifiers;
mustaq21aed4e2015-12-15 21:47:211476}
1477
[email protected]3db130e2014-03-27 08:14:481478void EventSender::KeyDown(const std::string& code_str,
1479 int modifiers,
1480 KeyLocationCode location) {
1481 // FIXME: I'm not exactly sure how we should convert the string to a key
1482 // event. This seems to work in the cases I tested.
1483 // FIXME: Should we also generate a KEY_UP?
1484
1485 bool generate_char = false;
1486
1487 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when
1488 // Windows uses \r for "Enter".
1489 int code = 0;
1490 int text = 0;
1491 bool needs_shift_key_modifier = false;
chongz40aff932016-05-04 14:30:121492 std::string domKeyString;
1493 std::string domCodeString;
[email protected]3db130e2014-03-27 08:14:481494
dtapuska0d1f4af2016-06-29 16:42:221495 if ("Enter" == code_str) {
[email protected]3db130e2014-03-27 08:14:481496 generate_char = true;
[email protected]a731f1a92014-04-17 19:31:061497 text = code = ui::VKEY_RETURN;
chongz40aff932016-05-04 14:30:121498 domKeyString.assign("Enter");
1499 domCodeString.assign("Enter");
dtapuska0d1f4af2016-06-29 16:42:221500 } else if ("ArrowRight" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061501 code = ui::VKEY_RIGHT;
chongz40aff932016-05-04 14:30:121502 domKeyString.assign("ArrowRight");
1503 domCodeString.assign("ArrowRight");
dtapuska0d1f4af2016-06-29 16:42:221504 } else if ("ArrowDown" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061505 code = ui::VKEY_DOWN;
chongz40aff932016-05-04 14:30:121506 domKeyString.assign("ArrowDown");
1507 domCodeString.assign("ArrowDown");
dtapuska0d1f4af2016-06-29 16:42:221508 } else if ("ArrowLeft" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061509 code = ui::VKEY_LEFT;
chongz40aff932016-05-04 14:30:121510 domKeyString.assign("ArrowLeft");
1511 domCodeString.assign("ArrowLeft");
dtapuska0d1f4af2016-06-29 16:42:221512 } else if ("ArrowUp" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061513 code = ui::VKEY_UP;
chongz40aff932016-05-04 14:30:121514 domKeyString.assign("ArrowUp");
1515 domCodeString.assign("ArrowUp");
dtapuska0d1f4af2016-06-29 16:42:221516 } else if ("Insert" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061517 code = ui::VKEY_INSERT;
chongz40aff932016-05-04 14:30:121518 domKeyString.assign("Insert");
1519 domCodeString.assign("Insert");
dtapuska0d1f4af2016-06-29 16:42:221520 } else if ("Delete" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061521 code = ui::VKEY_DELETE;
chongz40aff932016-05-04 14:30:121522 domKeyString.assign("Delete");
1523 domCodeString.assign("Delete");
dtapuska0d1f4af2016-06-29 16:42:221524 } else if ("PageUp" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061525 code = ui::VKEY_PRIOR;
chongz40aff932016-05-04 14:30:121526 domKeyString.assign("PageUp");
1527 domCodeString.assign("PageUp");
dtapuska0d1f4af2016-06-29 16:42:221528 } else if ("PageDown" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061529 code = ui::VKEY_NEXT;
chongz40aff932016-05-04 14:30:121530 domKeyString.assign("PageDown");
1531 domCodeString.assign("PageDown");
dtapuska0d1f4af2016-06-29 16:42:221532 } else if ("Home" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061533 code = ui::VKEY_HOME;
chongz40aff932016-05-04 14:30:121534 domKeyString.assign("Home");
1535 domCodeString.assign("Home");
dtapuska0d1f4af2016-06-29 16:42:221536 } else if ("End" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061537 code = ui::VKEY_END;
chongz40aff932016-05-04 14:30:121538 domKeyString.assign("End");
1539 domCodeString.assign("End");
dtapuska0d1f4af2016-06-29 16:42:221540 } else if ("PrintScreen" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061541 code = ui::VKEY_SNAPSHOT;
chongz40aff932016-05-04 14:30:121542 domKeyString.assign("PrintScreen");
1543 domCodeString.assign("PrintScreen");
dtapuska0d1f4af2016-06-29 16:42:221544 } else if ("ContextMenu" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061545 code = ui::VKEY_APPS;
chongz40aff932016-05-04 14:30:121546 domKeyString.assign("ContextMenu");
1547 domCodeString.assign("ContextMenu");
dtapuska0d1f4af2016-06-29 16:42:221548 } else if ("ControlLeft" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051549 code = ui::VKEY_CONTROL;
chongz40aff932016-05-04 14:30:121550 domKeyString.assign("Control");
1551 domCodeString.assign("ControlLeft");
dtapuskad3ba0f042015-08-27 14:08:051552 location = DOMKeyLocationLeft;
dtapuska0d1f4af2016-06-29 16:42:221553 } else if ("ControlRight" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051554 code = ui::VKEY_CONTROL;
chongz40aff932016-05-04 14:30:121555 domKeyString.assign("Control");
1556 domCodeString.assign("ControlRight");
dtapuskad3ba0f042015-08-27 14:08:051557 location = DOMKeyLocationRight;
dtapuska0d1f4af2016-06-29 16:42:221558 } else if ("ShiftLeft" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051559 code = ui::VKEY_SHIFT;
chongz40aff932016-05-04 14:30:121560 domKeyString.assign("Shift");
1561 domCodeString.assign("ShiftLeft");
dtapuskad3ba0f042015-08-27 14:08:051562 location = DOMKeyLocationLeft;
dtapuska0d1f4af2016-06-29 16:42:221563 } else if ("ShiftRight" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051564 code = ui::VKEY_SHIFT;
chongz40aff932016-05-04 14:30:121565 domKeyString.assign("Shift");
1566 domCodeString.assign("ShiftRight");
dtapuskad3ba0f042015-08-27 14:08:051567 location = DOMKeyLocationRight;
dtapuska0d1f4af2016-06-29 16:42:221568 } else if ("AltLeft" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051569 code = ui::VKEY_MENU;
chongz40aff932016-05-04 14:30:121570 domKeyString.assign("Alt");
1571 domCodeString.assign("AltLeft");
dtapuskad3ba0f042015-08-27 14:08:051572 location = DOMKeyLocationLeft;
dtapuska0d1f4af2016-06-29 16:42:221573 } else if ("AltRight" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051574 code = ui::VKEY_MENU;
chongz40aff932016-05-04 14:30:121575 domKeyString.assign("Alt");
1576 domCodeString.assign("AltRight");
dtapuskad3ba0f042015-08-27 14:08:051577 location = DOMKeyLocationRight;
dtapuska0d1f4af2016-06-29 16:42:221578 } else if ("NumLock" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061579 code = ui::VKEY_NUMLOCK;
chongz40aff932016-05-04 14:30:121580 domKeyString.assign("NumLock");
1581 domCodeString.assign("NumLock");
dtapuska0d1f4af2016-06-29 16:42:221582 } else if ("Backspace" == code_str) {
[email protected]4c07a712014-08-21 17:05:541583 code = ui::VKEY_BACK;
chongz40aff932016-05-04 14:30:121584 domKeyString.assign("Backspace");
1585 domCodeString.assign("Backspace");
dtapuska0d1f4af2016-06-29 16:42:221586 } else if ("Escape" == code_str) {
[email protected]4c07a712014-08-21 17:05:541587 code = ui::VKEY_ESCAPE;
chongz40aff932016-05-04 14:30:121588 domKeyString.assign("Escape");
1589 domCodeString.assign("Escape");
dtapuska8f3b1e52016-06-21 16:34:071590 } else if ("Tab" == code_str) {
1591 code = ui::VKEY_TAB;
1592 domKeyString.assign("Tab");
1593 domCodeString.assign("Tab");
chongz78364d672016-08-03 00:13:431594 } else if ("Cut" == code_str || "Copy" == code_str || "Paste" == code_str) {
1595 // No valid KeyboardCode for Cut/Copy/Paste.
1596 code = 0;
1597 domKeyString.assign(code_str);
1598 // It's OK to assign the same string as the DomCode strings happens to be
1599 // the same for these keys.
1600 domCodeString.assign(code_str);
[email protected]3db130e2014-03-27 08:14:481601 } else {
1602 // Compare the input string with the function-key names defined by the
1603 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key
1604 // name, set its key code.
1605 for (int i = 1; i <= 24; ++i) {
1606 std::string function_key_name = base::StringPrintf("F%d", i);
1607 if (function_key_name == code_str) {
[email protected]a731f1a92014-04-17 19:31:061608 code = ui::VKEY_F1 + (i - 1);
chongz40aff932016-05-04 14:30:121609 domKeyString = function_key_name;
1610 domCodeString = function_key_name;
[email protected]3db130e2014-03-27 08:14:481611 break;
1612 }
1613 }
1614 if (!code) {
esprehnd29ab802015-12-11 13:01:191615 base::string16 code_str16 = base::UTF8ToUTF16(code_str);
1616 if (code_str16.size() != 1u) {
dtapuskabd2a1652015-05-20 00:30:151617 v8::Isolate* isolate = blink::mainThreadIsolate();
1618 isolate->ThrowException(v8::Exception::TypeError(
1619 gin::StringToV8(isolate, "Invalid web code.")));
1620 return;
1621 }
esprehnd29ab802015-12-11 13:01:191622 text = code = code_str16[0];
zhongyi23960342016-04-12 23:13:201623 needs_shift_key_modifier = base::IsAsciiUpper(code & 0xFF);
1624 if (base::IsAsciiLower(code & 0xFF))
[email protected]3db130e2014-03-27 08:14:481625 code -= 'a' - 'A';
zhongyi23960342016-04-12 23:13:201626 if (base::IsAsciiAlpha(code)) {
chongz40aff932016-05-04 14:30:121627 domKeyString.assign(code_str);
1628 domCodeString.assign("Key");
1629 domCodeString.push_back(
brettwc15100c2015-08-06 22:54:161630 base::ToUpperASCII(static_cast<base::char16>(code)));
zhongyi23960342016-04-12 23:13:201631 } else if (base::IsAsciiDigit(code)) {
chongz40aff932016-05-04 14:30:121632 domKeyString.assign(code_str);
1633 domCodeString.assign("Digit");
1634 domCodeString.push_back(code);
habib.virji565c80c2015-02-06 12:26:431635 } else if (code == ' ') {
chongz40aff932016-05-04 14:30:121636 domKeyString.assign(code_str);
1637 domCodeString.assign("Space");
habib.virji565c80c2015-02-06 12:26:431638 } else if (code == 9) {
chongz40aff932016-05-04 14:30:121639 domKeyString.assign("Tab");
1640 domCodeString.assign("Tab");
habib.virji565c80c2015-02-06 12:26:431641 }
[email protected]3db130e2014-03-27 08:14:481642 generate_char = true;
1643 }
1644
1645 if ("(" == code_str) {
1646 code = '9';
1647 needs_shift_key_modifier = true;
chongz40aff932016-05-04 14:30:121648 domKeyString.assign("(");
1649 domCodeString.assign("Digit9");
[email protected]3db130e2014-03-27 08:14:481650 }
1651 }
1652
dtapuska899ac222017-01-03 18:09:161653 if (needs_shift_key_modifier)
1654 modifiers |= WebInputEvent::ShiftKey;
1655
1656 // See if KeyLocation argument is given.
1657 switch (location) {
1658 case DOMKeyLocationStandard:
1659 break;
1660 case DOMKeyLocationLeft:
1661 modifiers |= WebInputEvent::IsLeft;
1662 break;
1663 case DOMKeyLocationRight:
1664 modifiers |= WebInputEvent::IsRight;
1665 break;
1666 case DOMKeyLocationNumpad:
1667 modifiers |= WebInputEvent::IsKeyPad;
1668 break;
1669 }
1670
[email protected]3db130e2014-03-27 08:14:481671 // For one generated keyboard event, we need to generate a keyDown/keyUp
1672 // pair;
1673 // On Windows, we might also need to generate a char event to mimic the
1674 // Windows event flow; on other platforms we create a merged event and test
1675 // the event flow that that platform provides.
dtapuska899ac222017-01-03 18:09:161676 WebKeyboardEvent event_down(WebInputEvent::RawKeyDown, modifiers,
1677 GetCurrentEventTimeSec());
[email protected]3db130e2014-03-27 08:14:481678 event_down.windowsKeyCode = code;
chongz40aff932016-05-04 14:30:121679 event_down.domKey = static_cast<int>(
1680 ui::KeycodeConverter::KeyStringToDomKey(domKeyString));
habib.virji565c80c2015-02-06 12:26:431681 event_down.domCode = static_cast<int>(
chongz40aff932016-05-04 14:30:121682 ui::KeycodeConverter::CodeStringToDomCode(domCodeString));
[email protected]3db130e2014-03-27 08:14:481683
[email protected]3db130e2014-03-27 08:14:481684 if (generate_char) {
1685 event_down.text[0] = text;
1686 event_down.unmodifiedText[0] = text;
1687 }
1688
dtapuska8c4dae12017-01-13 00:23:061689 if (event_down.modifiers() != 0)
[email protected]a731f1a92014-04-17 19:31:061690 event_down.isSystemKey = IsSystemKeyEvent(event_down);
[email protected]3db130e2014-03-27 08:14:481691
dtapuska899ac222017-01-03 18:09:161692 WebKeyboardEvent event_up = event_down;
1693 event_up.setType(WebInputEvent::KeyUp);
[email protected]3db130e2014-03-27 08:14:481694 // EventSender.m forces a layout here, with at least one
1695 // test (fast/forms/focus-control-to-page.html) relying on this.
1696 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:341697 widget()->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481698
1699 // In the browser, if a keyboard event corresponds to an editor command,
1700 // the command will be dispatched to the renderer just before dispatching
1701 // the keyboard event, and then it will be executed in the
1702 // RenderView::handleCurrentKeyboardEvent() method.
1703 // We just simulate the same behavior here.
1704 std::string edit_command;
1705 if (GetEditCommand(event_down, &edit_command))
lukasza335bb762016-04-22 16:44:031706 delegate()->SetEditCommand(edit_command, "");
[email protected]3db130e2014-03-27 08:14:481707
tkent588765612014-11-28 01:07:481708 HandleInputEventOnViewOrPopup(event_down);
[email protected]3db130e2014-03-27 08:14:481709
[email protected]a731f1a92014-04-17 19:31:061710 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) {
dtapuska899ac222017-01-03 18:09:161711 WebMouseEvent event(WebInputEvent::MouseDown,
1712 ModifiersForPointer(kRawMousePointerId),
1713 GetCurrentEventTimeSec());
1714 InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_,
mustaqabca6ff2016-06-09 17:29:531715 current_pointer_state_[kRawMousePointerId].current_buttons_,
1716 current_pointer_state_[kRawMousePointerId].last_pos_,
dtapuska899ac222017-01-03 18:09:161717 click_count_, &event);
[email protected]3db130e2014-03-27 08:14:481718 FinishDragAndDrop(event, blink::WebDragOperationNone);
1719 }
1720
lukasza335bb762016-04-22 16:44:031721 delegate()->ClearEditCommand();
[email protected]3db130e2014-03-27 08:14:481722
1723 if (generate_char) {
1724 WebKeyboardEvent event_char = event_up;
dtapuska899ac222017-01-03 18:09:161725 event_char.setType(WebInputEvent::Char);
tkent588765612014-11-28 01:07:481726 HandleInputEventOnViewOrPopup(event_char);
[email protected]3db130e2014-03-27 08:14:481727 }
1728
tkent588765612014-11-28 01:07:481729 HandleInputEventOnViewOrPopup(event_up);
[email protected]3db130e2014-03-27 08:14:481730}
1731
1732void EventSender::EnableDOMUIEventLogging() {}
1733
1734void EventSender::FireKeyboardEventsToElement() {}
1735
1736void EventSender::ClearKillRing() {}
1737
1738std::vector<std::string> EventSender::ContextClick() {
lukaszad322c5ca2016-10-07 00:32:341739 if (force_layout_on_events_)
1740 widget()->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481741
nzolghadr656569e2016-08-19 16:53:001742 UpdateClickCountForButton(WebMouseEvent::Button::Right);
[email protected]3db130e2014-03-27 08:14:481743
1744 // Clears last context menu data because we need to know if the context menu
1745 // be requested after following mouse events.
1746 last_context_menu_data_.reset();
1747
1748 // Generate right mouse down and up.
[email protected]3db130e2014-03-27 08:14:481749 // This is a hack to work around only allowing a single pressed button since
1750 // we want to test the case where both the left and right mouse buttons are
1751 // pressed.
mustaq21aed4e2015-12-15 21:47:211752 // TODO(mustaq): This hack seems unused here! But do we need this hack at all
1753 // after adding current_buttons_.
mustaqabca6ff2016-06-09 17:29:531754 if (current_pointer_state_[kRawMousePointerId].pressed_button_ ==
nzolghadr656569e2016-08-19 16:53:001755 WebMouseEvent::Button::NoButton) {
mustaqabca6ff2016-06-09 17:29:531756 current_pointer_state_[kRawMousePointerId].pressed_button_ =
nzolghadr656569e2016-08-19 16:53:001757 WebMouseEvent::Button::Right;
mustaqabca6ff2016-06-09 17:29:531758 current_pointer_state_[kRawMousePointerId].current_buttons_ |=
nzolghadr43146032016-04-11 15:33:381759 GetWebMouseEventModifierForButton(
mustaqabca6ff2016-06-09 17:29:531760 current_pointer_state_[kRawMousePointerId].pressed_button_);
[email protected]3db130e2014-03-27 08:14:481761 }
dtapuska899ac222017-01-03 18:09:161762 WebMouseEvent event(WebInputEvent::MouseDown,
1763 ModifiersForPointer(kRawMousePointerId),
1764 GetCurrentEventTimeSec());
1765 InitMouseEvent(WebMouseEvent::Button::Right,
mustaqabca6ff2016-06-09 17:29:531766 current_pointer_state_[kRawMousePointerId].current_buttons_,
1767 current_pointer_state_[kRawMousePointerId].last_pos_,
dtapuska899ac222017-01-03 18:09:161768 click_count_, &event);
tkent588765612014-11-28 01:07:481769 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481770
1771#if defined(OS_WIN)
mustaqabca6ff2016-06-09 17:29:531772 current_pointer_state_[kRawMousePointerId].current_buttons_ &=
nzolghadr656569e2016-08-19 16:53:001773 ~GetWebMouseEventModifierForButton(WebMouseEvent::Button::Right);
mustaqabca6ff2016-06-09 17:29:531774 current_pointer_state_[kRawMousePointerId].pressed_button_ =
nzolghadr656569e2016-08-19 16:53:001775 WebMouseEvent::Button::NoButton;
mustaq21aed4e2015-12-15 21:47:211776
dtapuska899ac222017-01-03 18:09:161777 WebMouseEvent mouseUpEvent(WebInputEvent::MouseUp,
1778 ModifiersForPointer(kRawMousePointerId),
1779 GetCurrentEventTimeSec());
1780 InitMouseEvent(WebMouseEvent::Button::Right,
mustaqabca6ff2016-06-09 17:29:531781 current_pointer_state_[kRawMousePointerId].current_buttons_,
1782 current_pointer_state_[kRawMousePointerId].last_pos_,
dtapuska899ac222017-01-03 18:09:161783 click_count_, &mouseUpEvent);
1784 HandleInputEventOnViewOrPopup(mouseUpEvent);
[email protected]3db130e2014-03-27 08:14:481785#endif
1786
jochen73e711c2015-06-03 10:01:461787 std::vector<std::string> menu_items =
lukasza335bb762016-04-22 16:44:031788 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate());
[email protected]e7c71192014-04-23 11:53:481789 last_context_menu_data_.reset();
1790 return menu_items;
[email protected]3db130e2014-03-27 08:14:481791}
1792
1793void EventSender::TextZoomIn() {
lukasza335bb762016-04-22 16:44:031794 view()->setTextZoomFactor(view()->textZoomFactor() * 1.2f);
[email protected]3db130e2014-03-27 08:14:481795}
1796
1797void EventSender::TextZoomOut() {
lukasza335bb762016-04-22 16:44:031798 view()->setTextZoomFactor(view()->textZoomFactor() / 1.2f);
[email protected]3db130e2014-03-27 08:14:481799}
1800
1801void EventSender::ZoomPageIn() {
lfg05e41372016-07-22 15:38:101802 const std::vector<WebViewTestProxyBase*>& window_list =
lukasza335bb762016-04-22 16:44:031803 interfaces()->GetWindowList();
[email protected]3db130e2014-03-27 08:14:481804
1805 for (size_t i = 0; i < window_list.size(); ++i) {
lukasza01da2602016-04-05 14:51:261806 window_list.at(i)->web_view()->setZoomLevel(
1807 window_list.at(i)->web_view()->zoomLevel() + 1);
[email protected]3db130e2014-03-27 08:14:481808 }
1809}
1810
1811void EventSender::ZoomPageOut() {
lfg05e41372016-07-22 15:38:101812 const std::vector<WebViewTestProxyBase*>& window_list =
lukasza335bb762016-04-22 16:44:031813 interfaces()->GetWindowList();
[email protected]3db130e2014-03-27 08:14:481814
1815 for (size_t i = 0; i < window_list.size(); ++i) {
lukasza01da2602016-04-05 14:51:261816 window_list.at(i)->web_view()->setZoomLevel(
1817 window_list.at(i)->web_view()->zoomLevel() - 1);
[email protected]3db130e2014-03-27 08:14:481818 }
1819}
1820
[email protected]b32fe542014-04-30 08:42:061821void EventSender::SetPageZoomFactor(double zoom_factor) {
lfg05e41372016-07-22 15:38:101822 const std::vector<WebViewTestProxyBase*>& window_list =
lukasza335bb762016-04-22 16:44:031823 interfaces()->GetWindowList();
[email protected]b32fe542014-04-30 08:42:061824
1825 for (size_t i = 0; i < window_list.size(); ++i) {
lukasza01da2602016-04-05 14:51:261826 window_list.at(i)->web_view()->setZoomLevel(std::log(zoom_factor) /
1827 std::log(1.2));
[email protected]b32fe542014-04-30 08:42:061828 }
1829}
1830
[email protected]3db130e2014-03-27 08:14:481831void EventSender::ClearTouchPoints() {
1832 touch_points_.clear();
1833}
1834
[email protected]bfb6a602014-04-16 19:59:411835void EventSender::ThrowTouchPointError() {
1836 v8::Isolate* isolate = blink::mainThreadIsolate();
1837 isolate->ThrowException(v8::Exception::TypeError(
1838 gin::StringToV8(isolate, "Invalid touch point.")));
1839}
1840
[email protected]3db130e2014-03-27 08:14:481841void EventSender::ReleaseTouchPoint(unsigned index) {
[email protected]bfb6a602014-04-16 19:59:411842 if (index >= touch_points_.size()) {
1843 ThrowTouchPointError();
1844 return;
1845 }
[email protected]3db130e2014-03-27 08:14:481846
1847 WebTouchPoint* touch_point = &touch_points_[index];
1848 touch_point->state = WebTouchPoint::StateReleased;
1849}
1850
e.hakkinen80033922015-07-31 08:41:351851void EventSender::UpdateTouchPoint(unsigned index,
1852 float x,
1853 float y,
1854 gin::Arguments* args) {
[email protected]bfb6a602014-04-16 19:59:411855 if (index >= touch_points_.size()) {
1856 ThrowTouchPointError();
1857 return;
1858 }
[email protected]3db130e2014-03-27 08:14:481859
1860 WebTouchPoint* touch_point = &touch_points_[index];
1861 touch_point->state = WebTouchPoint::StateMoved;
1862 touch_point->position = WebFloatPoint(x, y);
1863 touch_point->screenPosition = touch_point->position;
e.hakkinen80033922015-07-31 08:41:351864
1865 InitPointerProperties(args, touch_point, &touch_point->radiusX,
1866 &touch_point->radiusY);
[email protected]3db130e2014-03-27 08:14:481867}
1868
1869void EventSender::CancelTouchPoint(unsigned index) {
[email protected]bfb6a602014-04-16 19:59:411870 if (index >= touch_points_.size()) {
1871 ThrowTouchPointError();
1872 return;
1873 }
[email protected]3db130e2014-03-27 08:14:481874
1875 WebTouchPoint* touch_point = &touch_points_[index];
1876 touch_point->state = WebTouchPoint::StateCancelled;
1877}
1878
1879void EventSender::SetTouchModifier(const std::string& key_name,
1880 bool set_mask) {
mustaq21aed4e2015-12-15 21:47:211881 int mask = GetKeyModifier(key_name);
[email protected]3db130e2014-03-27 08:14:481882
1883 if (set_mask)
1884 touch_modifiers_ |= mask;
1885 else
1886 touch_modifiers_ &= ~mask;
1887}
1888
[email protected]ace1cd502014-04-24 21:05:301889void EventSender::SetTouchCancelable(bool cancelable) {
1890 touch_cancelable_ = cancelable;
1891}
1892
[email protected]3db130e2014-03-27 08:14:481893void EventSender::DumpFilenameBeingDragged() {
dchengc3fe4642015-01-22 06:29:521894 if (current_drag_data_.isNull())
1895 return;
1896
[email protected]3db130e2014-03-27 08:14:481897 WebVector<WebDragData::Item> items = current_drag_data_.items();
1898 for (size_t i = 0; i < items.size(); ++i) {
1899 if (items[i].storageType == WebDragData::Item::StorageTypeBinaryData) {
dcheng3dd85612017-02-08 10:46:231900 WebURL url = items[i].binaryDataSourceURL;
1901 WebString filename_extension = items[i].binaryDataFilenameExtension;
1902 WebString content_disposition = items[i].binaryDataContentDisposition;
1903 base::FilePath filename =
1904 net::GenerateFileName(url, content_disposition.utf8(),
1905 std::string(), // referrer_charset
1906 std::string(), // suggested_name
1907 std::string(), // mime_type
1908 std::string()); // default_name
1909#if defined(OS_WIN)
1910 filename = filename.ReplaceExtension(filename_extension.utf16());
1911#else
1912 filename = filename.ReplaceExtension(filename_extension.utf8());
1913#endif
1914 delegate()->PrintMessage(std::string("Filename being dragged: ") +
1915 filename.AsUTF8Unsafe() + "\n");
1916 return;
[email protected]3db130e2014-03-27 08:14:481917 }
1918 }
[email protected]3db130e2014-03-27 08:14:481919}
1920
1921void EventSender::GestureFlingCancel() {
dtapuska899ac222017-01-03 18:09:161922 WebGestureEvent event(WebInputEvent::GestureFlingCancel,
1923 WebInputEvent::NoModifiers, GetCurrentEventTimeSec());
wjmaclean3bb814792015-10-20 01:13:321924 // Generally it won't matter what device we use here, and since it might
1925 // be cumbersome to expect all callers to specify a device, we'll just
1926 // choose Touchpad here.
1927 event.sourceDevice = blink::WebGestureDeviceTouchpad;
[email protected]3db130e2014-03-27 08:14:481928
1929 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:341930 widget()->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481931
tkent588765612014-11-28 01:07:481932 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481933}
1934
1935void EventSender::GestureFlingStart(float x,
tdresser3a1c9722015-02-13 15:44:531936 float y,
1937 float velocity_x,
1938 float velocity_y,
1939 gin::Arguments* args) {
dtapuska899ac222017-01-03 18:09:161940 WebGestureEvent event(WebInputEvent::GestureFlingStart,
1941 WebInputEvent::NoModifiers, GetCurrentEventTimeSec());
[email protected]3db130e2014-03-27 08:14:481942
tdresser15af5872015-02-18 14:03:021943 std::string device_string;
1944 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString())
1945 args->GetNext(&device_string);
tdresser3a1c9722015-02-13 15:44:531946
1947 if (device_string == kSourceDeviceStringTouchpad) {
1948 event.sourceDevice = blink::WebGestureDeviceTouchpad;
1949 } else if (device_string == kSourceDeviceStringTouchscreen) {
1950 event.sourceDevice = blink::WebGestureDeviceTouchscreen;
1951 } else {
1952 args->ThrowError();
1953 return;
1954 }
1955
sahel42a50bb2016-07-22 19:34:041956 float max_start_velocity = std::max(fabs(velocity_x), fabs(velocity_y));
1957 if (!max_start_velocity) {
1958 v8::Isolate* isolate = blink::mainThreadIsolate();
1959 isolate->ThrowException(v8::Exception::TypeError(
1960 gin::StringToV8(isolate, "Invalid max start velocity.")));
1961 return;
1962 }
1963
[email protected]3db130e2014-03-27 08:14:481964 event.x = x;
1965 event.y = y;
1966 event.globalX = event.x;
1967 event.globalY = event.y;
1968
1969 event.data.flingStart.velocityX = velocity_x;
1970 event.data.flingStart.velocityY = velocity_y;
[email protected]3db130e2014-03-27 08:14:481971
1972 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:341973 widget()->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481974
tkent588765612014-11-28 01:07:481975 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481976}
1977
tdresserd7bba522016-02-19 22:40:131978bool EventSender::IsFlinging() const {
lukasza335bb762016-04-22 16:44:031979 return view()->isFlinging();
tdresserd7bba522016-02-19 22:40:131980}
1981
[email protected]3db130e2014-03-27 08:14:481982void EventSender::GestureScrollFirstPoint(int x, int y) {
1983 current_gesture_location_ = WebPoint(x, y);
1984}
1985
rbyers709aa1e2016-05-12 04:44:061986void EventSender::TouchStart(gin::Arguments* args) {
mustaq19048372016-06-16 21:39:321987 SendCurrentTouchEvent(WebInputEvent::TouchStart, args);
mustaq96985f722015-06-30 21:41:531988}
1989
rbyers709aa1e2016-05-12 04:44:061990void EventSender::TouchMove(gin::Arguments* args) {
mustaq19048372016-06-16 21:39:321991 SendCurrentTouchEvent(WebInputEvent::TouchMove, args);
[email protected]3db130e2014-03-27 08:14:481992}
1993
rbyers709aa1e2016-05-12 04:44:061994void EventSender::TouchCancel(gin::Arguments* args) {
mustaq19048372016-06-16 21:39:321995 SendCurrentTouchEvent(WebInputEvent::TouchCancel, args);
rbyers709aa1e2016-05-12 04:44:061996}
1997
1998void EventSender::TouchEnd(gin::Arguments* args) {
mustaq19048372016-06-16 21:39:321999 SendCurrentTouchEvent(WebInputEvent::TouchEnd, args);
[email protected]3db130e2014-03-27 08:14:482000}
2001
mustaqb3c44a02016-04-19 18:49:052002void EventSender::NotifyStartOfTouchScroll() {
dtapuska899ac222017-01-03 18:09:162003 WebTouchEvent event(WebInputEvent::TouchScrollStarted,
2004 WebInputEvent::NoModifiers, GetCurrentEventTimeSec());
mustaqb3c44a02016-04-19 18:49:052005 HandleInputEventOnViewOrPopup(event);
2006}
2007
[email protected]3db130e2014-03-27 08:14:482008void EventSender::LeapForward(int milliseconds) {
nzolghadr43146032016-04-11 15:33:382009 if (is_drag_mode_ &&
mustaqabca6ff2016-06-09 17:29:532010 current_pointer_state_[kRawMousePointerId].pressed_button_ ==
nzolghadr656569e2016-08-19 16:53:002011 WebMouseEvent::Button::Left &&
[email protected]3db130e2014-03-27 08:14:482012 !replaying_saved_events_) {
2013 SavedEvent saved_event;
2014 saved_event.type = SavedEvent::TYPE_LEAP_FORWARD;
2015 saved_event.milliseconds = milliseconds;
2016 mouse_event_queue_.push_back(saved_event);
2017 } else {
2018 DoLeapForward(milliseconds);
2019 }
2020}
2021
2022void EventSender::BeginDragWithFiles(const std::vector<std::string>& files) {
sigbjornf23324ff2016-02-22 15:46:312023 if (!current_drag_data_.isNull()) {
2024 // Nested dragging not supported, fuzzer code a likely culprit.
2025 // Cancel the current drag operation and throw an error.
dtapuska0d1f4af2016-06-29 16:42:222026 KeyDown("Escape", 0, DOMKeyLocationStandard);
sigbjornf23324ff2016-02-22 15:46:312027 v8::Isolate* isolate = blink::mainThreadIsolate();
2028 isolate->ThrowException(v8::Exception::Error(
2029 gin::StringToV8(isolate,
2030 "Nested beginDragWithFiles() not supported.")));
2031 return;
2032 }
[email protected]3db130e2014-03-27 08:14:482033 current_drag_data_.initialize();
2034 WebVector<WebString> absolute_filenames(files.size());
2035 for (size_t i = 0; i < files.size(); ++i) {
2036 WebDragData::Item item;
2037 item.storageType = WebDragData::Item::StorageTypeFilename;
lukasza335bb762016-04-22 16:44:032038 item.filenameData = delegate()->GetAbsoluteWebStringFromUTF8Path(files[i]);
[email protected]3db130e2014-03-27 08:14:482039 current_drag_data_.addItem(item);
2040 absolute_filenames[i] = item.filenameData;
2041 }
2042 current_drag_data_.setFilesystemId(
lukasza335bb762016-04-22 16:44:032043 delegate()->RegisterIsolatedFileSystem(absolute_filenames));
[email protected]3db130e2014-03-27 08:14:482044 current_drag_effects_allowed_ = blink::WebDragOperationCopy;
2045
oshima76b6eeb2016-06-27 15:55:122046 const WebPoint& last_pos =
2047 current_pointer_state_[kRawMousePointerId].last_pos_;
2048 float scale = delegate()->GetWindowToViewportScale();
2049 WebPoint scaled_last_pos(last_pos.x * scale, last_pos.y * scale);
2050
[email protected]3db130e2014-03-27 08:14:482051 // Provide a drag source.
paulmeyer90f6c31d2016-11-12 00:17:592052 mainFrameWidget()->dragTargetDragEnter(
oshima76b6eeb2016-06-27 15:55:122053 current_drag_data_, scaled_last_pos, scaled_last_pos,
mustaqabca6ff2016-06-09 17:29:532054 current_drag_effects_allowed_, 0);
[email protected]3db130e2014-03-27 08:14:482055 // |is_drag_mode_| saves events and then replays them later. We don't
2056 // need/want that.
2057 is_drag_mode_ = false;
2058
2059 // Make the rest of eventSender think a drag is in progress.
mustaqabca6ff2016-06-09 17:29:532060 current_pointer_state_[kRawMousePointerId].pressed_button_ =
nzolghadr656569e2016-08-19 16:53:002061 WebMouseEvent::Button::Left;
mustaqabca6ff2016-06-09 17:29:532062 current_pointer_state_[kRawMousePointerId].current_buttons_ |=
nzolghadr43146032016-04-11 15:33:382063 GetWebMouseEventModifierForButton(
mustaqabca6ff2016-06-09 17:29:532064 current_pointer_state_[kRawMousePointerId].pressed_button_);
[email protected]3db130e2014-03-27 08:14:482065}
2066
e.hakkinen80033922015-07-31 08:41:352067void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:482068 WebTouchPoint touch_point;
mustaqcc6220fa2016-03-09 22:07:542069 touch_point.pointerType = WebPointerProperties::PointerType::Touch;
[email protected]3db130e2014-03-27 08:14:482070 touch_point.state = WebTouchPoint::StatePressed;
e.hakkinen80033922015-07-31 08:41:352071 touch_point.position = WebFloatPoint(x, y);
[email protected]3db130e2014-03-27 08:14:482072 touch_point.screenPosition = touch_point.position;
2073
mustaq913e8922015-09-09 20:15:362074 int highest_id = -1;
[email protected]3db130e2014-03-27 08:14:482075 for (size_t i = 0; i < touch_points_.size(); i++) {
mustaq913e8922015-09-09 20:15:362076 if (touch_points_[i].id > highest_id)
2077 highest_id = touch_points_[i].id;
[email protected]3db130e2014-03-27 08:14:482078 }
mustaq913e8922015-09-09 20:15:362079 touch_point.id = highest_id + 1;
e.hakkinen80033922015-07-31 08:41:352080
2081 InitPointerProperties(args, &touch_point, &touch_point.radiusX,
2082 &touch_point.radiusY);
2083
nzolghadr88114bc2016-02-01 21:46:162084 // Set the touch point pressure to zero if it was not set by the caller
landell7d38a9a12016-02-04 16:34:552085 if (std::isnan(touch_point.force))
nzolghadr88114bc2016-02-01 21:46:162086 touch_point.force = 0.0;
2087
[email protected]3db130e2014-03-27 08:14:482088 touch_points_.push_back(touch_point);
2089}
2090
[email protected]3db130e2014-03-27 08:14:482091void EventSender::GestureScrollBegin(gin::Arguments* args) {
2092 GestureEvent(WebInputEvent::GestureScrollBegin, args);
2093}
2094
2095void EventSender::GestureScrollEnd(gin::Arguments* args) {
2096 GestureEvent(WebInputEvent::GestureScrollEnd, args);
2097}
2098
2099void EventSender::GestureScrollUpdate(gin::Arguments* args) {
2100 GestureEvent(WebInputEvent::GestureScrollUpdate, args);
2101}
2102
ccameronb81b8072015-01-30 00:54:492103void EventSender::GesturePinchBegin(gin::Arguments* args) {
2104 GestureEvent(WebInputEvent::GesturePinchBegin, args);
2105}
2106
2107void EventSender::GesturePinchEnd(gin::Arguments* args) {
2108 GestureEvent(WebInputEvent::GesturePinchEnd, args);
2109}
2110
2111void EventSender::GesturePinchUpdate(gin::Arguments* args) {
2112 GestureEvent(WebInputEvent::GesturePinchUpdate, args);
2113}
2114
[email protected]3db130e2014-03-27 08:14:482115void EventSender::GestureTap(gin::Arguments* args) {
2116 GestureEvent(WebInputEvent::GestureTap, args);
2117}
2118
2119void EventSender::GestureTapDown(gin::Arguments* args) {
2120 GestureEvent(WebInputEvent::GestureTapDown, args);
2121}
2122
2123void EventSender::GestureShowPress(gin::Arguments* args) {
2124 GestureEvent(WebInputEvent::GestureShowPress, args);
2125}
2126
2127void EventSender::GestureTapCancel(gin::Arguments* args) {
2128 GestureEvent(WebInputEvent::GestureTapCancel, args);
2129}
2130
2131void EventSender::GestureLongPress(gin::Arguments* args) {
2132 GestureEvent(WebInputEvent::GestureLongPress, args);
2133}
2134
2135void EventSender::GestureLongTap(gin::Arguments* args) {
2136 GestureEvent(WebInputEvent::GestureLongTap, args);
2137}
2138
2139void EventSender::GestureTwoFingerTap(gin::Arguments* args) {
2140 GestureEvent(WebInputEvent::GestureTwoFingerTap, args);
2141}
2142
dtapuska43f18e9e2016-03-20 20:21:302143void EventSender::MouseScrollBy(gin::Arguments* args,
2144 MouseScrollType scroll_type) {
dtapuska43f18e9e2016-03-20 20:21:302145 // TODO(dtapuska): Gestures really should be sent by the MouseWheelEventQueue
2146 // class in the browser. But since the event doesn't propogate up into
2147 // the browser generate the events here. See crbug.com/596095.
dtapuskab8b21412016-06-16 11:09:142148 bool send_gestures = true;
dtapuska899ac222017-01-03 18:09:162149 WebMouseWheelEvent wheel_event =
2150 GetMouseWheelEvent(args, scroll_type, &send_gestures);
dtapuska8c4dae12017-01-13 00:23:062151 if (wheel_event.type() != WebInputEvent::Undefined &&
dtapuska899ac222017-01-03 18:09:162152 HandleInputEventOnViewOrPopup(wheel_event) ==
dtapuska43f18e9e2016-03-20 20:21:302153 WebInputEventResult::NotHandled &&
2154 send_gestures) {
2155 SendGesturesForMouseWheelEvent(wheel_event);
2156 }
[email protected]3db130e2014-03-27 08:14:482157}
2158
[email protected]3db130e2014-03-27 08:14:482159void EventSender::MouseMoveTo(gin::Arguments* args) {
2160 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:342161 widget()->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:482162
[email protected]f53eba122014-04-16 11:30:012163 double x;
2164 double y;
mustaq0fff7fc32014-09-24 20:21:432165 if (!args->GetNext(&x) || !args->GetNext(&y)) {
2166 args->ThrowError();
2167 return;
2168 }
[email protected]f53eba122014-04-16 11:30:012169 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y));
[email protected]3db130e2014-03-27 08:14:482170
2171 int modifiers = 0;
nzolghadr43146032016-04-11 15:33:382172 if (!args->PeekNext().IsEmpty()) {
bashidbd2ef9bb2015-06-02 01:39:322173 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
nzolghadr43146032016-04-11 15:33:382174 args->Skip();
2175 }
[email protected]3db130e2014-03-27 08:14:482176
mustaqabca6ff2016-06-09 17:29:532177 WebPointerProperties::PointerType pointerType =
2178 WebPointerProperties::PointerType::Mouse;
2179 int pointerId = 0;
2180 float pressure = 0;
2181 int tiltX = 0;
2182 int tiltY = 0;
2183 if (!getMousePenPointerProperties(args, pointerType, pointerId, pressure,
2184 tiltX, tiltY))
nzolghadr43146032016-04-11 15:33:382185 return;
2186
mustaqabca6ff2016-06-09 17:29:532187 if (pointerType == WebPointerProperties::PointerType::Mouse &&
nzolghadr43146032016-04-11 15:33:382188 is_drag_mode_ && !replaying_saved_events_ &&
mustaqabca6ff2016-06-09 17:29:532189 current_pointer_state_[kRawMousePointerId].pressed_button_ ==
nzolghadr656569e2016-08-19 16:53:002190 WebMouseEvent::Button::Left) {
[email protected]3db130e2014-03-27 08:14:482191 SavedEvent saved_event;
2192 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE;
2193 saved_event.pos = mouse_pos;
2194 saved_event.modifiers = modifiers;
2195 mouse_event_queue_.push_back(saved_event);
2196 } else {
nzolghadr43146032016-04-11 15:33:382197 current_pointer_state_[pointerId].last_pos_ = mouse_pos;
dtapuska899ac222017-01-03 18:09:162198 current_pointer_state_[pointerId].modifiers_ = modifiers;
2199 WebMouseEvent event(WebInputEvent::MouseMove,
2200 ModifiersForPointer(pointerId),
2201 GetCurrentEventTimeSec());
mustaqabca6ff2016-06-09 17:29:532202 int click_count = pointerType == WebPointerProperties::PointerType::Mouse
2203 ? click_count_
2204 : 0;
2205 InitMouseEventGeneric(
mustaqabca6ff2016-06-09 17:29:532206 current_pointer_state_[kRawMousePointerId].pressed_button_,
2207 current_pointer_state_[kRawMousePointerId].current_buttons_, mouse_pos,
dtapuska899ac222017-01-03 18:09:162208 click_count, pointerType, pointerId, pressure, tiltX, tiltY, &event);
nzolghadr43146032016-04-11 15:33:382209 HandleInputEventOnViewOrPopup(event);
mustaqabca6ff2016-06-09 17:29:532210 if (pointerType == WebPointerProperties::PointerType::Mouse)
nzolghadr43146032016-04-11 15:33:382211 DoDragAfterMouseMove(event);
[email protected]3db130e2014-03-27 08:14:482212 }
2213}
2214
myid.shin12c7fea22015-03-06 02:31:242215void EventSender::MouseLeave() {
2216 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:342217 widget()->updateAllLifecyclePhases();
myid.shin12c7fea22015-03-06 02:31:242218
dtapuska899ac222017-01-03 18:09:162219 WebMouseEvent event(WebInputEvent::MouseLeave,
2220 ModifiersForPointer(kRawMousePointerId),
2221 GetCurrentEventTimeSec());
2222 InitMouseEvent(WebMouseEvent::Button::NoButton, 0,
mustaqabca6ff2016-06-09 17:29:532223 current_pointer_state_[kRawMousePointerId].last_pos_,
dtapuska899ac222017-01-03 18:09:162224 click_count_, &event);
thestigfd11ffe2015-12-30 19:25:452225 HandleInputEventOnViewOrPopup(event);
myid.shin12c7fea22015-03-06 02:31:242226}
2227
2228
[email protected]3db130e2014-03-27 08:14:482229void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) {
tzik5f3ffb22016-09-21 16:54:542230 delegate()->PostTask(base::Bind(&EventSender::MouseDown,
2231 weak_factory_.GetWeakPtr(), button_number,
2232 modifiers));
2233 delegate()->PostTask(base::Bind(&EventSender::MouseUp,
2234 weak_factory_.GetWeakPtr(), button_number,
2235 modifiers));
[email protected]3db130e2014-03-27 08:14:482236}
2237
2238void EventSender::ScheduleAsynchronousKeyDown(const std::string& code_str,
2239 int modifiers,
2240 KeyLocationCode location) {
tzik5f3ffb22016-09-21 16:54:542241 delegate()->PostTask(base::Bind(&EventSender::KeyDown,
2242 weak_factory_.GetWeakPtr(), code_str,
2243 modifiers, location));
[email protected]3db130e2014-03-27 08:14:482244}
2245
2246double EventSender::GetCurrentEventTimeSec() {
majidvpeabdeb82015-11-30 19:02:052247 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF() +
majidvpbfabb0712015-10-02 16:30:002248 time_offset_ms_ / 1000.0;
[email protected]3db130e2014-03-27 08:14:482249}
2250
2251void EventSender::DoLeapForward(int milliseconds) {
2252 time_offset_ms_ += milliseconds;
2253}
2254
mustaq19048372016-06-16 21:39:322255uint32_t EventSender::GetUniqueTouchEventId(gin::Arguments* args) {
2256 uint32_t unique_touch_event_id;
2257 if(!args->PeekNext().IsEmpty() && args->GetNext(&unique_touch_event_id))
2258 return unique_touch_event_id;
2259
2260 return 0;
2261}
2262
mustaq96985f722015-06-30 21:41:532263void EventSender::SendCurrentTouchEvent(WebInputEvent::Type type,
mustaq19048372016-06-16 21:39:322264 gin::Arguments* args) {
lanwei00f70892017-02-07 23:12:212265 uint32_t unique_touch_event_id = GetUniqueTouchEventId(args);
mustaq19048372016-06-16 21:39:322266
dtapuska8502cd582016-07-22 17:16:292267 DCHECK_GT(static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap),
[email protected]3db130e2014-03-27 08:14:482268 touch_points_.size());
2269 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:342270 widget()->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:482271
dtapuska899ac222017-01-03 18:09:162272 WebTouchEvent touch_event(type, touch_modifiers_, GetCurrentEventTimeSec());
dtapuskaafb8f542016-04-20 21:38:202273 touch_event.dispatchType = touch_cancelable_
2274 ? WebInputEvent::Blocking
2275 : WebInputEvent::EventNonBlocking;
lanwei00f70892017-02-07 23:12:212276 touch_event.movedBeyondSlopRegion = true;
mustaq19048372016-06-16 21:39:322277 touch_event.uniqueTouchEventId = unique_touch_event_id;
[email protected]3db130e2014-03-27 08:14:482278 touch_event.touchesLength = touch_points_.size();
2279 for (size_t i = 0; i < touch_points_.size(); ++i)
2280 touch_event.touches[i] = touch_points_[i];
tkent588765612014-11-28 01:07:482281 HandleInputEventOnViewOrPopup(touch_event);
[email protected]3db130e2014-03-27 08:14:482282
2283 for (size_t i = 0; i < touch_points_.size(); ++i) {
2284 WebTouchPoint* touch_point = &touch_points_[i];
mustaq913e8922015-09-09 20:15:362285 if (touch_point->state == WebTouchPoint::StateReleased
2286 || touch_point->state == WebTouchPoint::StateCancelled) {
[email protected]3db130e2014-03-27 08:14:482287 touch_points_.erase(touch_points_.begin() + i);
2288 --i;
thestigfd11ffe2015-12-30 19:25:452289 } else {
[email protected]3db130e2014-03-27 08:14:482290 touch_point->state = WebTouchPoint::StateStationary;
thestigfd11ffe2015-12-30 19:25:452291 }
[email protected]3db130e2014-03-27 08:14:482292 }
2293}
2294
2295void EventSender::GestureEvent(WebInputEvent::Type type,
majidvp41c4272a2014-12-08 15:51:142296 gin::Arguments* args) {
dtapuska899ac222017-01-03 18:09:162297 WebGestureEvent event(type, WebInputEvent::NoModifiers,
2298 GetCurrentEventTimeSec());
ccameronb81b8072015-01-30 00:54:492299
2300 // If the first argument is a string, it is to specify the device, otherwise
2301 // the device is assumed to be a touchscreen (since most tests were written
2302 // assuming this).
2303 event.sourceDevice = blink::WebGestureDeviceTouchscreen;
jochen87d2fee2015-07-13 08:21:342304 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) {
ccameronb81b8072015-01-30 00:54:492305 std::string device_string;
2306 if (!args->GetNext(&device_string)) {
2307 args->ThrowError();
2308 return;
2309 }
tdresser3a1c9722015-02-13 15:44:532310 if (device_string == kSourceDeviceStringTouchpad) {
ccameronb81b8072015-01-30 00:54:492311 event.sourceDevice = blink::WebGestureDeviceTouchpad;
tdresser3a1c9722015-02-13 15:44:532312 } else if (device_string == kSourceDeviceStringTouchscreen) {
ccameronb81b8072015-01-30 00:54:492313 event.sourceDevice = blink::WebGestureDeviceTouchscreen;
2314 } else {
2315 args->ThrowError();
2316 return;
2317 }
2318 }
2319
[email protected]3db130e2014-03-27 08:14:482320 double x;
2321 double y;
mustaq0fff7fc32014-09-24 20:21:432322 if (!args->GetNext(&x) || !args->GetNext(&y)) {
2323 args->ThrowError();
2324 return;
2325 }
[email protected]3db130e2014-03-27 08:14:482326
[email protected]3db130e2014-03-27 08:14:482327 switch (type) {
2328 case WebInputEvent::GestureScrollUpdate:
majidvp50205db2014-11-27 17:28:522329 {
majidvp41c4272a2014-12-08 15:51:142330 bool preventPropagation = false;
2331 if (!args->PeekNext().IsEmpty()) {
majidvp50205db2014-11-27 17:28:522332 if (!args->GetNext(&preventPropagation)) {
2333 args->ThrowError();
2334 return;
2335 }
2336 }
dtapuskab1c5ece2016-01-18 18:18:022337 if (!GetScrollUnits(args, &event.data.scrollUpdate.deltaUnits))
2338 return;
majidvp50205db2014-11-27 17:28:522339
[email protected]3db130e2014-03-27 08:14:482340 event.data.scrollUpdate.deltaX = static_cast<float>(x);
2341 event.data.scrollUpdate.deltaY = static_cast<float>(y);
majidvp50205db2014-11-27 17:28:522342 event.data.scrollUpdate.preventPropagation = preventPropagation;
[email protected]3db130e2014-03-27 08:14:482343 event.x = current_gesture_location_.x;
2344 event.y = current_gesture_location_.y;
2345 current_gesture_location_.x =
2346 current_gesture_location_.x + event.data.scrollUpdate.deltaX;
2347 current_gesture_location_.y =
2348 current_gesture_location_.y + event.data.scrollUpdate.deltaY;
2349 break;
majidvp50205db2014-11-27 17:28:522350 }
[email protected]3db130e2014-03-27 08:14:482351 case WebInputEvent::GestureScrollBegin:
mustaq0fff7fc32014-09-24 20:21:432352 current_gesture_location_ = WebPoint(x, y);
[email protected]3db130e2014-03-27 08:14:482353 event.x = current_gesture_location_.x;
2354 event.y = current_gesture_location_.y;
2355 break;
2356 case WebInputEvent::GestureScrollEnd:
2357 case WebInputEvent::GestureFlingStart:
2358 event.x = current_gesture_location_.x;
2359 event.y = current_gesture_location_.y;
2360 break;
ccameronb81b8072015-01-30 00:54:492361 case WebInputEvent::GesturePinchBegin:
2362 case WebInputEvent::GesturePinchEnd:
2363 current_gesture_location_ = WebPoint(x, y);
2364 event.x = current_gesture_location_.x;
2365 event.y = current_gesture_location_.y;
2366 break;
2367 case WebInputEvent::GesturePinchUpdate:
2368 {
2369 float scale = 1;
2370 if (!args->PeekNext().IsEmpty()) {
2371 if (!args->GetNext(&scale)) {
2372 args->ThrowError();
2373 return;
2374 }
2375 }
2376 event.data.pinchUpdate.scale = scale;
2377 current_gesture_location_ = WebPoint(x, y);
2378 event.x = current_gesture_location_.x;
2379 event.y = current_gesture_location_.y;
2380 break;
2381 }
[email protected]4c07a712014-08-21 17:05:542382 case WebInputEvent::GestureTap:
[email protected]c278d7532014-07-31 19:51:452383 {
2384 float tap_count = 1;
2385 float width = 30;
2386 float height = 30;
[email protected]3db130e2014-03-27 08:14:482387 if (!args->PeekNext().IsEmpty()) {
[email protected]3db130e2014-03-27 08:14:482388 if (!args->GetNext(&tap_count)) {
2389 args->ThrowError();
2390 return;
2391 }
[email protected]3db130e2014-03-27 08:14:482392 }
[email protected]cc42ccf2014-06-27 21:31:432393 if (!args->PeekNext().IsEmpty()) {
[email protected]cc42ccf2014-06-27 21:31:432394 if (!args->GetNext(&width)) {
2395 args->ThrowError();
2396 return;
2397 }
[email protected]cc42ccf2014-06-27 21:31:432398 }
2399 if (!args->PeekNext().IsEmpty()) {
[email protected]cc42ccf2014-06-27 21:31:432400 if (!args->GetNext(&height)) {
2401 args->ThrowError();
2402 return;
2403 }
[email protected]cc42ccf2014-06-27 21:31:432404 }
[email protected]c278d7532014-07-31 19:51:452405 event.data.tap.tapCount = tap_count;
2406 event.data.tap.width = width;
2407 event.data.tap.height = height;
mustaq0fff7fc32014-09-24 20:21:432408 event.x = x;
2409 event.y = y;
[email protected]3db130e2014-03-27 08:14:482410 break;
[email protected]c278d7532014-07-31 19:51:452411 }
[email protected]3db130e2014-03-27 08:14:482412 case WebInputEvent::GestureTapUnconfirmed:
2413 if (!args->PeekNext().IsEmpty()) {
2414 float tap_count;
2415 if (!args->GetNext(&tap_count)) {
2416 args->ThrowError();
2417 return;
2418 }
2419 event.data.tap.tapCount = tap_count;
2420 } else {
2421 event.data.tap.tapCount = 1;
2422 }
mustaq0fff7fc32014-09-24 20:21:432423 event.x = x;
2424 event.y = y;
[email protected]3db130e2014-03-27 08:14:482425 break;
2426 case WebInputEvent::GestureTapDown:
[email protected]c278d7532014-07-31 19:51:452427 {
2428 float width = 30;
2429 float height = 30;
[email protected]3db130e2014-03-27 08:14:482430 if (!args->PeekNext().IsEmpty()) {
[email protected]3db130e2014-03-27 08:14:482431 if (!args->GetNext(&width)) {
2432 args->ThrowError();
2433 return;
2434 }
[email protected]3db130e2014-03-27 08:14:482435 }
2436 if (!args->PeekNext().IsEmpty()) {
[email protected]3db130e2014-03-27 08:14:482437 if (!args->GetNext(&height)) {
2438 args->ThrowError();
2439 return;
2440 }
[email protected]3db130e2014-03-27 08:14:482441 }
mustaq0fff7fc32014-09-24 20:21:432442 event.x = x;
2443 event.y = y;
[email protected]c278d7532014-07-31 19:51:452444 event.data.tapDown.width = width;
2445 event.data.tapDown.height = height;
2446 break;
2447 }
2448 case WebInputEvent::GestureShowPress:
2449 {
2450 float width = 30;
2451 float height = 30;
[email protected]3db130e2014-03-27 08:14:482452 if (!args->PeekNext().IsEmpty()) {
[email protected]3db130e2014-03-27 08:14:482453 if (!args->GetNext(&width)) {
2454 args->ThrowError();
2455 return;
2456 }
[email protected]3db130e2014-03-27 08:14:482457 if (!args->PeekNext().IsEmpty()) {
[email protected]3db130e2014-03-27 08:14:482458 if (!args->GetNext(&height)) {
2459 args->ThrowError();
2460 return;
2461 }
[email protected]3db130e2014-03-27 08:14:482462 }
2463 }
mustaq0fff7fc32014-09-24 20:21:432464 event.x = x;
2465 event.y = y;
[email protected]c278d7532014-07-31 19:51:452466 event.data.showPress.width = width;
2467 event.data.showPress.height = height;
[email protected]3db130e2014-03-27 08:14:482468 break;
[email protected]c278d7532014-07-31 19:51:452469 }
[email protected]3db130e2014-03-27 08:14:482470 case WebInputEvent::GestureTapCancel:
mustaq0fff7fc32014-09-24 20:21:432471 event.x = x;
2472 event.y = y;
[email protected]3db130e2014-03-27 08:14:482473 break;
2474 case WebInputEvent::GestureLongPress:
[email protected]3db130e2014-03-27 08:14:482475 case WebInputEvent::GestureLongTap:
mustaq0fff7fc32014-09-24 20:21:432476 event.x = x;
2477 event.y = y;
[email protected]3db130e2014-03-27 08:14:482478 if (!args->PeekNext().IsEmpty()) {
2479 float width;
2480 if (!args->GetNext(&width)) {
2481 args->ThrowError();
2482 return;
2483 }
2484 event.data.longPress.width = width;
2485 if (!args->PeekNext().IsEmpty()) {
2486 float height;
2487 if (!args->GetNext(&height)) {
2488 args->ThrowError();
2489 return;
2490 }
2491 event.data.longPress.height = height;
2492 }
2493 }
2494 break;
2495 case WebInputEvent::GestureTwoFingerTap:
mustaq0fff7fc32014-09-24 20:21:432496 event.x = x;
2497 event.y = y;
[email protected]3db130e2014-03-27 08:14:482498 if (!args->PeekNext().IsEmpty()) {
2499 float first_finger_width;
2500 if (!args->GetNext(&first_finger_width)) {
2501 args->ThrowError();
2502 return;
2503 }
2504 event.data.twoFingerTap.firstFingerWidth = first_finger_width;
2505 if (!args->PeekNext().IsEmpty()) {
2506 float first_finger_height;
2507 if (!args->GetNext(&first_finger_height)) {
2508 args->ThrowError();
2509 return;
2510 }
2511 event.data.twoFingerTap.firstFingerHeight = first_finger_height;
2512 }
2513 }
2514 break;
2515 default:
2516 NOTREACHED();
2517 }
2518
mustaq19048372016-06-16 21:39:322519 event.uniqueTouchEventId = GetUniqueTouchEventId(args);
2520
[email protected]3db130e2014-03-27 08:14:482521 event.globalX = event.x;
2522 event.globalY = event.y;
[email protected]3db130e2014-03-27 08:14:482523
2524 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:342525 widget()->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:482526
dtapuska5d2e9c32015-12-03 16:39:492527 WebInputEventResult result = HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:482528
2529 // Long press might start a drag drop session. Complete it if so.
2530 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) {
dtapuska899ac222017-01-03 18:09:162531 WebMouseEvent mouse_event(WebInputEvent::MouseDown,
2532 ModifiersForPointer(kRawMousePointerId),
2533 GetCurrentEventTimeSec());
2534
2535 InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_,
mustaqabca6ff2016-06-09 17:29:532536 current_pointer_state_[kRawMousePointerId].current_buttons_,
dtapuska899ac222017-01-03 18:09:162537 WebPoint(x, y), click_count_, &mouse_event);
[email protected]3db130e2014-03-27 08:14:482538
2539 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone);
2540 }
dtapuska5d2e9c32015-12-03 16:39:492541 args->Return(result != WebInputEventResult::NotHandled);
[email protected]3db130e2014-03-27 08:14:482542}
2543
2544void EventSender::UpdateClickCountForButton(
2545 WebMouseEvent::Button button_type) {
2546 if ((GetCurrentEventTimeSec() - last_click_time_sec_ <
2547 kMultipleClickTimeSec) &&
nzolghadr43146032016-04-11 15:33:382548 (!OutsideMultiClickRadius(
mustaqabca6ff2016-06-09 17:29:532549 current_pointer_state_[kRawMousePointerId].last_pos_,
nzolghadr43146032016-04-11 15:33:382550 last_click_pos_)) &&
[email protected]3db130e2014-03-27 08:14:482551 (button_type == last_button_type_)) {
2552 ++click_count_;
2553 } else {
2554 click_count_ = 1;
2555 last_button_type_ = button_type;
2556 }
2557}
2558
dtapuska899ac222017-01-03 18:09:162559WebMouseWheelEvent EventSender::GetMouseWheelEvent(gin::Arguments* args,
2560 MouseScrollType scroll_type,
2561 bool* send_gestures) {
[email protected]3db130e2014-03-27 08:14:482562 // Force a layout here just to make sure every position has been
2563 // determined before we send events (as well as all the other methods
2564 // that send an event do).
2565 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:342566 widget()->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:482567
2568 double horizontal;
[email protected]3db130e2014-03-27 08:14:482569 double vertical;
dtapuska899ac222017-01-03 18:09:162570 if (!args->GetNext(&horizontal) || !args->GetNext(&vertical)) {
[email protected]3db130e2014-03-27 08:14:482571 args->ThrowError();
dtapuska899ac222017-01-03 18:09:162572 return WebMouseWheelEvent();
[email protected]3db130e2014-03-27 08:14:482573 }
2574
2575 bool paged = false;
2576 bool has_precise_scrolling_deltas = false;
2577 int modifiers = 0;
chongzb92d7112016-07-04 22:11:542578 WebMouseWheelEvent::Phase phase = WebMouseWheelEvent::PhaseNone;
yutakf3990fd2014-12-23 03:52:382579 if (!args->PeekNext().IsEmpty()) {
2580 args->GetNext(&paged);
2581 if (!args->PeekNext().IsEmpty()) {
2582 args->GetNext(&has_precise_scrolling_deltas);
lanweia93644f2015-01-21 22:00:332583 if (!args->PeekNext().IsEmpty()) {
deepak.s750d68f2015-04-30 07:32:412584 v8::Local<v8::Value> value;
lanweia93644f2015-01-21 22:00:332585 args->GetNext(&value);
bashidbd2ef9bb2015-06-02 01:39:322586 modifiers = GetKeyModifiersFromV8(args->isolate(), value);
dtapuska43f18e9e2016-03-20 20:21:302587 if (!args->PeekNext().IsEmpty()) {
dtapuskab8b21412016-06-16 11:09:142588 args->GetNext(send_gestures);
chongzb92d7112016-07-04 22:11:542589 if (!args->PeekNext().IsEmpty()) {
2590 v8::Local<v8::Value> phase_value;
2591 args->GetNext(&phase_value);
2592 phase = GetMouseWheelEventPhaseFromV8(phase_value);
2593 }
dtapuska43f18e9e2016-03-20 20:21:302594 }
lanweia93644f2015-01-21 22:00:332595 }
yutakf3990fd2014-12-23 03:52:382596 }
2597 }
[email protected]3db130e2014-03-27 08:14:482598
dtapuska899ac222017-01-03 18:09:162599 current_pointer_state_[kRawMousePointerId].modifiers_ = modifiers;
2600 WebMouseWheelEvent event(WebInputEvent::MouseWheel,
2601 ModifiersForPointer(kRawMousePointerId),
2602 GetCurrentEventTimeSec());
2603 InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_,
mustaqabca6ff2016-06-09 17:29:532604 current_pointer_state_[kRawMousePointerId].current_buttons_,
2605 current_pointer_state_[kRawMousePointerId].last_pos_,
dtapuska899ac222017-01-03 18:09:162606 click_count_, &event);
2607 event.wheelTicksX = static_cast<float>(horizontal);
2608 event.wheelTicksY = static_cast<float>(vertical);
2609 event.deltaX = event.wheelTicksX;
2610 event.deltaY = event.wheelTicksY;
2611 event.scrollByPage = paged;
2612 event.hasPreciseScrollingDeltas = has_precise_scrolling_deltas;
2613 event.phase = phase;
dtapuska43f18e9e2016-03-20 20:21:302614 if (scroll_type == MouseScrollType::PIXEL) {
dtapuska899ac222017-01-03 18:09:162615 event.wheelTicksX /= kScrollbarPixelsPerTick;
2616 event.wheelTicksY /= kScrollbarPixelsPerTick;
[email protected]3db130e2014-03-27 08:14:482617 } else {
dtapuska899ac222017-01-03 18:09:162618 event.deltaX *= kScrollbarPixelsPerTick;
2619 event.deltaY *= kScrollbarPixelsPerTick;
[email protected]3db130e2014-03-27 08:14:482620 }
dtapuska899ac222017-01-03 18:09:162621 return event;
[email protected]3db130e2014-03-27 08:14:482622}
2623
e.hakkinen80033922015-07-31 08:41:352624// Radius fields radius_x and radius_y should eventually be moved to
2625// WebPointerProperties.
2626// TODO(e_hakkinen): Drop radius_{x,y}_pointer parameters once that happens.
2627void EventSender::InitPointerProperties(gin::Arguments* args,
mustaqabca6ff2016-06-09 17:29:532628 WebPointerProperties* e,
e.hakkinen80033922015-07-31 08:41:352629 float* radius_x_pointer,
2630 float* radius_y_pointer) {
2631 if (!args->PeekNext().IsEmpty()) {
2632 double radius_x;
2633 if (!args->GetNext(&radius_x)) {
2634 args->ThrowError();
2635 return;
2636 }
2637
2638 double radius_y = radius_x;
2639 if (!args->PeekNext().IsEmpty()) {
2640 if (!args->GetNext(&radius_y)) {
2641 args->ThrowError();
2642 return;
2643 }
2644 }
2645
2646 *radius_x_pointer = static_cast<float>(radius_x);
2647 *radius_y_pointer = static_cast<float>(radius_y);
2648 }
2649
2650 if (!args->PeekNext().IsEmpty()) {
2651 double force;
2652 if (!args->GetNext(&force)) {
2653 args->ThrowError();
2654 return;
2655 }
2656 e->force = static_cast<float>(force);
2657 }
2658
2659 if (!args->PeekNext().IsEmpty()) {
2660 int tiltX, tiltY;
2661 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) {
2662 args->ThrowError();
2663 return;
2664 }
2665 e->tiltX = tiltX;
2666 e->tiltY = tiltY;
2667 }
2668
nzolghadr43146032016-04-11 15:33:382669 if (!getPointerType(args, false, e->pointerType))
2670 return;
e.hakkinen80033922015-07-31 08:41:352671}
2672
lukaszad322c5ca2016-10-07 00:32:342673void EventSender::FinishDragAndDrop(const WebMouseEvent& raw_event,
oshima76b6eeb2016-06-27 15:55:122674 blink::WebDragOperation drag_effect) {
lukaszad322c5ca2016-10-07 00:32:342675 std::unique_ptr<WebInputEvent> widget_event =
2676 TransformScreenToWidgetCoordinates(raw_event);
oshima76b6eeb2016-06-27 15:55:122677 const WebMouseEvent* event =
lukaszad322c5ca2016-10-07 00:32:342678 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2679 : &raw_event;
oshima76b6eeb2016-06-27 15:55:122680
2681 WebPoint client_point(event->x, event->y);
2682 WebPoint screen_point(event->globalX, event->globalY);
[email protected]3db130e2014-03-27 08:14:482683 current_drag_effect_ = drag_effect;
2684 if (current_drag_effect_) {
2685 // Specifically pass any keyboard modifiers to the drop method. This allows
2686 // tests to control the drop type (i.e. copy or move).
paulmeyer90f6c31d2016-11-12 00:17:592687 mainFrameWidget()->dragTargetDrop(current_drag_data_, client_point,
dtapuska8c4dae12017-01-13 00:23:062688 screen_point, event->modifiers());
[email protected]3db130e2014-03-27 08:14:482689 } else {
kenrb07c272802017-02-07 23:48:172690 mainFrameWidget()->dragTargetDragLeave(blink::WebPoint(),
2691 blink::WebPoint());
[email protected]3db130e2014-03-27 08:14:482692 }
mustaqf2d3dd782016-07-14 17:22:062693 current_drag_data_.reset();
paulmeyer8fc8ea92016-11-15 05:12:212694 mainFrameWidget()->dragSourceEndedAt(client_point, screen_point,
2695 current_drag_effect_);
2696 mainFrameWidget()->dragSourceSystemDragEnded();
[email protected]3db130e2014-03-27 08:14:482697}
2698
lukaszad322c5ca2016-10-07 00:32:342699void EventSender::DoDragAfterMouseUp(const WebMouseEvent& raw_event) {
2700 std::unique_ptr<WebInputEvent> widget_event =
2701 TransformScreenToWidgetCoordinates(raw_event);
oshima76b6eeb2016-06-27 15:55:122702 const WebMouseEvent* event =
lukaszad322c5ca2016-10-07 00:32:342703 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2704 : &raw_event;
oshima76b6eeb2016-06-27 15:55:122705
dtapuska8c4dae12017-01-13 00:23:062706 last_click_time_sec_ = event->timeStampSeconds();
mustaqabca6ff2016-06-09 17:29:532707 last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_;
[email protected]3db130e2014-03-27 08:14:482708
2709 // If we're in a drag operation, complete it.
2710 if (current_drag_data_.isNull())
2711 return;
2712
oshima76b6eeb2016-06-27 15:55:122713 WebPoint client_point(event->x, event->y);
2714 WebPoint screen_point(event->globalX, event->globalY);
paulmeyer90f6c31d2016-11-12 00:17:592715 blink::WebDragOperation drag_effect = mainFrameWidget()->dragTargetDragOver(
oshima76b6eeb2016-06-27 15:55:122716 client_point, screen_point, current_drag_effects_allowed_,
dtapuska8c4dae12017-01-13 00:23:062717 event->modifiers());
sigbjornf8d568b122016-02-24 21:29:472718
2719 // Bail if dragover caused cancellation.
2720 if (current_drag_data_.isNull())
2721 return;
2722
lukaszad322c5ca2016-10-07 00:32:342723 FinishDragAndDrop(raw_event, drag_effect);
[email protected]3db130e2014-03-27 08:14:482724}
2725
lukaszad322c5ca2016-10-07 00:32:342726void EventSender::DoDragAfterMouseMove(const WebMouseEvent& raw_event) {
mustaqabca6ff2016-06-09 17:29:532727 if (current_pointer_state_[kRawMousePointerId].pressed_button_ ==
nzolghadr656569e2016-08-19 16:53:002728 WebMouseEvent::Button::NoButton ||
[email protected]3db130e2014-03-27 08:14:482729 current_drag_data_.isNull()) {
2730 return;
2731 }
2732
lukaszad322c5ca2016-10-07 00:32:342733 std::unique_ptr<WebInputEvent> widget_event =
2734 TransformScreenToWidgetCoordinates(raw_event);
oshima76b6eeb2016-06-27 15:55:122735 const WebMouseEvent* event =
lukaszad322c5ca2016-10-07 00:32:342736 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2737 : &raw_event;
oshima76b6eeb2016-06-27 15:55:122738
2739 WebPoint client_point(event->x, event->y);
2740 WebPoint screen_point(event->globalX, event->globalY);
paulmeyer90f6c31d2016-11-12 00:17:592741 current_drag_effect_ = mainFrameWidget()->dragTargetDragOver(
oshima76b6eeb2016-06-27 15:55:122742 client_point, screen_point, current_drag_effects_allowed_,
dtapuska8c4dae12017-01-13 00:23:062743 event->modifiers());
[email protected]3db130e2014-03-27 08:14:482744}
2745
2746void EventSender::ReplaySavedEvents() {
2747 replaying_saved_events_ = true;
2748 while (!mouse_event_queue_.empty()) {
2749 SavedEvent e = mouse_event_queue_.front();
2750 mouse_event_queue_.pop_front();
2751
2752 switch (e.type) {
2753 case SavedEvent::TYPE_MOUSE_MOVE: {
dtapuska899ac222017-01-03 18:09:162754 current_pointer_state_[kRawMousePointerId].modifiers_ = e.modifiers;
2755 WebMouseEvent event(WebInputEvent::MouseMove,
2756 ModifiersForPointer(kRawMousePointerId),
2757 GetCurrentEventTimeSec());
nzolghadr43146032016-04-11 15:33:382758 InitMouseEvent(
mustaqabca6ff2016-06-09 17:29:532759 current_pointer_state_[kRawMousePointerId].pressed_button_,
2760 current_pointer_state_[kRawMousePointerId].current_buttons_, e.pos,
dtapuska899ac222017-01-03 18:09:162761 click_count_, &event);
mustaqabca6ff2016-06-09 17:29:532762 current_pointer_state_[kRawMousePointerId].last_pos_ =
nzolghadr43146032016-04-11 15:33:382763 WebPoint(event.x, event.y);
2764 HandleInputEventOnViewOrPopup(event);
2765 DoDragAfterMouseMove(event);
[email protected]3db130e2014-03-27 08:14:482766 break;
2767 }
2768 case SavedEvent::TYPE_LEAP_FORWARD:
2769 DoLeapForward(e.milliseconds);
2770 break;
2771 case SavedEvent::TYPE_MOUSE_UP: {
mustaqabca6ff2016-06-09 17:29:532772 current_pointer_state_[kRawMousePointerId].current_buttons_ &=
nzolghadr43146032016-04-11 15:33:382773 ~GetWebMouseEventModifierForButton(e.button_type);
mustaqabca6ff2016-06-09 17:29:532774 current_pointer_state_[kRawMousePointerId].pressed_button_ =
nzolghadr656569e2016-08-19 16:53:002775 WebMouseEvent::Button::NoButton;
dtapuska899ac222017-01-03 18:09:162776 current_pointer_state_[kRawMousePointerId].modifiers_ = e.modifiers;
mustaq21aed4e2015-12-15 21:47:212777
dtapuska899ac222017-01-03 18:09:162778 WebMouseEvent event(WebInputEvent::MouseUp,
2779 ModifiersForPointer(kRawMousePointerId),
2780 GetCurrentEventTimeSec());
mustaqabca6ff2016-06-09 17:29:532781 InitMouseEvent(
dtapuska899ac222017-01-03 18:09:162782 e.button_type,
mustaqabca6ff2016-06-09 17:29:532783 current_pointer_state_[kRawMousePointerId].current_buttons_,
dtapuska899ac222017-01-03 18:09:162784 current_pointer_state_[kRawMousePointerId].last_pos_, click_count_,
2785 &event);
nzolghadr43146032016-04-11 15:33:382786 HandleInputEventOnViewOrPopup(event);
2787 DoDragAfterMouseUp(event);
[email protected]3db130e2014-03-27 08:14:482788 break;
2789 }
2790 default:
2791 NOTREACHED();
2792 }
2793 }
2794
2795 replaying_saved_events_ = false;
2796}
2797
dtapuska5d2e9c32015-12-03 16:39:492798WebInputEventResult EventSender::HandleInputEventOnViewOrPopup(
lukaszad322c5ca2016-10-07 00:32:342799 const WebInputEvent& raw_event) {
dtapuska8c4dae12017-01-13 00:23:062800 last_event_timestamp_ = raw_event.timeStampSeconds();
oshima76b6eeb2016-06-27 15:55:122801
lukaszad322c5ca2016-10-07 00:32:342802 WebPagePopup* popup = widget()->pagePopup();
dtapuska8c4dae12017-01-13 00:23:062803 if (popup && !WebInputEvent::isKeyboardEventType(raw_event.type())) {
lukaszad322c5ca2016-10-07 00:32:342804 // ui::ScaleWebInputEvent returns nullptr when the scale is 1.0f as the
2805 // event does not have to be converted.
2806 std::unique_ptr<WebInputEvent> scaled_event = ui::ScaleWebInputEvent(
2807 raw_event, delegate()->GetWindowToViewportScale());
2808 const WebInputEvent* popup_friendly_event =
2809 scaled_event.get() ? scaled_event.get() : &raw_event;
nzolghadr5d8596502017-01-23 22:59:352810 return popup->handleInputEvent(
2811 blink::WebCoalescedInputEvent(*popup_friendly_event));
tkent588765612014-11-28 01:07:482812 }
lukaszad322c5ca2016-10-07 00:32:342813
2814 std::unique_ptr<WebInputEvent> widget_event =
2815 TransformScreenToWidgetCoordinates(raw_event);
2816 const WebInputEvent* event =
2817 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2818 : &raw_event;
nzolghadr5d8596502017-01-23 22:59:352819 return widget()->handleInputEvent(blink::WebCoalescedInputEvent(*event));
tkent588765612014-11-28 01:07:482820}
2821
dtapuska43f18e9e2016-03-20 20:21:302822void EventSender::SendGesturesForMouseWheelEvent(
2823 const WebMouseWheelEvent wheel_event) {
dtapuska899ac222017-01-03 18:09:162824 WebGestureEvent begin_event(WebInputEvent::GestureScrollBegin,
dtapuska8c4dae12017-01-13 00:23:062825 wheel_event.modifiers(),
2826 GetCurrentEventTimeSec());
dtapuska899ac222017-01-03 18:09:162827 InitGestureEventFromMouseWheel(wheel_event, &begin_event);
dtapuska43f18e9e2016-03-20 20:21:302828 begin_event.data.scrollBegin.deltaXHint = wheel_event.deltaX;
2829 begin_event.data.scrollBegin.deltaYHint = wheel_event.deltaY;
2830 if (wheel_event.scrollByPage) {
2831 begin_event.data.scrollBegin.deltaHintUnits = blink::WebGestureEvent::Page;
2832 if (begin_event.data.scrollBegin.deltaXHint) {
2833 begin_event.data.scrollBegin.deltaXHint =
2834 begin_event.data.scrollBegin.deltaXHint > 0 ? 1 : -1;
2835 }
2836 if (begin_event.data.scrollBegin.deltaYHint) {
2837 begin_event.data.scrollBegin.deltaYHint =
2838 begin_event.data.scrollBegin.deltaYHint > 0 ? 1 : -1;
2839 }
2840 } else {
2841 begin_event.data.scrollBegin.deltaHintUnits =
2842 wheel_event.hasPreciseScrollingDeltas
2843 ? blink::WebGestureEvent::PrecisePixels
2844 : blink::WebGestureEvent::Pixels;
2845 }
2846
2847 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:342848 widget()->updateAllLifecyclePhases();
dtapuska43f18e9e2016-03-20 20:21:302849
2850 HandleInputEventOnViewOrPopup(begin_event);
2851
dtapuska899ac222017-01-03 18:09:162852 WebGestureEvent update_event(WebInputEvent::GestureScrollUpdate,
dtapuska8c4dae12017-01-13 00:23:062853 wheel_event.modifiers(),
2854 GetCurrentEventTimeSec());
dtapuska899ac222017-01-03 18:09:162855 InitGestureEventFromMouseWheel(wheel_event, &update_event);
dtapuska43f18e9e2016-03-20 20:21:302856 update_event.data.scrollUpdate.deltaX =
2857 begin_event.data.scrollBegin.deltaXHint;
2858 update_event.data.scrollUpdate.deltaY =
2859 begin_event.data.scrollBegin.deltaYHint;
2860 update_event.data.scrollUpdate.deltaUnits =
2861 begin_event.data.scrollBegin.deltaHintUnits;
2862
2863 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:342864 widget()->updateAllLifecyclePhases();
dtapuska43f18e9e2016-03-20 20:21:302865 HandleInputEventOnViewOrPopup(update_event);
2866
dtapuska899ac222017-01-03 18:09:162867 WebGestureEvent end_event(WebInputEvent::GestureScrollEnd,
dtapuska8c4dae12017-01-13 00:23:062868 wheel_event.modifiers(), GetCurrentEventTimeSec());
dtapuska899ac222017-01-03 18:09:162869 InitGestureEventFromMouseWheel(wheel_event, &end_event);
dtapuska43f18e9e2016-03-20 20:21:302870 end_event.data.scrollEnd.deltaUnits =
2871 begin_event.data.scrollBegin.deltaHintUnits;
2872
2873 if (force_layout_on_events_)
lukaszad322c5ca2016-10-07 00:32:342874 widget()->updateAllLifecyclePhases();
dtapuska43f18e9e2016-03-20 20:21:302875 HandleInputEventOnViewOrPopup(end_event);
2876}
2877
lukasza335bb762016-04-22 16:44:032878TestInterfaces* EventSender::interfaces() {
lukaszad322c5ca2016-10-07 00:32:342879 return web_widget_test_proxy_base_->web_view_test_proxy_base()
2880 ->test_interfaces();
lukasza335bb762016-04-22 16:44:032881}
2882
2883WebTestDelegate* EventSender::delegate() {
lukaszad322c5ca2016-10-07 00:32:342884 return web_widget_test_proxy_base_->web_view_test_proxy_base()->delegate();
lukasza335bb762016-04-22 16:44:032885}
2886
2887const blink::WebView* EventSender::view() const {
lukaszad322c5ca2016-10-07 00:32:342888 return web_widget_test_proxy_base_->web_view_test_proxy_base()->web_view();
lukasza335bb762016-04-22 16:44:032889}
2890
2891blink::WebView* EventSender::view() {
lukaszad322c5ca2016-10-07 00:32:342892 return web_widget_test_proxy_base_->web_view_test_proxy_base()->web_view();
lukasza335bb762016-04-22 16:44:032893}
2894
lukaszad322c5ca2016-10-07 00:32:342895blink::WebWidget* EventSender::widget() {
2896 return web_widget_test_proxy_base_->web_widget();
2897}
2898
paulmeyer90f6c31d2016-11-12 00:17:592899blink::WebFrameWidget* EventSender::mainFrameWidget() {
2900 return view()->mainFrame()->toWebLocalFrame()->frameWidget();
2901}
2902
lukaszad322c5ca2016-10-07 00:32:342903std::unique_ptr<WebInputEvent> EventSender::TransformScreenToWidgetCoordinates(
oshima76b6eeb2016-06-27 15:55:122904 const WebInputEvent& event) {
lukaszad322c5ca2016-10-07 00:32:342905 return delegate()->TransformScreenToWidgetCoordinates(
2906 web_widget_test_proxy_base_, event);
oshima76b6eeb2016-06-27 15:55:122907}
2908
jochenf5f31752015-06-03 12:06:342909} // namespace test_runner