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 // The following are internal methods for Firefox OS system app only.
34 // Set the value on the currently focused element. This has to be used
35 // for special situations where the value had to be chosen amongst a
36 // list (type=month) or a widget (type=date, time, etc.).
37 // If the value passed in parameter isn't valid (in the term of HTML5
38 // Forms Validation), the value will simply be ignored by the element.
40 void setValue(DOMString value);
42 // Select the <select> option specified by index.
43 // If this method is called on a <select> that support multiple
44 // selection, then the option specified by index will be added to
46 // If this method is called for a select that does not support multiple
47 // selection the previous element will be unselected.
49 void setSelectedOption(long index);
51 // Select the <select> options specified by indexes. All other options
52 // will be deselected.
53 // If this method is called for a <select> that does not support multiple
54 // selection, then the last index specified in indexes will be selected.
56 void setSelectedOptions(sequence<long> indexes);
62 // Manages the list of IMEs, enables/disables IME and switches to an
64 [JSImplementation="@mozilla.org/b2g-imm;1",
65 Pref="dom.mozInputMethod.enabled"]
66 interface MozInputMethodManager {
67 // Ask the OS to show a list of available IMEs for users to switch from.
68 // OS should ignore this request if the app is currently not the active one.
71 // Ask the OS to switch away from the current active Keyboard app.
72 // OS should ignore this request if the app is currently not the active one.
75 // To know if the OS supports IME switching or not.
76 // Use case: let the keyboard app knows if it is necessary to show the "IME switching"
77 // (globe) button. We have a use case that when there is only one IME enabled, we
78 // should not show the globe icon.
79 boolean supportsSwitching();
81 // Ask the OS to hide the current active Keyboard app. (was: |removeFocus()|)
82 // OS should ignore this request if the app is currently not the active one.
83 // The OS will void the current input context (if it exists).
84 // This method belong to |mgmt| because we would like to allow Keyboard to access to
85 // this method w/o a input context.
89 // The input context, which consists of attributes and information of current input field.
90 // It also hosts the methods available to the keyboard app to mutate the input field represented.
91 // An "input context" gets void when the app is no longer allowed to interact with the text field,
92 // e.g., the text field does no longer exist, the app is being switched to background, and etc.
93 [JSImplementation="@mozilla.org/b2g-inputcontext;1",
94 Pref="dom.mozInputMethod.enabled"]
95 interface MozInputContext: EventTarget {
96 // The tag name of input field, which is enum of "input", "textarea", or "contenteditable"
97 readonly attribute DOMString? type;
98 // The type of the input field, which is enum of text, number, password, url, search, email, and so on.
99 // See http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#states-of-the-type-attribute
100 readonly attribute DOMString? inputType;
102 * The inputmode string, representing the input mode.
103 * See http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#input-modalities:-the-inputmode-attribute
105 readonly attribute DOMString? inputMode;
107 * The primary language for the input field.
108 * It is the value of HTMLElement.lang.
109 * See http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#htmlelement
111 readonly attribute DOMString? lang;
113 * Get the whole text content of the input field.
116 Promise<DOMString> getText(optional long offset, optional long length);
117 // The start and stop position of the selection.
118 readonly attribute long selectionStart;
119 readonly attribute long selectionEnd;
121 // The text before and after the begining of the selected text.
122 readonly attribute DOMString? textBeforeCursor;
123 readonly attribute DOMString? textAfterCursor;
126 * Set the selection range of the the editable text.
127 * Note: This method cannot be used to move the cursor during composition. Calling this
128 * method will cancel composition.
129 * @param start The beginning of the selected text.
130 * @param length The length of the selected text.
132 * Note that the start position should be less or equal to the end position.
133 * To move the cursor, set the start and end position to the same value.
137 Promise<boolean> setSelectionRange(long start, long length);
139 /* User moves the cursor, or changes the selection with other means. If the text around
140 * cursor has changed, but the cursor has not been moved, the IME won't get notification.
142 * A dict is provided in the detail property of the event containing the new values, and
143 * an "ownAction" property to denote the event is the result of our own mutation to
146 attribute EventHandler onselectionchange;
149 * Commit text to current input field and replace text around
150 * cursor position. It will clear the current composition.
152 * @param text The string to be replaced with.
153 * @param offset The offset from the cursor position where replacing starts. Defaults to 0.
154 * @param length The length of text to replace. Defaults to 0.
157 Promise<boolean> replaceSurroundingText(DOMString text, optional long offset, optional long length);
161 * Delete text around the cursor.
162 * @param offset The offset from the cursor position where deletion starts.
163 * @param length The length of text to delete.
164 * TODO: maybe updateSurroundingText(DOMString beforeText, DOMString afterText); ?
167 Promise<boolean> deleteSurroundingText(long offset, long length);
170 * Notifies when the text around the cursor is changed, due to either text
171 * editing or cursor movement. If the cursor has been moved, but the text around has not
172 * changed, the IME won't get notification.
174 * A dict is provided in the detail property of the event containing the new values, and
175 * an "ownAction" property to denote the event is the result of our own mutation to
178 attribute EventHandler onsurroundingtextchange;
181 * send a character with its key events.
182 * @param modifiers see http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/base/nsIDOMWindowUtils.idl#206
183 * @param repeat indicates whether a key would be sent repeatedly.
184 * @return true if succeeds. Otherwise false if the input context becomes void.
185 * Alternative: sendKey(KeyboardEvent event), but we will likely
186 * waste memory for creating the KeyboardEvent object.
187 * Note that, if you want to send a key n times repeatedly, make sure set
188 * parameter repeat to true and invoke sendKey n-1 times, and then set
189 * repeat to false in the last invoke.
191 Promise<boolean> sendKey(long keyCode, long charCode, long modifiers, optional boolean repeat);
194 * Set current composing text. This method will start composition or update
195 * composition if it has started. The composition will be started right
196 * before the cursor position and any selected text will be replaced by the
197 * composing text. When the composition is started, calling this method can
198 * update the text and move cursor winthin the range of the composing text.
199 * @param text The new composition text to show.
200 * @param cursor The new cursor position relative to the start of the
201 * composition text. The cursor should be positioned within the composition
202 * text. This means the value should be >= 0 and <= the length of
203 * composition text. Defaults to the lenght of composition text, i.e., the
204 * cursor will be positioned after the composition text.
205 * @param clauses The array of composition clause information. If not set,
206 * only one clause is supported.
208 * The composing text, which is shown with underlined style to distinguish
209 * from the existing text, is used to compose non-ASCII characters from
210 * keystrokes, e.g. Pinyin or Hiragana. The composing text is the
211 * intermediate text to help input complex character and is not committed to
212 * current input field. Therefore if any text operation other than
213 * composition is performed, the composition will automatically end. Same
214 * apply when the inputContext is lost during an unfinished composition
217 * To finish composition and commit text to current input field, an IME
218 * should call |endComposition|.
220 // XXXbz what is this promise resolved with?
221 Promise<any> setComposition(DOMString text, optional long cursor,
222 optional sequence<CompositionClauseParameters> clauses);
225 * End composition, clear the composing text and commit given text to
226 * current input field. The text will be committed before the cursor
228 * @param text The text to commited before cursor position. If empty string
229 * is given, no text will be committed.
231 * Note that composition always ends automatically with nothing to commit if
232 * the composition does not explicitly end by calling |endComposition|, but
233 * is interrupted by |sendKey|, |setSelectionRange|,
234 * |replaceSurroundingText|, |deleteSurroundingText|, user moving the
235 * cursor, changing the focus, etc.
237 // XXXbz what is this promise resolved with?
238 Promise<any> endComposition(optional DOMString text);
241 enum CompositionClauseSelectionType {
245 "selected-converted-text"
248 dictionary CompositionClauseParameters {
249 DOMString selectionType = "raw-input";