Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Unified Diff: ui/aura/window_tree_host.cc

Issue 1155013005: Refactoring the ownership of ui::InputMethod. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..343854a56e2233ccf887323eb2969ee43b7b4c91 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::SetInputMethod(ui::InputMethod* input_method) {
+ DCHECK(!input_method_);
+ input_method_ = input_method;
+ owned_input_method_ = false;
+}
+
+bool WindowTreeHost::DispatchKeyEventPostIME(const ui::KeyEvent& event) {
sadrul 2015/06/08 22:45:12 Not for this CL, but would it be possible for Disp
Shu Chen 2015/06/09 02:28:49 The caller of InputMethod::DispatchKeyEvent() want
sadrul 2015/06/09 15:29:32 You could send a pointer to the KeyEvent in Dispat
Shu Chen 2015/06/10 03:01:35 Actually I meant "InputMethod can intercept the ke
+ 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,22 @@ 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();
+ return ui::EventDispatchDetails();
+ }
+ }
+ return ui::EventSource::DeliverEventToProcessor(event);
+}
+
////////////////////////////////////////////////////////////////////////////////
// WindowTreeHost, private:

Powered by Google App Engine
This is Rietveld 408576698