| 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/aura/mus/input_method_mus.h" | 5 #include "ui/aura/mus/input_method_mus.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "services/ui/public/interfaces/constants.mojom.h" | 10 #include "services/ui/public/interfaces/constants.mojom.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 void InputMethodMus::DispatchKeyEvent( | 49 void InputMethodMus::DispatchKeyEvent( |
| 50 ui::KeyEvent* event, | 50 ui::KeyEvent* event, |
| 51 std::unique_ptr<EventResultCallback> ack_callback) { | 51 std::unique_ptr<EventResultCallback> ack_callback) { |
| 52 DCHECK(event->type() == ui::ET_KEY_PRESSED || | 52 DCHECK(event->type() == ui::ET_KEY_PRESSED || |
| 53 event->type() == ui::ET_KEY_RELEASED); | 53 event->type() == ui::ET_KEY_RELEASED); |
| 54 | 54 |
| 55 // If no text input client, do nothing. | 55 // If no text input client, do nothing. |
| 56 if (!GetTextInputClient()) { | 56 if (!GetTextInputClient()) { |
| 57 ignore_result(DispatchKeyEventPostIME(event)); | 57 DispatchKeyEventPostIME(event); |
| 58 if (ack_callback) { | 58 if (ack_callback) { |
| 59 ack_callback->Run(event->handled() ? EventResult::HANDLED | 59 ack_callback->Run(event->handled() ? EventResult::HANDLED |
| 60 : EventResult::UNHANDLED); | 60 : EventResult::UNHANDLED); |
| 61 } | 61 } |
| 62 return; | 62 return; |
| 63 } | 63 } |
| 64 | 64 |
| 65 SendKeyEventToInputMethod(*event, std::move(ack_callback)); | 65 SendKeyEventToInputMethod(*event, std::move(ack_callback)); |
| 66 } | 66 } |
| 67 | 67 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 bool InputMethodMus::IsCandidatePopupOpen() const { | 116 bool InputMethodMus::IsCandidatePopupOpen() const { |
| 117 // TODO(moshayedi): crbug.com/637416. Implement this properly when we have a | 117 // TODO(moshayedi): crbug.com/637416. Implement this properly when we have a |
| 118 // mean for displaying candidate list popup. | 118 // mean for displaying candidate list popup. |
| 119 return false; | 119 return false; |
| 120 } | 120 } |
| 121 | 121 |
| 122 void InputMethodMus::SendKeyEventToInputMethod( | 122 void InputMethodMus::SendKeyEventToInputMethod( |
| 123 const ui::KeyEvent& event, | 123 const ui::KeyEvent& event, |
| 124 std::unique_ptr<EventResultCallback> ack_callback) { | 124 std::unique_ptr<EventResultCallback> ack_callback) { |
| 125 if (!input_method_) { |
| 126 // This code path is hit in tests that don't connect to the server. |
| 127 DCHECK(!ack_callback); |
| 128 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event); |
| 129 DispatchKeyEventPostIME(event_clone->AsKeyEvent()); |
| 130 return; |
| 131 } |
| 125 // IME driver will notify us whether it handled the event or not by calling | 132 // IME driver will notify us whether it handled the event or not by calling |
| 126 // ProcessKeyEventCallback(), in which we will run the |ack_callback| to tell | 133 // ProcessKeyEventCallback(), in which we will run the |ack_callback| to tell |
| 127 // the window server if client handled the event or not. | 134 // the window server if client handled the event or not. |
| 128 pending_callbacks_.push_back(std::move(ack_callback)); | 135 pending_callbacks_.push_back(std::move(ack_callback)); |
| 129 input_method_->ProcessKeyEvent( | 136 input_method_->ProcessKeyEvent( |
| 130 ui::Event::Clone(event), | 137 ui::Event::Clone(event), |
| 131 base::Bind(&InputMethodMus::ProcessKeyEventCallback, | 138 base::Bind(&InputMethodMus::ProcessKeyEventCallback, |
| 132 base::Unretained(this), event)); | 139 base::Unretained(this), event)); |
| 133 } | 140 } |
| 134 | 141 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 180 |
| 174 void InputMethodMus::ProcessKeyEventCallback( | 181 void InputMethodMus::ProcessKeyEventCallback( |
| 175 const ui::KeyEvent& event, | 182 const ui::KeyEvent& event, |
| 176 bool handled) { | 183 bool handled) { |
| 177 EventResult event_result; | 184 EventResult event_result; |
| 178 if (!handled) { | 185 if (!handled) { |
| 179 // If not handled by IME, try dispatching the event to delegate to see if | 186 // If not handled by IME, try dispatching the event to delegate to see if |
| 180 // any client-side post-ime processing needs to be done. This includes cases | 187 // any client-side post-ime processing needs to be done. This includes cases |
| 181 // like backspace, return key, etc. | 188 // like backspace, return key, etc. |
| 182 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event); | 189 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event); |
| 183 ignore_result(DispatchKeyEventPostIME(event_clone->AsKeyEvent())); | 190 DispatchKeyEventPostIME(event_clone->AsKeyEvent()); |
| 184 event_result = | 191 event_result = |
| 185 event_clone->handled() ? EventResult::HANDLED : EventResult::UNHANDLED; | 192 event_clone->handled() ? EventResult::HANDLED : EventResult::UNHANDLED; |
| 186 } else { | 193 } else { |
| 187 event_result = EventResult::HANDLED; | 194 event_result = EventResult::HANDLED; |
| 188 } | 195 } |
| 189 DCHECK(!pending_callbacks_.empty()); | 196 DCHECK(!pending_callbacks_.empty()); |
| 190 std::unique_ptr<EventResultCallback> ack_callback = | 197 std::unique_ptr<EventResultCallback> ack_callback = |
| 191 std::move(pending_callbacks_.front()); | 198 std::move(pending_callbacks_.front()); |
| 192 pending_callbacks_.pop_front(); | 199 pending_callbacks_.pop_front(); |
| 193 // |ack_callback| can be null if the standard form of DispatchKeyEvent() is | 200 // |ack_callback| can be null if the standard form of DispatchKeyEvent() is |
| 194 // called instead of the version which provides a callback. In mus+ash we | 201 // called instead of the version which provides a callback. In mus+ash we |
| 195 // use the version with callback, but some unittests use the standard form. | 202 // use the version with callback, but some unittests use the standard form. |
| 196 if (ack_callback) | 203 if (ack_callback) |
| 197 ack_callback->Run(event_result); | 204 ack_callback->Run(event_result); |
| 198 } | 205 } |
| 199 | 206 |
| 200 } // namespace aura | 207 } // namespace aura |
| OLD | NEW |