michael@0: /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: [JSImplementation="@mozilla.org/b2g-inputmethod;1", michael@0: NavigatorProperty="mozInputMethod", michael@0: Func="Navigator::HasInputMethodSupport"] michael@0: interface MozInputMethod : EventTarget { michael@0: // Input Method Manager contain a few global methods expose to apps michael@0: readonly attribute MozInputMethodManager mgmt; michael@0: michael@0: // Fired when the input context changes, include changes from and to null. michael@0: // The new InputContext instance will be available in the event michael@0: // object under |inputcontext| property. When it changes to null it michael@0: // means the app (the user of this API) no longer has the control of michael@0: // the original focused input field. michael@0: // Note that if the app saves the original context, it might get michael@0: // void; implementation decides when to void the input context. michael@0: attribute EventHandler oninputcontextchange; michael@0: michael@0: // An "input context" is mapped to a text field that the app is michael@0: // allow to mutate. this attribute should be null when there is no michael@0: // text field currently focused. michael@0: readonly attribute MozInputContext? inputcontext; michael@0: michael@0: [ChromeOnly] michael@0: // Activate or decactive current input method window. michael@0: void setActive(boolean isActive); michael@0: michael@0: // The following are internal methods for Firefox OS system app only. michael@0: michael@0: // Set the value on the currently focused element. This has to be used michael@0: // for special situations where the value had to be chosen amongst a michael@0: // list (type=month) or a widget (type=date, time, etc.). michael@0: // If the value passed in parameter isn't valid (in the term of HTML5 michael@0: // Forms Validation), the value will simply be ignored by the element. michael@0: [Throws] michael@0: void setValue(DOMString value); michael@0: michael@0: // Select the that support multiple michael@0: // selection, then the option specified by index will be added to michael@0: // the selection. michael@0: // If this method is called for a select that does not support multiple michael@0: // selection the previous element will be unselected. michael@0: [Throws] michael@0: void setSelectedOption(long index); michael@0: michael@0: // Select the that does not support multiple michael@0: // selection, then the last index specified in indexes will be selected. michael@0: [Throws] michael@0: void setSelectedOptions(sequence indexes); michael@0: michael@0: [Throws] michael@0: void removeFocus(); michael@0: }; michael@0: michael@0: // Manages the list of IMEs, enables/disables IME and switches to an michael@0: // IME. michael@0: [JSImplementation="@mozilla.org/b2g-imm;1", michael@0: Pref="dom.mozInputMethod.enabled"] michael@0: interface MozInputMethodManager { michael@0: // Ask the OS to show a list of available IMEs for users to switch from. michael@0: // OS should ignore this request if the app is currently not the active one. michael@0: void showAll(); michael@0: michael@0: // Ask the OS to switch away from the current active Keyboard app. michael@0: // OS should ignore this request if the app is currently not the active one. michael@0: void next(); michael@0: michael@0: // To know if the OS supports IME switching or not. michael@0: // Use case: let the keyboard app knows if it is necessary to show the "IME switching" michael@0: // (globe) button. We have a use case that when there is only one IME enabled, we michael@0: // should not show the globe icon. michael@0: boolean supportsSwitching(); michael@0: michael@0: // Ask the OS to hide the current active Keyboard app. (was: |removeFocus()|) michael@0: // OS should ignore this request if the app is currently not the active one. michael@0: // The OS will void the current input context (if it exists). michael@0: // This method belong to |mgmt| because we would like to allow Keyboard to access to michael@0: // this method w/o a input context. michael@0: void hide(); michael@0: }; michael@0: michael@0: // The input context, which consists of attributes and information of current input field. michael@0: // It also hosts the methods available to the keyboard app to mutate the input field represented. michael@0: // An "input context" gets void when the app is no longer allowed to interact with the text field, michael@0: // e.g., the text field does no longer exist, the app is being switched to background, and etc. michael@0: [JSImplementation="@mozilla.org/b2g-inputcontext;1", michael@0: Pref="dom.mozInputMethod.enabled"] michael@0: interface MozInputContext: EventTarget { michael@0: // The tag name of input field, which is enum of "input", "textarea", or "contenteditable" michael@0: readonly attribute DOMString? type; michael@0: // The type of the input field, which is enum of text, number, password, url, search, email, and so on. michael@0: // See http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#states-of-the-type-attribute michael@0: readonly attribute DOMString? inputType; michael@0: /* michael@0: * The inputmode string, representing the input mode. michael@0: * See http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#input-modalities:-the-inputmode-attribute michael@0: */ michael@0: readonly attribute DOMString? inputMode; michael@0: /* michael@0: * The primary language for the input field. michael@0: * It is the value of HTMLElement.lang. michael@0: * See http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#htmlelement michael@0: */ michael@0: readonly attribute DOMString? lang; michael@0: /* michael@0: * Get the whole text content of the input field. michael@0: * @return DOMString michael@0: */ michael@0: Promise getText(optional long offset, optional long length); michael@0: // The start and stop position of the selection. michael@0: readonly attribute long selectionStart; michael@0: readonly attribute long selectionEnd; michael@0: michael@0: // The text before and after the begining of the selected text. michael@0: readonly attribute DOMString? textBeforeCursor; michael@0: readonly attribute DOMString? textAfterCursor; michael@0: michael@0: /* michael@0: * Set the selection range of the the editable text. michael@0: * Note: This method cannot be used to move the cursor during composition. Calling this michael@0: * method will cancel composition. michael@0: * @param start The beginning of the selected text. michael@0: * @param length The length of the selected text. michael@0: * michael@0: * Note that the start position should be less or equal to the end position. michael@0: * To move the cursor, set the start and end position to the same value. michael@0: * michael@0: * @return boolean michael@0: */ michael@0: Promise setSelectionRange(long start, long length); michael@0: michael@0: /* User moves the cursor, or changes the selection with other means. If the text around michael@0: * cursor has changed, but the cursor has not been moved, the IME won't get notification. michael@0: */ michael@0: attribute EventHandler onselectionchange; michael@0: michael@0: /* michael@0: * Commit text to current input field and replace text around michael@0: * cursor position. It will clear the current composition. michael@0: * michael@0: * @param text The string to be replaced with. michael@0: * @param offset The offset from the cursor position where replacing starts. Defaults to 0. michael@0: * @param length The length of text to replace. Defaults to 0. michael@0: * @return boolean michael@0: */ michael@0: Promise replaceSurroundingText(DOMString text, optional long offset, optional long length); michael@0: michael@0: /* michael@0: * michael@0: * Delete text around the cursor. michael@0: * @param offset The offset from the cursor position where deletion starts. michael@0: * @param length The length of text to delete. michael@0: * TODO: maybe updateSurroundingText(DOMString beforeText, DOMString afterText); ? michael@0: * @return boolean michael@0: */ michael@0: Promise deleteSurroundingText(long offset, long length); michael@0: michael@0: /* michael@0: * Notifies when the text around the cursor is changed, due to either text michael@0: * editing or cursor movement. If the cursor has been moved, but the text around has not michael@0: * changed, the IME won't get notification. michael@0: * michael@0: * The event handler function is specified as: michael@0: * @param beforeString Text before and including cursor position. michael@0: * @param afterString Text after and excluing cursor position. michael@0: * function(DOMString beforeText, DOMString afterText) { michael@0: * ... michael@0: * } michael@0: */ michael@0: attribute EventHandler onsurroundingtextchange; michael@0: michael@0: /* michael@0: * send a character with its key events. michael@0: * @param modifiers see http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/base/nsIDOMWindowUtils.idl#206 michael@0: * @param repeat indicates whether a key would be sent repeatedly. michael@0: * @return true if succeeds. Otherwise false if the input context becomes void. michael@0: * Alternative: sendKey(KeyboardEvent event), but we will likely michael@0: * waste memory for creating the KeyboardEvent object. michael@0: * Note that, if you want to send a key n times repeatedly, make sure set michael@0: * parameter repeat to true and invoke sendKey n-1 times, and then set michael@0: * repeat to false in the last invoke. michael@0: */ michael@0: Promise sendKey(long keyCode, long charCode, long modifiers, optional boolean repeat); michael@0: michael@0: /* michael@0: * Set current composing text. This method will start composition or update michael@0: * composition if it has started. The composition will be started right michael@0: * before the cursor position and any selected text will be replaced by the michael@0: * composing text. When the composition is started, calling this method can michael@0: * update the text and move cursor winthin the range of the composing text. michael@0: * @param text The new composition text to show. michael@0: * @param cursor The new cursor position relative to the start of the michael@0: * composition text. The cursor should be positioned within the composition michael@0: * text. This means the value should be >= 0 and <= the length of michael@0: * composition text. Defaults to the lenght of composition text, i.e., the michael@0: * cursor will be positioned after the composition text. michael@0: * @param clauses The array of composition clause information. If not set, michael@0: * only one clause is supported. michael@0: * michael@0: * The composing text, which is shown with underlined style to distinguish michael@0: * from the existing text, is used to compose non-ASCII characters from michael@0: * keystrokes, e.g. Pinyin or Hiragana. The composing text is the michael@0: * intermediate text to help input complex character and is not committed to michael@0: * current input field. Therefore if any text operation other than michael@0: * composition is performed, the composition will automatically end. Same michael@0: * apply when the inputContext is lost during an unfinished composition michael@0: * session. michael@0: * michael@0: * To finish composition and commit text to current input field, an IME michael@0: * should call |endComposition|. michael@0: */ michael@0: Promise setComposition(DOMString text, optional long cursor, michael@0: optional sequence clauses); michael@0: michael@0: /* michael@0: * End composition, clear the composing text and commit given text to michael@0: * current input field. The text will be committed before the cursor michael@0: * position. michael@0: * @param text The text to commited before cursor position. If empty string michael@0: * is given, no text will be committed. michael@0: * michael@0: * Note that composition always ends automatically with nothing to commit if michael@0: * the composition does not explicitly end by calling |endComposition|, but michael@0: * is interrupted by |sendKey|, |setSelectionRange|, michael@0: * |replaceSurroundingText|, |deleteSurroundingText|, user moving the michael@0: * cursor, changing the focus, etc. michael@0: */ michael@0: Promise endComposition(optional DOMString text); michael@0: }; michael@0: michael@0: enum CompositionClauseSelectionType { michael@0: "raw-input", michael@0: "selected-raw-text", michael@0: "converted-text", michael@0: "selected-converted-text" michael@0: }; michael@0: michael@0: dictionary CompositionClauseParameters { michael@0: DOMString selectionType = "raw-input"; michael@0: long length; michael@0: };