blob: 18f52929021a0736a01c76be74845648bfd3b6f3 [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
7#include "base/basictypes.h"
8#include "base/logging.h"
esprehnd29ab802015-12-11 13:01:199#include "base/strings/string16.h"
habib.virji565c80c2015-02-06 12:26:4310#include "base/strings/string_util.h"
[email protected]3db130e2014-03-27 08:14:4811#include "base/strings/stringprintf.h"
esprehnd29ab802015-12-11 13:01:1912#include "base/strings/utf_string_conversions.h"
jochen73e711c2015-06-03 10:01:4613#include "components/test_runner/mock_spell_check.h"
14#include "components/test_runner/test_interfaces.h"
15#include "components/test_runner/web_test_delegate.h"
16#include "components/test_runner/web_test_proxy.h"
[email protected]3db130e2014-03-27 08:14:4817#include "gin/handle.h"
18#include "gin/object_template_builder.h"
19#include "gin/wrappable.h"
20#include "third_party/WebKit/public/platform/WebString.h"
21#include "third_party/WebKit/public/platform/WebVector.h"
22#include "third_party/WebKit/public/web/WebContextMenuData.h"
23#include "third_party/WebKit/public/web/WebFrame.h"
24#include "third_party/WebKit/public/web/WebKit.h"
tkent588765612014-11-28 01:07:4825#include "third_party/WebKit/public/web/WebPagePopup.h"
[email protected]3db130e2014-03-27 08:14:4826#include "third_party/WebKit/public/web/WebView.h"
kpschoedel3b0960a2015-05-11 17:52:1127#include "ui/events/keycodes/dom/keycode_converter.h"
[email protected]a731f1a92014-04-17 19:31:0628#include "ui/events/keycodes/keyboard_codes.h"
[email protected]3db130e2014-03-27 08:14:4829#include "v8/include/v8.h"
30
[email protected]3db130e2014-03-27 08:14:4831using blink::WebContextMenuData;
32using blink::WebDragData;
33using blink::WebDragOperationsMask;
34using blink::WebFloatPoint;
35using blink::WebFrame;
36using blink::WebGestureEvent;
37using blink::WebInputEvent;
dtapuska5d2e9c32015-12-03 16:39:4938using blink::WebInputEventResult;
[email protected]3db130e2014-03-27 08:14:4839using blink::WebKeyboardEvent;
[email protected]f9634a82014-08-05 13:10:1940using blink::WebMenuItemInfo;
[email protected]3db130e2014-03-27 08:14:4841using blink::WebMouseEvent;
42using blink::WebMouseWheelEvent;
tkent588765612014-11-28 01:07:4843using blink::WebPagePopup;
[email protected]3db130e2014-03-27 08:14:4844using blink::WebPoint;
45using blink::WebString;
46using blink::WebTouchEvent;
47using blink::WebTouchPoint;
48using blink::WebVector;
49using blink::WebView;
50
jochenf5f31752015-06-03 12:06:3451namespace test_runner {
[email protected]3db130e2014-03-27 08:14:4852
53namespace {
54
mustaq8911f4e2015-10-27 18:10:2255WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) {
56 switch (button_code) {
57 case -1:
58 return WebMouseEvent::ButtonNone;
59 case 0:
60 return WebMouseEvent::ButtonLeft;
61 case 1:
62 return WebMouseEvent::ButtonMiddle;
63 case 2:
64 return WebMouseEvent::ButtonRight;
65 }
66 NOTREACHED();
67 return WebMouseEvent::ButtonNone;
68}
69
mustaq21aed4e2015-12-15 21:47:2170int GetWebMouseEventModifierForButton(WebMouseEvent::Button button) {
71 switch (button) {
72 case WebMouseEvent::ButtonNone:
73 return 0;
74 case WebMouseEvent::ButtonLeft:
75 return WebMouseEvent::LeftButtonDown;
76 case WebMouseEvent::ButtonMiddle:
77 return WebMouseEvent::MiddleButtonDown;
78 case WebMouseEvent::ButtonRight:
79 return WebMouseEvent::RightButtonDown;
80 }
81 NOTREACHED();
82 return 0;
83}
84
85const int kButtonsInModifiers = WebMouseEvent::LeftButtonDown
86 | WebMouseEvent::MiddleButtonDown | WebMouseEvent::RightButtonDown;
87
[email protected]3db130e2014-03-27 08:14:4888void InitMouseEvent(WebInputEvent::Type t,
89 WebMouseEvent::Button b,
mustaq21aed4e2015-12-15 21:47:2190 int current_buttons,
[email protected]3db130e2014-03-27 08:14:4891 const WebPoint& pos,
92 double time_stamp,
93 int click_count,
94 int modifiers,
95 WebMouseEvent* e) {
96 e->type = t;
97 e->button = b;
mustaq21aed4e2015-12-15 21:47:2198 e->modifiers = (modifiers & ~kButtonsInModifiers)
99 | (current_buttons & kButtonsInModifiers);
[email protected]3db130e2014-03-27 08:14:48100 e->x = pos.x;
101 e->y = pos.y;
102 e->globalX = pos.x;
103 e->globalY = pos.y;
nzolghadr06d3f722015-12-02 20:06:51104 e->pointerType = blink::WebPointerProperties::PointerType::Mouse;
[email protected]3db130e2014-03-27 08:14:48105 e->timeStampSeconds = time_stamp;
106 e->clickCount = click_count;
107}
108
109int GetKeyModifier(const std::string& modifier_name) {
110 const char* characters = modifier_name.c_str();
111 if (!strcmp(characters, "ctrlKey")
112#ifndef __APPLE__
113 || !strcmp(characters, "addSelectionKey")
114#endif
115 ) {
116 return WebInputEvent::ControlKey;
117 } else if (!strcmp(characters, "shiftKey") ||
118 !strcmp(characters, "rangeSelectionKey")) {
119 return WebInputEvent::ShiftKey;
120 } else if (!strcmp(characters, "altKey")) {
121 return WebInputEvent::AltKey;
122#ifdef __APPLE__
123 } else if (!strcmp(characters, "metaKey") ||
124 !strcmp(characters, "addSelectionKey")) {
125 return WebInputEvent::MetaKey;
126#else
127 } else if (!strcmp(characters, "metaKey")) {
128 return WebInputEvent::MetaKey;
129#endif
130 } else if (!strcmp(characters, "autoRepeat")) {
131 return WebInputEvent::IsAutoRepeat;
132 } else if (!strcmp(characters, "copyKey")) {
133#ifdef __APPLE__
134 return WebInputEvent::AltKey;
135#else
136 return WebInputEvent::ControlKey;
137#endif
tkentc8c0bc82015-10-15 22:43:48138 } else if (!strcmp(characters, "accessKey")) {
139#ifdef __APPLE__
140 return WebInputEvent::AltKey | WebInputEvent::ControlKey;
141#else
142 return WebInputEvent::AltKey;
143#endif
jinho.bangffc700e2014-11-17 04:05:26144 } else if (!strcmp(characters, "leftButton")) {
145 return WebInputEvent::LeftButtonDown;
146 } else if (!strcmp(characters, "middleButton")) {
147 return WebInputEvent::MiddleButtonDown;
148 } else if (!strcmp(characters, "rightButton")) {
149 return WebInputEvent::RightButtonDown;
dtapuska299efe12015-10-05 16:53:44150 } else if (!strcmp(characters, "capsLockOn")) {
151 return WebInputEvent::CapsLockOn;
152 } else if (!strcmp(characters, "numLockOn")) {
153 return WebInputEvent::NumLockOn;
154 } else if (!strcmp(characters, "locationLeft")) {
155 return WebInputEvent::IsLeft;
156 } else if (!strcmp(characters, "locationRight")) {
157 return WebInputEvent::IsRight;
158 } else if (!strcmp(characters, "locationNumpad")) {
159 return WebInputEvent::IsKeyPad;
160 } else if (!strcmp(characters, "isComposing")) {
161 return WebInputEvent::IsComposing;
162 } else if (!strcmp(characters, "altGraphKey")) {
163 return WebInputEvent::AltGrKey;
164 } else if (!strcmp(characters, "osKey")) {
165 return WebInputEvent::OSKey;
166 } else if (!strcmp(characters, "fnKey")) {
167 return WebInputEvent::FnKey;
168 } else if (!strcmp(characters, "symbolKey")) {
169 return WebInputEvent::SymbolKey;
170 } else if (!strcmp(characters, "scrollLockOn")) {
171 return WebInputEvent::ScrollLockOn;
[email protected]3db130e2014-03-27 08:14:48172 }
173
174 return 0;
175}
176
177int GetKeyModifiers(const std::vector<std::string>& modifier_names) {
178 int modifiers = 0;
179 for (std::vector<std::string>::const_iterator it = modifier_names.begin();
180 it != modifier_names.end(); ++it) {
181 modifiers |= GetKeyModifier(*it);
182 }
183 return modifiers;
184}
185
bashidbd2ef9bb2015-06-02 01:39:32186int GetKeyModifiersFromV8(v8::Isolate* isolate, v8::Local<v8::Value> value) {
[email protected]3db130e2014-03-27 08:14:48187 std::vector<std::string> modifier_names;
188 if (value->IsString()) {
189 modifier_names.push_back(gin::V8ToString(value));
190 } else if (value->IsArray()) {
191 gin::Converter<std::vector<std::string> >::FromV8(
bashidbd2ef9bb2015-06-02 01:39:32192 isolate, value, &modifier_names);
[email protected]3db130e2014-03-27 08:14:48193 }
194 return GetKeyModifiers(modifier_names);
195}
196
197// Maximum distance (in space and time) for a mouse click to register as a
198// double or triple click.
199const double kMultipleClickTimeSec = 1;
200const int kMultipleClickRadiusPixels = 5;
[email protected]f9634a82014-08-05 13:10:19201const char kSubMenuDepthIdentifier[] = "_";
202const char kSubMenuIdentifier[] = " >";
sanjoy.pal362c3252014-08-26 08:07:08203const char kSeparatorIdentifier[] = "---------";
sanjoy.pala62675e2014-11-27 00:47:29204const char kDisabledIdentifier[] = "#";
205const char kCheckedIdentifier[] = "*";
[email protected]3db130e2014-03-27 08:14:48206
207bool OutsideMultiClickRadius(const WebPoint& a, const WebPoint& b) {
208 return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) >
209 kMultipleClickRadiusPixels * kMultipleClickRadiusPixels;
210}
211
[email protected]f9634a82014-08-05 13:10:19212void PopulateCustomItems(const WebVector<WebMenuItemInfo>& customItems,
213 const std::string& prefix, std::vector<std::string>* strings) {
214 for (size_t i = 0; i < customItems.size(); ++i) {
sanjoy.pala62675e2014-11-27 00:47:29215 std::string prefixCopy = prefix;
216 if (!customItems[i].enabled)
217 prefixCopy = kDisabledIdentifier + prefix;
218 if (customItems[i].checked)
219 prefixCopy = kCheckedIdentifier + prefix;
sanjoy.pal362c3252014-08-26 08:07:08220 if (customItems[i].type == blink::WebMenuItemInfo::Separator) {
sanjoy.pala62675e2014-11-27 00:47:29221 strings->push_back(prefixCopy + kSeparatorIdentifier);
sanjoy.pal362c3252014-08-26 08:07:08222 } else if (customItems[i].type == blink::WebMenuItemInfo::SubMenu) {
sanjoy.pala62675e2014-11-27 00:47:29223 strings->push_back(prefixCopy + customItems[i].label.utf8() +
sanjoy.pal2adb5c52015-01-13 11:26:49224 customItems[i].icon.utf8() + kSubMenuIdentifier);
sanjoy.pala62675e2014-11-27 00:47:29225 PopulateCustomItems(customItems[i].subMenuItems, prefixCopy +
[email protected]f9634a82014-08-05 13:10:19226 kSubMenuDepthIdentifier, strings);
227 } else {
sanjoy.pal2adb5c52015-01-13 11:26:49228 strings->push_back(prefixCopy + customItems[i].label.utf8() +
229 customItems[i].icon.utf8());
[email protected]f9634a82014-08-05 13:10:19230 }
231 }
232}
233
[email protected]3db130e2014-03-27 08:14:48234// Because actual context menu is implemented by the browser side,
235// this function does only what LayoutTests are expecting:
236// - Many test checks the count of items. So returning non-zero value makes
237// sense.
238// - Some test compares the count before and after some action. So changing the
239// count based on flags also makes sense. This function is doing such for some
240// flags.
241// - Some test even checks actual string content. So providing it would be also
242// helpful.
243std::vector<std::string> MakeMenuItemStringsFor(
244 WebContextMenuData* context_menu,
[email protected]79ecada2014-05-04 05:16:16245 WebTestDelegate* delegate) {
[email protected]3db130e2014-03-27 08:14:48246 // These constants are based on Safari's context menu because tests are made
247 // for it.
248 static const char* kNonEditableMenuStrings[] = {
249 "Back",
250 "Reload Page",
251 "Open in Dashbaord",
252 "<separator>",
253 "View Source",
254 "Save Page As",
255 "Print Page",
256 "Inspect Element",
257 0
258 };
259 static const char* kEditableMenuStrings[] = {
260 "Cut",
261 "Copy",
262 "<separator>",
263 "Paste",
264 "Spelling and Grammar",
265 "Substitutions, Transformations",
266 "Font",
267 "Speech",
268 "Paragraph Direction",
269 "<separator>",
270 0
271 };
272
273 // This is possible because mouse events are cancelleable.
274 if (!context_menu)
275 return std::vector<std::string>();
276
277 std::vector<std::string> strings;
278
[email protected]f9634a82014-08-05 13:10:19279 // Populate custom menu items if provided by blink.
280 PopulateCustomItems(context_menu->customItems, "", &strings);
281
[email protected]3db130e2014-03-27 08:14:48282 if (context_menu->isEditable) {
283 for (const char** item = kEditableMenuStrings; *item; ++item) {
284 strings.push_back(*item);
285 }
286 WebVector<WebString> suggestions;
[email protected]f656a652014-07-25 12:19:52287 MockSpellCheck::FillSuggestionList(context_menu->misspelledWord,
288 &suggestions);
[email protected]3db130e2014-03-27 08:14:48289 for (size_t i = 0; i < suggestions.size(); ++i) {
290 strings.push_back(suggestions[i].utf8());
291 }
292 } else {
293 for (const char** item = kNonEditableMenuStrings; *item; ++item) {
294 strings.push_back(*item);
295 }
296 }
297
298 return strings;
299}
300
301// How much we should scroll per event - the value here is chosen to match the
302// WebKit impl and layout test results.
303const float kScrollbarPixelsPerTick = 40.0f;
304
[email protected]79ecada2014-05-04 05:16:16305class MouseDownTask : public WebMethodTask<EventSender> {
[email protected]3db130e2014-03-27 08:14:48306 public:
307 MouseDownTask(EventSender* obj, int button_number, int modifiers)
308 : WebMethodTask<EventSender>(obj),
309 button_number_(button_number),
310 modifiers_(modifiers) {}
311
dchenge933b3e2014-10-21 11:44:09312 void RunIfValid() override { object_->MouseDown(button_number_, modifiers_); }
[email protected]3db130e2014-03-27 08:14:48313
314 private:
315 int button_number_;
316 int modifiers_;
317};
318
[email protected]79ecada2014-05-04 05:16:16319class MouseUpTask : public WebMethodTask<EventSender> {
[email protected]3db130e2014-03-27 08:14:48320 public:
321 MouseUpTask(EventSender* obj, int button_number, int modifiers)
322 : WebMethodTask<EventSender>(obj),
323 button_number_(button_number),
324 modifiers_(modifiers) {}
325
dchenge933b3e2014-10-21 11:44:09326 void RunIfValid() override { object_->MouseUp(button_number_, modifiers_); }
[email protected]3db130e2014-03-27 08:14:48327
328 private:
329 int button_number_;
330 int modifiers_;
331};
332
[email protected]79ecada2014-05-04 05:16:16333class KeyDownTask : public WebMethodTask<EventSender> {
[email protected]3db130e2014-03-27 08:14:48334 public:
335 KeyDownTask(EventSender* obj,
336 const std::string code_str,
337 int modifiers,
338 KeyLocationCode location)
339 : WebMethodTask<EventSender>(obj),
340 code_str_(code_str),
341 modifiers_(modifiers),
342 location_(location) {}
343
dchenge933b3e2014-10-21 11:44:09344 void RunIfValid() override {
abhishek.a21ab71acb2014-09-12 16:46:31345 object_->KeyDown(code_str_, modifiers_, location_);
[email protected]3db130e2014-03-27 08:14:48346 }
347
348 private:
349 std::string code_str_;
350 int modifiers_;
351 KeyLocationCode location_;
352};
353
354bool NeedsShiftModifier(int keyCode) {
355 // If code is an uppercase letter, assign a SHIFT key to eventDown.modifier.
356 return (keyCode & 0xFF) >= 'A' && (keyCode & 0xFF) <= 'Z';
357}
358
359// Get the edit command corresponding to a keyboard event.
360// Returns true if the specified event corresponds to an edit command, the name
361// of the edit command will be stored in |*name|.
362bool GetEditCommand(const WebKeyboardEvent& event, std::string* name) {
363#if defined(OS_MACOSX)
364// We only cares about Left,Right,Up,Down keys with Command or Command+Shift
365// modifiers. These key events correspond to some special movement and
366// selection editor commands. These keys will be marked as system key, which
367// prevents them from being handled. Thus they must be handled specially.
368 if ((event.modifiers & ~WebKeyboardEvent::ShiftKey) !=
369 WebKeyboardEvent::MetaKey)
370 return false;
371
372 switch (event.windowsKeyCode) {
[email protected]a731f1a92014-04-17 19:31:06373 case ui::VKEY_LEFT:
[email protected]3db130e2014-03-27 08:14:48374 *name = "MoveToBeginningOfLine";
375 break;
[email protected]a731f1a92014-04-17 19:31:06376 case ui::VKEY_RIGHT:
[email protected]3db130e2014-03-27 08:14:48377 *name = "MoveToEndOfLine";
378 break;
[email protected]a731f1a92014-04-17 19:31:06379 case ui::VKEY_UP:
[email protected]3db130e2014-03-27 08:14:48380 *name = "MoveToBeginningOfDocument";
381 break;
[email protected]a731f1a92014-04-17 19:31:06382 case ui::VKEY_DOWN:
[email protected]3db130e2014-03-27 08:14:48383 *name = "MoveToEndOfDocument";
384 break;
385 default:
386 return false;
387 }
388
389 if (event.modifiers & WebKeyboardEvent::ShiftKey)
390 name->append("AndModifySelection");
391
392 return true;
393#else
394 return false;
395#endif
396}
397
[email protected]a731f1a92014-04-17 19:31:06398bool IsSystemKeyEvent(const WebKeyboardEvent& event) {
399#if defined(OS_MACOSX)
400 return event.modifiers & WebInputEvent::MetaKey &&
401 event.windowsKeyCode != ui::VKEY_B &&
402 event.windowsKeyCode != ui::VKEY_I;
403#else
404 return !!(event.modifiers & WebInputEvent::AltKey);
405#endif
406}
407
tdresser3a1c9722015-02-13 15:44:53408const char* kSourceDeviceStringTouchpad = "touchpad";
409const char* kSourceDeviceStringTouchscreen = "touchscreen";
410
e.hakkinen80033922015-07-31 08:41:35411const char* kPointerTypeStringUnknown = "";
412const char* kPointerTypeStringMouse = "mouse";
413const char* kPointerTypeStringPen = "pen";
414const char* kPointerTypeStringTouch = "touch";
415
[email protected]3db130e2014-03-27 08:14:48416} // namespace
417
418class EventSenderBindings : public gin::Wrappable<EventSenderBindings> {
419 public:
420 static gin::WrapperInfo kWrapperInfo;
421
422 static void Install(base::WeakPtr<EventSender> sender,
423 blink::WebFrame* frame);
424
425 private:
426 explicit EventSenderBindings(base::WeakPtr<EventSender> sender);
dchenge933b3e2014-10-21 11:44:09427 ~EventSenderBindings() override;
[email protected]3db130e2014-03-27 08:14:48428
429 // gin::Wrappable:
dchenge933b3e2014-10-21 11:44:09430 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
anand.ratn449f39a42014-10-06 13:45:57431 v8::Isolate* isolate) override;
[email protected]3db130e2014-03-27 08:14:48432
433 // Bound methods:
434 void EnableDOMUIEventLogging();
435 void FireKeyboardEventsToElement();
436 void ClearKillRing();
437 std::vector<std::string> ContextClick();
438 void TextZoomIn();
439 void TextZoomOut();
440 void ZoomPageIn();
441 void ZoomPageOut();
[email protected]d160488f2014-05-06 17:03:01442 void SetPageZoomFactor(double factor);
[email protected]3db130e2014-03-27 08:14:48443 void ClearTouchPoints();
444 void ReleaseTouchPoint(unsigned index);
e.hakkinen80033922015-07-31 08:41:35445 void UpdateTouchPoint(unsigned index,
446 double x,
447 double y,
448 gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48449 void CancelTouchPoint(unsigned index);
450 void SetTouchModifier(const std::string& key_name, bool set_mask);
[email protected]ace1cd502014-04-24 21:05:30451 void SetTouchCancelable(bool cancelable);
[email protected]3db130e2014-03-27 08:14:48452 void DumpFilenameBeingDragged();
453 void GestureFlingCancel();
tdresser3a1c9722015-02-13 15:44:53454 void GestureFlingStart(float x,
455 float y,
456 float velocity_x,
457 float velocity_y,
458 gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48459 void GestureScrollFirstPoint(int x, int y);
460 void TouchStart();
461 void TouchMove();
mustaq96985f722015-06-30 21:41:53462 void TouchMoveCausingScrollIfUncanceled();
[email protected]3db130e2014-03-27 08:14:48463 void TouchCancel();
464 void TouchEnd();
465 void LeapForward(int milliseconds);
majidvpbfabb0712015-10-02 16:30:00466 double LastEventTimestamp();
[email protected]3db130e2014-03-27 08:14:48467 void BeginDragWithFiles(const std::vector<std::string>& files);
e.hakkinen80033922015-07-31 08:41:35468 void AddTouchPoint(double x, double y, gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48469 void MouseDragBegin();
470 void MouseDragEnd();
[email protected]3db130e2014-03-27 08:14:48471 void GestureScrollBegin(gin::Arguments* args);
472 void GestureScrollEnd(gin::Arguments* args);
473 void GestureScrollUpdate(gin::Arguments* args);
ccameronb81b8072015-01-30 00:54:49474 void GesturePinchBegin(gin::Arguments* args);
475 void GesturePinchEnd(gin::Arguments* args);
476 void GesturePinchUpdate(gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48477 void GestureTap(gin::Arguments* args);
478 void GestureTapDown(gin::Arguments* args);
479 void GestureShowPress(gin::Arguments* args);
480 void GestureTapCancel(gin::Arguments* args);
481 void GestureLongPress(gin::Arguments* args);
482 void GestureLongTap(gin::Arguments* args);
483 void GestureTwoFingerTap(gin::Arguments* args);
484 void ContinuousMouseScrollBy(gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48485 void MouseMoveTo(gin::Arguments* args);
myid.shin12c7fea22015-03-06 02:31:24486 void MouseLeave();
[email protected]9d80c822014-05-19 19:07:12487 void TrackpadScrollBegin();
488 void TrackpadScroll(gin::Arguments* args);
489 void TrackpadScrollEnd();
[email protected]3db130e2014-03-27 08:14:48490 void MouseScrollBy(gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48491 void ScheduleAsynchronousClick(gin::Arguments* args);
492 void ScheduleAsynchronousKeyDown(gin::Arguments* args);
493 void MouseDown(gin::Arguments* args);
494 void MouseUp(gin::Arguments* args);
mustaq21aed4e2015-12-15 21:47:21495 void SetMouseButtonState(gin::Arguments* args);
[email protected]3db130e2014-03-27 08:14:48496 void KeyDown(gin::Arguments* args);
497
498 // Binding properties:
499 bool ForceLayoutOnEvents() const;
500 void SetForceLayoutOnEvents(bool force);
501 bool IsDragMode() const;
502 void SetIsDragMode(bool drag_mode);
503
504#if defined(OS_WIN)
505 int WmKeyDown() const;
506 void SetWmKeyDown(int key_down);
507
508 int WmKeyUp() const;
509 void SetWmKeyUp(int key_up);
510
511 int WmChar() const;
512 void SetWmChar(int wm_char);
513
514 int WmDeadChar() const;
515 void SetWmDeadChar(int dead_char);
516
517 int WmSysKeyDown() const;
518 void SetWmSysKeyDown(int key_down);
519
520 int WmSysKeyUp() const;
521 void SetWmSysKeyUp(int key_up);
522
523 int WmSysChar() const;
524 void SetWmSysChar(int sys_char);
525
526 int WmSysDeadChar() const;
527 void SetWmSysDeadChar(int sys_dead_char);
528#endif
529
530 base::WeakPtr<EventSender> sender_;
531
532 DISALLOW_COPY_AND_ASSIGN(EventSenderBindings);
533};
534
535gin::WrapperInfo EventSenderBindings::kWrapperInfo = {gin::kEmbedderNativeGin};
536
537EventSenderBindings::EventSenderBindings(base::WeakPtr<EventSender> sender)
538 : sender_(sender) {
539}
540
541EventSenderBindings::~EventSenderBindings() {}
542
543// static
544void EventSenderBindings::Install(base::WeakPtr<EventSender> sender,
545 WebFrame* frame) {
546 v8::Isolate* isolate = blink::mainThreadIsolate();
547 v8::HandleScope handle_scope(isolate);
deepak.s750d68f2015-04-30 07:32:41548 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
[email protected]3db130e2014-03-27 08:14:48549 if (context.IsEmpty())
550 return;
551
552 v8::Context::Scope context_scope(context);
553
554 gin::Handle<EventSenderBindings> bindings =
555 gin::CreateHandle(isolate, new EventSenderBindings(sender));
[email protected]ad4d2032014-04-28 13:50:59556 if (bindings.IsEmpty())
557 return;
deepak.s750d68f2015-04-30 07:32:41558 v8::Local<v8::Object> global = context->Global();
[email protected]3db130e2014-03-27 08:14:48559 global->Set(gin::StringToV8(isolate, "eventSender"), bindings.ToV8());
560}
561
562gin::ObjectTemplateBuilder
563EventSenderBindings::GetObjectTemplateBuilder(v8::Isolate* isolate) {
564 return gin::Wrappable<EventSenderBindings>::GetObjectTemplateBuilder(isolate)
565 .SetMethod("enableDOMUIEventLogging",
566 &EventSenderBindings::EnableDOMUIEventLogging)
567 .SetMethod("fireKeyboardEventsToElement",
568 &EventSenderBindings::FireKeyboardEventsToElement)
569 .SetMethod("clearKillRing", &EventSenderBindings::ClearKillRing)
570 .SetMethod("contextClick", &EventSenderBindings::ContextClick)
571 .SetMethod("textZoomIn", &EventSenderBindings::TextZoomIn)
572 .SetMethod("textZoomOut", &EventSenderBindings::TextZoomOut)
573 .SetMethod("zoomPageIn", &EventSenderBindings::ZoomPageIn)
574 .SetMethod("zoomPageOut", &EventSenderBindings::ZoomPageOut)
[email protected]b32fe542014-04-30 08:42:06575 .SetMethod("setPageZoomFactor", &EventSenderBindings::SetPageZoomFactor)
[email protected]3db130e2014-03-27 08:14:48576 .SetMethod("clearTouchPoints", &EventSenderBindings::ClearTouchPoints)
577 .SetMethod("releaseTouchPoint", &EventSenderBindings::ReleaseTouchPoint)
578 .SetMethod("updateTouchPoint", &EventSenderBindings::UpdateTouchPoint)
579 .SetMethod("cancelTouchPoint", &EventSenderBindings::CancelTouchPoint)
580 .SetMethod("setTouchModifier", &EventSenderBindings::SetTouchModifier)
[email protected]ace1cd502014-04-24 21:05:30581 .SetMethod("setTouchCancelable", &EventSenderBindings::SetTouchCancelable)
[email protected]3db130e2014-03-27 08:14:48582 .SetMethod("dumpFilenameBeingDragged",
583 &EventSenderBindings::DumpFilenameBeingDragged)
584 .SetMethod("gestureFlingCancel", &EventSenderBindings::GestureFlingCancel)
585 .SetMethod("gestureFlingStart", &EventSenderBindings::GestureFlingStart)
586 .SetMethod("gestureScrollFirstPoint",
587 &EventSenderBindings::GestureScrollFirstPoint)
588 .SetMethod("touchStart", &EventSenderBindings::TouchStart)
589 .SetMethod("touchMove", &EventSenderBindings::TouchMove)
mustaq96985f722015-06-30 21:41:53590 .SetMethod("touchMoveCausingScrollIfUncanceled",
591 &EventSenderBindings::TouchMoveCausingScrollIfUncanceled)
[email protected]3db130e2014-03-27 08:14:48592 .SetMethod("touchCancel", &EventSenderBindings::TouchCancel)
593 .SetMethod("touchEnd", &EventSenderBindings::TouchEnd)
594 .SetMethod("leapForward", &EventSenderBindings::LeapForward)
majidvpbfabb0712015-10-02 16:30:00595 .SetMethod("lastEventTimestamp", &EventSenderBindings::LastEventTimestamp)
[email protected]3db130e2014-03-27 08:14:48596 .SetMethod("beginDragWithFiles", &EventSenderBindings::BeginDragWithFiles)
597 .SetMethod("addTouchPoint", &EventSenderBindings::AddTouchPoint)
598 .SetMethod("mouseDragBegin", &EventSenderBindings::MouseDragBegin)
599 .SetMethod("mouseDragEnd", &EventSenderBindings::MouseDragEnd)
[email protected]3db130e2014-03-27 08:14:48600 .SetMethod("gestureScrollBegin", &EventSenderBindings::GestureScrollBegin)
601 .SetMethod("gestureScrollEnd", &EventSenderBindings::GestureScrollEnd)
602 .SetMethod("gestureScrollUpdate",
603 &EventSenderBindings::GestureScrollUpdate)
ccameronb81b8072015-01-30 00:54:49604 .SetMethod("gesturePinchBegin", &EventSenderBindings::GesturePinchBegin)
605 .SetMethod("gesturePinchEnd", &EventSenderBindings::GesturePinchEnd)
606 .SetMethod("gesturePinchUpdate", &EventSenderBindings::GesturePinchUpdate)
[email protected]3db130e2014-03-27 08:14:48607 .SetMethod("gestureTap", &EventSenderBindings::GestureTap)
608 .SetMethod("gestureTapDown", &EventSenderBindings::GestureTapDown)
609 .SetMethod("gestureShowPress", &EventSenderBindings::GestureShowPress)
610 .SetMethod("gestureTapCancel", &EventSenderBindings::GestureTapCancel)
611 .SetMethod("gestureLongPress", &EventSenderBindings::GestureLongPress)
612 .SetMethod("gestureLongTap", &EventSenderBindings::GestureLongTap)
613 .SetMethod("gestureTwoFingerTap",
614 &EventSenderBindings::GestureTwoFingerTap)
615 .SetMethod("continuousMouseScrollBy",
616 &EventSenderBindings::ContinuousMouseScrollBy)
[email protected]3db130e2014-03-27 08:14:48617 .SetMethod("keyDown", &EventSenderBindings::KeyDown)
618 .SetMethod("mouseDown", &EventSenderBindings::MouseDown)
619 .SetMethod("mouseMoveTo", &EventSenderBindings::MouseMoveTo)
myid.shin12c7fea22015-03-06 02:31:24620 .SetMethod("mouseLeave", &EventSenderBindings::MouseLeave)
[email protected]9d80c822014-05-19 19:07:12621 .SetMethod("trackpadScrollBegin",
622 &EventSenderBindings::TrackpadScrollBegin)
623 .SetMethod("trackpadScroll", &EventSenderBindings::TrackpadScroll)
624 .SetMethod("trackpadScrollEnd", &EventSenderBindings::TrackpadScrollEnd)
[email protected]3db130e2014-03-27 08:14:48625 .SetMethod("mouseScrollBy", &EventSenderBindings::MouseScrollBy)
626 .SetMethod("mouseUp", &EventSenderBindings::MouseUp)
mustaq21aed4e2015-12-15 21:47:21627 .SetMethod("setMouseButtonState",
628 &EventSenderBindings::SetMouseButtonState)
[email protected]3db130e2014-03-27 08:14:48629 .SetMethod("scheduleAsynchronousClick",
630 &EventSenderBindings::ScheduleAsynchronousClick)
631 .SetMethod("scheduleAsynchronousKeyDown",
632 &EventSenderBindings::ScheduleAsynchronousKeyDown)
633 .SetProperty("forceLayoutOnEvents",
634 &EventSenderBindings::ForceLayoutOnEvents,
635 &EventSenderBindings::SetForceLayoutOnEvents)
mustaq96985f722015-06-30 21:41:53636 .SetProperty("dragMode", &EventSenderBindings::IsDragMode,
[email protected]3db130e2014-03-27 08:14:48637 &EventSenderBindings::SetIsDragMode)
638#if defined(OS_WIN)
mustaq96985f722015-06-30 21:41:53639 .SetProperty("WM_KEYDOWN", &EventSenderBindings::WmKeyDown,
[email protected]3db130e2014-03-27 08:14:48640 &EventSenderBindings::SetWmKeyDown)
mustaq96985f722015-06-30 21:41:53641 .SetProperty("WM_KEYUP", &EventSenderBindings::WmKeyUp,
[email protected]3db130e2014-03-27 08:14:48642 &EventSenderBindings::SetWmKeyUp)
mustaq96985f722015-06-30 21:41:53643 .SetProperty("WM_CHAR", &EventSenderBindings::WmChar,
[email protected]3db130e2014-03-27 08:14:48644 &EventSenderBindings::SetWmChar)
mustaq96985f722015-06-30 21:41:53645 .SetProperty("WM_DEADCHAR", &EventSenderBindings::WmDeadChar,
[email protected]3db130e2014-03-27 08:14:48646 &EventSenderBindings::SetWmDeadChar)
mustaq96985f722015-06-30 21:41:53647 .SetProperty("WM_SYSKEYDOWN", &EventSenderBindings::WmSysKeyDown,
[email protected]3db130e2014-03-27 08:14:48648 &EventSenderBindings::SetWmSysKeyDown)
mustaq96985f722015-06-30 21:41:53649 .SetProperty("WM_SYSKEYUP", &EventSenderBindings::WmSysKeyUp,
[email protected]3db130e2014-03-27 08:14:48650 &EventSenderBindings::SetWmSysKeyUp)
mustaq96985f722015-06-30 21:41:53651 .SetProperty("WM_SYSCHAR", &EventSenderBindings::WmSysChar,
[email protected]3db130e2014-03-27 08:14:48652 &EventSenderBindings::SetWmSysChar)
mustaq96985f722015-06-30 21:41:53653 .SetProperty("WM_SYSDEADCHAR", &EventSenderBindings::WmSysDeadChar,
[email protected]3db130e2014-03-27 08:14:48654 &EventSenderBindings::SetWmSysDeadChar);
655#else
656 ;
657#endif
658}
659
660void EventSenderBindings::EnableDOMUIEventLogging() {
661 if (sender_)
662 sender_->EnableDOMUIEventLogging();
663}
664
665void EventSenderBindings::FireKeyboardEventsToElement() {
666 if (sender_)
667 sender_->FireKeyboardEventsToElement();
668}
669
670void EventSenderBindings::ClearKillRing() {
671 if (sender_)
672 sender_->ClearKillRing();
673}
674
675std::vector<std::string> EventSenderBindings::ContextClick() {
676 if (sender_)
677 return sender_->ContextClick();
678 return std::vector<std::string>();
679}
680
681void EventSenderBindings::TextZoomIn() {
682 if (sender_)
683 sender_->TextZoomIn();
684}
685
686void EventSenderBindings::TextZoomOut() {
687 if (sender_)
688 sender_->TextZoomOut();
689}
690
691void EventSenderBindings::ZoomPageIn() {
692 if (sender_)
693 sender_->ZoomPageIn();
694}
695
696void EventSenderBindings::ZoomPageOut() {
697 if (sender_)
698 sender_->ZoomPageOut();
699}
700
[email protected]d160488f2014-05-06 17:03:01701void EventSenderBindings::SetPageZoomFactor(double factor) {
702 if (sender_)
703 sender_->SetPageZoomFactor(factor);
[email protected]b32fe542014-04-30 08:42:06704}
705
[email protected]3db130e2014-03-27 08:14:48706void EventSenderBindings::ClearTouchPoints() {
707 if (sender_)
708 sender_->ClearTouchPoints();
709}
710
711void EventSenderBindings::ReleaseTouchPoint(unsigned index) {
712 if (sender_)
713 sender_->ReleaseTouchPoint(index);
714}
715
e.hakkinen80033922015-07-31 08:41:35716void EventSenderBindings::UpdateTouchPoint(unsigned index,
717 double x,
718 double y,
719 gin::Arguments* args) {
jochen73e711c2015-06-03 10:01:46720 if (sender_) {
721 sender_->UpdateTouchPoint(index, static_cast<float>(x),
e.hakkinen80033922015-07-31 08:41:35722 static_cast<float>(y), args);
jochen73e711c2015-06-03 10:01:46723 }
[email protected]3db130e2014-03-27 08:14:48724}
725
726void EventSenderBindings::CancelTouchPoint(unsigned index) {
727 if (sender_)
728 sender_->CancelTouchPoint(index);
729}
730
731void EventSenderBindings::SetTouchModifier(const std::string& key_name,
732 bool set_mask) {
733 if (sender_)
734 sender_->SetTouchModifier(key_name, set_mask);
735}
736
[email protected]ace1cd502014-04-24 21:05:30737void EventSenderBindings::SetTouchCancelable(bool cancelable) {
738 if (sender_)
739 sender_->SetTouchCancelable(cancelable);
740}
741
[email protected]3db130e2014-03-27 08:14:48742void EventSenderBindings::DumpFilenameBeingDragged() {
743 if (sender_)
744 sender_->DumpFilenameBeingDragged();
745}
746
747void EventSenderBindings::GestureFlingCancel() {
748 if (sender_)
749 sender_->GestureFlingCancel();
750}
751
752void EventSenderBindings::GestureFlingStart(float x,
753 float y,
754 float velocity_x,
tdresser3a1c9722015-02-13 15:44:53755 float velocity_y,
756 gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:48757 if (sender_)
tdresser3a1c9722015-02-13 15:44:53758 sender_->GestureFlingStart(x, y, velocity_x, velocity_y, args);
[email protected]3db130e2014-03-27 08:14:48759}
760
761void EventSenderBindings::GestureScrollFirstPoint(int x, int y) {
762 if (sender_)
763 sender_->GestureScrollFirstPoint(x, y);
764}
765
766void EventSenderBindings::TouchStart() {
767 if (sender_)
768 sender_->TouchStart();
769}
770
771void EventSenderBindings::TouchMove() {
772 if (sender_)
773 sender_->TouchMove();
774}
775
mustaq96985f722015-06-30 21:41:53776void EventSenderBindings::TouchMoveCausingScrollIfUncanceled() {
777 if (sender_)
778 sender_->TouchMoveCausingScrollIfUncanceled();
779}
780
[email protected]3db130e2014-03-27 08:14:48781void EventSenderBindings::TouchCancel() {
782 if (sender_)
783 sender_->TouchCancel();
784}
785
786void EventSenderBindings::TouchEnd() {
787 if (sender_)
788 sender_->TouchEnd();
789}
790
791void EventSenderBindings::LeapForward(int milliseconds) {
792 if (sender_)
793 sender_->LeapForward(milliseconds);
794}
795
majidvpbfabb0712015-10-02 16:30:00796double EventSenderBindings::LastEventTimestamp() {
797 if (sender_)
798 return sender_->last_event_timestamp();
799 return 0;
800}
801
[email protected]3db130e2014-03-27 08:14:48802void EventSenderBindings::BeginDragWithFiles(
803 const std::vector<std::string>& files) {
804 if (sender_)
805 sender_->BeginDragWithFiles(files);
806}
807
e.hakkinen80033922015-07-31 08:41:35808void EventSenderBindings::AddTouchPoint(double x,
809 double y,
810 gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:48811 if (sender_)
e.hakkinen80033922015-07-31 08:41:35812 sender_->AddTouchPoint(static_cast<float>(x), static_cast<float>(y), args);
[email protected]3db130e2014-03-27 08:14:48813}
814
815void EventSenderBindings::MouseDragBegin() {
816 if (sender_)
817 sender_->MouseDragBegin();
818}
819
820void EventSenderBindings::MouseDragEnd() {
821 if (sender_)
822 sender_->MouseDragEnd();
823}
824
[email protected]3db130e2014-03-27 08:14:48825void EventSenderBindings::GestureScrollBegin(gin::Arguments* args) {
826 if (sender_)
827 sender_->GestureScrollBegin(args);
828}
829
830void EventSenderBindings::GestureScrollEnd(gin::Arguments* args) {
831 if (sender_)
832 sender_->GestureScrollEnd(args);
833}
834
835void EventSenderBindings::GestureScrollUpdate(gin::Arguments* args) {
836 if (sender_)
837 sender_->GestureScrollUpdate(args);
838}
839
ccameronb81b8072015-01-30 00:54:49840void EventSenderBindings::GesturePinchBegin(gin::Arguments* args) {
841 if (sender_)
842 sender_->GesturePinchBegin(args);
843}
844
845void EventSenderBindings::GesturePinchEnd(gin::Arguments* args) {
846 if (sender_)
847 sender_->GesturePinchEnd(args);
848}
849
850void EventSenderBindings::GesturePinchUpdate(gin::Arguments* args) {
851 if (sender_)
852 sender_->GesturePinchUpdate(args);
853}
854
[email protected]3db130e2014-03-27 08:14:48855void EventSenderBindings::GestureTap(gin::Arguments* args) {
856 if (sender_)
857 sender_->GestureTap(args);
858}
859
860void EventSenderBindings::GestureTapDown(gin::Arguments* args) {
861 if (sender_)
862 sender_->GestureTapDown(args);
863}
864
865void EventSenderBindings::GestureShowPress(gin::Arguments* args) {
866 if (sender_)
867 sender_->GestureShowPress(args);
868}
869
870void EventSenderBindings::GestureTapCancel(gin::Arguments* args) {
871 if (sender_)
872 sender_->GestureTapCancel(args);
873}
874
875void EventSenderBindings::GestureLongPress(gin::Arguments* args) {
876 if (sender_)
877 sender_->GestureLongPress(args);
878}
879
880void EventSenderBindings::GestureLongTap(gin::Arguments* args) {
881 if (sender_)
882 sender_->GestureLongTap(args);
883}
884
885void EventSenderBindings::GestureTwoFingerTap(gin::Arguments* args) {
886 if (sender_)
887 sender_->GestureTwoFingerTap(args);
888}
889
890void EventSenderBindings::ContinuousMouseScrollBy(gin::Arguments* args) {
891 if (sender_)
892 sender_->ContinuousMouseScrollBy(args);
893}
894
[email protected]3db130e2014-03-27 08:14:48895void EventSenderBindings::MouseMoveTo(gin::Arguments* args) {
896 if (sender_)
897 sender_->MouseMoveTo(args);
898}
899
myid.shin12c7fea22015-03-06 02:31:24900void EventSenderBindings::MouseLeave() {
901 if (sender_)
902 sender_->MouseLeave();
903}
904
[email protected]9d80c822014-05-19 19:07:12905void EventSenderBindings::TrackpadScrollBegin() {
906 if (sender_)
907 sender_->TrackpadScrollBegin();
908}
909
910void EventSenderBindings::TrackpadScroll(gin::Arguments* args) {
911 if (sender_)
912 sender_->TrackpadScroll(args);
913}
914
915void EventSenderBindings::TrackpadScrollEnd() {
916 if (sender_)
917 sender_->TrackpadScrollEnd();
918}
919
[email protected]3db130e2014-03-27 08:14:48920void EventSenderBindings::MouseScrollBy(gin::Arguments* args) {
921 if (sender_)
922 sender_->MouseScrollBy(args);
923}
924
[email protected]3db130e2014-03-27 08:14:48925void EventSenderBindings::ScheduleAsynchronousClick(gin::Arguments* args) {
926 if (!sender_)
927 return;
928
929 int button_number = 0;
930 int modifiers = 0;
931 if (!args->PeekNext().IsEmpty()) {
932 args->GetNext(&button_number);
933 if (!args->PeekNext().IsEmpty())
bashidbd2ef9bb2015-06-02 01:39:32934 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
[email protected]3db130e2014-03-27 08:14:48935 }
936 sender_->ScheduleAsynchronousClick(button_number, modifiers);
937}
938
939void EventSenderBindings::ScheduleAsynchronousKeyDown(gin::Arguments* args) {
940 if (!sender_)
941 return;
942
943 std::string code_str;
944 int modifiers = 0;
945 int location = DOMKeyLocationStandard;
946 args->GetNext(&code_str);
947 if (!args->PeekNext().IsEmpty()) {
deepak.s750d68f2015-04-30 07:32:41948 v8::Local<v8::Value> value;
[email protected]3db130e2014-03-27 08:14:48949 args->GetNext(&value);
bashidbd2ef9bb2015-06-02 01:39:32950 modifiers = GetKeyModifiersFromV8(args->isolate(), value);
[email protected]3db130e2014-03-27 08:14:48951 if (!args->PeekNext().IsEmpty())
952 args->GetNext(&location);
953 }
954 sender_->ScheduleAsynchronousKeyDown(code_str, modifiers,
955 static_cast<KeyLocationCode>(location));
956}
957
958void EventSenderBindings::MouseDown(gin::Arguments* args) {
959 if (!sender_)
960 return;
961
962 int button_number = 0;
963 int modifiers = 0;
964 if (!args->PeekNext().IsEmpty()) {
965 args->GetNext(&button_number);
966 if (!args->PeekNext().IsEmpty())
bashidbd2ef9bb2015-06-02 01:39:32967 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
[email protected]3db130e2014-03-27 08:14:48968 }
969 sender_->MouseDown(button_number, modifiers);
970}
971
972void EventSenderBindings::MouseUp(gin::Arguments* args) {
973 if (!sender_)
974 return;
975
976 int button_number = 0;
977 int modifiers = 0;
978 if (!args->PeekNext().IsEmpty()) {
979 args->GetNext(&button_number);
980 if (!args->PeekNext().IsEmpty())
bashidbd2ef9bb2015-06-02 01:39:32981 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
[email protected]3db130e2014-03-27 08:14:48982 }
983 sender_->MouseUp(button_number, modifiers);
984}
985
mustaq21aed4e2015-12-15 21:47:21986void EventSenderBindings::SetMouseButtonState(gin::Arguments* args) {
987 if (!sender_)
988 return;
989
990 int button_number;
991 if (!args->GetNext(&button_number)) {
992 args->ThrowError();
993 return;
994 }
995
996 int modifiers = -1; // Default to the modifier implied by button_number
997 if (!args->PeekNext().IsEmpty()) {
998 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
999 }
1000
1001 sender_->SetMouseButtonState(button_number, modifiers);
1002}
1003
[email protected]3db130e2014-03-27 08:14:481004void EventSenderBindings::KeyDown(gin::Arguments* args) {
1005 if (!sender_)
1006 return;
1007
1008 std::string code_str;
1009 int modifiers = 0;
1010 int location = DOMKeyLocationStandard;
1011 args->GetNext(&code_str);
1012 if (!args->PeekNext().IsEmpty()) {
deepak.s750d68f2015-04-30 07:32:411013 v8::Local<v8::Value> value;
[email protected]3db130e2014-03-27 08:14:481014 args->GetNext(&value);
bashidbd2ef9bb2015-06-02 01:39:321015 modifiers = GetKeyModifiersFromV8(args->isolate(), value);
[email protected]3db130e2014-03-27 08:14:481016 if (!args->PeekNext().IsEmpty())
1017 args->GetNext(&location);
1018 }
1019 sender_->KeyDown(code_str, modifiers, static_cast<KeyLocationCode>(location));
1020}
1021
1022bool EventSenderBindings::ForceLayoutOnEvents() const {
1023 if (sender_)
1024 return sender_->force_layout_on_events();
1025 return false;
1026}
1027
1028void EventSenderBindings::SetForceLayoutOnEvents(bool force) {
1029 if (sender_)
1030 sender_->set_force_layout_on_events(force);
1031}
1032
1033bool EventSenderBindings::IsDragMode() const {
1034 if (sender_)
1035 return sender_->is_drag_mode();
1036 return true;
1037}
1038
1039void EventSenderBindings::SetIsDragMode(bool drag_mode) {
1040 if (sender_)
1041 sender_->set_is_drag_mode(drag_mode);
1042}
1043
1044#if defined(OS_WIN)
1045int EventSenderBindings::WmKeyDown() const {
1046 if (sender_)
1047 return sender_->wm_key_down();
1048 return 0;
1049}
1050
1051void EventSenderBindings::SetWmKeyDown(int key_down) {
1052 if (sender_)
1053 sender_->set_wm_key_down(key_down);
1054}
1055
1056int EventSenderBindings::WmKeyUp() const {
1057 if (sender_)
1058 return sender_->wm_key_up();
1059 return 0;
1060}
1061
1062void EventSenderBindings::SetWmKeyUp(int key_up) {
1063 if (sender_)
1064 sender_->set_wm_key_up(key_up);
1065}
1066
1067int EventSenderBindings::WmChar() const {
1068 if (sender_)
1069 return sender_->wm_char();
1070 return 0;
1071}
1072
1073void EventSenderBindings::SetWmChar(int wm_char) {
1074 if (sender_)
1075 sender_->set_wm_char(wm_char);
1076}
1077
1078int EventSenderBindings::WmDeadChar() const {
1079 if (sender_)
1080 return sender_->wm_dead_char();
1081 return 0;
1082}
1083
1084void EventSenderBindings::SetWmDeadChar(int dead_char) {
1085 if (sender_)
1086 sender_->set_wm_dead_char(dead_char);
1087}
1088
1089int EventSenderBindings::WmSysKeyDown() const {
1090 if (sender_)
1091 return sender_->wm_sys_key_down();
1092 return 0;
1093}
1094
1095void EventSenderBindings::SetWmSysKeyDown(int key_down) {
1096 if (sender_)
1097 sender_->set_wm_sys_key_down(key_down);
1098}
1099
1100int EventSenderBindings::WmSysKeyUp() const {
1101 if (sender_)
1102 return sender_->wm_sys_key_up();
1103 return 0;
1104}
1105
1106void EventSenderBindings::SetWmSysKeyUp(int key_up) {
1107 if (sender_)
1108 sender_->set_wm_sys_key_up(key_up);
1109}
1110
1111int EventSenderBindings::WmSysChar() const {
1112 if (sender_)
1113 return sender_->wm_sys_char();
1114 return 0;
1115}
1116
1117void EventSenderBindings::SetWmSysChar(int sys_char) {
1118 if (sender_)
1119 sender_->set_wm_sys_char(sys_char);
1120}
1121
1122int EventSenderBindings::WmSysDeadChar() const {
1123 if (sender_)
1124 return sender_->wm_sys_dead_char();
1125 return 0;
1126}
1127
1128void EventSenderBindings::SetWmSysDeadChar(int sys_dead_char) {
1129 if (sender_)
1130 sender_->set_wm_sys_dead_char(sys_dead_char);
1131}
1132#endif
1133
1134// EventSender -----------------------------------------------------------------
1135
1136WebMouseEvent::Button EventSender::pressed_button_ = WebMouseEvent::ButtonNone;
mustaq21aed4e2015-12-15 21:47:211137int EventSender::current_buttons_ = 0;
jinho.banga7447af2015-03-11 04:56:581138int EventSender::modifiers_ = 0;
[email protected]3db130e2014-03-27 08:14:481139
1140WebPoint EventSender::last_mouse_pos_;
1141
1142WebMouseEvent::Button EventSender::last_button_type_ =
1143 WebMouseEvent::ButtonNone;
1144
1145EventSender::SavedEvent::SavedEvent()
1146 : type(TYPE_UNSPECIFIED),
1147 button_type(WebMouseEvent::ButtonNone),
1148 milliseconds(0),
1149 modifiers(0) {}
1150
[email protected]79ecada2014-05-04 05:16:161151EventSender::EventSender(TestInterfaces* interfaces)
sammc5648c852015-07-02 01:25:001152 :
1153#if defined(OS_WIN)
1154 wm_key_down_(0),
1155 wm_key_up_(0),
1156 wm_char_(0),
1157 wm_dead_char_(0),
1158 wm_sys_key_down_(0),
1159 wm_sys_key_up_(0),
1160 wm_sys_char_(0),
1161 wm_sys_dead_char_(0),
1162#endif
1163 interfaces_(interfaces),
[email protected]3db130e2014-03-27 08:14:481164 delegate_(NULL),
1165 view_(NULL),
1166 force_layout_on_events_(false),
1167 is_drag_mode_(true),
1168 touch_modifiers_(0),
[email protected]ace1cd502014-04-24 21:05:301169 touch_cancelable_(true),
[email protected]3db130e2014-03-27 08:14:481170 replaying_saved_events_(false),
1171 current_drag_effects_allowed_(blink::WebDragOperationNone),
1172 last_click_time_sec_(0),
1173 current_drag_effect_(blink::WebDragOperationNone),
1174 time_offset_ms_(0),
1175 click_count_(0),
sammc5648c852015-07-02 01:25:001176 weak_factory_(this) {
1177}
[email protected]3db130e2014-03-27 08:14:481178
1179EventSender::~EventSender() {}
1180
1181void EventSender::Reset() {
1182 DCHECK(current_drag_data_.isNull());
1183 current_drag_data_.reset();
1184 current_drag_effect_ = blink::WebDragOperationNone;
1185 current_drag_effects_allowed_ = blink::WebDragOperationNone;
1186 if (view_ && pressed_button_ != WebMouseEvent::ButtonNone)
1187 view_->mouseCaptureLost();
1188 pressed_button_ = WebMouseEvent::ButtonNone;
mustaq21aed4e2015-12-15 21:47:211189 current_buttons_ = 0;
mustaq06b26f2002015-12-14 18:37:161190 modifiers_ = 0;
[email protected]3db130e2014-03-27 08:14:481191 is_drag_mode_ = true;
1192 force_layout_on_events_ = true;
1193
1194#if defined(OS_WIN)
1195 wm_key_down_ = WM_KEYDOWN;
1196 wm_key_up_ = WM_KEYUP;
1197 wm_char_ = WM_CHAR;
1198 wm_dead_char_ = WM_DEADCHAR;
1199 wm_sys_key_down_ = WM_SYSKEYDOWN;
1200 wm_sys_key_up_ = WM_SYSKEYUP;
1201 wm_sys_char_ = WM_SYSCHAR;
1202 wm_sys_dead_char_ = WM_SYSDEADCHAR;
1203#endif
1204
1205 last_mouse_pos_ = WebPoint(0, 0);
1206 last_click_time_sec_ = 0;
1207 last_click_pos_ = WebPoint(0, 0);
1208 last_button_type_ = WebMouseEvent::ButtonNone;
1209 touch_points_.clear();
[email protected]644616d2014-03-27 16:14:471210 last_context_menu_data_.reset();
abhishek.a21ab71acb2014-09-12 16:46:311211 task_list_.RevokeAll();
[email protected]3db130e2014-03-27 08:14:481212 current_gesture_location_ = WebPoint(0, 0);
1213 mouse_event_queue_.clear();
1214
1215 time_offset_ms_ = 0;
1216 click_count_ = 0;
[email protected]ace1cd502014-04-24 21:05:301217
1218 touch_modifiers_ = 0;
1219 touch_cancelable_ = true;
1220 touch_points_.clear();
[email protected]3db130e2014-03-27 08:14:481221}
1222
1223void EventSender::Install(WebFrame* frame) {
1224 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame);
1225}
1226
[email protected]79ecada2014-05-04 05:16:161227void EventSender::SetDelegate(WebTestDelegate* delegate) {
[email protected]3db130e2014-03-27 08:14:481228 delegate_ = delegate;
1229}
1230
1231void EventSender::SetWebView(WebView* view) {
1232 view_ = view;
1233}
1234
1235void EventSender::SetContextMenuData(const WebContextMenuData& data) {
1236 last_context_menu_data_.reset(new WebContextMenuData(data));
1237}
1238
1239void EventSender::DoDragDrop(const WebDragData& drag_data,
1240 WebDragOperationsMask mask) {
1241 WebMouseEvent event;
1242 InitMouseEvent(WebInputEvent::MouseDown,
1243 pressed_button_,
mustaq21aed4e2015-12-15 21:47:211244 current_buttons_,
[email protected]3db130e2014-03-27 08:14:481245 last_mouse_pos_,
1246 GetCurrentEventTimeSec(),
1247 click_count_,
jinho.banga7447af2015-03-11 04:56:581248 modifiers_,
[email protected]3db130e2014-03-27 08:14:481249 &event);
1250 WebPoint client_point(event.x, event.y);
1251 WebPoint screen_point(event.globalX, event.globalY);
1252 current_drag_data_ = drag_data;
1253 current_drag_effects_allowed_ = mask;
1254 current_drag_effect_ = view_->dragTargetDragEnter(
jinho.banga7447af2015-03-11 04:56:581255 drag_data,
1256 client_point,
1257 screen_point,
1258 current_drag_effects_allowed_,
1259 modifiers_);
[email protected]3db130e2014-03-27 08:14:481260
1261 // Finish processing events.
1262 ReplaySavedEvents();
1263}
1264
1265void EventSender::MouseDown(int button_number, int modifiers) {
1266 if (force_layout_on_events_)
wkorman7265db012015-11-03 04:08:251267 view_->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481268
1269 DCHECK_NE(-1, button_number);
1270
1271 WebMouseEvent::Button button_type =
1272 GetButtonTypeFromButtonNumber(button_number);
1273
1274 UpdateClickCountForButton(button_type);
1275
1276 pressed_button_ = button_type;
mustaq21aed4e2015-12-15 21:47:211277 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_);
jinho.banga7447af2015-03-11 04:56:581278 modifiers_ = modifiers;
[email protected]3db130e2014-03-27 08:14:481279
1280 WebMouseEvent event;
1281 InitMouseEvent(WebInputEvent::MouseDown,
mustaq21aed4e2015-12-15 21:47:211282 pressed_button_,
1283 current_buttons_,
[email protected]3db130e2014-03-27 08:14:481284 last_mouse_pos_,
1285 GetCurrentEventTimeSec(),
1286 click_count_,
mustaq21aed4e2015-12-15 21:47:211287 modifiers_,
[email protected]3db130e2014-03-27 08:14:481288 &event);
tkent588765612014-11-28 01:07:481289 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481290}
1291
1292void EventSender::MouseUp(int button_number, int modifiers) {
1293 if (force_layout_on_events_)
wkorman7265db012015-11-03 04:08:251294 view_->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481295
1296 DCHECK_NE(-1, button_number);
1297
1298 WebMouseEvent::Button button_type =
1299 GetButtonTypeFromButtonNumber(button_number);
1300
1301 if (is_drag_mode_ && !replaying_saved_events_) {
1302 SavedEvent saved_event;
1303 saved_event.type = SavedEvent::TYPE_MOUSE_UP;
1304 saved_event.button_type = button_type;
1305 saved_event.modifiers = modifiers;
1306 mouse_event_queue_.push_back(saved_event);
1307 ReplaySavedEvents();
1308 } else {
mustaq21aed4e2015-12-15 21:47:211309 current_buttons_ &= ~GetWebMouseEventModifierForButton(button_type);
1310 pressed_button_ = WebMouseEvent::ButtonNone;
1311
[email protected]3db130e2014-03-27 08:14:481312 WebMouseEvent event;
1313 InitMouseEvent(WebInputEvent::MouseUp,
1314 button_type,
mustaq21aed4e2015-12-15 21:47:211315 current_buttons_,
[email protected]3db130e2014-03-27 08:14:481316 last_mouse_pos_,
1317 GetCurrentEventTimeSec(),
1318 click_count_,
1319 modifiers,
1320 &event);
1321 DoMouseUp(event);
1322 }
1323}
1324
mustaq21aed4e2015-12-15 21:47:211325void EventSender::SetMouseButtonState(int button_number, int modifiers) {
1326 pressed_button_ = GetButtonTypeFromButtonNumber(button_number);
1327 current_buttons_ = (modifiers == -1) ?
1328 GetWebMouseEventModifierForButton(pressed_button_) :
1329 modifiers & kButtonsInModifiers;
1330}
1331
[email protected]3db130e2014-03-27 08:14:481332void EventSender::KeyDown(const std::string& code_str,
1333 int modifiers,
1334 KeyLocationCode location) {
1335 // FIXME: I'm not exactly sure how we should convert the string to a key
1336 // event. This seems to work in the cases I tested.
1337 // FIXME: Should we also generate a KEY_UP?
1338
1339 bool generate_char = false;
1340
1341 // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when
1342 // Windows uses \r for "Enter".
1343 int code = 0;
1344 int text = 0;
1345 bool needs_shift_key_modifier = false;
habib.virji565c80c2015-02-06 12:26:431346 std::string domString;
[email protected]3db130e2014-03-27 08:14:481347
1348 if ("\n" == code_str) {
1349 generate_char = true;
[email protected]a731f1a92014-04-17 19:31:061350 text = code = ui::VKEY_RETURN;
habib.virji565c80c2015-02-06 12:26:431351 domString.assign("Enter");
[email protected]3db130e2014-03-27 08:14:481352 } else if ("rightArrow" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061353 code = ui::VKEY_RIGHT;
habib.virji565c80c2015-02-06 12:26:431354 domString.assign("ArrowRight");
[email protected]3db130e2014-03-27 08:14:481355 } else if ("downArrow" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061356 code = ui::VKEY_DOWN;
habib.virji565c80c2015-02-06 12:26:431357 domString.assign("ArrowDown");
[email protected]3db130e2014-03-27 08:14:481358 } else if ("leftArrow" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061359 code = ui::VKEY_LEFT;
habib.virji565c80c2015-02-06 12:26:431360 domString.assign("ArrowLeft");
[email protected]3db130e2014-03-27 08:14:481361 } else if ("upArrow" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061362 code = ui::VKEY_UP;
habib.virji565c80c2015-02-06 12:26:431363 domString.assign("ArrowUp");
[email protected]3db130e2014-03-27 08:14:481364 } else if ("insert" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061365 code = ui::VKEY_INSERT;
habib.virji565c80c2015-02-06 12:26:431366 domString.assign("Insert");
[email protected]3db130e2014-03-27 08:14:481367 } else if ("delete" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061368 code = ui::VKEY_DELETE;
habib.virji565c80c2015-02-06 12:26:431369 domString.assign("Delete");
[email protected]3db130e2014-03-27 08:14:481370 } else if ("pageUp" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061371 code = ui::VKEY_PRIOR;
habib.virji565c80c2015-02-06 12:26:431372 domString.assign("PageUp");
[email protected]3db130e2014-03-27 08:14:481373 } else if ("pageDown" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061374 code = ui::VKEY_NEXT;
habib.virji565c80c2015-02-06 12:26:431375 domString.assign("PageDown");
[email protected]3db130e2014-03-27 08:14:481376 } else if ("home" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061377 code = ui::VKEY_HOME;
habib.virji565c80c2015-02-06 12:26:431378 domString.assign("Home");
[email protected]3db130e2014-03-27 08:14:481379 } else if ("end" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061380 code = ui::VKEY_END;
habib.virji565c80c2015-02-06 12:26:431381 domString.assign("End");
[email protected]3db130e2014-03-27 08:14:481382 } else if ("printScreen" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061383 code = ui::VKEY_SNAPSHOT;
habib.virji565c80c2015-02-06 12:26:431384 domString.assign("PrintScreen");
[email protected]3db130e2014-03-27 08:14:481385 } else if ("menu" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061386 code = ui::VKEY_APPS;
habib.virji565c80c2015-02-06 12:26:431387 domString.assign("ContextMenu");
[email protected]3db130e2014-03-27 08:14:481388 } else if ("leftControl" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051389 code = ui::VKEY_CONTROL;
habib.virji565c80c2015-02-06 12:26:431390 domString.assign("ControlLeft");
dtapuskad3ba0f042015-08-27 14:08:051391 location = DOMKeyLocationLeft;
[email protected]3db130e2014-03-27 08:14:481392 } else if ("rightControl" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051393 code = ui::VKEY_CONTROL;
habib.virji565c80c2015-02-06 12:26:431394 domString.assign("ControlRight");
dtapuskad3ba0f042015-08-27 14:08:051395 location = DOMKeyLocationRight;
[email protected]3db130e2014-03-27 08:14:481396 } else if ("leftShift" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051397 code = ui::VKEY_SHIFT;
habib.virji565c80c2015-02-06 12:26:431398 domString.assign("ShiftLeft");
dtapuskad3ba0f042015-08-27 14:08:051399 location = DOMKeyLocationLeft;
[email protected]3db130e2014-03-27 08:14:481400 } else if ("rightShift" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051401 code = ui::VKEY_SHIFT;
habib.virji565c80c2015-02-06 12:26:431402 domString.assign("ShiftRight");
dtapuskad3ba0f042015-08-27 14:08:051403 location = DOMKeyLocationRight;
[email protected]3db130e2014-03-27 08:14:481404 } else if ("leftAlt" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051405 code = ui::VKEY_MENU;
habib.virji565c80c2015-02-06 12:26:431406 domString.assign("AltLeft");
dtapuskad3ba0f042015-08-27 14:08:051407 location = DOMKeyLocationLeft;
[email protected]3db130e2014-03-27 08:14:481408 } else if ("rightAlt" == code_str) {
dtapuskad3ba0f042015-08-27 14:08:051409 code = ui::VKEY_MENU;
habib.virji565c80c2015-02-06 12:26:431410 domString.assign("AltRight");
dtapuskad3ba0f042015-08-27 14:08:051411 location = DOMKeyLocationRight;
[email protected]3db130e2014-03-27 08:14:481412 } else if ("numLock" == code_str) {
[email protected]a731f1a92014-04-17 19:31:061413 code = ui::VKEY_NUMLOCK;
habib.virji565c80c2015-02-06 12:26:431414 domString.assign("NumLock");
[email protected]4c07a712014-08-21 17:05:541415 } else if ("backspace" == code_str) {
1416 code = ui::VKEY_BACK;
habib.virji565c80c2015-02-06 12:26:431417 domString.assign("Backspace");
[email protected]4c07a712014-08-21 17:05:541418 } else if ("escape" == code_str) {
1419 code = ui::VKEY_ESCAPE;
habib.virji565c80c2015-02-06 12:26:431420 domString.assign("Escape");
[email protected]3db130e2014-03-27 08:14:481421 } else {
1422 // Compare the input string with the function-key names defined by the
1423 // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key
1424 // name, set its key code.
1425 for (int i = 1; i <= 24; ++i) {
1426 std::string function_key_name = base::StringPrintf("F%d", i);
1427 if (function_key_name == code_str) {
[email protected]a731f1a92014-04-17 19:31:061428 code = ui::VKEY_F1 + (i - 1);
habib.virji565c80c2015-02-06 12:26:431429 domString = function_key_name;
[email protected]3db130e2014-03-27 08:14:481430 break;
1431 }
1432 }
1433 if (!code) {
esprehnd29ab802015-12-11 13:01:191434 base::string16 code_str16 = base::UTF8ToUTF16(code_str);
1435 if (code_str16.size() != 1u) {
dtapuskabd2a1652015-05-20 00:30:151436 v8::Isolate* isolate = blink::mainThreadIsolate();
1437 isolate->ThrowException(v8::Exception::TypeError(
1438 gin::StringToV8(isolate, "Invalid web code.")));
1439 return;
1440 }
esprehnd29ab802015-12-11 13:01:191441 text = code = code_str16[0];
[email protected]3db130e2014-03-27 08:14:481442 needs_shift_key_modifier = NeedsShiftModifier(code);
1443 if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z')
1444 code -= 'a' - 'A';
habib.virji565c80c2015-02-06 12:26:431445 if ((code >= 'A' && code <= 'Z') || (code >= 'a' && code <= 'z')) {
1446 domString.assign("Key");
brettwc15100c2015-08-06 22:54:161447 domString.push_back(
1448 base::ToUpperASCII(static_cast<base::char16>(code)));
habib.virji565c80c2015-02-06 12:26:431449 } else if (code >= '0' && code <= '9') {
1450 domString.assign("Digit");
1451 domString.push_back(code);
1452 } else if (code == ' ') {
1453 domString.assign("Space");
1454 } else if (code == 9) {
1455 domString.assign("Tab");
1456 }
[email protected]3db130e2014-03-27 08:14:481457 generate_char = true;
1458 }
1459
1460 if ("(" == code_str) {
1461 code = '9';
1462 needs_shift_key_modifier = true;
1463 }
1464 }
1465
1466 // For one generated keyboard event, we need to generate a keyDown/keyUp
1467 // pair;
1468 // On Windows, we might also need to generate a char event to mimic the
1469 // Windows event flow; on other platforms we create a merged event and test
1470 // the event flow that that platform provides.
1471 WebKeyboardEvent event_down;
majidvp0c6422a2015-09-17 20:07:251472 event_down.timeStampSeconds = GetCurrentEventTimeSec();
[email protected]3db130e2014-03-27 08:14:481473 event_down.type = WebInputEvent::RawKeyDown;
1474 event_down.modifiers = modifiers;
1475 event_down.windowsKeyCode = code;
habib.virji565c80c2015-02-06 12:26:431476 event_down.domCode = static_cast<int>(
kpschoedela6d524f332015-10-26 14:46:251477 ui::KeycodeConverter::CodeStringToDomCode(domString));
[email protected]3db130e2014-03-27 08:14:481478
[email protected]3db130e2014-03-27 08:14:481479 if (generate_char) {
1480 event_down.text[0] = text;
1481 event_down.unmodifiedText[0] = text;
1482 }
1483
1484 event_down.setKeyIdentifierFromWindowsKeyCode();
1485
[email protected]3db130e2014-03-27 08:14:481486 if (event_down.modifiers != 0)
[email protected]a731f1a92014-04-17 19:31:061487 event_down.isSystemKey = IsSystemKeyEvent(event_down);
[email protected]3db130e2014-03-27 08:14:481488
1489 if (needs_shift_key_modifier)
1490 event_down.modifiers |= WebInputEvent::ShiftKey;
1491
1492 // See if KeyLocation argument is given.
dtapuskad3ba0f042015-08-27 14:08:051493 switch(location) {
1494 case DOMKeyLocationStandard:
1495 break;
1496 case DOMKeyLocationLeft:
1497 event_down.modifiers |= WebInputEvent::IsLeft;
1498 break;
1499 case DOMKeyLocationRight:
1500 event_down.modifiers |= WebInputEvent::IsRight;
1501 break;
1502 case DOMKeyLocationNumpad:
[email protected]3db130e2014-03-27 08:14:481503 event_down.modifiers |= WebInputEvent::IsKeyPad;
dtapuskad3ba0f042015-08-27 14:08:051504 break;
1505 }
[email protected]3db130e2014-03-27 08:14:481506
1507 WebKeyboardEvent event_up;
1508 event_up = event_down;
1509 event_up.type = WebInputEvent::KeyUp;
1510 // EventSender.m forces a layout here, with at least one
1511 // test (fast/forms/focus-control-to-page.html) relying on this.
1512 if (force_layout_on_events_)
wkorman7265db012015-11-03 04:08:251513 view_->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481514
1515 // In the browser, if a keyboard event corresponds to an editor command,
1516 // the command will be dispatched to the renderer just before dispatching
1517 // the keyboard event, and then it will be executed in the
1518 // RenderView::handleCurrentKeyboardEvent() method.
1519 // We just simulate the same behavior here.
1520 std::string edit_command;
1521 if (GetEditCommand(event_down, &edit_command))
abhishek.a21ca9b5602014-09-19 07:33:331522 delegate_->SetEditCommand(edit_command, "");
[email protected]3db130e2014-03-27 08:14:481523
tkent588765612014-11-28 01:07:481524 HandleInputEventOnViewOrPopup(event_down);
[email protected]3db130e2014-03-27 08:14:481525
[email protected]a731f1a92014-04-17 19:31:061526 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) {
[email protected]3db130e2014-03-27 08:14:481527 WebMouseEvent event;
1528 InitMouseEvent(WebInputEvent::MouseDown,
1529 pressed_button_,
mustaq21aed4e2015-12-15 21:47:211530 current_buttons_,
[email protected]3db130e2014-03-27 08:14:481531 last_mouse_pos_,
1532 GetCurrentEventTimeSec(),
1533 click_count_,
1534 0,
1535 &event);
1536 FinishDragAndDrop(event, blink::WebDragOperationNone);
1537 }
1538
abhishek.a21ca9b5602014-09-19 07:33:331539 delegate_->ClearEditCommand();
[email protected]3db130e2014-03-27 08:14:481540
1541 if (generate_char) {
1542 WebKeyboardEvent event_char = event_up;
1543 event_char.type = WebInputEvent::Char;
rob994f9e82014-11-02 20:55:041544 // keyIdentifier is an empty string, unless the Enter key was pressed.
1545 // This behavior is not standard (keyIdentifier itself is not even a
1546 // standard any more), but it matches the actual behavior in Blink.
1547 if (code != ui::VKEY_RETURN)
1548 event_char.keyIdentifier[0] = '\0';
tkent588765612014-11-28 01:07:481549 HandleInputEventOnViewOrPopup(event_char);
[email protected]3db130e2014-03-27 08:14:481550 }
1551
tkent588765612014-11-28 01:07:481552 HandleInputEventOnViewOrPopup(event_up);
[email protected]3db130e2014-03-27 08:14:481553}
1554
1555void EventSender::EnableDOMUIEventLogging() {}
1556
1557void EventSender::FireKeyboardEventsToElement() {}
1558
1559void EventSender::ClearKillRing() {}
1560
1561std::vector<std::string> EventSender::ContextClick() {
1562 if (force_layout_on_events_) {
wkorman7265db012015-11-03 04:08:251563 view_->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481564 }
1565
1566 UpdateClickCountForButton(WebMouseEvent::ButtonRight);
1567
1568 // Clears last context menu data because we need to know if the context menu
1569 // be requested after following mouse events.
1570 last_context_menu_data_.reset();
1571
1572 // Generate right mouse down and up.
1573 WebMouseEvent event;
1574 // This is a hack to work around only allowing a single pressed button since
1575 // we want to test the case where both the left and right mouse buttons are
1576 // pressed.
mustaq21aed4e2015-12-15 21:47:211577 // TODO(mustaq): This hack seems unused here! But do we need this hack at all
1578 // after adding current_buttons_.
[email protected]3db130e2014-03-27 08:14:481579 if (pressed_button_ == WebMouseEvent::ButtonNone) {
1580 pressed_button_ = WebMouseEvent::ButtonRight;
mustaq21aed4e2015-12-15 21:47:211581 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_);
[email protected]3db130e2014-03-27 08:14:481582 }
1583 InitMouseEvent(WebInputEvent::MouseDown,
1584 WebMouseEvent::ButtonRight,
mustaq21aed4e2015-12-15 21:47:211585 current_buttons_,
[email protected]3db130e2014-03-27 08:14:481586 last_mouse_pos_,
1587 GetCurrentEventTimeSec(),
1588 click_count_,
1589 0,
1590 &event);
tkent588765612014-11-28 01:07:481591 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481592
1593#if defined(OS_WIN)
mustaq21aed4e2015-12-15 21:47:211594 current_buttons_ &=
1595 ~GetWebMouseEventModifierForButton(WebMouseEvent::ButtonRight);
1596 pressed_button_= WebMouseEvent::ButtonNone;
1597
[email protected]3db130e2014-03-27 08:14:481598 InitMouseEvent(WebInputEvent::MouseUp,
1599 WebMouseEvent::ButtonRight,
mustaq21aed4e2015-12-15 21:47:211600 current_buttons_,
[email protected]3db130e2014-03-27 08:14:481601 last_mouse_pos_,
1602 GetCurrentEventTimeSec(),
1603 click_count_,
1604 0,
1605 &event);
tkent588765612014-11-28 01:07:481606 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481607#endif
1608
jochen73e711c2015-06-03 10:01:461609 std::vector<std::string> menu_items =
1610 MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate_);
[email protected]e7c71192014-04-23 11:53:481611 last_context_menu_data_.reset();
1612 return menu_items;
[email protected]3db130e2014-03-27 08:14:481613}
1614
1615void EventSender::TextZoomIn() {
1616 view_->setTextZoomFactor(view_->textZoomFactor() * 1.2f);
1617}
1618
1619void EventSender::TextZoomOut() {
1620 view_->setTextZoomFactor(view_->textZoomFactor() / 1.2f);
1621}
1622
1623void EventSender::ZoomPageIn() {
[email protected]8ed8bf432014-08-11 19:47:551624 const std::vector<WebTestProxyBase*>& window_list =
1625 interfaces_->GetWindowList();
[email protected]3db130e2014-03-27 08:14:481626
1627 for (size_t i = 0; i < window_list.size(); ++i) {
[email protected]a1640e42014-05-14 13:43:321628 window_list.at(i)->GetWebView()->setZoomLevel(
1629 window_list.at(i)->GetWebView()->zoomLevel() + 1);
[email protected]3db130e2014-03-27 08:14:481630 }
1631}
1632
1633void EventSender::ZoomPageOut() {
[email protected]8ed8bf432014-08-11 19:47:551634 const std::vector<WebTestProxyBase*>& window_list =
1635 interfaces_->GetWindowList();
[email protected]3db130e2014-03-27 08:14:481636
1637 for (size_t i = 0; i < window_list.size(); ++i) {
[email protected]a1640e42014-05-14 13:43:321638 window_list.at(i)->GetWebView()->setZoomLevel(
1639 window_list.at(i)->GetWebView()->zoomLevel() - 1);
[email protected]3db130e2014-03-27 08:14:481640 }
1641}
1642
[email protected]b32fe542014-04-30 08:42:061643void EventSender::SetPageZoomFactor(double zoom_factor) {
[email protected]8ed8bf432014-08-11 19:47:551644 const std::vector<WebTestProxyBase*>& window_list =
1645 interfaces_->GetWindowList();
[email protected]b32fe542014-04-30 08:42:061646
1647 for (size_t i = 0; i < window_list.size(); ++i) {
[email protected]a1640e42014-05-14 13:43:321648 window_list.at(i)->GetWebView()->setZoomLevel(
jochen7fa00372015-05-13 07:13:351649 std::log(zoom_factor) / std::log(1.2));
[email protected]b32fe542014-04-30 08:42:061650 }
1651}
1652
[email protected]3db130e2014-03-27 08:14:481653void EventSender::ClearTouchPoints() {
1654 touch_points_.clear();
1655}
1656
[email protected]bfb6a602014-04-16 19:59:411657void EventSender::ThrowTouchPointError() {
1658 v8::Isolate* isolate = blink::mainThreadIsolate();
1659 isolate->ThrowException(v8::Exception::TypeError(
1660 gin::StringToV8(isolate, "Invalid touch point.")));
1661}
1662
[email protected]3db130e2014-03-27 08:14:481663void EventSender::ReleaseTouchPoint(unsigned index) {
[email protected]bfb6a602014-04-16 19:59:411664 if (index >= touch_points_.size()) {
1665 ThrowTouchPointError();
1666 return;
1667 }
[email protected]3db130e2014-03-27 08:14:481668
1669 WebTouchPoint* touch_point = &touch_points_[index];
1670 touch_point->state = WebTouchPoint::StateReleased;
1671}
1672
e.hakkinen80033922015-07-31 08:41:351673void EventSender::UpdateTouchPoint(unsigned index,
1674 float x,
1675 float y,
1676 gin::Arguments* args) {
[email protected]bfb6a602014-04-16 19:59:411677 if (index >= touch_points_.size()) {
1678 ThrowTouchPointError();
1679 return;
1680 }
[email protected]3db130e2014-03-27 08:14:481681
1682 WebTouchPoint* touch_point = &touch_points_[index];
1683 touch_point->state = WebTouchPoint::StateMoved;
1684 touch_point->position = WebFloatPoint(x, y);
1685 touch_point->screenPosition = touch_point->position;
e.hakkinen80033922015-07-31 08:41:351686
1687 InitPointerProperties(args, touch_point, &touch_point->radiusX,
1688 &touch_point->radiusY);
[email protected]3db130e2014-03-27 08:14:481689}
1690
1691void EventSender::CancelTouchPoint(unsigned index) {
[email protected]bfb6a602014-04-16 19:59:411692 if (index >= touch_points_.size()) {
1693 ThrowTouchPointError();
1694 return;
1695 }
[email protected]3db130e2014-03-27 08:14:481696
1697 WebTouchPoint* touch_point = &touch_points_[index];
1698 touch_point->state = WebTouchPoint::StateCancelled;
1699}
1700
1701void EventSender::SetTouchModifier(const std::string& key_name,
1702 bool set_mask) {
mustaq21aed4e2015-12-15 21:47:211703 int mask = GetKeyModifier(key_name);
[email protected]3db130e2014-03-27 08:14:481704
1705 if (set_mask)
1706 touch_modifiers_ |= mask;
1707 else
1708 touch_modifiers_ &= ~mask;
1709}
1710
[email protected]ace1cd502014-04-24 21:05:301711void EventSender::SetTouchCancelable(bool cancelable) {
1712 touch_cancelable_ = cancelable;
1713}
1714
[email protected]3db130e2014-03-27 08:14:481715void EventSender::DumpFilenameBeingDragged() {
dchengc3fe4642015-01-22 06:29:521716 if (current_drag_data_.isNull())
1717 return;
1718
[email protected]3db130e2014-03-27 08:14:481719 WebString filename;
1720 WebVector<WebDragData::Item> items = current_drag_data_.items();
1721 for (size_t i = 0; i < items.size(); ++i) {
1722 if (items[i].storageType == WebDragData::Item::StorageTypeBinaryData) {
1723 filename = items[i].title;
1724 break;
1725 }
1726 }
abhishek.a21ca9b5602014-09-19 07:33:331727 delegate_->PrintMessage(std::string("Filename being dragged: ") +
[email protected]3db130e2014-03-27 08:14:481728 filename.utf8().data() + "\n");
1729}
1730
1731void EventSender::GestureFlingCancel() {
1732 WebGestureEvent event;
1733 event.type = WebInputEvent::GestureFlingCancel;
wjmaclean3bb814792015-10-20 01:13:321734 // Generally it won't matter what device we use here, and since it might
1735 // be cumbersome to expect all callers to specify a device, we'll just
1736 // choose Touchpad here.
1737 event.sourceDevice = blink::WebGestureDeviceTouchpad;
[email protected]3db130e2014-03-27 08:14:481738 event.timeStampSeconds = GetCurrentEventTimeSec();
1739
1740 if (force_layout_on_events_)
wkorman7265db012015-11-03 04:08:251741 view_->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481742
tkent588765612014-11-28 01:07:481743 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481744}
1745
1746void EventSender::GestureFlingStart(float x,
tdresser3a1c9722015-02-13 15:44:531747 float y,
1748 float velocity_x,
1749 float velocity_y,
1750 gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:481751 WebGestureEvent event;
1752 event.type = WebInputEvent::GestureFlingStart;
1753
tdresser15af5872015-02-18 14:03:021754 std::string device_string;
1755 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString())
1756 args->GetNext(&device_string);
tdresser3a1c9722015-02-13 15:44:531757
1758 if (device_string == kSourceDeviceStringTouchpad) {
1759 event.sourceDevice = blink::WebGestureDeviceTouchpad;
1760 } else if (device_string == kSourceDeviceStringTouchscreen) {
1761 event.sourceDevice = blink::WebGestureDeviceTouchscreen;
1762 } else {
1763 args->ThrowError();
1764 return;
1765 }
1766
[email protected]3db130e2014-03-27 08:14:481767 event.x = x;
1768 event.y = y;
1769 event.globalX = event.x;
1770 event.globalY = event.y;
1771
1772 event.data.flingStart.velocityX = velocity_x;
1773 event.data.flingStart.velocityY = velocity_y;
1774 event.timeStampSeconds = GetCurrentEventTimeSec();
1775
1776 if (force_layout_on_events_)
wkorman7265db012015-11-03 04:08:251777 view_->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481778
tkent588765612014-11-28 01:07:481779 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481780}
1781
1782void EventSender::GestureScrollFirstPoint(int x, int y) {
1783 current_gesture_location_ = WebPoint(x, y);
1784}
1785
1786void EventSender::TouchStart() {
mustaq96985f722015-06-30 21:41:531787 SendCurrentTouchEvent(WebInputEvent::TouchStart, false);
[email protected]3db130e2014-03-27 08:14:481788}
1789
1790void EventSender::TouchMove() {
mustaq96985f722015-06-30 21:41:531791 SendCurrentTouchEvent(WebInputEvent::TouchMove, false);
1792}
1793
1794void EventSender::TouchMoveCausingScrollIfUncanceled() {
1795 SendCurrentTouchEvent(WebInputEvent::TouchMove, true);
[email protected]3db130e2014-03-27 08:14:481796}
1797
1798void EventSender::TouchCancel() {
mustaq96985f722015-06-30 21:41:531799 SendCurrentTouchEvent(WebInputEvent::TouchCancel, false);
[email protected]3db130e2014-03-27 08:14:481800}
1801
1802void EventSender::TouchEnd() {
mustaq96985f722015-06-30 21:41:531803 SendCurrentTouchEvent(WebInputEvent::TouchEnd, false);
[email protected]3db130e2014-03-27 08:14:481804}
1805
1806void EventSender::LeapForward(int milliseconds) {
1807 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft &&
1808 !replaying_saved_events_) {
1809 SavedEvent saved_event;
1810 saved_event.type = SavedEvent::TYPE_LEAP_FORWARD;
1811 saved_event.milliseconds = milliseconds;
1812 mouse_event_queue_.push_back(saved_event);
1813 } else {
1814 DoLeapForward(milliseconds);
1815 }
1816}
1817
1818void EventSender::BeginDragWithFiles(const std::vector<std::string>& files) {
1819 current_drag_data_.initialize();
1820 WebVector<WebString> absolute_filenames(files.size());
1821 for (size_t i = 0; i < files.size(); ++i) {
1822 WebDragData::Item item;
1823 item.storageType = WebDragData::Item::StorageTypeFilename;
abhishek.a21ca9b5602014-09-19 07:33:331824 item.filenameData = delegate_->GetAbsoluteWebStringFromUTF8Path(files[i]);
[email protected]3db130e2014-03-27 08:14:481825 current_drag_data_.addItem(item);
1826 absolute_filenames[i] = item.filenameData;
1827 }
1828 current_drag_data_.setFilesystemId(
abhishek.a21ca9b5602014-09-19 07:33:331829 delegate_->RegisterIsolatedFileSystem(absolute_filenames));
[email protected]3db130e2014-03-27 08:14:481830 current_drag_effects_allowed_ = blink::WebDragOperationCopy;
1831
1832 // Provide a drag source.
1833 view_->dragTargetDragEnter(current_drag_data_,
1834 last_mouse_pos_,
1835 last_mouse_pos_,
1836 current_drag_effects_allowed_,
1837 0);
1838 // |is_drag_mode_| saves events and then replays them later. We don't
1839 // need/want that.
1840 is_drag_mode_ = false;
1841
1842 // Make the rest of eventSender think a drag is in progress.
1843 pressed_button_ = WebMouseEvent::ButtonLeft;
mustaq21aed4e2015-12-15 21:47:211844 current_buttons_ |= GetWebMouseEventModifierForButton(pressed_button_);
[email protected]3db130e2014-03-27 08:14:481845}
1846
e.hakkinen80033922015-07-31 08:41:351847void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) {
[email protected]3db130e2014-03-27 08:14:481848 WebTouchPoint touch_point;
1849 touch_point.state = WebTouchPoint::StatePressed;
e.hakkinen80033922015-07-31 08:41:351850 touch_point.position = WebFloatPoint(x, y);
[email protected]3db130e2014-03-27 08:14:481851 touch_point.screenPosition = touch_point.position;
1852
mustaq913e8922015-09-09 20:15:361853 int highest_id = -1;
[email protected]3db130e2014-03-27 08:14:481854 for (size_t i = 0; i < touch_points_.size(); i++) {
mustaq913e8922015-09-09 20:15:361855 if (touch_points_[i].id > highest_id)
1856 highest_id = touch_points_[i].id;
[email protected]3db130e2014-03-27 08:14:481857 }
mustaq913e8922015-09-09 20:15:361858 touch_point.id = highest_id + 1;
e.hakkinen80033922015-07-31 08:41:351859
1860 InitPointerProperties(args, &touch_point, &touch_point.radiusX,
1861 &touch_point.radiusY);
1862
[email protected]3db130e2014-03-27 08:14:481863 touch_points_.push_back(touch_point);
1864}
1865
1866void EventSender::MouseDragBegin() {
1867 WebMouseWheelEvent event;
1868 InitMouseEvent(WebInputEvent::MouseWheel,
1869 WebMouseEvent::ButtonNone,
mustaq21aed4e2015-12-15 21:47:211870 0,
[email protected]3db130e2014-03-27 08:14:481871 last_mouse_pos_,
1872 GetCurrentEventTimeSec(),
1873 click_count_,
1874 0,
1875 &event);
1876 event.phase = WebMouseWheelEvent::PhaseBegan;
1877 event.hasPreciseScrollingDeltas = true;
tkent588765612014-11-28 01:07:481878 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481879}
1880
1881void EventSender::MouseDragEnd() {
1882 WebMouseWheelEvent event;
1883 InitMouseEvent(WebInputEvent::MouseWheel,
1884 WebMouseEvent::ButtonNone,
mustaq21aed4e2015-12-15 21:47:211885 0,
[email protected]3db130e2014-03-27 08:14:481886 last_mouse_pos_,
1887 GetCurrentEventTimeSec(),
1888 click_count_,
1889 0,
1890 &event);
1891 event.phase = WebMouseWheelEvent::PhaseEnded;
1892 event.hasPreciseScrollingDeltas = true;
tkent588765612014-11-28 01:07:481893 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481894}
1895
[email protected]3db130e2014-03-27 08:14:481896void EventSender::GestureScrollBegin(gin::Arguments* args) {
1897 GestureEvent(WebInputEvent::GestureScrollBegin, args);
1898}
1899
1900void EventSender::GestureScrollEnd(gin::Arguments* args) {
1901 GestureEvent(WebInputEvent::GestureScrollEnd, args);
1902}
1903
1904void EventSender::GestureScrollUpdate(gin::Arguments* args) {
1905 GestureEvent(WebInputEvent::GestureScrollUpdate, args);
1906}
1907
ccameronb81b8072015-01-30 00:54:491908void EventSender::GesturePinchBegin(gin::Arguments* args) {
1909 GestureEvent(WebInputEvent::GesturePinchBegin, args);
1910}
1911
1912void EventSender::GesturePinchEnd(gin::Arguments* args) {
1913 GestureEvent(WebInputEvent::GesturePinchEnd, args);
1914}
1915
1916void EventSender::GesturePinchUpdate(gin::Arguments* args) {
1917 GestureEvent(WebInputEvent::GesturePinchUpdate, args);
1918}
1919
[email protected]3db130e2014-03-27 08:14:481920void EventSender::GestureTap(gin::Arguments* args) {
1921 GestureEvent(WebInputEvent::GestureTap, args);
1922}
1923
1924void EventSender::GestureTapDown(gin::Arguments* args) {
1925 GestureEvent(WebInputEvent::GestureTapDown, args);
1926}
1927
1928void EventSender::GestureShowPress(gin::Arguments* args) {
1929 GestureEvent(WebInputEvent::GestureShowPress, args);
1930}
1931
1932void EventSender::GestureTapCancel(gin::Arguments* args) {
1933 GestureEvent(WebInputEvent::GestureTapCancel, args);
1934}
1935
1936void EventSender::GestureLongPress(gin::Arguments* args) {
1937 GestureEvent(WebInputEvent::GestureLongPress, args);
1938}
1939
1940void EventSender::GestureLongTap(gin::Arguments* args) {
1941 GestureEvent(WebInputEvent::GestureLongTap, args);
1942}
1943
1944void EventSender::GestureTwoFingerTap(gin::Arguments* args) {
1945 GestureEvent(WebInputEvent::GestureTwoFingerTap, args);
1946}
1947
1948void EventSender::ContinuousMouseScrollBy(gin::Arguments* args) {
1949 WebMouseWheelEvent event;
1950 InitMouseWheelEvent(args, true, &event);
tkent588765612014-11-28 01:07:481951 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:481952}
1953
[email protected]3db130e2014-03-27 08:14:481954void EventSender::MouseMoveTo(gin::Arguments* args) {
1955 if (force_layout_on_events_)
wkorman7265db012015-11-03 04:08:251956 view_->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:481957
[email protected]f53eba122014-04-16 11:30:011958 double x;
1959 double y;
mustaq0fff7fc32014-09-24 20:21:431960 if (!args->GetNext(&x) || !args->GetNext(&y)) {
1961 args->ThrowError();
1962 return;
1963 }
[email protected]f53eba122014-04-16 11:30:011964 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y));
[email protected]3db130e2014-03-27 08:14:481965
1966 int modifiers = 0;
1967 if (!args->PeekNext().IsEmpty())
bashidbd2ef9bb2015-06-02 01:39:321968 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
[email protected]3db130e2014-03-27 08:14:481969
1970 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft &&
1971 !replaying_saved_events_) {
1972 SavedEvent saved_event;
1973 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE;
1974 saved_event.pos = mouse_pos;
1975 saved_event.modifiers = modifiers;
1976 mouse_event_queue_.push_back(saved_event);
1977 } else {
1978 WebMouseEvent event;
1979 InitMouseEvent(WebInputEvent::MouseMove,
1980 pressed_button_,
mustaq21aed4e2015-12-15 21:47:211981 current_buttons_,
[email protected]3db130e2014-03-27 08:14:481982 mouse_pos,
1983 GetCurrentEventTimeSec(),
1984 click_count_,
1985 modifiers,
1986 &event);
1987 DoMouseMove(event);
1988 }
1989}
1990
myid.shin12c7fea22015-03-06 02:31:241991void EventSender::MouseLeave() {
1992 if (force_layout_on_events_)
wkorman7265db012015-11-03 04:08:251993 view_->updateAllLifecyclePhases();
myid.shin12c7fea22015-03-06 02:31:241994
1995 WebMouseEvent event;
1996 InitMouseEvent(WebInputEvent::MouseLeave,
1997 WebMouseEvent::ButtonNone,
mustaq21aed4e2015-12-15 21:47:211998 0,
myid.shin12c7fea22015-03-06 02:31:241999 last_mouse_pos_,
2000 GetCurrentEventTimeSec(),
2001 click_count_,
2002 0,
2003 &event);
majidvpbfabb0712015-10-02 16:30:002004 HandleInputEventOnViewOrPopup(event);
myid.shin12c7fea22015-03-06 02:31:242005}
2006
2007
[email protected]9d80c822014-05-19 19:07:122008void EventSender::TrackpadScrollBegin() {
2009 WebMouseWheelEvent event;
2010 InitMouseEvent(WebInputEvent::MouseWheel,
2011 WebMouseEvent::ButtonNone,
mustaq21aed4e2015-12-15 21:47:212012 0,
[email protected]9d80c822014-05-19 19:07:122013 last_mouse_pos_,
2014 GetCurrentEventTimeSec(),
2015 click_count_,
2016 0,
2017 &event);
2018 event.phase = blink::WebMouseWheelEvent::PhaseBegan;
2019 event.hasPreciseScrollingDeltas = true;
tkent588765612014-11-28 01:07:482020 HandleInputEventOnViewOrPopup(event);
[email protected]9d80c822014-05-19 19:07:122021}
2022
2023void EventSender::TrackpadScroll(gin::Arguments* args) {
2024 WebMouseWheelEvent event;
2025 InitMouseWheelEvent(args, true, &event);
2026 event.phase = blink::WebMouseWheelEvent::PhaseChanged;
2027 event.hasPreciseScrollingDeltas = true;
tkent588765612014-11-28 01:07:482028 HandleInputEventOnViewOrPopup(event);
[email protected]9d80c822014-05-19 19:07:122029}
2030
2031void EventSender::TrackpadScrollEnd() {
2032 WebMouseWheelEvent event;
2033 InitMouseEvent(WebInputEvent::MouseWheel,
2034 WebMouseEvent::ButtonNone,
mustaq21aed4e2015-12-15 21:47:212035 0,
[email protected]9d80c822014-05-19 19:07:122036 last_mouse_pos_,
2037 GetCurrentEventTimeSec(),
2038 click_count_,
2039 0,
2040 &event);
2041 event.phase = WebMouseWheelEvent::PhaseEnded;
2042 event.hasPreciseScrollingDeltas = true;
tkent588765612014-11-28 01:07:482043 HandleInputEventOnViewOrPopup(event);
[email protected]9d80c822014-05-19 19:07:122044}
2045
[email protected]3db130e2014-03-27 08:14:482046void EventSender::MouseScrollBy(gin::Arguments* args) {
2047 WebMouseWheelEvent event;
2048 InitMouseWheelEvent(args, false, &event);
tkent588765612014-11-28 01:07:482049 HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:482050}
2051
[email protected]3db130e2014-03-27 08:14:482052void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) {
abhishek.a21ca9b5602014-09-19 07:33:332053 delegate_->PostTask(new MouseDownTask(this, button_number, modifiers));
2054 delegate_->PostTask(new MouseUpTask(this, button_number, modifiers));
[email protected]3db130e2014-03-27 08:14:482055}
2056
2057void EventSender::ScheduleAsynchronousKeyDown(const std::string& code_str,
2058 int modifiers,
2059 KeyLocationCode location) {
abhishek.a21ca9b5602014-09-19 07:33:332060 delegate_->PostTask(new KeyDownTask(this, code_str, modifiers, location));
[email protected]3db130e2014-03-27 08:14:482061}
2062
2063double EventSender::GetCurrentEventTimeSec() {
majidvpeabdeb82015-11-30 19:02:052064 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF() +
majidvpbfabb0712015-10-02 16:30:002065 time_offset_ms_ / 1000.0;
[email protected]3db130e2014-03-27 08:14:482066}
2067
2068void EventSender::DoLeapForward(int milliseconds) {
2069 time_offset_ms_ += milliseconds;
2070}
2071
mustaq96985f722015-06-30 21:41:532072void EventSender::SendCurrentTouchEvent(WebInputEvent::Type type,
2073 bool causesScrollingIfUncanceled) {
[email protected]3db130e2014-03-27 08:14:482074 DCHECK_GT(static_cast<unsigned>(WebTouchEvent::touchesLengthCap),
2075 touch_points_.size());
2076 if (force_layout_on_events_)
wkorman7265db012015-11-03 04:08:252077 view_->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:482078
2079 WebTouchEvent touch_event;
2080 touch_event.type = type;
2081 touch_event.modifiers = touch_modifiers_;
[email protected]ace1cd502014-04-24 21:05:302082 touch_event.cancelable = touch_cancelable_;
[email protected]3db130e2014-03-27 08:14:482083 touch_event.timeStampSeconds = GetCurrentEventTimeSec();
mustaq96985f722015-06-30 21:41:532084 touch_event.causesScrollingIfUncanceled = causesScrollingIfUncanceled;
[email protected]3db130e2014-03-27 08:14:482085 touch_event.touchesLength = touch_points_.size();
2086 for (size_t i = 0; i < touch_points_.size(); ++i)
2087 touch_event.touches[i] = touch_points_[i];
tkent588765612014-11-28 01:07:482088 HandleInputEventOnViewOrPopup(touch_event);
[email protected]3db130e2014-03-27 08:14:482089
2090 for (size_t i = 0; i < touch_points_.size(); ++i) {
2091 WebTouchPoint* touch_point = &touch_points_[i];
mustaq913e8922015-09-09 20:15:362092 if (touch_point->state == WebTouchPoint::StateReleased
2093 || touch_point->state == WebTouchPoint::StateCancelled) {
[email protected]3db130e2014-03-27 08:14:482094 touch_points_.erase(touch_points_.begin() + i);
2095 --i;
2096 } else
2097 touch_point->state = WebTouchPoint::StateStationary;
2098 }
2099}
2100
2101void EventSender::GestureEvent(WebInputEvent::Type type,
majidvp41c4272a2014-12-08 15:51:142102 gin::Arguments* args) {
ccameronb81b8072015-01-30 00:54:492103 WebGestureEvent event;
2104 event.type = type;
2105
2106 // If the first argument is a string, it is to specify the device, otherwise
2107 // the device is assumed to be a touchscreen (since most tests were written
2108 // assuming this).
2109 event.sourceDevice = blink::WebGestureDeviceTouchscreen;
jochen87d2fee2015-07-13 08:21:342110 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) {
ccameronb81b8072015-01-30 00:54:492111 std::string device_string;
2112 if (!args->GetNext(&device_string)) {
2113 args->ThrowError();
2114 return;
2115 }
tdresser3a1c9722015-02-13 15:44:532116 if (device_string == kSourceDeviceStringTouchpad) {
ccameronb81b8072015-01-30 00:54:492117 event.sourceDevice = blink::WebGestureDeviceTouchpad;
tdresser3a1c9722015-02-13 15:44:532118 } else if (device_string == kSourceDeviceStringTouchscreen) {
ccameronb81b8072015-01-30 00:54:492119 event.sourceDevice = blink::WebGestureDeviceTouchscreen;
2120 } else {
2121 args->ThrowError();
2122 return;
2123 }
2124 }
2125
[email protected]3db130e2014-03-27 08:14:482126 double x;
2127 double y;
mustaq0fff7fc32014-09-24 20:21:432128 if (!args->GetNext(&x) || !args->GetNext(&y)) {
2129 args->ThrowError();
2130 return;
2131 }
[email protected]3db130e2014-03-27 08:14:482132
[email protected]3db130e2014-03-27 08:14:482133 switch (type) {
2134 case WebInputEvent::GestureScrollUpdate:
majidvp50205db2014-11-27 17:28:522135 {
majidvp41c4272a2014-12-08 15:51:142136 bool preventPropagation = false;
2137 if (!args->PeekNext().IsEmpty()) {
majidvp50205db2014-11-27 17:28:522138 if (!args->GetNext(&preventPropagation)) {
2139 args->ThrowError();
2140 return;
2141 }
2142 }
2143
[email protected]3db130e2014-03-27 08:14:482144 event.data.scrollUpdate.deltaX = static_cast<float>(x);
2145 event.data.scrollUpdate.deltaY = static_cast<float>(y);
majidvp50205db2014-11-27 17:28:522146 event.data.scrollUpdate.preventPropagation = preventPropagation;
[email protected]3db130e2014-03-27 08:14:482147 event.x = current_gesture_location_.x;
2148 event.y = current_gesture_location_.y;
2149 current_gesture_location_.x =
2150 current_gesture_location_.x + event.data.scrollUpdate.deltaX;
2151 current_gesture_location_.y =
2152 current_gesture_location_.y + event.data.scrollUpdate.deltaY;
2153 break;
majidvp50205db2014-11-27 17:28:522154 }
[email protected]3db130e2014-03-27 08:14:482155 case WebInputEvent::GestureScrollBegin:
mustaq0fff7fc32014-09-24 20:21:432156 current_gesture_location_ = WebPoint(x, y);
[email protected]3db130e2014-03-27 08:14:482157 event.x = current_gesture_location_.x;
2158 event.y = current_gesture_location_.y;
2159 break;
2160 case WebInputEvent::GestureScrollEnd:
2161 case WebInputEvent::GestureFlingStart:
2162 event.x = current_gesture_location_.x;
2163 event.y = current_gesture_location_.y;
2164 break;
ccameronb81b8072015-01-30 00:54:492165 case WebInputEvent::GesturePinchBegin:
2166 case WebInputEvent::GesturePinchEnd:
2167 current_gesture_location_ = WebPoint(x, y);
2168 event.x = current_gesture_location_.x;
2169 event.y = current_gesture_location_.y;
2170 break;
2171 case WebInputEvent::GesturePinchUpdate:
2172 {
2173 float scale = 1;
2174 if (!args->PeekNext().IsEmpty()) {
2175 if (!args->GetNext(&scale)) {
2176 args->ThrowError();
2177 return;
2178 }
2179 }
2180 event.data.pinchUpdate.scale = scale;
2181 current_gesture_location_ = WebPoint(x, y);
2182 event.x = current_gesture_location_.x;
2183 event.y = current_gesture_location_.y;
2184 break;
2185 }
[email protected]4c07a712014-08-21 17:05:542186 case WebInputEvent::GestureTap:
[email protected]c278d7532014-07-31 19:51:452187 {
2188 float tap_count = 1;
2189 float width = 30;
2190 float height = 30;
[email protected]3db130e2014-03-27 08:14:482191 if (!args->PeekNext().IsEmpty()) {
[email protected]3db130e2014-03-27 08:14:482192 if (!args->GetNext(&tap_count)) {
2193 args->ThrowError();
2194 return;
2195 }
[email protected]3db130e2014-03-27 08:14:482196 }
[email protected]cc42ccf2014-06-27 21:31:432197 if (!args->PeekNext().IsEmpty()) {
[email protected]cc42ccf2014-06-27 21:31:432198 if (!args->GetNext(&width)) {
2199 args->ThrowError();
2200 return;
2201 }
[email protected]cc42ccf2014-06-27 21:31:432202 }
2203 if (!args->PeekNext().IsEmpty()) {
[email protected]cc42ccf2014-06-27 21:31:432204 if (!args->GetNext(&height)) {
2205 args->ThrowError();
2206 return;
2207 }
[email protected]cc42ccf2014-06-27 21:31:432208 }
[email protected]c278d7532014-07-31 19:51:452209 event.data.tap.tapCount = tap_count;
2210 event.data.tap.width = width;
2211 event.data.tap.height = height;
mustaq0fff7fc32014-09-24 20:21:432212 event.x = x;
2213 event.y = y;
[email protected]3db130e2014-03-27 08:14:482214 break;
[email protected]c278d7532014-07-31 19:51:452215 }
[email protected]3db130e2014-03-27 08:14:482216 case WebInputEvent::GestureTapUnconfirmed:
2217 if (!args->PeekNext().IsEmpty()) {
2218 float tap_count;
2219 if (!args->GetNext(&tap_count)) {
2220 args->ThrowError();
2221 return;
2222 }
2223 event.data.tap.tapCount = tap_count;
2224 } else {
2225 event.data.tap.tapCount = 1;
2226 }
mustaq0fff7fc32014-09-24 20:21:432227 event.x = x;
2228 event.y = y;
[email protected]3db130e2014-03-27 08:14:482229 break;
2230 case WebInputEvent::GestureTapDown:
[email protected]c278d7532014-07-31 19:51:452231 {
2232 float width = 30;
2233 float height = 30;
[email protected]3db130e2014-03-27 08:14:482234 if (!args->PeekNext().IsEmpty()) {
[email protected]3db130e2014-03-27 08:14:482235 if (!args->GetNext(&width)) {
2236 args->ThrowError();
2237 return;
2238 }
[email protected]3db130e2014-03-27 08:14:482239 }
2240 if (!args->PeekNext().IsEmpty()) {
[email protected]3db130e2014-03-27 08:14:482241 if (!args->GetNext(&height)) {
2242 args->ThrowError();
2243 return;
2244 }
[email protected]3db130e2014-03-27 08:14:482245 }
mustaq0fff7fc32014-09-24 20:21:432246 event.x = x;
2247 event.y = y;
[email protected]c278d7532014-07-31 19:51:452248 event.data.tapDown.width = width;
2249 event.data.tapDown.height = height;
2250 break;
2251 }
2252 case WebInputEvent::GestureShowPress:
2253 {
2254 float width = 30;
2255 float height = 30;
[email protected]3db130e2014-03-27 08:14:482256 if (!args->PeekNext().IsEmpty()) {
[email protected]3db130e2014-03-27 08:14:482257 if (!args->GetNext(&width)) {
2258 args->ThrowError();
2259 return;
2260 }
[email protected]3db130e2014-03-27 08:14:482261 if (!args->PeekNext().IsEmpty()) {
[email protected]3db130e2014-03-27 08:14:482262 if (!args->GetNext(&height)) {
2263 args->ThrowError();
2264 return;
2265 }
[email protected]3db130e2014-03-27 08:14:482266 }
2267 }
mustaq0fff7fc32014-09-24 20:21:432268 event.x = x;
2269 event.y = y;
[email protected]c278d7532014-07-31 19:51:452270 event.data.showPress.width = width;
2271 event.data.showPress.height = height;
[email protected]3db130e2014-03-27 08:14:482272 break;
[email protected]c278d7532014-07-31 19:51:452273 }
[email protected]3db130e2014-03-27 08:14:482274 case WebInputEvent::GestureTapCancel:
mustaq0fff7fc32014-09-24 20:21:432275 event.x = x;
2276 event.y = y;
[email protected]3db130e2014-03-27 08:14:482277 break;
2278 case WebInputEvent::GestureLongPress:
mustaq0fff7fc32014-09-24 20:21:432279 event.x = x;
2280 event.y = y;
[email protected]3db130e2014-03-27 08:14:482281 if (!args->PeekNext().IsEmpty()) {
2282 float width;
2283 if (!args->GetNext(&width)) {
2284 args->ThrowError();
2285 return;
2286 }
2287 event.data.longPress.width = width;
2288 if (!args->PeekNext().IsEmpty()) {
2289 float height;
2290 if (!args->GetNext(&height)) {
2291 args->ThrowError();
2292 return;
2293 }
2294 event.data.longPress.height = height;
2295 }
2296 }
2297 break;
2298 case WebInputEvent::GestureLongTap:
mustaq0fff7fc32014-09-24 20:21:432299 event.x = x;
2300 event.y = y;
[email protected]3db130e2014-03-27 08:14:482301 if (!args->PeekNext().IsEmpty()) {
2302 float width;
2303 if (!args->GetNext(&width)) {
2304 args->ThrowError();
2305 return;
2306 }
2307 event.data.longPress.width = width;
2308 if (!args->PeekNext().IsEmpty()) {
2309 float height;
2310 if (!args->GetNext(&height)) {
2311 args->ThrowError();
2312 return;
2313 }
2314 event.data.longPress.height = height;
2315 }
2316 }
2317 break;
2318 case WebInputEvent::GestureTwoFingerTap:
mustaq0fff7fc32014-09-24 20:21:432319 event.x = x;
2320 event.y = y;
[email protected]3db130e2014-03-27 08:14:482321 if (!args->PeekNext().IsEmpty()) {
2322 float first_finger_width;
2323 if (!args->GetNext(&first_finger_width)) {
2324 args->ThrowError();
2325 return;
2326 }
2327 event.data.twoFingerTap.firstFingerWidth = first_finger_width;
2328 if (!args->PeekNext().IsEmpty()) {
2329 float first_finger_height;
2330 if (!args->GetNext(&first_finger_height)) {
2331 args->ThrowError();
2332 return;
2333 }
2334 event.data.twoFingerTap.firstFingerHeight = first_finger_height;
2335 }
2336 }
2337 break;
2338 default:
2339 NOTREACHED();
2340 }
2341
2342 event.globalX = event.x;
2343 event.globalY = event.y;
2344 event.timeStampSeconds = GetCurrentEventTimeSec();
2345
2346 if (force_layout_on_events_)
wkorman7265db012015-11-03 04:08:252347 view_->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:482348
dtapuska5d2e9c32015-12-03 16:39:492349 WebInputEventResult result = HandleInputEventOnViewOrPopup(event);
[email protected]3db130e2014-03-27 08:14:482350
2351 // Long press might start a drag drop session. Complete it if so.
2352 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) {
2353 WebMouseEvent mouse_event;
2354 InitMouseEvent(WebInputEvent::MouseDown,
2355 pressed_button_,
mustaq21aed4e2015-12-15 21:47:212356 current_buttons_,
mustaq0fff7fc32014-09-24 20:21:432357 WebPoint(x, y),
[email protected]3db130e2014-03-27 08:14:482358 GetCurrentEventTimeSec(),
2359 click_count_,
mustaq21aed4e2015-12-15 21:47:212360 modifiers_,
[email protected]3db130e2014-03-27 08:14:482361 &mouse_event);
2362
2363 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone);
2364 }
dtapuska5d2e9c32015-12-03 16:39:492365 args->Return(result != WebInputEventResult::NotHandled);
[email protected]3db130e2014-03-27 08:14:482366}
2367
2368void EventSender::UpdateClickCountForButton(
2369 WebMouseEvent::Button button_type) {
2370 if ((GetCurrentEventTimeSec() - last_click_time_sec_ <
2371 kMultipleClickTimeSec) &&
2372 (!OutsideMultiClickRadius(last_mouse_pos_, last_click_pos_)) &&
2373 (button_type == last_button_type_)) {
2374 ++click_count_;
2375 } else {
2376 click_count_ = 1;
2377 last_button_type_ = button_type;
2378 }
2379}
2380
2381void EventSender::InitMouseWheelEvent(gin::Arguments* args,
2382 bool continuous,
2383 WebMouseWheelEvent* event) {
2384 // Force a layout here just to make sure every position has been
2385 // determined before we send events (as well as all the other methods
2386 // that send an event do).
2387 if (force_layout_on_events_)
wkorman7265db012015-11-03 04:08:252388 view_->updateAllLifecyclePhases();
[email protected]3db130e2014-03-27 08:14:482389
2390 double horizontal;
2391 if (!args->GetNext(&horizontal)) {
2392 args->ThrowError();
2393 return;
2394 }
2395 double vertical;
2396 if (!args->GetNext(&vertical)) {
2397 args->ThrowError();
2398 return;
2399 }
2400
2401 bool paged = false;
2402 bool has_precise_scrolling_deltas = false;
2403 int modifiers = 0;
lanweia93644f2015-01-21 22:00:332404 bool can_scroll = true;
yutakf3990fd2014-12-23 03:52:382405 if (!args->PeekNext().IsEmpty()) {
2406 args->GetNext(&paged);
2407 if (!args->PeekNext().IsEmpty()) {
2408 args->GetNext(&has_precise_scrolling_deltas);
lanweia93644f2015-01-21 22:00:332409 if (!args->PeekNext().IsEmpty()) {
deepak.s750d68f2015-04-30 07:32:412410 v8::Local<v8::Value> value;
lanweia93644f2015-01-21 22:00:332411 args->GetNext(&value);
bashidbd2ef9bb2015-06-02 01:39:322412 modifiers = GetKeyModifiersFromV8(args->isolate(), value);
lanweia93644f2015-01-21 22:00:332413 if (!args->PeekNext().IsEmpty())
2414 args->GetNext(&can_scroll);
2415 }
yutakf3990fd2014-12-23 03:52:382416 }
2417 }
[email protected]3db130e2014-03-27 08:14:482418
2419 InitMouseEvent(WebInputEvent::MouseWheel,
2420 pressed_button_,
mustaq21aed4e2015-12-15 21:47:212421 current_buttons_,
[email protected]3db130e2014-03-27 08:14:482422 last_mouse_pos_,
2423 GetCurrentEventTimeSec(),
2424 click_count_,
2425 modifiers,
2426 event);
2427 event->wheelTicksX = static_cast<float>(horizontal);
2428 event->wheelTicksY = static_cast<float>(vertical);
2429 event->deltaX = event->wheelTicksX;
2430 event->deltaY = event->wheelTicksY;
2431 event->scrollByPage = paged;
2432 event->hasPreciseScrollingDeltas = has_precise_scrolling_deltas;
lanweia93644f2015-01-21 22:00:332433 event->canScroll = can_scroll;
[email protected]3db130e2014-03-27 08:14:482434 if (continuous) {
2435 event->wheelTicksX /= kScrollbarPixelsPerTick;
2436 event->wheelTicksY /= kScrollbarPixelsPerTick;
2437 } else {
2438 event->deltaX *= kScrollbarPixelsPerTick;
2439 event->deltaY *= kScrollbarPixelsPerTick;
2440 }
2441}
2442
e.hakkinen80033922015-07-31 08:41:352443// Radius fields radius_x and radius_y should eventually be moved to
2444// WebPointerProperties.
2445// TODO(e_hakkinen): Drop radius_{x,y}_pointer parameters once that happens.
2446void EventSender::InitPointerProperties(gin::Arguments* args,
2447 blink::WebPointerProperties* e,
2448 float* radius_x_pointer,
2449 float* radius_y_pointer) {
2450 if (!args->PeekNext().IsEmpty()) {
2451 double radius_x;
2452 if (!args->GetNext(&radius_x)) {
2453 args->ThrowError();
2454 return;
2455 }
2456
2457 double radius_y = radius_x;
2458 if (!args->PeekNext().IsEmpty()) {
2459 if (!args->GetNext(&radius_y)) {
2460 args->ThrowError();
2461 return;
2462 }
2463 }
2464
2465 *radius_x_pointer = static_cast<float>(radius_x);
2466 *radius_y_pointer = static_cast<float>(radius_y);
2467 }
2468
2469 if (!args->PeekNext().IsEmpty()) {
2470 double force;
2471 if (!args->GetNext(&force)) {
2472 args->ThrowError();
2473 return;
2474 }
2475 e->force = static_cast<float>(force);
2476 }
2477
2478 if (!args->PeekNext().IsEmpty()) {
2479 int tiltX, tiltY;
2480 if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) {
2481 args->ThrowError();
2482 return;
2483 }
2484 e->tiltX = tiltX;
2485 e->tiltY = tiltY;
2486 }
2487
2488 if (!args->PeekNext().IsEmpty()) {
2489 std::string pointer_type_string;
2490 if (!args->GetNext(&pointer_type_string)) {
2491 args->ThrowError();
2492 return;
2493 }
2494 if (pointer_type_string == kPointerTypeStringUnknown) {
mustaq496d6f3c2015-10-08 16:17:192495 e->pointerType = WebMouseEvent::PointerType::Unknown;
e.hakkinen80033922015-07-31 08:41:352496 } else if (pointer_type_string == kPointerTypeStringMouse) {
mustaq496d6f3c2015-10-08 16:17:192497 e->pointerType = WebMouseEvent::PointerType::Mouse;
e.hakkinen80033922015-07-31 08:41:352498 } else if (pointer_type_string == kPointerTypeStringPen) {
mustaq496d6f3c2015-10-08 16:17:192499 e->pointerType = WebMouseEvent::PointerType::Pen;
e.hakkinen80033922015-07-31 08:41:352500 } else if (pointer_type_string == kPointerTypeStringTouch) {
mustaq496d6f3c2015-10-08 16:17:192501 e->pointerType = WebMouseEvent::PointerType::Touch;
e.hakkinen80033922015-07-31 08:41:352502 } else {
2503 args->ThrowError();
2504 return;
2505 }
2506 }
2507}
2508
[email protected]3db130e2014-03-27 08:14:482509void EventSender::FinishDragAndDrop(const WebMouseEvent& e,
2510 blink::WebDragOperation drag_effect) {
2511 WebPoint client_point(e.x, e.y);
2512 WebPoint screen_point(e.globalX, e.globalY);
2513 current_drag_effect_ = drag_effect;
2514 if (current_drag_effect_) {
2515 // Specifically pass any keyboard modifiers to the drop method. This allows
2516 // tests to control the drop type (i.e. copy or move).
2517 view_->dragTargetDrop(client_point, screen_point, e.modifiers);
2518 } else {
2519 view_->dragTargetDragLeave();
2520 }
2521 view_->dragSourceEndedAt(client_point, screen_point, current_drag_effect_);
2522 view_->dragSourceSystemDragEnded();
2523
2524 current_drag_data_.reset();
2525}
2526
2527void EventSender::DoMouseUp(const WebMouseEvent& e) {
tkent588765612014-11-28 01:07:482528 HandleInputEventOnViewOrPopup(e);
[email protected]3db130e2014-03-27 08:14:482529
[email protected]3db130e2014-03-27 08:14:482530 last_click_time_sec_ = e.timeStampSeconds;
2531 last_click_pos_ = last_mouse_pos_;
2532
2533 // If we're in a drag operation, complete it.
2534 if (current_drag_data_.isNull())
2535 return;
2536
2537 WebPoint client_point(e.x, e.y);
2538 WebPoint screen_point(e.globalX, e.globalY);
2539 FinishDragAndDrop(
2540 e,
2541 view_->dragTargetDragOver(
jinho.banga7447af2015-03-11 04:56:582542 client_point,
2543 screen_point,
2544 current_drag_effects_allowed_,
2545 e.modifiers));
[email protected]3db130e2014-03-27 08:14:482546}
2547
2548void EventSender::DoMouseMove(const WebMouseEvent& e) {
2549 last_mouse_pos_ = WebPoint(e.x, e.y);
2550
tkent588765612014-11-28 01:07:482551 HandleInputEventOnViewOrPopup(e);
[email protected]3db130e2014-03-27 08:14:482552
2553 if (pressed_button_ == WebMouseEvent::ButtonNone ||
2554 current_drag_data_.isNull()) {
2555 return;
2556 }
2557
2558 WebPoint client_point(e.x, e.y);
2559 WebPoint screen_point(e.globalX, e.globalY);
2560 current_drag_effect_ = view_->dragTargetDragOver(
jinho.banga7447af2015-03-11 04:56:582561 client_point, screen_point, current_drag_effects_allowed_, e.modifiers);
[email protected]3db130e2014-03-27 08:14:482562}
2563
2564void EventSender::ReplaySavedEvents() {
2565 replaying_saved_events_ = true;
2566 while (!mouse_event_queue_.empty()) {
2567 SavedEvent e = mouse_event_queue_.front();
2568 mouse_event_queue_.pop_front();
2569
2570 switch (e.type) {
2571 case SavedEvent::TYPE_MOUSE_MOVE: {
2572 WebMouseEvent event;
2573 InitMouseEvent(WebInputEvent::MouseMove,
2574 pressed_button_,
mustaq21aed4e2015-12-15 21:47:212575 current_buttons_,
[email protected]3db130e2014-03-27 08:14:482576 e.pos,
2577 GetCurrentEventTimeSec(),
2578 click_count_,
2579 e.modifiers,
2580 &event);
2581 DoMouseMove(event);
2582 break;
2583 }
2584 case SavedEvent::TYPE_LEAP_FORWARD:
2585 DoLeapForward(e.milliseconds);
2586 break;
2587 case SavedEvent::TYPE_MOUSE_UP: {
mustaq21aed4e2015-12-15 21:47:212588 current_buttons_ &= ~GetWebMouseEventModifierForButton(e.button_type);
2589 pressed_button_ = WebMouseEvent::ButtonNone;
2590
[email protected]3db130e2014-03-27 08:14:482591 WebMouseEvent event;
2592 InitMouseEvent(WebInputEvent::MouseUp,
2593 e.button_type,
mustaq21aed4e2015-12-15 21:47:212594 current_buttons_,
[email protected]3db130e2014-03-27 08:14:482595 last_mouse_pos_,
2596 GetCurrentEventTimeSec(),
2597 click_count_,
2598 e.modifiers,
2599 &event);
2600 DoMouseUp(event);
2601 break;
2602 }
2603 default:
2604 NOTREACHED();
2605 }
2606 }
2607
2608 replaying_saved_events_ = false;
2609}
2610
dtapuska5d2e9c32015-12-03 16:39:492611WebInputEventResult EventSender::HandleInputEventOnViewOrPopup(
2612 const WebInputEvent& event) {
majidvpbfabb0712015-10-02 16:30:002613 last_event_timestamp_ = event.timeStampSeconds;
2614
tkent588765612014-11-28 01:07:482615 if (WebPagePopup* popup = view_->pagePopup()) {
2616 if (!WebInputEvent::isKeyboardEventType(event.type))
2617 return popup->handleInputEvent(event);
2618 }
2619 return view_->handleInputEvent(event);
2620}
2621
jochenf5f31752015-06-03 12:06:342622} // namespace test_runner