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

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: Fixed views_mus_unittests. 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
19 namespace {
20 void DoNothing(EventResult) {}
21 }
22
17 namespace views { 23 namespace views {
18 24
19 //////////////////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////////////////
20 // InputMethodMus, public: 26 // InputMethodMus, public:
21 27
22 InputMethodMus::InputMethodMus(ui::internal::InputMethodDelegate* delegate, 28 InputMethodMus::InputMethodMus(ui::internal::InputMethodDelegate* delegate,
23 ui::Window* window) 29 ui::Window* window)
24 : window_(window) { 30 : window_(window) {
25 SetDelegate(delegate); 31 SetDelegate(delegate);
26 } 32 }
(...skipping 18 matching lines...) Expand all
45 } 51 }
46 52
47 bool InputMethodMus::OnUntranslatedIMEMessage(const base::NativeEvent& event, 53 bool InputMethodMus::OnUntranslatedIMEMessage(const base::NativeEvent& event,
48 NativeEventResult* result) { 54 NativeEventResult* result) {
49 // This method is not called on non-Windows platforms. See the comments for 55 // This method is not called on non-Windows platforms. See the comments for
50 // ui::InputMethod::OnUntranslatedIMEMessage(). 56 // ui::InputMethod::OnUntranslatedIMEMessage().
51 return false; 57 return false;
52 } 58 }
53 59
54 void InputMethodMus::DispatchKeyEvent(ui::KeyEvent* event) { 60 void InputMethodMus::DispatchKeyEvent(ui::KeyEvent* event) {
61 DispatchKeyEvent(
62 event,
63 std::unique_ptr<base::Callback<void(EventResult)>>(
64 new base::Callback<void(EventResult)>(base::Bind(&DoNothing))));
sadrul 2016/10/13 16:36:29 Send nullptr instead?
65 }
66
67 void InputMethodMus::DispatchKeyEvent(
68 ui::KeyEvent* event,
69 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) {
55 DCHECK(event->type() == ui::ET_KEY_PRESSED || 70 DCHECK(event->type() == ui::ET_KEY_PRESSED ||
56 event->type() == ui::ET_KEY_RELEASED); 71 event->type() == ui::ET_KEY_RELEASED);
57 72
58 // If no text input client, do nothing. 73 // If no text input client, do nothing.
59 if (!GetTextInputClient()) { 74 if (!GetTextInputClient()) {
60 ignore_result(DispatchKeyEventPostIME(event)); 75 ignore_result(DispatchKeyEventPostIME(event));
76 ack_callback->Run(event->handled() ? EventResult::HANDLED
77 : EventResult::UNHANDLED);
61 return; 78 return;
62 } 79 }
63 80
64 // TODO(moshayedi): crbug.com/641355. Currently if we stop propagation of 81 // 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 82 // ProcessKeyEventCallback(), in which we will run the |ack_callback| to tell
66 // event ack too early in NativeWidgetMus. We should send both char and 83 // the window server if client handled the event or not.
67 // non-char events to the IME driver once we fix this. 84 input_method_->ProcessKeyEvent(
68 if (event->is_char()) { 85 ui::Event::Clone(*event),
69 // IME driver will notify the text input client if it is not interested in 86 base::Bind(&InputMethodMus::ProcessKeyEventCallback,
70 // event, which in turn will call DispatchKeyEventPostIME(). 87 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 } 88 }
78 89
79 void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) { 90 void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) {
80 if (IsTextInputClientFocused(client)) 91 if (IsTextInputClientFocused(client))
81 UpdateTextInputType(); 92 UpdateTextInputType();
82 InputMethodBase::OnTextInputTypeChanged(client); 93 InputMethodBase::OnTextInputTypeChanged(client);
83 94
84 if (input_method_) { 95 if (input_method_) {
85 input_method_->OnTextInputTypeChanged( 96 input_method_->OnTextInputTypeChanged(
86 static_cast<ui::mojom::TextInputType>(client->GetTextInputType())); 97 static_cast<ui::mojom::TextInputType>(client->GetTextInputType()));
(...skipping 20 matching lines...) Expand all
107 // mean for displaying candidate list popup. 118 // mean for displaying candidate list popup.
108 return false; 119 return false;
109 } 120 }
110 121
111 void InputMethodMus::OnDidChangeFocusedClient( 122 void InputMethodMus::OnDidChangeFocusedClient(
112 ui::TextInputClient* focused_before, 123 ui::TextInputClient* focused_before,
113 ui::TextInputClient* focused) { 124 ui::TextInputClient* focused) {
114 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); 125 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
115 UpdateTextInputType(); 126 UpdateTextInputType();
116 127
117 text_input_client_ = base::MakeUnique<TextInputClientImpl>(focused, this); 128 text_input_client_ = base::MakeUnique<TextInputClientImpl>(focused);
118 ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(), 129 ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(),
119 GetProxy(&input_method_)); 130 GetProxy(&input_method_));
120 } 131 }
121 132
122 void InputMethodMus::UpdateTextInputType() { 133 void InputMethodMus::UpdateTextInputType() {
123 ui::TextInputType type = GetTextInputType(); 134 ui::TextInputType type = GetTextInputType();
124 mojo::TextInputStatePtr state = mojo::TextInputState::New(); 135 mojo::TextInputStatePtr state = mojo::TextInputState::New();
125 state->type = mojo::ConvertTo<mojo::TextInputType>(type); 136 state->type = mojo::ConvertTo<mojo::TextInputType>(type);
126 if (window_) { 137 if (window_) {
127 if (type != ui::TEXT_INPUT_TYPE_NONE) 138 if (type != ui::TEXT_INPUT_TYPE_NONE)
128 window_->SetImeVisibility(true, std::move(state)); 139 window_->SetImeVisibility(true, std::move(state));
129 else 140 else
130 window_->SetTextInputState(std::move(state)); 141 window_->SetTextInputState(std::move(state));
131 } 142 }
132 } 143 }
133 144
145 void InputMethodMus::ProcessKeyEventCallback(
146 const ui::KeyEvent& event,
147 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback,
148 bool handled) {
149 EventResult event_result;
150 if (!handled) {
151 // If not handled by IME, try dispatching the event to delegate to see if
152 // any client-side post-ime processing needs to be done. This includes cases
153 // like backspace, return key, etc.
154 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event);
155 ignore_result(DispatchKeyEventPostIME(event_clone->AsKeyEvent()));
156 event_result =
157 event_clone->handled() ? EventResult::HANDLED : EventResult::UNHANDLED;
158 } else {
159 event_result = EventResult::HANDLED;
160 }
161 ack_callback->Run(event_result);
162 }
163
134 } // namespace views 164 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698