Index: ui/views/mus/input_method_mus.cc |
diff --git a/ui/views/mus/input_method_mus.cc b/ui/views/mus/input_method_mus.cc |
index c8d027eeab2e91aab2862567895df904e38a850f..942dde7411a78d78c883fbf6c25478a96fc05fb3 100644 |
--- a/ui/views/mus/input_method_mus.cc |
+++ b/ui/views/mus/input_method_mus.cc |
@@ -7,43 +7,51 @@ |
#include <utility> |
#include "services/ui/public/cpp/window.h" |
+#include "services/ui/public/interfaces/ime.mojom.h" |
#include "ui/base/ime/text_input_client.h" |
#include "ui/events/event.h" |
#include "ui/platform_window/mojo/ime_type_converters.h" |
#include "ui/platform_window/mojo/text_input_state.mojom.h" |
+#include "ui/views/mus/text_input_client_impl.h" |
namespace views { |
//////////////////////////////////////////////////////////////////////////////// |
-// InputMethodMUS, public: |
+// InputMethodMus, public: |
-InputMethodMUS::InputMethodMUS(ui::internal::InputMethodDelegate* delegate, |
+InputMethodMus::InputMethodMus(ui::internal::InputMethodDelegate* delegate, |
ui::Window* window) |
: window_(window) { |
SetDelegate(delegate); |
} |
-InputMethodMUS::~InputMethodMUS() {} |
+InputMethodMus::~InputMethodMus() {} |
+ |
+void InputMethodMus::Init(shell::Connector* connector) { |
+ connector->ConnectToInterface("mojo:ui", &ime_server_); |
+} |
//////////////////////////////////////////////////////////////////////////////// |
-// InputMethodMUS, ui::InputMethod implementation: |
+// InputMethodMus, ui::InputMethod implementation: |
-void InputMethodMUS::OnFocus() { |
+void InputMethodMus::OnFocus() { |
InputMethodBase::OnFocus(); |
UpdateTextInputType(); |
} |
-void InputMethodMUS::OnBlur() { |
+void InputMethodMus::OnBlur() { |
InputMethodBase::OnBlur(); |
UpdateTextInputType(); |
} |
-bool InputMethodMUS::OnUntranslatedIMEMessage(const base::NativeEvent& event, |
+bool InputMethodMus::OnUntranslatedIMEMessage(const base::NativeEvent& event, |
NativeEventResult* result) { |
+ // This method is not called on non-Windows platforms. See the comments for |
+ // ui::InputMethod::OnUntranslatedIMEMessage(). |
return false; |
} |
-void InputMethodMUS::DispatchKeyEvent(ui::KeyEvent* event) { |
+void InputMethodMus::DispatchKeyEvent(ui::KeyEvent* event) { |
DCHECK(event->type() == ui::ET_KEY_PRESSED || |
event->type() == ui::ET_KEY_RELEASED); |
@@ -53,12 +61,14 @@ void InputMethodMUS::DispatchKeyEvent(ui::KeyEvent* event) { |
return; |
} |
- // Here is where we change the differ from our base class's logic. Instead of |
- // always dispatching a key down event, and then sending a synthesized |
- // character event, we instead check to see if this is a character event and |
- // send out the key if it is. (We fallback to normal dispatch if it isn't.) |
+ // TODO(moshayedi): crbug.com/641355. Currently if we stop propagation of |
+ // non-char events here, accelerators ddn't work. This is because we send the |
+ // event ack too early in NativeWidgetMus. We should send both char and |
+ // non-char events to the IME driver once we fix this. |
if (event->is_char()) { |
- GetTextInputClient()->InsertChar(*event); |
+ // IME driver will notify the text input client if it is not interested in |
+ // event, which in turn will call DispatchKeyEventPostIME(). |
+ input_method_->ProcessKeyEvent(ui::Event::Clone(*event)); |
event->StopPropagation(); |
return; |
} |
@@ -66,41 +76,65 @@ void InputMethodMUS::DispatchKeyEvent(ui::KeyEvent* event) { |
ignore_result(DispatchKeyEventPostIME(event)); |
} |
-void InputMethodMUS::OnTextInputTypeChanged(const ui::TextInputClient* client) { |
+void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) { |
if (IsTextInputClientFocused(client)) |
UpdateTextInputType(); |
InputMethodBase::OnTextInputTypeChanged(client); |
+ |
+ if (input_method_) { |
+ input_method_->OnTextInputTypeChanged( |
+ static_cast<ui::mojom::TextInputType>(client->GetTextInputType())); |
+ } |
} |
-void InputMethodMUS::OnCaretBoundsChanged(const ui::TextInputClient* client) {} |
+void InputMethodMus::OnCaretBoundsChanged(const ui::TextInputClient* client) { |
+ if (input_method_) |
+ input_method_->OnCaretBoundsChanged(client->GetCaretBounds()); |
+} |
-void InputMethodMUS::CancelComposition(const ui::TextInputClient* client) {} |
+void InputMethodMus::CancelComposition(const ui::TextInputClient* client) { |
+ if (input_method_) |
+ input_method_->CancelComposition(); |
+} |
-void InputMethodMUS::OnInputLocaleChanged() {} |
+void InputMethodMus::OnInputLocaleChanged() { |
+ // TODO(moshayedi): crbug.com/637418. Not supported in ChromeOS. Investigate |
+ // whether we want to support this or not. |
+} |
-std::string InputMethodMUS::GetInputLocale() { |
- return ""; |
+std::string InputMethodMus::GetInputLocale() { |
+ // TODO(moshayedi): crbug.com/637418. Not supported in ChromeOS. Investigate |
+ // whether we want to support this or not. |
+ return std::string(); |
} |
-bool InputMethodMUS::IsCandidatePopupOpen() const { |
+bool InputMethodMus::IsCandidatePopupOpen() const { |
+ // TODO(moshayedi): crbug.com/637416. Implement this properly when we have a |
+ // mean for displaying candidate list popup. |
return false; |
} |
-void InputMethodMUS::OnDidChangeFocusedClient( |
+void InputMethodMus::OnDidChangeFocusedClient( |
ui::TextInputClient* focused_before, |
ui::TextInputClient* focused) { |
InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); |
UpdateTextInputType(); |
+ |
+ text_input_client_.reset(new TextInputClientImpl(focused, this)); |
+ ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(), |
+ GetProxy(&input_method_)); |
} |
-void InputMethodMUS::UpdateTextInputType() { |
+void InputMethodMus::UpdateTextInputType() { |
ui::TextInputType type = GetTextInputType(); |
mojo::TextInputStatePtr state = mojo::TextInputState::New(); |
state->type = mojo::ConvertTo<mojo::TextInputType>(type); |
- if (type != ui::TEXT_INPUT_TYPE_NONE) |
- window_->SetImeVisibility(true, std::move(state)); |
- else |
- window_->SetTextInputState(std::move(state)); |
+ if (window_) { |
+ if (type != ui::TEXT_INPUT_TYPE_NONE) |
+ window_->SetImeVisibility(true, std::move(state)); |
+ else |
+ window_->SetTextInputState(std::move(state)); |
+ } |
} |
} // namespace views |