Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: components/test_runner/event_sender.cc

Issue 2036873002: Making EventSender talk to the right WebWidget (for OOPIF support). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use RenderWidget::viewRect() [rather than windowRect()] in TransformScreenToWidgetCoordinates. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/test_runner/event_sender.h ('k') | components/test_runner/web_frame_test_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/test_runner/event_sender.h" 5 #include "components/test_runner/event_sender.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory>
10
9 #include "base/bind.h" 11 #include "base/bind.h"
10 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 13 #include "base/command_line.h"
12 #include "base/logging.h" 14 #include "base/logging.h"
13 #include "base/macros.h" 15 #include "base/macros.h"
14 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
15 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
18 #include "build/build_config.h" 20 #include "build/build_config.h"
19 #include "components/test_runner/mock_spell_check.h" 21 #include "components/test_runner/mock_spell_check.h"
20 #include "components/test_runner/test_interfaces.h" 22 #include "components/test_runner/test_interfaces.h"
21 #include "components/test_runner/web_test_delegate.h" 23 #include "components/test_runner/web_test_delegate.h"
22 #include "components/test_runner/web_view_test_proxy.h" 24 #include "components/test_runner/web_view_test_proxy.h"
25 #include "components/test_runner/web_widget_test_proxy.h"
23 #include "gin/handle.h" 26 #include "gin/handle.h"
24 #include "gin/object_template_builder.h" 27 #include "gin/object_template_builder.h"
25 #include "gin/wrappable.h" 28 #include "gin/wrappable.h"
29 #include "third_party/WebKit/public/platform/WebInputEvent.h"
26 #include "third_party/WebKit/public/platform/WebPointerProperties.h" 30 #include "third_party/WebKit/public/platform/WebPointerProperties.h"
27 #include "third_party/WebKit/public/platform/WebString.h" 31 #include "third_party/WebKit/public/platform/WebString.h"
28 #include "third_party/WebKit/public/platform/WebVector.h" 32 #include "third_party/WebKit/public/platform/WebVector.h"
29 #include "third_party/WebKit/public/web/WebContextMenuData.h" 33 #include "third_party/WebKit/public/web/WebContextMenuData.h"
30 #include "third_party/WebKit/public/web/WebKit.h" 34 #include "third_party/WebKit/public/web/WebKit.h"
31 #include "third_party/WebKit/public/web/WebLocalFrame.h" 35 #include "third_party/WebKit/public/web/WebLocalFrame.h"
32 #include "third_party/WebKit/public/web/WebPagePopup.h" 36 #include "third_party/WebKit/public/web/WebPagePopup.h"
33 #include "third_party/WebKit/public/web/WebView.h" 37 #include "third_party/WebKit/public/web/WebView.h"
34 #include "ui/events/blink/blink_event_util.h" 38 #include "ui/events/blink/blink_event_util.h"
35 #include "ui/events/keycodes/dom/keycode_converter.h" 39 #include "ui/events/keycodes/dom/keycode_converter.h"
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 1277
1274 WebMouseEvent::Button EventSender::last_button_type_ = 1278 WebMouseEvent::Button EventSender::last_button_type_ =
1275 WebMouseEvent::Button::NoButton; 1279 WebMouseEvent::Button::NoButton;
1276 1280
1277 EventSender::SavedEvent::SavedEvent() 1281 EventSender::SavedEvent::SavedEvent()
1278 : type(TYPE_UNSPECIFIED), 1282 : type(TYPE_UNSPECIFIED),
1279 button_type(WebMouseEvent::Button::NoButton), 1283 button_type(WebMouseEvent::Button::NoButton),
1280 milliseconds(0), 1284 milliseconds(0),
1281 modifiers(0) {} 1285 modifiers(0) {}
1282 1286
1283 EventSender::EventSender(WebViewTestProxyBase* web_view_test_proxy_base) 1287 EventSender::EventSender(WebWidgetTestProxyBase* web_widget_test_proxy_base)
1284 : web_view_test_proxy_base_(web_view_test_proxy_base), 1288 : web_widget_test_proxy_base_(web_widget_test_proxy_base),
1285 replaying_saved_events_(false), 1289 replaying_saved_events_(false),
1286 weak_factory_(this) { 1290 weak_factory_(this) {
1287 Reset(); 1291 Reset();
1288 } 1292 }
1289 1293
1290 EventSender::~EventSender() {} 1294 EventSender::~EventSender() {}
1291 1295
1292 void EventSender::Reset() { 1296 void EventSender::Reset() {
1293 DCHECK(current_drag_data_.isNull()); 1297 DCHECK(current_drag_data_.isNull());
1294 current_drag_data_.reset(); 1298 current_drag_data_.reset();
1295 current_drag_effect_ = blink::WebDragOperationNone; 1299 current_drag_effect_ = blink::WebDragOperationNone;
1296 current_drag_effects_allowed_ = blink::WebDragOperationNone; 1300 current_drag_effects_allowed_ = blink::WebDragOperationNone;
1297 if (view() && 1301 if (widget() &&
1298 current_pointer_state_[kRawMousePointerId].pressed_button_ != 1302 current_pointer_state_[kRawMousePointerId].pressed_button_ !=
1299 WebMouseEvent::Button::NoButton) 1303 WebMouseEvent::Button::NoButton)
1300 view()->mouseCaptureLost(); 1304 widget()->mouseCaptureLost();
1301 current_pointer_state_.clear(); 1305 current_pointer_state_.clear();
1302 is_drag_mode_ = true; 1306 is_drag_mode_ = true;
1303 force_layout_on_events_ = true; 1307 force_layout_on_events_ = true;
1304 1308
1305 #if defined(OS_WIN) 1309 #if defined(OS_WIN)
1306 wm_key_down_ = WM_KEYDOWN; 1310 wm_key_down_ = WM_KEYDOWN;
1307 wm_key_up_ = WM_KEYUP; 1311 wm_key_up_ = WM_KEYUP;
1308 wm_char_ = WM_CHAR; 1312 wm_char_ = WM_CHAR;
1309 wm_dead_char_ = WM_DEADCHAR; 1313 wm_dead_char_ = WM_DEADCHAR;
1310 wm_sys_key_down_ = WM_SYSKEYDOWN; 1314 wm_sys_key_down_ = WM_SYSKEYDOWN;
(...skipping 22 matching lines...) Expand all
1333 void EventSender::Install(WebLocalFrame* frame) { 1337 void EventSender::Install(WebLocalFrame* frame) {
1334 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame); 1338 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame);
1335 } 1339 }
1336 1340
1337 void EventSender::SetContextMenuData(const WebContextMenuData& data) { 1341 void EventSender::SetContextMenuData(const WebContextMenuData& data) {
1338 last_context_menu_data_.reset(new WebContextMenuData(data)); 1342 last_context_menu_data_.reset(new WebContextMenuData(data));
1339 } 1343 }
1340 1344
1341 void EventSender::DoDragDrop(const WebDragData& drag_data, 1345 void EventSender::DoDragDrop(const WebDragData& drag_data,
1342 WebDragOperationsMask mask) { 1346 WebDragOperationsMask mask) {
1343 WebMouseEvent unscaled_event; 1347 WebMouseEvent raw_event;
1344 InitMouseEvent(WebInputEvent::MouseDown, 1348 InitMouseEvent(WebInputEvent::MouseDown,
1345 current_pointer_state_[kRawMousePointerId].pressed_button_, 1349 current_pointer_state_[kRawMousePointerId].pressed_button_,
1346 current_pointer_state_[kRawMousePointerId].current_buttons_, 1350 current_pointer_state_[kRawMousePointerId].current_buttons_,
1347 current_pointer_state_[kRawMousePointerId].last_pos_, 1351 current_pointer_state_[kRawMousePointerId].last_pos_,
1348 GetCurrentEventTimeSec(), click_count_, 1352 GetCurrentEventTimeSec(), click_count_,
1349 current_pointer_state_[kRawMousePointerId].modifiers_, 1353 current_pointer_state_[kRawMousePointerId].modifiers_,
1350 &unscaled_event); 1354 &raw_event);
1351 1355
1352 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); 1356 std::unique_ptr<WebInputEvent> widget_event =
1357 TransformScreenToWidgetCoordinates(raw_event);
1353 const WebMouseEvent* event = 1358 const WebMouseEvent* event =
1354 scaled_event.get() ? static_cast<WebMouseEvent*>(scaled_event.get()) 1359 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
1355 : &unscaled_event; 1360 : &raw_event;
1356 1361
1357 WebPoint client_point(event->x, event->y); 1362 WebPoint client_point(event->x, event->y);
1358 WebPoint screen_point(event->globalX, event->globalY); 1363 WebPoint screen_point(event->globalX, event->globalY);
1359 current_drag_data_ = drag_data; 1364 current_drag_data_ = drag_data;
1360 current_drag_effects_allowed_ = mask; 1365 current_drag_effects_allowed_ = mask;
1361 current_drag_effect_ = view()->dragTargetDragEnter( 1366 current_drag_effect_ = view()->dragTargetDragEnter(
1362 drag_data, client_point, screen_point, current_drag_effects_allowed_, 1367 drag_data, client_point, screen_point, current_drag_effects_allowed_,
1363 modifiersWithButtons( 1368 modifiersWithButtons(
1364 current_pointer_state_[kRawMousePointerId].modifiers_, 1369 current_pointer_state_[kRawMousePointerId].modifiers_,
1365 current_pointer_state_[kRawMousePointerId].current_buttons_)); 1370 current_pointer_state_[kRawMousePointerId].current_buttons_));
(...skipping 14 matching lines...) Expand all
1380 } 1385 }
1381 1386
1382 void EventSender::PointerDown(int button_number, 1387 void EventSender::PointerDown(int button_number,
1383 int modifiers, 1388 int modifiers,
1384 WebPointerProperties::PointerType pointerType, 1389 WebPointerProperties::PointerType pointerType,
1385 int pointerId, 1390 int pointerId,
1386 float pressure, 1391 float pressure,
1387 int tiltX, 1392 int tiltX,
1388 int tiltY) { 1393 int tiltY) {
1389 if (force_layout_on_events_) 1394 if (force_layout_on_events_)
1390 view()->updateAllLifecyclePhases(); 1395 widget()->updateAllLifecyclePhases();
1391 1396
1392 DCHECK_NE(-1, button_number); 1397 DCHECK_NE(-1, button_number);
1393 1398
1394 WebMouseEvent::Button button_type = 1399 WebMouseEvent::Button button_type =
1395 GetButtonTypeFromButtonNumber(button_number); 1400 GetButtonTypeFromButtonNumber(button_number);
1396 1401
1397 WebMouseEvent event; 1402 WebMouseEvent event;
1398 int click_count = 0; 1403 int click_count = 0;
1399 current_pointer_state_[pointerId].pressed_button_ = button_type; 1404 current_pointer_state_[pointerId].pressed_button_ = button_type;
1400 current_pointer_state_[pointerId].current_buttons_ |= 1405 current_pointer_state_[pointerId].current_buttons_ |=
(...skipping 16 matching lines...) Expand all
1417 } 1422 }
1418 1423
1419 void EventSender::PointerUp(int button_number, 1424 void EventSender::PointerUp(int button_number,
1420 int modifiers, 1425 int modifiers,
1421 WebPointerProperties::PointerType pointerType, 1426 WebPointerProperties::PointerType pointerType,
1422 int pointerId, 1427 int pointerId,
1423 float pressure, 1428 float pressure,
1424 int tiltX, 1429 int tiltX,
1425 int tiltY) { 1430 int tiltY) {
1426 if (force_layout_on_events_) 1431 if (force_layout_on_events_)
1427 view()->updateAllLifecyclePhases(); 1432 widget()->updateAllLifecyclePhases();
1428 1433
1429 DCHECK_NE(-1, button_number); 1434 DCHECK_NE(-1, button_number);
1430 1435
1431 WebMouseEvent::Button button_type = 1436 WebMouseEvent::Button button_type =
1432 GetButtonTypeFromButtonNumber(button_number); 1437 GetButtonTypeFromButtonNumber(button_number);
1433 1438
1434 if (pointerType == WebPointerProperties::PointerType::Mouse && 1439 if (pointerType == WebPointerProperties::PointerType::Mouse &&
1435 is_drag_mode_ && !replaying_saved_events_) { 1440 is_drag_mode_ && !replaying_saved_events_) {
1436 SavedEvent saved_event; 1441 SavedEvent saved_event;
1437 saved_event.type = SavedEvent::TYPE_MOUSE_UP; 1442 saved_event.type = SavedEvent::TYPE_MOUSE_UP;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 event_down.modifiers |= WebInputEvent::IsKeyPad; 1691 event_down.modifiers |= WebInputEvent::IsKeyPad;
1687 break; 1692 break;
1688 } 1693 }
1689 1694
1690 WebKeyboardEvent event_up; 1695 WebKeyboardEvent event_up;
1691 event_up = event_down; 1696 event_up = event_down;
1692 event_up.type = WebInputEvent::KeyUp; 1697 event_up.type = WebInputEvent::KeyUp;
1693 // EventSender.m forces a layout here, with at least one 1698 // EventSender.m forces a layout here, with at least one
1694 // test (fast/forms/focus-control-to-page.html) relying on this. 1699 // test (fast/forms/focus-control-to-page.html) relying on this.
1695 if (force_layout_on_events_) 1700 if (force_layout_on_events_)
1696 view()->updateAllLifecyclePhases(); 1701 widget()->updateAllLifecyclePhases();
1697 1702
1698 // In the browser, if a keyboard event corresponds to an editor command, 1703 // In the browser, if a keyboard event corresponds to an editor command,
1699 // the command will be dispatched to the renderer just before dispatching 1704 // the command will be dispatched to the renderer just before dispatching
1700 // the keyboard event, and then it will be executed in the 1705 // the keyboard event, and then it will be executed in the
1701 // RenderView::handleCurrentKeyboardEvent() method. 1706 // RenderView::handleCurrentKeyboardEvent() method.
1702 // We just simulate the same behavior here. 1707 // We just simulate the same behavior here.
1703 std::string edit_command; 1708 std::string edit_command;
1704 if (GetEditCommand(event_down, &edit_command)) 1709 if (GetEditCommand(event_down, &edit_command))
1705 delegate()->SetEditCommand(edit_command, ""); 1710 delegate()->SetEditCommand(edit_command, "");
1706 1711
(...skipping 20 matching lines...) Expand all
1727 HandleInputEventOnViewOrPopup(event_up); 1732 HandleInputEventOnViewOrPopup(event_up);
1728 } 1733 }
1729 1734
1730 void EventSender::EnableDOMUIEventLogging() {} 1735 void EventSender::EnableDOMUIEventLogging() {}
1731 1736
1732 void EventSender::FireKeyboardEventsToElement() {} 1737 void EventSender::FireKeyboardEventsToElement() {}
1733 1738
1734 void EventSender::ClearKillRing() {} 1739 void EventSender::ClearKillRing() {}
1735 1740
1736 std::vector<std::string> EventSender::ContextClick() { 1741 std::vector<std::string> EventSender::ContextClick() {
1737 if (force_layout_on_events_) { 1742 if (force_layout_on_events_)
1738 view()->updateAllLifecyclePhases(); 1743 widget()->updateAllLifecyclePhases();
1739 }
1740 1744
1741 UpdateClickCountForButton(WebMouseEvent::Button::Right); 1745 UpdateClickCountForButton(WebMouseEvent::Button::Right);
1742 1746
1743 // Clears last context menu data because we need to know if the context menu 1747 // Clears last context menu data because we need to know if the context menu
1744 // be requested after following mouse events. 1748 // be requested after following mouse events.
1745 last_context_menu_data_.reset(); 1749 last_context_menu_data_.reset();
1746 1750
1747 // Generate right mouse down and up. 1751 // Generate right mouse down and up.
1748 WebMouseEvent event; 1752 WebMouseEvent event;
1749 // This is a hack to work around only allowing a single pressed button since 1753 // This is a hack to work around only allowing a single pressed button since
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 void EventSender::GestureFlingCancel() { 1907 void EventSender::GestureFlingCancel() {
1904 WebGestureEvent event; 1908 WebGestureEvent event;
1905 event.type = WebInputEvent::GestureFlingCancel; 1909 event.type = WebInputEvent::GestureFlingCancel;
1906 // Generally it won't matter what device we use here, and since it might 1910 // Generally it won't matter what device we use here, and since it might
1907 // be cumbersome to expect all callers to specify a device, we'll just 1911 // be cumbersome to expect all callers to specify a device, we'll just
1908 // choose Touchpad here. 1912 // choose Touchpad here.
1909 event.sourceDevice = blink::WebGestureDeviceTouchpad; 1913 event.sourceDevice = blink::WebGestureDeviceTouchpad;
1910 event.timeStampSeconds = GetCurrentEventTimeSec(); 1914 event.timeStampSeconds = GetCurrentEventTimeSec();
1911 1915
1912 if (force_layout_on_events_) 1916 if (force_layout_on_events_)
1913 view()->updateAllLifecyclePhases(); 1917 widget()->updateAllLifecyclePhases();
1914 1918
1915 HandleInputEventOnViewOrPopup(event); 1919 HandleInputEventOnViewOrPopup(event);
1916 } 1920 }
1917 1921
1918 void EventSender::GestureFlingStart(float x, 1922 void EventSender::GestureFlingStart(float x,
1919 float y, 1923 float y,
1920 float velocity_x, 1924 float velocity_x,
1921 float velocity_y, 1925 float velocity_y,
1922 gin::Arguments* args) { 1926 gin::Arguments* args) {
1923 WebGestureEvent event; 1927 WebGestureEvent event;
(...skipping 23 matching lines...) Expand all
1947 event.x = x; 1951 event.x = x;
1948 event.y = y; 1952 event.y = y;
1949 event.globalX = event.x; 1953 event.globalX = event.x;
1950 event.globalY = event.y; 1954 event.globalY = event.y;
1951 1955
1952 event.data.flingStart.velocityX = velocity_x; 1956 event.data.flingStart.velocityX = velocity_x;
1953 event.data.flingStart.velocityY = velocity_y; 1957 event.data.flingStart.velocityY = velocity_y;
1954 event.timeStampSeconds = GetCurrentEventTimeSec(); 1958 event.timeStampSeconds = GetCurrentEventTimeSec();
1955 1959
1956 if (force_layout_on_events_) 1960 if (force_layout_on_events_)
1957 view()->updateAllLifecyclePhases(); 1961 widget()->updateAllLifecyclePhases();
1958 1962
1959 HandleInputEventOnViewOrPopup(event); 1963 HandleInputEventOnViewOrPopup(event);
1960 } 1964 }
1961 1965
1962 bool EventSender::IsFlinging() const { 1966 bool EventSender::IsFlinging() const {
1963 return view()->isFlinging(); 1967 return view()->isFlinging();
1964 } 1968 }
1965 1969
1966 void EventSender::GestureScrollFirstPoint(int x, int y) { 1970 void EventSender::GestureScrollFirstPoint(int x, int y) {
1967 current_gesture_location_ = WebPoint(x, y); 1971 current_gesture_location_ = WebPoint(x, y);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
2134 InitMouseWheelEvent(args, scroll_type, &wheel_event, &send_gestures); 2138 InitMouseWheelEvent(args, scroll_type, &wheel_event, &send_gestures);
2135 if (HandleInputEventOnViewOrPopup(wheel_event) == 2139 if (HandleInputEventOnViewOrPopup(wheel_event) ==
2136 WebInputEventResult::NotHandled && 2140 WebInputEventResult::NotHandled &&
2137 send_gestures) { 2141 send_gestures) {
2138 SendGesturesForMouseWheelEvent(wheel_event); 2142 SendGesturesForMouseWheelEvent(wheel_event);
2139 } 2143 }
2140 } 2144 }
2141 2145
2142 void EventSender::MouseMoveTo(gin::Arguments* args) { 2146 void EventSender::MouseMoveTo(gin::Arguments* args) {
2143 if (force_layout_on_events_) 2147 if (force_layout_on_events_)
2144 view()->updateAllLifecyclePhases(); 2148 widget()->updateAllLifecyclePhases();
2145 2149
2146 double x; 2150 double x;
2147 double y; 2151 double y;
2148 if (!args->GetNext(&x) || !args->GetNext(&y)) { 2152 if (!args->GetNext(&x) || !args->GetNext(&y)) {
2149 args->ThrowError(); 2153 args->ThrowError();
2150 return; 2154 return;
2151 } 2155 }
2152 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); 2156 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y));
2153 2157
2154 int modifiers = 0; 2158 int modifiers = 0;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2189 GetCurrentEventTimeSec(), click_count, modifiers, pointerType, 2193 GetCurrentEventTimeSec(), click_count, modifiers, pointerType,
2190 pointerId, pressure, tiltX, tiltY, &event); 2194 pointerId, pressure, tiltX, tiltY, &event);
2191 HandleInputEventOnViewOrPopup(event); 2195 HandleInputEventOnViewOrPopup(event);
2192 if (pointerType == WebPointerProperties::PointerType::Mouse) 2196 if (pointerType == WebPointerProperties::PointerType::Mouse)
2193 DoDragAfterMouseMove(event); 2197 DoDragAfterMouseMove(event);
2194 } 2198 }
2195 } 2199 }
2196 2200
2197 void EventSender::MouseLeave() { 2201 void EventSender::MouseLeave() {
2198 if (force_layout_on_events_) 2202 if (force_layout_on_events_)
2199 view()->updateAllLifecyclePhases(); 2203 widget()->updateAllLifecyclePhases();
2200 2204
2201 WebMouseEvent event; 2205 WebMouseEvent event;
2202 InitMouseEvent(WebInputEvent::MouseLeave, WebMouseEvent::Button::NoButton, 0, 2206 InitMouseEvent(WebInputEvent::MouseLeave, WebMouseEvent::Button::NoButton, 0,
2203 current_pointer_state_[kRawMousePointerId].last_pos_, 2207 current_pointer_state_[kRawMousePointerId].last_pos_,
2204 GetCurrentEventTimeSec(), click_count_, 0, &event); 2208 GetCurrentEventTimeSec(), click_count_, 0, &event);
2205 HandleInputEventOnViewOrPopup(event); 2209 HandleInputEventOnViewOrPopup(event);
2206 } 2210 }
2207 2211
2208 2212
2209 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { 2213 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 2262
2259 void EventSender::SendCurrentTouchEvent(WebInputEvent::Type type, 2263 void EventSender::SendCurrentTouchEvent(WebInputEvent::Type type,
2260 gin::Arguments* args) { 2264 gin::Arguments* args) {
2261 bool moved_beyond_slop_region; 2265 bool moved_beyond_slop_region;
2262 uint32_t unique_touch_event_id; 2266 uint32_t unique_touch_event_id;
2263 GetOptionalTouchArgs(args, moved_beyond_slop_region, unique_touch_event_id); 2267 GetOptionalTouchArgs(args, moved_beyond_slop_region, unique_touch_event_id);
2264 2268
2265 DCHECK_GT(static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap), 2269 DCHECK_GT(static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap),
2266 touch_points_.size()); 2270 touch_points_.size());
2267 if (force_layout_on_events_) 2271 if (force_layout_on_events_)
2268 view()->updateAllLifecyclePhases(); 2272 widget()->updateAllLifecyclePhases();
2269 2273
2270 WebTouchEvent touch_event; 2274 WebTouchEvent touch_event;
2271 touch_event.type = type; 2275 touch_event.type = type;
2272 touch_event.modifiers = touch_modifiers_; 2276 touch_event.modifiers = touch_modifiers_;
2273 touch_event.dispatchType = touch_cancelable_ 2277 touch_event.dispatchType = touch_cancelable_
2274 ? WebInputEvent::Blocking 2278 ? WebInputEvent::Blocking
2275 : WebInputEvent::EventNonBlocking; 2279 : WebInputEvent::EventNonBlocking;
2276 touch_event.timeStampSeconds = GetCurrentEventTimeSec(); 2280 touch_event.timeStampSeconds = GetCurrentEventTimeSec();
2277 touch_event.movedBeyondSlopRegion = moved_beyond_slop_region; 2281 touch_event.movedBeyondSlopRegion = moved_beyond_slop_region;
2278 touch_event.uniqueTouchEventId = unique_touch_event_id; 2282 touch_event.uniqueTouchEventId = unique_touch_event_id;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2517 NOTREACHED(); 2521 NOTREACHED();
2518 } 2522 }
2519 2523
2520 event.uniqueTouchEventId = GetUniqueTouchEventId(args); 2524 event.uniqueTouchEventId = GetUniqueTouchEventId(args);
2521 2525
2522 event.globalX = event.x; 2526 event.globalX = event.x;
2523 event.globalY = event.y; 2527 event.globalY = event.y;
2524 event.timeStampSeconds = GetCurrentEventTimeSec(); 2528 event.timeStampSeconds = GetCurrentEventTimeSec();
2525 2529
2526 if (force_layout_on_events_) 2530 if (force_layout_on_events_)
2527 view()->updateAllLifecyclePhases(); 2531 widget()->updateAllLifecyclePhases();
2528 2532
2529 WebInputEventResult result = HandleInputEventOnViewOrPopup(event); 2533 WebInputEventResult result = HandleInputEventOnViewOrPopup(event);
2530 2534
2531 // Long press might start a drag drop session. Complete it if so. 2535 // Long press might start a drag drop session. Complete it if so.
2532 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { 2536 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) {
2533 WebMouseEvent mouse_event; 2537 WebMouseEvent mouse_event;
2534 InitMouseEvent(WebInputEvent::MouseDown, 2538 InitMouseEvent(WebInputEvent::MouseDown,
2535 current_pointer_state_[kRawMousePointerId].pressed_button_, 2539 current_pointer_state_[kRawMousePointerId].pressed_button_,
2536 current_pointer_state_[kRawMousePointerId].current_buttons_, 2540 current_pointer_state_[kRawMousePointerId].current_buttons_,
2537 WebPoint(x, y), GetCurrentEventTimeSec(), click_count_, 2541 WebPoint(x, y), GetCurrentEventTimeSec(), click_count_,
(...skipping 21 matching lines...) Expand all
2559 } 2563 }
2560 2564
2561 void EventSender::InitMouseWheelEvent(gin::Arguments* args, 2565 void EventSender::InitMouseWheelEvent(gin::Arguments* args,
2562 MouseScrollType scroll_type, 2566 MouseScrollType scroll_type,
2563 WebMouseWheelEvent* event, 2567 WebMouseWheelEvent* event,
2564 bool* send_gestures) { 2568 bool* send_gestures) {
2565 // Force a layout here just to make sure every position has been 2569 // Force a layout here just to make sure every position has been
2566 // determined before we send events (as well as all the other methods 2570 // determined before we send events (as well as all the other methods
2567 // that send an event do). 2571 // that send an event do).
2568 if (force_layout_on_events_) 2572 if (force_layout_on_events_)
2569 view()->updateAllLifecyclePhases(); 2573 widget()->updateAllLifecyclePhases();
2570 2574
2571 double horizontal; 2575 double horizontal;
2572 if (!args->GetNext(&horizontal)) { 2576 if (!args->GetNext(&horizontal)) {
2573 args->ThrowError(); 2577 args->ThrowError();
2574 return; 2578 return;
2575 } 2579 }
2576 double vertical; 2580 double vertical;
2577 if (!args->GetNext(&vertical)) { 2581 if (!args->GetNext(&vertical)) {
2578 args->ThrowError(); 2582 args->ThrowError();
2579 return; 2583 return;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2666 return; 2670 return;
2667 } 2671 }
2668 e->tiltX = tiltX; 2672 e->tiltX = tiltX;
2669 e->tiltY = tiltY; 2673 e->tiltY = tiltY;
2670 } 2674 }
2671 2675
2672 if (!getPointerType(args, false, e->pointerType)) 2676 if (!getPointerType(args, false, e->pointerType))
2673 return; 2677 return;
2674 } 2678 }
2675 2679
2676 void EventSender::FinishDragAndDrop(const WebMouseEvent& unscaled_event, 2680 void EventSender::FinishDragAndDrop(const WebMouseEvent& raw_event,
2677 blink::WebDragOperation drag_effect) { 2681 blink::WebDragOperation drag_effect) {
2678 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); 2682 std::unique_ptr<WebInputEvent> widget_event =
2683 TransformScreenToWidgetCoordinates(raw_event);
2679 const WebMouseEvent* event = 2684 const WebMouseEvent* event =
2680 scaled_event.get() ? static_cast<const WebMouseEvent*>(scaled_event.get()) 2685 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2681 : &unscaled_event; 2686 : &raw_event;
2682 2687
2683 WebPoint client_point(event->x, event->y); 2688 WebPoint client_point(event->x, event->y);
2684 WebPoint screen_point(event->globalX, event->globalY); 2689 WebPoint screen_point(event->globalX, event->globalY);
2685 current_drag_effect_ = drag_effect; 2690 current_drag_effect_ = drag_effect;
2686 if (current_drag_effect_) { 2691 if (current_drag_effect_) {
2687 // Specifically pass any keyboard modifiers to the drop method. This allows 2692 // Specifically pass any keyboard modifiers to the drop method. This allows
2688 // tests to control the drop type (i.e. copy or move). 2693 // tests to control the drop type (i.e. copy or move).
2689 view()->dragTargetDrop(current_drag_data_, client_point, screen_point, 2694 view()->dragTargetDrop(current_drag_data_, client_point, screen_point,
2690 event->modifiers); 2695 event->modifiers);
2691 } else { 2696 } else {
2692 view()->dragTargetDragLeave(); 2697 view()->dragTargetDragLeave();
2693 } 2698 }
2694 current_drag_data_.reset(); 2699 current_drag_data_.reset();
2695 view()->dragSourceEndedAt(client_point, screen_point, current_drag_effect_); 2700 view()->dragSourceEndedAt(client_point, screen_point, current_drag_effect_);
2696 view()->dragSourceSystemDragEnded(); 2701 view()->dragSourceSystemDragEnded();
2697 } 2702 }
2698 2703
2699 void EventSender::DoDragAfterMouseUp(const WebMouseEvent& unscaled_event) { 2704 void EventSender::DoDragAfterMouseUp(const WebMouseEvent& raw_event) {
2700 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); 2705 std::unique_ptr<WebInputEvent> widget_event =
2706 TransformScreenToWidgetCoordinates(raw_event);
2701 const WebMouseEvent* event = 2707 const WebMouseEvent* event =
2702 scaled_event.get() ? static_cast<WebMouseEvent*>(scaled_event.get()) 2708 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2703 : &unscaled_event; 2709 : &raw_event;
2704 2710
2705 last_click_time_sec_ = event->timeStampSeconds; 2711 last_click_time_sec_ = event->timeStampSeconds;
2706 last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_; 2712 last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_;
2707 2713
2708 // If we're in a drag operation, complete it. 2714 // If we're in a drag operation, complete it.
2709 if (current_drag_data_.isNull()) 2715 if (current_drag_data_.isNull())
2710 return; 2716 return;
2711 2717
2712 WebPoint client_point(event->x, event->y); 2718 WebPoint client_point(event->x, event->y);
2713 WebPoint screen_point(event->globalX, event->globalY); 2719 WebPoint screen_point(event->globalX, event->globalY);
2714 blink::WebDragOperation drag_effect = view()->dragTargetDragOver( 2720 blink::WebDragOperation drag_effect = view()->dragTargetDragOver(
2715 client_point, screen_point, current_drag_effects_allowed_, 2721 client_point, screen_point, current_drag_effects_allowed_,
2716 event->modifiers); 2722 event->modifiers);
2717 2723
2718 // Bail if dragover caused cancellation. 2724 // Bail if dragover caused cancellation.
2719 if (current_drag_data_.isNull()) 2725 if (current_drag_data_.isNull())
2720 return; 2726 return;
2721 2727
2722 FinishDragAndDrop(unscaled_event, drag_effect); 2728 FinishDragAndDrop(raw_event, drag_effect);
2723 } 2729 }
2724 2730
2725 void EventSender::DoDragAfterMouseMove(const WebMouseEvent& unscaled_event) { 2731 void EventSender::DoDragAfterMouseMove(const WebMouseEvent& raw_event) {
2726 if (current_pointer_state_[kRawMousePointerId].pressed_button_ == 2732 if (current_pointer_state_[kRawMousePointerId].pressed_button_ ==
2727 WebMouseEvent::Button::NoButton || 2733 WebMouseEvent::Button::NoButton ||
2728 current_drag_data_.isNull()) { 2734 current_drag_data_.isNull()) {
2729 return; 2735 return;
2730 } 2736 }
2731 2737
2732 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); 2738 std::unique_ptr<WebInputEvent> widget_event =
2739 TransformScreenToWidgetCoordinates(raw_event);
2733 const WebMouseEvent* event = 2740 const WebMouseEvent* event =
2734 scaled_event.get() ? static_cast<WebMouseEvent*>(scaled_event.get()) 2741 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2735 : &unscaled_event; 2742 : &raw_event;
2736 2743
2737 WebPoint client_point(event->x, event->y); 2744 WebPoint client_point(event->x, event->y);
2738 WebPoint screen_point(event->globalX, event->globalY); 2745 WebPoint screen_point(event->globalX, event->globalY);
2739 current_drag_effect_ = view()->dragTargetDragOver( 2746 current_drag_effect_ = view()->dragTargetDragOver(
2740 client_point, screen_point, current_drag_effects_allowed_, 2747 client_point, screen_point, current_drag_effects_allowed_,
2741 event->modifiers); 2748 event->modifiers);
2742 } 2749 }
2743 2750
2744 void EventSender::ReplaySavedEvents() { 2751 void EventSender::ReplaySavedEvents() {
2745 replaying_saved_events_ = true; 2752 replaying_saved_events_ = true;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2782 } 2789 }
2783 default: 2790 default:
2784 NOTREACHED(); 2791 NOTREACHED();
2785 } 2792 }
2786 } 2793 }
2787 2794
2788 replaying_saved_events_ = false; 2795 replaying_saved_events_ = false;
2789 } 2796 }
2790 2797
2791 WebInputEventResult EventSender::HandleInputEventOnViewOrPopup( 2798 WebInputEventResult EventSender::HandleInputEventOnViewOrPopup(
2792 const WebInputEvent& unscaled_event) { 2799 const WebInputEvent& raw_event) {
2793 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); 2800 last_event_timestamp_ = raw_event.timeStampSeconds;
2801
2802 WebPagePopup* popup = widget()->pagePopup();
2803 if (popup && !WebInputEvent::isKeyboardEventType(raw_event.type)) {
2804 // ui::ScaleWebInputEvent returns nullptr when the scale is 1.0f as the
2805 // event does not have to be converted.
2806 std::unique_ptr<WebInputEvent> scaled_event = ui::ScaleWebInputEvent(
2807 raw_event, delegate()->GetWindowToViewportScale());
2808 const WebInputEvent* popup_friendly_event =
2809 scaled_event.get() ? scaled_event.get() : &raw_event;
2810 return popup->handleInputEvent(*popup_friendly_event);
2811 }
2812
2813 std::unique_ptr<WebInputEvent> widget_event =
2814 TransformScreenToWidgetCoordinates(raw_event);
2794 const WebInputEvent* event = 2815 const WebInputEvent* event =
2795 scaled_event.get() ? scaled_event.get() : &unscaled_event; 2816 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2796 2817 : &raw_event;
2797 last_event_timestamp_ = event->timeStampSeconds; 2818 return widget()->handleInputEvent(*event);
2798
2799 if (WebPagePopup* popup = view()->pagePopup()) {
2800 if (!WebInputEvent::isKeyboardEventType(event->type))
2801 return popup->handleInputEvent(*event);
2802 }
2803 return view()->handleInputEvent(*event);
2804 } 2819 }
2805 2820
2806 void EventSender::SendGesturesForMouseWheelEvent( 2821 void EventSender::SendGesturesForMouseWheelEvent(
2807 const WebMouseWheelEvent wheel_event) { 2822 const WebMouseWheelEvent wheel_event) {
2808 WebGestureEvent begin_event; 2823 WebGestureEvent begin_event;
2809 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollBegin, 2824 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollBegin,
2810 GetCurrentEventTimeSec(), wheel_event, 2825 GetCurrentEventTimeSec(), wheel_event,
2811 &begin_event); 2826 &begin_event);
2812 begin_event.data.scrollBegin.deltaXHint = wheel_event.deltaX; 2827 begin_event.data.scrollBegin.deltaXHint = wheel_event.deltaX;
2813 begin_event.data.scrollBegin.deltaYHint = wheel_event.deltaY; 2828 begin_event.data.scrollBegin.deltaYHint = wheel_event.deltaY;
2814 if (wheel_event.scrollByPage) { 2829 if (wheel_event.scrollByPage) {
2815 begin_event.data.scrollBegin.deltaHintUnits = blink::WebGestureEvent::Page; 2830 begin_event.data.scrollBegin.deltaHintUnits = blink::WebGestureEvent::Page;
2816 if (begin_event.data.scrollBegin.deltaXHint) { 2831 if (begin_event.data.scrollBegin.deltaXHint) {
2817 begin_event.data.scrollBegin.deltaXHint = 2832 begin_event.data.scrollBegin.deltaXHint =
2818 begin_event.data.scrollBegin.deltaXHint > 0 ? 1 : -1; 2833 begin_event.data.scrollBegin.deltaXHint > 0 ? 1 : -1;
2819 } 2834 }
2820 if (begin_event.data.scrollBegin.deltaYHint) { 2835 if (begin_event.data.scrollBegin.deltaYHint) {
2821 begin_event.data.scrollBegin.deltaYHint = 2836 begin_event.data.scrollBegin.deltaYHint =
2822 begin_event.data.scrollBegin.deltaYHint > 0 ? 1 : -1; 2837 begin_event.data.scrollBegin.deltaYHint > 0 ? 1 : -1;
2823 } 2838 }
2824 } else { 2839 } else {
2825 begin_event.data.scrollBegin.deltaHintUnits = 2840 begin_event.data.scrollBegin.deltaHintUnits =
2826 wheel_event.hasPreciseScrollingDeltas 2841 wheel_event.hasPreciseScrollingDeltas
2827 ? blink::WebGestureEvent::PrecisePixels 2842 ? blink::WebGestureEvent::PrecisePixels
2828 : blink::WebGestureEvent::Pixels; 2843 : blink::WebGestureEvent::Pixels;
2829 } 2844 }
2830 2845
2831 if (force_layout_on_events_) 2846 if (force_layout_on_events_)
2832 view()->updateAllLifecyclePhases(); 2847 widget()->updateAllLifecyclePhases();
2833 2848
2834 HandleInputEventOnViewOrPopup(begin_event); 2849 HandleInputEventOnViewOrPopup(begin_event);
2835 2850
2836 WebGestureEvent update_event; 2851 WebGestureEvent update_event;
2837 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollUpdate, 2852 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollUpdate,
2838 GetCurrentEventTimeSec(), wheel_event, 2853 GetCurrentEventTimeSec(), wheel_event,
2839 &update_event); 2854 &update_event);
2840 update_event.data.scrollUpdate.deltaX = 2855 update_event.data.scrollUpdate.deltaX =
2841 begin_event.data.scrollBegin.deltaXHint; 2856 begin_event.data.scrollBegin.deltaXHint;
2842 update_event.data.scrollUpdate.deltaY = 2857 update_event.data.scrollUpdate.deltaY =
2843 begin_event.data.scrollBegin.deltaYHint; 2858 begin_event.data.scrollBegin.deltaYHint;
2844 update_event.data.scrollUpdate.deltaUnits = 2859 update_event.data.scrollUpdate.deltaUnits =
2845 begin_event.data.scrollBegin.deltaHintUnits; 2860 begin_event.data.scrollBegin.deltaHintUnits;
2846 2861
2847 if (force_layout_on_events_) 2862 if (force_layout_on_events_)
2848 view()->updateAllLifecyclePhases(); 2863 widget()->updateAllLifecyclePhases();
2849 HandleInputEventOnViewOrPopup(update_event); 2864 HandleInputEventOnViewOrPopup(update_event);
2850 2865
2851 WebGestureEvent end_event; 2866 WebGestureEvent end_event;
2852 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollEnd, 2867 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollEnd,
2853 GetCurrentEventTimeSec(), wheel_event, 2868 GetCurrentEventTimeSec(), wheel_event,
2854 &end_event); 2869 &end_event);
2855 end_event.data.scrollEnd.deltaUnits = 2870 end_event.data.scrollEnd.deltaUnits =
2856 begin_event.data.scrollBegin.deltaHintUnits; 2871 begin_event.data.scrollBegin.deltaHintUnits;
2857 2872
2858 if (force_layout_on_events_) 2873 if (force_layout_on_events_)
2859 view()->updateAllLifecyclePhases(); 2874 widget()->updateAllLifecyclePhases();
2860 HandleInputEventOnViewOrPopup(end_event); 2875 HandleInputEventOnViewOrPopup(end_event);
2861 } 2876 }
2862 2877
2863 TestInterfaces* EventSender::interfaces() { 2878 TestInterfaces* EventSender::interfaces() {
2864 return web_view_test_proxy_base_->test_interfaces(); 2879 return web_widget_test_proxy_base_->web_view_test_proxy_base()
2880 ->test_interfaces();
2865 } 2881 }
2866 2882
2867 WebTestDelegate* EventSender::delegate() { 2883 WebTestDelegate* EventSender::delegate() {
2868 return web_view_test_proxy_base_->delegate(); 2884 return web_widget_test_proxy_base_->web_view_test_proxy_base()->delegate();
2869 } 2885 }
2870 2886
2871 const blink::WebView* EventSender::view() const { 2887 const blink::WebView* EventSender::view() const {
2872 return web_view_test_proxy_base_->web_view(); 2888 return web_widget_test_proxy_base_->web_view_test_proxy_base()->web_view();
2873 } 2889 }
2874 2890
2875 blink::WebView* EventSender::view() { 2891 blink::WebView* EventSender::view() {
2876 return web_view_test_proxy_base_->web_view(); 2892 return web_widget_test_proxy_base_->web_view_test_proxy_base()->web_view();
2877 } 2893 }
2878 2894
2879 std::unique_ptr<WebInputEvent> EventSender::ScaleEvent( 2895 blink::WebWidget* EventSender::widget() {
2896 return web_widget_test_proxy_base_->web_widget();
2897 }
2898
2899 std::unique_ptr<WebInputEvent> EventSender::TransformScreenToWidgetCoordinates(
2880 const WebInputEvent& event) { 2900 const WebInputEvent& event) {
2881 // ui::ScaleWebInputEvent returns nullptr when the scale is 1.0f as the event 2901 return delegate()->TransformScreenToWidgetCoordinates(
2882 // does not have to be converted. 2902 web_widget_test_proxy_base_, event);
2883 return ui::ScaleWebInputEvent(event, delegate()->GetWindowToViewportScale());
2884 } 2903 }
2885 2904
2886 } // namespace test_runner 2905 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/event_sender.h ('k') | components/test_runner/web_frame_test_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698