| 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 // IME driver will notify the text input client if it is not interested in |
| 57 // always dispatching a key down event, and then sending a synthesized | 65 // event, which in turn will call DispatchKeyEventPostIME(). |
| 58 // character event, we instead check to see if this is a character event and | 66 input_method_->ProcessKeyEvent(ui::Event::Clone(*event)); |
| 59 // send out the key if it is. (We fallback to normal dispatch if it isn't.) | |
| 60 if (event->is_char()) { | |
| 61 GetTextInputClient()->InsertChar(*event); | |
| 62 event->StopPropagation(); | |
| 63 return; | |
| 64 } | |
| 65 | |
| 66 ignore_result(DispatchKeyEventPostIME(event)); | |
| 67 } | 67 } |
| 68 | 68 |
| 69 void InputMethodMUS::OnTextInputTypeChanged(const ui::TextInputClient* client) { | 69 void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) { |
| 70 if (IsTextInputClientFocused(client)) | 70 if (IsTextInputClientFocused(client)) |
| 71 UpdateTextInputType(); | 71 UpdateTextInputType(); |
| 72 InputMethodBase::OnTextInputTypeChanged(client); | 72 InputMethodBase::OnTextInputTypeChanged(client); |
| 73 |
| 74 if (input_method_) { |
| 75 input_method_->OnTextInputTypeChanged( |
| 76 static_cast<ui::mojom::TextInputType>(client->GetTextInputType())); |
| 77 } |
| 73 } | 78 } |
| 74 | 79 |
| 75 void InputMethodMUS::OnCaretBoundsChanged(const ui::TextInputClient* client) {} | 80 void InputMethodMus::OnCaretBoundsChanged(const ui::TextInputClient* client) { |
| 76 | 81 if (input_method_) |
| 77 void InputMethodMUS::CancelComposition(const ui::TextInputClient* client) {} | 82 input_method_->OnCaretBoundsChanged(client->GetCaretBounds()); |
| 78 | |
| 79 void InputMethodMUS::OnInputLocaleChanged() {} | |
| 80 | |
| 81 std::string InputMethodMUS::GetInputLocale() { | |
| 82 return ""; | |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool InputMethodMUS::IsCandidatePopupOpen() const { | 85 void InputMethodMus::CancelComposition(const ui::TextInputClient* client) { |
| 86 if (input_method_) |
| 87 input_method_->CancelComposition(); |
| 88 } |
| 89 |
| 90 void InputMethodMus::OnInputLocaleChanged() { |
| 91 // TODO(moshayedi): crbug.com/637418. Not supported in ChromeOS. Investigate |
| 92 // whether we want to support this or not. |
| 93 } |
| 94 |
| 95 std::string InputMethodMus::GetInputLocale() { |
| 96 // TODO(moshayedi): crbug.com/637418. Not supported in ChromeOS. Investigate |
| 97 // whether we want to support this or not. |
| 98 return std::string(); |
| 99 } |
| 100 |
| 101 bool InputMethodMus::IsCandidatePopupOpen() const { |
| 102 // TODO(moshayedi): crbug.com/637416. Implement this properly when we have a |
| 103 // mean for displaying candidate list popup. |
| 86 return false; | 104 return false; |
| 87 } | 105 } |
| 88 | 106 |
| 89 void InputMethodMUS::OnDidChangeFocusedClient( | 107 void InputMethodMus::OnDidChangeFocusedClient( |
| 90 ui::TextInputClient* focused_before, | 108 ui::TextInputClient* focused_before, |
| 91 ui::TextInputClient* focused) { | 109 ui::TextInputClient* focused) { |
| 92 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); | 110 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); |
| 93 UpdateTextInputType(); | 111 UpdateTextInputType(); |
| 112 |
| 113 text_input_client_.reset(new TextInputClientImpl(focused, this)); |
| 114 ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(), |
| 115 GetProxy(&input_method_)); |
| 94 } | 116 } |
| 95 | 117 |
| 96 void InputMethodMUS::UpdateTextInputType() { | 118 void InputMethodMus::UpdateTextInputType() { |
| 97 ui::TextInputType type = GetTextInputType(); | 119 ui::TextInputType type = GetTextInputType(); |
| 98 mojo::TextInputStatePtr state = mojo::TextInputState::New(); | 120 mojo::TextInputStatePtr state = mojo::TextInputState::New(); |
| 99 state->type = mojo::ConvertTo<mojo::TextInputType>(type); | 121 state->type = mojo::ConvertTo<mojo::TextInputType>(type); |
| 100 if (type != ui::TEXT_INPUT_TYPE_NONE) | 122 if (window_) { |
| 101 window_->SetImeVisibility(true, std::move(state)); | 123 if (type != ui::TEXT_INPUT_TYPE_NONE) |
| 102 else | 124 window_->SetImeVisibility(true, std::move(state)); |
| 103 window_->SetTextInputState(std::move(state)); | 125 else |
| 126 window_->SetTextInputState(std::move(state)); |
| 127 } |
| 104 } | 128 } |
| 105 | 129 |
| 106 } // namespace views | 130 } // namespace views |
| OLD | NEW |