[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 5 | #include "content/shell/test_runner/event_sender.h" |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 6 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 9 | #include <memory> |
| 10 | |
lukasza | c935882 | 2016-04-07 14:43:46 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/bind_helpers.h" |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 13 | #include "base/command_line.h" |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 15 | #include "base/logging.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 16 | #include "base/macros.h" |
esprehn | d29ab80 | 2015-12-11 13:01:19 | [diff] [blame] | 17 | #include "base/strings/string16.h" |
habib.virji | 565c80c | 2015-02-06 12:26:43 | [diff] [blame] | 18 | #include "base/strings/string_util.h" |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 19 | #include "base/strings/stringprintf.h" |
esprehn | d29ab80 | 2015-12-11 13:01:19 | [diff] [blame] | 20 | #include "base/strings/utf_string_conversions.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 21 | #include "build/build_config.h" |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 22 | #include "content/shell/test_runner/mock_spell_check.h" |
| 23 | #include "content/shell/test_runner/test_interfaces.h" |
| 24 | #include "content/shell/test_runner/web_test_delegate.h" |
| 25 | #include "content/shell/test_runner/web_view_test_proxy.h" |
| 26 | #include "content/shell/test_runner/web_widget_test_proxy.h" |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 27 | #include "gin/handle.h" |
| 28 | #include "gin/object_template_builder.h" |
| 29 | #include "gin/wrappable.h" |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 30 | #include "net/base/filename_util.h" |
| 31 | #include "third_party/WebKit/public/platform/URLConversion.h" |
nzolghadr | 5d859650 | 2017-01-23 22:59:35 | [diff] [blame] | 32 | #include "third_party/WebKit/public/platform/WebCoalescedInputEvent.h" |
dtapuska | 836e1f9 | 2016-11-15 00:38:06 | [diff] [blame] | 33 | #include "third_party/WebKit/public/platform/WebGestureEvent.h" |
dtapuska | a64845d | 2017-01-20 21:20:45 | [diff] [blame] | 34 | #include "third_party/WebKit/public/platform/WebKeyboardEvent.h" |
mustaq | cc6220fa | 2016-03-09 22:07:54 | [diff] [blame] | 35 | #include "third_party/WebKit/public/platform/WebPointerProperties.h" |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 36 | #include "third_party/WebKit/public/platform/WebString.h" |
dtapuska | a64845d | 2017-01-20 21:20:45 | [diff] [blame] | 37 | #include "third_party/WebKit/public/platform/WebTouchEvent.h" |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 38 | #include "third_party/WebKit/public/platform/WebVector.h" |
| 39 | #include "third_party/WebKit/public/web/WebContextMenuData.h" |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 40 | #include "third_party/WebKit/public/web/WebFrameWidget.h" |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 41 | #include "third_party/WebKit/public/web/WebKit.h" |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 42 | #include "third_party/WebKit/public/web/WebLocalFrame.h" |
tkent | 58876561 | 2014-11-28 01:07:48 | [diff] [blame] | 43 | #include "third_party/WebKit/public/web/WebPagePopup.h" |
Mustaq Ahmed | c9b974a | 2018-01-22 19:43:44 | [diff] [blame] | 44 | #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 45 | #include "third_party/WebKit/public/web/WebView.h" |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 46 | #include "ui/events/blink/blink_event_util.h" |
kpschoedel | 3b0960a | 2015-05-11 17:52:11 | [diff] [blame] | 47 | #include "ui/events/keycodes/dom/keycode_converter.h" |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 48 | #include "ui/events/keycodes/keyboard_codes.h" |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 49 | #include "v8/include/v8.h" |
| 50 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 51 | using blink::WebContextMenuData; |
| 52 | using blink::WebDragData; |
| 53 | using blink::WebDragOperationsMask; |
| 54 | using blink::WebFloatPoint; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 55 | using blink::WebGestureEvent; |
| 56 | using blink::WebInputEvent; |
dtapuska | 5d2e9c3 | 2015-12-03 16:39:49 | [diff] [blame] | 57 | using blink::WebInputEventResult; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 58 | using blink::WebKeyboardEvent; |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 59 | using blink::WebLocalFrame; |
[email protected] | f9634a8 | 2014-08-05 13:10:19 | [diff] [blame] | 60 | using blink::WebMenuItemInfo; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 61 | using blink::WebMouseEvent; |
| 62 | using blink::WebMouseWheelEvent; |
tkent | 58876561 | 2014-11-28 01:07:48 | [diff] [blame] | 63 | using blink::WebPagePopup; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 64 | using blink::WebPoint; |
Navid Zolghadr | 24ff17d | 2018-01-24 20:58:04 | [diff] [blame] | 65 | using blink::WebPointerEvent; |
mustaq | cc6220fa | 2016-03-09 22:07:54 | [diff] [blame] | 66 | using blink::WebPointerProperties; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 67 | using blink::WebString; |
| 68 | using blink::WebTouchEvent; |
| 69 | using blink::WebTouchPoint; |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 70 | using blink::WebURL; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 71 | using blink::WebVector; |
| 72 | using blink::WebView; |
| 73 | |
jochen | f5f3175 | 2015-06-03 12:06:34 | [diff] [blame] | 74 | namespace test_runner { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 75 | |
| 76 | namespace { |
| 77 | |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 78 | const int kRawMousePointerId = -1; |
mustaq | 758b115 | 2016-09-02 22:06:43 | [diff] [blame] | 79 | const char* const kPointerTypeStringUnknown = ""; |
| 80 | const char* const kPointerTypeStringMouse = "mouse"; |
| 81 | const char* const kPointerTypeStringTouch = "touch"; |
| 82 | const char* const kPointerTypeStringPen = "pen"; |
| 83 | const char* const kPointerTypeStringEraser = "eraser"; |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 84 | |
| 85 | // Assigns |pointerType| from the provided |args|. Returns false if there was |
| 86 | // any error. |
chongz | d65eacf | 2017-06-28 05:21:59 | [diff] [blame] | 87 | bool GetPointerType(gin::Arguments* args, |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 88 | bool isOnlyMouseAndPenAllowed, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 89 | WebPointerProperties::PointerType& pointerType) { |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 90 | if (args->PeekNext().IsEmpty()) |
| 91 | return true; |
| 92 | std::string pointer_type_string; |
| 93 | if (!args->GetNext(&pointer_type_string)) { |
| 94 | args->ThrowError(); |
| 95 | return false; |
| 96 | } |
| 97 | if (isOnlyMouseAndPenAllowed && |
| 98 | (pointer_type_string == kPointerTypeStringUnknown || |
| 99 | pointer_type_string == kPointerTypeStringTouch)) { |
| 100 | args->ThrowError(); |
| 101 | return false; |
| 102 | } |
| 103 | if (pointer_type_string == kPointerTypeStringUnknown) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 104 | pointerType = WebMouseEvent::PointerType::kUnknown; |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 105 | } else if (pointer_type_string == kPointerTypeStringMouse) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 106 | pointerType = WebMouseEvent::PointerType::kMouse; |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 107 | } else if (pointer_type_string == kPointerTypeStringTouch) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 108 | pointerType = WebMouseEvent::PointerType::kTouch; |
mustaq | 758b115 | 2016-09-02 22:06:43 | [diff] [blame] | 109 | } else if (pointer_type_string == kPointerTypeStringPen) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 110 | pointerType = WebMouseEvent::PointerType::kPen; |
mustaq | 758b115 | 2016-09-02 22:06:43 | [diff] [blame] | 111 | } else if (pointer_type_string == kPointerTypeStringEraser) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 112 | pointerType = WebMouseEvent::PointerType::kEraser; |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 113 | } else { |
| 114 | args->ThrowError(); |
| 115 | return false; |
| 116 | } |
| 117 | return true; |
| 118 | } |
| 119 | |
Navid Zolghadr | 24ff17d | 2018-01-24 20:58:04 | [diff] [blame] | 120 | WebInputEvent::Type PointerEventTypeForTouchPointState( |
| 121 | WebTouchPoint::State state) { |
| 122 | switch (state) { |
| 123 | case WebTouchPoint::kStateReleased: |
| 124 | return WebInputEvent::Type::kPointerUp; |
| 125 | case WebTouchPoint::kStateCancelled: |
| 126 | return WebInputEvent::Type::kPointerCancel; |
| 127 | case WebTouchPoint::kStatePressed: |
| 128 | return WebInputEvent::Type::kPointerDown; |
| 129 | case WebTouchPoint::kStateMoved: |
| 130 | return WebInputEvent::Type::kPointerMove; |
| 131 | case WebTouchPoint::kStateStationary: |
| 132 | default: |
| 133 | NOTREACHED(); |
| 134 | return WebInputEvent::Type::kUndefined; |
| 135 | } |
| 136 | } |
| 137 | |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 138 | // Parses |pointerType|, |rawPointerId|, |pressure|, |tiltX| and |tiltY| from |
| 139 | // the provided |args|. Returns false if there was any error, assuming the last |
| 140 | // 3 of the five parsed parameters are optional. |
| 141 | bool getMousePenPointerProperties( |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 142 | gin::Arguments* args, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 143 | WebPointerProperties::PointerType& pointerType, |
| 144 | int& rawPointerId, |
| 145 | float& pressure, |
| 146 | int& tiltX, |
| 147 | int& tiltY) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 148 | pointerType = WebPointerProperties::PointerType::kMouse; |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 149 | rawPointerId = kRawMousePointerId; |
| 150 | pressure = std::numeric_limits<float>::quiet_NaN(); |
| 151 | tiltX = 0; |
| 152 | tiltY = 0; |
| 153 | |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 154 | // Only allow pen or mouse through this API. |
chongz | d65eacf | 2017-06-28 05:21:59 | [diff] [blame] | 155 | if (!GetPointerType(args, false, pointerType)) |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 156 | return false; |
| 157 | if (!args->PeekNext().IsEmpty()) { |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 158 | if (!args->GetNext(&rawPointerId)) { |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 159 | args->ThrowError(); |
| 160 | return false; |
| 161 | } |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 162 | |
| 163 | // Parse optional params |
| 164 | if (!args->PeekNext().IsEmpty()) { |
| 165 | if (!args->GetNext(&pressure)) { |
| 166 | args->ThrowError(); |
| 167 | return false; |
| 168 | } |
| 169 | if (!args->PeekNext().IsEmpty()) { |
| 170 | if (!args->GetNext(&tiltX)) { |
| 171 | args->ThrowError(); |
| 172 | return false; |
| 173 | } |
| 174 | if (!args->PeekNext().IsEmpty()) { |
| 175 | if (!args->GetNext(&tiltY)) { |
| 176 | args->ThrowError(); |
| 177 | return false; |
| 178 | } |
| 179 | } |
| 180 | } |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 181 | } |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 182 | } |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 183 | |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 184 | return true; |
| 185 | } |
| 186 | |
mustaq | 8911f4e | 2015-10-27 18:10:22 | [diff] [blame] | 187 | WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { |
| 188 | switch (button_code) { |
| 189 | case -1: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 190 | return WebMouseEvent::Button::kNoButton; |
mustaq | 8911f4e | 2015-10-27 18:10:22 | [diff] [blame] | 191 | case 0: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 192 | return WebMouseEvent::Button::kLeft; |
mustaq | 8911f4e | 2015-10-27 18:10:22 | [diff] [blame] | 193 | case 1: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 194 | return WebMouseEvent::Button::kMiddle; |
mustaq | 8911f4e | 2015-10-27 18:10:22 | [diff] [blame] | 195 | case 2: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 196 | return WebMouseEvent::Button::kRight; |
mustaq | 6ee1f8d | 2017-03-31 19:23:04 | [diff] [blame] | 197 | case 3: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 198 | return WebMouseEvent::Button::kBack; |
mustaq | 6ee1f8d | 2017-03-31 19:23:04 | [diff] [blame] | 199 | case 4: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 200 | return WebMouseEvent::Button::kForward; |
mustaq | 8911f4e | 2015-10-27 18:10:22 | [diff] [blame] | 201 | } |
| 202 | NOTREACHED(); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 203 | return WebMouseEvent::Button::kNoButton; |
mustaq | 8911f4e | 2015-10-27 18:10:22 | [diff] [blame] | 204 | } |
| 205 | |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 206 | int GetWebMouseEventModifierForButton(WebMouseEvent::Button button) { |
| 207 | switch (button) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 208 | case WebMouseEvent::Button::kNoButton: |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 209 | return 0; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 210 | case WebMouseEvent::Button::kLeft: |
| 211 | return WebMouseEvent::kLeftButtonDown; |
| 212 | case WebMouseEvent::Button::kMiddle: |
| 213 | return WebMouseEvent::kMiddleButtonDown; |
| 214 | case WebMouseEvent::Button::kRight: |
| 215 | return WebMouseEvent::kRightButtonDown; |
| 216 | case WebPointerProperties::Button::kBack: |
| 217 | return WebMouseEvent::kBackButtonDown; |
| 218 | case WebPointerProperties::Button::kForward: |
| 219 | return WebMouseEvent::kForwardButtonDown; |
| 220 | case WebPointerProperties::Button::kEraser: |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 221 | return 0; // Not implemented yet |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 222 | } |
| 223 | NOTREACHED(); |
| 224 | return 0; |
| 225 | } |
| 226 | |
mustaq | 6ee1f8d | 2017-03-31 19:23:04 | [diff] [blame] | 227 | const int kButtonsInModifiers = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 228 | WebMouseEvent::kLeftButtonDown | WebMouseEvent::kMiddleButtonDown | |
| 229 | WebMouseEvent::kRightButtonDown | WebMouseEvent::kBackButtonDown | |
| 230 | WebMouseEvent::kForwardButtonDown; |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 231 | |
nzolghadr | 65468b4 | 2016-01-19 14:03:58 | [diff] [blame] | 232 | int modifiersWithButtons(int modifiers, int buttons) { |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 233 | return (modifiers & ~kButtonsInModifiers) | (buttons & kButtonsInModifiers); |
nzolghadr | 65468b4 | 2016-01-19 14:03:58 | [diff] [blame] | 234 | } |
| 235 | |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 236 | void InitMouseEventGeneric(WebMouseEvent::Button b, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 237 | int current_buttons, |
| 238 | const WebPoint& pos, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 239 | int click_count, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 240 | WebPointerProperties::PointerType pointerType, |
| 241 | int pointerId, |
| 242 | float pressure, |
| 243 | int tiltX, |
| 244 | int tiltY, |
| 245 | WebMouseEvent* e) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 246 | e->button = b; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 247 | e->SetPositionInWidget(pos.x, pos.y); |
| 248 | e->SetPositionInScreen(pos.x, pos.y); |
| 249 | e->pointer_type = pointerType; |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 250 | e->id = pointerId; |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 251 | e->force = pressure; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 252 | e->tilt_x = tiltX; |
| 253 | e->tilt_y = tiltY; |
| 254 | e->click_count = click_count; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 255 | } |
| 256 | |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 257 | void InitMouseEvent(WebMouseEvent::Button b, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 258 | int current_buttons, |
| 259 | const WebPoint& pos, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 260 | int click_count, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 261 | WebMouseEvent* e) { |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 262 | InitMouseEventGeneric(b, current_buttons, pos, click_count, |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 263 | WebPointerProperties::PointerType::kMouse, 0, 0.0, 0, 0, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 264 | e); |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 265 | } |
| 266 | |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 267 | void InitGestureEventFromMouseWheel(const WebMouseWheelEvent& wheel_event, |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 268 | WebGestureEvent* gesture_event) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 269 | gesture_event->source_device = blink::kWebGestureDeviceTouchpad; |
| 270 | gesture_event->x = wheel_event.PositionInWidget().x; |
| 271 | gesture_event->y = wheel_event.PositionInWidget().y; |
| 272 | gesture_event->global_x = wheel_event.PositionInScreen().x; |
| 273 | gesture_event->global_y = wheel_event.PositionInScreen().y; |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 274 | } |
| 275 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 276 | int GetKeyModifier(const std::string& modifier_name) { |
| 277 | const char* characters = modifier_name.c_str(); |
| 278 | if (!strcmp(characters, "ctrlKey") |
| 279 | #ifndef __APPLE__ |
| 280 | || !strcmp(characters, "addSelectionKey") |
| 281 | #endif |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 282 | ) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 283 | return WebInputEvent::kControlKey; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 284 | } else if (!strcmp(characters, "shiftKey") || |
| 285 | !strcmp(characters, "rangeSelectionKey")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 286 | return WebInputEvent::kShiftKey; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 287 | } else if (!strcmp(characters, "altKey")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 288 | return WebInputEvent::kAltKey; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 289 | #ifdef __APPLE__ |
| 290 | } else if (!strcmp(characters, "metaKey") || |
| 291 | !strcmp(characters, "addSelectionKey")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 292 | return WebInputEvent::kMetaKey; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 293 | #else |
| 294 | } else if (!strcmp(characters, "metaKey")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 295 | return WebInputEvent::kMetaKey; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 296 | #endif |
| 297 | } else if (!strcmp(characters, "autoRepeat")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 298 | return WebInputEvent::kIsAutoRepeat; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 299 | } else if (!strcmp(characters, "copyKey")) { |
| 300 | #ifdef __APPLE__ |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 301 | return WebInputEvent::kAltKey; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 302 | #else |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 303 | return WebInputEvent::kControlKey; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 304 | #endif |
tkent | c8c0bc8 | 2015-10-15 22:43:48 | [diff] [blame] | 305 | } else if (!strcmp(characters, "accessKey")) { |
| 306 | #ifdef __APPLE__ |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 307 | return WebInputEvent::kAltKey | WebInputEvent::kControlKey; |
tkent | c8c0bc8 | 2015-10-15 22:43:48 | [diff] [blame] | 308 | #else |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 309 | return WebInputEvent::kAltKey; |
tkent | c8c0bc8 | 2015-10-15 22:43:48 | [diff] [blame] | 310 | #endif |
jinho.bang | ffc700e | 2014-11-17 04:05:26 | [diff] [blame] | 311 | } else if (!strcmp(characters, "leftButton")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 312 | return WebInputEvent::kLeftButtonDown; |
jinho.bang | ffc700e | 2014-11-17 04:05:26 | [diff] [blame] | 313 | } else if (!strcmp(characters, "middleButton")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 314 | return WebInputEvent::kMiddleButtonDown; |
jinho.bang | ffc700e | 2014-11-17 04:05:26 | [diff] [blame] | 315 | } else if (!strcmp(characters, "rightButton")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 316 | return WebInputEvent::kRightButtonDown; |
mustaq | 6ee1f8d | 2017-03-31 19:23:04 | [diff] [blame] | 317 | } else if (!strcmp(characters, "backButton")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 318 | return WebInputEvent::kBackButtonDown; |
mustaq | 6ee1f8d | 2017-03-31 19:23:04 | [diff] [blame] | 319 | } else if (!strcmp(characters, "forwardButton")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 320 | return WebInputEvent::kForwardButtonDown; |
dtapuska | 299efe1 | 2015-10-05 16:53:44 | [diff] [blame] | 321 | } else if (!strcmp(characters, "capsLockOn")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 322 | return WebInputEvent::kCapsLockOn; |
dtapuska | 299efe1 | 2015-10-05 16:53:44 | [diff] [blame] | 323 | } else if (!strcmp(characters, "numLockOn")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 324 | return WebInputEvent::kNumLockOn; |
dtapuska | 299efe1 | 2015-10-05 16:53:44 | [diff] [blame] | 325 | } else if (!strcmp(characters, "locationLeft")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 326 | return WebInputEvent::kIsLeft; |
dtapuska | 299efe1 | 2015-10-05 16:53:44 | [diff] [blame] | 327 | } else if (!strcmp(characters, "locationRight")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 328 | return WebInputEvent::kIsRight; |
dtapuska | 299efe1 | 2015-10-05 16:53:44 | [diff] [blame] | 329 | } else if (!strcmp(characters, "locationNumpad")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 330 | return WebInputEvent::kIsKeyPad; |
dtapuska | 299efe1 | 2015-10-05 16:53:44 | [diff] [blame] | 331 | } else if (!strcmp(characters, "isComposing")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 332 | return WebInputEvent::kIsComposing; |
dtapuska | 299efe1 | 2015-10-05 16:53:44 | [diff] [blame] | 333 | } else if (!strcmp(characters, "altGraphKey")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 334 | return WebInputEvent::kAltGrKey; |
dtapuska | 299efe1 | 2015-10-05 16:53:44 | [diff] [blame] | 335 | } else if (!strcmp(characters, "fnKey")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 336 | return WebInputEvent::kFnKey; |
dtapuska | 299efe1 | 2015-10-05 16:53:44 | [diff] [blame] | 337 | } else if (!strcmp(characters, "symbolKey")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 338 | return WebInputEvent::kSymbolKey; |
dtapuska | 299efe1 | 2015-10-05 16:53:44 | [diff] [blame] | 339 | } else if (!strcmp(characters, "scrollLockOn")) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 340 | return WebInputEvent::kScrollLockOn; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | int GetKeyModifiers(const std::vector<std::string>& modifier_names) { |
| 347 | int modifiers = 0; |
| 348 | for (std::vector<std::string>::const_iterator it = modifier_names.begin(); |
| 349 | it != modifier_names.end(); ++it) { |
| 350 | modifiers |= GetKeyModifier(*it); |
| 351 | } |
| 352 | return modifiers; |
| 353 | } |
| 354 | |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 355 | int GetKeyModifiersFromV8(v8::Isolate* isolate, v8::Local<v8::Value> value) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 356 | std::vector<std::string> modifier_names; |
| 357 | if (value->IsString()) { |
| 358 | modifier_names.push_back(gin::V8ToString(value)); |
| 359 | } else if (value->IsArray()) { |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 360 | gin::Converter<std::vector<std::string>>::FromV8(isolate, value, |
| 361 | &modifier_names); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 362 | } |
| 363 | return GetKeyModifiers(modifier_names); |
| 364 | } |
| 365 | |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 366 | WebMouseWheelEvent::Phase GetMouseWheelEventPhase( |
| 367 | const std::string& phase_name) { |
| 368 | if (phase_name == "phaseNone") { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 369 | return WebMouseWheelEvent::kPhaseNone; |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 370 | } else if (phase_name == "phaseBegan") { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 371 | return WebMouseWheelEvent::kPhaseBegan; |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 372 | } else if (phase_name == "phaseStationary") { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 373 | return WebMouseWheelEvent::kPhaseStationary; |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 374 | } else if (phase_name == "phaseChanged") { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 375 | return WebMouseWheelEvent::kPhaseChanged; |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 376 | } else if (phase_name == "phaseEnded") { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 377 | return WebMouseWheelEvent::kPhaseEnded; |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 378 | } else if (phase_name == "phaseCancelled") { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 379 | return WebMouseWheelEvent::kPhaseCancelled; |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 380 | } else if (phase_name == "phaseMayBegin") { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 381 | return WebMouseWheelEvent::kPhaseMayBegin; |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 382 | } |
| 383 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 384 | return WebMouseWheelEvent::kPhaseNone; |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | WebMouseWheelEvent::Phase GetMouseWheelEventPhaseFromV8( |
| 388 | v8::Local<v8::Value> value) { |
| 389 | if (value->IsString()) |
| 390 | return GetMouseWheelEventPhase(gin::V8ToString(value)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 391 | return WebMouseWheelEvent::kPhaseNone; |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 392 | } |
| 393 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 394 | // Maximum distance (in space and time) for a mouse click to register as a |
| 395 | // double or triple click. |
| 396 | const double kMultipleClickTimeSec = 1; |
| 397 | const int kMultipleClickRadiusPixels = 5; |
[email protected] | f9634a8 | 2014-08-05 13:10:19 | [diff] [blame] | 398 | const char kSubMenuDepthIdentifier[] = "_"; |
| 399 | const char kSubMenuIdentifier[] = " >"; |
sanjoy.pal | 362c325 | 2014-08-26 08:07:08 | [diff] [blame] | 400 | const char kSeparatorIdentifier[] = "---------"; |
sanjoy.pal | a62675e | 2014-11-27 00:47:29 | [diff] [blame] | 401 | const char kDisabledIdentifier[] = "#"; |
| 402 | const char kCheckedIdentifier[] = "*"; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 403 | |
| 404 | bool OutsideMultiClickRadius(const WebPoint& a, const WebPoint& b) { |
| 405 | return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) > |
| 406 | kMultipleClickRadiusPixels * kMultipleClickRadiusPixels; |
| 407 | } |
| 408 | |
[email protected] | f9634a8 | 2014-08-05 13:10:19 | [diff] [blame] | 409 | void PopulateCustomItems(const WebVector<WebMenuItemInfo>& customItems, |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 410 | const std::string& prefix, |
| 411 | std::vector<std::string>* strings) { |
[email protected] | f9634a8 | 2014-08-05 13:10:19 | [diff] [blame] | 412 | for (size_t i = 0; i < customItems.size(); ++i) { |
sanjoy.pal | a62675e | 2014-11-27 00:47:29 | [diff] [blame] | 413 | std::string prefixCopy = prefix; |
| 414 | if (!customItems[i].enabled) |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 415 | prefixCopy = kDisabledIdentifier + prefix; |
sanjoy.pal | a62675e | 2014-11-27 00:47:29 | [diff] [blame] | 416 | if (customItems[i].checked) |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 417 | prefixCopy = kCheckedIdentifier + prefix; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 418 | if (customItems[i].type == blink::WebMenuItemInfo::kSeparator) { |
sanjoy.pal | a62675e | 2014-11-27 00:47:29 | [diff] [blame] | 419 | strings->push_back(prefixCopy + kSeparatorIdentifier); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 420 | } else if (customItems[i].type == blink::WebMenuItemInfo::kSubMenu) { |
| 421 | strings->push_back(prefixCopy + customItems[i].label.Utf8() + |
Kent Tamura | 08b987e | 2017-06-13 08:45:40 | [diff] [blame] | 422 | kSubMenuIdentifier); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 423 | PopulateCustomItems(customItems[i].sub_menu_items, |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 424 | prefixCopy + kSubMenuDepthIdentifier, strings); |
[email protected] | f9634a8 | 2014-08-05 13:10:19 | [diff] [blame] | 425 | } else { |
Kent Tamura | 08b987e | 2017-06-13 08:45:40 | [diff] [blame] | 426 | strings->push_back(prefixCopy + customItems[i].label.Utf8()); |
[email protected] | f9634a8 | 2014-08-05 13:10:19 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 431 | // Because actual context menu is implemented by the browser side, |
| 432 | // this function does only what LayoutTests are expecting: |
| 433 | // - Many test checks the count of items. So returning non-zero value makes |
| 434 | // sense. |
| 435 | // - Some test compares the count before and after some action. So changing the |
| 436 | // count based on flags also makes sense. This function is doing such for some |
| 437 | // flags. |
| 438 | // - Some test even checks actual string content. So providing it would be also |
| 439 | // helpful. |
| 440 | std::vector<std::string> MakeMenuItemStringsFor( |
| 441 | WebContextMenuData* context_menu, |
[email protected] | 79ecada | 2014-05-04 05:16:16 | [diff] [blame] | 442 | WebTestDelegate* delegate) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 443 | // These constants are based on Safari's context menu because tests are made |
| 444 | // for it. |
| 445 | static const char* kNonEditableMenuStrings[] = { |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 446 | "Back", "Reload Page", "Open in Dashbaord", |
| 447 | "<separator>", "View Source", "Save Page As", |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 448 | "Print Page", "Inspect Element", nullptr}; |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 449 | static const char* kEditableMenuStrings[] = {"Cut", |
| 450 | "Copy", |
| 451 | "<separator>", |
| 452 | "Paste", |
| 453 | "Spelling and Grammar", |
| 454 | "Substitutions, Transformations", |
| 455 | "Font", |
| 456 | "Speech", |
| 457 | "Paragraph Direction", |
| 458 | "<separator>", |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 459 | nullptr}; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 460 | |
| 461 | // This is possible because mouse events are cancelleable. |
| 462 | if (!context_menu) |
| 463 | return std::vector<std::string>(); |
| 464 | |
| 465 | std::vector<std::string> strings; |
| 466 | |
[email protected] | f9634a8 | 2014-08-05 13:10:19 | [diff] [blame] | 467 | // Populate custom menu items if provided by blink. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 468 | PopulateCustomItems(context_menu->custom_items, "", &strings); |
[email protected] | f9634a8 | 2014-08-05 13:10:19 | [diff] [blame] | 469 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 470 | if (context_menu->is_editable) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 471 | for (const char** item = kEditableMenuStrings; *item; ++item) { |
| 472 | strings.push_back(*item); |
| 473 | } |
| 474 | WebVector<WebString> suggestions; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 475 | MockSpellCheck::FillSuggestionList(context_menu->misspelled_word, |
[email protected] | f656a65 | 2014-07-25 12:19:52 | [diff] [blame] | 476 | &suggestions); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 477 | for (size_t i = 0; i < suggestions.size(); ++i) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 478 | strings.push_back(suggestions[i].Utf8()); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 479 | } |
| 480 | } else { |
| 481 | for (const char** item = kNonEditableMenuStrings; *item; ++item) { |
| 482 | strings.push_back(*item); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | return strings; |
| 487 | } |
| 488 | |
| 489 | // How much we should scroll per event - the value here is chosen to match the |
| 490 | // WebKit impl and layout test results. |
| 491 | const float kScrollbarPixelsPerTick = 40.0f; |
| 492 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 493 | // Get the edit command corresponding to a keyboard event. |
| 494 | // Returns true if the specified event corresponds to an edit command, the name |
| 495 | // of the edit command will be stored in |*name|. |
| 496 | bool GetEditCommand(const WebKeyboardEvent& event, std::string* name) { |
| 497 | #if defined(OS_MACOSX) |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 498 | // We only cares about Left,Right,Up,Down keys with Command or Command+Shift |
| 499 | // modifiers. These key events correspond to some special movement and |
| 500 | // selection editor commands. These keys will be marked as system key, which |
| 501 | // prevents them from being handled. Thus they must be handled specially. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 502 | if ((event.GetModifiers() & ~WebKeyboardEvent::kShiftKey) != |
| 503 | WebKeyboardEvent::kMetaKey) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 504 | return false; |
| 505 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 506 | switch (event.windows_key_code) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 507 | case ui::VKEY_LEFT: |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 508 | *name = "MoveToBeginningOfLine"; |
| 509 | break; |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 510 | case ui::VKEY_RIGHT: |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 511 | *name = "MoveToEndOfLine"; |
| 512 | break; |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 513 | case ui::VKEY_UP: |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 514 | *name = "MoveToBeginningOfDocument"; |
| 515 | break; |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 516 | case ui::VKEY_DOWN: |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 517 | *name = "MoveToEndOfDocument"; |
| 518 | break; |
| 519 | default: |
| 520 | return false; |
| 521 | } |
| 522 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 523 | if (event.GetModifiers() & WebKeyboardEvent::kShiftKey) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 524 | name->append("AndModifySelection"); |
| 525 | |
| 526 | return true; |
| 527 | #else |
| 528 | return false; |
| 529 | #endif |
| 530 | } |
| 531 | |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 532 | bool IsSystemKeyEvent(const WebKeyboardEvent& event) { |
| 533 | #if defined(OS_MACOSX) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 534 | return event.GetModifiers() & WebInputEvent::kMetaKey && |
| 535 | event.windows_key_code != ui::VKEY_B && |
| 536 | event.windows_key_code != ui::VKEY_I; |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 537 | #else |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 538 | return !!(event.GetModifiers() & WebInputEvent::kAltKey); |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 539 | #endif |
| 540 | } |
| 541 | |
dtapuska | b1c5ece | 2016-01-18 18:18:02 | [diff] [blame] | 542 | bool GetScrollUnits(gin::Arguments* args, WebGestureEvent::ScrollUnits* units) { |
| 543 | std::string units_string; |
| 544 | if (!args->PeekNext().IsEmpty()) { |
| 545 | if (args->PeekNext()->IsString()) |
| 546 | args->GetNext(&units_string); |
| 547 | if (units_string == "Page") { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 548 | *units = WebGestureEvent::kPage; |
dtapuska | b1c5ece | 2016-01-18 18:18:02 | [diff] [blame] | 549 | return true; |
| 550 | } else if (units_string == "Pixels") { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 551 | *units = WebGestureEvent::kPixels; |
dtapuska | b1c5ece | 2016-01-18 18:18:02 | [diff] [blame] | 552 | return true; |
| 553 | } else if (units_string == "PrecisePixels") { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 554 | *units = WebGestureEvent::kPrecisePixels; |
dtapuska | b1c5ece | 2016-01-18 18:18:02 | [diff] [blame] | 555 | return true; |
| 556 | } else { |
| 557 | args->ThrowError(); |
| 558 | return false; |
| 559 | } |
| 560 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 561 | *units = WebGestureEvent::kPrecisePixels; |
dtapuska | b1c5ece | 2016-01-18 18:18:02 | [diff] [blame] | 562 | return true; |
| 563 | } |
| 564 | } |
| 565 | |
tdresser | 3a1c972 | 2015-02-13 15:44:53 | [diff] [blame] | 566 | const char* kSourceDeviceStringTouchpad = "touchpad"; |
| 567 | const char* kSourceDeviceStringTouchscreen = "touchscreen"; |
| 568 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 569 | } // namespace |
| 570 | |
| 571 | class EventSenderBindings : public gin::Wrappable<EventSenderBindings> { |
| 572 | public: |
| 573 | static gin::WrapperInfo kWrapperInfo; |
| 574 | |
| 575 | static void Install(base::WeakPtr<EventSender> sender, |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 576 | blink::WebLocalFrame* frame); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 577 | |
| 578 | private: |
| 579 | explicit EventSenderBindings(base::WeakPtr<EventSender> sender); |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 580 | ~EventSenderBindings() override; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 581 | |
| 582 | // gin::Wrappable: |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 583 | gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
anand.ratn | 449f39a4 | 2014-10-06 13:45:57 | [diff] [blame] | 584 | v8::Isolate* isolate) override; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 585 | |
| 586 | // Bound methods: |
| 587 | void EnableDOMUIEventLogging(); |
| 588 | void FireKeyboardEventsToElement(); |
| 589 | void ClearKillRing(); |
| 590 | std::vector<std::string> ContextClick(); |
| 591 | void TextZoomIn(); |
| 592 | void TextZoomOut(); |
| 593 | void ZoomPageIn(); |
| 594 | void ZoomPageOut(); |
[email protected] | d160488f | 2014-05-06 17:03:01 | [diff] [blame] | 595 | void SetPageZoomFactor(double factor); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 596 | void ClearTouchPoints(); |
| 597 | void ReleaseTouchPoint(unsigned index); |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 598 | void UpdateTouchPoint(unsigned index, |
| 599 | double x, |
| 600 | double y, |
| 601 | gin::Arguments* args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 602 | void CancelTouchPoint(unsigned index); |
| 603 | void SetTouchModifier(const std::string& key_name, bool set_mask); |
[email protected] | ace1cd50 | 2014-04-24 21:05:30 | [diff] [blame] | 604 | void SetTouchCancelable(bool cancelable); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 605 | void DumpFilenameBeingDragged(); |
| 606 | void GestureFlingCancel(); |
tdresser | 3a1c972 | 2015-02-13 15:44:53 | [diff] [blame] | 607 | void GestureFlingStart(float x, |
| 608 | float y, |
| 609 | float velocity_x, |
| 610 | float velocity_y, |
| 611 | gin::Arguments* args); |
W. James MacLean | b5846e5 | 2017-08-31 20:39:50 | [diff] [blame] | 612 | bool IsFlinging(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 613 | void GestureScrollFirstPoint(int x, int y); |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 614 | void TouchStart(gin::Arguments* args); |
| 615 | void TouchMove(gin::Arguments* args); |
| 616 | void TouchCancel(gin::Arguments* args); |
| 617 | void TouchEnd(gin::Arguments* args); |
mustaq | b3c44a0 | 2016-04-19 18:49:05 | [diff] [blame] | 618 | void NotifyStartOfTouchScroll(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 619 | void LeapForward(int milliseconds); |
majidvp | bfabb071 | 2015-10-02 16:30:00 | [diff] [blame] | 620 | double LastEventTimestamp(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 621 | void BeginDragWithFiles(const std::vector<std::string>& files); |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 622 | void AddTouchPoint(double x, double y, gin::Arguments* args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 623 | void GestureScrollBegin(gin::Arguments* args); |
| 624 | void GestureScrollEnd(gin::Arguments* args); |
| 625 | void GestureScrollUpdate(gin::Arguments* args); |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 626 | void GesturePinchBegin(gin::Arguments* args); |
| 627 | void GesturePinchEnd(gin::Arguments* args); |
| 628 | void GesturePinchUpdate(gin::Arguments* args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 629 | void GestureTap(gin::Arguments* args); |
| 630 | void GestureTapDown(gin::Arguments* args); |
| 631 | void GestureShowPress(gin::Arguments* args); |
| 632 | void GestureTapCancel(gin::Arguments* args); |
| 633 | void GestureLongPress(gin::Arguments* args); |
| 634 | void GestureLongTap(gin::Arguments* args); |
| 635 | void GestureTwoFingerTap(gin::Arguments* args); |
| 636 | void ContinuousMouseScrollBy(gin::Arguments* args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 637 | void MouseMoveTo(gin::Arguments* args); |
lanwei | 0474c2a5 | 2017-05-12 18:52:01 | [diff] [blame] | 638 | void MouseLeave(gin::Arguments* args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 639 | void MouseScrollBy(gin::Arguments* args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 640 | void ScheduleAsynchronousClick(gin::Arguments* args); |
| 641 | void ScheduleAsynchronousKeyDown(gin::Arguments* args); |
Mustaq Ahmed | c9b974a | 2018-01-22 19:43:44 | [diff] [blame] | 642 | void ConsumeUserActivation(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 643 | void MouseDown(gin::Arguments* args); |
| 644 | void MouseUp(gin::Arguments* args); |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 645 | void SetMouseButtonState(gin::Arguments* args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 646 | void KeyDown(gin::Arguments* args); |
| 647 | |
| 648 | // Binding properties: |
| 649 | bool ForceLayoutOnEvents() const; |
| 650 | void SetForceLayoutOnEvents(bool force); |
| 651 | bool IsDragMode() const; |
| 652 | void SetIsDragMode(bool drag_mode); |
| 653 | |
| 654 | #if defined(OS_WIN) |
| 655 | int WmKeyDown() const; |
| 656 | void SetWmKeyDown(int key_down); |
| 657 | |
| 658 | int WmKeyUp() const; |
| 659 | void SetWmKeyUp(int key_up); |
| 660 | |
| 661 | int WmChar() const; |
| 662 | void SetWmChar(int wm_char); |
| 663 | |
| 664 | int WmDeadChar() const; |
| 665 | void SetWmDeadChar(int dead_char); |
| 666 | |
| 667 | int WmSysKeyDown() const; |
| 668 | void SetWmSysKeyDown(int key_down); |
| 669 | |
| 670 | int WmSysKeyUp() const; |
| 671 | void SetWmSysKeyUp(int key_up); |
| 672 | |
| 673 | int WmSysChar() const; |
| 674 | void SetWmSysChar(int sys_char); |
| 675 | |
| 676 | int WmSysDeadChar() const; |
| 677 | void SetWmSysDeadChar(int sys_dead_char); |
| 678 | #endif |
| 679 | |
| 680 | base::WeakPtr<EventSender> sender_; |
| 681 | |
| 682 | DISALLOW_COPY_AND_ASSIGN(EventSenderBindings); |
| 683 | }; |
| 684 | |
| 685 | gin::WrapperInfo EventSenderBindings::kWrapperInfo = {gin::kEmbedderNativeGin}; |
| 686 | |
| 687 | EventSenderBindings::EventSenderBindings(base::WeakPtr<EventSender> sender) |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 688 | : sender_(sender) {} |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 689 | |
| 690 | EventSenderBindings::~EventSenderBindings() {} |
| 691 | |
| 692 | // static |
| 693 | void EventSenderBindings::Install(base::WeakPtr<EventSender> sender, |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 694 | WebLocalFrame* frame) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 695 | v8::Isolate* isolate = blink::MainThreadIsolate(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 696 | v8::HandleScope handle_scope(isolate); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 697 | v8::Local<v8::Context> context = frame->MainWorldScriptContext(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 698 | if (context.IsEmpty()) |
| 699 | return; |
| 700 | |
| 701 | v8::Context::Scope context_scope(context); |
| 702 | |
| 703 | gin::Handle<EventSenderBindings> bindings = |
| 704 | gin::CreateHandle(isolate, new EventSenderBindings(sender)); |
[email protected] | ad4d203 | 2014-04-28 13:50:59 | [diff] [blame] | 705 | if (bindings.IsEmpty()) |
| 706 | return; |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 707 | v8::Local<v8::Object> global = context->Global(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 708 | global->Set(gin::StringToV8(isolate, "eventSender"), bindings.ToV8()); |
| 709 | } |
| 710 | |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 711 | gin::ObjectTemplateBuilder EventSenderBindings::GetObjectTemplateBuilder( |
| 712 | v8::Isolate* isolate) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 713 | return gin::Wrappable<EventSenderBindings>::GetObjectTemplateBuilder(isolate) |
| 714 | .SetMethod("enableDOMUIEventLogging", |
| 715 | &EventSenderBindings::EnableDOMUIEventLogging) |
| 716 | .SetMethod("fireKeyboardEventsToElement", |
| 717 | &EventSenderBindings::FireKeyboardEventsToElement) |
| 718 | .SetMethod("clearKillRing", &EventSenderBindings::ClearKillRing) |
| 719 | .SetMethod("contextClick", &EventSenderBindings::ContextClick) |
| 720 | .SetMethod("textZoomIn", &EventSenderBindings::TextZoomIn) |
| 721 | .SetMethod("textZoomOut", &EventSenderBindings::TextZoomOut) |
| 722 | .SetMethod("zoomPageIn", &EventSenderBindings::ZoomPageIn) |
| 723 | .SetMethod("zoomPageOut", &EventSenderBindings::ZoomPageOut) |
[email protected] | b32fe54 | 2014-04-30 08:42:06 | [diff] [blame] | 724 | .SetMethod("setPageZoomFactor", &EventSenderBindings::SetPageZoomFactor) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 725 | .SetMethod("clearTouchPoints", &EventSenderBindings::ClearTouchPoints) |
| 726 | .SetMethod("releaseTouchPoint", &EventSenderBindings::ReleaseTouchPoint) |
| 727 | .SetMethod("updateTouchPoint", &EventSenderBindings::UpdateTouchPoint) |
| 728 | .SetMethod("cancelTouchPoint", &EventSenderBindings::CancelTouchPoint) |
| 729 | .SetMethod("setTouchModifier", &EventSenderBindings::SetTouchModifier) |
[email protected] | ace1cd50 | 2014-04-24 21:05:30 | [diff] [blame] | 730 | .SetMethod("setTouchCancelable", &EventSenderBindings::SetTouchCancelable) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 731 | .SetMethod("dumpFilenameBeingDragged", |
| 732 | &EventSenderBindings::DumpFilenameBeingDragged) |
| 733 | .SetMethod("gestureFlingCancel", &EventSenderBindings::GestureFlingCancel) |
| 734 | .SetMethod("gestureFlingStart", &EventSenderBindings::GestureFlingStart) |
tdresser | d7bba52 | 2016-02-19 22:40:13 | [diff] [blame] | 735 | .SetMethod("isFlinging", &EventSenderBindings::IsFlinging) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 736 | .SetMethod("gestureScrollFirstPoint", |
| 737 | &EventSenderBindings::GestureScrollFirstPoint) |
| 738 | .SetMethod("touchStart", &EventSenderBindings::TouchStart) |
| 739 | .SetMethod("touchMove", &EventSenderBindings::TouchMove) |
| 740 | .SetMethod("touchCancel", &EventSenderBindings::TouchCancel) |
| 741 | .SetMethod("touchEnd", &EventSenderBindings::TouchEnd) |
mustaq | b3c44a0 | 2016-04-19 18:49:05 | [diff] [blame] | 742 | .SetMethod("notifyStartOfTouchScroll", |
| 743 | &EventSenderBindings::NotifyStartOfTouchScroll) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 744 | .SetMethod("leapForward", &EventSenderBindings::LeapForward) |
majidvp | bfabb071 | 2015-10-02 16:30:00 | [diff] [blame] | 745 | .SetMethod("lastEventTimestamp", &EventSenderBindings::LastEventTimestamp) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 746 | .SetMethod("beginDragWithFiles", &EventSenderBindings::BeginDragWithFiles) |
| 747 | .SetMethod("addTouchPoint", &EventSenderBindings::AddTouchPoint) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 748 | .SetMethod("gestureScrollBegin", &EventSenderBindings::GestureScrollBegin) |
| 749 | .SetMethod("gestureScrollEnd", &EventSenderBindings::GestureScrollEnd) |
| 750 | .SetMethod("gestureScrollUpdate", |
| 751 | &EventSenderBindings::GestureScrollUpdate) |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 752 | .SetMethod("gesturePinchBegin", &EventSenderBindings::GesturePinchBegin) |
| 753 | .SetMethod("gesturePinchEnd", &EventSenderBindings::GesturePinchEnd) |
| 754 | .SetMethod("gesturePinchUpdate", &EventSenderBindings::GesturePinchUpdate) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 755 | .SetMethod("gestureTap", &EventSenderBindings::GestureTap) |
| 756 | .SetMethod("gestureTapDown", &EventSenderBindings::GestureTapDown) |
| 757 | .SetMethod("gestureShowPress", &EventSenderBindings::GestureShowPress) |
| 758 | .SetMethod("gestureTapCancel", &EventSenderBindings::GestureTapCancel) |
| 759 | .SetMethod("gestureLongPress", &EventSenderBindings::GestureLongPress) |
| 760 | .SetMethod("gestureLongTap", &EventSenderBindings::GestureLongTap) |
| 761 | .SetMethod("gestureTwoFingerTap", |
| 762 | &EventSenderBindings::GestureTwoFingerTap) |
| 763 | .SetMethod("continuousMouseScrollBy", |
| 764 | &EventSenderBindings::ContinuousMouseScrollBy) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 765 | .SetMethod("keyDown", &EventSenderBindings::KeyDown) |
| 766 | .SetMethod("mouseDown", &EventSenderBindings::MouseDown) |
| 767 | .SetMethod("mouseMoveTo", &EventSenderBindings::MouseMoveTo) |
myid.shin | 12c7fea2 | 2015-03-06 02:31:24 | [diff] [blame] | 768 | .SetMethod("mouseLeave", &EventSenderBindings::MouseLeave) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 769 | .SetMethod("mouseScrollBy", &EventSenderBindings::MouseScrollBy) |
| 770 | .SetMethod("mouseUp", &EventSenderBindings::MouseUp) |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 771 | .SetMethod("setMouseButtonState", |
| 772 | &EventSenderBindings::SetMouseButtonState) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 773 | .SetMethod("scheduleAsynchronousClick", |
| 774 | &EventSenderBindings::ScheduleAsynchronousClick) |
| 775 | .SetMethod("scheduleAsynchronousKeyDown", |
| 776 | &EventSenderBindings::ScheduleAsynchronousKeyDown) |
Mustaq Ahmed | c9b974a | 2018-01-22 19:43:44 | [diff] [blame] | 777 | .SetMethod("consumeUserActivation", |
| 778 | &EventSenderBindings::ConsumeUserActivation) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 779 | .SetProperty("forceLayoutOnEvents", |
| 780 | &EventSenderBindings::ForceLayoutOnEvents, |
| 781 | &EventSenderBindings::SetForceLayoutOnEvents) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 782 | #if defined(OS_WIN) |
mustaq | 96985f72 | 2015-06-30 21:41:53 | [diff] [blame] | 783 | .SetProperty("WM_KEYDOWN", &EventSenderBindings::WmKeyDown, |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 784 | &EventSenderBindings::SetWmKeyDown) |
mustaq | 96985f72 | 2015-06-30 21:41:53 | [diff] [blame] | 785 | .SetProperty("WM_KEYUP", &EventSenderBindings::WmKeyUp, |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 786 | &EventSenderBindings::SetWmKeyUp) |
mustaq | 96985f72 | 2015-06-30 21:41:53 | [diff] [blame] | 787 | .SetProperty("WM_CHAR", &EventSenderBindings::WmChar, |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 788 | &EventSenderBindings::SetWmChar) |
mustaq | 96985f72 | 2015-06-30 21:41:53 | [diff] [blame] | 789 | .SetProperty("WM_DEADCHAR", &EventSenderBindings::WmDeadChar, |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 790 | &EventSenderBindings::SetWmDeadChar) |
mustaq | 96985f72 | 2015-06-30 21:41:53 | [diff] [blame] | 791 | .SetProperty("WM_SYSKEYDOWN", &EventSenderBindings::WmSysKeyDown, |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 792 | &EventSenderBindings::SetWmSysKeyDown) |
mustaq | 96985f72 | 2015-06-30 21:41:53 | [diff] [blame] | 793 | .SetProperty("WM_SYSKEYUP", &EventSenderBindings::WmSysKeyUp, |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 794 | &EventSenderBindings::SetWmSysKeyUp) |
mustaq | 96985f72 | 2015-06-30 21:41:53 | [diff] [blame] | 795 | .SetProperty("WM_SYSCHAR", &EventSenderBindings::WmSysChar, |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 796 | &EventSenderBindings::SetWmSysChar) |
mustaq | 96985f72 | 2015-06-30 21:41:53 | [diff] [blame] | 797 | .SetProperty("WM_SYSDEADCHAR", &EventSenderBindings::WmSysDeadChar, |
thestig | fd11ffe | 2015-12-30 19:25:45 | [diff] [blame] | 798 | &EventSenderBindings::SetWmSysDeadChar) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 799 | #endif |
thestig | fd11ffe | 2015-12-30 19:25:45 | [diff] [blame] | 800 | .SetProperty("dragMode", &EventSenderBindings::IsDragMode, |
| 801 | &EventSenderBindings::SetIsDragMode); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | void EventSenderBindings::EnableDOMUIEventLogging() { |
| 805 | if (sender_) |
| 806 | sender_->EnableDOMUIEventLogging(); |
| 807 | } |
| 808 | |
| 809 | void EventSenderBindings::FireKeyboardEventsToElement() { |
| 810 | if (sender_) |
| 811 | sender_->FireKeyboardEventsToElement(); |
| 812 | } |
| 813 | |
| 814 | void EventSenderBindings::ClearKillRing() { |
| 815 | if (sender_) |
| 816 | sender_->ClearKillRing(); |
| 817 | } |
| 818 | |
| 819 | std::vector<std::string> EventSenderBindings::ContextClick() { |
| 820 | if (sender_) |
| 821 | return sender_->ContextClick(); |
| 822 | return std::vector<std::string>(); |
| 823 | } |
| 824 | |
| 825 | void EventSenderBindings::TextZoomIn() { |
| 826 | if (sender_) |
| 827 | sender_->TextZoomIn(); |
| 828 | } |
| 829 | |
| 830 | void EventSenderBindings::TextZoomOut() { |
| 831 | if (sender_) |
| 832 | sender_->TextZoomOut(); |
| 833 | } |
| 834 | |
| 835 | void EventSenderBindings::ZoomPageIn() { |
| 836 | if (sender_) |
| 837 | sender_->ZoomPageIn(); |
| 838 | } |
| 839 | |
| 840 | void EventSenderBindings::ZoomPageOut() { |
| 841 | if (sender_) |
| 842 | sender_->ZoomPageOut(); |
| 843 | } |
| 844 | |
[email protected] | d160488f | 2014-05-06 17:03:01 | [diff] [blame] | 845 | void EventSenderBindings::SetPageZoomFactor(double factor) { |
| 846 | if (sender_) |
| 847 | sender_->SetPageZoomFactor(factor); |
[email protected] | b32fe54 | 2014-04-30 08:42:06 | [diff] [blame] | 848 | } |
| 849 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 850 | void EventSenderBindings::ClearTouchPoints() { |
| 851 | if (sender_) |
| 852 | sender_->ClearTouchPoints(); |
| 853 | } |
| 854 | |
| 855 | void EventSenderBindings::ReleaseTouchPoint(unsigned index) { |
| 856 | if (sender_) |
| 857 | sender_->ReleaseTouchPoint(index); |
| 858 | } |
| 859 | |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 860 | void EventSenderBindings::UpdateTouchPoint(unsigned index, |
| 861 | double x, |
| 862 | double y, |
| 863 | gin::Arguments* args) { |
jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 864 | if (sender_) { |
| 865 | sender_->UpdateTouchPoint(index, static_cast<float>(x), |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 866 | static_cast<float>(y), args); |
jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 867 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | void EventSenderBindings::CancelTouchPoint(unsigned index) { |
| 871 | if (sender_) |
| 872 | sender_->CancelTouchPoint(index); |
| 873 | } |
| 874 | |
| 875 | void EventSenderBindings::SetTouchModifier(const std::string& key_name, |
| 876 | bool set_mask) { |
| 877 | if (sender_) |
| 878 | sender_->SetTouchModifier(key_name, set_mask); |
| 879 | } |
| 880 | |
[email protected] | ace1cd50 | 2014-04-24 21:05:30 | [diff] [blame] | 881 | void EventSenderBindings::SetTouchCancelable(bool cancelable) { |
| 882 | if (sender_) |
| 883 | sender_->SetTouchCancelable(cancelable); |
| 884 | } |
| 885 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 886 | void EventSenderBindings::DumpFilenameBeingDragged() { |
| 887 | if (sender_) |
| 888 | sender_->DumpFilenameBeingDragged(); |
| 889 | } |
| 890 | |
| 891 | void EventSenderBindings::GestureFlingCancel() { |
| 892 | if (sender_) |
| 893 | sender_->GestureFlingCancel(); |
| 894 | } |
| 895 | |
| 896 | void EventSenderBindings::GestureFlingStart(float x, |
| 897 | float y, |
| 898 | float velocity_x, |
tdresser | 3a1c972 | 2015-02-13 15:44:53 | [diff] [blame] | 899 | float velocity_y, |
| 900 | gin::Arguments* args) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 901 | if (sender_) |
tdresser | 3a1c972 | 2015-02-13 15:44:53 | [diff] [blame] | 902 | sender_->GestureFlingStart(x, y, velocity_x, velocity_y, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 903 | } |
| 904 | |
W. James MacLean | b5846e5 | 2017-08-31 20:39:50 | [diff] [blame] | 905 | bool EventSenderBindings::IsFlinging() { |
tdresser | d7bba52 | 2016-02-19 22:40:13 | [diff] [blame] | 906 | if (sender_) |
| 907 | return sender_->IsFlinging(); |
| 908 | return false; |
| 909 | } |
| 910 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 911 | void EventSenderBindings::GestureScrollFirstPoint(int x, int y) { |
| 912 | if (sender_) |
| 913 | sender_->GestureScrollFirstPoint(x, y); |
| 914 | } |
| 915 | |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 916 | void EventSenderBindings::TouchStart(gin::Arguments* args) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 917 | if (sender_) |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 918 | sender_->TouchStart(args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 919 | } |
| 920 | |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 921 | void EventSenderBindings::TouchMove(gin::Arguments* args) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 922 | if (sender_) |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 923 | sender_->TouchMove(args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 924 | } |
| 925 | |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 926 | void EventSenderBindings::TouchCancel(gin::Arguments* args) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 927 | if (sender_) |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 928 | sender_->TouchCancel(args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 929 | } |
| 930 | |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 931 | void EventSenderBindings::TouchEnd(gin::Arguments* args) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 932 | if (sender_) |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 933 | sender_->TouchEnd(args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 934 | } |
| 935 | |
mustaq | b3c44a0 | 2016-04-19 18:49:05 | [diff] [blame] | 936 | void EventSenderBindings::NotifyStartOfTouchScroll() { |
| 937 | if (sender_) |
| 938 | sender_->NotifyStartOfTouchScroll(); |
| 939 | } |
| 940 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 941 | void EventSenderBindings::LeapForward(int milliseconds) { |
| 942 | if (sender_) |
| 943 | sender_->LeapForward(milliseconds); |
| 944 | } |
| 945 | |
majidvp | bfabb071 | 2015-10-02 16:30:00 | [diff] [blame] | 946 | double EventSenderBindings::LastEventTimestamp() { |
| 947 | if (sender_) |
| 948 | return sender_->last_event_timestamp(); |
| 949 | return 0; |
| 950 | } |
| 951 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 952 | void EventSenderBindings::BeginDragWithFiles( |
| 953 | const std::vector<std::string>& files) { |
| 954 | if (sender_) |
| 955 | sender_->BeginDragWithFiles(files); |
| 956 | } |
| 957 | |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 958 | void EventSenderBindings::AddTouchPoint(double x, |
| 959 | double y, |
| 960 | gin::Arguments* args) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 961 | if (sender_) |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 962 | sender_->AddTouchPoint(static_cast<float>(x), static_cast<float>(y), args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 963 | } |
| 964 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 965 | void EventSenderBindings::GestureScrollBegin(gin::Arguments* args) { |
| 966 | if (sender_) |
| 967 | sender_->GestureScrollBegin(args); |
| 968 | } |
| 969 | |
| 970 | void EventSenderBindings::GestureScrollEnd(gin::Arguments* args) { |
| 971 | if (sender_) |
| 972 | sender_->GestureScrollEnd(args); |
| 973 | } |
| 974 | |
| 975 | void EventSenderBindings::GestureScrollUpdate(gin::Arguments* args) { |
| 976 | if (sender_) |
| 977 | sender_->GestureScrollUpdate(args); |
| 978 | } |
| 979 | |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 980 | void EventSenderBindings::GesturePinchBegin(gin::Arguments* args) { |
| 981 | if (sender_) |
| 982 | sender_->GesturePinchBegin(args); |
| 983 | } |
| 984 | |
| 985 | void EventSenderBindings::GesturePinchEnd(gin::Arguments* args) { |
| 986 | if (sender_) |
| 987 | sender_->GesturePinchEnd(args); |
| 988 | } |
| 989 | |
| 990 | void EventSenderBindings::GesturePinchUpdate(gin::Arguments* args) { |
| 991 | if (sender_) |
| 992 | sender_->GesturePinchUpdate(args); |
| 993 | } |
| 994 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 995 | void EventSenderBindings::GestureTap(gin::Arguments* args) { |
| 996 | if (sender_) |
| 997 | sender_->GestureTap(args); |
| 998 | } |
| 999 | |
| 1000 | void EventSenderBindings::GestureTapDown(gin::Arguments* args) { |
| 1001 | if (sender_) |
| 1002 | sender_->GestureTapDown(args); |
| 1003 | } |
| 1004 | |
| 1005 | void EventSenderBindings::GestureShowPress(gin::Arguments* args) { |
| 1006 | if (sender_) |
| 1007 | sender_->GestureShowPress(args); |
| 1008 | } |
| 1009 | |
| 1010 | void EventSenderBindings::GestureTapCancel(gin::Arguments* args) { |
| 1011 | if (sender_) |
| 1012 | sender_->GestureTapCancel(args); |
| 1013 | } |
| 1014 | |
| 1015 | void EventSenderBindings::GestureLongPress(gin::Arguments* args) { |
| 1016 | if (sender_) |
| 1017 | sender_->GestureLongPress(args); |
| 1018 | } |
| 1019 | |
| 1020 | void EventSenderBindings::GestureLongTap(gin::Arguments* args) { |
| 1021 | if (sender_) |
| 1022 | sender_->GestureLongTap(args); |
| 1023 | } |
| 1024 | |
| 1025 | void EventSenderBindings::GestureTwoFingerTap(gin::Arguments* args) { |
| 1026 | if (sender_) |
| 1027 | sender_->GestureTwoFingerTap(args); |
| 1028 | } |
| 1029 | |
| 1030 | void EventSenderBindings::ContinuousMouseScrollBy(gin::Arguments* args) { |
| 1031 | if (sender_) |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 1032 | sender_->MouseScrollBy(args, EventSender::MouseScrollType::PIXEL); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1033 | } |
| 1034 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1035 | void EventSenderBindings::MouseMoveTo(gin::Arguments* args) { |
| 1036 | if (sender_) |
| 1037 | sender_->MouseMoveTo(args); |
| 1038 | } |
| 1039 | |
lanwei | 0474c2a5 | 2017-05-12 18:52:01 | [diff] [blame] | 1040 | void EventSenderBindings::MouseLeave(gin::Arguments* args) { |
| 1041 | if (!sender_) |
| 1042 | return; |
| 1043 | |
| 1044 | WebPointerProperties::PointerType pointerType = |
| 1045 | WebPointerProperties::PointerType::kMouse; |
| 1046 | int pointerId = kRawMousePointerId; |
| 1047 | |
| 1048 | // Only allow pen or mouse through this API. |
chongz | d65eacf | 2017-06-28 05:21:59 | [diff] [blame] | 1049 | if (!GetPointerType(args, false, pointerType)) |
lanwei | 0474c2a5 | 2017-05-12 18:52:01 | [diff] [blame] | 1050 | return; |
| 1051 | if (!args->PeekNext().IsEmpty()) { |
| 1052 | if (!args->GetNext(&pointerId)) { |
| 1053 | args->ThrowError(); |
| 1054 | return; |
| 1055 | } |
| 1056 | } |
| 1057 | sender_->MouseLeave(pointerType, pointerId); |
myid.shin | 12c7fea2 | 2015-03-06 02:31:24 | [diff] [blame] | 1058 | } |
| 1059 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1060 | void EventSenderBindings::MouseScrollBy(gin::Arguments* args) { |
| 1061 | if (sender_) |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 1062 | sender_->MouseScrollBy(args, EventSender::MouseScrollType::TICK); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1063 | } |
| 1064 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1065 | void EventSenderBindings::ScheduleAsynchronousClick(gin::Arguments* args) { |
| 1066 | if (!sender_) |
| 1067 | return; |
| 1068 | |
| 1069 | int button_number = 0; |
| 1070 | int modifiers = 0; |
| 1071 | if (!args->PeekNext().IsEmpty()) { |
| 1072 | args->GetNext(&button_number); |
| 1073 | if (!args->PeekNext().IsEmpty()) |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 1074 | modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1075 | } |
| 1076 | sender_->ScheduleAsynchronousClick(button_number, modifiers); |
| 1077 | } |
| 1078 | |
| 1079 | void EventSenderBindings::ScheduleAsynchronousKeyDown(gin::Arguments* args) { |
| 1080 | if (!sender_) |
| 1081 | return; |
| 1082 | |
| 1083 | std::string code_str; |
| 1084 | int modifiers = 0; |
| 1085 | int location = DOMKeyLocationStandard; |
| 1086 | args->GetNext(&code_str); |
| 1087 | if (!args->PeekNext().IsEmpty()) { |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 1088 | v8::Local<v8::Value> value; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1089 | args->GetNext(&value); |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 1090 | modifiers = GetKeyModifiersFromV8(args->isolate(), value); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1091 | if (!args->PeekNext().IsEmpty()) |
| 1092 | args->GetNext(&location); |
| 1093 | } |
| 1094 | sender_->ScheduleAsynchronousKeyDown(code_str, modifiers, |
| 1095 | static_cast<KeyLocationCode>(location)); |
| 1096 | } |
| 1097 | |
Mustaq Ahmed | c9b974a | 2018-01-22 19:43:44 | [diff] [blame] | 1098 | void EventSenderBindings::ConsumeUserActivation() { |
| 1099 | if (sender_) |
| 1100 | sender_->ConsumeUserActivation(); |
| 1101 | } |
| 1102 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1103 | void EventSenderBindings::MouseDown(gin::Arguments* args) { |
| 1104 | if (!sender_) |
| 1105 | return; |
| 1106 | |
| 1107 | int button_number = 0; |
| 1108 | int modifiers = 0; |
| 1109 | if (!args->PeekNext().IsEmpty()) { |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1110 | if (!args->GetNext(&button_number)) { |
| 1111 | args->ThrowError(); |
| 1112 | return; |
| 1113 | } |
| 1114 | if (!args->PeekNext().IsEmpty()) { |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 1115 | modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1116 | args->Skip(); |
| 1117 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1118 | } |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1119 | |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1120 | WebPointerProperties::PointerType pointerType = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1121 | WebPointerProperties::PointerType::kMouse; |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1122 | int pointerId = 0; |
| 1123 | float pressure = 0; |
| 1124 | int tiltX = 0; |
| 1125 | int tiltY = 0; |
| 1126 | if (!getMousePenPointerProperties(args, pointerType, pointerId, pressure, |
| 1127 | tiltX, tiltY)) |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1128 | return; |
| 1129 | |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1130 | sender_->PointerDown(button_number, modifiers, pointerType, pointerId, |
| 1131 | pressure, tiltX, tiltY); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | void EventSenderBindings::MouseUp(gin::Arguments* args) { |
| 1135 | if (!sender_) |
| 1136 | return; |
| 1137 | |
| 1138 | int button_number = 0; |
| 1139 | int modifiers = 0; |
| 1140 | if (!args->PeekNext().IsEmpty()) { |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1141 | if (!args->GetNext(&button_number)) { |
| 1142 | args->ThrowError(); |
| 1143 | return; |
| 1144 | } |
| 1145 | if (!args->PeekNext().IsEmpty()) { |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 1146 | modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1147 | args->Skip(); |
| 1148 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1149 | } |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1150 | |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1151 | WebPointerProperties::PointerType pointerType = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1152 | WebPointerProperties::PointerType::kMouse; |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1153 | int pointerId = 0; |
| 1154 | float pressure = 0; |
| 1155 | int tiltX = 0; |
| 1156 | int tiltY = 0; |
| 1157 | if (!getMousePenPointerProperties(args, pointerType, pointerId, pressure, |
| 1158 | tiltX, tiltY)) |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1159 | return; |
| 1160 | |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1161 | sender_->PointerUp(button_number, modifiers, pointerType, pointerId, pressure, |
| 1162 | tiltX, tiltY); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1163 | } |
| 1164 | |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 1165 | void EventSenderBindings::SetMouseButtonState(gin::Arguments* args) { |
| 1166 | if (!sender_) |
| 1167 | return; |
| 1168 | |
| 1169 | int button_number; |
| 1170 | if (!args->GetNext(&button_number)) { |
| 1171 | args->ThrowError(); |
| 1172 | return; |
| 1173 | } |
| 1174 | |
thestig | fd11ffe | 2015-12-30 19:25:45 | [diff] [blame] | 1175 | int modifiers = -1; // Default to the modifier implied by button_number |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 1176 | if (!args->PeekNext().IsEmpty()) { |
| 1177 | modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
| 1178 | } |
| 1179 | |
| 1180 | sender_->SetMouseButtonState(button_number, modifiers); |
| 1181 | } |
| 1182 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1183 | void EventSenderBindings::KeyDown(gin::Arguments* args) { |
| 1184 | if (!sender_) |
| 1185 | return; |
| 1186 | |
| 1187 | std::string code_str; |
| 1188 | int modifiers = 0; |
| 1189 | int location = DOMKeyLocationStandard; |
| 1190 | args->GetNext(&code_str); |
| 1191 | if (!args->PeekNext().IsEmpty()) { |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 1192 | v8::Local<v8::Value> value; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1193 | args->GetNext(&value); |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 1194 | modifiers = GetKeyModifiersFromV8(args->isolate(), value); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1195 | if (!args->PeekNext().IsEmpty()) |
| 1196 | args->GetNext(&location); |
| 1197 | } |
| 1198 | sender_->KeyDown(code_str, modifiers, static_cast<KeyLocationCode>(location)); |
| 1199 | } |
| 1200 | |
| 1201 | bool EventSenderBindings::ForceLayoutOnEvents() const { |
| 1202 | if (sender_) |
| 1203 | return sender_->force_layout_on_events(); |
| 1204 | return false; |
| 1205 | } |
| 1206 | |
| 1207 | void EventSenderBindings::SetForceLayoutOnEvents(bool force) { |
| 1208 | if (sender_) |
| 1209 | sender_->set_force_layout_on_events(force); |
| 1210 | } |
| 1211 | |
| 1212 | bool EventSenderBindings::IsDragMode() const { |
| 1213 | if (sender_) |
| 1214 | return sender_->is_drag_mode(); |
| 1215 | return true; |
| 1216 | } |
| 1217 | |
| 1218 | void EventSenderBindings::SetIsDragMode(bool drag_mode) { |
| 1219 | if (sender_) |
| 1220 | sender_->set_is_drag_mode(drag_mode); |
| 1221 | } |
| 1222 | |
| 1223 | #if defined(OS_WIN) |
| 1224 | int EventSenderBindings::WmKeyDown() const { |
| 1225 | if (sender_) |
| 1226 | return sender_->wm_key_down(); |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | void EventSenderBindings::SetWmKeyDown(int key_down) { |
| 1231 | if (sender_) |
| 1232 | sender_->set_wm_key_down(key_down); |
| 1233 | } |
| 1234 | |
| 1235 | int EventSenderBindings::WmKeyUp() const { |
| 1236 | if (sender_) |
| 1237 | return sender_->wm_key_up(); |
| 1238 | return 0; |
| 1239 | } |
| 1240 | |
| 1241 | void EventSenderBindings::SetWmKeyUp(int key_up) { |
| 1242 | if (sender_) |
| 1243 | sender_->set_wm_key_up(key_up); |
| 1244 | } |
| 1245 | |
| 1246 | int EventSenderBindings::WmChar() const { |
| 1247 | if (sender_) |
| 1248 | return sender_->wm_char(); |
| 1249 | return 0; |
| 1250 | } |
| 1251 | |
| 1252 | void EventSenderBindings::SetWmChar(int wm_char) { |
| 1253 | if (sender_) |
| 1254 | sender_->set_wm_char(wm_char); |
| 1255 | } |
| 1256 | |
| 1257 | int EventSenderBindings::WmDeadChar() const { |
| 1258 | if (sender_) |
| 1259 | return sender_->wm_dead_char(); |
| 1260 | return 0; |
| 1261 | } |
| 1262 | |
| 1263 | void EventSenderBindings::SetWmDeadChar(int dead_char) { |
| 1264 | if (sender_) |
| 1265 | sender_->set_wm_dead_char(dead_char); |
| 1266 | } |
| 1267 | |
| 1268 | int EventSenderBindings::WmSysKeyDown() const { |
| 1269 | if (sender_) |
| 1270 | return sender_->wm_sys_key_down(); |
| 1271 | return 0; |
| 1272 | } |
| 1273 | |
| 1274 | void EventSenderBindings::SetWmSysKeyDown(int key_down) { |
| 1275 | if (sender_) |
| 1276 | sender_->set_wm_sys_key_down(key_down); |
| 1277 | } |
| 1278 | |
| 1279 | int EventSenderBindings::WmSysKeyUp() const { |
| 1280 | if (sender_) |
| 1281 | return sender_->wm_sys_key_up(); |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | void EventSenderBindings::SetWmSysKeyUp(int key_up) { |
| 1286 | if (sender_) |
| 1287 | sender_->set_wm_sys_key_up(key_up); |
| 1288 | } |
| 1289 | |
| 1290 | int EventSenderBindings::WmSysChar() const { |
| 1291 | if (sender_) |
| 1292 | return sender_->wm_sys_char(); |
| 1293 | return 0; |
| 1294 | } |
| 1295 | |
| 1296 | void EventSenderBindings::SetWmSysChar(int sys_char) { |
| 1297 | if (sender_) |
| 1298 | sender_->set_wm_sys_char(sys_char); |
| 1299 | } |
| 1300 | |
| 1301 | int EventSenderBindings::WmSysDeadChar() const { |
| 1302 | if (sender_) |
| 1303 | return sender_->wm_sys_dead_char(); |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
| 1307 | void EventSenderBindings::SetWmSysDeadChar(int sys_dead_char) { |
| 1308 | if (sender_) |
| 1309 | sender_->set_wm_sys_dead_char(sys_dead_char); |
| 1310 | } |
| 1311 | #endif |
| 1312 | |
| 1313 | // EventSender ----------------------------------------------------------------- |
| 1314 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1315 | WebMouseEvent::Button EventSender::last_button_type_ = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1316 | WebMouseEvent::Button::kNoButton; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1317 | |
| 1318 | EventSender::SavedEvent::SavedEvent() |
| 1319 | : type(TYPE_UNSPECIFIED), |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1320 | button_type(WebMouseEvent::Button::kNoButton), |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1321 | milliseconds(0), |
| 1322 | modifiers(0) {} |
| 1323 | |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 1324 | EventSender::EventSender(WebWidgetTestProxyBase* web_widget_test_proxy_base) |
| 1325 | : web_widget_test_proxy_base_(web_widget_test_proxy_base), |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1326 | replaying_saved_events_(false), |
sammc | 5648c85 | 2015-07-02 01:25:00 | [diff] [blame] | 1327 | weak_factory_(this) { |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 1328 | Reset(); |
sammc | 5648c85 | 2015-07-02 01:25:00 | [diff] [blame] | 1329 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1330 | |
| 1331 | EventSender::~EventSender() {} |
| 1332 | |
| 1333 | void EventSender::Reset() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1334 | DCHECK(current_drag_data_.IsNull()); |
| 1335 | current_drag_data_.Reset(); |
| 1336 | current_drag_effect_ = blink::kWebDragOperationNone; |
| 1337 | current_drag_effects_allowed_ = blink::kWebDragOperationNone; |
| 1338 | if (widget() && current_pointer_state_[kRawMousePointerId].pressed_button_ != |
| 1339 | WebMouseEvent::Button::kNoButton) |
| 1340 | widget()->MouseCaptureLost(); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1341 | current_pointer_state_.clear(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1342 | is_drag_mode_ = true; |
| 1343 | force_layout_on_events_ = true; |
| 1344 | |
| 1345 | #if defined(OS_WIN) |
| 1346 | wm_key_down_ = WM_KEYDOWN; |
| 1347 | wm_key_up_ = WM_KEYUP; |
| 1348 | wm_char_ = WM_CHAR; |
| 1349 | wm_dead_char_ = WM_DEADCHAR; |
| 1350 | wm_sys_key_down_ = WM_SYSKEYDOWN; |
| 1351 | wm_sys_key_up_ = WM_SYSKEYUP; |
| 1352 | wm_sys_char_ = WM_SYSCHAR; |
| 1353 | wm_sys_dead_char_ = WM_SYSDEADCHAR; |
| 1354 | #endif |
| 1355 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1356 | last_click_time_sec_ = 0; |
| 1357 | last_click_pos_ = WebPoint(0, 0); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1358 | last_button_type_ = WebMouseEvent::Button::kNoButton; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1359 | touch_points_.clear(); |
[email protected] | 644616d | 2014-03-27 16:14:47 | [diff] [blame] | 1360 | last_context_menu_data_.reset(); |
lukasza | c935882 | 2016-04-07 14:43:46 | [diff] [blame] | 1361 | weak_factory_.InvalidateWeakPtrs(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1362 | current_gesture_location_ = WebPoint(0, 0); |
| 1363 | mouse_event_queue_.clear(); |
| 1364 | |
| 1365 | time_offset_ms_ = 0; |
| 1366 | click_count_ = 0; |
[email protected] | ace1cd50 | 2014-04-24 21:05:30 | [diff] [blame] | 1367 | |
| 1368 | touch_modifiers_ = 0; |
| 1369 | touch_cancelable_ = true; |
| 1370 | touch_points_.clear(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1371 | } |
| 1372 | |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 1373 | void EventSender::Install(WebLocalFrame* frame) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1374 | EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame); |
| 1375 | } |
| 1376 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1377 | void EventSender::SetContextMenuData(const WebContextMenuData& data) { |
| 1378 | last_context_menu_data_.reset(new WebContextMenuData(data)); |
| 1379 | } |
| 1380 | |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1381 | int EventSender::ModifiersForPointer(int pointer_id) { |
| 1382 | return modifiersWithButtons( |
| 1383 | current_pointer_state_[pointer_id].modifiers_, |
| 1384 | current_pointer_state_[pointer_id].current_buttons_); |
| 1385 | } |
| 1386 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1387 | void EventSender::DoDragDrop(const WebDragData& drag_data, |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 1388 | WebDragOperationsMask mask) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1389 | WebMouseEvent raw_event(WebInputEvent::kMouseDown, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1390 | ModifiersForPointer(kRawMousePointerId), |
| 1391 | GetCurrentEventTimeSec()); |
| 1392 | InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1393 | current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 1394 | current_pointer_state_[kRawMousePointerId].last_pos_, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1395 | click_count_, &raw_event); |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 1396 | |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 1397 | std::unique_ptr<WebInputEvent> widget_event = |
| 1398 | TransformScreenToWidgetCoordinates(raw_event); |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 1399 | const WebMouseEvent* event = |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 1400 | widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) |
| 1401 | : &raw_event; |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 1402 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1403 | current_drag_data_ = drag_data; |
| 1404 | current_drag_effects_allowed_ = mask; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1405 | current_drag_effect_ = mainFrameWidget()->DragTargetDragEnter( |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 1406 | drag_data, event->PositionInWidget(), event->PositionInScreen(), |
| 1407 | current_drag_effects_allowed_, |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1408 | modifiersWithButtons( |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1409 | current_pointer_state_[kRawMousePointerId].modifiers_, |
| 1410 | current_pointer_state_[kRawMousePointerId].current_buttons_)); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1411 | |
| 1412 | // Finish processing events. |
| 1413 | ReplaySavedEvents(); |
| 1414 | } |
| 1415 | |
| 1416 | void EventSender::MouseDown(int button_number, int modifiers) { |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1417 | PointerDown(button_number, modifiers, |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1418 | WebPointerProperties::PointerType::kMouse, kRawMousePointerId, |
| 1419 | 0.0, 0, 0); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | void EventSender::MouseUp(int button_number, int modifiers) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1423 | PointerUp(button_number, modifiers, WebPointerProperties::PointerType::kMouse, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1424 | kRawMousePointerId, 0.0, 0, 0); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1425 | } |
| 1426 | |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1427 | void EventSender::PointerDown(int button_number, |
| 1428 | int modifiers, |
| 1429 | WebPointerProperties::PointerType pointerType, |
| 1430 | int pointerId, |
| 1431 | float pressure, |
| 1432 | int tiltX, |
| 1433 | int tiltY) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1434 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1435 | widget()->UpdateAllLifecyclePhases(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1436 | |
| 1437 | DCHECK_NE(-1, button_number); |
| 1438 | |
| 1439 | WebMouseEvent::Button button_type = |
| 1440 | GetButtonTypeFromButtonNumber(button_number); |
| 1441 | |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1442 | int click_count = 0; |
| 1443 | current_pointer_state_[pointerId].pressed_button_ = button_type; |
| 1444 | current_pointer_state_[pointerId].current_buttons_ |= |
| 1445 | GetWebMouseEventModifierForButton(button_type); |
| 1446 | current_pointer_state_[pointerId].modifiers_ = modifiers; |
| 1447 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1448 | if (pointerType == WebPointerProperties::PointerType::kMouse) { |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1449 | UpdateClickCountForButton(button_type); |
| 1450 | click_count = click_count_; |
| 1451 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1452 | WebMouseEvent event(WebInputEvent::kMouseDown, ModifiersForPointer(pointerId), |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1453 | GetCurrentEventTimeSec()); |
| 1454 | InitMouseEventGeneric(current_pointer_state_[pointerId].pressed_button_, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1455 | current_pointer_state_[pointerId].current_buttons_, |
| 1456 | current_pointer_state_[pointerId].last_pos_, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1457 | click_count, pointerType, pointerId, pressure, tiltX, |
| 1458 | tiltY, &event); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1459 | |
| 1460 | HandleInputEventOnViewOrPopup(event); |
| 1461 | } |
| 1462 | |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1463 | void EventSender::PointerUp(int button_number, |
| 1464 | int modifiers, |
| 1465 | WebPointerProperties::PointerType pointerType, |
| 1466 | int pointerId, |
| 1467 | float pressure, |
| 1468 | int tiltX, |
| 1469 | int tiltY) { |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1470 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1471 | widget()->UpdateAllLifecyclePhases(); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1472 | |
| 1473 | DCHECK_NE(-1, button_number); |
| 1474 | |
| 1475 | WebMouseEvent::Button button_type = |
| 1476 | GetButtonTypeFromButtonNumber(button_number); |
| 1477 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1478 | if (pointerType == WebPointerProperties::PointerType::kMouse && |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1479 | is_drag_mode_ && !replaying_saved_events_) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1480 | SavedEvent saved_event; |
| 1481 | saved_event.type = SavedEvent::TYPE_MOUSE_UP; |
| 1482 | saved_event.button_type = button_type; |
| 1483 | saved_event.modifiers = modifiers; |
| 1484 | mouse_event_queue_.push_back(saved_event); |
| 1485 | ReplaySavedEvents(); |
| 1486 | } else { |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1487 | current_pointer_state_[pointerId].modifiers_ = modifiers; |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1488 | current_pointer_state_[pointerId].current_buttons_ &= |
| 1489 | ~GetWebMouseEventModifierForButton(button_type); |
| 1490 | current_pointer_state_[pointerId].pressed_button_ = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1491 | WebMouseEvent::Button::kNoButton; |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 1492 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1493 | WebMouseEvent event(WebInputEvent::kMouseUp, ModifiersForPointer(pointerId), |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1494 | GetCurrentEventTimeSec()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1495 | int click_count = pointerType == WebPointerProperties::PointerType::kMouse |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1496 | ? click_count_ |
| 1497 | : 0; |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1498 | InitMouseEventGeneric( |
| 1499 | button_type, current_pointer_state_[pointerId].current_buttons_, |
| 1500 | current_pointer_state_[pointerId].last_pos_, click_count, pointerType, |
| 1501 | pointerId, pressure, tiltX, tiltY, &event); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1502 | HandleInputEventOnViewOrPopup(event); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1503 | if (pointerType == WebPointerProperties::PointerType::kMouse) |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1504 | DoDragAfterMouseUp(event); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 1508 | void EventSender::SetMouseButtonState(int button_number, int modifiers) { |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1509 | current_pointer_state_[kRawMousePointerId].pressed_button_ = |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1510 | GetButtonTypeFromButtonNumber(button_number); |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1511 | current_pointer_state_[kRawMousePointerId].current_buttons_ = |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1512 | (modifiers == -1) |
| 1513 | ? GetWebMouseEventModifierForButton( |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1514 | current_pointer_state_[kRawMousePointerId].pressed_button_) |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1515 | : modifiers & kButtonsInModifiers; |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 1516 | } |
| 1517 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1518 | void EventSender::KeyDown(const std::string& code_str, |
| 1519 | int modifiers, |
| 1520 | KeyLocationCode location) { |
| 1521 | // FIXME: I'm not exactly sure how we should convert the string to a key |
| 1522 | // event. This seems to work in the cases I tested. |
| 1523 | // FIXME: Should we also generate a KEY_UP? |
| 1524 | |
| 1525 | bool generate_char = false; |
| 1526 | |
| 1527 | // Convert \n -> VK_RETURN. Some layout tests use \n to mean "Enter", when |
| 1528 | // Windows uses \r for "Enter". |
| 1529 | int code = 0; |
| 1530 | int text = 0; |
| 1531 | bool needs_shift_key_modifier = false; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1532 | std::string domKeyString; |
| 1533 | std::string domCodeString; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1534 | |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1535 | if ("Enter" == code_str) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1536 | generate_char = true; |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1537 | text = code = ui::VKEY_RETURN; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1538 | domKeyString.assign("Enter"); |
| 1539 | domCodeString.assign("Enter"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1540 | } else if ("ArrowRight" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1541 | code = ui::VKEY_RIGHT; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1542 | domKeyString.assign("ArrowRight"); |
| 1543 | domCodeString.assign("ArrowRight"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1544 | } else if ("ArrowDown" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1545 | code = ui::VKEY_DOWN; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1546 | domKeyString.assign("ArrowDown"); |
| 1547 | domCodeString.assign("ArrowDown"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1548 | } else if ("ArrowLeft" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1549 | code = ui::VKEY_LEFT; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1550 | domKeyString.assign("ArrowLeft"); |
| 1551 | domCodeString.assign("ArrowLeft"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1552 | } else if ("ArrowUp" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1553 | code = ui::VKEY_UP; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1554 | domKeyString.assign("ArrowUp"); |
| 1555 | domCodeString.assign("ArrowUp"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1556 | } else if ("Insert" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1557 | code = ui::VKEY_INSERT; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1558 | domKeyString.assign("Insert"); |
| 1559 | domCodeString.assign("Insert"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1560 | } else if ("Delete" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1561 | code = ui::VKEY_DELETE; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1562 | domKeyString.assign("Delete"); |
| 1563 | domCodeString.assign("Delete"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1564 | } else if ("PageUp" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1565 | code = ui::VKEY_PRIOR; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1566 | domKeyString.assign("PageUp"); |
| 1567 | domCodeString.assign("PageUp"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1568 | } else if ("PageDown" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1569 | code = ui::VKEY_NEXT; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1570 | domKeyString.assign("PageDown"); |
| 1571 | domCodeString.assign("PageDown"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1572 | } else if ("Home" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1573 | code = ui::VKEY_HOME; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1574 | domKeyString.assign("Home"); |
| 1575 | domCodeString.assign("Home"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1576 | } else if ("End" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1577 | code = ui::VKEY_END; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1578 | domKeyString.assign("End"); |
| 1579 | domCodeString.assign("End"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1580 | } else if ("PrintScreen" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1581 | code = ui::VKEY_SNAPSHOT; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1582 | domKeyString.assign("PrintScreen"); |
| 1583 | domCodeString.assign("PrintScreen"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1584 | } else if ("ContextMenu" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1585 | code = ui::VKEY_APPS; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1586 | domKeyString.assign("ContextMenu"); |
| 1587 | domCodeString.assign("ContextMenu"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1588 | } else if ("ControlLeft" == code_str) { |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1589 | code = ui::VKEY_CONTROL; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1590 | domKeyString.assign("Control"); |
| 1591 | domCodeString.assign("ControlLeft"); |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1592 | location = DOMKeyLocationLeft; |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1593 | } else if ("ControlRight" == code_str) { |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1594 | code = ui::VKEY_CONTROL; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1595 | domKeyString.assign("Control"); |
| 1596 | domCodeString.assign("ControlRight"); |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1597 | location = DOMKeyLocationRight; |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1598 | } else if ("ShiftLeft" == code_str) { |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1599 | code = ui::VKEY_SHIFT; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1600 | domKeyString.assign("Shift"); |
| 1601 | domCodeString.assign("ShiftLeft"); |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1602 | location = DOMKeyLocationLeft; |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1603 | } else if ("ShiftRight" == code_str) { |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1604 | code = ui::VKEY_SHIFT; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1605 | domKeyString.assign("Shift"); |
| 1606 | domCodeString.assign("ShiftRight"); |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1607 | location = DOMKeyLocationRight; |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1608 | } else if ("AltLeft" == code_str) { |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1609 | code = ui::VKEY_MENU; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1610 | domKeyString.assign("Alt"); |
| 1611 | domCodeString.assign("AltLeft"); |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1612 | location = DOMKeyLocationLeft; |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1613 | } else if ("AltRight" == code_str) { |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1614 | code = ui::VKEY_MENU; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1615 | domKeyString.assign("Alt"); |
| 1616 | domCodeString.assign("AltRight"); |
dtapuska | d3ba0f04 | 2015-08-27 14:08:05 | [diff] [blame] | 1617 | location = DOMKeyLocationRight; |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1618 | } else if ("NumLock" == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1619 | code = ui::VKEY_NUMLOCK; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1620 | domKeyString.assign("NumLock"); |
| 1621 | domCodeString.assign("NumLock"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1622 | } else if ("Backspace" == code_str) { |
[email protected] | 4c07a71 | 2014-08-21 17:05:54 | [diff] [blame] | 1623 | code = ui::VKEY_BACK; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1624 | domKeyString.assign("Backspace"); |
| 1625 | domCodeString.assign("Backspace"); |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 1626 | } else if ("Escape" == code_str) { |
[email protected] | 4c07a71 | 2014-08-21 17:05:54 | [diff] [blame] | 1627 | code = ui::VKEY_ESCAPE; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1628 | domKeyString.assign("Escape"); |
| 1629 | domCodeString.assign("Escape"); |
dtapuska | 8f3b1e5 | 2016-06-21 16:34:07 | [diff] [blame] | 1630 | } else if ("Tab" == code_str) { |
| 1631 | code = ui::VKEY_TAB; |
| 1632 | domKeyString.assign("Tab"); |
| 1633 | domCodeString.assign("Tab"); |
chongz | 78364d67 | 2016-08-03 00:13:43 | [diff] [blame] | 1634 | } else if ("Cut" == code_str || "Copy" == code_str || "Paste" == code_str) { |
| 1635 | // No valid KeyboardCode for Cut/Copy/Paste. |
| 1636 | code = 0; |
| 1637 | domKeyString.assign(code_str); |
| 1638 | // It's OK to assign the same string as the DomCode strings happens to be |
| 1639 | // the same for these keys. |
| 1640 | domCodeString.assign(code_str); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1641 | } else { |
| 1642 | // Compare the input string with the function-key names defined by the |
| 1643 | // DOM spec (i.e. "F1",...,"F24"). If the input string is a function-key |
| 1644 | // name, set its key code. |
| 1645 | for (int i = 1; i <= 24; ++i) { |
| 1646 | std::string function_key_name = base::StringPrintf("F%d", i); |
| 1647 | if (function_key_name == code_str) { |
[email protected] | a731f1a9 | 2014-04-17 19:31:06 | [diff] [blame] | 1648 | code = ui::VKEY_F1 + (i - 1); |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1649 | domKeyString = function_key_name; |
| 1650 | domCodeString = function_key_name; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1651 | break; |
| 1652 | } |
| 1653 | } |
| 1654 | if (!code) { |
esprehn | d29ab80 | 2015-12-11 13:01:19 | [diff] [blame] | 1655 | base::string16 code_str16 = base::UTF8ToUTF16(code_str); |
| 1656 | if (code_str16.size() != 1u) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1657 | v8::Isolate* isolate = blink::MainThreadIsolate(); |
dtapuska | bd2a165 | 2015-05-20 00:30:15 | [diff] [blame] | 1658 | isolate->ThrowException(v8::Exception::TypeError( |
| 1659 | gin::StringToV8(isolate, "Invalid web code."))); |
| 1660 | return; |
| 1661 | } |
esprehn | d29ab80 | 2015-12-11 13:01:19 | [diff] [blame] | 1662 | text = code = code_str16[0]; |
zhongyi | 2396034 | 2016-04-12 23:13:20 | [diff] [blame] | 1663 | needs_shift_key_modifier = base::IsAsciiUpper(code & 0xFF); |
| 1664 | if (base::IsAsciiLower(code & 0xFF)) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1665 | code -= 'a' - 'A'; |
zhongyi | 2396034 | 2016-04-12 23:13:20 | [diff] [blame] | 1666 | if (base::IsAsciiAlpha(code)) { |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1667 | domKeyString.assign(code_str); |
| 1668 | domCodeString.assign("Key"); |
| 1669 | domCodeString.push_back( |
brettw | c15100c | 2015-08-06 22:54:16 | [diff] [blame] | 1670 | base::ToUpperASCII(static_cast<base::char16>(code))); |
zhongyi | 2396034 | 2016-04-12 23:13:20 | [diff] [blame] | 1671 | } else if (base::IsAsciiDigit(code)) { |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1672 | domKeyString.assign(code_str); |
| 1673 | domCodeString.assign("Digit"); |
| 1674 | domCodeString.push_back(code); |
habib.virji | 565c80c | 2015-02-06 12:26:43 | [diff] [blame] | 1675 | } else if (code == ' ') { |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1676 | domKeyString.assign(code_str); |
| 1677 | domCodeString.assign("Space"); |
habib.virji | 565c80c | 2015-02-06 12:26:43 | [diff] [blame] | 1678 | } else if (code == 9) { |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1679 | domKeyString.assign("Tab"); |
| 1680 | domCodeString.assign("Tab"); |
habib.virji | 565c80c | 2015-02-06 12:26:43 | [diff] [blame] | 1681 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1682 | generate_char = true; |
| 1683 | } |
| 1684 | |
| 1685 | if ("(" == code_str) { |
| 1686 | code = '9'; |
| 1687 | needs_shift_key_modifier = true; |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1688 | domKeyString.assign("("); |
| 1689 | domCodeString.assign("Digit9"); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1690 | } |
| 1691 | } |
| 1692 | |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1693 | if (needs_shift_key_modifier) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1694 | modifiers |= WebInputEvent::kShiftKey; |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1695 | |
| 1696 | // See if KeyLocation argument is given. |
| 1697 | switch (location) { |
| 1698 | case DOMKeyLocationStandard: |
| 1699 | break; |
| 1700 | case DOMKeyLocationLeft: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1701 | modifiers |= WebInputEvent::kIsLeft; |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1702 | break; |
| 1703 | case DOMKeyLocationRight: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1704 | modifiers |= WebInputEvent::kIsRight; |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1705 | break; |
| 1706 | case DOMKeyLocationNumpad: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1707 | modifiers |= WebInputEvent::kIsKeyPad; |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1708 | break; |
| 1709 | } |
| 1710 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1711 | // For one generated keyboard event, we need to generate a keyDown/keyUp |
| 1712 | // pair; |
| 1713 | // On Windows, we might also need to generate a char event to mimic the |
| 1714 | // Windows event flow; on other platforms we create a merged event and test |
| 1715 | // the event flow that that platform provides. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1716 | WebKeyboardEvent event_down(WebInputEvent::kRawKeyDown, modifiers, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1717 | GetCurrentEventTimeSec()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1718 | event_down.windows_key_code = code; |
| 1719 | event_down.dom_key = |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 1720 | static_cast<int>(ui::KeycodeConverter::KeyStringToDomKey(domKeyString)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1721 | event_down.dom_code = static_cast<int>( |
chongz | 40aff93 | 2016-05-04 14:30:12 | [diff] [blame] | 1722 | ui::KeycodeConverter::CodeStringToDomCode(domCodeString)); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1723 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1724 | if (generate_char) { |
| 1725 | event_down.text[0] = text; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1726 | event_down.unmodified_text[0] = text; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1727 | } |
| 1728 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1729 | if (event_down.GetModifiers() != 0) |
| 1730 | event_down.is_system_key = IsSystemKeyEvent(event_down); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1731 | |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1732 | WebKeyboardEvent event_up = event_down; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1733 | event_up.SetType(WebInputEvent::kKeyUp); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1734 | // EventSender.m forces a layout here, with at least one |
| 1735 | // test (fast/forms/focus-control-to-page.html) relying on this. |
| 1736 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1737 | widget()->UpdateAllLifecyclePhases(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1738 | |
| 1739 | // In the browser, if a keyboard event corresponds to an editor command, |
| 1740 | // the command will be dispatched to the renderer just before dispatching |
| 1741 | // the keyboard event, and then it will be executed in the |
| 1742 | // RenderView::handleCurrentKeyboardEvent() method. |
| 1743 | // We just simulate the same behavior here. |
| 1744 | std::string edit_command; |
| 1745 | if (GetEditCommand(event_down, &edit_command)) |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 1746 | delegate()->SetEditCommand(edit_command, ""); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1747 | |
tkent | 58876561 | 2014-11-28 01:07:48 | [diff] [blame] | 1748 | HandleInputEventOnViewOrPopup(event_down); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1749 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1750 | if (code == ui::VKEY_ESCAPE && !current_drag_data_.IsNull()) { |
| 1751 | WebMouseEvent event(WebInputEvent::kMouseDown, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1752 | ModifiersForPointer(kRawMousePointerId), |
| 1753 | GetCurrentEventTimeSec()); |
| 1754 | InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1755 | current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 1756 | current_pointer_state_[kRawMousePointerId].last_pos_, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1757 | click_count_, &event); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1758 | FinishDragAndDrop(event, blink::kWebDragOperationNone); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1759 | } |
| 1760 | |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 1761 | delegate()->ClearEditCommand(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1762 | |
| 1763 | if (generate_char) { |
| 1764 | WebKeyboardEvent event_char = event_up; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1765 | event_char.SetType(WebInputEvent::kChar); |
tkent | 58876561 | 2014-11-28 01:07:48 | [diff] [blame] | 1766 | HandleInputEventOnViewOrPopup(event_char); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1767 | } |
| 1768 | |
tkent | 58876561 | 2014-11-28 01:07:48 | [diff] [blame] | 1769 | HandleInputEventOnViewOrPopup(event_up); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | void EventSender::EnableDOMUIEventLogging() {} |
| 1773 | |
| 1774 | void EventSender::FireKeyboardEventsToElement() {} |
| 1775 | |
| 1776 | void EventSender::ClearKillRing() {} |
| 1777 | |
| 1778 | std::vector<std::string> EventSender::ContextClick() { |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 1779 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1780 | widget()->UpdateAllLifecyclePhases(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1781 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1782 | UpdateClickCountForButton(WebMouseEvent::Button::kRight); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1783 | |
| 1784 | // Clears last context menu data because we need to know if the context menu |
| 1785 | // be requested after following mouse events. |
| 1786 | last_context_menu_data_.reset(); |
| 1787 | |
| 1788 | // Generate right mouse down and up. |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1789 | // This is a hack to work around only allowing a single pressed button since |
| 1790 | // we want to test the case where both the left and right mouse buttons are |
| 1791 | // pressed. |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 1792 | // TODO(mustaq): This hack seems unused here! But do we need this hack at all |
| 1793 | // after adding current_buttons_. |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1794 | if (current_pointer_state_[kRawMousePointerId].pressed_button_ == |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1795 | WebMouseEvent::Button::kNoButton) { |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1796 | current_pointer_state_[kRawMousePointerId].pressed_button_ = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1797 | WebMouseEvent::Button::kRight; |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1798 | current_pointer_state_[kRawMousePointerId].current_buttons_ |= |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 1799 | GetWebMouseEventModifierForButton( |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1800 | current_pointer_state_[kRawMousePointerId].pressed_button_); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1801 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1802 | WebMouseEvent event(WebInputEvent::kMouseDown, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1803 | ModifiersForPointer(kRawMousePointerId), |
| 1804 | GetCurrentEventTimeSec()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1805 | InitMouseEvent(WebMouseEvent::Button::kRight, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1806 | current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 1807 | current_pointer_state_[kRawMousePointerId].last_pos_, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1808 | click_count_, &event); |
tkent | 58876561 | 2014-11-28 01:07:48 | [diff] [blame] | 1809 | HandleInputEventOnViewOrPopup(event); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1810 | |
| 1811 | #if defined(OS_WIN) |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1812 | current_pointer_state_[kRawMousePointerId].current_buttons_ &= |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1813 | ~GetWebMouseEventModifierForButton(WebMouseEvent::Button::kRight); |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1814 | current_pointer_state_[kRawMousePointerId].pressed_button_ = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1815 | WebMouseEvent::Button::kNoButton; |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 1816 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1817 | WebMouseEvent mouseUpEvent(WebInputEvent::kMouseUp, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1818 | ModifiersForPointer(kRawMousePointerId), |
| 1819 | GetCurrentEventTimeSec()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1820 | InitMouseEvent(WebMouseEvent::Button::kRight, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 1821 | current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 1822 | current_pointer_state_[kRawMousePointerId].last_pos_, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 1823 | click_count_, &mouseUpEvent); |
| 1824 | HandleInputEventOnViewOrPopup(mouseUpEvent); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1825 | #endif |
| 1826 | |
jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 1827 | std::vector<std::string> menu_items = |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 1828 | MakeMenuItemStringsFor(last_context_menu_data_.get(), delegate()); |
[email protected] | e7c7119 | 2014-04-23 11:53:48 | [diff] [blame] | 1829 | last_context_menu_data_.reset(); |
| 1830 | return menu_items; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | void EventSender::TextZoomIn() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1834 | view()->SetTextZoomFactor(view()->TextZoomFactor() * 1.2f); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | void EventSender::TextZoomOut() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1838 | view()->SetTextZoomFactor(view()->TextZoomFactor() / 1.2f); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | void EventSender::ZoomPageIn() { |
lfg | 05e4137 | 2016-07-22 15:38:10 | [diff] [blame] | 1842 | const std::vector<WebViewTestProxyBase*>& window_list = |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 1843 | interfaces()->GetWindowList(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1844 | |
| 1845 | for (size_t i = 0; i < window_list.size(); ++i) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1846 | window_list.at(i)->web_view()->SetZoomLevel( |
| 1847 | window_list.at(i)->web_view()->ZoomLevel() + 1); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | void EventSender::ZoomPageOut() { |
lfg | 05e4137 | 2016-07-22 15:38:10 | [diff] [blame] | 1852 | const std::vector<WebViewTestProxyBase*>& window_list = |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 1853 | interfaces()->GetWindowList(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1854 | |
| 1855 | for (size_t i = 0; i < window_list.size(); ++i) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1856 | window_list.at(i)->web_view()->SetZoomLevel( |
| 1857 | window_list.at(i)->web_view()->ZoomLevel() - 1); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1858 | } |
| 1859 | } |
| 1860 | |
[email protected] | b32fe54 | 2014-04-30 08:42:06 | [diff] [blame] | 1861 | void EventSender::SetPageZoomFactor(double zoom_factor) { |
lfg | 05e4137 | 2016-07-22 15:38:10 | [diff] [blame] | 1862 | const std::vector<WebViewTestProxyBase*>& window_list = |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 1863 | interfaces()->GetWindowList(); |
[email protected] | b32fe54 | 2014-04-30 08:42:06 | [diff] [blame] | 1864 | |
| 1865 | for (size_t i = 0; i < window_list.size(); ++i) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1866 | window_list.at(i)->web_view()->SetZoomLevel(std::log(zoom_factor) / |
lukasza | 01da260 | 2016-04-05 14:51:26 | [diff] [blame] | 1867 | std::log(1.2)); |
[email protected] | b32fe54 | 2014-04-30 08:42:06 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1871 | void EventSender::ClearTouchPoints() { |
| 1872 | touch_points_.clear(); |
| 1873 | } |
| 1874 | |
[email protected] | bfb6a60 | 2014-04-16 19:59:41 | [diff] [blame] | 1875 | void EventSender::ThrowTouchPointError() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1876 | v8::Isolate* isolate = blink::MainThreadIsolate(); |
[email protected] | bfb6a60 | 2014-04-16 19:59:41 | [diff] [blame] | 1877 | isolate->ThrowException(v8::Exception::TypeError( |
| 1878 | gin::StringToV8(isolate, "Invalid touch point."))); |
| 1879 | } |
| 1880 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1881 | void EventSender::ReleaseTouchPoint(unsigned index) { |
[email protected] | bfb6a60 | 2014-04-16 19:59:41 | [diff] [blame] | 1882 | if (index >= touch_points_.size()) { |
| 1883 | ThrowTouchPointError(); |
| 1884 | return; |
| 1885 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1886 | |
| 1887 | WebTouchPoint* touch_point = &touch_points_[index]; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1888 | touch_point->state = WebTouchPoint::kStateReleased; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1889 | } |
| 1890 | |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 1891 | void EventSender::UpdateTouchPoint(unsigned index, |
| 1892 | float x, |
| 1893 | float y, |
| 1894 | gin::Arguments* args) { |
[email protected] | bfb6a60 | 2014-04-16 19:59:41 | [diff] [blame] | 1895 | if (index >= touch_points_.size()) { |
| 1896 | ThrowTouchPointError(); |
| 1897 | return; |
| 1898 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1899 | |
| 1900 | WebTouchPoint* touch_point = &touch_points_[index]; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1901 | touch_point->state = WebTouchPoint::kStateMoved; |
Mustaq Ahmed | ff30a0e4 | 2017-05-31 17:04:28 | [diff] [blame] | 1902 | touch_point->SetPositionInWidget(x, y); |
| 1903 | touch_point->SetPositionInScreen(x, y); |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 1904 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1905 | InitPointerProperties(args, touch_point, &touch_point->radius_x, |
| 1906 | &touch_point->radius_y); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | void EventSender::CancelTouchPoint(unsigned index) { |
[email protected] | bfb6a60 | 2014-04-16 19:59:41 | [diff] [blame] | 1910 | if (index >= touch_points_.size()) { |
| 1911 | ThrowTouchPointError(); |
| 1912 | return; |
| 1913 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1914 | |
| 1915 | WebTouchPoint* touch_point = &touch_points_[index]; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1916 | touch_point->state = WebTouchPoint::kStateCancelled; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1917 | } |
| 1918 | |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 1919 | void EventSender::SetTouchModifier(const std::string& key_name, bool set_mask) { |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 1920 | int mask = GetKeyModifier(key_name); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1921 | |
| 1922 | if (set_mask) |
| 1923 | touch_modifiers_ |= mask; |
| 1924 | else |
| 1925 | touch_modifiers_ &= ~mask; |
| 1926 | } |
| 1927 | |
[email protected] | ace1cd50 | 2014-04-24 21:05:30 | [diff] [blame] | 1928 | void EventSender::SetTouchCancelable(bool cancelable) { |
| 1929 | touch_cancelable_ = cancelable; |
| 1930 | } |
| 1931 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1932 | void EventSender::DumpFilenameBeingDragged() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1933 | if (current_drag_data_.IsNull()) |
dcheng | c3fe464 | 2015-01-22 06:29:52 | [diff] [blame] | 1934 | return; |
| 1935 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1936 | WebVector<WebDragData::Item> items = current_drag_data_.Items(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1937 | for (size_t i = 0; i < items.size(); ++i) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1938 | if (items[i].storage_type == WebDragData::Item::kStorageTypeBinaryData) { |
| 1939 | WebURL url = items[i].binary_data_source_url; |
| 1940 | WebString filename_extension = items[i].binary_data_filename_extension; |
| 1941 | WebString content_disposition = items[i].binary_data_content_disposition; |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 1942 | base::FilePath filename = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1943 | net::GenerateFileName(url, content_disposition.Utf8(), |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 1944 | std::string(), // referrer_charset |
| 1945 | std::string(), // suggested_name |
| 1946 | std::string(), // mime_type |
| 1947 | std::string()); // default_name |
| 1948 | #if defined(OS_WIN) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1949 | filename = filename.ReplaceExtension(filename_extension.Utf16()); |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 1950 | #else |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1951 | filename = filename.ReplaceExtension(filename_extension.Utf8()); |
dcheng | 3dd8561 | 2017-02-08 10:46:23 | [diff] [blame] | 1952 | #endif |
| 1953 | delegate()->PrintMessage(std::string("Filename being dragged: ") + |
| 1954 | filename.AsUTF8Unsafe() + "\n"); |
| 1955 | return; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1956 | } |
| 1957 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | void EventSender::GestureFlingCancel() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1961 | WebGestureEvent event(WebInputEvent::kGestureFlingCancel, |
| 1962 | WebInputEvent::kNoModifiers, GetCurrentEventTimeSec()); |
wjmaclean | 3bb81479 | 2015-10-20 01:13:32 | [diff] [blame] | 1963 | // Generally it won't matter what device we use here, and since it might |
| 1964 | // be cumbersome to expect all callers to specify a device, we'll just |
| 1965 | // choose Touchpad here. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1966 | event.source_device = blink::kWebGestureDeviceTouchpad; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1967 | |
| 1968 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1969 | widget()->UpdateAllLifecyclePhases(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1970 | |
tkent | 58876561 | 2014-11-28 01:07:48 | [diff] [blame] | 1971 | HandleInputEventOnViewOrPopup(event); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | void EventSender::GestureFlingStart(float x, |
tdresser | 3a1c972 | 2015-02-13 15:44:53 | [diff] [blame] | 1975 | float y, |
| 1976 | float velocity_x, |
| 1977 | float velocity_y, |
| 1978 | gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1979 | WebGestureEvent event(WebInputEvent::kGestureFlingStart, |
| 1980 | WebInputEvent::kNoModifiers, GetCurrentEventTimeSec()); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 1981 | |
tdresser | 15af587 | 2015-02-18 14:03:02 | [diff] [blame] | 1982 | std::string device_string; |
| 1983 | if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) |
| 1984 | args->GetNext(&device_string); |
tdresser | 3a1c972 | 2015-02-13 15:44:53 | [diff] [blame] | 1985 | |
| 1986 | if (device_string == kSourceDeviceStringTouchpad) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1987 | event.source_device = blink::kWebGestureDeviceTouchpad; |
tdresser | 3a1c972 | 2015-02-13 15:44:53 | [diff] [blame] | 1988 | } else if (device_string == kSourceDeviceStringTouchscreen) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1989 | event.source_device = blink::kWebGestureDeviceTouchscreen; |
tdresser | 3a1c972 | 2015-02-13 15:44:53 | [diff] [blame] | 1990 | } else { |
| 1991 | args->ThrowError(); |
| 1992 | return; |
| 1993 | } |
| 1994 | |
sahel | 42a50bb | 2016-07-22 19:34:04 | [diff] [blame] | 1995 | float max_start_velocity = std::max(fabs(velocity_x), fabs(velocity_y)); |
| 1996 | if (!max_start_velocity) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1997 | v8::Isolate* isolate = blink::MainThreadIsolate(); |
sahel | 42a50bb | 2016-07-22 19:34:04 | [diff] [blame] | 1998 | isolate->ThrowException(v8::Exception::TypeError( |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 1999 | gin::StringToV8(isolate, "Invalid max start velocity."))); |
sahel | 42a50bb | 2016-07-22 19:34:04 | [diff] [blame] | 2000 | return; |
| 2001 | } |
| 2002 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2003 | event.x = x; |
| 2004 | event.y = y; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2005 | event.global_x = event.x; |
| 2006 | event.global_y = event.y; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2007 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2008 | event.data.fling_start.velocity_x = velocity_x; |
| 2009 | event.data.fling_start.velocity_y = velocity_y; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2010 | |
| 2011 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2012 | widget()->UpdateAllLifecyclePhases(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2013 | |
tkent | 58876561 | 2014-11-28 01:07:48 | [diff] [blame] | 2014 | HandleInputEventOnViewOrPopup(event); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2015 | } |
| 2016 | |
W. James MacLean | b5846e5 | 2017-08-31 20:39:50 | [diff] [blame] | 2017 | bool EventSender::IsFlinging() { |
| 2018 | return mainFrameWidget()->IsFlinging(); |
tdresser | d7bba52 | 2016-02-19 22:40:13 | [diff] [blame] | 2019 | } |
| 2020 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2021 | void EventSender::GestureScrollFirstPoint(int x, int y) { |
| 2022 | current_gesture_location_ = WebPoint(x, y); |
| 2023 | } |
| 2024 | |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 2025 | void EventSender::TouchStart(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2026 | SendCurrentTouchEvent(WebInputEvent::kTouchStart, args); |
mustaq | 96985f72 | 2015-06-30 21:41:53 | [diff] [blame] | 2027 | } |
| 2028 | |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 2029 | void EventSender::TouchMove(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2030 | SendCurrentTouchEvent(WebInputEvent::kTouchMove, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2031 | } |
| 2032 | |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 2033 | void EventSender::TouchCancel(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2034 | SendCurrentTouchEvent(WebInputEvent::kTouchCancel, args); |
rbyers | 709aa1e | 2016-05-12 04:44:06 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | void EventSender::TouchEnd(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2038 | SendCurrentTouchEvent(WebInputEvent::kTouchEnd, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2039 | } |
| 2040 | |
mustaq | b3c44a0 | 2016-04-19 18:49:05 | [diff] [blame] | 2041 | void EventSender::NotifyStartOfTouchScroll() { |
Navid Zolghadr | 24ff17d | 2018-01-24 20:58:04 | [diff] [blame] | 2042 | WebPointerEvent event = WebPointerEvent::CreatePointerCausesUaActionEvent( |
| 2043 | WebPointerProperties::PointerType::kUnknown, GetCurrentEventTimeSec()); |
mustaq | b3c44a0 | 2016-04-19 18:49:05 | [diff] [blame] | 2044 | HandleInputEventOnViewOrPopup(event); |
| 2045 | } |
| 2046 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2047 | void EventSender::LeapForward(int milliseconds) { |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2048 | if (is_drag_mode_ && |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2049 | current_pointer_state_[kRawMousePointerId].pressed_button_ == |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2050 | WebMouseEvent::Button::kLeft && |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2051 | !replaying_saved_events_) { |
| 2052 | SavedEvent saved_event; |
| 2053 | saved_event.type = SavedEvent::TYPE_LEAP_FORWARD; |
| 2054 | saved_event.milliseconds = milliseconds; |
| 2055 | mouse_event_queue_.push_back(saved_event); |
| 2056 | } else { |
| 2057 | DoLeapForward(milliseconds); |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | void EventSender::BeginDragWithFiles(const std::vector<std::string>& files) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2062 | if (!current_drag_data_.IsNull()) { |
sigbjornf | 23324ff | 2016-02-22 15:46:31 | [diff] [blame] | 2063 | // Nested dragging not supported, fuzzer code a likely culprit. |
| 2064 | // Cancel the current drag operation and throw an error. |
dtapuska | 0d1f4af | 2016-06-29 16:42:22 | [diff] [blame] | 2065 | KeyDown("Escape", 0, DOMKeyLocationStandard); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2066 | v8::Isolate* isolate = blink::MainThreadIsolate(); |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 2067 | isolate->ThrowException(v8::Exception::Error(gin::StringToV8( |
| 2068 | isolate, "Nested beginDragWithFiles() not supported."))); |
sigbjornf | 23324ff | 2016-02-22 15:46:31 | [diff] [blame] | 2069 | return; |
| 2070 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2071 | current_drag_data_.Initialize(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2072 | WebVector<WebString> absolute_filenames(files.size()); |
| 2073 | for (size_t i = 0; i < files.size(); ++i) { |
| 2074 | WebDragData::Item item; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2075 | item.storage_type = WebDragData::Item::kStorageTypeFilename; |
| 2076 | item.filename_data = delegate()->GetAbsoluteWebStringFromUTF8Path(files[i]); |
| 2077 | current_drag_data_.AddItem(item); |
| 2078 | absolute_filenames[i] = item.filename_data; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2079 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2080 | current_drag_data_.SetFilesystemId( |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 2081 | delegate()->RegisterIsolatedFileSystem(absolute_filenames)); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2082 | current_drag_effects_allowed_ = blink::kWebDragOperationCopy; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2083 | |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2084 | const WebPoint& last_pos = |
| 2085 | current_pointer_state_[kRawMousePointerId].last_pos_; |
| 2086 | float scale = delegate()->GetWindowToViewportScale(); |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2087 | WebFloatPoint scaled_last_pos(last_pos.x * scale, last_pos.y * scale); |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2088 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2089 | // Provide a drag source. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2090 | mainFrameWidget()->DragTargetDragEnter(current_drag_data_, scaled_last_pos, |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 2091 | scaled_last_pos, |
| 2092 | current_drag_effects_allowed_, 0); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2093 | // |is_drag_mode_| saves events and then replays them later. We don't |
| 2094 | // need/want that. |
| 2095 | is_drag_mode_ = false; |
| 2096 | |
| 2097 | // Make the rest of eventSender think a drag is in progress. |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2098 | current_pointer_state_[kRawMousePointerId].pressed_button_ = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2099 | WebMouseEvent::Button::kLeft; |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2100 | current_pointer_state_[kRawMousePointerId].current_buttons_ |= |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2101 | GetWebMouseEventModifierForButton( |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2102 | current_pointer_state_[kRawMousePointerId].pressed_button_); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2103 | } |
| 2104 | |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 2105 | void EventSender::AddTouchPoint(float x, float y, gin::Arguments* args) { |
Ella Ge | f69b51b | 2017-09-28 16:30:45 | [diff] [blame] | 2106 | if (touch_points_.size() == WebTouchEvent::kTouchesLengthCap) { |
| 2107 | args->ThrowError(); |
| 2108 | return; |
| 2109 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2110 | WebTouchPoint touch_point; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2111 | touch_point.pointer_type = WebPointerProperties::PointerType::kTouch; |
| 2112 | touch_point.state = WebTouchPoint::kStatePressed; |
Mustaq Ahmed | ff30a0e4 | 2017-05-31 17:04:28 | [diff] [blame] | 2113 | touch_point.SetPositionInWidget(x, y); |
| 2114 | touch_point.SetPositionInScreen(x, y); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2115 | |
mustaq | 913e892 | 2015-09-09 20:15:36 | [diff] [blame] | 2116 | int highest_id = -1; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2117 | for (size_t i = 0; i < touch_points_.size(); i++) { |
mustaq | 913e892 | 2015-09-09 20:15:36 | [diff] [blame] | 2118 | if (touch_points_[i].id > highest_id) |
| 2119 | highest_id = touch_points_[i].id; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2120 | } |
mustaq | 913e892 | 2015-09-09 20:15:36 | [diff] [blame] | 2121 | touch_point.id = highest_id + 1; |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 2122 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2123 | InitPointerProperties(args, &touch_point, &touch_point.radius_x, |
| 2124 | &touch_point.radius_y); |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 2125 | |
nzolghadr | 88114bc | 2016-02-01 21:46:16 | [diff] [blame] | 2126 | // Set the touch point pressure to zero if it was not set by the caller |
landell | 7d38a9a1 | 2016-02-04 16:34:55 | [diff] [blame] | 2127 | if (std::isnan(touch_point.force)) |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 2128 | touch_point.force = 0.0; |
nzolghadr | 88114bc | 2016-02-01 21:46:16 | [diff] [blame] | 2129 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2130 | touch_points_.push_back(touch_point); |
| 2131 | } |
| 2132 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2133 | void EventSender::GestureScrollBegin(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2134 | GestureEvent(WebInputEvent::kGestureScrollBegin, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | void EventSender::GestureScrollEnd(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2138 | GestureEvent(WebInputEvent::kGestureScrollEnd, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | void EventSender::GestureScrollUpdate(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2142 | GestureEvent(WebInputEvent::kGestureScrollUpdate, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2143 | } |
| 2144 | |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 2145 | void EventSender::GesturePinchBegin(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2146 | GestureEvent(WebInputEvent::kGesturePinchBegin, args); |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | void EventSender::GesturePinchEnd(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2150 | GestureEvent(WebInputEvent::kGesturePinchEnd, args); |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | void EventSender::GesturePinchUpdate(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2154 | GestureEvent(WebInputEvent::kGesturePinchUpdate, args); |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 2155 | } |
| 2156 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2157 | void EventSender::GestureTap(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2158 | GestureEvent(WebInputEvent::kGestureTap, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | void EventSender::GestureTapDown(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2162 | GestureEvent(WebInputEvent::kGestureTapDown, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | void EventSender::GestureShowPress(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2166 | GestureEvent(WebInputEvent::kGestureShowPress, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | void EventSender::GestureTapCancel(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2170 | GestureEvent(WebInputEvent::kGestureTapCancel, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | void EventSender::GestureLongPress(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2174 | GestureEvent(WebInputEvent::kGestureLongPress, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | void EventSender::GestureLongTap(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2178 | GestureEvent(WebInputEvent::kGestureLongTap, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | void EventSender::GestureTwoFingerTap(gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2182 | GestureEvent(WebInputEvent::kGestureTwoFingerTap, args); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2183 | } |
| 2184 | |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2185 | void EventSender::MouseScrollBy(gin::Arguments* args, |
| 2186 | MouseScrollType scroll_type) { |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2187 | // TODO(dtapuska): Gestures really should be sent by the MouseWheelEventQueue |
| 2188 | // class in the browser. But since the event doesn't propogate up into |
| 2189 | // the browser generate the events here. See crbug.com/596095. |
dtapuska | b8b2141 | 2016-06-16 11:09:14 | [diff] [blame] | 2190 | bool send_gestures = true; |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2191 | WebMouseWheelEvent wheel_event = |
| 2192 | GetMouseWheelEvent(args, scroll_type, &send_gestures); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2193 | if (wheel_event.GetType() != WebInputEvent::kUndefined && |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2194 | HandleInputEventOnViewOrPopup(wheel_event) == |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2195 | WebInputEventResult::kNotHandled && |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2196 | send_gestures) { |
| 2197 | SendGesturesForMouseWheelEvent(wheel_event); |
| 2198 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2199 | } |
| 2200 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2201 | void EventSender::MouseMoveTo(gin::Arguments* args) { |
| 2202 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2203 | widget()->UpdateAllLifecyclePhases(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2204 | |
[email protected] | f53eba12 | 2014-04-16 11:30:01 | [diff] [blame] | 2205 | double x; |
| 2206 | double y; |
mustaq | 0fff7fc3 | 2014-09-24 20:21:43 | [diff] [blame] | 2207 | if (!args->GetNext(&x) || !args->GetNext(&y)) { |
| 2208 | args->ThrowError(); |
| 2209 | return; |
| 2210 | } |
[email protected] | f53eba12 | 2014-04-16 11:30:01 | [diff] [blame] | 2211 | WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2212 | |
| 2213 | int modifiers = 0; |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2214 | if (!args->PeekNext().IsEmpty()) { |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 2215 | modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext()); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2216 | args->Skip(); |
| 2217 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2218 | |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2219 | WebPointerProperties::PointerType pointerType = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2220 | WebPointerProperties::PointerType::kMouse; |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2221 | int pointerId = 0; |
| 2222 | float pressure = 0; |
| 2223 | int tiltX = 0; |
| 2224 | int tiltY = 0; |
| 2225 | if (!getMousePenPointerProperties(args, pointerType, pointerId, pressure, |
| 2226 | tiltX, tiltY)) |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2227 | return; |
| 2228 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2229 | if (pointerType == WebPointerProperties::PointerType::kMouse && |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2230 | is_drag_mode_ && !replaying_saved_events_ && |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2231 | current_pointer_state_[kRawMousePointerId].pressed_button_ == |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2232 | WebMouseEvent::Button::kLeft) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2233 | SavedEvent saved_event; |
| 2234 | saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; |
| 2235 | saved_event.pos = mouse_pos; |
| 2236 | saved_event.modifiers = modifiers; |
| 2237 | mouse_event_queue_.push_back(saved_event); |
| 2238 | } else { |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2239 | current_pointer_state_[pointerId].last_pos_ = mouse_pos; |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2240 | current_pointer_state_[pointerId].modifiers_ = modifiers; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2241 | WebMouseEvent event(WebInputEvent::kMouseMove, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2242 | ModifiersForPointer(pointerId), |
| 2243 | GetCurrentEventTimeSec()); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2244 | int click_count = pointerType == WebPointerProperties::PointerType::kMouse |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2245 | ? click_count_ |
| 2246 | : 0; |
| 2247 | InitMouseEventGeneric( |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2248 | current_pointer_state_[kRawMousePointerId].pressed_button_, |
| 2249 | current_pointer_state_[kRawMousePointerId].current_buttons_, mouse_pos, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2250 | click_count, pointerType, pointerId, pressure, tiltX, tiltY, &event); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2251 | HandleInputEventOnViewOrPopup(event); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2252 | if (pointerType == WebPointerProperties::PointerType::kMouse) |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2253 | DoDragAfterMouseMove(event); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2254 | } |
| 2255 | } |
| 2256 | |
lanwei | 0474c2a5 | 2017-05-12 18:52:01 | [diff] [blame] | 2257 | void EventSender::MouseLeave( |
| 2258 | blink::WebPointerProperties::PointerType pointerType, |
| 2259 | int pointerId) { |
myid.shin | 12c7fea2 | 2015-03-06 02:31:24 | [diff] [blame] | 2260 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2261 | widget()->UpdateAllLifecyclePhases(); |
myid.shin | 12c7fea2 | 2015-03-06 02:31:24 | [diff] [blame] | 2262 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2263 | WebMouseEvent event(WebInputEvent::kMouseLeave, |
lanwei | 0474c2a5 | 2017-05-12 18:52:01 | [diff] [blame] | 2264 | ModifiersForPointer(pointerId), GetCurrentEventTimeSec()); |
| 2265 | InitMouseEventGeneric(WebMouseEvent::Button::kNoButton, 0, |
| 2266 | current_pointer_state_[kRawMousePointerId].last_pos_, |
| 2267 | click_count_, pointerType, pointerId, 0.0, 0, 0, |
| 2268 | &event); |
thestig | fd11ffe | 2015-12-30 19:25:45 | [diff] [blame] | 2269 | HandleInputEventOnViewOrPopup(event); |
myid.shin | 12c7fea2 | 2015-03-06 02:31:24 | [diff] [blame] | 2270 | } |
| 2271 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2272 | void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { |
tzik | 5f3ffb2 | 2016-09-21 16:54:54 | [diff] [blame] | 2273 | delegate()->PostTask(base::Bind(&EventSender::MouseDown, |
| 2274 | weak_factory_.GetWeakPtr(), button_number, |
| 2275 | modifiers)); |
| 2276 | delegate()->PostTask(base::Bind(&EventSender::MouseUp, |
| 2277 | weak_factory_.GetWeakPtr(), button_number, |
| 2278 | modifiers)); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | void EventSender::ScheduleAsynchronousKeyDown(const std::string& code_str, |
| 2282 | int modifiers, |
| 2283 | KeyLocationCode location) { |
tzik | 5f3ffb2 | 2016-09-21 16:54:54 | [diff] [blame] | 2284 | delegate()->PostTask(base::Bind(&EventSender::KeyDown, |
| 2285 | weak_factory_.GetWeakPtr(), code_str, |
| 2286 | modifiers, location)); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2287 | } |
| 2288 | |
Mustaq Ahmed | c9b974a | 2018-01-22 19:43:44 | [diff] [blame] | 2289 | void EventSender::ConsumeUserActivation() { |
| 2290 | blink::WebUserGestureIndicator::ConsumeUserGesture( |
| 2291 | view()->MainFrame()->ToWebLocalFrame()); |
| 2292 | } |
| 2293 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2294 | double EventSender::GetCurrentEventTimeSec() { |
majidvp | eabdeb8 | 2015-11-30 19:02:05 | [diff] [blame] | 2295 | return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF() + |
majidvp | bfabb071 | 2015-10-02 16:30:00 | [diff] [blame] | 2296 | time_offset_ms_ / 1000.0; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | void EventSender::DoLeapForward(int milliseconds) { |
| 2300 | time_offset_ms_ += milliseconds; |
| 2301 | } |
| 2302 | |
mustaq | 1904837 | 2016-06-16 21:39:32 | [diff] [blame] | 2303 | uint32_t EventSender::GetUniqueTouchEventId(gin::Arguments* args) { |
| 2304 | uint32_t unique_touch_event_id; |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 2305 | if (!args->PeekNext().IsEmpty() && args->GetNext(&unique_touch_event_id)) |
mustaq | 1904837 | 2016-06-16 21:39:32 | [diff] [blame] | 2306 | return unique_touch_event_id; |
| 2307 | |
| 2308 | return 0; |
| 2309 | } |
| 2310 | |
mustaq | 96985f72 | 2015-06-30 21:41:53 | [diff] [blame] | 2311 | void EventSender::SendCurrentTouchEvent(WebInputEvent::Type type, |
mustaq | 1904837 | 2016-06-16 21:39:32 | [diff] [blame] | 2312 | gin::Arguments* args) { |
lanwei | 00f7089 | 2017-02-07 23:12:21 | [diff] [blame] | 2313 | uint32_t unique_touch_event_id = GetUniqueTouchEventId(args); |
mustaq | 1904837 | 2016-06-16 21:39:32 | [diff] [blame] | 2314 | |
Ella Ge | f69b51b | 2017-09-28 16:30:45 | [diff] [blame] | 2315 | DCHECK_LE(touch_points_.size(), |
| 2316 | static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap)); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2317 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2318 | widget()->UpdateAllLifecyclePhases(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2319 | |
Navid Zolghadr | 24ff17d | 2018-01-24 20:58:04 | [diff] [blame] | 2320 | double time_stamp = GetCurrentEventTimeSec(); |
| 2321 | blink::WebInputEvent::DispatchType dispatch_type = |
| 2322 | touch_cancelable_ ? WebInputEvent::kBlocking |
| 2323 | : WebInputEvent::kEventNonBlocking; |
| 2324 | |
| 2325 | for (unsigned i = 0; i < touch_points_.size(); ++i) { |
| 2326 | const WebTouchPoint& touch_point = touch_points_[i]; |
| 2327 | if (touch_point.state != blink::WebTouchPoint::kStateStationary) { |
| 2328 | WebPointerEvent pointer_event = WebPointerEvent( |
| 2329 | PointerEventTypeForTouchPointState(touch_point.state), touch_point, |
| 2330 | touch_point.radius_x * 2, touch_point.radius_y * 2); |
Navid Zolghadr | abfb81c | 2018-02-07 15:59:05 | [diff] [blame^] | 2331 | pointer_event.hovering = false; |
Navid Zolghadr | 24ff17d | 2018-01-24 20:58:04 | [diff] [blame] | 2332 | pointer_event.dispatch_type = dispatch_type; |
| 2333 | pointer_event.moved_beyond_slop_region = true; |
| 2334 | pointer_event.unique_touch_event_id = unique_touch_event_id; |
| 2335 | pointer_event.SetTimeStampSeconds(time_stamp); |
| 2336 | pointer_event.SetModifiers(touch_modifiers_); |
| 2337 | |
| 2338 | HandleInputEventOnViewOrPopup(pointer_event); |
| 2339 | } |
| 2340 | } |
| 2341 | WebPagePopup* popup = widget()->GetPagePopup(); |
| 2342 | if (popup) |
| 2343 | popup->DispatchBufferedTouchEvents(); |
| 2344 | else |
| 2345 | widget()->DispatchBufferedTouchEvents(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2346 | |
| 2347 | for (size_t i = 0; i < touch_points_.size(); ++i) { |
| 2348 | WebTouchPoint* touch_point = &touch_points_[i]; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2349 | if (touch_point->state == WebTouchPoint::kStateReleased || |
| 2350 | touch_point->state == WebTouchPoint::kStateCancelled) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2351 | touch_points_.erase(touch_points_.begin() + i); |
| 2352 | --i; |
thestig | fd11ffe | 2015-12-30 19:25:45 | [diff] [blame] | 2353 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2354 | touch_point->state = WebTouchPoint::kStateStationary; |
thestig | fd11ffe | 2015-12-30 19:25:45 | [diff] [blame] | 2355 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2356 | } |
| 2357 | } |
| 2358 | |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 2359 | void EventSender::GestureEvent(WebInputEvent::Type type, gin::Arguments* args) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2360 | WebGestureEvent event(type, WebInputEvent::kNoModifiers, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2361 | GetCurrentEventTimeSec()); |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 2362 | |
| 2363 | // If the first argument is a string, it is to specify the device, otherwise |
| 2364 | // the device is assumed to be a touchscreen (since most tests were written |
| 2365 | // assuming this). |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2366 | event.source_device = blink::kWebGestureDeviceTouchscreen; |
jochen | 87d2fee | 2015-07-13 08:21:34 | [diff] [blame] | 2367 | if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsString()) { |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 2368 | std::string device_string; |
| 2369 | if (!args->GetNext(&device_string)) { |
| 2370 | args->ThrowError(); |
| 2371 | return; |
| 2372 | } |
tdresser | 3a1c972 | 2015-02-13 15:44:53 | [diff] [blame] | 2373 | if (device_string == kSourceDeviceStringTouchpad) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2374 | event.source_device = blink::kWebGestureDeviceTouchpad; |
tdresser | 3a1c972 | 2015-02-13 15:44:53 | [diff] [blame] | 2375 | } else if (device_string == kSourceDeviceStringTouchscreen) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2376 | event.source_device = blink::kWebGestureDeviceTouchscreen; |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 2377 | } else { |
| 2378 | args->ThrowError(); |
| 2379 | return; |
| 2380 | } |
| 2381 | } |
| 2382 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2383 | double x; |
| 2384 | double y; |
mustaq | 0fff7fc3 | 2014-09-24 20:21:43 | [diff] [blame] | 2385 | if (!args->GetNext(&x) || !args->GetNext(&y)) { |
| 2386 | args->ThrowError(); |
| 2387 | return; |
| 2388 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2389 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2390 | switch (type) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2391 | case WebInputEvent::kGestureScrollUpdate: { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2392 | if (!GetScrollUnits(args, &event.data.scroll_update.delta_units)) |
dtapuska | b1c5ece | 2016-01-18 18:18:02 | [diff] [blame] | 2393 | return; |
majidvp | 50205db | 2014-11-27 17:28:52 | [diff] [blame] | 2394 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2395 | event.data.scroll_update.delta_x = static_cast<float>(x); |
| 2396 | event.data.scroll_update.delta_y = static_cast<float>(y); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2397 | event.x = current_gesture_location_.x; |
| 2398 | event.y = current_gesture_location_.y; |
| 2399 | current_gesture_location_.x = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2400 | current_gesture_location_.x + event.data.scroll_update.delta_x; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2401 | current_gesture_location_.y = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2402 | current_gesture_location_.y + event.data.scroll_update.delta_y; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2403 | break; |
majidvp | 50205db | 2014-11-27 17:28:52 | [diff] [blame] | 2404 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2405 | case WebInputEvent::kGestureScrollBegin: |
mustaq | 0fff7fc3 | 2014-09-24 20:21:43 | [diff] [blame] | 2406 | current_gesture_location_ = WebPoint(x, y); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2407 | event.x = current_gesture_location_.x; |
| 2408 | event.y = current_gesture_location_.y; |
| 2409 | break; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2410 | case WebInputEvent::kGestureScrollEnd: |
| 2411 | case WebInputEvent::kGestureFlingStart: |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2412 | event.x = current_gesture_location_.x; |
| 2413 | event.y = current_gesture_location_.y; |
| 2414 | break; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2415 | case WebInputEvent::kGesturePinchBegin: |
| 2416 | case WebInputEvent::kGesturePinchEnd: |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 2417 | current_gesture_location_ = WebPoint(x, y); |
| 2418 | event.x = current_gesture_location_.x; |
| 2419 | event.y = current_gesture_location_.y; |
| 2420 | break; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2421 | case WebInputEvent::kGesturePinchUpdate: { |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 2422 | float scale = 1; |
| 2423 | if (!args->PeekNext().IsEmpty()) { |
| 2424 | if (!args->GetNext(&scale)) { |
| 2425 | args->ThrowError(); |
| 2426 | return; |
| 2427 | } |
| 2428 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2429 | event.data.pinch_update.scale = scale; |
ccameron | b81b807 | 2015-01-30 00:54:49 | [diff] [blame] | 2430 | current_gesture_location_ = WebPoint(x, y); |
| 2431 | event.x = current_gesture_location_.x; |
| 2432 | event.y = current_gesture_location_.y; |
| 2433 | break; |
| 2434 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2435 | case WebInputEvent::kGestureTap: { |
[email protected] | c278d753 | 2014-07-31 19:51:45 | [diff] [blame] | 2436 | float tap_count = 1; |
| 2437 | float width = 30; |
| 2438 | float height = 30; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2439 | if (!args->PeekNext().IsEmpty()) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2440 | if (!args->GetNext(&tap_count)) { |
| 2441 | args->ThrowError(); |
| 2442 | return; |
| 2443 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2444 | } |
[email protected] | cc42ccf | 2014-06-27 21:31:43 | [diff] [blame] | 2445 | if (!args->PeekNext().IsEmpty()) { |
[email protected] | cc42ccf | 2014-06-27 21:31:43 | [diff] [blame] | 2446 | if (!args->GetNext(&width)) { |
| 2447 | args->ThrowError(); |
| 2448 | return; |
| 2449 | } |
[email protected] | cc42ccf | 2014-06-27 21:31:43 | [diff] [blame] | 2450 | } |
| 2451 | if (!args->PeekNext().IsEmpty()) { |
[email protected] | cc42ccf | 2014-06-27 21:31:43 | [diff] [blame] | 2452 | if (!args->GetNext(&height)) { |
| 2453 | args->ThrowError(); |
| 2454 | return; |
| 2455 | } |
[email protected] | cc42ccf | 2014-06-27 21:31:43 | [diff] [blame] | 2456 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2457 | event.data.tap.tap_count = tap_count; |
[email protected] | c278d753 | 2014-07-31 19:51:45 | [diff] [blame] | 2458 | event.data.tap.width = width; |
| 2459 | event.data.tap.height = height; |
mustaq | 0fff7fc3 | 2014-09-24 20:21:43 | [diff] [blame] | 2460 | event.x = x; |
| 2461 | event.y = y; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2462 | break; |
[email protected] | c278d753 | 2014-07-31 19:51:45 | [diff] [blame] | 2463 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2464 | case WebInputEvent::kGestureTapUnconfirmed: |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2465 | if (!args->PeekNext().IsEmpty()) { |
| 2466 | float tap_count; |
| 2467 | if (!args->GetNext(&tap_count)) { |
| 2468 | args->ThrowError(); |
| 2469 | return; |
| 2470 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2471 | event.data.tap.tap_count = tap_count; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2472 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2473 | event.data.tap.tap_count = 1; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2474 | } |
mustaq | 0fff7fc3 | 2014-09-24 20:21:43 | [diff] [blame] | 2475 | event.x = x; |
| 2476 | event.y = y; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2477 | break; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2478 | case WebInputEvent::kGestureTapDown: { |
[email protected] | c278d753 | 2014-07-31 19:51:45 | [diff] [blame] | 2479 | float width = 30; |
| 2480 | float height = 30; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2481 | if (!args->PeekNext().IsEmpty()) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2482 | if (!args->GetNext(&width)) { |
| 2483 | args->ThrowError(); |
| 2484 | return; |
| 2485 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2486 | } |
| 2487 | if (!args->PeekNext().IsEmpty()) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2488 | if (!args->GetNext(&height)) { |
| 2489 | args->ThrowError(); |
| 2490 | return; |
| 2491 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2492 | } |
mustaq | 0fff7fc3 | 2014-09-24 20:21:43 | [diff] [blame] | 2493 | event.x = x; |
| 2494 | event.y = y; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2495 | event.data.tap_down.width = width; |
| 2496 | event.data.tap_down.height = height; |
[email protected] | c278d753 | 2014-07-31 19:51:45 | [diff] [blame] | 2497 | break; |
| 2498 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2499 | case WebInputEvent::kGestureShowPress: { |
[email protected] | c278d753 | 2014-07-31 19:51:45 | [diff] [blame] | 2500 | float width = 30; |
| 2501 | float height = 30; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2502 | if (!args->PeekNext().IsEmpty()) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2503 | if (!args->GetNext(&width)) { |
| 2504 | args->ThrowError(); |
| 2505 | return; |
| 2506 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2507 | if (!args->PeekNext().IsEmpty()) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2508 | if (!args->GetNext(&height)) { |
| 2509 | args->ThrowError(); |
| 2510 | return; |
| 2511 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2512 | } |
| 2513 | } |
mustaq | 0fff7fc3 | 2014-09-24 20:21:43 | [diff] [blame] | 2514 | event.x = x; |
| 2515 | event.y = y; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2516 | event.data.show_press.width = width; |
| 2517 | event.data.show_press.height = height; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2518 | break; |
[email protected] | c278d753 | 2014-07-31 19:51:45 | [diff] [blame] | 2519 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2520 | case WebInputEvent::kGestureTapCancel: |
mustaq | 0fff7fc3 | 2014-09-24 20:21:43 | [diff] [blame] | 2521 | event.x = x; |
| 2522 | event.y = y; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2523 | break; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2524 | case WebInputEvent::kGestureLongPress: |
| 2525 | case WebInputEvent::kGestureLongTap: |
mustaq | 0fff7fc3 | 2014-09-24 20:21:43 | [diff] [blame] | 2526 | event.x = x; |
| 2527 | event.y = y; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2528 | if (!args->PeekNext().IsEmpty()) { |
| 2529 | float width; |
| 2530 | if (!args->GetNext(&width)) { |
| 2531 | args->ThrowError(); |
| 2532 | return; |
| 2533 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2534 | event.data.long_press.width = width; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2535 | if (!args->PeekNext().IsEmpty()) { |
| 2536 | float height; |
| 2537 | if (!args->GetNext(&height)) { |
| 2538 | args->ThrowError(); |
| 2539 | return; |
| 2540 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2541 | event.data.long_press.height = height; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2542 | } |
| 2543 | } |
| 2544 | break; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2545 | case WebInputEvent::kGestureTwoFingerTap: |
mustaq | 0fff7fc3 | 2014-09-24 20:21:43 | [diff] [blame] | 2546 | event.x = x; |
| 2547 | event.y = y; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2548 | if (!args->PeekNext().IsEmpty()) { |
| 2549 | float first_finger_width; |
| 2550 | if (!args->GetNext(&first_finger_width)) { |
| 2551 | args->ThrowError(); |
| 2552 | return; |
| 2553 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2554 | event.data.two_finger_tap.first_finger_width = first_finger_width; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2555 | if (!args->PeekNext().IsEmpty()) { |
| 2556 | float first_finger_height; |
| 2557 | if (!args->GetNext(&first_finger_height)) { |
| 2558 | args->ThrowError(); |
| 2559 | return; |
| 2560 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2561 | event.data.two_finger_tap.first_finger_height = first_finger_height; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2562 | } |
| 2563 | } |
| 2564 | break; |
| 2565 | default: |
| 2566 | NOTREACHED(); |
| 2567 | } |
| 2568 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2569 | event.unique_touch_event_id = GetUniqueTouchEventId(args); |
chongz | d65eacf | 2017-06-28 05:21:59 | [diff] [blame] | 2570 | if (!GetPointerType(args, false, event.primary_pointer_type)) |
| 2571 | return; |
mustaq | 1904837 | 2016-06-16 21:39:32 | [diff] [blame] | 2572 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2573 | event.global_x = event.x; |
| 2574 | event.global_y = event.y; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2575 | |
| 2576 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2577 | widget()->UpdateAllLifecyclePhases(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2578 | |
dtapuska | 5d2e9c3 | 2015-12-03 16:39:49 | [diff] [blame] | 2579 | WebInputEventResult result = HandleInputEventOnViewOrPopup(event); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2580 | |
| 2581 | // Long press might start a drag drop session. Complete it if so. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2582 | if (type == WebInputEvent::kGestureLongPress && |
| 2583 | !current_drag_data_.IsNull()) { |
| 2584 | WebMouseEvent mouse_event(WebInputEvent::kMouseDown, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2585 | ModifiersForPointer(kRawMousePointerId), |
| 2586 | GetCurrentEventTimeSec()); |
| 2587 | |
| 2588 | InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2589 | current_pointer_state_[kRawMousePointerId].current_buttons_, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2590 | WebPoint(x, y), click_count_, &mouse_event); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2591 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2592 | FinishDragAndDrop(mouse_event, blink::kWebDragOperationNone); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2593 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2594 | args->Return(result != WebInputEventResult::kNotHandled); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2595 | } |
| 2596 | |
dcheng | 59826e3 | 2017-02-22 10:31:36 | [diff] [blame] | 2597 | void EventSender::UpdateClickCountForButton(WebMouseEvent::Button button_type) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2598 | if ((GetCurrentEventTimeSec() - last_click_time_sec_ < |
| 2599 | kMultipleClickTimeSec) && |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2600 | (!OutsideMultiClickRadius( |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2601 | current_pointer_state_[kRawMousePointerId].last_pos_, |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2602 | last_click_pos_)) && |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2603 | (button_type == last_button_type_)) { |
| 2604 | ++click_count_; |
| 2605 | } else { |
| 2606 | click_count_ = 1; |
| 2607 | last_button_type_ = button_type; |
| 2608 | } |
| 2609 | } |
| 2610 | |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2611 | WebMouseWheelEvent EventSender::GetMouseWheelEvent(gin::Arguments* args, |
| 2612 | MouseScrollType scroll_type, |
| 2613 | bool* send_gestures) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2614 | // Force a layout here just to make sure every position has been |
| 2615 | // determined before we send events (as well as all the other methods |
| 2616 | // that send an event do). |
| 2617 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2618 | widget()->UpdateAllLifecyclePhases(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2619 | |
| 2620 | double horizontal; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2621 | double vertical; |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2622 | if (!args->GetNext(&horizontal) || !args->GetNext(&vertical)) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2623 | args->ThrowError(); |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2624 | return WebMouseWheelEvent(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | bool paged = false; |
| 2628 | bool has_precise_scrolling_deltas = false; |
| 2629 | int modifiers = 0; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2630 | WebMouseWheelEvent::Phase phase = WebMouseWheelEvent::kPhaseNone; |
yutak | f3990fd | 2014-12-23 03:52:38 | [diff] [blame] | 2631 | if (!args->PeekNext().IsEmpty()) { |
| 2632 | args->GetNext(&paged); |
| 2633 | if (!args->PeekNext().IsEmpty()) { |
| 2634 | args->GetNext(&has_precise_scrolling_deltas); |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 2635 | if (!args->PeekNext().IsEmpty()) { |
deepak.s | 750d68f | 2015-04-30 07:32:41 | [diff] [blame] | 2636 | v8::Local<v8::Value> value; |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 2637 | args->GetNext(&value); |
bashi | dbd2ef9bb | 2015-06-02 01:39:32 | [diff] [blame] | 2638 | modifiers = GetKeyModifiersFromV8(args->isolate(), value); |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2639 | if (!args->PeekNext().IsEmpty()) { |
dtapuska | b8b2141 | 2016-06-16 11:09:14 | [diff] [blame] | 2640 | args->GetNext(send_gestures); |
chongz | b92d711 | 2016-07-04 22:11:54 | [diff] [blame] | 2641 | if (!args->PeekNext().IsEmpty()) { |
| 2642 | v8::Local<v8::Value> phase_value; |
| 2643 | args->GetNext(&phase_value); |
| 2644 | phase = GetMouseWheelEventPhaseFromV8(phase_value); |
| 2645 | } |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2646 | } |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 2647 | } |
yutak | f3990fd | 2014-12-23 03:52:38 | [diff] [blame] | 2648 | } |
| 2649 | } |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2650 | |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2651 | current_pointer_state_[kRawMousePointerId].modifiers_ = modifiers; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2652 | WebMouseWheelEvent event(WebInputEvent::kMouseWheel, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2653 | ModifiersForPointer(kRawMousePointerId), |
| 2654 | GetCurrentEventTimeSec()); |
| 2655 | InitMouseEvent(current_pointer_state_[kRawMousePointerId].pressed_button_, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2656 | current_pointer_state_[kRawMousePointerId].current_buttons_, |
| 2657 | current_pointer_state_[kRawMousePointerId].last_pos_, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2658 | click_count_, &event); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2659 | event.wheel_ticks_x = static_cast<float>(horizontal); |
| 2660 | event.wheel_ticks_y = static_cast<float>(vertical); |
| 2661 | event.delta_x = event.wheel_ticks_x; |
| 2662 | event.delta_y = event.wheel_ticks_y; |
| 2663 | event.scroll_by_page = paged; |
| 2664 | event.has_precise_scrolling_deltas = has_precise_scrolling_deltas; |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2665 | event.phase = phase; |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2666 | if (scroll_type == MouseScrollType::PIXEL) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2667 | event.wheel_ticks_x /= kScrollbarPixelsPerTick; |
| 2668 | event.wheel_ticks_y /= kScrollbarPixelsPerTick; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2669 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2670 | event.delta_x *= kScrollbarPixelsPerTick; |
| 2671 | event.delta_y *= kScrollbarPixelsPerTick; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2672 | } |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2673 | return event; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2674 | } |
| 2675 | |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 2676 | // Radius fields radius_x and radius_y should eventually be moved to |
| 2677 | // WebPointerProperties. |
| 2678 | // TODO(e_hakkinen): Drop radius_{x,y}_pointer parameters once that happens. |
| 2679 | void EventSender::InitPointerProperties(gin::Arguments* args, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2680 | WebPointerProperties* e, |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 2681 | float* radius_x_pointer, |
| 2682 | float* radius_y_pointer) { |
| 2683 | if (!args->PeekNext().IsEmpty()) { |
| 2684 | double radius_x; |
| 2685 | if (!args->GetNext(&radius_x)) { |
| 2686 | args->ThrowError(); |
| 2687 | return; |
| 2688 | } |
| 2689 | |
| 2690 | double radius_y = radius_x; |
| 2691 | if (!args->PeekNext().IsEmpty()) { |
| 2692 | if (!args->GetNext(&radius_y)) { |
| 2693 | args->ThrowError(); |
| 2694 | return; |
| 2695 | } |
| 2696 | } |
| 2697 | |
| 2698 | *radius_x_pointer = static_cast<float>(radius_x); |
| 2699 | *radius_y_pointer = static_cast<float>(radius_y); |
| 2700 | } |
| 2701 | |
| 2702 | if (!args->PeekNext().IsEmpty()) { |
| 2703 | double force; |
| 2704 | if (!args->GetNext(&force)) { |
| 2705 | args->ThrowError(); |
| 2706 | return; |
| 2707 | } |
| 2708 | e->force = static_cast<float>(force); |
| 2709 | } |
| 2710 | |
| 2711 | if (!args->PeekNext().IsEmpty()) { |
| 2712 | int tiltX, tiltY; |
| 2713 | if (!args->GetNext(&tiltX) || !args->GetNext(&tiltY)) { |
| 2714 | args->ThrowError(); |
| 2715 | return; |
| 2716 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2717 | e->tilt_x = tiltX; |
| 2718 | e->tilt_y = tiltY; |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 2719 | } |
| 2720 | |
chongz | d65eacf | 2017-06-28 05:21:59 | [diff] [blame] | 2721 | if (!GetPointerType(args, false, e->pointer_type)) |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2722 | return; |
e.hakkinen | 8003392 | 2015-07-31 08:41:35 | [diff] [blame] | 2723 | } |
| 2724 | |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2725 | void EventSender::FinishDragAndDrop(const WebMouseEvent& raw_event, |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2726 | blink::WebDragOperation drag_effect) { |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2727 | std::unique_ptr<WebInputEvent> widget_event = |
| 2728 | TransformScreenToWidgetCoordinates(raw_event); |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2729 | const WebMouseEvent* event = |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2730 | widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) |
| 2731 | : &raw_event; |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2732 | |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2733 | current_drag_effect_ = drag_effect; |
| 2734 | if (current_drag_effect_) { |
| 2735 | // Specifically pass any keyboard modifiers to the drop method. This allows |
| 2736 | // tests to control the drop type (i.e. copy or move). |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2737 | mainFrameWidget()->DragTargetDrop( |
| 2738 | current_drag_data_, event->PositionInWidget(), |
| 2739 | event->PositionInScreen(), event->GetModifiers()); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2740 | } else { |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2741 | mainFrameWidget()->DragTargetDragLeave(blink::WebFloatPoint(), |
| 2742 | blink::WebFloatPoint()); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2743 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2744 | current_drag_data_.Reset(); |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2745 | mainFrameWidget()->DragSourceEndedAt(event->PositionInWidget(), |
| 2746 | event->PositionInScreen(), |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 2747 | current_drag_effect_); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2748 | mainFrameWidget()->DragSourceSystemDragEnded(); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2749 | } |
| 2750 | |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2751 | void EventSender::DoDragAfterMouseUp(const WebMouseEvent& raw_event) { |
| 2752 | std::unique_ptr<WebInputEvent> widget_event = |
| 2753 | TransformScreenToWidgetCoordinates(raw_event); |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2754 | const WebMouseEvent* event = |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2755 | widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) |
| 2756 | : &raw_event; |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2757 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2758 | last_click_time_sec_ = event->TimeStampSeconds(); |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2759 | last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_; |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2760 | |
| 2761 | // If we're in a drag operation, complete it. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2762 | if (current_drag_data_.IsNull()) |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2763 | return; |
| 2764 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2765 | blink::WebDragOperation drag_effect = mainFrameWidget()->DragTargetDragOver( |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2766 | event->PositionInWidget(), event->PositionInScreen(), |
| 2767 | current_drag_effects_allowed_, event->GetModifiers()); |
sigbjornf | 8d568b12 | 2016-02-24 21:29:47 | [diff] [blame] | 2768 | |
| 2769 | // Bail if dragover caused cancellation. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2770 | if (current_drag_data_.IsNull()) |
sigbjornf | 8d568b12 | 2016-02-24 21:29:47 | [diff] [blame] | 2771 | return; |
| 2772 | |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2773 | FinishDragAndDrop(raw_event, drag_effect); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2774 | } |
| 2775 | |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2776 | void EventSender::DoDragAfterMouseMove(const WebMouseEvent& raw_event) { |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2777 | if (current_pointer_state_[kRawMousePointerId].pressed_button_ == |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2778 | WebMouseEvent::Button::kNoButton || |
| 2779 | current_drag_data_.IsNull()) { |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2780 | return; |
| 2781 | } |
| 2782 | |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2783 | std::unique_ptr<WebInputEvent> widget_event = |
| 2784 | TransformScreenToWidgetCoordinates(raw_event); |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2785 | const WebMouseEvent* event = |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2786 | widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) |
| 2787 | : &raw_event; |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2788 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2789 | current_drag_effect_ = mainFrameWidget()->DragTargetDragOver( |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 2790 | event->PositionInWidget(), event->PositionInScreen(), |
| 2791 | current_drag_effects_allowed_, event->GetModifiers()); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | void EventSender::ReplaySavedEvents() { |
| 2795 | replaying_saved_events_ = true; |
| 2796 | while (!mouse_event_queue_.empty()) { |
| 2797 | SavedEvent e = mouse_event_queue_.front(); |
| 2798 | mouse_event_queue_.pop_front(); |
| 2799 | |
| 2800 | switch (e.type) { |
| 2801 | case SavedEvent::TYPE_MOUSE_MOVE: { |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2802 | current_pointer_state_[kRawMousePointerId].modifiers_ = e.modifiers; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2803 | WebMouseEvent event(WebInputEvent::kMouseMove, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2804 | ModifiersForPointer(kRawMousePointerId), |
| 2805 | GetCurrentEventTimeSec()); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2806 | InitMouseEvent( |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2807 | current_pointer_state_[kRawMousePointerId].pressed_button_, |
| 2808 | current_pointer_state_[kRawMousePointerId].current_buttons_, e.pos, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2809 | click_count_, &event); |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2810 | current_pointer_state_[kRawMousePointerId].last_pos_ = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2811 | WebPoint(event.PositionInWidget().x, event.PositionInWidget().y); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2812 | HandleInputEventOnViewOrPopup(event); |
| 2813 | DoDragAfterMouseMove(event); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2814 | break; |
| 2815 | } |
| 2816 | case SavedEvent::TYPE_LEAP_FORWARD: |
| 2817 | DoLeapForward(e.milliseconds); |
| 2818 | break; |
| 2819 | case SavedEvent::TYPE_MOUSE_UP: { |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2820 | current_pointer_state_[kRawMousePointerId].current_buttons_ &= |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2821 | ~GetWebMouseEventModifierForButton(e.button_type); |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2822 | current_pointer_state_[kRawMousePointerId].pressed_button_ = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2823 | WebMouseEvent::Button::kNoButton; |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2824 | current_pointer_state_[kRawMousePointerId].modifiers_ = e.modifiers; |
mustaq | 21aed4e | 2015-12-15 21:47:21 | [diff] [blame] | 2825 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2826 | WebMouseEvent event(WebInputEvent::kMouseUp, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2827 | ModifiersForPointer(kRawMousePointerId), |
| 2828 | GetCurrentEventTimeSec()); |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2829 | InitMouseEvent( |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2830 | e.button_type, |
mustaq | abca6ff | 2016-06-09 17:29:53 | [diff] [blame] | 2831 | current_pointer_state_[kRawMousePointerId].current_buttons_, |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2832 | current_pointer_state_[kRawMousePointerId].last_pos_, click_count_, |
| 2833 | &event); |
nzolghadr | 4314603 | 2016-04-11 15:33:38 | [diff] [blame] | 2834 | HandleInputEventOnViewOrPopup(event); |
| 2835 | DoDragAfterMouseUp(event); |
[email protected] | 3db130e | 2014-03-27 08:14:48 | [diff] [blame] | 2836 | break; |
| 2837 | } |
| 2838 | default: |
| 2839 | NOTREACHED(); |
| 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | replaying_saved_events_ = false; |
| 2844 | } |
| 2845 | |
dtapuska | 5d2e9c3 | 2015-12-03 16:39:49 | [diff] [blame] | 2846 | WebInputEventResult EventSender::HandleInputEventOnViewOrPopup( |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2847 | const WebInputEvent& raw_event) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2848 | last_event_timestamp_ = raw_event.TimeStampSeconds(); |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2849 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2850 | WebPagePopup* popup = widget()->GetPagePopup(); |
| 2851 | if (popup && !WebInputEvent::IsKeyboardEventType(raw_event.GetType())) { |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2852 | // ui::ScaleWebInputEvent returns nullptr when the scale is 1.0f as the |
| 2853 | // event does not have to be converted. |
| 2854 | std::unique_ptr<WebInputEvent> scaled_event = ui::ScaleWebInputEvent( |
| 2855 | raw_event, delegate()->GetWindowToViewportScale()); |
| 2856 | const WebInputEvent* popup_friendly_event = |
| 2857 | scaled_event.get() ? scaled_event.get() : &raw_event; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2858 | return popup->HandleInputEvent( |
nzolghadr | 5d859650 | 2017-01-23 22:59:35 | [diff] [blame] | 2859 | blink::WebCoalescedInputEvent(*popup_friendly_event)); |
tkent | 58876561 | 2014-11-28 01:07:48 | [diff] [blame] | 2860 | } |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2861 | |
| 2862 | std::unique_ptr<WebInputEvent> widget_event = |
| 2863 | TransformScreenToWidgetCoordinates(raw_event); |
| 2864 | const WebInputEvent* event = |
| 2865 | widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) |
| 2866 | : &raw_event; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2867 | return widget()->HandleInputEvent(blink::WebCoalescedInputEvent(*event)); |
tkent | 58876561 | 2014-11-28 01:07:48 | [diff] [blame] | 2868 | } |
| 2869 | |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2870 | void EventSender::SendGesturesForMouseWheelEvent( |
| 2871 | const WebMouseWheelEvent wheel_event) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2872 | WebGestureEvent begin_event(WebInputEvent::kGestureScrollBegin, |
| 2873 | wheel_event.GetModifiers(), |
dtapuska | 8c4dae1 | 2017-01-13 00:23:06 | [diff] [blame] | 2874 | GetCurrentEventTimeSec()); |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2875 | InitGestureEventFromMouseWheel(wheel_event, &begin_event); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2876 | begin_event.data.scroll_begin.delta_x_hint = wheel_event.delta_x; |
| 2877 | begin_event.data.scroll_begin.delta_y_hint = wheel_event.delta_y; |
| 2878 | if (wheel_event.scroll_by_page) { |
| 2879 | begin_event.data.scroll_begin.delta_hint_units = |
| 2880 | blink::WebGestureEvent::kPage; |
| 2881 | if (begin_event.data.scroll_begin.delta_x_hint) { |
| 2882 | begin_event.data.scroll_begin.delta_x_hint = |
| 2883 | begin_event.data.scroll_begin.delta_x_hint > 0 ? 1 : -1; |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2884 | } |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2885 | if (begin_event.data.scroll_begin.delta_y_hint) { |
| 2886 | begin_event.data.scroll_begin.delta_y_hint = |
| 2887 | begin_event.data.scroll_begin.delta_y_hint > 0 ? 1 : -1; |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2888 | } |
| 2889 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2890 | begin_event.data.scroll_begin.delta_hint_units = |
| 2891 | wheel_event.has_precise_scrolling_deltas |
| 2892 | ? blink::WebGestureEvent::kPrecisePixels |
| 2893 | : blink::WebGestureEvent::kPixels; |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2897 | widget()->UpdateAllLifecyclePhases(); |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2898 | |
| 2899 | HandleInputEventOnViewOrPopup(begin_event); |
| 2900 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2901 | WebGestureEvent update_event(WebInputEvent::kGestureScrollUpdate, |
| 2902 | wheel_event.GetModifiers(), |
dtapuska | 8c4dae1 | 2017-01-13 00:23:06 | [diff] [blame] | 2903 | GetCurrentEventTimeSec()); |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2904 | InitGestureEventFromMouseWheel(wheel_event, &update_event); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2905 | update_event.data.scroll_update.delta_x = |
| 2906 | begin_event.data.scroll_begin.delta_x_hint; |
| 2907 | update_event.data.scroll_update.delta_y = |
| 2908 | begin_event.data.scroll_begin.delta_y_hint; |
| 2909 | update_event.data.scroll_update.delta_units = |
| 2910 | begin_event.data.scroll_begin.delta_hint_units; |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2911 | |
| 2912 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2913 | widget()->UpdateAllLifecyclePhases(); |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2914 | HandleInputEventOnViewOrPopup(update_event); |
| 2915 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2916 | WebGestureEvent end_event(WebInputEvent::kGestureScrollEnd, |
| 2917 | wheel_event.GetModifiers(), |
| 2918 | GetCurrentEventTimeSec()); |
dtapuska | 899ac22 | 2017-01-03 18:09:16 | [diff] [blame] | 2919 | InitGestureEventFromMouseWheel(wheel_event, &end_event); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2920 | end_event.data.scroll_end.delta_units = |
| 2921 | begin_event.data.scroll_begin.delta_hint_units; |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2922 | |
| 2923 | if (force_layout_on_events_) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2924 | widget()->UpdateAllLifecyclePhases(); |
dtapuska | 43f18e9e | 2016-03-20 20:21:30 | [diff] [blame] | 2925 | HandleInputEventOnViewOrPopup(end_event); |
| 2926 | } |
| 2927 | |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 2928 | TestInterfaces* EventSender::interfaces() { |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2929 | return web_widget_test_proxy_base_->web_view_test_proxy_base() |
| 2930 | ->test_interfaces(); |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 2931 | } |
| 2932 | |
| 2933 | WebTestDelegate* EventSender::delegate() { |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2934 | return web_widget_test_proxy_base_->web_view_test_proxy_base()->delegate(); |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | const blink::WebView* EventSender::view() const { |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2938 | return web_widget_test_proxy_base_->web_view_test_proxy_base()->web_view(); |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | blink::WebView* EventSender::view() { |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2942 | return web_widget_test_proxy_base_->web_view_test_proxy_base()->web_view(); |
lukasza | 335bb76 | 2016-04-22 16:44:03 | [diff] [blame] | 2943 | } |
| 2944 | |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2945 | blink::WebWidget* EventSender::widget() { |
| 2946 | return web_widget_test_proxy_base_->web_widget(); |
| 2947 | } |
| 2948 | |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2949 | blink::WebFrameWidget* EventSender::mainFrameWidget() { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2950 | return view()->MainFrame()->ToWebLocalFrame()->FrameWidget(); |
paulmeyer | 90f6c31d | 2016-11-12 00:17:59 | [diff] [blame] | 2951 | } |
| 2952 | |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2953 | std::unique_ptr<WebInputEvent> EventSender::TransformScreenToWidgetCoordinates( |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2954 | const WebInputEvent& event) { |
lukasza | d322c5ca | 2016-10-07 00:32:34 | [diff] [blame] | 2955 | return delegate()->TransformScreenToWidgetCoordinates( |
| 2956 | web_widget_test_proxy_base_, event); |
oshima | 76b6eeb | 2016-06-27 15:55:12 | [diff] [blame] | 2957 | } |
| 2958 | |
jochen | f5f3175 | 2015-06-03 12:06:34 | [diff] [blame] | 2959 | } // namespace test_runner |