diff options
author | suzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 07:22:48 +0000 |
---|---|---|
committer | suzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-10 07:22:48 +0000 |
commit | 4467058769b543946faf628c3b20a0803ca3f061 (patch) | |
tree | f4011c5e25465f291de65e72f688a46ad2b6677d /webkit | |
parent | 85f07ece0d4e006389f238c804e77b0496c02c30 (diff) | |
download | chromium_src-4467058769b543946faf628c3b20a0803ca3f061.zip chromium_src-4467058769b543946faf628c3b20a0803ca3f061.tar.gz chromium_src-4467058769b543946faf628c3b20a0803ca3f061.tar.bz2 |
Supports Gtk keyboard themes.
This CL fixes issue 11480: Support GTK keyboard themes (emacs keybindings).
A new class GtkKeyBindingsHandler has been added, which matches a key event against key bindings defined in current Gtk keyboard theme.
A new render message ViewMsg_SetEditCommandsForNextKeyEvent has been added for sending edit commands associated to a key event to renderer. This message shall be sent just before sending the key event. RenderView will handle this event and cache the edit commands until the key event is processed.
When processing the key event, EditClientImpl::handleKeyboardEvent() will eventually be called to handle the key event, if it's not handled by DOM and the focus is inside an input box. Then a newly added method WebViewDelegate::ExecuteEditCommandsForCurrentKeyEvent(), which is implemented in RenderView, will be called by EditClientImpl::handleKeyboardEvent() to execute edit commands previously sent from browser by ViewMsg_SetEditCommandsForNextKeyEvent message. If WebViewDelegate::ExecuteEditCommandsForCurrentKeyEvent() returns false, which means the key event doesn't have edit command associated, EditClientImpl will handle the key event with built-in logic, which may trigger a built-in key binding.
With this approach, system defined key bindings always have higher priority than built-in key bindings defined in editor_client_impl.cc.
Known issue:
If a key event matches not only a system defined key binding but also an accesskey of a DOM element, then both corresponding edit commands and accesskey action will be executed. Because accesskey is handled in WebViewImpl::CharEvent(), while edit commands are bound to RawKeyDown or KeyUp events.
BUG=11480 "Support GTK keyboard themes (emacs keybindings)"
TEST=Switch to Emacs keyboard theme by changing the value of gconf key
"/desktop/gnome/interface/gtk_key_theme" to "Emacs", then starts chrome and
opens a webpage with a text input box. Input something into the text box, then
press any of the Emacs key bindings defined in
/usr/share/themes/Emacs/gtk-2.0-key/gtkrc, to see if it works as expected. For
example, ctrl-p should move the cursor up one line, and ctrl-k should delete to
the end of paragraph.
Review URL: http://codereview.chromium.org/165293
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25852 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/editor_client_impl.cc | 6 | ||||
-rw-r--r-- | webkit/glue/webview_delegate.h | 13 | ||||
-rw-r--r-- | webkit/glue/webview_impl.cc | 11 |
3 files changed, 21 insertions, 9 deletions
diff --git a/webkit/glue/editor_client_impl.cc b/webkit/glue/editor_client_impl.cc index 4106ff6..e1187f7 100644 --- a/webkit/glue/editor_client_impl.cc +++ b/webkit/glue/editor_client_impl.cc @@ -643,7 +643,11 @@ void EditorClientImpl::handleKeyboardEvent(WebCore::KeyboardEvent* evt) { ShowFormAutofillForNode(evt->target()->toNode()); } - if (handleEditingKeyboardEvent(evt)) + // Calls WebViewDelegate's HandleCurrentKeyboardEvent() first to give it a + // chance to handle the keyboard event. Bypass handleEditingKeyboardEvent(), + // if WebViewDelegate handles the event. + WebViewDelegate* d = web_view_->delegate(); + if ((d && d->HandleCurrentKeyboardEvent()) || handleEditingKeyboardEvent(evt)) evt->setDefaultHandled(); } diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index c5c6b6a..2e4c333 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -415,6 +415,19 @@ class WebViewDelegate : virtual public WebKit::WebWidgetClient { // Called when an item was added to the history virtual void DidAddHistoryItem() { } + // The "CurrentKeyboardEvent" refers to the keyboard event passed to + // WebView's handleInputEvent method. + // + // This method is called in response to WebView's handleInputEvent() when + // the default action for the current keyboard event is not suppressed by the + // page, to give WebViewDelegate a chance to handle the keyboard event + // specially. + // + // Returns true if the keyboard event was handled by WebViewDelegate. + virtual bool HandleCurrentKeyboardEvent() { + return false; + } + protected: ~WebViewDelegate() { } }; diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index f82c6c7..2ff98d2 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -635,15 +635,10 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) { PlatformKeyboardEventBuilder evt(event); - if (WebInputEvent::RawKeyDown == event.type) { - if (handler->keyEvent(evt) && !evt.isSystemKey()) { + if (handler->keyEvent(evt)) { + if (WebInputEvent::RawKeyDown == event.type && !evt.isSystemKey()) suppress_next_keypress_event_ = true; - return true; - } - } else { - if (handler->keyEvent(evt)) { - return true; - } + return true; } return KeyEventDefault(event); |