OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/render_widget_host.h" | 5 #include "chrome/browser/renderer_host/render_widget_host.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
9 #include "base/keyboard_codes.h" | 9 #include "base/keyboard_codes.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 : renderer_initialized_(false), | 59 : renderer_initialized_(false), |
60 view_(NULL), | 60 view_(NULL), |
61 process_(process), | 61 process_(process), |
62 painting_observer_(NULL), | 62 painting_observer_(NULL), |
63 routing_id_(routing_id), | 63 routing_id_(routing_id), |
64 is_loading_(false), | 64 is_loading_(false), |
65 is_hidden_(false), | 65 is_hidden_(false), |
66 repaint_ack_pending_(false), | 66 repaint_ack_pending_(false), |
67 resize_ack_pending_(false), | 67 resize_ack_pending_(false), |
68 mouse_move_pending_(false), | 68 mouse_move_pending_(false), |
| 69 mouse_wheel_pending_(false), |
69 needs_repainting_on_restore_(false), | 70 needs_repainting_on_restore_(false), |
70 is_unresponsive_(false), | 71 is_unresponsive_(false), |
71 in_get_backing_store_(false), | 72 in_get_backing_store_(false), |
72 view_being_painted_(false), | 73 view_being_painted_(false), |
73 text_direction_updated_(false), | 74 text_direction_updated_(false), |
74 text_direction_(WebKit::WebTextDirectionLeftToRight), | 75 text_direction_(WebKit::WebTextDirectionLeftToRight), |
75 text_direction_canceled_(false), | 76 text_direction_canceled_(false), |
76 suppress_next_char_events_(false) { | 77 suppress_next_char_events_(false) { |
77 if (routing_id_ == MSG_ROUTING_NONE) | 78 if (routing_id_ == MSG_ROUTING_NONE) |
78 routing_id_ = process_->GetNextRoutingID(); | 79 routing_id_ = process_->GetNextRoutingID(); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } | 370 } |
370 | 371 |
371 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), false); | 372 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), false); |
372 } | 373 } |
373 | 374 |
374 void RenderWidgetHost::ForwardWheelEvent( | 375 void RenderWidgetHost::ForwardWheelEvent( |
375 const WebMouseWheelEvent& wheel_event) { | 376 const WebMouseWheelEvent& wheel_event) { |
376 if (process_->ignore_input_events()) | 377 if (process_->ignore_input_events()) |
377 return; | 378 return; |
378 | 379 |
| 380 // If there's already a mouse wheel event waiting to be sent to the renderer, |
| 381 // add the new deltas to that event. Not doing so (e.g., by dropping the old |
| 382 // event, as for mouse moves) results in very slow scrolling on the Mac (on |
| 383 // which many, very small wheel events are sent). |
| 384 if (mouse_wheel_pending_) { |
| 385 if (coalesced_mouse_wheel_events_.empty() || |
| 386 coalesced_mouse_wheel_events_.back().modifiers |
| 387 != wheel_event.modifiers || |
| 388 coalesced_mouse_wheel_events_.back().scrollByPage |
| 389 != wheel_event.scrollByPage) { |
| 390 coalesced_mouse_wheel_events_.push_back(wheel_event); |
| 391 } else { |
| 392 coalesced_mouse_wheel_events_.back().deltaX += wheel_event.deltaX; |
| 393 coalesced_mouse_wheel_events_.back().deltaY += wheel_event.deltaY; |
| 394 DCHECK_GE(wheel_event.timeStampSeconds, |
| 395 coalesced_mouse_wheel_events_.back().timeStampSeconds); |
| 396 coalesced_mouse_wheel_events_.back().timeStampSeconds = |
| 397 wheel_event.timeStampSeconds; |
| 398 } |
| 399 return; |
| 400 } |
| 401 mouse_wheel_pending_ = true; |
| 402 |
| 403 HISTOGRAM_COUNTS_100("MPArch.RWH_WheelQueueSize", |
| 404 coalesced_mouse_wheel_events_.size()); |
379 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent), false); | 405 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent), false); |
380 } | 406 } |
381 | 407 |
382 void RenderWidgetHost::ForwardKeyboardEvent( | 408 void RenderWidgetHost::ForwardKeyboardEvent( |
383 const NativeWebKeyboardEvent& key_event) { | 409 const NativeWebKeyboardEvent& key_event) { |
384 if (process_->ignore_input_events()) | 410 if (process_->ignore_input_events()) |
385 return; | 411 return; |
386 | 412 |
387 if (key_event.type == WebKeyboardEvent::Char && | 413 if (key_event.type == WebKeyboardEvent::Char && |
388 (key_event.windowsKeyCode == base::VKEY_RETURN || | 414 (key_event.windowsKeyCode == base::VKEY_RETURN || |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 reinterpret_cast<const char*>(&input_event), event_size); | 475 reinterpret_cast<const char*>(&input_event), event_size); |
450 // |is_keyboard_shortcut| only makes sense for RawKeyDown events. | 476 // |is_keyboard_shortcut| only makes sense for RawKeyDown events. |
451 if (input_event.type == WebInputEvent::RawKeyDown) | 477 if (input_event.type == WebInputEvent::RawKeyDown) |
452 message->WriteBool(is_keyboard_shortcut); | 478 message->WriteBool(is_keyboard_shortcut); |
453 input_event_start_time_ = TimeTicks::Now(); | 479 input_event_start_time_ = TimeTicks::Now(); |
454 Send(message); | 480 Send(message); |
455 | 481 |
456 // Any input event cancels a pending mouse move event. | 482 // Any input event cancels a pending mouse move event. |
457 next_mouse_move_.reset(); | 483 next_mouse_move_.reset(); |
458 | 484 |
| 485 // Any non-wheel input event cancels pending wheel events. |
| 486 if (input_event.type != WebInputEvent::MouseWheel) |
| 487 coalesced_mouse_wheel_events_.clear(); |
| 488 |
459 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kHungRendererDelayMs)); | 489 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kHungRendererDelayMs)); |
460 } | 490 } |
461 | 491 |
462 void RenderWidgetHost::ForwardEditCommand(const std::string& name, | 492 void RenderWidgetHost::ForwardEditCommand(const std::string& name, |
463 const std::string& value) { | 493 const std::string& value) { |
464 // We don't need an implementation of this function here since the | 494 // We don't need an implementation of this function here since the |
465 // only place we use this is for the case of dropdown menus and other | 495 // only place we use this is for the case of dropdown menus and other |
466 // edge cases for which edit commands don't make sense. | 496 // edge cases for which edit commands don't make sense. |
467 } | 497 } |
468 | 498 |
469 void RenderWidgetHost::ForwardEditCommandsForNextKeyEvent( | 499 void RenderWidgetHost::ForwardEditCommandsForNextKeyEvent( |
470 const EditCommands& edit_commands) { | 500 const EditCommands& edit_commands) { |
471 // We don't need an implementation of this function here since this message is | 501 // We don't need an implementation of this function here since this message is |
472 // only handled by RenderView. | 502 // only handled by RenderView. |
473 } | 503 } |
474 | 504 |
475 void RenderWidgetHost::RendererExited() { | 505 void RenderWidgetHost::RendererExited() { |
476 // Clearing this flag causes us to re-create the renderer when recovering | 506 // Clearing this flag causes us to re-create the renderer when recovering |
477 // from a crashed renderer. | 507 // from a crashed renderer. |
478 renderer_initialized_ = false; | 508 renderer_initialized_ = false; |
479 | 509 |
480 // Must reset these to ensure that mouse move events work with a new renderer. | 510 // Must reset these to ensure that mouse move/wheel events work with a new |
| 511 // renderer. |
481 mouse_move_pending_ = false; | 512 mouse_move_pending_ = false; |
482 next_mouse_move_.reset(); | 513 next_mouse_move_.reset(); |
| 514 mouse_wheel_pending_ = false; |
| 515 coalesced_mouse_wheel_events_.clear(); |
483 | 516 |
484 // Must reset these to ensure that keyboard events work with a new renderer. | 517 // Must reset these to ensure that keyboard events work with a new renderer. |
485 key_queue_.clear(); | 518 key_queue_.clear(); |
486 suppress_next_char_events_ = false; | 519 suppress_next_char_events_ = false; |
487 | 520 |
488 // Reset some fields in preparation for recovering from a crash. | 521 // Reset some fields in preparation for recovering from a crash. |
489 resize_ack_pending_ = false; | 522 resize_ack_pending_ = false; |
490 repaint_ack_pending_ = false; | 523 repaint_ack_pending_ = false; |
491 | 524 |
492 in_flight_size_.SetSize(0, 0); | 525 in_flight_size_.SetSize(0, 0); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 if (!message.ReadInt(&iter, &type) || (type < WebInputEvent::Undefined)) { | 768 if (!message.ReadInt(&iter, &type) || (type < WebInputEvent::Undefined)) { |
736 process()->ReceivedBadMessage(message.type()); | 769 process()->ReceivedBadMessage(message.type()); |
737 } else if (type == WebInputEvent::MouseMove) { | 770 } else if (type == WebInputEvent::MouseMove) { |
738 mouse_move_pending_ = false; | 771 mouse_move_pending_ = false; |
739 | 772 |
740 // now, we can send the next mouse move event | 773 // now, we can send the next mouse move event |
741 if (next_mouse_move_.get()) { | 774 if (next_mouse_move_.get()) { |
742 DCHECK(next_mouse_move_->type == WebInputEvent::MouseMove); | 775 DCHECK(next_mouse_move_->type == WebInputEvent::MouseMove); |
743 ForwardMouseEvent(*next_mouse_move_); | 776 ForwardMouseEvent(*next_mouse_move_); |
744 } | 777 } |
| 778 } else if (type == WebInputEvent::MouseWheel) { |
| 779 mouse_wheel_pending_ = false; |
| 780 |
| 781 // Now send the next (coalesced) mouse wheel event. |
| 782 if (!coalesced_mouse_wheel_events_.empty()) { |
| 783 WebMouseWheelEvent next_wheel_event = |
| 784 coalesced_mouse_wheel_events_.front(); |
| 785 coalesced_mouse_wheel_events_.pop_front(); |
| 786 ForwardWheelEvent(next_wheel_event); |
| 787 } |
745 } else if (WebInputEvent::isKeyboardEventType(type)) { | 788 } else if (WebInputEvent::isKeyboardEventType(type)) { |
746 bool processed = false; | 789 bool processed = false; |
747 if (!message.ReadBool(&iter, &processed)) | 790 if (!message.ReadBool(&iter, &processed)) |
748 process()->ReceivedBadMessage(message.type()); | 791 process()->ReceivedBadMessage(message.type()); |
749 | 792 |
750 ProcessKeyboardEventAck(type, processed); | 793 ProcessKeyboardEventAck(type, processed); |
751 } | 794 } |
752 } | 795 } |
753 | 796 |
754 void RenderWidgetHost::OnMsgFocus() { | 797 void RenderWidgetHost::OnMsgFocus() { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 | 959 |
917 if (!processed) { | 960 if (!processed) { |
918 UnhandledKeyboardEvent(front_item); | 961 UnhandledKeyboardEvent(front_item); |
919 | 962 |
920 // WARNING: This RenderWidgetHost can be deallocated at this point | 963 // WARNING: This RenderWidgetHost can be deallocated at this point |
921 // (i.e. in the case of Ctrl+W, where the call to | 964 // (i.e. in the case of Ctrl+W, where the call to |
922 // UnhandledKeyboardEvent destroys this RenderWidgetHost). | 965 // UnhandledKeyboardEvent destroys this RenderWidgetHost). |
923 } | 966 } |
924 } | 967 } |
925 } | 968 } |
OLD | NEW |