summaryrefslogtreecommitdiff
path: root/chromium/components/arc/mojom/input_method_manager.mojom
blob: c8e3dcde0293b2c719d5a5e78ac89868332c5d2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Next MinVersion: 9

module arc.mojom;

import "mojo/public/mojom/base/string16.mojom";
import "components/arc/mojom/gfx.mojom";
import "components/arc/mojom/ime.mojom";

// Represents the information of an Android IME.
struct ImeInfo {
  // The unique ID for the Android IME. Corresponds to InputMethodInfo.getId().
  string ime_id;
  // The user-displayed label for the IME. Corresponds to
  // InputMethodInfo.loadLabel().
  string display_name;
  // Whether the IME is enabled or not. It's equivalent to whether the IME is
  // in ENABLED_INPUT_METHODS settings.
  bool enabled;
  // intent: URL to open the settings activity of the IME.
  string settings_url;
  // Whether the IME is allowed to be enabled in clamshell mode.
  [MinVersion=8] bool is_allowed_in_clamshell_mode;
};

// Represents the information of the text field.
[MinVersion=2]
struct TextInputState {
  // The current cursor position in 16-bit code units in the overall text
  // of the text field.
  int32 cursor_pos;
  // A part of the text in the text field. The text is in UTF-8,
  // but should be converted to UTF-16 in both ends of mojo call.
  mojo_base.mojom.String16 text;
  // The range of |text| in 16-bit code units index in the overall text
  // of the text field.
  Range text_range;
  // The range of the selected text in 16-bit code units index
  // in the overall text of the text field.
  Range selection_range;
  // The type of the text field.
  TextInputType type;
  // Indicates that IMEs should do personalized learning based on the contents.
  bool should_do_learning;
  // The other text input flags. For example auto-capitalization flag
  // and auto-correction flag are included in this flag.
  // These values are from ui::TextInputFlags in ui/base/ime/text_input_flags.h
  uint32 flags;
  // Whether this state update is sent as a first update after an operation
  // by Android IMEs.
  // Android IMEs need this flag to know the latest state after their operation
  // becomes effective.
  bool first_update_after_operation;
  // The range of the composition text in 16-bit code units index
  // in the overall text of the text field.
  [MinVersion=6] Range? composition_text_range;
};

// Represents the information of a key event.
[MinVersion=7]
struct KeyEventData {
  // Whether the event is a press event or a release event.
  bool pressed;
  // The key touched in the event represented in |ui::KeyboardCode|.
  int32 key_code;
  // The flags for modifiers state.
  bool is_shift_down;
  bool is_control_down;
  bool is_alt_down;
  bool is_capslock_on;
};

// This interface provides methods to control a text field.
// It is generated for each focused text field and passed to Android.
// This interface will be closed when the focus moves to another text field.
//
// Next method ID: 8
[MinVersion=2]
interface InputConnection {
  // Commits text to the focused text field and set the new cursor position.
  CommitText@0(mojo_base.mojom.String16 text, int32 new_cursor_pos);

  // Deletes |before| characters of text before the cursor position,
  // and deletes |after| characters of text after the cursor position.
  DeleteSurroundingText@1(int32 before, int32 after);

  // Has the text field finish the ongoing composition.
  FinishComposingText@2();

  // Requests to send the latest TextInputState of the active text field.
  // For example, this is called when the IME calls getTextBeforeCursor()
  // and getTextAfterCursor().
  RequestTextInputState@3() => (TextInputState state);

  // Replaces the currently composing text with the given text,
  // and sets the cursor position and the selection range.
  SetComposingText@4(mojo_base.mojom.String16 text,
                     int32 new_cursor_pos,
                     [MinVersion=3] Range? new_selection_range);

  // Selects the given UTF-16 based character range.
  [MinVersion=5] SetSelection@5(Range new_selection_range);

  // Sends a key event.
  [MinVersion=7] SendKeyEvent@6(KeyEventData key_event_data);

  // Starts composition over a given range.
  [MinVersion=8] SetCompositionRange@7(Range new_range);
};

// This interface is called by container when Android's InputMethodManager state
// is changed.
// In Android container, ArcInputMethodService IME is pre-installed to bridge
// Chrome OS's IME to Android apps. The bridge is defined in ime.mojom.
//
// Next method ID: 3
interface InputMethodManagerHost {
  // Notifies Chrome that active IME in Android is changed.
  OnActiveImeChanged@0(string ime_id);

  // Notifies Chrome of the ID of the IME Android has disabled.
  [MinVersion=1] OnImeDisabled@2(string ime_id);

  // Notifies Chrome of information of installed IMEs in Android.
  // The passed list doesn't contain information of our bridge IME,
  // ArcInputMethodService.
  OnImeInfoChanged@1(array<ImeInfo> ime_infos);
};

// This interface provides methods to control Android's InputMethodManager.
//
// Next method ID: 7
interface InputMethodManagerInstance {
  // Establishes full-duplex communication with the host.
  Init@0(InputMethodManagerHost host_ptr) => ();

  // Enables/Disables an IME in Android. Calling this method will add/remove
  // the specified IME to/from ENABLED_INPUT_METHODS settings.
  EnableIme@1(string ime_id, bool enable) => (bool success);

  // Switches active IME in Android.
  SwitchImeTo@2(string ime_id) => (bool success);

  // Notifies Android's ArcInputMethodManagerService that
  // a text field is focused.
  [MinVersion=2] Focus@3(InputConnection connection,
                         TextInputState initial_state);

  // Sends the latest TextInputState of the active text field.
  [MinVersion=2] UpdateTextInputState@4(TextInputState state);

  // Requests the active IME to show virtual keyboard.
  [MinVersion=4] ShowVirtualKeyboard@5();

  // Requests the active IME to hide virtual keyboard.
  [MinVersion=4] HideVirtualKeyboard@6();
};