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

Side by Side Diff: webkit/tools/test_shell/event_sending_controller.cc

Issue 387002: Implement EventSender.mouseWheelTo method.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « webkit/tools/test_shell/event_sending_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // This file contains the definition for EventSendingController. 5 // This file contains the definition for EventSendingController.
6 // 6 //
7 // Some notes about drag and drop handling: 7 // Some notes about drag and drop handling:
8 // Windows drag and drop goes through a system call to DoDragDrop. At that 8 // Windows drag and drop goes through a system call to DoDragDrop. At that
9 // point, program control is given to Windows which then periodically makes 9 // point, program control is given to Windows which then periodically makes
10 // callbacks into the webview. This won't work for layout tests, so instead, 10 // callbacks into the webview. This won't work for layout tests, so instead,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // TODO(mpcomplete): do we need modifiers for mouse events? 49 // TODO(mpcomplete): do we need modifiers for mouse events?
50 50
51 using base::Time; 51 using base::Time;
52 using base::TimeTicks; 52 using base::TimeTicks;
53 using WebKit::WebDragOperation; 53 using WebKit::WebDragOperation;
54 using WebKit::WebDragOperationsMask; 54 using WebKit::WebDragOperationsMask;
55 using WebKit::WebDragData; 55 using WebKit::WebDragData;
56 using WebKit::WebInputEvent; 56 using WebKit::WebInputEvent;
57 using WebKit::WebKeyboardEvent; 57 using WebKit::WebKeyboardEvent;
58 using WebKit::WebMouseEvent; 58 using WebKit::WebMouseEvent;
59 using WebKit::WebMouseWheelEvent;
59 using WebKit::WebPoint; 60 using WebKit::WebPoint;
60 using WebKit::WebString; 61 using WebKit::WebString;
61 using WebKit::WebView; 62 using WebKit::WebView;
62 63
63 TestShell* EventSendingController::shell_ = NULL; 64 TestShell* EventSendingController::shell_ = NULL;
64 gfx::Point EventSendingController::last_mouse_pos_; 65 gfx::Point EventSendingController::last_mouse_pos_;
65 WebMouseEvent::Button EventSendingController::pressed_button_ = 66 WebMouseEvent::Button EventSendingController::pressed_button_ =
66 WebMouseEvent::ButtonNone; 67 WebMouseEvent::ButtonNone;
67 68
68 WebMouseEvent::Button EventSendingController::last_button_type_ = 69 WebMouseEvent::Button EventSendingController::last_button_type_ =
(...skipping 30 matching lines...) Expand all
99 // Time and place of the last mouse up event. 100 // Time and place of the last mouse up event.
100 static double last_click_time_sec = 0; 101 static double last_click_time_sec = 0;
101 static gfx::Point last_click_pos; 102 static gfx::Point last_click_pos;
102 static int click_count = 0; 103 static int click_count = 0;
103 104
104 // maximum distance (in space and time) for a mouse click 105 // maximum distance (in space and time) for a mouse click
105 // to register as a double or triple click 106 // to register as a double or triple click
106 static const double kMultiClickTimeSec = 1; 107 static const double kMultiClickTimeSec = 1;
107 static const int kMultiClickRadiusPixels = 5; 108 static const int kMultiClickRadiusPixels = 5;
108 109
110 // How much we should scroll per event - the value here is chosen to
111 // match the WebKit impl and layout test results.
112 static const float kScrollbarPixelsPerTick = 40.0f;
113
109 inline bool outside_multiclick_radius(const gfx::Point &a, const gfx::Point &b) { 114 inline bool outside_multiclick_radius(const gfx::Point &a, const gfx::Point &b) {
110 return ((a.x() - b.x()) * (a.x() - b.x()) + (a.y() - b.y()) * (a.y() - b.y())) > 115 return ((a.x() - b.x()) * (a.x() - b.x()) + (a.y() - b.y()) * (a.y() - b.y())) >
111 kMultiClickRadiusPixels * kMultiClickRadiusPixels; 116 kMultiClickRadiusPixels * kMultiClickRadiusPixels;
112 } 117 }
113 118
114 // Used to offset the time the event hander things an event happened. This is 119 // Used to offset the time the event hander things an event happened. This is
115 // done so tests can run without a delay, but bypass checks that are time 120 // done so tests can run without a delay, but bypass checks that are time
116 // dependent (e.g., dragging has a timeout vs selection). 121 // dependent (e.g., dragging has a timeout vs selection).
117 static uint32 time_offset_ms = 0; 122 static uint32 time_offset_ms = 0;
118 123
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 shell_ = shell; 181 shell_ = shell;
177 182
178 // Initialize the map that associates methods of this class with the names 183 // Initialize the map that associates methods of this class with the names
179 // they will use when called by JavaScript. The actual binding of those 184 // they will use when called by JavaScript. The actual binding of those
180 // names to their methods will be done by calling BindToJavaScript() (defined 185 // names to their methods will be done by calling BindToJavaScript() (defined
181 // by CppBoundClass, the parent to EventSendingController). 186 // by CppBoundClass, the parent to EventSendingController).
182 BindMethod("mouseDown", &EventSendingController::mouseDown); 187 BindMethod("mouseDown", &EventSendingController::mouseDown);
183 BindMethod("mouseUp", &EventSendingController::mouseUp); 188 BindMethod("mouseUp", &EventSendingController::mouseUp);
184 BindMethod("contextClick", &EventSendingController::contextClick); 189 BindMethod("contextClick", &EventSendingController::contextClick);
185 BindMethod("mouseMoveTo", &EventSendingController::mouseMoveTo); 190 BindMethod("mouseMoveTo", &EventSendingController::mouseMoveTo);
191 BindMethod("mouseWheelTo", &EventSendingController::mouseWheelTo);
186 BindMethod("leapForward", &EventSendingController::leapForward); 192 BindMethod("leapForward", &EventSendingController::leapForward);
187 BindMethod("keyDown", &EventSendingController::keyDown); 193 BindMethod("keyDown", &EventSendingController::keyDown);
188 BindMethod("dispatchMessage", &EventSendingController::dispatchMessage); 194 BindMethod("dispatchMessage", &EventSendingController::dispatchMessage);
189 BindMethod("enableDOMUIEventLogging", 195 BindMethod("enableDOMUIEventLogging",
190 &EventSendingController::enableDOMUIEventLogging); 196 &EventSendingController::enableDOMUIEventLogging);
191 BindMethod("fireKeyboardEventsToElement", 197 BindMethod("fireKeyboardEventsToElement",
192 &EventSendingController::fireKeyboardEventsToElement); 198 &EventSendingController::fireKeyboardEventsToElement);
193 BindMethod("clearKillRing", &EventSendingController::clearKillRing); 199 BindMethod("clearKillRing", &EventSendingController::clearKillRing);
194 BindMethod("textZoomIn", &EventSendingController::textZoomIn); 200 BindMethod("textZoomIn", &EventSendingController::textZoomIn);
195 BindMethod("textZoomOut", &EventSendingController::textZoomOut); 201 BindMethod("textZoomOut", &EventSendingController::textZoomOut);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 mouse_event_queue.push(saved_event); 402 mouse_event_queue.push(saved_event);
397 } else { 403 } else {
398 WebMouseEvent event; 404 WebMouseEvent event;
399 InitMouseEvent(WebInputEvent::MouseMove, pressed_button_, 405 InitMouseEvent(WebInputEvent::MouseMove, pressed_button_,
400 mouse_pos, &event); 406 mouse_pos, &event);
401 DoMouseMove(event); 407 DoMouseMove(event);
402 } 408 }
403 } 409 }
404 } 410 }
405 411
412 void EventSendingController::mouseWheelTo(
413 const CppArgumentList& args, CppVariant* result) {
414 result->SetNull();
415
416 if (args.size() >= 2 && args[0].isNumber() && args[1].isNumber()) {
417 // Force a layout here just to make sure every position has been
418 // determined before we send events (as well as all the other methods
419 // that send an event do). The layout test calling this
420 // (scrollbars/overflow-scrollbar-horizontal-wheel-scroll.html, only one
421 // for now) does not rely on this though.
422 webview()->layout();
423
424 int horizontal = args[0].ToInt32();
425 int vertical = args[1].ToInt32();
426
427 WebMouseWheelEvent event;
428 InitMouseEvent(WebInputEvent::MouseWheel, pressed_button_,
429 last_mouse_pos_, &event);
430 event.wheelTicksX = static_cast<float>(horizontal);
431 event.wheelTicksY = static_cast<float>(vertical);
432 event.deltaX = -horizontal * kScrollbarPixelsPerTick;
433 event.deltaY = -vertical * kScrollbarPixelsPerTick;
434 webview()->handleInputEvent(event);
435 }
436 }
437
406 // static 438 // static
407 void EventSendingController::DoMouseMove(const WebMouseEvent& e) { 439 void EventSendingController::DoMouseMove(const WebMouseEvent& e) {
408 last_mouse_pos_.SetPoint(e.x, e.y); 440 last_mouse_pos_.SetPoint(e.x, e.y);
409 441
410 webview()->handleInputEvent(e); 442 webview()->handleInputEvent(e);
411 443
412 if (pressed_button_ != WebMouseEvent::ButtonNone && 444 if (pressed_button_ != WebMouseEvent::ButtonNone &&
413 !current_drag_data.isNull()) { 445 !current_drag_data.isNull()) {
414 WebPoint client_point(e.x, e.y); 446 WebPoint client_point(e.x, e.y);
415 WebPoint screen_point(e.globalX, e.globalY); 447 WebPoint screen_point(e.globalX, e.globalY);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 750
719 void EventSendingController::fireKeyboardEventsToElement( 751 void EventSendingController::fireKeyboardEventsToElement(
720 const CppArgumentList& args, CppVariant* result) { 752 const CppArgumentList& args, CppVariant* result) {
721 result->SetNull(); 753 result->SetNull();
722 } 754 }
723 755
724 void EventSendingController::clearKillRing( 756 void EventSendingController::clearKillRing(
725 const CppArgumentList& args, CppVariant* result) { 757 const CppArgumentList& args, CppVariant* result) {
726 result->SetNull(); 758 result->SetNull();
727 } 759 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/event_sending_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698