| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mandoline/ui/aura/input_method_mandoline.h" | |
| 6 | |
| 7 #include "components/mus/public/cpp/view.h" | |
| 8 #include "mojo/converters/ime/ime_type_converters.h" | |
| 9 #include "ui/base/ime/text_input_client.h" | |
| 10 #include "ui/events/event.h" | |
| 11 #include "ui/mojo/ime/text_input_state.mojom.h" | |
| 12 | |
| 13 namespace mandoline { | |
| 14 | |
| 15 //////////////////////////////////////////////////////////////////////////////// | |
| 16 // InputMethodMandoline, public: | |
| 17 | |
| 18 InputMethodMandoline::InputMethodMandoline( | |
| 19 ui::internal::InputMethodDelegate* delegate, | |
| 20 mus::View* view) | |
| 21 : view_(view) { | |
| 22 SetDelegate(delegate); | |
| 23 } | |
| 24 | |
| 25 InputMethodMandoline::~InputMethodMandoline() {} | |
| 26 | |
| 27 //////////////////////////////////////////////////////////////////////////////// | |
| 28 // InputMethodMandoline, ui::InputMethod implementation: | |
| 29 | |
| 30 void InputMethodMandoline::OnFocus() { | |
| 31 InputMethodBase::OnFocus(); | |
| 32 UpdateTextInputType(); | |
| 33 } | |
| 34 | |
| 35 void InputMethodMandoline::OnBlur() { | |
| 36 InputMethodBase::OnBlur(); | |
| 37 UpdateTextInputType(); | |
| 38 } | |
| 39 | |
| 40 bool InputMethodMandoline::OnUntranslatedIMEMessage( | |
| 41 const base::NativeEvent& event, | |
| 42 NativeEventResult* result) { | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 void InputMethodMandoline::DispatchKeyEvent(ui::KeyEvent* event) { | |
| 47 DCHECK(event->type() == ui::ET_KEY_PRESSED || | |
| 48 event->type() == ui::ET_KEY_RELEASED); | |
| 49 | |
| 50 // If no text input client, do nothing. | |
| 51 if (!GetTextInputClient()) { | |
| 52 ignore_result(DispatchKeyEventPostIME(event)); | |
| 53 return; | |
| 54 } | |
| 55 | |
| 56 // Here is where we change the differ from our base class's logic. Instead of | |
| 57 // always dispatching a key down event, and then sending a synthesized | |
| 58 // character event, we instead check to see if this is a character event and | |
| 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->GetCharacter(), event->flags()); | |
| 62 event->StopPropagation(); | |
| 63 return; | |
| 64 } | |
| 65 | |
| 66 ignore_result(DispatchKeyEventPostIME(event)); | |
| 67 } | |
| 68 | |
| 69 void InputMethodMandoline::OnTextInputTypeChanged( | |
| 70 const ui::TextInputClient* client) { | |
| 71 if (IsTextInputClientFocused(client)) | |
| 72 UpdateTextInputType(); | |
| 73 InputMethodBase::OnTextInputTypeChanged(client); | |
| 74 } | |
| 75 | |
| 76 void InputMethodMandoline::OnCaretBoundsChanged( | |
| 77 const ui::TextInputClient* client) { | |
| 78 } | |
| 79 | |
| 80 void InputMethodMandoline::CancelComposition( | |
| 81 const ui::TextInputClient* client) { | |
| 82 } | |
| 83 | |
| 84 void InputMethodMandoline::OnInputLocaleChanged() { | |
| 85 } | |
| 86 | |
| 87 std::string InputMethodMandoline::GetInputLocale() { | |
| 88 return ""; | |
| 89 } | |
| 90 | |
| 91 bool InputMethodMandoline::IsCandidatePopupOpen() const { | |
| 92 return false; | |
| 93 } | |
| 94 | |
| 95 void InputMethodMandoline::OnDidChangeFocusedClient( | |
| 96 ui::TextInputClient* focused_before, | |
| 97 ui::TextInputClient* focused) { | |
| 98 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); | |
| 99 UpdateTextInputType(); | |
| 100 } | |
| 101 | |
| 102 void InputMethodMandoline::UpdateTextInputType() { | |
| 103 ui::TextInputType type = GetTextInputType(); | |
| 104 mojo::TextInputStatePtr state = mojo::TextInputState::New(); | |
| 105 state->type = mojo::ConvertTo<mojo::TextInputType>(type); | |
| 106 if (type != ui::TEXT_INPUT_TYPE_NONE) | |
| 107 view_->SetImeVisibility(true, state.Pass()); | |
| 108 else | |
| 109 view_->SetTextInputState(state.Pass()); | |
| 110 } | |
| 111 | |
| 112 } // namespace mandoline | |
| OLD | NEW |