| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/mus/input_method_mus.h" | 5 #include "ui/views/mus/input_method_mus.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "services/ui/public/cpp/window.h" | 9 #include "services/ui/public/cpp/window.h" |
| 10 #include "services/ui/public/interfaces/ime.mojom.h" | |
| 11 #include "ui/base/ime/text_input_client.h" | 10 #include "ui/base/ime/text_input_client.h" |
| 12 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
| 13 #include "ui/platform_window/mojo/ime_type_converters.h" | 12 #include "ui/platform_window/mojo/ime_type_converters.h" |
| 14 #include "ui/platform_window/mojo/text_input_state.mojom.h" | 13 #include "ui/platform_window/mojo/text_input_state.mojom.h" |
| 15 #include "ui/views/mus/text_input_client_impl.h" | |
| 16 | 14 |
| 17 namespace views { | 15 namespace views { |
| 18 | 16 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 17 //////////////////////////////////////////////////////////////////////////////// |
| 20 // InputMethodMus, public: | 18 // InputMethodMUS, public: |
| 21 | 19 |
| 22 InputMethodMus::InputMethodMus(ui::internal::InputMethodDelegate* delegate, | 20 InputMethodMUS::InputMethodMUS(ui::internal::InputMethodDelegate* delegate, |
| 23 ui::Window* window) | 21 ui::Window* window) |
| 24 : window_(window) { | 22 : window_(window) { |
| 25 SetDelegate(delegate); | 23 SetDelegate(delegate); |
| 26 } | 24 } |
| 27 | 25 |
| 28 InputMethodMus::~InputMethodMus() {} | 26 InputMethodMUS::~InputMethodMUS() {} |
| 29 | |
| 30 void InputMethodMus::Init(shell::Connector* connector) { | |
| 31 connector->ConnectToInterface("mojo:ui", &ime_server_); | |
| 32 } | |
| 33 | 27 |
| 34 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
| 35 // InputMethodMus, ui::InputMethod implementation: | 29 // InputMethodMUS, ui::InputMethod implementation: |
| 36 | 30 |
| 37 void InputMethodMus::OnFocus() { | 31 void InputMethodMUS::OnFocus() { |
| 38 InputMethodBase::OnFocus(); | 32 InputMethodBase::OnFocus(); |
| 39 UpdateTextInputType(); | 33 UpdateTextInputType(); |
| 40 } | 34 } |
| 41 | 35 |
| 42 void InputMethodMus::OnBlur() { | 36 void InputMethodMUS::OnBlur() { |
| 43 InputMethodBase::OnBlur(); | 37 InputMethodBase::OnBlur(); |
| 44 UpdateTextInputType(); | 38 UpdateTextInputType(); |
| 45 } | 39 } |
| 46 | 40 |
| 47 bool InputMethodMus::OnUntranslatedIMEMessage(const base::NativeEvent& event, | 41 bool InputMethodMUS::OnUntranslatedIMEMessage(const base::NativeEvent& event, |
| 48 NativeEventResult* result) { | 42 NativeEventResult* result) { |
| 49 // This method is not called on non-Windows platforms. See the comments for | |
| 50 // ui::InputMethod::OnUntranslatedIMEMessage(). | |
| 51 return false; | 43 return false; |
| 52 } | 44 } |
| 53 | 45 |
| 54 void InputMethodMus::DispatchKeyEvent(ui::KeyEvent* event) { | 46 void InputMethodMUS::DispatchKeyEvent(ui::KeyEvent* event) { |
| 55 DCHECK(event->type() == ui::ET_KEY_PRESSED || | 47 DCHECK(event->type() == ui::ET_KEY_PRESSED || |
| 56 event->type() == ui::ET_KEY_RELEASED); | 48 event->type() == ui::ET_KEY_RELEASED); |
| 57 | 49 |
| 58 // If no text input client, do nothing. | 50 // If no text input client, do nothing. |
| 59 if (!GetTextInputClient()) { | 51 if (!GetTextInputClient()) { |
| 60 ignore_result(DispatchKeyEventPostIME(event)); | 52 ignore_result(DispatchKeyEventPostIME(event)); |
| 61 return; | 53 return; |
| 62 } | 54 } |
| 63 | 55 |
| 64 // TODO(moshayedi): crbug.com/641355. Currently if we stop propagation of | 56 // Here is where we change the differ from our base class's logic. Instead of |
| 65 // non-char events here, accelerators ddn't work. This is because we send the | 57 // always dispatching a key down event, and then sending a synthesized |
| 66 // event ack too early in NativeWidgetMus. We should send both char and | 58 // character event, we instead check to see if this is a character event and |
| 67 // non-char events to the IME driver once we fix this. | 59 // send out the key if it is. (We fallback to normal dispatch if it isn't.) |
| 68 if (event->is_char()) { | 60 if (event->is_char()) { |
| 69 // IME driver will notify the text input client if it is not interested in | 61 GetTextInputClient()->InsertChar(*event); |
| 70 // event, which in turn will call DispatchKeyEventPostIME(). | |
| 71 input_method_->ProcessKeyEvent(ui::Event::Clone(*event)); | |
| 72 event->StopPropagation(); | 62 event->StopPropagation(); |
| 73 return; | 63 return; |
| 74 } | 64 } |
| 75 | 65 |
| 76 ignore_result(DispatchKeyEventPostIME(event)); | 66 ignore_result(DispatchKeyEventPostIME(event)); |
| 77 } | 67 } |
| 78 | 68 |
| 79 void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) { | 69 void InputMethodMUS::OnTextInputTypeChanged(const ui::TextInputClient* client) { |
| 80 if (IsTextInputClientFocused(client)) | 70 if (IsTextInputClientFocused(client)) |
| 81 UpdateTextInputType(); | 71 UpdateTextInputType(); |
| 82 InputMethodBase::OnTextInputTypeChanged(client); | 72 InputMethodBase::OnTextInputTypeChanged(client); |
| 83 | |
| 84 if (input_method_) { | |
| 85 input_method_->OnTextInputTypeChanged( | |
| 86 static_cast<ui::mojom::TextInputType>(client->GetTextInputType())); | |
| 87 } | |
| 88 } | 73 } |
| 89 | 74 |
| 90 void InputMethodMus::OnCaretBoundsChanged(const ui::TextInputClient* client) { | 75 void InputMethodMUS::OnCaretBoundsChanged(const ui::TextInputClient* client) {} |
| 91 if (input_method_) | 76 |
| 92 input_method_->OnCaretBoundsChanged(client->GetCaretBounds()); | 77 void InputMethodMUS::CancelComposition(const ui::TextInputClient* client) {} |
| 78 |
| 79 void InputMethodMUS::OnInputLocaleChanged() {} |
| 80 |
| 81 std::string InputMethodMUS::GetInputLocale() { |
| 82 return ""; |
| 93 } | 83 } |
| 94 | 84 |
| 95 void InputMethodMus::CancelComposition(const ui::TextInputClient* client) { | 85 bool InputMethodMUS::IsCandidatePopupOpen() const { |
| 96 if (input_method_) | |
| 97 input_method_->CancelComposition(); | |
| 98 } | |
| 99 | |
| 100 void InputMethodMus::OnInputLocaleChanged() { | |
| 101 // TODO(moshayedi): crbug.com/637418. Not supported in ChromeOS. Investigate | |
| 102 // whether we want to support this or not. | |
| 103 } | |
| 104 | |
| 105 std::string InputMethodMus::GetInputLocale() { | |
| 106 // TODO(moshayedi): crbug.com/637418. Not supported in ChromeOS. Investigate | |
| 107 // whether we want to support this or not. | |
| 108 return std::string(); | |
| 109 } | |
| 110 | |
| 111 bool InputMethodMus::IsCandidatePopupOpen() const { | |
| 112 // TODO(moshayedi): crbug.com/637416. Implement this properly when we have a | |
| 113 // mean for displaying candidate list popup. | |
| 114 return false; | 86 return false; |
| 115 } | 87 } |
| 116 | 88 |
| 117 void InputMethodMus::OnDidChangeFocusedClient( | 89 void InputMethodMUS::OnDidChangeFocusedClient( |
| 118 ui::TextInputClient* focused_before, | 90 ui::TextInputClient* focused_before, |
| 119 ui::TextInputClient* focused) { | 91 ui::TextInputClient* focused) { |
| 120 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); | 92 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); |
| 121 UpdateTextInputType(); | 93 UpdateTextInputType(); |
| 122 | |
| 123 text_input_client_.reset(new TextInputClientImpl(focused, this)); | |
| 124 ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(), | |
| 125 GetProxy(&input_method_)); | |
| 126 } | 94 } |
| 127 | 95 |
| 128 void InputMethodMus::UpdateTextInputType() { | 96 void InputMethodMUS::UpdateTextInputType() { |
| 129 ui::TextInputType type = GetTextInputType(); | 97 ui::TextInputType type = GetTextInputType(); |
| 130 mojo::TextInputStatePtr state = mojo::TextInputState::New(); | 98 mojo::TextInputStatePtr state = mojo::TextInputState::New(); |
| 131 state->type = mojo::ConvertTo<mojo::TextInputType>(type); | 99 state->type = mojo::ConvertTo<mojo::TextInputType>(type); |
| 132 if (window_) { | 100 if (type != ui::TEXT_INPUT_TYPE_NONE) |
| 133 if (type != ui::TEXT_INPUT_TYPE_NONE) | 101 window_->SetImeVisibility(true, std::move(state)); |
| 134 window_->SetImeVisibility(true, std::move(state)); | 102 else |
| 135 else | 103 window_->SetTextInputState(std::move(state)); |
| 136 window_->SetTextInputState(std::move(state)); | |
| 137 } | |
| 138 } | 104 } |
| 139 | 105 |
| 140 } // namespace views | 106 } // namespace views |
| OLD | NEW |