| OLD | NEW |
| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 241 |
| 242 // | 242 // |
| 243 // Implemented javascript methods. | 243 // Implemented javascript methods. |
| 244 // | 244 // |
| 245 | 245 |
| 246 void EventSendingController::mouseDown( | 246 void EventSendingController::mouseDown( |
| 247 const CppArgumentList& args, CppVariant* result) { | 247 const CppArgumentList& args, CppVariant* result) { |
| 248 if (result) // Could be NULL if invoked asynchronously. | 248 if (result) // Could be NULL if invoked asynchronously. |
| 249 result->SetNull(); | 249 result->SetNull(); |
| 250 | 250 |
| 251 webview()->Layout(); | 251 webview()->layout(); |
| 252 | 252 |
| 253 int button_number = GetButtonNumberFromSingleArg(args); | 253 int button_number = GetButtonNumberFromSingleArg(args); |
| 254 DCHECK(button_number != -1); | 254 DCHECK(button_number != -1); |
| 255 | 255 |
| 256 WebMouseEvent::Button button_type = GetButtonTypeFromButtonNumber( | 256 WebMouseEvent::Button button_type = GetButtonTypeFromButtonNumber( |
| 257 button_number); | 257 button_number); |
| 258 | 258 |
| 259 if ((GetCurrentEventTimeSec() - last_click_time_sec < kMultiClickTimeSec) && | 259 if ((GetCurrentEventTimeSec() - last_click_time_sec < kMultiClickTimeSec) && |
| 260 (!outside_multiclick_radius(last_mouse_pos_, last_click_pos)) && | 260 (!outside_multiclick_radius(last_mouse_pos_, last_click_pos)) && |
| 261 (button_number == last_button_number_)) { | 261 (button_number == last_button_number_)) { |
| 262 ++click_count; | 262 ++click_count; |
| 263 } else { | 263 } else { |
| 264 click_count = 1; | 264 click_count = 1; |
| 265 } | 265 } |
| 266 | 266 |
| 267 last_button_number_ = button_number; | 267 last_button_number_ = button_number; |
| 268 | 268 |
| 269 WebMouseEvent event; | 269 WebMouseEvent event; |
| 270 pressed_button_ = button_type; | 270 pressed_button_ = button_type; |
| 271 InitMouseEvent(WebInputEvent::MouseDown, button_type, | 271 InitMouseEvent(WebInputEvent::MouseDown, button_type, |
| 272 last_mouse_pos_, &event); | 272 last_mouse_pos_, &event); |
| 273 webview()->HandleInputEvent(&event); | 273 webview()->handleInputEvent(event); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void EventSendingController::mouseUp( | 276 void EventSendingController::mouseUp( |
| 277 const CppArgumentList& args, CppVariant* result) { | 277 const CppArgumentList& args, CppVariant* result) { |
| 278 if (result) // Could be NULL if invoked asynchronously. | 278 if (result) // Could be NULL if invoked asynchronously. |
| 279 result->SetNull(); | 279 result->SetNull(); |
| 280 | 280 |
| 281 webview()->Layout(); | 281 webview()->layout(); |
| 282 | 282 |
| 283 int button_number = GetButtonNumberFromSingleArg(args); | 283 int button_number = GetButtonNumberFromSingleArg(args); |
| 284 DCHECK(button_number != -1); | 284 DCHECK(button_number != -1); |
| 285 | 285 |
| 286 WebMouseEvent::Button button_type = GetButtonTypeFromButtonNumber( | 286 WebMouseEvent::Button button_type = GetButtonTypeFromButtonNumber( |
| 287 button_number); | 287 button_number); |
| 288 | 288 |
| 289 last_button_number_ = button_number; | 289 last_button_number_ = button_number; |
| 290 | 290 |
| 291 WebMouseEvent event; | 291 WebMouseEvent event; |
| 292 InitMouseEvent(WebInputEvent::MouseUp, button_type, | 292 InitMouseEvent(WebInputEvent::MouseUp, button_type, |
| 293 last_mouse_pos_, &event); | 293 last_mouse_pos_, &event); |
| 294 if (drag_mode() && !replaying_saved_events) { | 294 if (drag_mode() && !replaying_saved_events) { |
| 295 mouse_event_queue.push(event); | 295 mouse_event_queue.push(event); |
| 296 ReplaySavedEvents(); | 296 ReplaySavedEvents(); |
| 297 } else { | 297 } else { |
| 298 DoMouseUp(event); | 298 DoMouseUp(event); |
| 299 } | 299 } |
| 300 | 300 |
| 301 last_click_time_sec = event.timeStampSeconds; | 301 last_click_time_sec = event.timeStampSeconds; |
| 302 last_click_pos = gfx::Point(event.x, event.y); | 302 last_click_pos = gfx::Point(event.x, event.y); |
| 303 } | 303 } |
| 304 | 304 |
| 305 /* static */ void EventSendingController::DoMouseUp(const WebMouseEvent& e) { | 305 /* static */ void EventSendingController::DoMouseUp(const WebMouseEvent& e) { |
| 306 webview()->HandleInputEvent(&e); | 306 webview()->handleInputEvent(e); |
| 307 pressed_button_ = WebMouseEvent::ButtonNone; | 307 pressed_button_ = WebMouseEvent::ButtonNone; |
| 308 | 308 |
| 309 // If we're in a drag operation, complete it. | 309 // If we're in a drag operation, complete it. |
| 310 if (!current_drag_data.isNull()) { | 310 if (!current_drag_data.isNull()) { |
| 311 WebPoint client_point(e.x, e.y); | 311 WebPoint client_point(e.x, e.y); |
| 312 WebPoint screen_point(e.globalX, e.globalY); | 312 WebPoint screen_point(e.globalX, e.globalY); |
| 313 | 313 |
| 314 bool valid = webview()->DragTargetDragOver(client_point, screen_point); | 314 bool valid = webview()->DragTargetDragOver(client_point, screen_point); |
| 315 if (valid) { | 315 if (valid) { |
| 316 webview()->DragSourceEndedAt(client_point, screen_point); | 316 webview()->DragSourceEndedAt(client_point, screen_point); |
| 317 webview()->DragTargetDrop(client_point, screen_point); | 317 webview()->DragTargetDrop(client_point, screen_point); |
| 318 } else { | 318 } else { |
| 319 webview()->DragSourceEndedAt(client_point, screen_point); | 319 webview()->DragSourceEndedAt(client_point, screen_point); |
| 320 webview()->DragTargetDragLeave(); | 320 webview()->DragTargetDragLeave(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 current_drag_data.reset(); | 323 current_drag_data.reset(); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 void EventSendingController::mouseMoveTo( | 327 void EventSendingController::mouseMoveTo( |
| 328 const CppArgumentList& args, CppVariant* result) { | 328 const CppArgumentList& args, CppVariant* result) { |
| 329 result->SetNull(); | 329 result->SetNull(); |
| 330 | 330 |
| 331 if (args.size() >= 2 && args[0].isNumber() && args[1].isNumber()) { | 331 if (args.size() >= 2 && args[0].isNumber() && args[1].isNumber()) { |
| 332 webview()->Layout(); | 332 webview()->layout(); |
| 333 | 333 |
| 334 WebMouseEvent event; | 334 WebMouseEvent event; |
| 335 last_mouse_pos_.SetPoint(args[0].ToInt32(), args[1].ToInt32()); | 335 last_mouse_pos_.SetPoint(args[0].ToInt32(), args[1].ToInt32()); |
| 336 InitMouseEvent(WebInputEvent::MouseMove, pressed_button_, | 336 InitMouseEvent(WebInputEvent::MouseMove, pressed_button_, |
| 337 last_mouse_pos_, &event); | 337 last_mouse_pos_, &event); |
| 338 | 338 |
| 339 if (drag_mode() && pressed_button_ != WebMouseEvent::ButtonNone && | 339 if (drag_mode() && pressed_button_ != WebMouseEvent::ButtonNone && |
| 340 !replaying_saved_events) { | 340 !replaying_saved_events) { |
| 341 mouse_event_queue.push(event); | 341 mouse_event_queue.push(event); |
| 342 } else { | 342 } else { |
| 343 DoMouseMove(event); | 343 DoMouseMove(event); |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| 348 // static | 348 // static |
| 349 void EventSendingController::DoMouseMove(const WebMouseEvent& e) { | 349 void EventSendingController::DoMouseMove(const WebMouseEvent& e) { |
| 350 webview()->HandleInputEvent(&e); | 350 webview()->handleInputEvent(e); |
| 351 | 351 |
| 352 if (pressed_button_ != WebMouseEvent::ButtonNone && | 352 if (pressed_button_ != WebMouseEvent::ButtonNone && |
| 353 !current_drag_data.isNull()) { | 353 !current_drag_data.isNull()) { |
| 354 WebPoint client_point(e.x, e.y); | 354 WebPoint client_point(e.x, e.y); |
| 355 WebPoint screen_point(e.globalX, e.globalY); | 355 WebPoint screen_point(e.globalX, e.globalY); |
| 356 | 356 |
| 357 webview()->DragSourceMovedTo(client_point, screen_point); | 357 webview()->DragSourceMovedTo(client_point, screen_point); |
| 358 webview()->DragTargetDragOver(client_point, screen_point); | 358 webview()->DragTargetDragOver(client_point, screen_point); |
| 359 } | 359 } |
| 360 } | 360 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 if (args.size() >= 2 && (args[1].isObject() || args[1].isString())) | 421 if (args.size() >= 2 && (args[1].isObject() || args[1].isString())) |
| 422 ApplyKeyModifiers(&(args[1]), &event_down); | 422 ApplyKeyModifiers(&(args[1]), &event_down); |
| 423 | 423 |
| 424 if (needs_shift_key_modifier) | 424 if (needs_shift_key_modifier) |
| 425 event_down.modifiers |= WebInputEvent::ShiftKey; | 425 event_down.modifiers |= WebInputEvent::ShiftKey; |
| 426 | 426 |
| 427 event_up = event_down; | 427 event_up = event_down; |
| 428 event_up.type = WebInputEvent::KeyUp; | 428 event_up.type = WebInputEvent::KeyUp; |
| 429 // EventSendingController.m forces a layout here, with at least one | 429 // EventSendingController.m forces a layout here, with at least one |
| 430 // test (fast\forms\focus-control-to-page.html) relying on this. | 430 // test (fast\forms\focus-control-to-page.html) relying on this. |
| 431 webview()->Layout(); | 431 webview()->layout(); |
| 432 | 432 |
| 433 webview()->HandleInputEvent(&event_down); | 433 webview()->handleInputEvent(event_down); |
| 434 | 434 |
| 435 #if defined(OS_WIN) | 435 #if defined(OS_WIN) |
| 436 if (generate_char) { | 436 if (generate_char) { |
| 437 WebKeyboardEvent event_char = event_down; | 437 WebKeyboardEvent event_char = event_down; |
| 438 event_char.type = WebInputEvent::Char; | 438 event_char.type = WebInputEvent::Char; |
| 439 event_char.keyIdentifier[0] = '\0'; | 439 event_char.keyIdentifier[0] = '\0'; |
| 440 webview()->HandleInputEvent(&event_char); | 440 webview()->handleInputEvent(event_char); |
| 441 } | 441 } |
| 442 #endif | 442 #endif |
| 443 | 443 |
| 444 webview()->HandleInputEvent(&event_up); | 444 webview()->handleInputEvent(event_up); |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 | 447 |
| 448 void EventSendingController::dispatchMessage( | 448 void EventSendingController::dispatchMessage( |
| 449 const CppArgumentList& args, CppVariant* result) { | 449 const CppArgumentList& args, CppVariant* result) { |
| 450 result->SetNull(); | 450 result->SetNull(); |
| 451 | 451 |
| 452 #if defined(OS_WIN) | 452 #if defined(OS_WIN) |
| 453 if (args.size() == 3) { | 453 if (args.size() == 3) { |
| 454 // Grab the message id to see if we need to dispatch it. | 454 // Grab the message id to see if we need to dispatch it. |
| 455 int msg = args[0].ToInt32(); | 455 int msg = args[0].ToInt32(); |
| 456 | 456 |
| 457 // WebKit's version of this function stuffs a MSG struct and uses | 457 // WebKit's version of this function stuffs a MSG struct and uses |
| 458 // TranslateMessage and DispatchMessage. We use a WebKeyboardEvent, which | 458 // TranslateMessage and DispatchMessage. We use a WebKeyboardEvent, which |
| 459 // doesn't need to receive the DeadChar and SysDeadChar messages. | 459 // doesn't need to receive the DeadChar and SysDeadChar messages. |
| 460 if (msg == WM_DEADCHAR || msg == WM_SYSDEADCHAR) | 460 if (msg == WM_DEADCHAR || msg == WM_SYSDEADCHAR) |
| 461 return; | 461 return; |
| 462 | 462 |
| 463 webview()->Layout(); | 463 webview()->layout(); |
| 464 | 464 |
| 465 unsigned long lparam = static_cast<unsigned long>(args[2].ToDouble()); | 465 unsigned long lparam = static_cast<unsigned long>(args[2].ToDouble()); |
| 466 const WebKeyboardEvent& key_event = WebInputEventFactory::keyboardEvent( | 466 webview()->handleInputEvent(WebInputEventFactory::keyboardEvent( |
| 467 NULL, msg, args[1].ToInt32(), lparam); | 467 NULL, msg, args[1].ToInt32(), lparam)); |
| 468 webview()->HandleInputEvent(&key_event); | |
| 469 } else { | 468 } else { |
| 470 NOTREACHED() << L"Wrong number of arguments"; | 469 NOTREACHED() << L"Wrong number of arguments"; |
| 471 } | 470 } |
| 472 #endif | 471 #endif |
| 473 } | 472 } |
| 474 | 473 |
| 475 bool EventSendingController::NeedsShiftModifier(int key_code) { | 474 bool EventSendingController::NeedsShiftModifier(int key_code) { |
| 476 // If code is an uppercase letter, assign a SHIFT key to | 475 // If code is an uppercase letter, assign a SHIFT key to |
| 477 // event_down.modifier, this logic comes from | 476 // event_down.modifier, this logic comes from |
| 478 // WebKit/WebKitTools/DumpRenderTree/Win/EventSender.cpp | 477 // WebKit/WebKitTools/DumpRenderTree/Win/EventSender.cpp |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 535 } |
| 537 } | 536 } |
| 538 | 537 |
| 539 replaying_saved_events = false; | 538 replaying_saved_events = false; |
| 540 } | 539 } |
| 541 | 540 |
| 542 void EventSendingController::contextClick( | 541 void EventSendingController::contextClick( |
| 543 const CppArgumentList& args, CppVariant* result) { | 542 const CppArgumentList& args, CppVariant* result) { |
| 544 result->SetNull(); | 543 result->SetNull(); |
| 545 | 544 |
| 546 webview()->Layout(); | 545 webview()->layout(); |
| 547 | 546 |
| 548 if (GetCurrentEventTimeSec() - last_click_time_sec >= 1) { | 547 if (GetCurrentEventTimeSec() - last_click_time_sec >= 1) { |
| 549 click_count = 1; | 548 click_count = 1; |
| 550 } else { | 549 } else { |
| 551 ++click_count; | 550 ++click_count; |
| 552 } | 551 } |
| 553 | 552 |
| 554 // Generate right mouse down and up. | 553 // Generate right mouse down and up. |
| 555 | 554 |
| 556 WebMouseEvent event; | 555 WebMouseEvent event; |
| 557 pressed_button_ = WebMouseEvent::ButtonRight; | 556 pressed_button_ = WebMouseEvent::ButtonRight; |
| 558 InitMouseEvent(WebInputEvent::MouseDown, WebMouseEvent::ButtonRight, | 557 InitMouseEvent(WebInputEvent::MouseDown, WebMouseEvent::ButtonRight, |
| 559 last_mouse_pos_, &event); | 558 last_mouse_pos_, &event); |
| 560 webview()->HandleInputEvent(&event); | 559 webview()->handleInputEvent(event); |
| 561 | 560 |
| 562 InitMouseEvent(WebInputEvent::MouseUp, WebMouseEvent::ButtonRight, | 561 InitMouseEvent(WebInputEvent::MouseUp, WebMouseEvent::ButtonRight, |
| 563 last_mouse_pos_, &event); | 562 last_mouse_pos_, &event); |
| 564 webview()->HandleInputEvent(&event); | 563 webview()->handleInputEvent(event); |
| 565 | 564 |
| 566 pressed_button_ = WebMouseEvent::ButtonNone; | 565 pressed_button_ = WebMouseEvent::ButtonNone; |
| 567 } | 566 } |
| 568 | 567 |
| 569 void EventSendingController::scheduleAsynchronousClick( | 568 void EventSendingController::scheduleAsynchronousClick( |
| 570 const CppArgumentList& args, CppVariant* result) { | 569 const CppArgumentList& args, CppVariant* result) { |
| 571 result->SetNull(); | 570 result->SetNull(); |
| 572 | 571 |
| 573 MessageLoop::current()->PostTask(FROM_HERE, | 572 MessageLoop::current()->PostTask(FROM_HERE, |
| 574 method_factory_.NewRunnableMethod(&EventSendingController::mouseDown, | 573 method_factory_.NewRunnableMethod(&EventSendingController::mouseDown, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 589 | 588 |
| 590 void EventSendingController::fireKeyboardEventsToElement( | 589 void EventSendingController::fireKeyboardEventsToElement( |
| 591 const CppArgumentList& args, CppVariant* result) { | 590 const CppArgumentList& args, CppVariant* result) { |
| 592 result->SetNull(); | 591 result->SetNull(); |
| 593 } | 592 } |
| 594 | 593 |
| 595 void EventSendingController::clearKillRing( | 594 void EventSendingController::clearKillRing( |
| 596 const CppArgumentList& args, CppVariant* result) { | 595 const CppArgumentList& args, CppVariant* result) { |
| 597 result->SetNull(); | 596 result->SetNull(); |
| 598 } | 597 } |
| OLD | NEW |