Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1299)

Side by Side Diff: ui/views/mus/input_method_mus.cc

Issue 2230393002: IME for Mus: Make InputMethodMus use the IME Mojo API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix dependencies Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/mus/input_method_mus.h ('k') | ui/views/mus/input_method_mus_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Send the key event to the IME driver if it is a character event, and fall
57 // always dispatching a key down event, and then sending a synthesized 65 // back to normal dispatch if it isn't.
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()) { 66 if (event->is_char()) {
61 GetTextInputClient()->InsertChar(*event); 67 input_method_->ProcessKeyEvent(ui::Event::Clone(*event));
sadrul 2016/08/16 22:32:02 Wait, this seems backwards. We are supposed to rec
62 event->StopPropagation(); 68 event->StopPropagation();
63 return; 69 return;
64 } 70 }
65 71
66 ignore_result(DispatchKeyEventPostIME(event)); 72 ignore_result(DispatchKeyEventPostIME(event));
67 } 73 }
68 74
69 void InputMethodMUS::OnTextInputTypeChanged(const ui::TextInputClient* client) { 75 void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) {
70 if (IsTextInputClientFocused(client)) 76 if (IsTextInputClientFocused(client))
71 UpdateTextInputType(); 77 UpdateTextInputType();
72 InputMethodBase::OnTextInputTypeChanged(client); 78 InputMethodBase::OnTextInputTypeChanged(client);
79
80 if (input_method_) {
81 input_method_->OnTextInputTypeChanged(
82 static_cast<ui::mojom::TextInputType>(client->GetTextInputType()));
83 }
73 } 84 }
74 85
75 void InputMethodMUS::OnCaretBoundsChanged(const ui::TextInputClient* client) {} 86 void InputMethodMus::OnCaretBoundsChanged(const ui::TextInputClient* client) {
87 if (input_method_)
88 input_method_->OnCaretBoundsChanged(client->GetCaretBounds());
89 }
76 90
77 void InputMethodMUS::CancelComposition(const ui::TextInputClient* client) {} 91 void InputMethodMus::CancelComposition(const ui::TextInputClient* client) {
92 if (input_method_)
93 input_method_->CancelComposition();
94 }
78 95
79 void InputMethodMUS::OnInputLocaleChanged() {} 96 void InputMethodMus::OnInputLocaleChanged() {
97 // TODO(moshayedi): crbug.com/637418. Not supported in ChromeOS. Investigate
98 // whether we want to support this or not.
99 }
80 100
81 std::string InputMethodMUS::GetInputLocale() { 101 std::string InputMethodMus::GetInputLocale() {
102 // TODO(moshayedi): crbug.com/637418. Not supported in ChromeOS. Investigate
103 // whether we want to support this or not.
82 return ""; 104 return "";
83 } 105 }
84 106
85 bool InputMethodMUS::IsCandidatePopupOpen() const { 107 bool InputMethodMus::IsCandidatePopupOpen() const {
108 // TODO(moshayedi): crbug.com/637416. Implement this properly when we have a
109 // mean for displaying candidate list popup.
86 return false; 110 return false;
87 } 111 }
88 112
89 void InputMethodMUS::OnDidChangeFocusedClient( 113 void InputMethodMus::OnDidChangeFocusedClient(
90 ui::TextInputClient* focused_before, 114 ui::TextInputClient* focused_before,
91 ui::TextInputClient* focused) { 115 ui::TextInputClient* focused) {
92 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); 116 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
93 UpdateTextInputType(); 117 UpdateTextInputType();
118
119 text_input_client_.reset(new TextInputClientImpl(focused));
120 ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(),
121 GetProxy(&input_method_));
94 } 122 }
95 123
96 void InputMethodMUS::UpdateTextInputType() { 124 void InputMethodMus::UpdateTextInputType() {
97 ui::TextInputType type = GetTextInputType(); 125 ui::TextInputType type = GetTextInputType();
98 mojo::TextInputStatePtr state = mojo::TextInputState::New(); 126 mojo::TextInputStatePtr state = mojo::TextInputState::New();
99 state->type = mojo::ConvertTo<mojo::TextInputType>(type); 127 state->type = mojo::ConvertTo<mojo::TextInputType>(type);
100 if (type != ui::TEXT_INPUT_TYPE_NONE) 128 if (window_) {
101 window_->SetImeVisibility(true, std::move(state)); 129 if (type != ui::TEXT_INPUT_TYPE_NONE)
102 else 130 window_->SetImeVisibility(true, std::move(state));
103 window_->SetTextInputState(std::move(state)); 131 else
132 window_->SetTextInputState(std::move(state));
133 }
104 } 134 }
105 135
106 } // namespace views 136 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/input_method_mus.h ('k') | ui/views/mus/input_method_mus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698