Index: ui/aura_shell/input_method_event_filter.cc |
diff --git a/ui/aura_shell/input_method_event_filter.cc b/ui/aura_shell/input_method_event_filter.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1e1e0873064e385a69d5cc3c052982610bf306d0 |
--- /dev/null |
+++ b/ui/aura_shell/input_method_event_filter.cc |
@@ -0,0 +1,74 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/aura_shell/input_method_event_filter.h" |
+ |
+#include "ui/aura/event.h" |
+#include "ui/aura/root_window.h" |
+#include "ui/aura_shell/shell.h" |
+ |
+#if defined(HAVE_IBUS) |
+#include "ui/base/ime/input_method_ibus.h" |
+#else |
+#include "ui/base/ime/mock_input_method.h" |
+#endif |
+ |
+namespace aura_shell { |
+namespace internal { |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// InputMethodEventFilter, public: |
+ |
+InputMethodEventFilter::InputMethodEventFilter() |
+ : EventFilter(aura::RootWindow::GetInstance()), |
+#if defined(HAVE_IBUS) |
+ ALLOW_THIS_IN_INITIALIZER_LIST( |
+ input_method_(new ui::InputMethodIBus(this))) |
+#else |
+ ALLOW_THIS_IN_INITIALIZER_LIST( |
+ input_method_(new ui::MockInputMethod(this))) |
+#endif |
+{ |
+ // TODO(yusukes): Check if the root window is currently focused and pass the |
+ // result to Init(). |
+ input_method_->Init(true); |
+ aura::RootWindow::GetInstance()->set_input_method(input_method_.get()); |
+} |
+ |
+InputMethodEventFilter::~InputMethodEventFilter() { |
+ aura::RootWindow::GetInstance()->set_input_method(NULL); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// InputMethodEventFilter, EventFilter implementation: |
+ |
+bool InputMethodEventFilter::PreHandleKeyEvent(aura::Window* target, |
+ aura::KeyEvent* event) { |
+ if (event->skip_ime()) |
+ return false; |
+ input_method_->DispatchKeyEvent(event->native_event()); |
+ return true; |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// InputMethodEventFilter, ui::InputMethodDelegate implementation: |
+ |
+void InputMethodEventFilter::DispatchKeyEventPostIME( |
+ const base::NativeEvent& event) { |
+ aura::KeyEvent aura_event(event, false /* is_char */); |
+ aura_event.set_skip_ime(true); |
+ aura::RootWindow::GetInstance()->DispatchKeyEvent(&aura_event); |
+} |
+ |
+void InputMethodEventFilter::DispatchFabricatedKeyEventPostIME( |
+ ui::EventType type, |
+ ui::KeyboardCode key_code, |
+ int flags) { |
+ aura::KeyEvent aura_event(type, key_code, flags); |
+ aura_event.set_skip_ime(true); |
+ aura::RootWindow::GetInstance()->DispatchKeyEvent(&aura_event); |
+} |
+ |
+} // namespace internal |
+} // namespace aura_shell |