Commit a49fb9bf authored by isherman@chromium.org's avatar isherman@chromium.org

Centralize keypress listener handling in non-platform-specific code.

This moves the GTK- and Views-specific code for alerting RenderWidgetHostView keypress listeners of keypress events into the shared method RenderWidgetHostImpl::ForwardKeyboardEvent() that all implementations bottleneck through.

Also updates RenderWidgetHostImpl::KeyPressListenersHandleEvent() to ignore events with the skip_in_browser flag set.

BUG=51644


Review URL: https://chromiumcodereview.appspot.com/11779035

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175691 0039d316-1c4b-4281-b951-d872f2087c98
parent 4c0e3d72
...@@ -1033,6 +1033,11 @@ void RenderWidgetHostImpl::ForwardKeyboardEvent( ...@@ -1033,6 +1033,11 @@ void RenderWidgetHostImpl::ForwardKeyboardEvent(
if (ignore_input_events_ || process_->IgnoreInputEvents()) if (ignore_input_events_ || process_->IgnoreInputEvents())
return; return;
// First, let keypress listeners take a shot at handling the event. If a
// listener handles the event, it should not be propagated to the renderer.
if (KeyPressListenersHandleEvent(key_event))
return;
if (key_event.type == WebKeyboardEvent::Char && if (key_event.type == WebKeyboardEvent::Char &&
(key_event.windowsKeyCode == ui::VKEY_RETURN || (key_event.windowsKeyCode == ui::VKEY_RETURN ||
key_event.windowsKeyCode == ui::VKEY_SPACE)) { key_event.windowsKeyCode == ui::VKEY_SPACE)) {
...@@ -1163,20 +1168,6 @@ void RenderWidgetHostImpl::ForwardTouchEvent( ...@@ -1163,20 +1168,6 @@ void RenderWidgetHostImpl::ForwardTouchEvent(
touch_event_queue_->QueueEvent(touch_event); touch_event_queue_->QueueEvent(touch_event);
} }
bool RenderWidgetHostImpl::KeyPressListenersHandleEvent(
const NativeWebKeyboardEvent& event) {
if (event.type != WebKeyboardEvent::RawKeyDown)
return false;
for (std::list<KeyboardListener*>::iterator it = keyboard_listeners_.begin();
it != keyboard_listeners_.end(); ++it) {
if ((*it)->HandleKeyPressEvent(event))
return true;
}
return false;
}
void RenderWidgetHostImpl::AddKeyboardListener(KeyboardListener* listener) { void RenderWidgetHostImpl::AddKeyboardListener(KeyboardListener* listener) {
keyboard_listeners_.push_back(listener); keyboard_listeners_.push_back(listener);
} }
...@@ -2086,6 +2077,20 @@ void RenderWidgetHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { ...@@ -2086,6 +2077,20 @@ void RenderWidgetHostImpl::SetIgnoreInputEvents(bool ignore_input_events) {
ignore_input_events_ = ignore_input_events; ignore_input_events_ = ignore_input_events;
} }
bool RenderWidgetHostImpl::KeyPressListenersHandleEvent(
const NativeWebKeyboardEvent& event) {
if (event.skip_in_browser || event.type != WebKeyboardEvent::RawKeyDown)
return false;
for (std::list<KeyboardListener*>::iterator it = keyboard_listeners_.begin();
it != keyboard_listeners_.end(); ++it) {
if ((*it)->HandleKeyPressEvent(event))
return true;
}
return false;
}
void RenderWidgetHostImpl::ProcessKeyboardEventAck(int type, bool processed) { void RenderWidgetHostImpl::ProcessKeyboardEventAck(int type, bool processed) {
if (key_queue_.empty()) { if (key_queue_.empty()) {
LOG(ERROR) << "Got a KeyEvent back from the renderer but we " LOG(ERROR) << "Got a KeyEvent back from the renderer but we "
......
...@@ -247,10 +247,6 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, ...@@ -247,10 +247,6 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost,
void ForwardGestureEventImmediately( void ForwardGestureEventImmediately(
const WebKit::WebGestureEvent& gesture_event); const WebKit::WebGestureEvent& gesture_event);
// Give key press listeners a chance to handle this key press. This allow
// widgets that don't have focus to still handle key presses.
bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
void CancelUpdateTextDirection(); void CancelUpdateTextDirection();
// Called when a mouse click/gesture tap activates the renderer. // Called when a mouse click/gesture tap activates the renderer.
...@@ -644,6 +640,10 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, ...@@ -644,6 +640,10 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost,
const gfx::Rect& clip_rect, const gfx::Rect& clip_rect,
const gfx::Size& view_size); const gfx::Size& view_size);
// Give key press listeners a chance to handle this key press. This allow
// widgets that don't have focus to still handle key presses.
bool KeyPressListenersHandleEvent(const NativeWebKeyboardEvent& event);
// Called by OnInputEventAck() to process a keyboard event ack message. // Called by OnInputEventAck() to process a keyboard event ack message.
void ProcessKeyboardEventAck(int type, bool processed); void ProcessKeyboardEventAck(int type, bool processed);
......
...@@ -224,11 +224,6 @@ class RenderWidgetHostViewGtkWidget { ...@@ -224,11 +224,6 @@ class RenderWidgetHostViewGtkWidget {
host_view->is_fullscreen_; host_view->is_fullscreen_;
if (should_close_on_escape && GDK_Escape == event->keyval) { if (should_close_on_escape && GDK_Escape == event->keyval) {
host_view->host_->Shutdown(); host_view->host_->Shutdown();
} else if (host_view->host_ &&
host_view->host_->KeyPressListenersHandleEvent(
NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(
event)))) {
return TRUE;
} else { } else {
// Send key event to input method. // Send key event to input method.
host_view->im_context_->ProcessKeyEvent(event); host_view->im_context_->ProcessKeyEvent(event);
......
...@@ -1823,15 +1823,10 @@ LRESULT RenderWidgetHostViewWin::OnKeyEvent(UINT message, WPARAM wparam, ...@@ -1823,15 +1823,10 @@ LRESULT RenderWidgetHostViewWin::OnKeyEvent(UINT message, WPARAM wparam,
} }
} }
MSG msg = { m_hWnd, message, wparam, lparam }; if (render_widget_host_ && !ignore_keyboard_event) {
ui::KeyEvent key_event(msg, message == WM_CHAR); MSG msg = { m_hWnd, message, wparam, lparam };
if (render_widget_host_ &&
render_widget_host_->KeyPressListenersHandleEvent(
NativeWebKeyboardEvent(msg)))
return 0;
if (render_widget_host_ && !ignore_keyboard_event)
render_widget_host_->ForwardKeyboardEvent(NativeWebKeyboardEvent(msg)); render_widget_host_->ForwardKeyboardEvent(NativeWebKeyboardEvent(msg));
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment