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

Side by Side Diff: chrome/browser/renderer_host/render_widget_host.cc

Issue 2679003: Peek at the event queue for wheel events for gtk (Closed)
Patch Set: Change name of event routine Created 10 years, 6 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 (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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/keyboard_codes.h" 10 #include "base/keyboard_codes.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 mouse_move_pending_(false), 81 mouse_move_pending_(false),
82 mouse_wheel_pending_(false), 82 mouse_wheel_pending_(false),
83 needs_repainting_on_restore_(false), 83 needs_repainting_on_restore_(false),
84 is_unresponsive_(false), 84 is_unresponsive_(false),
85 in_get_backing_store_(false), 85 in_get_backing_store_(false),
86 view_being_painted_(false), 86 view_being_painted_(false),
87 ignore_input_events_(false), 87 ignore_input_events_(false),
88 text_direction_updated_(false), 88 text_direction_updated_(false),
89 text_direction_(WebKit::WebTextDirectionLeftToRight), 89 text_direction_(WebKit::WebTextDirectionLeftToRight),
90 text_direction_canceled_(false), 90 text_direction_canceled_(false),
91 suppress_next_char_events_(false), 91 suppress_next_char_events_(false) {
92 spin_runloop_before_sending_wheel_event_(false),
93 ALLOW_THIS_IN_INITIALIZER_LIST(method_runner_(this)) {
94 if (routing_id_ == MSG_ROUTING_NONE) 92 if (routing_id_ == MSG_ROUTING_NONE)
95 routing_id_ = process_->GetNextRoutingID(); 93 routing_id_ = process_->GetNextRoutingID();
96 94
97 process_->Attach(this, routing_id_); 95 process_->Attach(this, routing_id_);
98 // Because the widget initializes as is_hidden_ == false, 96 // Because the widget initializes as is_hidden_ == false,
99 // tell the process host that we're alive. 97 // tell the process host that we're alive.
100 process_->WidgetRestored(); 98 process_->WidgetRestored();
101 } 99 }
102 100
103 RenderWidgetHost::~RenderWidgetHost() { 101 RenderWidgetHost::~RenderWidgetHost() {
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 414 }
417 415
418 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), false); 416 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), false);
419 } 417 }
420 418
421 void RenderWidgetHost::ForwardWheelEvent( 419 void RenderWidgetHost::ForwardWheelEvent(
422 const WebMouseWheelEvent& wheel_event) { 420 const WebMouseWheelEvent& wheel_event) {
423 if (ignore_input_events_ || process_->ignore_input_events()) 421 if (ignore_input_events_ || process_->ignore_input_events())
424 return; 422 return;
425 423
426 spin_runloop_before_sending_wheel_event_ = true;
427
428 // If there's already a mouse wheel event waiting to be sent to the renderer, 424 // If there's already a mouse wheel event waiting to be sent to the renderer,
429 // add the new deltas to that event. Not doing so (e.g., by dropping the old 425 // add the new deltas to that event. Not doing so (e.g., by dropping the old
430 // event, as for mouse moves) results in very slow scrolling on the Mac (on 426 // event, as for mouse moves) results in very slow scrolling on the Mac (on
431 // which many, very small wheel events are sent). 427 // which many, very small wheel events are sent).
432 if (mouse_wheel_pending_) { 428 if (mouse_wheel_pending_) {
433 if (coalesced_mouse_wheel_events_.empty() || 429 if (coalesced_mouse_wheel_events_.empty() ||
434 coalesced_mouse_wheel_events_.back().modifiers 430 coalesced_mouse_wheel_events_.back().modifiers
435 != wheel_event.modifiers || 431 != wheel_event.modifiers ||
436 coalesced_mouse_wheel_events_.back().scrollByPage 432 coalesced_mouse_wheel_events_.back().scrollByPage
437 != wheel_event.scrollByPage) { 433 != wheel_event.scrollByPage) {
438 coalesced_mouse_wheel_events_.push_back(wheel_event); 434 coalesced_mouse_wheel_events_.push_back(wheel_event);
439 } else { 435 } else {
440 WebMouseWheelEvent* last_wheel_event = 436 WebMouseWheelEvent* last_wheel_event =
441 &coalesced_mouse_wheel_events_.back(); 437 &coalesced_mouse_wheel_events_.back();
442 last_wheel_event->deltaX += wheel_event.deltaX; 438 last_wheel_event->deltaX += wheel_event.deltaX;
443 last_wheel_event->deltaY += wheel_event.deltaY; 439 last_wheel_event->deltaY += wheel_event.deltaY;
444 DCHECK_GE(wheel_event.timeStampSeconds, 440 DCHECK_GE(wheel_event.timeStampSeconds,
445 last_wheel_event->timeStampSeconds); 441 last_wheel_event->timeStampSeconds);
446 last_wheel_event->timeStampSeconds = wheel_event.timeStampSeconds; 442 last_wheel_event->timeStampSeconds = wheel_event.timeStampSeconds;
447 } 443 }
448 return; 444 return;
449 } 445 }
450 mouse_wheel_pending_ = true; 446 mouse_wheel_pending_ = true;
451 447
452 HISTOGRAM_COUNTS_100("MPArch.RWH_WheelQueueSize", 448 HISTOGRAM_COUNTS_100("MPArch.RWH_WheelQueueSize",
453 coalesced_mouse_wheel_events_.size()); 449 coalesced_mouse_wheel_events_.size());
454 450
455 last_wheel_message_time_ = TimeTicks::Now();
456 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent), false); 451 ForwardInputEvent(wheel_event, sizeof(WebMouseWheelEvent), false);
457 } 452 }
458 453
459 void RenderWidgetHost::ForwardKeyboardEvent( 454 void RenderWidgetHost::ForwardKeyboardEvent(
460 const NativeWebKeyboardEvent& key_event) { 455 const NativeWebKeyboardEvent& key_event) {
461 if (ignore_input_events_ || process_->ignore_input_events()) 456 if (ignore_input_events_ || process_->ignore_input_events())
462 return; 457 return;
463 458
464 if (key_event.type == WebKeyboardEvent::Char && 459 if (key_event.type == WebKeyboardEvent::Char &&
465 (key_event.windowsKeyCode == base::VKEY_RETURN || 460 (key_event.windowsKeyCode == base::VKEY_RETURN ||
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 void RenderWidgetHost::RendererExited() { 553 void RenderWidgetHost::RendererExited() {
559 // Clearing this flag causes us to re-create the renderer when recovering 554 // Clearing this flag causes us to re-create the renderer when recovering
560 // from a crashed renderer. 555 // from a crashed renderer.
561 renderer_initialized_ = false; 556 renderer_initialized_ = false;
562 557
563 // Must reset these to ensure that mouse move/wheel events work with a new 558 // Must reset these to ensure that mouse move/wheel events work with a new
564 // renderer. 559 // renderer.
565 mouse_move_pending_ = false; 560 mouse_move_pending_ = false;
566 next_mouse_move_.reset(); 561 next_mouse_move_.reset();
567 mouse_wheel_pending_ = false; 562 mouse_wheel_pending_ = false;
568 spin_runloop_before_sending_wheel_event_ = false;
569 coalesced_mouse_wheel_events_.clear(); 563 coalesced_mouse_wheel_events_.clear();
570 564
571 // Must reset these to ensure that keyboard events work with a new renderer. 565 // Must reset these to ensure that keyboard events work with a new renderer.
572 key_queue_.clear(); 566 key_queue_.clear();
573 suppress_next_char_events_ = false; 567 suppress_next_char_events_ = false;
574 568
575 // Reset some fields in preparation for recovering from a crash. 569 // Reset some fields in preparation for recovering from a crash.
576 resize_ack_pending_ = false; 570 resize_ack_pending_ = false;
577 repaint_ack_pending_ = false; 571 repaint_ack_pending_ = false;
578 572
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 } else if (WebInputEvent::isKeyboardEventType(type)) { 856 } else if (WebInputEvent::isKeyboardEventType(type)) {
863 bool processed = false; 857 bool processed = false;
864 if (!message.ReadBool(&iter, &processed)) 858 if (!message.ReadBool(&iter, &processed))
865 process()->ReceivedBadMessage(message.type()); 859 process()->ReceivedBadMessage(message.type());
866 860
867 ProcessKeyboardEventAck(type, processed); 861 ProcessKeyboardEventAck(type, processed);
868 } 862 }
869 } 863 }
870 864
871 void RenderWidgetHost::ProcessWheelAck() { 865 void RenderWidgetHost::ProcessWheelAck() {
872 static const base::TimeDelta kMaxTimeBetweenWheelMessages =
873 base::TimeDelta::FromMilliseconds(kMaxTimeBetweenWheelMessagesMs);
874
875 // Allow additional wheel events pending in the message queue to be coalesced.
876 if (spin_runloop_before_sending_wheel_event_) {
877 base::TimeDelta time_since_last_wheel_message_ =
878 TimeTicks::Now() - last_wheel_message_time_;
879 if (time_since_last_wheel_message_ < kMaxTimeBetweenWheelMessages) {
880 spin_runloop_before_sending_wheel_event_ = false;
881 MessageLoop::current()->PostTask(FROM_HERE,
882 method_runner_.NewRunnableMethod(&RenderWidgetHost::ProcessWheelAck));
883 return;
884 }
885 }
886
887 mouse_wheel_pending_ = false; 866 mouse_wheel_pending_ = false;
888 867
889 // Now send the next (coalesced) mouse wheel event. 868 // Now send the next (coalesced) mouse wheel event.
890 if (!coalesced_mouse_wheel_events_.empty()) { 869 if (!coalesced_mouse_wheel_events_.empty()) {
891 WebMouseWheelEvent next_wheel_event = 870 WebMouseWheelEvent next_wheel_event =
892 coalesced_mouse_wheel_events_.front(); 871 coalesced_mouse_wheel_events_.front();
893 coalesced_mouse_wheel_events_.pop_front(); 872 coalesced_mouse_wheel_events_.pop_front();
894 ForwardWheelEvent(next_wheel_event); 873 ForwardWheelEvent(next_wheel_event);
895 } 874 }
896 } 875 }
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 // of this key event. 1154 // of this key event.
1176 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { 1155 if (!processed && !is_hidden_ && !front_item.skip_in_browser) {
1177 UnhandledKeyboardEvent(front_item); 1156 UnhandledKeyboardEvent(front_item);
1178 1157
1179 // WARNING: This RenderWidgetHost can be deallocated at this point 1158 // WARNING: This RenderWidgetHost can be deallocated at this point
1180 // (i.e. in the case of Ctrl+W, where the call to 1159 // (i.e. in the case of Ctrl+W, where the call to
1181 // UnhandledKeyboardEvent destroys this RenderWidgetHost). 1160 // UnhandledKeyboardEvent destroys this RenderWidgetHost).
1182 } 1161 }
1183 } 1162 }
1184 } 1163 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host.h ('k') | chrome/browser/renderer_host/render_widget_host_view_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698