1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/.
7 [JSImplementation="@mozilla.org/b2g-inputmethod;1",
8 NavigatorProperty="mozInputMethod",
9 Func="Navigator::HasInputMethodSupport"]
10 interface MozInputMethod : EventTarget {
11 // Input Method Manager contain a few global methods expose to apps
12 readonly attribute MozInputMethodManager mgmt;
14 // Fired when the input context changes, include changes from and to null.
15 // The new InputContext instance will be available in the event
16 // object under |inputcontext| property. When it changes to null it
17 // means the app (the user of this API) no longer has the control of
18 // the original focused input field.
19 // Note that if the app saves the original context, it might get
20 // void; implementation decides when to void the input context.
21 attribute EventHandler oninputcontextchange;
23 // An "input context" is mapped to a text field that the app is
24 // allow to mutate. this attribute should be null when there is no
25 // text field currently focused.
26 readonly attribute MozInputContext? inputcontext;
29 // Activate or decactive current input method window.
30 void setActive(boolean isActive);
32 // Add a dynamically declared input.
34 // The id must not be the same with any statically declared input in the app
35 // manifest. If an input of the same id is already declared, the info of that
36 // input will be updated.
37 Promise<void> addInput(DOMString inputId, object inputManifest);
39 // Remove a dynamically declared input.
41 // The id must not be the same with any statically declared input in the app
42 // manifest. Silently resolves if the input is not previously declared;
43 // rejects if attempt to remove a statically declared input.
44 Promise<void> removeInput(DOMString id);
46 // The following are internal methods for Firefox OS system app only.
48 // Set the value on the currently focused element. This has to be used
49 // for special situations where the value had to be chosen amongst a
50 // list (type=month) or a widget (type=date, time, etc.).
51 // If the value passed in parameter isn't valid (in the term of HTML5
52 // Forms Validation), the value will simply be ignored by the element.
54 void setValue(DOMString value);
56 // Select the <select> option specified by index.
57 // If this method is called on a <select> that support multiple
58 // selection, then the option specified by index will be added to
60 // If this method is called for a select that does not support multiple
61 // selection the previous element will be unselected.
63 void setSelectedOption(long index);
65 // Select the <select> options specified by indexes. All other options
66 // will be deselected.
67 // If this method is called for a <select> that does not support multiple
68 // selection, then the last index specified in indexes will be selected.
70 void setSelectedOptions(sequence<long> indexes);
76 // Manages the list of IMEs, enables/disables IME and switches to an
78 [JSImplementation="@mozilla.org/b2g-imm;1",
79 Pref="dom.mozInputMethod.enabled"]
80 interface MozInputMethodManager {
81 // Ask the OS to show a list of available IMEs for users to switch from.
82 // OS should ignore this request if the app is currently not the active one.
85 // Ask the OS to switch away from the current active Keyboard app.
86 // OS should ignore this request if the app is currently not the active one.
89 // To know if the OS supports IME switching or not.
90 // Use case: let the keyboard app knows if it is necessary to show the "IME switching"
91 // (globe) button. We have a use case that when there is only one IME enabled, we
92 // should not show the globe icon.
93 boolean supportsSwitching();
95 // Ask the OS to hide the current active Keyboard app. (was: |removeFocus()|)
96 // OS should ignore this request if the app is currently not the active one.
97 // The OS will void the current input context (if it exists).
98 // This method belong to |mgmt| because we would like to allow Keyboard to access to
99 // this method w/o a input context.
103 // The input context, which consists of attributes and information of current input field.
104 // It also hosts the methods available to the keyboard app to mutate the input field represented.
105 // An "input context" gets void when the app is no longer allowed to interact with the text field,
106 // e.g., the text field does no longer exist, the app is being switched to background, and etc.
107 [JSImplementation="@mozilla.org/b2g-inputcontext;1",
108 Pref="dom.mozInputMethod.enabled"]
109 interface MozInputContext: EventTarget {
110 // The tag name of input field, which is enum of "input", "textarea", or "contenteditable"
111 readonly attribute DOMString? type;
112 // The type of the input field, which is enum of text, number, password, url, search, email, and so on.
113 // See http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#states-of-the-type-attribute
114 readonly attribute DOMString? inputType;
116 * The inputmode string, representing the input mode.
117 * See http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#input-modalities:-the-inputmode-attribute
119 readonly attribute DOMString? inputMode;
121 * The primary language for the input field.
122 * It is the value of HTMLElement.lang.
123 * See http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#htmlelement
125 readonly attribute DOMString? lang;
127 * Get the whole text content of the input field.
130 Promise<DOMString> getText(optional long offset, optional long length);
131 // The start and stop position of the selection.
132 readonly attribute long selectionStart;
133 readonly attribute long selectionEnd;
135 // The text before and after the begining of the selected text.
136 readonly attribute DOMString? textBeforeCursor;
137 readonly attribute DOMString? textAfterCursor;
140 * Set the selection range of the the editable text.
141 * Note: This method cannot be used to move the cursor during composition. Calling this
142 * method will cancel composition.
143 * @param start The beginning of the selected text.
144 * @param length The length of the selected text.
146 * Note that the start position should be less or equal to the end position.
147 * To move the cursor, set the start and end position to the same value.
151 Promise<boolean> setSelectionRange(long start, long length);
153 /* User moves the cursor, or changes the selection with other means. If the text around
154 * cursor has changed, but the cursor has not been moved, the IME won't get notification.
156 * A dict is provided in the detail property of the event containing the new values, and
157 * an "ownAction" property to denote the event is the result of our own mutation to
160 attribute EventHandler onselectionchange;
163 * Commit text to current input field and replace text around
164 * cursor position. It will clear the current composition.
166 * @param text The string to be replaced with.
167 * @param offset The offset from the cursor position where replacing starts. Defaults to 0.
168 * @param length The length of text to replace. Defaults to 0.
171 Promise<boolean> replaceSurroundingText(DOMString text, optional long offset, optional long length);
175 * Delete text around the cursor.
176 * @param offset The offset from the cursor position where deletion starts.
177 * @param length The length of text to delete.
178 * TODO: maybe updateSurroundingText(DOMString beforeText, DOMString afterText); ?
181 Promise<boolean> deleteSurroundingText(long offset, long length);
184 * Notifies when the text around the cursor is changed, due to either text
185 * editing or cursor movement. If the cursor has been moved, but the text around has not
186 * changed, the IME won't get notification.
188 * A dict is provided in the detail property of the event containing the new values, and
189 * an "ownAction" property to denote the event is the result of our own mutation to
192 attribute EventHandler onsurroundingtextchange;
195 * send a character with its key events.
196 * @param modifiers see http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/base/nsIDOMWindowUtils.idl#206
197 * @param repeat indicates whether a key would be sent repeatedly.
198 * @return true if succeeds. Otherwise false if the input context becomes void.
199 * Alternative: sendKey(KeyboardEvent event), but we will likely
200 * waste memory for creating the KeyboardEvent object.
201 * Note that, if you want to send a key n times repeatedly, make sure set
202 * parameter repeat to true and invoke sendKey n-1 times, and then set
203 * repeat to false in the last invoke.
205 Promise<boolean> sendKey(long keyCode, long charCode, long modifiers, optional boolean repeat);
208 * Set current composing text. This method will start composition or update
209 * composition if it has started. The composition will be started right
210 * before the cursor position and any selected text will be replaced by the
211 * composing text. When the composition is started, calling this method can
212 * update the text and move cursor winthin the range of the composing text.
213 * @param text The new composition text to show.
214 * @param cursor The new cursor position relative to the start of the
215 * composition text. The cursor should be positioned within the composition
216 * text. This means the value should be >= 0 and <= the length of
217 * composition text. Defaults to the lenght of composition text, i.e., the
218 * cursor will be positioned after the composition text.
219 * @param clauses The array of composition clause information. If not set,
220 * only one clause is supported.
222 * The composing text, which is shown with underlined style to distinguish
223 * from the existing text, is used to compose non-ASCII characters from
224 * keystrokes, e.g. Pinyin or Hiragana. The composing text is the
225 * intermediate text to help input complex character and is not committed to
226 * current input field. Therefore if any text operation other than
227 * composition is performed, the composition will automatically end. Same
228 * apply when the inputContext is lost during an unfinished composition
231 * To finish composition and commit text to current input field, an IME
232 * should call |endComposition|.
234 // XXXbz what is this promise resolved with?
235 Promise<any> setComposition(DOMString text, optional long cursor,
236 optional sequence<CompositionClauseParameters> clauses);
239 * End composition, clear the composing text and commit given text to
240 * current input field. The text will be committed before the cursor
242 * @param text The text to commited before cursor position. If empty string
243 * is given, no text will be committed.
245 * Note that composition always ends automatically with nothing to commit if
246 * the composition does not explicitly end by calling |endComposition|, but
247 * is interrupted by |sendKey|, |setSelectionRange|,
248 * |replaceSurroundingText|, |deleteSurroundingText|, user moving the
249 * cursor, changing the focus, etc.
251 // XXXbz what is this promise resolved with?
252 Promise<any> endComposition(optional DOMString text);
255 enum CompositionClauseSelectionType {
259 "selected-converted-text"
262 dictionary CompositionClauseParameters {
263 DOMString selectionType = "raw-input";