Yuichiro Hanada | e05251ec | 2018-05-23 06:19:59 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Yuichiro Hanada | 0109cc4 | 2018-12-18 01:13:57 | [diff] [blame] | 5 | // Next MinVersion: 6 |
yusukes | c4aa423 | 2018-08-27 17:22:45 | [diff] [blame] | 6 | |
Yuichiro Hanada | e05251ec | 2018-05-23 06:19:59 | [diff] [blame] | 7 | module arc.mojom; |
| 8 | |
Yuichiro Hanada | 176393f | 2018-10-01 09:02:14 | [diff] [blame] | 9 | import "mojo/public/mojom/base/string16.mojom"; |
| 10 | import "components/arc/common/gfx.mojom"; |
| 11 | import "components/arc/common/ime.mojom"; |
| 12 | |
Yuichiro Hanada | e05251ec | 2018-05-23 06:19:59 | [diff] [blame] | 13 | // Represents the information of an Android IME. |
| 14 | struct ImeInfo { |
| 15 | // The unique ID for the Android IME. Corresponds to InputMethodInfo.getId(). |
| 16 | string ime_id; |
| 17 | // The user-displayed label for the IME. Corresponds to |
| 18 | // InputMethodInfo.loadLabel(). |
| 19 | string display_name; |
| 20 | // Whether the IME is enabled or not. It's equivalent to whether the IME is |
| 21 | // in ENABLED_INPUT_METHODS settings. |
| 22 | bool enabled; |
| 23 | // intent: URL to open the settings activity of the IME. |
| 24 | string settings_url; |
| 25 | }; |
| 26 | |
Yuichiro Hanada | 176393f | 2018-10-01 09:02:14 | [diff] [blame] | 27 | // Represents the information of the text field. |
| 28 | [MinVersion=2] |
| 29 | struct TextInputState { |
| 30 | // The current cursor position in 16-bit code units in the overall text |
| 31 | // of the text field. |
| 32 | int32 cursor_pos; |
| 33 | // A part of the text in the text field. The text is in UTF-8, |
| 34 | // but should be converted to UTF-16 in both ends of mojo call. |
| 35 | mojo_base.mojom.String16 text; |
| 36 | // The range of |text| in 16-bit code units index in the overall text |
| 37 | // of the text field. |
| 38 | Range text_range; |
| 39 | // The range of the selected text in 16-bit code units index |
| 40 | // in the overall text of the text field. |
| 41 | Range selection_range; |
| 42 | // The type of the text field. |
| 43 | TextInputType type; |
| 44 | // Indicates that IMEs should do personalized learning based on the contents. |
| 45 | bool should_do_learning; |
| 46 | // The other text input flags. For example auto-capitalization flag |
| 47 | // and auto-correction flag are included in this flag. |
| 48 | // These values are from ui::TextInputFlags in ui/base/ime/text_input_flags.h |
| 49 | uint32 flags; |
| 50 | // Whether this state update is sent as a first update after an operation |
| 51 | // by Android IMEs. |
| 52 | // Android IMEs need this flag to know the latest state after their operation |
| 53 | // becomes effective. |
| 54 | bool first_update_after_operation; |
| 55 | }; |
| 56 | |
| 57 | // This interface provides methods to control a text field. |
| 58 | // It is generated for each focused text field and passed to Android. |
| 59 | // This interface will be closed when the focus moves to another text field. |
| 60 | // |
Yuichiro Hanada | 0109cc4 | 2018-12-18 01:13:57 | [diff] [blame] | 61 | // Next method ID: 6 |
Yuichiro Hanada | 176393f | 2018-10-01 09:02:14 | [diff] [blame] | 62 | [MinVersion=2] |
| 63 | interface InputConnection { |
| 64 | // Commits text to the focused text field and set the new cursor position. |
| 65 | CommitText@0(mojo_base.mojom.String16 text, int32 new_cursor_pos); |
| 66 | |
| 67 | // Deletes |before| characters of text before the cursor position, |
| 68 | // and deletes |after| characters of text after the cursor position. |
| 69 | DeleteSurroundingText@1(int32 before, int32 after); |
| 70 | |
| 71 | // Has the text field finish the ongoing composition. |
| 72 | FinishComposingText@2(); |
| 73 | |
| 74 | // Requests to send the latest TextInputState of the active text field. |
| 75 | // For example, this is called when the IME calls getTextBeforeCursor() |
| 76 | // and getTextAfterCursor(). |
| 77 | RequestTextInputState@3() => (TextInputState state); |
| 78 | |
| 79 | // Replaces the currently composing text with the given text, |
Yuichiro Hanada | 4ac1c772 | 2018-10-04 09:34:48 | [diff] [blame] | 80 | // and sets the cursor position and the selection range. |
| 81 | SetComposingText@4(mojo_base.mojom.String16 text, |
| 82 | int32 new_cursor_pos, |
| 83 | [MinVersion=3] Range? new_selection_range); |
Yuichiro Hanada | cfb63864 | 2018-12-13 10:16:35 | [diff] [blame] | 84 | |
| 85 | // Selects the given UTF-16 based character range. |
Yuichiro Hanada | 0109cc4 | 2018-12-18 01:13:57 | [diff] [blame] | 86 | [MinVersion=5] SetSelection@5(Range new_selection_range); |
Yuichiro Hanada | 176393f | 2018-10-01 09:02:14 | [diff] [blame] | 87 | }; |
| 88 | |
Yuichiro Hanada | e05251ec | 2018-05-23 06:19:59 | [diff] [blame] | 89 | // This interface is called by container when Android's InputMethodManager state |
| 90 | // is changed. |
| 91 | // In Android container, ArcInputMethodService IME is pre-installed to bridge |
| 92 | // Chrome OS's IME to Android apps. The bridge is defined in ime.mojom. |
| 93 | // |
yusukes | c4aa423 | 2018-08-27 17:22:45 | [diff] [blame] | 94 | // Next method ID: 3 |
Yuichiro Hanada | e05251ec | 2018-05-23 06:19:59 | [diff] [blame] | 95 | interface InputMethodManagerHost { |
| 96 | // Notifies Chrome that active IME in Android is changed. |
| 97 | OnActiveImeChanged@0(string ime_id); |
| 98 | |
yusukes | c4aa423 | 2018-08-27 17:22:45 | [diff] [blame] | 99 | // Notifies Chrome of the ID of the IME Android has disabled. |
| 100 | [MinVersion=1] OnImeDisabled@2(string ime_id); |
| 101 | |
Yuichiro Hanada | e05251ec | 2018-05-23 06:19:59 | [diff] [blame] | 102 | // Notifies Chrome of information of installed IMEs in Android. |
| 103 | // The passed list doesn't contain information of our bridge IME, |
| 104 | // ArcInputMethodService. |
| 105 | OnImeInfoChanged@1(array<ImeInfo> ime_infos); |
| 106 | }; |
| 107 | |
| 108 | // This interface provides methods to control Android's InputMethodManager. |
| 109 | // |
Yuichiro Hanada | 7e2e3d3 | 2018-10-11 14:10:16 | [diff] [blame] | 110 | // Next method ID: 7 |
Yuichiro Hanada | e05251ec | 2018-05-23 06:19:59 | [diff] [blame] | 111 | interface InputMethodManagerInstance { |
| 112 | // Establishes full-duplex communication with the host. |
| 113 | Init@0(InputMethodManagerHost host_ptr) => (); |
| 114 | |
| 115 | // Enables/Disables an IME in Android. Calling this method will add/remove |
| 116 | // the specified IME to/from ENABLED_INPUT_METHODS settings. |
| 117 | EnableIme@1(string ime_id, bool enable) => (bool success); |
| 118 | |
| 119 | // Switches active IME in Android. |
| 120 | SwitchImeTo@2(string ime_id) => (bool success); |
Yuichiro Hanada | 176393f | 2018-10-01 09:02:14 | [diff] [blame] | 121 | |
| 122 | // Notifies Android's ArcInputMethodManagerService that |
| 123 | // a text field is focused. |
| 124 | [MinVersion=2] Focus@3(InputConnection connection, |
| 125 | TextInputState initial_state); |
| 126 | |
| 127 | // Sends the latest TextInputState of the active text field. |
| 128 | [MinVersion=2] UpdateTextInputState@4(TextInputState state); |
Yuichiro Hanada | 7e2e3d3 | 2018-10-11 14:10:16 | [diff] [blame] | 129 | |
| 130 | // Requests the active IME to show virtual keyboard. |
| 131 | [MinVersion=4] ShowVirtualKeyboard@5(); |
| 132 | |
| 133 | // Requests the active IME to hide virtual keyboard. |
| 134 | [MinVersion=4] HideVirtualKeyboard@6(); |
Yuichiro Hanada | e05251ec | 2018-05-23 06:19:59 | [diff] [blame] | 135 | }; |