summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsuzhe@google.com <suzhe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-13 23:28:59 +0000
committersuzhe@google.com <suzhe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-13 23:28:59 +0000
commit5dfa20bced5edc7a76e1ac285799fba86acf283c (patch)
tree8491cd760e07ef607576e0db35139c8b29c67204
parentf7942c4551c2dc8b116f9a58b824baf955728798 (diff)
downloadchromium_src-5dfa20bced5edc7a76e1ac285799fba86acf283c.zip
chromium_src-5dfa20bced5edc7a76e1ac285799fba86acf283c.tar.gz
chromium_src-5dfa20bced5edc7a76e1ac285799fba86acf283c.tar.bz2
[Linux] Workaround issue 45478: IME dysfunctional after BACKSPACE
The reason of the issue is ibus intercepts all key events and does not forward them to chrome at all, while webkit relies on key events to reset one of its internal flag. This CL just fakes key down/up events if the input method intercepts all key events. BUG=45478 TEST=see bug report. Review URL: http://codereview.chromium.org/5787004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69067 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/renderer_host/gtk_im_context_wrapper.cc48
-rw-r--r--chrome/browser/renderer_host/gtk_im_context_wrapper.h5
2 files changed, 38 insertions, 15 deletions
diff --git a/chrome/browser/renderer_host/gtk_im_context_wrapper.cc b/chrome/browser/renderer_host/gtk_im_context_wrapper.cc
index 25ec4f0..0c2002c 100644
--- a/chrome/browser/renderer_host/gtk_im_context_wrapper.cc
+++ b/chrome/browser/renderer_host/gtk_im_context_wrapper.cc
@@ -28,6 +28,22 @@
#include "grit/generated_resources.h"
#include "third_party/skia/include/core/SkColor.h"
+namespace {
+// Copied from third_party/WebKit/WebCore/page/EventHandler.cpp
+//
+// Match key code of composition keydown event on windows.
+// IE sends VK_PROCESSKEY which has value 229;
+//
+// Please refer to following documents for detals:
+// - Virtual-Key Codes
+// http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx
+// - How the IME System Works
+// http://msdn.microsoft.com/en-us/library/cc194848.aspx
+// - ImmGetVirtualKey Function
+// http://msdn.microsoft.com/en-us/library/dd318570(VS.85).aspx
+const int kCompositionEventKeyCode = 229;
+} // namespace
+
GtkIMContextWrapper::GtkIMContextWrapper(RenderWidgetHostViewGtk* host_view)
: host_view_(host_view),
context_(gtk_im_multicontext_new()),
@@ -317,20 +333,6 @@ bool GtkIMContextWrapper::NeedCommitByForwardingCharEvent() {
void GtkIMContextWrapper::ProcessFilteredKeyPressEvent(
NativeWebKeyboardEvent* wke) {
- // Copied from third_party/WebKit/WebCore/page/EventHandler.cpp
- //
- // Match key code of composition keydown event on windows.
- // IE sends VK_PROCESSKEY which has value 229;
- //
- // Please refer to following documents for detals:
- // - Virtual-Key Codes
- // http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx
- // - How the IME System Works
- // http://msdn.microsoft.com/en-us/library/cc194848.aspx
- // - ImmGetVirtualKey Function
- // http://msdn.microsoft.com/en-us/library/dd318570(VS.85).aspx
- const int kCompositionEventKeyCode = 229;
-
// If IME has filtered this event, then replace virtual key code with
// VK_PROCESSKEY. See comment in ProcessKeyEvent() for details.
// It's only required for keydown events.
@@ -450,8 +452,12 @@ void GtkIMContextWrapper::HandleCommit(const string16& text) {
// It's possible that commit signal is fired without a key event, for
// example when user input via a voice or handwriting recognition software.
// In this case, the text must be committed directly.
- if (!is_in_key_event_handler_ && host_view_->GetRenderWidgetHost())
+ if (!is_in_key_event_handler_ && host_view_->GetRenderWidgetHost()) {
+ // Workaround http://crbug.com/45478 by sending fake key down/up events.
+ SendFakeCompositionKeyEvent(WebKit::WebInputEvent::RawKeyDown);
host_view_->GetRenderWidgetHost()->ImeConfirmComposition(text);
+ SendFakeCompositionKeyEvent(WebKit::WebInputEvent::KeyUp);
+ }
}
void GtkIMContextWrapper::HandlePreeditStart() {
@@ -490,9 +496,12 @@ void GtkIMContextWrapper::HandlePreeditChanged(const gchar* text,
// Otherwise, we need send it here if it's been changed.
if (!is_in_key_event_handler_ && is_composing_text_ &&
host_view_->GetRenderWidgetHost()) {
+ // Workaround http://crbug.com/45478 by sending fake key down/up events.
+ SendFakeCompositionKeyEvent(WebKit::WebInputEvent::RawKeyDown);
host_view_->GetRenderWidgetHost()->ImeSetComposition(
preedit_text_, preedit_underlines_, preedit_selection_start_,
preedit_selection_end_);
+ SendFakeCompositionKeyEvent(WebKit::WebInputEvent::KeyUp);
}
}
@@ -529,6 +538,15 @@ void GtkIMContextWrapper::HandleHostViewUnrealize() {
gtk_im_context_set_client_window(context_simple_, NULL);
}
+void GtkIMContextWrapper::SendFakeCompositionKeyEvent(
+ WebKit::WebInputEvent::Type type) {
+ NativeWebKeyboardEvent fake_event;
+ fake_event.windowsKeyCode = kCompositionEventKeyCode;
+ fake_event.skip_in_browser = true;
+ fake_event.type = type;
+ host_view_->ForwardKeyboardEvent(fake_event);
+}
+
void GtkIMContextWrapper::HandleCommitThunk(
GtkIMContext* context, gchar* text, GtkIMContextWrapper* self) {
self->HandleCommit(UTF8ToUTF16(text));
diff --git a/chrome/browser/renderer_host/gtk_im_context_wrapper.h b/chrome/browser/renderer_host/gtk_im_context_wrapper.h
index 1538e26..94d6bfa 100644
--- a/chrome/browser/renderer_host/gtk_im_context_wrapper.h
+++ b/chrome/browser/renderer_host/gtk_im_context_wrapper.h
@@ -14,6 +14,7 @@
#include "base/gtest_prod_util.h"
#include "base/string16.h"
#include "third_party/WebKit/WebKit/chromium/public/WebCompositionUnderline.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h"
#include "third_party/WebKit/WebKit/chromium/public/WebTextInputType.h"
namespace gfx {
@@ -100,6 +101,10 @@ class GtkIMContextWrapper {
// client window.
void HandleHostViewUnrealize();
+ // Sends a fake composition key event with specified event type. A composition
+ // key event is a key event with special key code 229.
+ void SendFakeCompositionKeyEvent(WebKit::WebInputEvent::Type type);
+
// Signal handlers of GtkIMContext object.
static void HandleCommitThunk(GtkIMContext* context, gchar* text,
GtkIMContextWrapper* self);