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

Side by Side Diff: content/shell/test_runner/event_sender.cc

Issue 2782893002: WebMouseEvent coordinates are now fractional & private (Closed)
Patch Set: Fixed a compile failure Created 3 years, 8 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
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 "content/shell/test_runner/event_sender.h" 5 #include "content/shell/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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 int current_buttons, 210 int current_buttons,
211 const WebPoint& pos, 211 const WebPoint& pos,
212 int click_count, 212 int click_count,
213 WebPointerProperties::PointerType pointerType, 213 WebPointerProperties::PointerType pointerType,
214 int pointerId, 214 int pointerId,
215 float pressure, 215 float pressure,
216 int tiltX, 216 int tiltX,
217 int tiltY, 217 int tiltY,
218 WebMouseEvent* e) { 218 WebMouseEvent* e) {
219 e->button = b; 219 e->button = b;
220 e->x = pos.x; 220 e->setPositionInWidget(pos.x, pos.y);
221 e->y = pos.y; 221 e->setPositionInScreen(pos.x, pos.y);
222 e->globalX = pos.x;
223 e->globalY = pos.y;
224 e->pointerType = pointerType; 222 e->pointerType = pointerType;
225 e->id = pointerId; 223 e->id = pointerId;
226 e->force = pressure; 224 e->force = pressure;
227 e->tiltX = tiltX; 225 e->tiltX = tiltX;
228 e->tiltY = tiltY; 226 e->tiltY = tiltY;
229 e->clickCount = click_count; 227 e->clickCount = click_count;
230 } 228 }
231 229
232 void InitMouseEvent(WebMouseEvent::Button b, 230 void InitMouseEvent(WebMouseEvent::Button b,
233 int current_buttons, 231 int current_buttons,
234 const WebPoint& pos, 232 const WebPoint& pos,
235 int click_count, 233 int click_count,
236 WebMouseEvent* e) { 234 WebMouseEvent* e) {
237 InitMouseEventGeneric(b, current_buttons, pos, click_count, 235 InitMouseEventGeneric(b, current_buttons, pos, click_count,
238 WebPointerProperties::PointerType::Mouse, 0, 0.0, 0, 0, 236 WebPointerProperties::PointerType::Mouse, 0, 0.0, 0, 0,
239 e); 237 e);
240 } 238 }
241 239
242 void InitGestureEventFromMouseWheel(const WebMouseWheelEvent& wheel_event, 240 void InitGestureEventFromMouseWheel(const WebMouseWheelEvent& wheel_event,
243 WebGestureEvent* gesture_event) { 241 WebGestureEvent* gesture_event) {
244 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad; 242 gesture_event->sourceDevice = blink::WebGestureDeviceTouchpad;
245 gesture_event->x = wheel_event.x; 243 gesture_event->x = wheel_event.positionInWidget().x;
246 gesture_event->y = wheel_event.y; 244 gesture_event->y = wheel_event.positionInWidget().y;
247 gesture_event->globalX = wheel_event.globalX; 245 gesture_event->globalX = wheel_event.positionInScreen().x;
248 gesture_event->globalY = wheel_event.globalY; 246 gesture_event->globalY = wheel_event.positionInScreen().y;
249 } 247 }
250 248
251 int GetKeyModifier(const std::string& modifier_name) { 249 int GetKeyModifier(const std::string& modifier_name) {
252 const char* characters = modifier_name.c_str(); 250 const char* characters = modifier_name.c_str();
253 if (!strcmp(characters, "ctrlKey") 251 if (!strcmp(characters, "ctrlKey")
254 #ifndef __APPLE__ 252 #ifndef __APPLE__
255 || !strcmp(characters, "addSelectionKey") 253 || !strcmp(characters, "addSelectionKey")
256 #endif 254 #endif
257 ) { 255 ) {
258 return WebInputEvent::ControlKey; 256 return WebInputEvent::ControlKey;
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 current_pointer_state_[kRawMousePointerId].current_buttons_, 1341 current_pointer_state_[kRawMousePointerId].current_buttons_,
1344 current_pointer_state_[kRawMousePointerId].last_pos_, 1342 current_pointer_state_[kRawMousePointerId].last_pos_,
1345 click_count_, &raw_event); 1343 click_count_, &raw_event);
1346 1344
1347 std::unique_ptr<WebInputEvent> widget_event = 1345 std::unique_ptr<WebInputEvent> widget_event =
1348 TransformScreenToWidgetCoordinates(raw_event); 1346 TransformScreenToWidgetCoordinates(raw_event);
1349 const WebMouseEvent* event = 1347 const WebMouseEvent* event =
1350 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) 1348 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
1351 : &raw_event; 1349 : &raw_event;
1352 1350
1353 WebPoint client_point(event->x, event->y); 1351 WebPoint client_point(event->positionInWidget().x,
1354 WebPoint screen_point(event->globalX, event->globalY); 1352 event->positionInWidget().y);
1353 WebPoint screen_point(event->positionInScreen().x,
1354 event->positionInScreen().y);
1355 current_drag_data_ = drag_data; 1355 current_drag_data_ = drag_data;
1356 current_drag_effects_allowed_ = mask; 1356 current_drag_effects_allowed_ = mask;
1357 current_drag_effect_ = mainFrameWidget()->dragTargetDragEnter( 1357 current_drag_effect_ = mainFrameWidget()->dragTargetDragEnter(
1358 drag_data, client_point, screen_point, current_drag_effects_allowed_, 1358 drag_data, client_point, screen_point, current_drag_effects_allowed_,
1359 modifiersWithButtons( 1359 modifiersWithButtons(
1360 current_pointer_state_[kRawMousePointerId].modifiers_, 1360 current_pointer_state_[kRawMousePointerId].modifiers_,
1361 current_pointer_state_[kRawMousePointerId].current_buttons_)); 1361 current_pointer_state_[kRawMousePointerId].current_buttons_));
1362 1362
1363 // Finish processing events. 1363 // Finish processing events.
1364 ReplaySavedEvents(); 1364 ReplaySavedEvents();
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after
2652 } 2652 }
2653 2653
2654 void EventSender::FinishDragAndDrop(const WebMouseEvent& raw_event, 2654 void EventSender::FinishDragAndDrop(const WebMouseEvent& raw_event,
2655 blink::WebDragOperation drag_effect) { 2655 blink::WebDragOperation drag_effect) {
2656 std::unique_ptr<WebInputEvent> widget_event = 2656 std::unique_ptr<WebInputEvent> widget_event =
2657 TransformScreenToWidgetCoordinates(raw_event); 2657 TransformScreenToWidgetCoordinates(raw_event);
2658 const WebMouseEvent* event = 2658 const WebMouseEvent* event =
2659 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) 2659 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2660 : &raw_event; 2660 : &raw_event;
2661 2661
2662 WebPoint client_point(event->x, event->y); 2662 WebPoint client_point(event->positionInWidget().x,
2663 WebPoint screen_point(event->globalX, event->globalY); 2663 event->positionInWidget().y);
2664 WebPoint screen_point(event->positionInScreen().x,
2665 event->positionInScreen().y);
2664 current_drag_effect_ = drag_effect; 2666 current_drag_effect_ = drag_effect;
2665 if (current_drag_effect_) { 2667 if (current_drag_effect_) {
2666 // Specifically pass any keyboard modifiers to the drop method. This allows 2668 // Specifically pass any keyboard modifiers to the drop method. This allows
2667 // tests to control the drop type (i.e. copy or move). 2669 // tests to control the drop type (i.e. copy or move).
2668 mainFrameWidget()->dragTargetDrop(current_drag_data_, client_point, 2670 mainFrameWidget()->dragTargetDrop(current_drag_data_, client_point,
2669 screen_point, event->modifiers()); 2671 screen_point, event->modifiers());
2670 } else { 2672 } else {
2671 mainFrameWidget()->dragTargetDragLeave(blink::WebPoint(), 2673 mainFrameWidget()->dragTargetDragLeave(blink::WebPoint(),
2672 blink::WebPoint()); 2674 blink::WebPoint());
2673 } 2675 }
(...skipping 10 matching lines...) Expand all
2684 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) 2686 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2685 : &raw_event; 2687 : &raw_event;
2686 2688
2687 last_click_time_sec_ = event->timeStampSeconds(); 2689 last_click_time_sec_ = event->timeStampSeconds();
2688 last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_; 2690 last_click_pos_ = current_pointer_state_[kRawMousePointerId].last_pos_;
2689 2691
2690 // If we're in a drag operation, complete it. 2692 // If we're in a drag operation, complete it.
2691 if (current_drag_data_.isNull()) 2693 if (current_drag_data_.isNull())
2692 return; 2694 return;
2693 2695
2694 WebPoint client_point(event->x, event->y); 2696 WebPoint client_point(event->positionInWidget().x,
2695 WebPoint screen_point(event->globalX, event->globalY); 2697 event->positionInWidget().y);
2698 WebPoint screen_point(event->positionInScreen().x,
2699 event->positionInScreen().y);
2696 blink::WebDragOperation drag_effect = mainFrameWidget()->dragTargetDragOver( 2700 blink::WebDragOperation drag_effect = mainFrameWidget()->dragTargetDragOver(
2697 client_point, screen_point, current_drag_effects_allowed_, 2701 client_point, screen_point, current_drag_effects_allowed_,
2698 event->modifiers()); 2702 event->modifiers());
2699 2703
2700 // Bail if dragover caused cancellation. 2704 // Bail if dragover caused cancellation.
2701 if (current_drag_data_.isNull()) 2705 if (current_drag_data_.isNull())
2702 return; 2706 return;
2703 2707
2704 FinishDragAndDrop(raw_event, drag_effect); 2708 FinishDragAndDrop(raw_event, drag_effect);
2705 } 2709 }
2706 2710
2707 void EventSender::DoDragAfterMouseMove(const WebMouseEvent& raw_event) { 2711 void EventSender::DoDragAfterMouseMove(const WebMouseEvent& raw_event) {
2708 if (current_pointer_state_[kRawMousePointerId].pressed_button_ == 2712 if (current_pointer_state_[kRawMousePointerId].pressed_button_ ==
2709 WebMouseEvent::Button::NoButton || 2713 WebMouseEvent::Button::NoButton ||
2710 current_drag_data_.isNull()) { 2714 current_drag_data_.isNull()) {
2711 return; 2715 return;
2712 } 2716 }
2713 2717
2714 std::unique_ptr<WebInputEvent> widget_event = 2718 std::unique_ptr<WebInputEvent> widget_event =
2715 TransformScreenToWidgetCoordinates(raw_event); 2719 TransformScreenToWidgetCoordinates(raw_event);
2716 const WebMouseEvent* event = 2720 const WebMouseEvent* event =
2717 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get()) 2721 widget_event.get() ? static_cast<WebMouseEvent*>(widget_event.get())
2718 : &raw_event; 2722 : &raw_event;
2719 2723
2720 WebPoint client_point(event->x, event->y); 2724 WebPoint client_point(event->positionInWidget().x,
2721 WebPoint screen_point(event->globalX, event->globalY); 2725 event->positionInWidget().y);
2726 WebPoint screen_point(event->positionInScreen().x,
2727 event->positionInScreen().y);
2722 current_drag_effect_ = mainFrameWidget()->dragTargetDragOver( 2728 current_drag_effect_ = mainFrameWidget()->dragTargetDragOver(
2723 client_point, screen_point, current_drag_effects_allowed_, 2729 client_point, screen_point, current_drag_effects_allowed_,
2724 event->modifiers()); 2730 event->modifiers());
2725 } 2731 }
2726 2732
2727 void EventSender::ReplaySavedEvents() { 2733 void EventSender::ReplaySavedEvents() {
2728 replaying_saved_events_ = true; 2734 replaying_saved_events_ = true;
2729 while (!mouse_event_queue_.empty()) { 2735 while (!mouse_event_queue_.empty()) {
2730 SavedEvent e = mouse_event_queue_.front(); 2736 SavedEvent e = mouse_event_queue_.front();
2731 mouse_event_queue_.pop_front(); 2737 mouse_event_queue_.pop_front();
2732 2738
2733 switch (e.type) { 2739 switch (e.type) {
2734 case SavedEvent::TYPE_MOUSE_MOVE: { 2740 case SavedEvent::TYPE_MOUSE_MOVE: {
2735 current_pointer_state_[kRawMousePointerId].modifiers_ = e.modifiers; 2741 current_pointer_state_[kRawMousePointerId].modifiers_ = e.modifiers;
2736 WebMouseEvent event(WebInputEvent::MouseMove, 2742 WebMouseEvent event(WebInputEvent::MouseMove,
2737 ModifiersForPointer(kRawMousePointerId), 2743 ModifiersForPointer(kRawMousePointerId),
2738 GetCurrentEventTimeSec()); 2744 GetCurrentEventTimeSec());
2739 InitMouseEvent( 2745 InitMouseEvent(
2740 current_pointer_state_[kRawMousePointerId].pressed_button_, 2746 current_pointer_state_[kRawMousePointerId].pressed_button_,
2741 current_pointer_state_[kRawMousePointerId].current_buttons_, e.pos, 2747 current_pointer_state_[kRawMousePointerId].current_buttons_, e.pos,
2742 click_count_, &event); 2748 click_count_, &event);
2743 current_pointer_state_[kRawMousePointerId].last_pos_ = 2749 current_pointer_state_[kRawMousePointerId].last_pos_ =
2744 WebPoint(event.x, event.y); 2750 WebPoint(event.positionInWidget().x, event.positionInWidget().y);
2745 HandleInputEventOnViewOrPopup(event); 2751 HandleInputEventOnViewOrPopup(event);
2746 DoDragAfterMouseMove(event); 2752 DoDragAfterMouseMove(event);
2747 break; 2753 break;
2748 } 2754 }
2749 case SavedEvent::TYPE_LEAP_FORWARD: 2755 case SavedEvent::TYPE_LEAP_FORWARD:
2750 DoLeapForward(e.milliseconds); 2756 DoLeapForward(e.milliseconds);
2751 break; 2757 break;
2752 case SavedEvent::TYPE_MOUSE_UP: { 2758 case SavedEvent::TYPE_MOUSE_UP: {
2753 current_pointer_state_[kRawMousePointerId].current_buttons_ &= 2759 current_pointer_state_[kRawMousePointerId].current_buttons_ &=
2754 ~GetWebMouseEventModifierForButton(e.button_type); 2760 ~GetWebMouseEventModifierForButton(e.button_type);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2881 return view()->mainFrame()->toWebLocalFrame()->frameWidget(); 2887 return view()->mainFrame()->toWebLocalFrame()->frameWidget();
2882 } 2888 }
2883 2889
2884 std::unique_ptr<WebInputEvent> EventSender::TransformScreenToWidgetCoordinates( 2890 std::unique_ptr<WebInputEvent> EventSender::TransformScreenToWidgetCoordinates(
2885 const WebInputEvent& event) { 2891 const WebInputEvent& event) {
2886 return delegate()->TransformScreenToWidgetCoordinates( 2892 return delegate()->TransformScreenToWidgetCoordinates(
2887 web_widget_test_proxy_base_, event); 2893 web_widget_test_proxy_base_, event);
2888 } 2894 }
2889 2895
2890 } // namespace test_runner 2896 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698