diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-09 03:24:55 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-09 03:24:55 +0000 |
commit | a49fb9bf90643ad5c1b4f91385f8f978235949ce (patch) | |
tree | 61faae589a384c651b1843bc5e971806632b935a | |
parent | 4c0e3d72a5ccdc72aace7e29f3d7458eaf5b7224 (diff) | |
download | chromium_src-a49fb9bf90643ad5c1b4f91385f8f978235949ce.zip chromium_src-a49fb9bf90643ad5c1b4f91385f8f978235949ce.tar.gz chromium_src-a49fb9bf90643ad5c1b4f91385f8f978235949ce.tar.bz2 |
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
4 files changed, 26 insertions, 31 deletions
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc index be9a489..d433291 100644 --- a/content/browser/renderer_host/render_widget_host_impl.cc +++ b/content/browser/renderer_host/render_widget_host_impl.cc @@ -1033,6 +1033,11 @@ void RenderWidgetHostImpl::ForwardKeyboardEvent( if (ignore_input_events_ || process_->IgnoreInputEvents()) 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 && (key_event.windowsKeyCode == ui::VKEY_RETURN || key_event.windowsKeyCode == ui::VKEY_SPACE)) { @@ -1163,20 +1168,6 @@ void RenderWidgetHostImpl::ForwardTouchEvent( 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) { keyboard_listeners_.push_back(listener); } @@ -2086,6 +2077,20 @@ void RenderWidgetHostImpl::SetIgnoreInputEvents(bool 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) { if (key_queue_.empty()) { LOG(ERROR) << "Got a KeyEvent back from the renderer but we " diff --git a/content/browser/renderer_host/render_widget_host_impl.h b/content/browser/renderer_host/render_widget_host_impl.h index 7549ac2..1d8e4df 100644 --- a/content/browser/renderer_host/render_widget_host_impl.h +++ b/content/browser/renderer_host/render_widget_host_impl.h @@ -247,10 +247,6 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, void ForwardGestureEventImmediately( 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(); // Called when a mouse click/gesture tap activates the renderer. @@ -644,6 +640,10 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, const gfx::Rect& clip_rect, 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. void ProcessKeyboardEventAck(int type, bool processed); diff --git a/content/browser/renderer_host/render_widget_host_view_gtk.cc b/content/browser/renderer_host/render_widget_host_view_gtk.cc index 2562912..ebf1fb9 100644 --- a/content/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/content/browser/renderer_host/render_widget_host_view_gtk.cc @@ -224,11 +224,6 @@ class RenderWidgetHostViewGtkWidget { host_view->is_fullscreen_; if (should_close_on_escape && GDK_Escape == event->keyval) { host_view->host_->Shutdown(); - } else if (host_view->host_ && - host_view->host_->KeyPressListenersHandleEvent( - NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>( - event)))) { - return TRUE; } else { // Send key event to input method. host_view->im_context_->ProcessKeyEvent(event); diff --git a/content/browser/renderer_host/render_widget_host_view_win.cc b/content/browser/renderer_host/render_widget_host_view_win.cc index 7e6c598..ae30134 100644 --- a/content/browser/renderer_host/render_widget_host_view_win.cc +++ b/content/browser/renderer_host/render_widget_host_view_win.cc @@ -1823,15 +1823,10 @@ LRESULT RenderWidgetHostViewWin::OnKeyEvent(UINT message, WPARAM wparam, } } - MSG msg = { m_hWnd, message, wparam, lparam }; - ui::KeyEvent key_event(msg, message == WM_CHAR); - if (render_widget_host_ && - render_widget_host_->KeyPressListenersHandleEvent( - NativeWebKeyboardEvent(msg))) - return 0; - - if (render_widget_host_ && !ignore_keyboard_event) + if (render_widget_host_ && !ignore_keyboard_event) { + MSG msg = { m_hWnd, message, wparam, lparam }; render_widget_host_->ForwardKeyboardEvent(NativeWebKeyboardEvent(msg)); + } return 0; } |