| 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..8a794db30bd969150ab2b97dd3527870563fdd85
|
| --- /dev/null
|
| +++ b/ui/aura_shell/input_method_event_filter.cc
|
| @@ -0,0 +1,98 @@
|
| +// 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/client/aura_constants.h"
|
| +#include "ui/aura/event.h"
|
| +#include "ui/aura/root_window.h"
|
| +#include "ui/aura_shell/shell.h"
|
| +#include "ui/base/ime/input_method.h"
|
| +#include "ui/base/ime/input_method_factory.h"
|
| +
|
| +namespace aura_shell {
|
| +namespace internal {
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// InputMethodEventFilter, public:
|
| +
|
| +InputMethodEventFilter::InputMethodEventFilter()
|
| + : EventFilter(aura::RootWindow::GetInstance()),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(
|
| + input_method_(ui::CreateInputMethod(this))),
|
| + root_window_destroyed_(false) {
|
| + aura::RootWindow* root_window = aura::RootWindow::GetInstance();
|
| +
|
| + // TODO(yusukes): Check if the root window is currently focused and pass the
|
| + // result to Init().
|
| + input_method_->Init(true);
|
| + root_window->SetProperty(aura::kRootWindowInputMethod, input_method_.get());
|
| + root_window->AddObserver(this);
|
| +}
|
| +
|
| +InputMethodEventFilter::~InputMethodEventFilter() {
|
| + if (root_window_destroyed_) {
|
| + // On Linux and Chrome OS, RootWindow is deleted before this function is
|
| + // called (see RootWindowHostLinux::WillDestroyCurrentMessageLoop in for
|
| + // details). In this case, calling RootWindow::GetInstance here results in
|
| + // regeneration of the singleton which is not what we want to do.
|
| + return;
|
| + }
|
| + aura::RootWindow* root_window = aura::RootWindow::GetInstance();
|
| + root_window->SetProperty(aura::kRootWindowInputMethod, NULL);
|
| + root_window->RemoveObserver(this);
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// InputMethodEventFilter, EventFilter implementation:
|
| +
|
| +bool InputMethodEventFilter::PreHandleKeyEvent(aura::Window* target,
|
| + aura::KeyEvent* event) {
|
| + input_method_->DispatchKeyEvent(event->native_event());
|
| + return true;
|
| +}
|
| +
|
| +bool InputMethodEventFilter::PreHandleTranslatedKeyEvent(
|
| + aura::Window* target,
|
| + aura::TranslatedKeyEvent* event) {
|
| + return false;
|
| +}
|
| +
|
| +bool InputMethodEventFilter::PreHandleMouseEvent(aura::Window* target,
|
| + aura::MouseEvent* event) {
|
| + return false;
|
| +}
|
| +
|
| +ui::TouchStatus InputMethodEventFilter::PreHandleTouchEvent(
|
| + aura::Window* target,
|
| + aura::TouchEvent* event) {
|
| + return ui::TOUCH_STATUS_UNKNOWN;
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// InputMethodEventFilter, ui::InputMethodDelegate implementation:
|
| +
|
| +void InputMethodEventFilter::DispatchKeyEventPostIME(
|
| + const base::NativeEvent& event) {
|
| + aura::TranslatedKeyEvent aura_event(event, false /* is_char */);
|
| + aura::RootWindow::GetInstance()->DispatchTranslatedKeyEvent(&aura_event);
|
| +}
|
| +
|
| +void InputMethodEventFilter::DispatchFabricatedKeyEventPostIME(
|
| + ui::EventType type,
|
| + ui::KeyboardCode key_code,
|
| + int flags) {
|
| + aura::TranslatedKeyEvent aura_event(type, key_code, flags);
|
| + aura::RootWindow::GetInstance()->DispatchTranslatedKeyEvent(&aura_event);
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// InputMethodEventFilter, aura::WindowObserver implementation:
|
| +
|
| +void InputMethodEventFilter::OnWindowDestroyed(aura::Window* window) {
|
| + root_window_destroyed_ = true;
|
| +}
|
| +
|
| +} // namespace internal
|
| +} // namespace aura_shell
|
|
|