diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 04:41:53 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-01 04:41:53 +0000 |
commit | feab536198e21e8f4777c3c8035a6ca6479f6912 (patch) | |
tree | 75d5f0578e2b101c3fb50568842711b87197e9c0 | |
parent | be61bb5c487f1020756c31a39fbe23535e4d425b (diff) | |
download | chromium_src-feab536198e21e8f4777c3c8035a6ca6479f6912.zip chromium_src-feab536198e21e8f4777c3c8035a6ca6479f6912.tar.gz chromium_src-feab536198e21e8f4777c3c8035a6ca6479f6912.tar.bz2 |
A quick fix for Issue 15531 and 10953
This issue is caused by my another mistake that I forgot setting the modifier-key state in creating a Char event in RenderWidgetHostViewGtkWidget::ForwardCharEvent().
Since the GtkIMContext signal-handlers don't use GdkEventKey objects and cannot get the modififer-key state, this change save the state in RenderWidgetHostViewGtkWidget::KeyPressReleaseEvent() before dispatching a key event to the GtkIMContext object.
Also, this change adds gtk_im_context_focus_in() and gtk_im_context_focus_out() calls to fix compatibility problems with ibus.
BUG=10953 "IME support"
BUG=15531 "regression: shift-space doesn't scroll the page backwards"
TEST=Open a test page in <http://crbug.com/15531>, press shift+space keys, and observe ev.shiftKey is true.
Review URL: http://codereview.chromium.org/151010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19707 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 38 insertions, 11 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc index 12185cf..1da195f 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc @@ -121,6 +121,11 @@ class RenderWidgetHostViewGtkWidget { host_view->GetRenderWidgetHost()->ForwardKeyboardEvent(wke); } + // Save the current modifier-key state before dispatching this event to the + // GtkIMContext object so its event handlers can use this state to create + // Char events. + host_view->im_modifier_state_ = event->state; + // Dispatch this event to the GtkIMContext object. // It sends a "commit" signal when it has a character to be inserted // even when we use a US keyboard so that we can send a Char event @@ -182,6 +187,15 @@ class RenderWidgetHostViewGtkWidget { host_view->ShowCurrentCursor(); host_view->GetRenderWidgetHost()->Focus(); + + // Notify the GtkIMContext object of this focus-in event and + // attach this GtkIMContext object to this window. + // We should call gtk_im_context_set_client_window() only when this window + // gain (or release) the window focus because an immodule may reset its + // internal status when processing this function. + gtk_im_context_focus_in(host_view->im_context_); + gtk_im_context_set_client_window(host_view->im_context_, + host_view->native_view()->window); return FALSE; } @@ -194,6 +208,11 @@ class RenderWidgetHostViewGtkWidget { // focus. if (!host_view->is_showing_context_menu_) host_view->GetRenderWidgetHost()->Blur(); + + // Notify the GtkIMContext object of this focus-in event and + // detach this GtkIMContext object from this window. + gtk_im_context_focus_out(host_view->im_context_); + gtk_im_context_set_client_window(host_view->im_context_, NULL); return FALSE; } @@ -319,6 +338,7 @@ class RenderWidgetHostViewGtkWidget { return; NativeWebKeyboardEvent char_event(im_character, + host_view->im_modifier_state_, base::Time::Now().ToDoubleT()); host_view->GetRenderWidgetHost()->ForwardKeyboardEvent(char_event); } @@ -342,7 +362,8 @@ RenderWidgetHostViewGtk::RenderWidgetHostViewGtk(RenderWidgetHost* widget_host) parent_(NULL), is_popup_first_mouse_release_(true), im_context_(NULL), - im_is_composing_cjk_text_(false) { + im_is_composing_cjk_text_(false), + im_modifier_state_(0) { host_->set_view(this); } @@ -514,19 +535,15 @@ void RenderWidgetHostViewGtk::IMEUpdateStatus(int control, return; if (control == IME_DISABLE) { - // TODO(hbono): this code just resets the GtkIMContext object and - // detaches it from this window. Should we prevent sending key events to - // the GtkIMContext object (or unref it) when we disable IMEs? + // TODO(hbono): this code just resets the GtkIMContext object. + // Should we prevent sending key events to the GtkIMContext object + // (or unref it) when we disable IMEs? gtk_im_context_reset(im_context_); - gtk_im_context_set_client_window(im_context_, NULL); gtk_im_context_set_cursor_location(im_context_, NULL); } else { // TODO(hbono): we should finish (not reset) an ongoing composition // when |control| is IME_COMPLETE_COMPOSITION. - // Attach the GtkIMContext object to this window. - gtk_im_context_set_client_window(im_context_, view_.get()->window); - // Updates the position of the IME candidate window. // The position sent from the renderer is a relative one, so we need to // attach the GtkIMContext object to this window before changing the diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.h b/chrome/browser/renderer_host/render_widget_host_view_gtk.h index e727e08..3df3006 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.h +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.h @@ -132,6 +132,11 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView { // composing Latin texts. So, we monitor the above signals to check whether // or not the GtkIMContext object is composing a CJK text. bool im_is_composing_cjk_text_; + + // Represents the current modifier-key state. + // This state is used when GtkIMContext signal handlers create Char events + // because they don't use the GdkEventKey objects and cannot get the state. + int im_modifier_state_; }; #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_ diff --git a/chrome/common/native_web_keyboard_event.h b/chrome/common/native_web_keyboard_event.h index 4c25979..021d061 100644 --- a/chrome/common/native_web_keyboard_event.h +++ b/chrome/common/native_web_keyboard_event.h @@ -31,7 +31,9 @@ struct NativeWebKeyboardEvent : public WebKit::WebKeyboardEvent { explicit NativeWebKeyboardEvent(NSEvent *event); #elif defined(OS_LINUX) explicit NativeWebKeyboardEvent(const GdkEventKey* event); - NativeWebKeyboardEvent(wchar_t character, double time_stamp_seconds); + NativeWebKeyboardEvent(wchar_t character, + int state, + double time_stamp_seconds); #endif NativeWebKeyboardEvent(const NativeWebKeyboardEvent& event); diff --git a/chrome/common/native_web_keyboard_event_linux.cc b/chrome/common/native_web_keyboard_event_linux.cc index 4ad74a3..6df2290 100644 --- a/chrome/common/native_web_keyboard_event_linux.cc +++ b/chrome/common/native_web_keyboard_event_linux.cc @@ -39,8 +39,10 @@ NativeWebKeyboardEvent::NativeWebKeyboardEvent(const GdkEventKey* native_event) } NativeWebKeyboardEvent::NativeWebKeyboardEvent(wchar_t character, + int state, double time_stamp_seconds) : WebKeyboardEvent(WebInputEventFactory::keyboardEvent(character, + state, time_stamp_seconds)), os_event(NULL) { } diff --git a/webkit/api/public/gtk/WebInputEventFactory.h b/webkit/api/public/gtk/WebInputEventFactory.h index cdc80ea..5fdfa97 100644 --- a/webkit/api/public/gtk/WebInputEventFactory.h +++ b/webkit/api/public/gtk/WebInputEventFactory.h @@ -47,7 +47,7 @@ namespace WebKit { class WebInputEventFactory { public: WEBKIT_API static WebKeyboardEvent keyboardEvent(const GdkEventKey*); - WEBKIT_API static WebKeyboardEvent keyboardEvent(wchar_t character, double timeStampSeconds); + WEBKIT_API static WebKeyboardEvent keyboardEvent(wchar_t character, int state, double timeStampSeconds); WEBKIT_API static WebMouseEvent mouseEvent(const GdkEventButton*); WEBKIT_API static WebMouseEvent mouseEvent(const GdkEventMotion*); WEBKIT_API static WebMouseWheelEvent mouseWheelEvent(const GdkEventScroll*); diff --git a/webkit/api/src/gtk/WebInputEventFactory.cpp b/webkit/api/src/gtk/WebInputEventFactory.cpp index 8086471..96ef4c8 100644 --- a/webkit/api/src/gtk/WebInputEventFactory.cpp +++ b/webkit/api/src/gtk/WebInputEventFactory.cpp @@ -214,7 +214,7 @@ WebKeyboardEvent WebInputEventFactory::keyboardEvent(const GdkEventKey* event) return result; } -WebKeyboardEvent WebInputEventFactory::keyboardEvent(wchar_t character, double timeStampSeconds) +WebKeyboardEvent WebInputEventFactory::keyboardEvent(wchar_t character, int state, double timeStampSeconds) { // keyboardEvent(const GdkEventKey*) depends on the GdkEventKey object and // it is hard to use/ it from signal handlers which don't use GdkEventKey @@ -224,6 +224,7 @@ WebKeyboardEvent WebInputEventFactory::keyboardEvent(wchar_t character, double t WebKeyboardEvent result; result.type = WebKit::WebInputEvent::Char; result.timeStampSeconds = timeStampSeconds; + result.modifiers = gdkStateToWebEventModifiers(state); result.windowsKeyCode = character; result.nativeKeyCode = character; result.text[0] = character; |