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

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

Issue 2485693003: Drag-and-drop: DragEnter, DragOver, DragLeave, DragDrop (Closed)
Patch Set: Rebased. More fixes. Created 4 years, 1 month 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
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> 9 #include <memory>
10 10
(...skipping 13 matching lines...) Expand all
24 #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" 25 #include "components/test_runner/web_widget_test_proxy.h"
26 #include "gin/handle.h" 26 #include "gin/handle.h"
27 #include "gin/object_template_builder.h" 27 #include "gin/object_template_builder.h"
28 #include "gin/wrappable.h" 28 #include "gin/wrappable.h"
29 #include "third_party/WebKit/public/platform/WebInputEvent.h" 29 #include "third_party/WebKit/public/platform/WebInputEvent.h"
30 #include "third_party/WebKit/public/platform/WebPointerProperties.h" 30 #include "third_party/WebKit/public/platform/WebPointerProperties.h"
31 #include "third_party/WebKit/public/platform/WebString.h" 31 #include "third_party/WebKit/public/platform/WebString.h"
32 #include "third_party/WebKit/public/platform/WebVector.h" 32 #include "third_party/WebKit/public/platform/WebVector.h"
33 #include "third_party/WebKit/public/web/WebContextMenuData.h" 33 #include "third_party/WebKit/public/web/WebContextMenuData.h"
34 #include "third_party/WebKit/public/web/WebFrameWidget.h"
34 #include "third_party/WebKit/public/web/WebKit.h" 35 #include "third_party/WebKit/public/web/WebKit.h"
35 #include "third_party/WebKit/public/web/WebLocalFrame.h" 36 #include "third_party/WebKit/public/web/WebLocalFrame.h"
36 #include "third_party/WebKit/public/web/WebPagePopup.h" 37 #include "third_party/WebKit/public/web/WebPagePopup.h"
37 #include "third_party/WebKit/public/web/WebView.h" 38 #include "third_party/WebKit/public/web/WebView.h"
38 #include "ui/events/blink/blink_event_util.h" 39 #include "ui/events/blink/blink_event_util.h"
39 #include "ui/events/keycodes/dom/keycode_converter.h" 40 #include "ui/events/keycodes/dom/keycode_converter.h"
40 #include "ui/events/keycodes/keyboard_codes.h" 41 #include "ui/events/keycodes/keyboard_codes.h"
41 #include "v8/include/v8.h" 42 #include "v8/include/v8.h"
42 43
43 using blink::WebContextMenuData; 44 using blink::WebContextMenuData;
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 std::unique_ptr<WebInputEvent> widget_event = 1357 std::unique_ptr<WebInputEvent> widget_event =
1357 TransformScreenToWidgetCoordinates(raw_event); 1358 TransformScreenToWidgetCoordinates(raw_event);
1358 const WebMouseEvent* event = 1359 const WebMouseEvent* event =
1359 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) 1360 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
1360 : &raw_event; 1361 : &raw_event;
1361 1362
1362 WebPoint client_point(event->x, event->y); 1363 WebPoint client_point(event->x, event->y);
1363 WebPoint screen_point(event->globalX, event->globalY); 1364 WebPoint screen_point(event->globalX, event->globalY);
1364 current_drag_data_ = drag_data; 1365 current_drag_data_ = drag_data;
1365 current_drag_effects_allowed_ = mask; 1366 current_drag_effects_allowed_ = mask;
1366 current_drag_effect_ = view()->dragTargetDragEnter( 1367 current_drag_effect_ = mainFrameWidget()->dragTargetDragEnter(
1367 drag_data, client_point, screen_point, current_drag_effects_allowed_, 1368 drag_data, client_point, screen_point, current_drag_effects_allowed_,
1368 modifiersWithButtons( 1369 modifiersWithButtons(
1369 current_pointer_state_[kRawMousePointerId].modifiers_, 1370 current_pointer_state_[kRawMousePointerId].modifiers_,
1370 current_pointer_state_[kRawMousePointerId].current_buttons_)); 1371 current_pointer_state_[kRawMousePointerId].current_buttons_));
1371 1372
1372 // Finish processing events. 1373 // Finish processing events.
1373 ReplaySavedEvents(); 1374 ReplaySavedEvents();
1374 } 1375 }
1375 1376
1376 void EventSender::MouseDown(int button_number, int modifiers) { 1377 void EventSender::MouseDown(int button_number, int modifiers) {
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 current_drag_data_.setFilesystemId( 2031 current_drag_data_.setFilesystemId(
2031 delegate()->RegisterIsolatedFileSystem(absolute_filenames)); 2032 delegate()->RegisterIsolatedFileSystem(absolute_filenames));
2032 current_drag_effects_allowed_ = blink::WebDragOperationCopy; 2033 current_drag_effects_allowed_ = blink::WebDragOperationCopy;
2033 2034
2034 const WebPoint& last_pos = 2035 const WebPoint& last_pos =
2035 current_pointer_state_[kRawMousePointerId].last_pos_; 2036 current_pointer_state_[kRawMousePointerId].last_pos_;
2036 float scale = delegate()->GetWindowToViewportScale(); 2037 float scale = delegate()->GetWindowToViewportScale();
2037 WebPoint scaled_last_pos(last_pos.x * scale, last_pos.y * scale); 2038 WebPoint scaled_last_pos(last_pos.x * scale, last_pos.y * scale);
2038 2039
2039 // Provide a drag source. 2040 // Provide a drag source.
2040 view()->dragTargetDragEnter( 2041 mainFrameWidget()->dragTargetDragEnter(
2041 current_drag_data_, scaled_last_pos, scaled_last_pos, 2042 current_drag_data_, scaled_last_pos, scaled_last_pos,
2042 current_drag_effects_allowed_, 0); 2043 current_drag_effects_allowed_, 0);
2043 // |is_drag_mode_| saves events and then replays them later. We don't 2044 // |is_drag_mode_| saves events and then replays them later. We don't
2044 // need/want that. 2045 // need/want that.
2045 is_drag_mode_ = false; 2046 is_drag_mode_ = false;
2046 2047
2047 // Make the rest of eventSender think a drag is in progress. 2048 // Make the rest of eventSender think a drag is in progress.
2048 current_pointer_state_[kRawMousePointerId].pressed_button_ = 2049 current_pointer_state_[kRawMousePointerId].pressed_button_ =
2049 WebMouseEvent::Button::Left; 2050 WebMouseEvent::Button::Left;
2050 current_pointer_state_[kRawMousePointerId].current_buttons_ |= 2051 current_pointer_state_[kRawMousePointerId].current_buttons_ |=
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 const WebMouseEvent* event = 2685 const WebMouseEvent* event =
2685 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) 2686 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2686 : &raw_event; 2687 : &raw_event;
2687 2688
2688 WebPoint client_point(event->x, event->y); 2689 WebPoint client_point(event->x, event->y);
2689 WebPoint screen_point(event->globalX, event->globalY); 2690 WebPoint screen_point(event->globalX, event->globalY);
2690 current_drag_effect_ = drag_effect; 2691 current_drag_effect_ = drag_effect;
2691 if (current_drag_effect_) { 2692 if (current_drag_effect_) {
2692 // Specifically pass any keyboard modifiers to the drop method. This allows 2693 // Specifically pass any keyboard modifiers to the drop method. This allows
2693 // tests to control the drop type (i.e. copy or move). 2694 // tests to control the drop type (i.e. copy or move).
2694 view()->dragTargetDrop(current_drag_data_, client_point, screen_point, 2695 mainFrameWidget()->dragTargetDrop(current_drag_data_, client_point,
2695 event->modifiers); 2696 screen_point, event->modifiers);
2696 } else { 2697 } else {
2697 view()->dragTargetDragLeave(); 2698 mainFrameWidget()->dragTargetDragLeave();
2698 } 2699 }
2699 current_drag_data_.reset(); 2700 current_drag_data_.reset();
2700 view()->dragSourceEndedAt(client_point, screen_point, current_drag_effect_); 2701 view()->dragSourceEndedAt(client_point, screen_point, current_drag_effect_);
2701 view()->dragSourceSystemDragEnded(); 2702 view()->dragSourceSystemDragEnded();
2702 } 2703 }
2703 2704
2704 void EventSender::DoDragAfterMouseUp(const WebMouseEvent& raw_event) { 2705 void EventSender::DoDragAfterMouseUp(const WebMouseEvent& raw_event) {
2705 std::unique_ptr<WebInputEvent> widget_event = 2706 std::unique_ptr<WebInputEvent> widget_event =
2706 TransformScreenToWidgetCoordinates(raw_event); 2707 TransformScreenToWidgetCoordinates(raw_event);
2707 const WebMouseEvent* event = 2708 const WebMouseEvent* event =
2708 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) 2709 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2709 : &raw_event; 2710 : &raw_event;
2710 2711
2711 last_click_time_sec_ = event->timeStampSeconds; 2712 last_click_time_sec_ = event->timeStampSeconds;
2712 last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_; 2713 last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_;
2713 2714
2714 // If we're in a drag operation, complete it. 2715 // If we're in a drag operation, complete it.
2715 if (current_drag_data_.isNull()) 2716 if (current_drag_data_.isNull())
2716 return; 2717 return;
2717 2718
2718 WebPoint client_point(event->x, event->y); 2719 WebPoint client_point(event->x, event->y);
2719 WebPoint screen_point(event->globalX, event->globalY); 2720 WebPoint screen_point(event->globalX, event->globalY);
2720 blink::WebDragOperation drag_effect = view()->dragTargetDragOver( 2721 blink::WebDragOperation drag_effect = mainFrameWidget()->dragTargetDragOver(
2721 client_point, screen_point, current_drag_effects_allowed_, 2722 client_point, screen_point, current_drag_effects_allowed_,
2722 event->modifiers); 2723 event->modifiers);
2723 2724
2724 // Bail if dragover caused cancellation. 2725 // Bail if dragover caused cancellation.
2725 if (current_drag_data_.isNull()) 2726 if (current_drag_data_.isNull())
2726 return; 2727 return;
2727 2728
2728 FinishDragAndDrop(raw_event, drag_effect); 2729 FinishDragAndDrop(raw_event, drag_effect);
2729 } 2730 }
2730 2731
2731 void EventSender::DoDragAfterMouseMove(const WebMouseEvent& raw_event) { 2732 void EventSender::DoDragAfterMouseMove(const WebMouseEvent& raw_event) {
2732 if (current_pointer_state_[kRawMousePointerId].pressed_button_ == 2733 if (current_pointer_state_[kRawMousePointerId].pressed_button_ ==
2733 WebMouseEvent::Button::NoButton || 2734 WebMouseEvent::Button::NoButton ||
2734 current_drag_data_.isNull()) { 2735 current_drag_data_.isNull()) {
2735 return; 2736 return;
2736 } 2737 }
2737 2738
2738 std::unique_ptr<WebInputEvent> widget_event = 2739 std::unique_ptr<WebInputEvent> widget_event =
2739 TransformScreenToWidgetCoordinates(raw_event); 2740 TransformScreenToWidgetCoordinates(raw_event);
2740 const WebMouseEvent* event = 2741 const WebMouseEvent* event =
2741 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) 2742 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2742 : &raw_event; 2743 : &raw_event;
2743 2744
2744 WebPoint client_point(event->x, event->y); 2745 WebPoint client_point(event->x, event->y);
2745 WebPoint screen_point(event->globalX, event->globalY); 2746 WebPoint screen_point(event->globalX, event->globalY);
2746 current_drag_effect_ = view()->dragTargetDragOver( 2747 current_drag_effect_ = mainFrameWidget()->dragTargetDragOver(
2747 client_point, screen_point, current_drag_effects_allowed_, 2748 client_point, screen_point, current_drag_effects_allowed_,
2748 event->modifiers); 2749 event->modifiers);
2749 } 2750 }
2750 2751
2751 void EventSender::ReplaySavedEvents() { 2752 void EventSender::ReplaySavedEvents() {
2752 replaying_saved_events_ = true; 2753 replaying_saved_events_ = true;
2753 while (!mouse_event_queue_.empty()) { 2754 while (!mouse_event_queue_.empty()) {
2754 SavedEvent e = mouse_event_queue_.front(); 2755 SavedEvent e = mouse_event_queue_.front();
2755 mouse_event_queue_.pop_front(); 2756 mouse_event_queue_.pop_front();
2756 2757
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2889 } 2890 }
2890 2891
2891 blink::WebView* EventSender::view() { 2892 blink::WebView* EventSender::view() {
2892 return web_widget_test_proxy_base_->web_view_test_proxy_base()->web_view(); 2893 return web_widget_test_proxy_base_->web_view_test_proxy_base()->web_view();
2893 } 2894 }
2894 2895
2895 blink::WebWidget* EventSender::widget() { 2896 blink::WebWidget* EventSender::widget() {
2896 return web_widget_test_proxy_base_->web_widget(); 2897 return web_widget_test_proxy_base_->web_widget();
2897 } 2898 }
2898 2899
2900 blink::WebFrameWidget* EventSender::mainFrameWidget() {
2901 return view()->mainFrame()->toWebLocalFrame()->frameWidget();
2902 }
2903
2899 std::unique_ptr<WebInputEvent> EventSender::TransformScreenToWidgetCoordinates( 2904 std::unique_ptr<WebInputEvent> EventSender::TransformScreenToWidgetCoordinates(
2900 const WebInputEvent& event) { 2905 const WebInputEvent& event) {
2901 return delegate()->TransformScreenToWidgetCoordinates( 2906 return delegate()->TransformScreenToWidgetCoordinates(
2902 web_widget_test_proxy_base_, event); 2907 web_widget_test_proxy_base_, event);
2903 } 2908 }
2904 2909
2905 } // namespace test_runner 2910 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/event_sender.h ('k') | content/browser/browser_plugin/browser_plugin_guest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698