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

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

Issue 2412593002: IME for Mus: Send ack for key events after IME driver processes the event. (Closed)
Patch Set: Addressed feedback. Created 4 years, 2 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
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 "services/ui/public/interfaces/ime.mojom.h"
11 #include "ui/base/ime/text_input_client.h" 11 #include "ui/base/ime/text_input_client.h"
12 #include "ui/events/event.h" 12 #include "ui/events/event.h"
13 #include "ui/platform_window/mojo/ime_type_converters.h" 13 #include "ui/platform_window/mojo/ime_type_converters.h"
14 #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" 15 #include "ui/views/mus/text_input_client_impl.h"
16 16
17 using ui::mojom::EventResult;
18
17 namespace views { 19 namespace views {
18 20
19 //////////////////////////////////////////////////////////////////////////////// 21 ////////////////////////////////////////////////////////////////////////////////
20 // InputMethodMus, public: 22 // InputMethodMus, public:
21 23
22 InputMethodMus::InputMethodMus(ui::internal::InputMethodDelegate* delegate, 24 InputMethodMus::InputMethodMus(ui::internal::InputMethodDelegate* delegate,
23 ui::Window* window) 25 ui::Window* window)
24 : window_(window) { 26 : window_(window) {
25 SetDelegate(delegate); 27 SetDelegate(delegate);
26 } 28 }
(...skipping 18 matching lines...) Expand all
45 } 47 }
46 48
47 bool InputMethodMus::OnUntranslatedIMEMessage(const base::NativeEvent& event, 49 bool InputMethodMus::OnUntranslatedIMEMessage(const base::NativeEvent& event,
48 NativeEventResult* result) { 50 NativeEventResult* result) {
49 // This method is not called on non-Windows platforms. See the comments for 51 // This method is not called on non-Windows platforms. See the comments for
50 // ui::InputMethod::OnUntranslatedIMEMessage(). 52 // ui::InputMethod::OnUntranslatedIMEMessage().
51 return false; 53 return false;
52 } 54 }
53 55
54 void InputMethodMus::DispatchKeyEvent(ui::KeyEvent* event) { 56 void InputMethodMus::DispatchKeyEvent(ui::KeyEvent* event) {
57 DispatchKeyEvent(event, nullptr);
58 }
59
60 void InputMethodMus::DispatchKeyEvent(
sky 2016/10/14 22:15:51 Definition and declaration order should match (see
61 ui::KeyEvent* event,
62 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) {
55 DCHECK(event->type() == ui::ET_KEY_PRESSED || 63 DCHECK(event->type() == ui::ET_KEY_PRESSED ||
56 event->type() == ui::ET_KEY_RELEASED); 64 event->type() == ui::ET_KEY_RELEASED);
57 65
58 // If no text input client, do nothing. 66 // If no text input client, do nothing.
59 if (!GetTextInputClient()) { 67 if (!GetTextInputClient()) {
60 ignore_result(DispatchKeyEventPostIME(event)); 68 ignore_result(DispatchKeyEventPostIME(event));
69 if (ack_callback) {
70 ack_callback->Run(event->handled() ? EventResult::HANDLED
71 : EventResult::UNHANDLED);
72 }
61 return; 73 return;
62 } 74 }
63 75
64 // TODO(moshayedi): crbug.com/641355. Currently if we stop propagation of 76 // IME driver will notify us whether it handled the event or not by calling
65 // non-char events here, accelerators ddn't work. This is because we send the 77 // ProcessKeyEventCallback(), in which we will run the |ack_callback| to tell
66 // event ack too early in NativeWidgetMus. We should send both char and 78 // the window server if client handled the event or not.
67 // non-char events to the IME driver once we fix this. 79 input_method_->ProcessKeyEvent(
68 if (event->is_char()) { 80 ui::Event::Clone(*event),
69 // IME driver will notify the text input client if it is not interested in 81 base::Bind(&InputMethodMus::ProcessKeyEventCallback,
70 // event, which in turn will call DispatchKeyEventPostIME(). 82 base::Unretained(this), *event, Passed(&ack_callback)));
71 input_method_->ProcessKeyEvent(ui::Event::Clone(*event));
72 event->StopPropagation();
73 return;
74 }
75
76 ignore_result(DispatchKeyEventPostIME(event));
77 } 83 }
78 84
79 void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) { 85 void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) {
80 if (IsTextInputClientFocused(client)) 86 if (IsTextInputClientFocused(client))
81 UpdateTextInputType(); 87 UpdateTextInputType();
82 InputMethodBase::OnTextInputTypeChanged(client); 88 InputMethodBase::OnTextInputTypeChanged(client);
83 89
84 if (input_method_) { 90 if (input_method_) {
85 input_method_->OnTextInputTypeChanged( 91 input_method_->OnTextInputTypeChanged(
86 static_cast<ui::mojom::TextInputType>(client->GetTextInputType())); 92 static_cast<ui::mojom::TextInputType>(client->GetTextInputType()));
(...skipping 20 matching lines...) Expand all
107 // mean for displaying candidate list popup. 113 // mean for displaying candidate list popup.
108 return false; 114 return false;
109 } 115 }
110 116
111 void InputMethodMus::OnDidChangeFocusedClient( 117 void InputMethodMus::OnDidChangeFocusedClient(
112 ui::TextInputClient* focused_before, 118 ui::TextInputClient* focused_before,
113 ui::TextInputClient* focused) { 119 ui::TextInputClient* focused) {
114 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); 120 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
115 UpdateTextInputType(); 121 UpdateTextInputType();
116 122
117 text_input_client_ = base::MakeUnique<TextInputClientImpl>(focused, this); 123 text_input_client_ = base::MakeUnique<TextInputClientImpl>(focused);
118 ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(), 124 ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(),
119 GetProxy(&input_method_)); 125 GetProxy(&input_method_));
120 } 126 }
121 127
122 void InputMethodMus::UpdateTextInputType() { 128 void InputMethodMus::UpdateTextInputType() {
123 ui::TextInputType type = GetTextInputType(); 129 ui::TextInputType type = GetTextInputType();
124 mojo::TextInputStatePtr state = mojo::TextInputState::New(); 130 mojo::TextInputStatePtr state = mojo::TextInputState::New();
125 state->type = mojo::ConvertTo<mojo::TextInputType>(type); 131 state->type = mojo::ConvertTo<mojo::TextInputType>(type);
126 if (window_) { 132 if (window_) {
127 if (type != ui::TEXT_INPUT_TYPE_NONE) 133 if (type != ui::TEXT_INPUT_TYPE_NONE)
128 window_->SetImeVisibility(true, std::move(state)); 134 window_->SetImeVisibility(true, std::move(state));
129 else 135 else
130 window_->SetTextInputState(std::move(state)); 136 window_->SetTextInputState(std::move(state));
131 } 137 }
132 } 138 }
133 139
140 void InputMethodMus::ProcessKeyEventCallback(
141 const ui::KeyEvent& event,
142 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback,
143 bool handled) {
144 EventResult event_result;
145 if (!handled) {
146 // If not handled by IME, try dispatching the event to delegate to see if
147 // any client-side post-ime processing needs to be done. This includes cases
148 // like backspace, return key, etc.
149 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event);
150 ignore_result(DispatchKeyEventPostIME(event_clone->AsKeyEvent()));
151 event_result =
152 event_clone->handled() ? EventResult::HANDLED : EventResult::UNHANDLED;
153 } else {
154 event_result = EventResult::HANDLED;
155 }
156 // |ack_callback| can be null if the standard form of DispatchKeyEvent() is
157 // called instead of the version which provides a callback. In mus+ash we
158 // use the version with callback, but some unittests use the standard form.
159 if (ack_callback)
160 ack_callback->Run(event_result);
161 }
162
134 } // namespace views 163 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698