summaryrefslogtreecommitdiffstats
path: root/views/ime
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 23:33:30 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 23:33:30 +0000
commit988ace29e4f1990cf22f7d9781049e0b14d3d5cd (patch)
tree24ed6ac562ae60944980dd45ea1394a0f5b01902 /views/ime
parent4776115ccf7fff738be23e7638248209ba00417c (diff)
downloadchromium_src-988ace29e4f1990cf22f7d9781049e0b14d3d5cd.zip
chromium_src-988ace29e4f1990cf22f7d9781049e0b14d3d5cd.tar.gz
chromium_src-988ace29e4f1990cf22f7d9781049e0b14d3d5cd.tar.bz2
Add NativeWidgetDelegate/Widget::OnKeyEvent post-IME handling.
Refactor XEvent code and InputMethodGtk::DispatchKeyEvent. Nix WidgetWin::GetFocusedViewRootView, rename RootView::OnKeyEvent. Cleanup headers and refactor code in extension_input_api.cc. BUG=72040 TEST=Key event handling in win/linux_views/touch; extension input API SendKeyboardEventInputFunction use. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=82713 Review URL: http://codereview.chromium.org/6823055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82751 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/ime')
-rw-r--r--views/ime/input_method_gtk.cc72
1 files changed, 27 insertions, 45 deletions
diff --git a/views/ime/input_method_gtk.cc b/views/ime/input_method_gtk.cc
index 023bcc6..07da18f 100644
--- a/views/ime/input_method_gtk.cc
+++ b/views/ime/input_method_gtk.cc
@@ -110,13 +110,13 @@ void InputMethodGtk::OnBlur() {
}
void InputMethodGtk::DispatchKeyEvent(const KeyEvent& key) {
+ DCHECK(key.type() == ui::ET_KEY_PRESSED || key.type() == ui::ET_KEY_RELEASED);
suppress_next_result_ = false;
// We should bypass |context_| and |context_simple_| only if there is no
- // text input client is focused at all. Otherwise, we should always send the
- // key event to either |context_| or |context_simple_| even if the text input
- // type is ui::TEXT_INPUT_TYPE_NONE, to make sure we can get correct character
- // result.
+ // text input client focused. Otherwise, always send the key event to either
+ // |context_| or |context_simple_| even if the text input type is
+ // ui::TEXT_INPUT_TYPE_NONE, to make sure we can get correct character result.
if (!GetTextInputClient()) {
DispatchKeyEventPostIME(key);
return;
@@ -126,22 +126,11 @@ void InputMethodGtk::DispatchKeyEvent(const KeyEvent& key) {
composition_changed_ = false;
result_text_.clear();
- GdkEvent* event = key.native_event();
- DCHECK(!event || event->type == GDK_KEY_PRESS ||
- event->type == GDK_KEY_RELEASE);
-
- // If it's a fake key event, then we need to synthesis a GdkEventKey.
- bool need_free_event = false;
- if (!event) {
- event = SynthesizeGdkEventKey(key);
- need_free_event = true;
- }
-
- gboolean filtered = false;
- if (context_focused_)
- filtered = gtk_im_context_filter_keypress(context_, &event->key);
- else
- filtered = gtk_im_context_filter_keypress(context_simple_, &event->key);
+ // If it's a fake key event, then we need to synthesize a GdkEventKey.
+ GdkEvent* event = key.native_event() ? key.native_event() :
+ SynthesizeGdkEventKey(key);
+ gboolean filtered = gtk_im_context_filter_keypress(
+ context_focused_ ? context_ : context_simple_, &event->key);
handling_key_event_ = false;
@@ -149,24 +138,21 @@ void InputMethodGtk::DispatchKeyEvent(const KeyEvent& key) {
if (key.type() == ui::ET_KEY_PRESSED && filtered)
ProcessFilteredKeyPressEvent(key);
- // In case the focus was changed by the key event.
- if (old_focused_view != focused_view())
- return;
-
- if (HasInputMethodResult())
- ProcessInputMethodResult(key, filtered);
-
- // In case the focus was changed when sending input method results to the
- // focused View.
- if (old_focused_view != focused_view())
- return;
-
- if (key.type() == ui::ET_KEY_PRESSED && !filtered)
- ProcessUnfilteredKeyPressEvent(key);
- else if (key.type() == ui::ET_KEY_RELEASED)
- DispatchKeyEventPostIME(key);
+ // Ensure no focus change from processing the key event.
+ if (old_focused_view == focused_view()) {
+ if (HasInputMethodResult())
+ ProcessInputMethodResult(key, filtered);
+ // Ensure no focus change sending input method results to the focused View.
+ if (old_focused_view == focused_view()) {
+ if (key.type() == ui::ET_KEY_PRESSED && !filtered)
+ ProcessUnfilteredKeyPressEvent(key);
+ else if (key.type() == ui::ET_KEY_RELEASED)
+ DispatchKeyEventPostIME(key);
+ }
+ }
- if (need_free_event)
+ // Free the synthesized event if there was no underlying native event.
+ if (event != key.native_event())
gdk_event_free(event);
}
@@ -360,14 +346,10 @@ GdkEvent* InputMethodGtk::SynthesizeGdkEventKey(const KeyEvent& key) const {
guint keyval =
ui::GdkKeyCodeForWindowsKeyCode(key.key_code(), key.IsShiftDown());
guint state = 0;
- if (key.IsShiftDown())
- state |= GDK_SHIFT_MASK;
- if (key.IsControlDown())
- state |= GDK_CONTROL_MASK;
- if (key.IsAltDown())
- state |= GDK_MOD1_MASK;
- if (key.IsCapsLockDown())
- state |= GDK_LOCK_MASK;
+ state |= key.IsShiftDown() ? GDK_SHIFT_MASK : 0;
+ state |= key.IsControlDown() ? GDK_CONTROL_MASK : 0;
+ state |= key.IsAltDown() ? GDK_MOD1_MASK : 0;
+ state |= key.IsCapsLockDown() ? GDK_LOCK_MASK : 0;
DCHECK(widget()->GetNativeView()->window);
return ui::SynthesizeKeyEvent(widget()->GetNativeView()->window,