Index: ui/aura/window_tree_host.cc |
diff --git a/ui/aura/window_tree_host.cc b/ui/aura/window_tree_host.cc |
index 772b020586660d0d9f671afdb914f0326536b926..2beb0ea19d8992f57ef1ce44e43caa6b64a3cee7 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) |
@@ -50,7 +56,7 @@ WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) { |
// adding the CHECK. |
// TODO(sky): decide if we want a factory. |
CHECK(false); |
- return NULL; |
+ return nullptr; |
} |
#endif |
@@ -172,6 +178,33 @@ void WindowTreeHost::MoveCursorToHostLocation(const gfx::Point& host_location) { |
MoveCursorToInternal(root_location, host_location); |
} |
+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, because |
+ // some environment doesn't have activated/focused state in WindowTreeHost. |
+ // TODO(shuchen): move this to DisplayController so it's only for Ash. |
+ input_method_->OnFocus(); |
+ owned_input_method_ = true; |
+ } |
+ return input_method_; |
+} |
+ |
+void WindowTreeHost::SetSharedInputMethod(ui::InputMethod* input_method) { |
+ DCHECK(!input_method_); |
+ input_method_ = input_method; |
+ owned_input_method_ = false; |
+} |
+ |
+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(); |
+} |
+ |
void WindowTreeHost::Show() { |
if (compositor()) |
compositor()->SetVisible(true); |
@@ -188,8 +221,10 @@ void WindowTreeHost::Hide() { |
// WindowTreeHost, protected: |
WindowTreeHost::WindowTreeHost() |
- : window_(new Window(NULL)), |
- last_cursor_(ui::kCursorNull) { |
+ : window_(new Window(nullptr)), |
+ last_cursor_(ui::kCursorNull), |
+ input_method_(nullptr), |
+ owned_input_method_(false) { |
} |
void WindowTreeHost::DestroyCompositor() { |
@@ -198,7 +233,7 @@ void WindowTreeHost::DestroyCompositor() { |
void WindowTreeHost::DestroyDispatcher() { |
delete window_; |
- window_ = NULL; |
+ window_ = nullptr; |
dispatcher_.reset(); |
// TODO(beng): this comment is no longer quite valid since this function |
@@ -271,6 +306,24 @@ void WindowTreeHost::OnHostLostWindowCapture() { |
capture_window->ReleaseCapture(); |
} |
+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(); |
+ // TODO(shuchen): pass around the EventDispatchDetails from |
+ // DispatchKeyEventPostIME instead of creating new from here. |
+ return ui::EventDispatchDetails(); |
+ } |
+ } |
oshima
2015/06/19 00:43:40
Hi, we noticed that with this CL, InputMethod rece
|
+ return ui::EventSource::DeliverEventToProcessor(event); |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// WindowTreeHost, private: |