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.
5 #include "mandoline/ui/aura/input_method_mandoline.h"
7 #include "components/view_manager/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"
15 ////////////////////////////////////////////////////////////////////////////////
16 // InputMethodMandoline, public:
18 InputMethodMandoline::InputMethodMandoline(
19 ui::internal::InputMethodDelegate
* delegate
,
22 SetDelegate(delegate
);
25 InputMethodMandoline::~InputMethodMandoline() {}
27 ////////////////////////////////////////////////////////////////////////////////
28 // InputMethodMandoline, ui::InputMethod implementation:
30 void InputMethodMandoline::OnFocus() {
31 InputMethodBase::OnFocus();
32 UpdateTextInputType();
35 void InputMethodMandoline::OnBlur() {
36 InputMethodBase::OnBlur();
37 UpdateTextInputType();
40 bool InputMethodMandoline::OnUntranslatedIMEMessage(
41 const base::NativeEvent
& event
,
42 NativeEventResult
* result
) {
46 void InputMethodMandoline::DispatchKeyEvent(ui::KeyEvent
* event
) {
47 DCHECK(event
->type() == ui::ET_KEY_PRESSED
||
48 event
->type() == ui::ET_KEY_RELEASED
);
50 // If no text input client, do nothing.
51 if (!GetTextInputClient()) {
52 ignore_result(DispatchKeyEventPostIME(event
));
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();
66 ignore_result(DispatchKeyEventPostIME(event
));
69 void InputMethodMandoline::OnTextInputTypeChanged(
70 const ui::TextInputClient
* client
) {
71 if (IsTextInputClientFocused(client
))
72 UpdateTextInputType();
73 InputMethodBase::OnTextInputTypeChanged(client
);
76 void InputMethodMandoline::OnCaretBoundsChanged(
77 const ui::TextInputClient
* client
) {
80 void InputMethodMandoline::CancelComposition(
81 const ui::TextInputClient
* client
) {
84 void InputMethodMandoline::OnInputLocaleChanged() {
87 std::string
InputMethodMandoline::GetInputLocale() {
91 bool InputMethodMandoline::IsCandidatePopupOpen() const {
95 void InputMethodMandoline::OnDidChangeFocusedClient(
96 ui::TextInputClient
* focused_before
,
97 ui::TextInputClient
* focused
) {
98 InputMethodBase::OnDidChangeFocusedClient(focused_before
, focused
);
99 UpdateTextInputType();
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());
109 view_
->SetTextInputState(state
.Pass());
112 } // namespace mandoline