Chromium Code Reviews| 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..cb2a24bf3bfe1868bf9f955002dc190a1ecb518e |
| --- /dev/null |
| +++ b/ui/aura_shell/input_method_event_filter.cc |
| @@ -0,0 +1,76 @@ |
| +// 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()) { |
| + ui::InputMethod* input_method; |
| +#if defined(HAVE_IBUS) |
| + input_method = new ui::InputMethodIBus(this); |
|
Ben Goodger (Google)
2011/12/12 16:51:03
I've seen this pattern (and the associated include
Yusuke Sato
2011/12/14 13:42:04
Done.
|
| +#else |
| + 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); |
| + // Pass ownership. |
| + aura::RootWindow::GetInstance()->SetInputMethod(input_method); |
| +} |
| + |
| +InputMethodEventFilter::~InputMethodEventFilter() { |
| +} |
| + |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// InputMethodEventFilter, EventFilter implementation: |
| + |
| +bool InputMethodEventFilter::PreHandleKeyEvent(aura::Window* target, |
| + aura::KeyEvent* event) { |
| + if (event->skip_ime()) |
| + return false; |
| + |
| + ui::InputMethod* input_method = |
| + aura::RootWindow::GetInstance()->GetInputMethod(); |
| + DCHECK(input_method); |
| + 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 |