/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ /** * InputMethod API implements a bridge between the web content hosting an input * element and the input content (a.k.a. input app, virtual keyboard app, * or IME). This API is input content facing in order for it to interact with * the remote input element. * The API also contains a few Gaia System app only methods * (marked with "input-manage" permission) for Gaia System app to interact with * some types of inputs and to regulate the input apps. */ [JSImplementation="@mozilla.org/b2g-inputmethod;1", NavigatorProperty="mozInputMethod", Pref="dom.mozInputMethod.enabled", CheckAnyPermissions="input input-manage"] interface MozInputMethod : EventTarget { /** * Activate or decactive current API instance. * Gaia System app call this method via BrowserElement#setInputMethodActive. */ [ChromeOnly] void setActive(boolean isActive); /** * InputMethodManager contain a few global methods expose to input apps. */ readonly attribute MozInputMethodManager mgmt; /** * Fired when the input context changes, include changes from and to null. * The new InputContext instance will be available in the event * object under |inputcontext| property. When it changes to null it * means the app (the user of this API) no longer has the control of * the original focused input field. * Note that if the app saves the original context, it might get * void; implementation decides when to void the input context. */ [CheckAnyPermissions="input"] attribute EventHandler oninputcontextchange; /** * An "input context" is mapped to a text field that the app is * allow to mutate. This attribute should be null when there is no * text field currently focused. */ [CheckAnyPermissions="input"] readonly attribute MozInputContext? inputcontext; /** * Add a dynamically declared input. * * The id must not be the same with any statically declared input in the app * manifest. If an input of the same id is already declared, the info of that * input will be updated. */ [CheckAnyPermissions="input"] Promise addInput(DOMString inputId, MozInputMethodInputManifest inputManifest); /** * Remove a dynamically declared input. * * The id must not be the same with any statically declared input in the app * manifest. Silently resolves if the input is not previously declared; * rejects if attempt to remove a statically declared input. */ [CheckAnyPermissions="input"] Promise removeInput(DOMString id); /** * Remove focus from the current input, usable by Gaia System app, globally, * regardless of the current focus state. */ [CheckAnyPermissions="input-manage"] void removeFocus(); /** * The following are internal methods for Firefox OS System app only, * for handling the "option" group inputs. */ /** * Set the value on the currently focused element. This has to be used * for special situations where the value had to be chosen amongst a * list (type=month) or a widget (type=date, time, etc.). * If the value passed in parameter isn't valid (in the term of HTML5 * Forms Validation), the value will simply be ignored by the element. */ [CheckAnyPermissions="input-manage"] void setValue(DOMString value); /** * Select the that support multiple * selection, then the option specified by index will be added to * the selection. * If this method is called for a select that does not support multiple * selection the previous element will be unselected. */ [CheckAnyPermissions="input-manage"] void setSelectedOption(long index); /** * Select the that does not support multiple * selection, then the last index specified in indexes will be selected. */ [CheckAnyPermissions="input-manage"] void setSelectedOptions(sequence indexes); }; /** * InputMethodManager contains a few of the global methods for the input app. */ [JSImplementation="@mozilla.org/b2g-imm;1", Pref="dom.mozInputMethod.enabled", CheckAnyPermissions="input input-manage"] interface MozInputMethodManager : EventTarget { /** * Ask the OS to show a list of available inputs for users to switch from. * OS should sliently ignore this request if the app is currently not the * active one. */ [CheckAllPermissions="input"] void showAll(); /** * Ask the OS to switch away from the current active input app. * OS should sliently ignore this request if the app is currently not the * active one. */ [CheckAllPermissions="input"] void next(); /** * If this method returns true, it is recommended that the input app provides * a shortcut that would invoke the next() method above, for easy switching * between inputs -- i.e. show a "global" button on screen if the input app * implements an on-screen virtual keyboard. * * The returning value is depend on the inputType of the current input context. */ [CheckAllPermissions="input"] boolean supportsSwitching(); /** * Ask the OS to remove the input focus, will cause the lost of input context. * OS should sliently ignore this request if the app is currently not the * active one. */ [CheckAllPermissions="input"] void hide(); /** * Update Gecko with information on the input types which supportsSwitching() * should return ture. * * @param types Array of input types in which supportsSwitching() should * return true. */ [CheckAllPermissions="input-manage"] void setSupportsSwitchingTypes(sequence types); /** * CustomEvent dispatches to System when there is an input to handle. * If the API consumer failed to handle and call preventDefault(), * there will be a message printed on the console. * * evt.detail is defined by MozInputContextFocusEventDetail. */ [CheckAnyPermissions="input-manage"] attribute EventHandler oninputcontextfocus; /** * Event dispatches to System when there is no longer an input to handle. * If the API consumer failed to handle and call preventDefault(), * there will be a message printed on the console. */ [CheckAnyPermissions="input-manage"] attribute EventHandler oninputcontextblur; /** * Event dispatches to System when there is a showAll() call. * If the API consumer failed to handle and call preventDefault(), * there will be a message printed on the console. */ [CheckAnyPermissions="input-manage"] attribute EventHandler onshowallrequest; /** * Event dispatches to System when there is a next() call. * If the API consumer failed to handle and call preventDefault(), * there will be a message printed on the console. */ [CheckAnyPermissions="input-manage"] attribute EventHandler onnextrequest; /** * Event dispatches to System when there is a addInput() call. * The API consumer must call preventDefault() to indicate the event is * consumed, otherwise the request is not considered handled even if * waitUntil() was called. * * evt.detail is defined by MozInputRegistryEventDetail. */ [CheckAnyPermissions="input-manage"] attribute EventHandler onaddinputrequest; /** * Event dispatches to System when there is a removeInput() call. * The API consumer must call preventDefault() to indicate the event is * consumed, otherwise the request is not considered handled even if * waitUntil() was called. * * evt.detail is defined by MozInputRegistryEventDetail. */ [CheckAnyPermissions="input-manage"] attribute EventHandler onremoveinputrequest; }; /** * Detail of the inputcontextfocus event. */ [JSImplementation="@mozilla.org/b2g-imm-focus;1", Pref="dom.mozInputMethod.enabled", CheckAnyPermissions="input-manage"] interface MozInputContextFocusEventDetail { /** * The type of the focused input. */ readonly attribute MozInputMethodInputContextTypes type; /** * The input type of the focused input. */ readonly attribute MozInputMethodInputContextInputTypes inputType; /** * The following is only needed for rendering and handling "option" input types, * in System app. */ /** * Current value of the input/select element. */ readonly attribute DOMString? value; /** * An object representing all the and