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.) | 67 event->StopPropagation(); |
sky
2016/08/18 23:43:07
Is the unconditional StopPropagation here going to
Hadi
2016/08/25 18:06:06
1. If the key event still needs handling post-ime,
sky
2016/08/25 20:17:53
Wow, thanks for the great writeup, and it all make
| |
60 if (event->is_char()) { | |
61 GetTextInputClient()->InsertChar(*event); | |
62 event->StopPropagation(); | |
63 return; | |
64 } | |
65 | |
66 ignore_result(DispatchKeyEventPostIME(event)); | |
67 } | 68 } |
68 | 69 |
69 void InputMethodMUS::OnTextInputTypeChanged(const ui::TextInputClient* client) { | 70 void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) { |
70 if (IsTextInputClientFocused(client)) | 71 if (IsTextInputClientFocused(client)) |
71 UpdateTextInputType(); | 72 UpdateTextInputType(); |
72 InputMethodBase::OnTextInputTypeChanged(client); | 73 InputMethodBase::OnTextInputTypeChanged(client); |
74 | |
75 if (input_method_) { | |
76 input_method_->OnTextInputTypeChanged( | |
77 static_cast<ui::mojom::TextInputType>(client->GetTextInputType())); | |
78 } | |
73 } | 79 } |
74 | 80 |
75 void InputMethodMUS::OnCaretBoundsChanged(const ui::TextInputClient* client) {} | 81 void InputMethodMus::OnCaretBoundsChanged(const ui::TextInputClient* client) { |
82 if (input_method_) | |
83 input_method_->OnCaretBoundsChanged(client->GetCaretBounds()); | |
84 } | |
76 | 85 |
77 void InputMethodMUS::CancelComposition(const ui::TextInputClient* client) {} | 86 void InputMethodMus::CancelComposition(const ui::TextInputClient* client) { |
87 if (input_method_) | |
88 input_method_->CancelComposition(); | |
89 } | |
78 | 90 |
79 void InputMethodMUS::OnInputLocaleChanged() {} | 91 void InputMethodMus::OnInputLocaleChanged() { |
92 // TODO(moshayedi): crbug.com/637418. Not supported in ChromeOS. Investigate | |
93 // whether we want to support this or not. | |
94 } | |
80 | 95 |
81 std::string InputMethodMUS::GetInputLocale() { | 96 std::string InputMethodMus::GetInputLocale() { |
97 // TODO(moshayedi): crbug.com/637418. Not supported in ChromeOS. Investigate | |
98 // whether we want to support this or not. | |
82 return ""; | 99 return ""; |
sky
2016/08/18 23:43:07
"" -> std::string()
Hadi
2016/08/25 18:06:06
Done.
| |
83 } | 100 } |
84 | 101 |
85 bool InputMethodMUS::IsCandidatePopupOpen() const { | 102 bool InputMethodMus::IsCandidatePopupOpen() const { |
103 // TODO(moshayedi): crbug.com/637416. Implement this properly when we have a | |
104 // mean for displaying candidate list popup. | |
86 return false; | 105 return false; |
87 } | 106 } |
88 | 107 |
89 void InputMethodMUS::OnDidChangeFocusedClient( | 108 void InputMethodMus::OnDidChangeFocusedClient( |
90 ui::TextInputClient* focused_before, | 109 ui::TextInputClient* focused_before, |
91 ui::TextInputClient* focused) { | 110 ui::TextInputClient* focused) { |
92 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); | 111 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); |
93 UpdateTextInputType(); | 112 UpdateTextInputType(); |
113 | |
114 text_input_client_.reset(new TextInputClientImpl(focused, this)); | |
115 ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(), | |
116 GetProxy(&input_method_)); | |
94 } | 117 } |
95 | 118 |
96 void InputMethodMUS::UpdateTextInputType() { | 119 void InputMethodMus::UpdateTextInputType() { |
97 ui::TextInputType type = GetTextInputType(); | 120 ui::TextInputType type = GetTextInputType(); |
98 mojo::TextInputStatePtr state = mojo::TextInputState::New(); | 121 mojo::TextInputStatePtr state = mojo::TextInputState::New(); |
99 state->type = mojo::ConvertTo<mojo::TextInputType>(type); | 122 state->type = mojo::ConvertTo<mojo::TextInputType>(type); |
100 if (type != ui::TEXT_INPUT_TYPE_NONE) | 123 if (window_) { |
101 window_->SetImeVisibility(true, std::move(state)); | 124 if (type != ui::TEXT_INPUT_TYPE_NONE) |
102 else | 125 window_->SetImeVisibility(true, std::move(state)); |
103 window_->SetTextInputState(std::move(state)); | 126 else |
127 window_->SetTextInputState(std::move(state)); | |
128 } | |
104 } | 129 } |
105 | 130 |
106 } // namespace views | 131 } // namespace views |
OLD | NEW |