Commit e0a5b1e2 authored by sadrul's avatar sadrul Committed by Commit bot

aura: Fix IME interaction in content-shell in chromeos build.

Make sure the key events received by the aura::WindowTreeHost instance goes
through the IME, so that text input works correctly.

BUG=629596

Review-Url: https://codereview.chromium.org/2166863002
Cr-Commit-Position: refs/heads/master@{#406740}
parent f192a075
...@@ -162,6 +162,8 @@ static_library("test_support") { ...@@ -162,6 +162,8 @@ static_library("test_support") {
"test/env_test_helper.h", "test/env_test_helper.h",
"test/event_generator_delegate_aura.cc", "test/event_generator_delegate_aura.cc",
"test/event_generator_delegate_aura.h", "test/event_generator_delegate_aura.h",
"test/input_method_glue.cc",
"test/input_method_glue.h",
"test/test_cursor_client.cc", "test/test_cursor_client.cc",
"test/test_cursor_client.h", "test/test_cursor_client.h",
"test/test_focus_client.cc", "test/test_focus_client.cc",
......
...@@ -179,6 +179,8 @@ ...@@ -179,6 +179,8 @@
'test/env_test_helper.h', 'test/env_test_helper.h',
'test/event_generator_delegate_aura.cc', 'test/event_generator_delegate_aura.cc',
'test/event_generator_delegate_aura.h', 'test/event_generator_delegate_aura.h',
'test/input_method_glue.cc',
'test/input_method_glue.h',
'test/test_cursor_client.cc', 'test/test_cursor_client.cc',
'test/test_cursor_client.h', 'test/test_cursor_client.h',
'test/test_focus_client.cc', 'test/test_focus_client.cc',
......
// Copyright 2016 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/test/input_method_glue.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/input_method.h"
#include "ui/events/event.h"
namespace aura {
InputMethodGlue::InputMethodGlue(aura::WindowTreeHost* host) : host_(host) {
aura::Env::GetInstance()->AddPreTargetHandler(this);
host_->GetInputMethod()->SetDelegate(this);
}
InputMethodGlue::~InputMethodGlue() {
host_->GetInputMethod()->SetDelegate(host_);
aura::Env::GetInstance()->RemovePreTargetHandler(this);
}
void InputMethodGlue::OnKeyEvent(ui::KeyEvent* key) {
if (processing_ime_event_)
return;
host_->GetInputMethod()->DispatchKeyEvent(key);
key->StopPropagation();
}
ui::EventDispatchDetails InputMethodGlue::DispatchKeyEventPostIME(
ui::KeyEvent* key) {
base::AutoReset<bool> reset(&processing_ime_event_, true);
return host_->DispatchKeyEventPostIME(key);
}
} // namespace aura
// Copyright 2016 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.
#ifndef UI_AURA_TEST_INPUT_METHOD_GLUE_H_
#define UI_AURA_TEST_INPUT_METHOD_GLUE_H_
#include "ui/base/ime/input_method_delegate.h"
#include "ui/events/event_handler.h"
namespace aura {
class WindowTreeHost;
class InputMethodGlue : public ui::EventHandler,
public ui::internal::InputMethodDelegate {
public:
explicit InputMethodGlue(aura::WindowTreeHost* host);
~InputMethodGlue() override;
private:
// ui::EventHandler:
void OnKeyEvent(ui::KeyEvent* key) override;
// ui::internal::InputMethodDelegate:
ui::EventDispatchDetails DispatchKeyEventPostIME(ui::KeyEvent* key) override;
aura::WindowTreeHost* host_;
bool processing_ime_event_ = false;
DISALLOW_COPY_AND_ASSIGN(InputMethodGlue);
};
} // namespace aura
#endif // UI_AURA_TEST_INPUT_METHOD_GLUE_H_
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "ui/aura/client/default_capture_client.h" #include "ui/aura/client/default_capture_client.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/aura/test/input_method_glue.h"
#include "ui/aura/test/test_focus_client.h" #include "ui/aura/test/test_focus_client.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/wm/core/compound_event_filter.h" #include "ui/wm/core/compound_event_filter.h"
...@@ -18,6 +19,7 @@ WMTestHelper::WMTestHelper(const gfx::Size& default_window_size, ...@@ -18,6 +19,7 @@ WMTestHelper::WMTestHelper(const gfx::Size& default_window_size,
aura::Env::GetInstance()->set_context_factory(context_factory); aura::Env::GetInstance()->set_context_factory(context_factory);
host_.reset(aura::WindowTreeHost::Create(gfx::Rect(default_window_size))); host_.reset(aura::WindowTreeHost::Create(gfx::Rect(default_window_size)));
host_->InitHost(); host_->InitHost();
input_method_glue_.reset(new aura::InputMethodGlue(host_.get()));
aura::client::SetWindowTreeClient(host_->window(), this); aura::client::SetWindowTreeClient(host_->window(), this);
focus_client_.reset(new aura::test::TestFocusClient); focus_client_.reset(new aura::test::TestFocusClient);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
namespace aura { namespace aura {
class InputMethodGlue;
class Window; class Window;
class WindowTreeHost; class WindowTreeHost;
namespace client { namespace client {
...@@ -52,7 +53,7 @@ class WMTestHelper : public aura::client::WindowTreeClient { ...@@ -52,7 +53,7 @@ class WMTestHelper : public aura::client::WindowTreeClient {
private: private:
std::unique_ptr<aura::WindowTreeHost> host_; std::unique_ptr<aura::WindowTreeHost> host_;
std::unique_ptr<aura::InputMethodGlue> input_method_glue_;
std::unique_ptr<wm::CompoundEventFilter> root_window_event_filter_; std::unique_ptr<wm::CompoundEventFilter> root_window_event_filter_;
std::unique_ptr<aura::client::DefaultCaptureClient> capture_client_; std::unique_ptr<aura::client::DefaultCaptureClient> capture_client_;
std::unique_ptr<aura::client::FocusClient> focus_client_; std::unique_ptr<aura::client::FocusClient> focus_client_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment