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

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 11779035: Centralize keypress listener handling in non-platform-specific code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Keep ignoring input events Created 7 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_impl.h" 5 #include "content/browser/renderer_host/render_widget_host_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 return; 1026 return;
1027 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), false); 1027 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), false);
1028 } 1028 }
1029 1029
1030 void RenderWidgetHostImpl::ForwardKeyboardEvent( 1030 void RenderWidgetHostImpl::ForwardKeyboardEvent(
1031 const NativeWebKeyboardEvent& key_event) { 1031 const NativeWebKeyboardEvent& key_event) {
1032 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardKeyboardEvent"); 1032 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardKeyboardEvent");
1033 if (ignore_input_events_ || process_->IgnoreInputEvents()) 1033 if (ignore_input_events_ || process_->IgnoreInputEvents())
1034 return; 1034 return;
1035 1035
1036 // First, let keypress listeners take a shot at handling the event. If a
1037 // listener handles the event, it should not be propagated to the renderer.
1038 if (KeyPressListenersHandleEvent(key_event))
1039 return;
1040
1036 if (key_event.type == WebKeyboardEvent::Char && 1041 if (key_event.type == WebKeyboardEvent::Char &&
1037 (key_event.windowsKeyCode == ui::VKEY_RETURN || 1042 (key_event.windowsKeyCode == ui::VKEY_RETURN ||
1038 key_event.windowsKeyCode == ui::VKEY_SPACE)) { 1043 key_event.windowsKeyCode == ui::VKEY_SPACE)) {
1039 OnUserGesture(); 1044 OnUserGesture();
1040 } 1045 }
1041 1046
1042 // Double check the type to make sure caller hasn't sent us nonsense that 1047 // Double check the type to make sure caller hasn't sent us nonsense that
1043 // will mess up our key queue. 1048 // will mess up our key queue.
1044 if (WebInputEvent::isKeyboardEventType(key_event.type)) { 1049 if (WebInputEvent::isKeyboardEventType(key_event.type)) {
1045 if (suppress_next_char_events_) { 1050 if (suppress_next_char_events_) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 1161
1157 StartHangMonitorTimeout( 1162 StartHangMonitorTimeout(
1158 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); 1163 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_));
1159 } 1164 }
1160 1165
1161 void RenderWidgetHostImpl::ForwardTouchEvent( 1166 void RenderWidgetHostImpl::ForwardTouchEvent(
1162 const WebKit::WebTouchEvent& touch_event) { 1167 const WebKit::WebTouchEvent& touch_event) {
1163 touch_event_queue_->QueueEvent(touch_event); 1168 touch_event_queue_->QueueEvent(touch_event);
1164 } 1169 }
1165 1170
1166 bool RenderWidgetHostImpl::KeyPressListenersHandleEvent(
1167 const NativeWebKeyboardEvent& event) {
1168 if (event.type != WebKeyboardEvent::RawKeyDown)
1169 return false;
1170
1171 for (std::list<KeyboardListener*>::iterator it = keyboard_listeners_.begin();
1172 it != keyboard_listeners_.end(); ++it) {
1173 if ((*it)->HandleKeyPressEvent(event))
1174 return true;
1175 }
1176
1177 return false;
1178 }
1179
1180 void RenderWidgetHostImpl::AddKeyboardListener(KeyboardListener* listener) { 1171 void RenderWidgetHostImpl::AddKeyboardListener(KeyboardListener* listener) {
1181 keyboard_listeners_.push_back(listener); 1172 keyboard_listeners_.push_back(listener);
1182 } 1173 }
1183 1174
1184 void RenderWidgetHostImpl::RemoveKeyboardListener( 1175 void RenderWidgetHostImpl::RemoveKeyboardListener(
1185 KeyboardListener* listener) { 1176 KeyboardListener* listener) {
1186 keyboard_listeners_.remove(listener); 1177 keyboard_listeners_.remove(listener);
1187 } 1178 }
1188 1179
1189 void RenderWidgetHostImpl::NotifyScreenInfoChanged() { 1180 void RenderWidgetHostImpl::NotifyScreenInfoChanged() {
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 } 2070 }
2080 2071
2081 void RenderWidgetHostImpl::Replace(const string16& word) { 2072 void RenderWidgetHostImpl::Replace(const string16& word) {
2082 Send(new ViewMsg_Replace(routing_id_, word)); 2073 Send(new ViewMsg_Replace(routing_id_, word));
2083 } 2074 }
2084 2075
2085 void RenderWidgetHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { 2076 void RenderWidgetHostImpl::SetIgnoreInputEvents(bool ignore_input_events) {
2086 ignore_input_events_ = ignore_input_events; 2077 ignore_input_events_ = ignore_input_events;
2087 } 2078 }
2088 2079
2080 bool RenderWidgetHostImpl::KeyPressListenersHandleEvent(
2081 const NativeWebKeyboardEvent& event) {
2082 if (event.skip_in_browser || event.type != WebKeyboardEvent::RawKeyDown)
2083 return false;
2084
2085 for (std::list<KeyboardListener*>::iterator it = keyboard_listeners_.begin();
2086 it != keyboard_listeners_.end(); ++it) {
2087 if ((*it)->HandleKeyPressEvent(event))
2088 return true;
2089 }
2090
2091 return false;
2092 }
2093
2089 void RenderWidgetHostImpl::ProcessKeyboardEventAck(int type, bool processed) { 2094 void RenderWidgetHostImpl::ProcessKeyboardEventAck(int type, bool processed) {
2090 if (key_queue_.empty()) { 2095 if (key_queue_.empty()) {
2091 LOG(ERROR) << "Got a KeyEvent back from the renderer but we " 2096 LOG(ERROR) << "Got a KeyEvent back from the renderer but we "
2092 << "don't seem to have sent it to the renderer!"; 2097 << "don't seem to have sent it to the renderer!";
2093 } else if (key_queue_.front().type != type) { 2098 } else if (key_queue_.front().type != type) {
2094 LOG(ERROR) << "We seem to have a different key type sent from " 2099 LOG(ERROR) << "We seem to have a different key type sent from "
2095 << "the renderer. (" << key_queue_.front().type << " vs. " 2100 << "the renderer. (" << key_queue_.front().type << " vs. "
2096 << type << "). Ignoring event."; 2101 << type << "). Ignoring event.";
2097 2102
2098 // Something must be wrong. Clear the |key_queue_| and 2103 // Something must be wrong. Clear the |key_queue_| and
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 return; 2336 return;
2332 2337
2333 OnRenderAutoResized(new_size); 2338 OnRenderAutoResized(new_size);
2334 } 2339 }
2335 2340
2336 void RenderWidgetHostImpl::DetachDelegate() { 2341 void RenderWidgetHostImpl::DetachDelegate() {
2337 delegate_ = NULL; 2342 delegate_ = NULL;
2338 } 2343 }
2339 2344
2340 } // namespace content 2345 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/renderer_host/render_widget_host_view_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698