Chromium Code Reviews| Index: ui/aura/window_tree_host.cc |
| diff --git a/ui/aura/window_tree_host.cc b/ui/aura/window_tree_host.cc |
| index e60208be8c19b09974210da56efa2e38134f23d5..bf36035f30e091ce59ae76bcda3f8c4eb738e7d7 100644 |
| --- a/ui/aura/window_tree_host.cc |
| +++ b/ui/aura/window_tree_host.cc |
| @@ -13,6 +13,8 @@ |
| #include "ui/aura/window_event_dispatcher.h" |
| #include "ui/aura/window_targeter.h" |
| #include "ui/aura/window_tree_host_observer.h" |
| +#include "ui/base/ime/input_method.h" |
| +#include "ui/base/ime/input_method_factory.h" |
| #include "ui/base/view_prop.h" |
| #include "ui/compositor/dip_util.h" |
| #include "ui/compositor/layer.h" |
| @@ -41,6 +43,10 @@ float GetDeviceScaleFactorFromDisplay(Window* window) { |
| WindowTreeHost::~WindowTreeHost() { |
| DCHECK(!compositor_) << "compositor must be destroyed before root window"; |
| + if (owned_input_method_) { |
| + delete input_method_; |
| + input_method_ = nullptr; |
| + } |
| } |
| #if defined(OS_ANDROID) |
| @@ -177,7 +183,26 @@ void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) { |
| WindowTreeHost::WindowTreeHost() |
| : window_(new Window(NULL)), |
| - last_cursor_(ui::kCursorNull) { |
| + last_cursor_(ui::kCursorNull), |
| + input_method_(NULL), |
|
James Su
2015/06/03 06:41:16
nullptr?
Shu Chen
2015/06/03 07:29:57
Done.
|
| + owned_input_method_(false) { |
| +} |
| + |
| +ui::InputMethod* WindowTreeHost::GetInputMethod() { |
| + if (!input_method_) { |
| + input_method_ = |
| + ui::CreateInputMethod(this, GetAcceleratedWidget()).release(); |
| + // Makes sure the input method is focused by default when created. |
| + input_method_->OnFocus(); |
| + owned_input_method_ = true; |
| + } |
| + return input_method_; |
| +}; |
| + |
| +void WindowTreeHost::SetInputMethod(ui::InputMethod* input_method) { |
| + DCHECK(!input_method_); |
| + input_method_ = input_method; |
| + owned_input_method_ = false; |
| } |
| void WindowTreeHost::DestroyCompositor() { |
| @@ -259,6 +284,30 @@ void WindowTreeHost::OnHostLostWindowCapture() { |
| capture_window->ReleaseCapture(); |
| } |
| +bool WindowTreeHost::DispatchKeyEventPostIME(const ui::KeyEvent& event) { |
| + ui::KeyEvent copied_event(event); |
| + ui::EventDispatchDetails details = |
| + event_processor()->OnEventFromSource(&copied_event); |
| + DCHECK(!details.dispatcher_destroyed); |
| + return copied_event.handled(); |
| +} |
| + |
| +ui::EventProcessor* WindowTreeHost::GetEventProcessor() { |
| + return event_processor(); |
| +} |
| + |
| +ui::EventDispatchDetails WindowTreeHost::DeliverEventToProcessor( |
| + ui::Event* event) { |
| + if (event->IsKeyEvent()) { |
| + if (GetInputMethod()->DispatchKeyEvent( |
| + *static_cast<ui::KeyEvent*>(event))) { |
| + event->StopPropagation(); |
| + return ui::EventDispatchDetails(); |
| + } |
| + } |
| + return ui::EventSource::DeliverEventToProcessor(event); |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // WindowTreeHost, private: |