OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/test_runner/event_sender.h" | 5 #include "components/test_runner/event_sender.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "gin/object_template_builder.h" | 25 #include "gin/object_template_builder.h" |
26 #include "gin/wrappable.h" | 26 #include "gin/wrappable.h" |
27 #include "third_party/WebKit/public/platform/WebPointerProperties.h" | 27 #include "third_party/WebKit/public/platform/WebPointerProperties.h" |
28 #include "third_party/WebKit/public/platform/WebString.h" | 28 #include "third_party/WebKit/public/platform/WebString.h" |
29 #include "third_party/WebKit/public/platform/WebVector.h" | 29 #include "third_party/WebKit/public/platform/WebVector.h" |
30 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 30 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
31 #include "third_party/WebKit/public/web/WebKit.h" | 31 #include "third_party/WebKit/public/web/WebKit.h" |
32 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 32 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
33 #include "third_party/WebKit/public/web/WebPagePopup.h" | 33 #include "third_party/WebKit/public/web/WebPagePopup.h" |
34 #include "third_party/WebKit/public/web/WebView.h" | 34 #include "third_party/WebKit/public/web/WebView.h" |
| 35 #include "ui/events/blink/blink_event_util.h" |
35 #include "ui/events/keycodes/dom/keycode_converter.h" | 36 #include "ui/events/keycodes/dom/keycode_converter.h" |
36 #include "ui/events/keycodes/keyboard_codes.h" | 37 #include "ui/events/keycodes/keyboard_codes.h" |
37 #include "v8/include/v8.h" | 38 #include "v8/include/v8.h" |
38 | 39 |
39 using blink::WebContextMenuData; | 40 using blink::WebContextMenuData; |
40 using blink::WebDragData; | 41 using blink::WebDragData; |
41 using blink::WebDragOperationsMask; | 42 using blink::WebDragOperationsMask; |
42 using blink::WebFloatPoint; | 43 using blink::WebFloatPoint; |
43 using blink::WebGestureEvent; | 44 using blink::WebGestureEvent; |
44 using blink::WebInputEvent; | 45 using blink::WebInputEvent; |
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 void EventSender::Install(WebLocalFrame* frame) { | 1299 void EventSender::Install(WebLocalFrame* frame) { |
1299 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame); | 1300 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame); |
1300 } | 1301 } |
1301 | 1302 |
1302 void EventSender::SetContextMenuData(const WebContextMenuData& data) { | 1303 void EventSender::SetContextMenuData(const WebContextMenuData& data) { |
1303 last_context_menu_data_.reset(new WebContextMenuData(data)); | 1304 last_context_menu_data_.reset(new WebContextMenuData(data)); |
1304 } | 1305 } |
1305 | 1306 |
1306 void EventSender::DoDragDrop(const WebDragData& drag_data, | 1307 void EventSender::DoDragDrop(const WebDragData& drag_data, |
1307 WebDragOperationsMask mask) { | 1308 WebDragOperationsMask mask) { |
1308 WebMouseEvent event; | 1309 WebMouseEvent unscaled_event; |
1309 InitMouseEvent(WebInputEvent::MouseDown, | 1310 InitMouseEvent(WebInputEvent::MouseDown, |
1310 current_pointer_state_[kRawMousePointerId].pressed_button_, | 1311 current_pointer_state_[kRawMousePointerId].pressed_button_, |
1311 current_pointer_state_[kRawMousePointerId].current_buttons_, | 1312 current_pointer_state_[kRawMousePointerId].current_buttons_, |
1312 current_pointer_state_[kRawMousePointerId].last_pos_, | 1313 current_pointer_state_[kRawMousePointerId].last_pos_, |
1313 GetCurrentEventTimeSec(), click_count_, | 1314 GetCurrentEventTimeSec(), click_count_, |
1314 current_pointer_state_[kRawMousePointerId].modifiers_, &event); | 1315 current_pointer_state_[kRawMousePointerId].modifiers_, |
1315 WebPoint client_point(event.x, event.y); | 1316 &unscaled_event); |
1316 WebPoint screen_point(event.globalX, event.globalY); | 1317 |
| 1318 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); |
| 1319 const WebMouseEvent* event = |
| 1320 scaled_event.get() ? static_cast<WebMouseEvent*>(scaled_event.get()) |
| 1321 : &unscaled_event; |
| 1322 |
| 1323 WebPoint client_point(event->x, event->y); |
| 1324 WebPoint screen_point(event->globalX, event->globalY); |
1317 current_drag_data_ = drag_data; | 1325 current_drag_data_ = drag_data; |
1318 current_drag_effects_allowed_ = mask; | 1326 current_drag_effects_allowed_ = mask; |
1319 current_drag_effect_ = view()->dragTargetDragEnter( | 1327 current_drag_effect_ = view()->dragTargetDragEnter( |
1320 drag_data, client_point, screen_point, current_drag_effects_allowed_, | 1328 drag_data, client_point, screen_point, current_drag_effects_allowed_, |
1321 modifiersWithButtons( | 1329 modifiersWithButtons( |
1322 current_pointer_state_[kRawMousePointerId].modifiers_, | 1330 current_pointer_state_[kRawMousePointerId].modifiers_, |
1323 current_pointer_state_[kRawMousePointerId].current_buttons_)); | 1331 current_pointer_state_[kRawMousePointerId].current_buttons_)); |
1324 | 1332 |
1325 // Finish processing events. | 1333 // Finish processing events. |
1326 ReplaySavedEvents(); | 1334 ReplaySavedEvents(); |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1994 WebDragData::Item item; | 2002 WebDragData::Item item; |
1995 item.storageType = WebDragData::Item::StorageTypeFilename; | 2003 item.storageType = WebDragData::Item::StorageTypeFilename; |
1996 item.filenameData = delegate()->GetAbsoluteWebStringFromUTF8Path(files[i]); | 2004 item.filenameData = delegate()->GetAbsoluteWebStringFromUTF8Path(files[i]); |
1997 current_drag_data_.addItem(item); | 2005 current_drag_data_.addItem(item); |
1998 absolute_filenames[i] = item.filenameData; | 2006 absolute_filenames[i] = item.filenameData; |
1999 } | 2007 } |
2000 current_drag_data_.setFilesystemId( | 2008 current_drag_data_.setFilesystemId( |
2001 delegate()->RegisterIsolatedFileSystem(absolute_filenames)); | 2009 delegate()->RegisterIsolatedFileSystem(absolute_filenames)); |
2002 current_drag_effects_allowed_ = blink::WebDragOperationCopy; | 2010 current_drag_effects_allowed_ = blink::WebDragOperationCopy; |
2003 | 2011 |
| 2012 const WebPoint& last_pos = |
| 2013 current_pointer_state_[kRawMousePointerId].last_pos_; |
| 2014 float scale = delegate()->GetWindowToViewportScale(); |
| 2015 WebPoint scaled_last_pos(last_pos.x * scale, last_pos.y * scale); |
| 2016 |
2004 // Provide a drag source. | 2017 // Provide a drag source. |
2005 view()->dragTargetDragEnter( | 2018 view()->dragTargetDragEnter( |
2006 current_drag_data_, current_pointer_state_[kRawMousePointerId].last_pos_, | 2019 current_drag_data_, scaled_last_pos, scaled_last_pos, |
2007 current_pointer_state_[kRawMousePointerId].last_pos_, | |
2008 current_drag_effects_allowed_, 0); | 2020 current_drag_effects_allowed_, 0); |
2009 // |is_drag_mode_| saves events and then replays them later. We don't | 2021 // |is_drag_mode_| saves events and then replays them later. We don't |
2010 // need/want that. | 2022 // need/want that. |
2011 is_drag_mode_ = false; | 2023 is_drag_mode_ = false; |
2012 | 2024 |
2013 // Make the rest of eventSender think a drag is in progress. | 2025 // Make the rest of eventSender think a drag is in progress. |
2014 current_pointer_state_[kRawMousePointerId].pressed_button_ = | 2026 current_pointer_state_[kRawMousePointerId].pressed_button_ = |
2015 WebMouseEvent::ButtonLeft; | 2027 WebMouseEvent::ButtonLeft; |
2016 current_pointer_state_[kRawMousePointerId].current_buttons_ |= | 2028 current_pointer_state_[kRawMousePointerId].current_buttons_ |= |
2017 GetWebMouseEventModifierForButton( | 2029 GetWebMouseEventModifierForButton( |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2629 return; | 2641 return; |
2630 } | 2642 } |
2631 e->tiltX = tiltX; | 2643 e->tiltX = tiltX; |
2632 e->tiltY = tiltY; | 2644 e->tiltY = tiltY; |
2633 } | 2645 } |
2634 | 2646 |
2635 if (!getPointerType(args, false, e->pointerType)) | 2647 if (!getPointerType(args, false, e->pointerType)) |
2636 return; | 2648 return; |
2637 } | 2649 } |
2638 | 2650 |
2639 void EventSender::FinishDragAndDrop(const WebMouseEvent& e, | 2651 void EventSender::FinishDragAndDrop(const WebMouseEvent& unscaled_event, |
2640 blink::WebDragOperation drag_effect) { | 2652 blink::WebDragOperation drag_effect) { |
2641 WebPoint client_point(e.x, e.y); | 2653 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); |
2642 WebPoint screen_point(e.globalX, e.globalY); | 2654 const WebMouseEvent* event = |
| 2655 scaled_event.get() ? static_cast<const WebMouseEvent*>(scaled_event.get()) |
| 2656 : &unscaled_event; |
| 2657 |
| 2658 WebPoint client_point(event->x, event->y); |
| 2659 WebPoint screen_point(event->globalX, event->globalY); |
2643 current_drag_effect_ = drag_effect; | 2660 current_drag_effect_ = drag_effect; |
2644 if (current_drag_effect_) { | 2661 if (current_drag_effect_) { |
2645 // Specifically pass any keyboard modifiers to the drop method. This allows | 2662 // Specifically pass any keyboard modifiers to the drop method. This allows |
2646 // tests to control the drop type (i.e. copy or move). | 2663 // tests to control the drop type (i.e. copy or move). |
2647 view()->dragTargetDrop(current_drag_data_, client_point, screen_point, | 2664 view()->dragTargetDrop(current_drag_data_, client_point, screen_point, |
2648 e.modifiers); | 2665 event->modifiers); |
2649 } else { | 2666 } else { |
2650 view()->dragTargetDragLeave(); | 2667 view()->dragTargetDragLeave(); |
2651 } | 2668 } |
2652 view()->dragSourceEndedAt(client_point, screen_point, current_drag_effect_); | 2669 view()->dragSourceEndedAt(client_point, screen_point, current_drag_effect_); |
2653 view()->dragSourceSystemDragEnded(); | 2670 view()->dragSourceSystemDragEnded(); |
2654 | 2671 |
2655 current_drag_data_.reset(); | 2672 current_drag_data_.reset(); |
2656 } | 2673 } |
2657 | 2674 |
2658 void EventSender::DoDragAfterMouseUp(const WebMouseEvent& e) { | 2675 void EventSender::DoDragAfterMouseUp(const WebMouseEvent& unscaled_event) { |
2659 last_click_time_sec_ = e.timeStampSeconds; | 2676 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); |
| 2677 const WebMouseEvent* event = |
| 2678 scaled_event.get() ? static_cast<WebMouseEvent*>(scaled_event.get()) |
| 2679 : &unscaled_event; |
| 2680 |
| 2681 last_click_time_sec_ = event->timeStampSeconds; |
2660 last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_; | 2682 last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_; |
2661 | 2683 |
2662 // If we're in a drag operation, complete it. | 2684 // If we're in a drag operation, complete it. |
2663 if (current_drag_data_.isNull()) | 2685 if (current_drag_data_.isNull()) |
2664 return; | 2686 return; |
2665 | 2687 |
2666 WebPoint client_point(e.x, e.y); | 2688 WebPoint client_point(event->x, event->y); |
2667 WebPoint screen_point(e.globalX, e.globalY); | 2689 WebPoint screen_point(event->globalX, event->globalY); |
2668 blink::WebDragOperation drag_effect = view()->dragTargetDragOver( | 2690 blink::WebDragOperation drag_effect = view()->dragTargetDragOver( |
2669 client_point, screen_point, current_drag_effects_allowed_, e.modifiers); | 2691 client_point, screen_point, current_drag_effects_allowed_, |
| 2692 event->modifiers); |
2670 | 2693 |
2671 // Bail if dragover caused cancellation. | 2694 // Bail if dragover caused cancellation. |
2672 if (current_drag_data_.isNull()) | 2695 if (current_drag_data_.isNull()) |
2673 return; | 2696 return; |
2674 | 2697 |
2675 FinishDragAndDrop(e, drag_effect); | 2698 FinishDragAndDrop(unscaled_event, drag_effect); |
2676 } | 2699 } |
2677 | 2700 |
2678 void EventSender::DoDragAfterMouseMove(const WebMouseEvent& e) { | 2701 void EventSender::DoDragAfterMouseMove(const WebMouseEvent& unscaled_event) { |
2679 if (current_pointer_state_[kRawMousePointerId].pressed_button_ == | 2702 if (current_pointer_state_[kRawMousePointerId].pressed_button_ == |
2680 WebMouseEvent::ButtonNone || | 2703 WebMouseEvent::ButtonNone || |
2681 current_drag_data_.isNull()) { | 2704 current_drag_data_.isNull()) { |
2682 return; | 2705 return; |
2683 } | 2706 } |
2684 | 2707 |
2685 WebPoint client_point(e.x, e.y); | 2708 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); |
2686 WebPoint screen_point(e.globalX, e.globalY); | 2709 const WebMouseEvent* event = |
| 2710 scaled_event.get() ? static_cast<WebMouseEvent*>(scaled_event.get()) |
| 2711 : &unscaled_event; |
| 2712 |
| 2713 WebPoint client_point(event->x, event->y); |
| 2714 WebPoint screen_point(event->globalX, event->globalY); |
2687 current_drag_effect_ = view()->dragTargetDragOver( | 2715 current_drag_effect_ = view()->dragTargetDragOver( |
2688 client_point, screen_point, current_drag_effects_allowed_, e.modifiers); | 2716 client_point, screen_point, current_drag_effects_allowed_, |
| 2717 event->modifiers); |
2689 } | 2718 } |
2690 | 2719 |
2691 void EventSender::ReplaySavedEvents() { | 2720 void EventSender::ReplaySavedEvents() { |
2692 replaying_saved_events_ = true; | 2721 replaying_saved_events_ = true; |
2693 while (!mouse_event_queue_.empty()) { | 2722 while (!mouse_event_queue_.empty()) { |
2694 SavedEvent e = mouse_event_queue_.front(); | 2723 SavedEvent e = mouse_event_queue_.front(); |
2695 mouse_event_queue_.pop_front(); | 2724 mouse_event_queue_.pop_front(); |
2696 | 2725 |
2697 switch (e.type) { | 2726 switch (e.type) { |
2698 case SavedEvent::TYPE_MOUSE_MOVE: { | 2727 case SavedEvent::TYPE_MOUSE_MOVE: { |
(...skipping 30 matching lines...) Expand all Loading... |
2729 } | 2758 } |
2730 default: | 2759 default: |
2731 NOTREACHED(); | 2760 NOTREACHED(); |
2732 } | 2761 } |
2733 } | 2762 } |
2734 | 2763 |
2735 replaying_saved_events_ = false; | 2764 replaying_saved_events_ = false; |
2736 } | 2765 } |
2737 | 2766 |
2738 WebInputEventResult EventSender::HandleInputEventOnViewOrPopup( | 2767 WebInputEventResult EventSender::HandleInputEventOnViewOrPopup( |
2739 const WebInputEvent& event) { | 2768 const WebInputEvent& unscaled_event) { |
2740 last_event_timestamp_ = event.timeStampSeconds; | 2769 std::unique_ptr<WebInputEvent> scaled_event = ScaleEvent(unscaled_event); |
| 2770 const WebInputEvent* event = |
| 2771 scaled_event.get() ? scaled_event.get() : &unscaled_event; |
| 2772 |
| 2773 last_event_timestamp_ = event->timeStampSeconds; |
2741 | 2774 |
2742 if (WebPagePopup* popup = view()->pagePopup()) { | 2775 if (WebPagePopup* popup = view()->pagePopup()) { |
2743 if (!WebInputEvent::isKeyboardEventType(event.type)) | 2776 if (!WebInputEvent::isKeyboardEventType(event->type)) |
2744 return popup->handleInputEvent(event); | 2777 return popup->handleInputEvent(*event); |
2745 } | 2778 } |
2746 return view()->handleInputEvent(event); | 2779 return view()->handleInputEvent(*event); |
2747 } | 2780 } |
2748 | 2781 |
2749 void EventSender::SendGesturesForMouseWheelEvent( | 2782 void EventSender::SendGesturesForMouseWheelEvent( |
2750 const WebMouseWheelEvent wheel_event) { | 2783 const WebMouseWheelEvent wheel_event) { |
2751 WebGestureEvent begin_event; | 2784 WebGestureEvent begin_event; |
2752 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollBegin, | 2785 InitGestureEventFromMouseWheel(WebInputEvent::GestureScrollBegin, |
2753 GetCurrentEventTimeSec(), wheel_event, | 2786 GetCurrentEventTimeSec(), wheel_event, |
2754 &begin_event); | 2787 &begin_event); |
2755 begin_event.data.scrollBegin.deltaXHint = wheel_event.deltaX; | 2788 begin_event.data.scrollBegin.deltaXHint = wheel_event.deltaX; |
2756 begin_event.data.scrollBegin.deltaYHint = wheel_event.deltaY; | 2789 begin_event.data.scrollBegin.deltaYHint = wheel_event.deltaY; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2812 } | 2845 } |
2813 | 2846 |
2814 const blink::WebView* EventSender::view() const { | 2847 const blink::WebView* EventSender::view() const { |
2815 return web_test_proxy_base_->web_view(); | 2848 return web_test_proxy_base_->web_view(); |
2816 } | 2849 } |
2817 | 2850 |
2818 blink::WebView* EventSender::view() { | 2851 blink::WebView* EventSender::view() { |
2819 return web_test_proxy_base_->web_view(); | 2852 return web_test_proxy_base_->web_view(); |
2820 } | 2853 } |
2821 | 2854 |
| 2855 std::unique_ptr<WebInputEvent> EventSender::ScaleEvent( |
| 2856 const WebInputEvent& event) { |
| 2857 return ui::ScaleWebInputEvent(event, delegate()->GetWindowToViewportScale()); |
| 2858 } |
| 2859 |
2822 } // namespace test_runner | 2860 } // namespace test_runner |
OLD | NEW |