| 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 #ifndef UI_AURA_MUS_INPUT_METHOD_MUS_H_ | 5 #ifndef UI_AURA_MUS_INPUT_METHOD_MUS_H_ |
| 6 #define UI_AURA_MUS_INPUT_METHOD_MUS_H_ | 6 #define UI_AURA_MUS_INPUT_METHOD_MUS_H_ |
| 7 | 7 |
| 8 #include <deque> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "mojo/public/cpp/bindings/strong_binding.h" | 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 10 #include "services/service_manager/public/cpp/connector.h" | 12 #include "services/service_manager/public/cpp/connector.h" |
| 11 #include "services/ui/public/interfaces/ime/ime.mojom.h" | 13 #include "services/ui/public/interfaces/ime/ime.mojom.h" |
| 12 #include "ui/aura/aura_export.h" | 14 #include "ui/aura/aura_export.h" |
| 13 #include "ui/base/ime/input_method_base.h" | 15 #include "ui/base/ime/input_method_base.h" |
| 14 | 16 |
| 15 namespace ui { | 17 namespace ui { |
| 16 namespace mojom { | 18 namespace mojom { |
| 17 enum class EventResult; | 19 enum class EventResult; |
| 18 } | 20 } |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace aura { | 23 namespace aura { |
| 22 | 24 |
| 25 class InputMethodMusTestApi; |
| 23 class TextInputClientImpl; | 26 class TextInputClientImpl; |
| 24 class Window; | 27 class Window; |
| 25 | 28 |
| 26 class AURA_EXPORT InputMethodMus : public ui::InputMethodBase { | 29 class AURA_EXPORT InputMethodMus : public ui::InputMethodBase { |
| 27 public: | 30 public: |
| 31 using EventResultCallback = base::Callback<void(ui::mojom::EventResult)>; |
| 32 |
| 28 InputMethodMus(ui::internal::InputMethodDelegate* delegate, Window* window); | 33 InputMethodMus(ui::internal::InputMethodDelegate* delegate, Window* window); |
| 29 ~InputMethodMus() override; | 34 ~InputMethodMus() override; |
| 30 | 35 |
| 31 void Init(service_manager::Connector* connector); | 36 void Init(service_manager::Connector* connector); |
| 32 void DispatchKeyEvent( | 37 void DispatchKeyEvent(ui::KeyEvent* event, |
| 33 ui::KeyEvent* event, | 38 std::unique_ptr<EventResultCallback> ack_callback); |
| 34 std::unique_ptr<base::Callback<void(ui::mojom::EventResult)>> | |
| 35 ack_callback); | |
| 36 | 39 |
| 37 // Overridden from ui::InputMethod: | 40 // Overridden from ui::InputMethod: |
| 38 void OnFocus() override; | 41 void OnFocus() override; |
| 39 void OnBlur() override; | 42 void OnBlur() override; |
| 40 bool OnUntranslatedIMEMessage(const base::NativeEvent& event, | 43 bool OnUntranslatedIMEMessage(const base::NativeEvent& event, |
| 41 NativeEventResult* result) override; | 44 NativeEventResult* result) override; |
| 42 void DispatchKeyEvent(ui::KeyEvent* event) override; | 45 void DispatchKeyEvent(ui::KeyEvent* event) override; |
| 43 void OnTextInputTypeChanged(const ui::TextInputClient* client) override; | 46 void OnTextInputTypeChanged(const ui::TextInputClient* client) override; |
| 44 void OnCaretBoundsChanged(const ui::TextInputClient* client) override; | 47 void OnCaretBoundsChanged(const ui::TextInputClient* client) override; |
| 45 void CancelComposition(const ui::TextInputClient* client) override; | 48 void CancelComposition(const ui::TextInputClient* client) override; |
| 46 void OnInputLocaleChanged() override; | 49 void OnInputLocaleChanged() override; |
| 47 bool IsCandidatePopupOpen() const override; | 50 bool IsCandidatePopupOpen() const override; |
| 48 | 51 |
| 49 private: | 52 private: |
| 53 friend class InputMethodMusTestApi; |
| 50 friend TextInputClientImpl; | 54 friend TextInputClientImpl; |
| 51 | 55 |
| 56 // Called from DispatchKeyEvent() to call to the InputMethod. |
| 57 void SendKeyEventToInputMethod( |
| 58 const ui::KeyEvent& event, |
| 59 std::unique_ptr<EventResultCallback> ack_callback); |
| 60 |
| 52 // Overridden from ui::InputMethodBase: | 61 // Overridden from ui::InputMethodBase: |
| 53 void OnDidChangeFocusedClient(ui::TextInputClient* focused_before, | 62 void OnDidChangeFocusedClient(ui::TextInputClient* focused_before, |
| 54 ui::TextInputClient* focused) override; | 63 ui::TextInputClient* focused) override; |
| 55 | 64 |
| 56 void UpdateTextInputType(); | 65 void UpdateTextInputType(); |
| 66 |
| 67 // Called when the server responds to our request to process an event. |
| 57 void ProcessKeyEventCallback( | 68 void ProcessKeyEventCallback( |
| 58 const ui::KeyEvent& event, | 69 const ui::KeyEvent& event, |
| 59 std::unique_ptr<base::Callback<void(ui::mojom::EventResult)>> | |
| 60 ack_callback, | |
| 61 bool handled); | 70 bool handled); |
| 62 | 71 |
| 63 // The toplevel window which is not owned by this class. This may be null | 72 // The toplevel window which is not owned by this class. This may be null |
| 64 // for tests. | 73 // for tests. |
| 65 Window* window_; | 74 Window* window_; |
| 66 | 75 |
| 67 // May be null in tests. | 76 // May be null in tests. |
| 68 ui::mojom::IMEServerPtr ime_server_; | 77 ui::mojom::IMEServerPtr ime_server_; |
| 69 ui::mojom::InputMethodPtr input_method_; | 78 ui::mojom::InputMethodPtr input_method_ptr_; |
| 79 // Typically this is the same as |input_method_ptr_|, but it may be mocked |
| 80 // in tests. |
| 81 ui::mojom::InputMethod* input_method_ = nullptr; |
| 70 std::unique_ptr<TextInputClientImpl> text_input_client_; | 82 std::unique_ptr<TextInputClientImpl> text_input_client_; |
| 71 | 83 |
| 84 // Callbacks supplied to DispatchKeyEvent() are added here while awaiting |
| 85 // the response from the server. These are removed when the response is |
| 86 // received (ProcessKeyEventCallback()). |
| 87 std::deque<std::unique_ptr<EventResultCallback>> pending_callbacks_; |
| 88 |
| 72 DISALLOW_COPY_AND_ASSIGN(InputMethodMus); | 89 DISALLOW_COPY_AND_ASSIGN(InputMethodMus); |
| 73 }; | 90 }; |
| 74 | 91 |
| 75 } // namespace aura | 92 } // namespace aura |
| 76 | 93 |
| 77 #endif // UI_AURA_MUS_INPUT_METHOD_MUS_H_ | 94 #endif // UI_AURA_MUS_INPUT_METHOD_MUS_H_ |
| OLD | NEW |