dom/webidl/InputMethod.webidl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/.
     5  */
     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;
    28   [ChromeOnly]
    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.
    39   [Throws]
    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
    45   // the selection.
    46   // If this method is called for a select that does not support multiple
    47   // selection the previous element will be unselected.
    48   [Throws]
    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.
    55   [Throws]
    56   void setSelectedOptions(sequence<long> indexes);
    58   [Throws]
    59   void removeFocus();
    60 };
    62 // Manages the list of IMEs, enables/disables IME and switches to an
    63 // IME.
    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.
    69   void showAll();
    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.
    73   void next();
    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.
    86   void hide();
    87 };
    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;
   101    /*
   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
   104     */
   105    readonly attribute DOMString? inputMode;
   106    /*
   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
   110     */
   111    readonly attribute DOMString? lang;
   112    /*
   113     * Get the whole text content of the input field.
   114     * @return DOMString
   115     */
   116    Promise 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;
   125     /*
   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.
   131      *
   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.
   134      *
   135      * @return boolean
   136      */
   137     Promise 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.
   141      */
   142     attribute EventHandler onselectionchange;
   144     /*
   145      * Commit text to current input field and replace text around
   146      * cursor position. It will clear the current composition.
   147      *
   148      * @param text The string to be replaced with.
   149      * @param offset The offset from the cursor position where replacing starts. Defaults to 0.
   150      * @param length The length of text to replace. Defaults to 0.
   151      * @return boolean
   152      */
   153      Promise replaceSurroundingText(DOMString text, optional long offset, optional long length);
   155     /*
   156      *
   157      * Delete text around the cursor.
   158      * @param offset The offset from the cursor position where deletion starts.
   159      * @param length The length of text to delete.
   160      * TODO: maybe updateSurroundingText(DOMString beforeText, DOMString afterText); ?
   161      * @return boolean
   162      */
   163     Promise deleteSurroundingText(long offset, long length);
   165     /*
   166     * Notifies when the text around the cursor is changed, due to either text
   167     * editing or cursor movement. If the cursor has been moved, but the text around has not
   168     * changed, the IME won't get notification.
   169     *
   170     * The event handler function is specified as:
   171     * @param beforeString Text before and including cursor position.
   172     * @param afterString Text after and excluing cursor position.
   173     * function(DOMString beforeText, DOMString afterText) {
   174     * ...
   175     *  }
   176     */
   177     attribute EventHandler onsurroundingtextchange;
   179     /*
   180       * send a character with its key events.
   181       * @param modifiers see http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/base/nsIDOMWindowUtils.idl#206
   182       * @param repeat indicates whether a key would be sent repeatedly.
   183       * @return true if succeeds. Otherwise false if the input context becomes void.
   184       * Alternative: sendKey(KeyboardEvent event), but we will likely
   185       * waste memory for creating the KeyboardEvent object.
   186       * Note that, if you want to send a key n times repeatedly, make sure set
   187       * parameter repeat to true and invoke sendKey n-1 times, and then set
   188       * repeat to false in the last invoke.
   189       */
   190     Promise sendKey(long keyCode, long charCode, long modifiers, optional boolean repeat);
   192     /*
   193      * Set current composing text. This method will start composition or update
   194      * composition if it has started. The composition will be started right
   195      * before the cursor position and any selected text will be replaced by the
   196      * composing text. When the composition is started, calling this method can
   197      * update the text and move cursor winthin the range of the composing text.
   198      * @param text The new composition text to show.
   199      * @param cursor The new cursor position relative to the start of the
   200      * composition text. The cursor should be positioned within the composition
   201      * text. This means the value should be >= 0 and <= the length of
   202      * composition text. Defaults to the lenght of composition text, i.e., the
   203      * cursor will be positioned after the composition text.
   204      * @param clauses The array of composition clause information. If not set,
   205      * only one clause is supported.
   206      *
   207      * The composing text, which is shown with underlined style to distinguish
   208      * from the existing text, is used to compose non-ASCII characters from
   209      * keystrokes, e.g. Pinyin or Hiragana. The composing text is the
   210      * intermediate text to help input complex character and is not committed to
   211      * current input field. Therefore if any text operation other than
   212      * composition is performed, the composition will automatically end. Same
   213      * apply when the inputContext is lost during an unfinished composition
   214      * session.
   215      *
   216      * To finish composition and commit text to current input field, an IME
   217      * should call |endComposition|.
   218      */
   219     Promise setComposition(DOMString text, optional long cursor,
   220                            optional sequence<CompositionClauseParameters> clauses);
   222     /*
   223      * End composition, clear the composing text and commit given text to
   224      * current input field. The text will be committed before the cursor
   225      * position.
   226      * @param text The text to commited before cursor position. If empty string
   227      * is given, no text will be committed.
   228      *
   229      * Note that composition always ends automatically with nothing to commit if
   230      * the composition does not explicitly end by calling |endComposition|, but
   231      * is interrupted by |sendKey|, |setSelectionRange|,
   232      * |replaceSurroundingText|, |deleteSurroundingText|, user moving the
   233      * cursor, changing the focus, etc.
   234      */
   235     Promise endComposition(optional DOMString text);
   236 };
   238 enum CompositionClauseSelectionType {
   239   "raw-input",
   240   "selected-raw-text",
   241   "converted-text",
   242   "selected-converted-text"
   243 };
   245 dictionary CompositionClauseParameters {
   246   DOMString selectionType = "raw-input";
   247   long length;
   248 };

mercurial