This source file includes following definitions.
- target_dispatcher_
- SetInputMethodPropertyInRootWindow
- OnKeyEvent
- DispatchKeyEventPostIME
#include "ui/wm/core/input_method_event_filter.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h"
#include "ui/events/event.h"
#include "ui/events/event_processor.h"
namespace wm {
InputMethodEventFilter::InputMethodEventFilter(gfx::AcceleratedWidget widget)
: input_method_(ui::CreateInputMethod(this, widget)),
target_dispatcher_(NULL) {
input_method_->Init(true);
}
InputMethodEventFilter::~InputMethodEventFilter() {
}
void InputMethodEventFilter::SetInputMethodPropertyInRootWindow(
aura::Window* root_window) {
root_window->SetProperty(aura::client::kRootWindowInputMethodKey,
input_method_.get());
}
void InputMethodEventFilter::OnKeyEvent(ui::KeyEvent* event) {
const ui::EventType type = event->type();
if (type == ui::ET_TRANSLATED_KEY_PRESS ||
type == ui::ET_TRANSLATED_KEY_RELEASE) {
static_cast<ui::TranslatedKeyEvent*>(event)->ConvertToKeyEvent();
} else {
aura::Window* target = static_cast<aura::Window*>(event->target());
target_dispatcher_ = target->GetRootWindow()->GetHost()->event_processor();
DCHECK(target_dispatcher_);
if (input_method_->DispatchKeyEvent(*event))
event->StopPropagation();
}
}
bool InputMethodEventFilter::DispatchKeyEventPostIME(
const ui::KeyEvent& event) {
#if defined(OS_WIN)
DCHECK(!event.HasNativeEvent() || event.native_event().message != WM_CHAR);
#endif
ui::TranslatedKeyEvent aura_event(event);
ui::EventDispatchDetails details =
target_dispatcher_->OnEventFromSource(&aura_event);
CHECK(!details.dispatcher_destroyed);
return aura_event.handled();
}
}