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