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

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: 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 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 void RenderWidgetHostImpl::ForwardGestureEventImmediately( 1023 void RenderWidgetHostImpl::ForwardGestureEventImmediately(
1024 const WebKit::WebGestureEvent& gesture_event) { 1024 const WebKit::WebGestureEvent& gesture_event) {
1025 if (ignore_input_events_ || process_->IgnoreInputEvents()) 1025 if (ignore_input_events_ || process_->IgnoreInputEvents())
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
1034 // First, let keypress listeners take a shot at handling the event. If a
1035 // listener handles the event, it should not be propagated to the renderer.
1036 if (KeyPressListenersHandleEvent(key_event))
Evan Stade 2013/01/08 20:54:56 should this come after the ignore input events che
Ilya Sherman 2013/01/08 21:01:45 Yeah, I wasn't sure either... but after some more
1037 return;
1038
1033 if (ignore_input_events_ || process_->IgnoreInputEvents()) 1039 if (ignore_input_events_ || process_->IgnoreInputEvents())
1034 return; 1040 return;
1035 1041
1036 if (key_event.type == WebKeyboardEvent::Char && 1042 if (key_event.type == WebKeyboardEvent::Char &&
1037 (key_event.windowsKeyCode == ui::VKEY_RETURN || 1043 (key_event.windowsKeyCode == ui::VKEY_RETURN ||
1038 key_event.windowsKeyCode == ui::VKEY_SPACE)) { 1044 key_event.windowsKeyCode == ui::VKEY_SPACE)) {
1039 OnUserGesture(); 1045 OnUserGesture();
1040 } 1046 }
1041 1047
1042 // Double check the type to make sure caller hasn't sent us nonsense that 1048 // Double check the type to make sure caller hasn't sent us nonsense that
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 1162
1157 StartHangMonitorTimeout( 1163 StartHangMonitorTimeout(
1158 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); 1164 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_));
1159 } 1165 }
1160 1166
1161 void RenderWidgetHostImpl::ForwardTouchEvent( 1167 void RenderWidgetHostImpl::ForwardTouchEvent(
1162 const WebKit::WebTouchEvent& touch_event) { 1168 const WebKit::WebTouchEvent& touch_event) {
1163 touch_event_queue_->QueueEvent(touch_event); 1169 touch_event_queue_->QueueEvent(touch_event);
1164 } 1170 }
1165 1171
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) { 1172 void RenderWidgetHostImpl::AddKeyboardListener(KeyboardListener* listener) {
1181 keyboard_listeners_.push_back(listener); 1173 keyboard_listeners_.push_back(listener);
1182 } 1174 }
1183 1175
1184 void RenderWidgetHostImpl::RemoveKeyboardListener( 1176 void RenderWidgetHostImpl::RemoveKeyboardListener(
1185 KeyboardListener* listener) { 1177 KeyboardListener* listener) {
1186 keyboard_listeners_.remove(listener); 1178 keyboard_listeners_.remove(listener);
1187 } 1179 }
1188 1180
1189 void RenderWidgetHostImpl::NotifyScreenInfoChanged() { 1181 void RenderWidgetHostImpl::NotifyScreenInfoChanged() {
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 } 2071 }
2080 2072
2081 void RenderWidgetHostImpl::Replace(const string16& word) { 2073 void RenderWidgetHostImpl::Replace(const string16& word) {
2082 Send(new ViewMsg_Replace(routing_id_, word)); 2074 Send(new ViewMsg_Replace(routing_id_, word));
2083 } 2075 }
2084 2076
2085 void RenderWidgetHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { 2077 void RenderWidgetHostImpl::SetIgnoreInputEvents(bool ignore_input_events) {
2086 ignore_input_events_ = ignore_input_events; 2078 ignore_input_events_ = ignore_input_events;
2087 } 2079 }
2088 2080
2081 bool RenderWidgetHostImpl::KeyPressListenersHandleEvent(
2082 const NativeWebKeyboardEvent& event) {
2083 if (event.skip_in_browser || event.type != WebKeyboardEvent::RawKeyDown)
2084 return false;
2085
2086 for (std::list<KeyboardListener*>::iterator it = keyboard_listeners_.begin();
2087 it != keyboard_listeners_.end(); ++it) {
2088 if ((*it)->HandleKeyPressEvent(event))
2089 return true;
2090 }
2091
2092 return false;
2093 }
2094
2089 void RenderWidgetHostImpl::ProcessKeyboardEventAck(int type, bool processed) { 2095 void RenderWidgetHostImpl::ProcessKeyboardEventAck(int type, bool processed) {
2090 if (key_queue_.empty()) { 2096 if (key_queue_.empty()) {
2091 LOG(ERROR) << "Got a KeyEvent back from the renderer but we " 2097 LOG(ERROR) << "Got a KeyEvent back from the renderer but we "
2092 << "don't seem to have sent it to the renderer!"; 2098 << "don't seem to have sent it to the renderer!";
2093 } else if (key_queue_.front().type != type) { 2099 } else if (key_queue_.front().type != type) {
2094 LOG(ERROR) << "We seem to have a different key type sent from " 2100 LOG(ERROR) << "We seem to have a different key type sent from "
2095 << "the renderer. (" << key_queue_.front().type << " vs. " 2101 << "the renderer. (" << key_queue_.front().type << " vs. "
2096 << type << "). Ignoring event."; 2102 << type << "). Ignoring event.";
2097 2103
2098 // Something must be wrong. Clear the |key_queue_| and 2104 // Something must be wrong. Clear the |key_queue_| and
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 return; 2337 return;
2332 2338
2333 OnRenderAutoResized(new_size); 2339 OnRenderAutoResized(new_size);
2334 } 2340 }
2335 2341
2336 void RenderWidgetHostImpl::DetachDelegate() { 2342 void RenderWidgetHostImpl::DetachDelegate() {
2337 delegate_ = NULL; 2343 delegate_ = NULL;
2338 } 2344 }
2339 2345
2340 } // namespace content 2346 } // 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