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

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

Issue 266076: Fix EventSendingController so that we do event saving and replay like what We... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 TestShell* EventSendingController::shell_ = NULL; 62 TestShell* EventSendingController::shell_ = NULL;
63 gfx::Point EventSendingController::last_mouse_pos_; 63 gfx::Point EventSendingController::last_mouse_pos_;
64 WebMouseEvent::Button EventSendingController::pressed_button_ = 64 WebMouseEvent::Button EventSendingController::pressed_button_ =
65 WebMouseEvent::ButtonNone; 65 WebMouseEvent::ButtonNone;
66 66
67 int EventSendingController::last_button_number_ = -1; 67 int EventSendingController::last_button_number_ = -1;
68 68
69 namespace { 69 namespace {
70 70
71 struct SavedEvent {
72 enum SavedEventType {
73 Unspecified,
74 MouseUp,
75 MouseMove,
76 LeapForward
77 };
78
79 SavedEventType type;
80 WebMouseEvent::Button button_type; // For MouseUp
81 gfx::Point pos; // For MouseMove.
82 int milliseconds; // For LeapForward.
83
84 SavedEvent()
85 : type(Unspecified),
86 button_type(WebMouseEvent::ButtonNone),
87 milliseconds(0) {
88 }
89 };
90
71 static WebDragData current_drag_data; 91 static WebDragData current_drag_data;
72 static WebDragOperation current_drag_effect; 92 static WebDragOperation current_drag_effect;
73 static WebDragOperationsMask current_drag_effects_allowed; 93 static WebDragOperationsMask current_drag_effects_allowed;
74 static bool replaying_saved_events = false; 94 static bool replaying_saved_events = false;
75 static std::queue<WebMouseEvent> mouse_event_queue; 95 static std::queue<SavedEvent> mouse_event_queue;
76 96
77 // Time and place of the last mouse up event. 97 // Time and place of the last mouse up event.
78 static double last_click_time_sec = 0; 98 static double last_click_time_sec = 0;
79 static gfx::Point last_click_pos; 99 static gfx::Point last_click_pos;
80 static int click_count = 0; 100 static int click_count = 0;
81 101
82 // maximum distance (in space and time) for a mouse click 102 // maximum distance (in space and time) for a mouse click
83 // to register as a double or triple click 103 // to register as a double or triple click
84 static const double kMultiClickTimeSec = 1; 104 static const double kMultiClickTimeSec = 1;
85 static const int kMultiClickRadiusPixels = 5; 105 static const int kMultiClickRadiusPixels = 5;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 #if defined(OS_WIN) 226 #if defined(OS_WIN)
207 wmKeyDown.Set(WM_KEYDOWN); 227 wmKeyDown.Set(WM_KEYDOWN);
208 wmKeyUp.Set(WM_KEYUP); 228 wmKeyUp.Set(WM_KEYUP);
209 wmChar.Set(WM_CHAR); 229 wmChar.Set(WM_CHAR);
210 wmDeadChar.Set(WM_DEADCHAR); 230 wmDeadChar.Set(WM_DEADCHAR);
211 wmSysKeyDown.Set(WM_SYSKEYDOWN); 231 wmSysKeyDown.Set(WM_SYSKEYDOWN);
212 wmSysKeyUp.Set(WM_SYSKEYUP); 232 wmSysKeyUp.Set(WM_SYSKEYUP);
213 wmSysChar.Set(WM_SYSCHAR); 233 wmSysChar.Set(WM_SYSCHAR);
214 wmSysDeadChar.Set(WM_SYSDEADCHAR); 234 wmSysDeadChar.Set(WM_SYSDEADCHAR);
215 #endif 235 #endif
236 last_mouse_pos_.SetPoint(0, 0);
216 last_click_time_sec = 0; 237 last_click_time_sec = 0;
238 last_click_pos.SetPoint(0, 0);
217 click_count = 0; 239 click_count = 0;
218 last_button_number_ = -1; 240 last_button_number_ = -1;
241 time_offset_ms = 0;
219 } 242 }
220 243
221 // static 244 // static
222 WebView* EventSendingController::webview() { 245 WebView* EventSendingController::webview() {
223 return shell_->webView(); 246 return shell_->webView();
224 } 247 }
225 248
226 // static 249 // static
227 void EventSendingController::DoDragDrop(const WebKit::WebPoint &event_pos, 250 void EventSendingController::DoDragDrop(const WebKit::WebPoint &event_pos,
228 const WebDragData& drag_data, 251 const WebDragData& drag_data,
229 WebDragOperationsMask mask) { 252 WebDragOperationsMask mask) {
230 WebMouseEvent event; 253 WebMouseEvent event;
231 InitMouseEvent(WebInputEvent::MouseDown, pressed_button_, event_pos, &event); 254 InitMouseEvent(WebInputEvent::MouseDown, pressed_button_, last_mouse_pos_, &ev ent);
232 WebPoint client_point(event.x, event.y); 255 WebPoint client_point(event.x, event.y);
233 WebPoint screen_point(event.globalX, event.globalY); 256 WebPoint screen_point(event.globalX, event.globalY);
234 current_drag_data = drag_data; 257 current_drag_data = drag_data;
235 current_drag_effects_allowed = mask; 258 current_drag_effects_allowed = mask;
236 current_drag_effect = webview()->dragTargetDragEnter( 259 current_drag_effect = webview()->dragTargetDragEnter(
237 drag_data, 0, client_point, screen_point, current_drag_effects_allowed); 260 drag_data, 0, client_point, screen_point, current_drag_effects_allowed);
238 261
239 // Finish processing events. 262 // Finish processing events.
240 ReplaySavedEvents(); 263 ReplaySavedEvents();
241 } 264 }
(...skipping 13 matching lines...) Expand all
255 const CppArgumentList& args) { 278 const CppArgumentList& args) {
256 int button_code = 0; 279 int button_code = 0;
257 280
258 if (args.size() > 0 && args[0].isNumber()) { 281 if (args.size() > 0 && args[0].isNumber()) {
259 button_code = args[0].ToInt32(); 282 button_code = args[0].ToInt32();
260 } 283 }
261 284
262 return button_code; 285 return button_code;
263 } 286 }
264 287
288 void EventSendingController::UpdateClickCountForButton(int button_number) {
dglazkov 2009/10/14 01:32:00 Can this take an enum instead?
289 if ((GetCurrentEventTimeSec() - last_click_time_sec < kMultiClickTimeSec) &&
290 (!outside_multiclick_radius(last_mouse_pos_, last_click_pos)) &&
291 (button_number == last_button_number_)) {
292 ++click_count;
293 } else {
294 click_count = 1;
295 last_button_number_ = button_number;
296 }
297 }
298
265 // 299 //
266 // Implemented javascript methods. 300 // Implemented javascript methods.
267 // 301 //
268 302
269 void EventSendingController::mouseDown( 303 void EventSendingController::mouseDown(
270 const CppArgumentList& args, CppVariant* result) { 304 const CppArgumentList& args, CppVariant* result) {
271 if (result) // Could be NULL if invoked asynchronously. 305 if (result) // Could be NULL if invoked asynchronously.
272 result->SetNull(); 306 result->SetNull();
273 307
274 webview()->layout(); 308 webview()->layout();
275 309
276 int button_number = GetButtonNumberFromSingleArg(args); 310 int button_number = GetButtonNumberFromSingleArg(args);
277 DCHECK(button_number != -1); 311 DCHECK(button_number != -1);
278 312
279 WebMouseEvent::Button button_type = GetButtonTypeFromButtonNumber( 313 WebMouseEvent::Button button_type = GetButtonTypeFromButtonNumber(
280 button_number); 314 button_number);
281 315
282 if ((GetCurrentEventTimeSec() - last_click_time_sec < kMultiClickTimeSec) && 316 UpdateClickCountForButton(button_number);
283 (!outside_multiclick_radius(last_mouse_pos_, last_click_pos)) &&
284 (button_number == last_button_number_)) {
285 ++click_count;
286 } else {
287 click_count = 1;
288 }
289
290 last_button_number_ = button_number;
291 317
292 WebMouseEvent event; 318 WebMouseEvent event;
293 pressed_button_ = button_type; 319 pressed_button_ = button_type;
294 InitMouseEvent(WebInputEvent::MouseDown, button_type, 320 InitMouseEvent(WebInputEvent::MouseDown, button_type,
295 last_mouse_pos_, &event); 321 last_mouse_pos_, &event);
296 webview()->handleInputEvent(event); 322 webview()->handleInputEvent(event);
297 } 323 }
298 324
299 void EventSendingController::mouseUp( 325 void EventSendingController::mouseUp(
300 const CppArgumentList& args, CppVariant* result) { 326 const CppArgumentList& args, CppVariant* result) {
301 if (result) // Could be NULL if invoked asynchronously. 327 if (result) // Could be NULL if invoked asynchronously.
302 result->SetNull(); 328 result->SetNull();
303 329
304 webview()->layout(); 330 webview()->layout();
305 331
306 int button_number = GetButtonNumberFromSingleArg(args); 332 int button_number = GetButtonNumberFromSingleArg(args);
307 DCHECK(button_number != -1); 333 DCHECK(button_number != -1);
308 334
309 WebMouseEvent::Button button_type = GetButtonTypeFromButtonNumber( 335 WebMouseEvent::Button button_type = GetButtonTypeFromButtonNumber(
310 button_number); 336 button_number);
311 337
312 last_button_number_ = button_number;
313
314 WebMouseEvent event;
315 InitMouseEvent(WebInputEvent::MouseUp, button_type,
316 last_mouse_pos_, &event);
317 if (drag_mode() && !replaying_saved_events) { 338 if (drag_mode() && !replaying_saved_events) {
318 mouse_event_queue.push(event); 339 SavedEvent saved_event;
340 saved_event.type = SavedEvent::MouseUp;
341 saved_event.button_type = button_type;
342 mouse_event_queue.push(saved_event);
319 ReplaySavedEvents(); 343 ReplaySavedEvents();
320 } else { 344 } else {
345 WebMouseEvent event;
346 InitMouseEvent(WebInputEvent::MouseUp, button_type,
347 last_mouse_pos_, &event);
321 DoMouseUp(event); 348 DoMouseUp(event);
322 } 349 }
323
324 last_click_time_sec = event.timeStampSeconds;
325 last_click_pos = gfx::Point(event.x, event.y);
326 } 350 }
327 351
328 /* static */ void EventSendingController::DoMouseUp(const WebMouseEvent& e) { 352 /* static */ void EventSendingController::DoMouseUp(const WebMouseEvent& e) {
329 webview()->handleInputEvent(e); 353 webview()->handleInputEvent(e);
354
330 pressed_button_ = WebMouseEvent::ButtonNone; 355 pressed_button_ = WebMouseEvent::ButtonNone;
356 last_click_time_sec = e.timeStampSeconds;
357 last_click_pos = last_mouse_pos_;
331 358
332 // If we're in a drag operation, complete it. 359 // If we're in a drag operation, complete it.
333 if (!current_drag_data.isNull()) { 360 if (!current_drag_data.isNull()) {
334 WebPoint client_point(e.x, e.y); 361 WebPoint client_point(e.x, e.y);
335 WebPoint screen_point(e.globalX, e.globalY); 362 WebPoint screen_point(e.globalX, e.globalY);
336 363
337 webview()->dragSourceMovedTo(client_point, screen_point); 364 webview()->dragSourceMovedTo(client_point, screen_point);
338 current_drag_effect = webview()->dragTargetDragOver( 365 current_drag_effect = webview()->dragTargetDragOver(
339 client_point, screen_point, current_drag_effects_allowed); 366 client_point, screen_point, current_drag_effects_allowed);
340 if (current_drag_effect) { 367 if (current_drag_effect) {
341 webview()->dragTargetDrop(client_point, screen_point); 368 webview()->dragTargetDrop(client_point, screen_point);
342 } else { 369 } else {
343 webview()->dragTargetDragLeave(); 370 webview()->dragTargetDragLeave();
344 } 371 }
345 webview()->dragSourceEndedAt( 372 webview()->dragSourceEndedAt(
346 client_point, screen_point, current_drag_effect); 373 client_point, screen_point, current_drag_effect);
374 webview()->dragSourceSystemDragEnded();
347 375
348 current_drag_data.reset(); 376 current_drag_data.reset();
349 } 377 }
350 } 378 }
351 379
352 void EventSendingController::mouseMoveTo( 380 void EventSendingController::mouseMoveTo(
353 const CppArgumentList& args, CppVariant* result) { 381 const CppArgumentList& args, CppVariant* result) {
354 result->SetNull(); 382 result->SetNull();
355 383
356 if (args.size() >= 2 && args[0].isNumber() && args[1].isNumber()) { 384 if (args.size() >= 2 && args[0].isNumber() && args[1].isNumber()) {
357 webview()->layout(); 385 webview()->layout();
358 386
359 WebMouseEvent event; 387 gfx::Point mouse_pos;
360 last_mouse_pos_.SetPoint(args[0].ToInt32(), args[1].ToInt32()); 388 mouse_pos.SetPoint(args[0].ToInt32(), args[1].ToInt32());
361 InitMouseEvent(WebInputEvent::MouseMove, pressed_button_,
362 last_mouse_pos_, &event);
363 389
364 if (drag_mode() && pressed_button_ != WebMouseEvent::ButtonNone && 390 if (drag_mode() && pressed_button_ == WebMouseEvent::ButtonLeft &&
365 !replaying_saved_events) { 391 !replaying_saved_events) {
366 mouse_event_queue.push(event); 392 SavedEvent saved_event;
393 saved_event.type = SavedEvent::MouseMove;
394 saved_event.pos = mouse_pos;
395 mouse_event_queue.push(saved_event);
367 } else { 396 } else {
397 WebMouseEvent event;
398 InitMouseEvent(WebInputEvent::MouseMove, pressed_button_,
399 mouse_pos, &event);
368 DoMouseMove(event); 400 DoMouseMove(event);
369 } 401 }
370 } 402 }
371 } 403 }
372 404
373 // static 405 // static
374 void EventSendingController::DoMouseMove(const WebMouseEvent& e) { 406 void EventSendingController::DoMouseMove(const WebMouseEvent& e) {
407 last_mouse_pos_.SetPoint(e.x, e.y);
408
375 webview()->handleInputEvent(e); 409 webview()->handleInputEvent(e);
376 410
377 if (pressed_button_ != WebMouseEvent::ButtonNone && 411 if (pressed_button_ != WebMouseEvent::ButtonNone &&
378 !current_drag_data.isNull()) { 412 !current_drag_data.isNull()) {
379 WebPoint client_point(e.x, e.y); 413 WebPoint client_point(e.x, e.y);
380 WebPoint screen_point(e.globalX, e.globalY); 414 WebPoint screen_point(e.globalX, e.globalY);
381 415
382 webview()->dragSourceMovedTo(client_point, screen_point); 416 webview()->dragSourceMovedTo(client_point, screen_point);
383 current_drag_effect = webview()->dragTargetDragOver( 417 current_drag_effect = webview()->dragTargetDragOver(
384 client_point, screen_point, current_drag_effects_allowed); 418 client_point, screen_point, current_drag_effects_allowed);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 // WebKit/WebKitTools/DumpRenderTree/Win/EventSender.cpp 555 // WebKit/WebKitTools/DumpRenderTree/Win/EventSender.cpp
522 if ((key_code & 0xFF) >= 'A' && (key_code & 0xFF) <= 'Z') 556 if ((key_code & 0xFF) >= 'A' && (key_code & 0xFF) <= 'Z')
523 return true; 557 return true;
524 return false; 558 return false;
525 } 559 }
526 560
527 void EventSendingController::leapForward( 561 void EventSendingController::leapForward(
528 const CppArgumentList& args, CppVariant* result) { 562 const CppArgumentList& args, CppVariant* result) {
529 result->SetNull(); 563 result->SetNull();
530 564
531 // TODO(mpcomplete): DumpRenderTree defers this under certain conditions. 565 if (args.size() <1 || !args[0].isNumber())
566 return;
532 567
533 if (args.size() >=1 && args[0].isNumber()) { 568 int milliseconds = args[0].ToInt32();
534 AdvanceEventTime(args[0].ToInt32()); 569 if (drag_mode() && pressed_button_ == WebMouseEvent::ButtonLeft &&
570 !replaying_saved_events) {
571 SavedEvent saved_event;
572 saved_event.type = SavedEvent::LeapForward;
573 saved_event.milliseconds = milliseconds;
574 mouse_event_queue.push(saved_event);
575 } else {
576 DoLeapForward(milliseconds);
535 } 577 }
536 } 578 }
537 579
580 /* static */ void EventSendingController::DoLeapForward(int milliseconds) {
dglazkov 2009/10/14 01:32:00 I think you should just do // static at the top of
581 AdvanceEventTime(milliseconds);
582 }
583
538 // Apple's port of WebKit zooms by a factor of 1.2 (see 584 // Apple's port of WebKit zooms by a factor of 1.2 (see
539 // WebKit/WebView/WebView.mm) 585 // WebKit/WebView/WebView.mm)
540 void EventSendingController::textZoomIn( 586 void EventSendingController::textZoomIn(
541 const CppArgumentList& args, CppVariant* result) { 587 const CppArgumentList& args, CppVariant* result) {
542 webview()->zoomIn(true); 588 webview()->zoomIn(true);
543 result->SetNull(); 589 result->SetNull();
544 } 590 }
545 591
546 void EventSendingController::textZoomOut( 592 void EventSendingController::textZoomOut(
547 const CppArgumentList& args, CppVariant* result) { 593 const CppArgumentList& args, CppVariant* result) {
548 webview()->zoomOut(true); 594 webview()->zoomOut(true);
549 result->SetNull(); 595 result->SetNull();
550 } 596 }
551 597
552 void EventSendingController::zoomPageIn( 598 void EventSendingController::zoomPageIn(
553 const CppArgumentList& args, CppVariant* result) { 599 const CppArgumentList& args, CppVariant* result) {
554 webview()->zoomIn(false); 600 webview()->zoomIn(false);
555 result->SetNull(); 601 result->SetNull();
556 } 602 }
557 603
558 void EventSendingController::zoomPageOut( 604 void EventSendingController::zoomPageOut(
559 const CppArgumentList& args, CppVariant* result) { 605 const CppArgumentList& args, CppVariant* result) {
560 webview()->zoomOut(false); 606 webview()->zoomOut(false);
561 result->SetNull(); 607 result->SetNull();
562 } 608 }
563 609
564 void EventSendingController::ReplaySavedEvents() { 610 void EventSendingController::ReplaySavedEvents() {
565 replaying_saved_events = true; 611 replaying_saved_events = true;
566 while (!mouse_event_queue.empty()) { 612 while (!mouse_event_queue.empty()) {
567 WebMouseEvent event = mouse_event_queue.front(); 613 SavedEvent e = mouse_event_queue.front();
568 mouse_event_queue.pop(); 614 mouse_event_queue.pop();
569 615
570 switch (event.type) { 616 switch (e.type) {
571 case WebInputEvent::MouseUp: 617 case SavedEvent::MouseMove: {
618 WebMouseEvent event;
619 InitMouseEvent(WebInputEvent::MouseMove, pressed_button_,
620 e.pos, &event);
621 DoMouseMove(event);
622 break;
623 }
624 case SavedEvent::LeapForward:
625 DoLeapForward(e.milliseconds);
626 break;
627 case SavedEvent::MouseUp: {
628 WebMouseEvent event;
629 InitMouseEvent(WebInputEvent::MouseUp, e.button_type,
630 last_mouse_pos_, &event);
572 DoMouseUp(event); 631 DoMouseUp(event);
573 break; 632 break;
574 case WebInputEvent::MouseMove: 633 }
575 DoMouseMove(event);
576 break;
577 default: 634 default:
578 NOTREACHED(); 635 NOTREACHED();
579 } 636 }
580 } 637 }
581 638
582 replaying_saved_events = false; 639 replaying_saved_events = false;
583 } 640 }
584 641
585 void EventSendingController::contextClick( 642 void EventSendingController::contextClick(
586 const CppArgumentList& args, CppVariant* result) { 643 const CppArgumentList& args, CppVariant* result) {
587 result->SetNull(); 644 result->SetNull();
588 645
589 webview()->layout(); 646 webview()->layout();
590 647
591 if (GetCurrentEventTimeSec() - last_click_time_sec >= 1) { 648 UpdateClickCountForButton(2 /*RightMouseButton*/);
592 click_count = 1;
593 } else {
594 ++click_count;
595 }
596 649
597 // Generate right mouse down and up. 650 // Generate right mouse down and up.
598 651
599 WebMouseEvent event; 652 WebMouseEvent event;
600 pressed_button_ = WebMouseEvent::ButtonRight; 653 pressed_button_ = WebMouseEvent::ButtonRight;
601 InitMouseEvent(WebInputEvent::MouseDown, WebMouseEvent::ButtonRight, 654 InitMouseEvent(WebInputEvent::MouseDown, WebMouseEvent::ButtonRight,
602 last_mouse_pos_, &event); 655 last_mouse_pos_, &event);
603 webview()->handleInputEvent(event); 656 webview()->handleInputEvent(event);
604 657
605 InitMouseEvent(WebInputEvent::MouseUp, WebMouseEvent::ButtonRight, 658 InitMouseEvent(WebInputEvent::MouseUp, WebMouseEvent::ButtonRight,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 713
661 void EventSendingController::fireKeyboardEventsToElement( 714 void EventSendingController::fireKeyboardEventsToElement(
662 const CppArgumentList& args, CppVariant* result) { 715 const CppArgumentList& args, CppVariant* result) {
663 result->SetNull(); 716 result->SetNull();
664 } 717 }
665 718
666 void EventSendingController::clearKillRing( 719 void EventSendingController::clearKillRing(
667 const CppArgumentList& args, CppVariant* result) { 720 const CppArgumentList& args, CppVariant* result) {
668 result->SetNull(); 721 result->SetNull();
669 } 722 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/event_sending_controller.h ('k') | webkit/tools/test_shell/test_webview_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698