WebAPI/KeboardIME: Difference between revisions

Line 46: Line 46:


== Proposed API ==
== Proposed API ==
The input method API is available to web content who intend to implement an input method, or "input source", or "virtual keyboard".


  partial interface Navigator {
  partial interface Navigator {
Line 54: Line 56:
     // Input Method Manager contain a few global methods expose to apps
     // Input Method Manager contain a few global methods expose to apps
     readonly attribute InputMethodManager mgmt;
     readonly attribute InputMethodManager mgmt;
    // It informs the IME that text input has started in an input field. If the IME is activated,
    // this event is sent when focus enters a new input field. Otherwise this event is sent when
    // user switches to the IME and activates it.
    attribute EventHandler onstart;
    // It informs the IME that text input has finished in last input field. This event is sent
    // when focus leaves current input field or user switches to another IME.
    attribute EventHandler onfinish;
   
   
     // Fired when the input context changes, include changes from and to null.
     // Fired when the input context changes, include changes from and to null.
     attribute EventHandler oncontextchange;
    // 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.
     attribute EventHandler oninputcontextchange;
   
   
     // An "input context" is mapped to a text field that the app is allow to mutate.
     // 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.
     // this attribute should be null when there is no text field currently focused.
     readonly attribute InputContext? inputcontext;
     readonly attribute InputContext? inputcontext;
};
// Manages the list of IMEs, enables/disables IME and switches to an IME.
interface InputMethodManager {
    // Ask the OS to show a list of available IMEs for users to switch from.
    // OS should ignore this request if the app is currently not the active one.
    void showAll();
    // Ask the OS to switch away from the current active Keyboard app.
    // OS should ignore this request if the app is currently not the active one.
    void next();
    // Clear the focus of the current input field.
    // The OS might respond with hidden of the virtual keyboard and void the input context.
    void removeFocus();
  };
// The input context, which consists of attributes and information of current input field.
// It also hosts the methods available to the keyboard app to mutate the input field represented.
// An "input context" gets void when the app is no longer allowed to interact with the text field,
// e.g., the text field does no longer exist, the app is being switched to background, and etc.
interface InputContext {
    // The tag name of input field, which is enum of "input", "textarea", or "contenteditable"
    DOMString name;
    // The type of the input field, which is enum of text, number, password, url, search, email, and so on.
    // See http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#states-of-the-type-attribute
    DOMString type;
    /*
    * The inputmode string, representing the input mode.
    * See http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#input-modalities:-the-inputmode-attribute
    */
    DOMString inputmode;
   
   
    /*
    * The primary language for the input field.
    * It is the value of HTMLElement.lang.
    * See http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#htmlelement
    */
    DOMString lang;
     /*
     /*
       * This event is sent when the text around the cursor is changed, due to either text
       * This event is sent when the text around the cursor is changed, due to either text
Line 79: Line 115:
       * @param beforeString Text before and including cursor position.
       * @param beforeString Text before and including cursor position.
       * @param afterString Text after and excluing cursor position.
       * @param afterString Text after and excluing cursor position.
       * function(long contextId, DOMString beforeText, DOMString afterText) {
       * function(DOMString beforeText, DOMString afterText) {
       * ...
       * ...
       *  }
       *  }
Line 141: Line 177:
       */
       */
     Promise<boolean> clearComposition();
     Promise<boolean> clearComposition();
    // Clear the focus of the current input field and hide the keyboard.
    Promise<boolean> removeFocus();
};
// Manages the list of IMEs, enables/disables IME and switches to an IME.
interface InputMethodManager {
    // Ask the OS to show a list of available IMEs for users to switch from.
    // OS should ignore this request if we are currently not the active one.
    void showAll();
    // Ask the OS to switch away from the current active Keyboard app.
    // OS should ignore this request if we are currently not the active one.
    void next();
  };
// The input context, which consists of attributes and information of current input field.
// An "input context" gets void when the app is no longer allowed to interact with the text field,
// e.g., the text field does no longer exist, the app is being switched to background, and etc.
interface InputContext {
    // The tag name of input field, which is enum of "input", "textarea", or "contenteditable"
    DOMString name;
    // The type of the input field, which is enum of text, number, password, url, search and email.
    DOMString type;
    /*
    * The input mode string.
    * https://bugzilla.mozilla.org/show_bug.cgi?id=796544
    * It can be one of the following values:
    * "none"
    * "verbatim"    - no capitalization, no word suggestions
    * "latin"      - word suggestions but no capitalization
    * "latin-prose" - word suggestions and capitalization at the start of sentences
    * "latin-name"  - word suggestions and capitalize each word
    * "digit"      - digits(0-9) only.
    */
    DOMString inputmode;
    /*
    * The primary language for the input field.
    * It is the value of HTMLElement.lang.
    * see http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#htmlelement
    */
    DOMString lang;
  };
  };


Confirmed users
478

edits