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