Home | History | Annotate | Download | only in api
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 [
      6   {
      7     "namespace": "input.ime",
      8     "description": "Use the <code>chrome.input.ime</code> API to implement a custom IME for Chrome OS. This allows your extension to handle keystrokes, set the composition, and manage the candidate window.",
      9     "platforms": ["chromeos"],
     10     "types": [
     11       {
     12         "id": "KeyboardEvent",
     13         "type": "object",
     14         "description": "See http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent",
     15         "properties": {
     16           "type": {"type": "string", "description": "One of keyup or keydown.", "enum": ["keyup", "keydown"]},
     17           "requestId": {"type": "string", "description": "The ID of the request."},
     18           "key": {"type": "string", "description": "Value of the key being pressed"},
     19           "code": {"type": "string", "description": "Value of the physical key being pressed. The value is not affected by current keyboard layout or modifier state."},
     20           "altKey": {"type": "boolean", "optional": true, "description": "Whether or not the ALT key is pressed."},
     21           "ctrlKey": {"type": "boolean", "optional": true, "description": "Whether or not the CTRL key is pressed."},
     22           "shiftKey": {"type": "boolean", "optional": true, "description": "Whether or not the SHIFT key is pressed."},
     23           "capsLock": {"type": "boolean", "optional": true, "description": "Whether or not the CAPS_LOCK is enabled."}
     24         }
     25       },
     26       {
     27         "id": "InputContext",
     28         "type": "object",
     29         "description": "Describes an input Context",
     30         "properties": {
     31           "contextID": {"type": "integer", "description": "This is used to specify targets of text field operations.  This ID becomes invalid as soon as onBlur is called."},
     32           "type": {"type": "string", "description": "Type of value this text field edits, (Text, Number, URL, etc)", "enum": ["text", "search", "tel", "url", "email", "number"]}
     33         }
     34       },
     35       {
     36         "id": "MenuItem",
     37         "type": "object",
     38         "description": "A menu item used by an input method to interact with the user from the language menu.",
     39         "properties": {
     40           "id": {"type": "string", "description": "String that will be passed to callbacks referencing this MenuItem."},
     41           "label": {"type": "string", "optional": true, "description": "Text displayed in the menu for this item."},
     42           "style": {
     43             "type": "string",
     44             "optional": true,
     45             "description": "Enum representing if this item is: check, radio, or a separator.  Radio buttons between separators are considered grouped.",
     46             "enum": ["check", "radio", "separator"]
     47           },
     48           "visible": {"type": "boolean", "optional": true, "description": "Indicates this item is visible."},
     49           "checked": {"type": "boolean", "optional": true, "description": "Indicates this item should be drawn with a check."},
     50           "enabled": {"type": "boolean", "optional": true, "description": "Indicates this item is enabled."}
     51         }
     52       }
     53     ],
     54     "functions": [
     55       {
     56         "name": "setComposition",
     57         "type": "function",
     58         "description": "Set the current composition. If this extension does not own the active IME, this fails.",
     59         "parameters": [
     60           {
     61             "name": "parameters",
     62             "type": "object",
     63             "properties": {
     64               "contextID": {
     65                 "description": "ID of the context where the composition text will be set",
     66                 "type": "integer"
     67               },
     68               "text": {
     69                 "description": "Text to set",
     70                 "type": "string"
     71               },
     72               "selectionStart": {
     73                 "description": "Position in the text that the selection starts at.",
     74                 "optional": true,
     75                 "type": "integer"
     76               },
     77               "selectionEnd": {
     78                 "description": "Position in the text that the selection ends at.",
     79                 "optional": true,
     80                 "type": "integer"
     81               },
     82               "cursor": {
     83                 "description": "Position in the text of the cursor.",
     84                 "type": "integer"
     85               },
     86               "segments": {
     87                 "description": "List of segments and their associated types.",
     88                 "type": "array",
     89                 "optional": true,
     90                 "items": {
     91                   "type": "object",
     92                   "properties": {
     93                     "start": {
     94                       "description": "Index of the character to start this segment at",
     95                       "type": "integer"
     96                     },
     97                     "end": {
     98                       "description": "Index of the character to end this segment after.",
     99                       "type": "integer"
    100                     },
    101                     "style": {
    102                       "description": "How to render this segment",
    103                       "enum": ["underline", "doubleUnderline"],
    104                       "type": "string"
    105                     }
    106                   }
    107                 }
    108               }
    109             }
    110           },
    111           {
    112             "type": "function",
    113             "name": "callback",
    114             "optional": true,
    115             "description": "Called when the operation completes with a boolean indicating if the text was accepted or not. On failure, chrome.runtime.lastError is set.",
    116             "parameters": [
    117               {
    118                 "name": "success",
    119                 "type": "boolean"
    120               }
    121             ]
    122           }
    123         ]
    124       },
    125       {
    126         "name": "clearComposition",
    127         "type": "function",
    128         "description": "Clear the current composition. If this extension does not own the active IME, this fails.",
    129         "parameters": [
    130           {
    131             "name": "parameters",
    132             "type": "object",
    133             "properties": {
    134               "contextID": {
    135                 "description": "ID of the context where the composition will be cleared",
    136                 "type": "integer"
    137               }
    138             }
    139           },
    140           {
    141             "type": "function",
    142             "name": "callback",
    143             "optional": true,
    144             "description": "Called when the operation completes with a boolean indicating if the text was accepted or not. On failure, chrome.runtime.lastError is set.",
    145             "parameters": [
    146               {
    147                 "name": "success",
    148                 "type": "boolean"
    149               }
    150             ]
    151           }
    152         ]
    153       },
    154       {
    155         "name": "commitText",
    156         "type": "function",
    157         "description": "Commits the provided text to the current input.",
    158         "parameters": [
    159           {
    160             "name": "parameters",
    161             "type": "object",
    162             "properties": {
    163               "contextID": {
    164                 "description": "ID of the context where the text will be committed",
    165                 "type": "integer"
    166               },
    167               "text": {
    168                 "description": "The text to commit",
    169                 "type": "string"
    170               }
    171             }
    172           },
    173           {
    174             "type": "function",
    175             "name": "callback",
    176             "optional": true,
    177             "description": "Called when the operation completes with a boolean indicating if the text was accepted or not. On failure, chrome.runtime.lastError is set.",
    178             "parameters": [
    179               {
    180                 "name": "success",
    181                 "type": "boolean"
    182               }
    183             ]
    184           }
    185         ]
    186       },
    187       {
    188         "name": "sendKeyEvents",
    189         "type": "function",
    190         "description": "Sends the key events.  This function is expected to be used by virtual keyboards.  When key(s) on a virtual keyboard is pressed by a user, this function is used to propagate that event to the system.",
    191         "parameters": [
    192           {
    193             "name": "parameters",
    194             "type": "object",
    195             "properties": {
    196               "contextID": {
    197                 "description": "ID of the context where the key events will be sent",
    198                 "type": "integer"
    199               },
    200               "keyData": {
    201                 "type": "array",
    202                 "description": "Data on the key event.",
    203                 "items": {
    204                   "$ref": "KeyboardEvent"
    205                 }
    206               }
    207             }
    208           },
    209           {
    210             "type": "function",
    211             "name": "callback",
    212             "optional": true,
    213             "description": "Called when the operation completes.",
    214             "parameters": []
    215           }
    216         ]
    217       },
    218       {
    219         "name": "setCandidateWindowProperties",
    220         "type": "function",
    221         "description": "Sets the properties of the candidate window. This fails if the extension doesn't own the active IME",
    222         "parameters": [
    223           {
    224             "name": "parameters",
    225             "type": "object",
    226             "properties": {
    227               "engineID": {
    228                 "description": "ID of the engine to set properties on.",
    229                 "type": "string"
    230               },
    231               "properties": {
    232                 "type": "object",
    233                 "properties": {
    234                   "visible": {
    235                     "type": "boolean",
    236                     "optional": true,
    237                     "description": "True to show the Candidate window, false to hide it."
    238                   },
    239                   "cursorVisible": {
    240                     "type": "boolean",
    241                     "optional": true,
    242                     "description": "True to show the cursor, false to hide it."
    243                   },
    244                   "vertical": {
    245                     "type": "boolean",
    246                     "optional": true,
    247                     "description": "True if the candidate window should be rendered vertical, false to make it horizontal."
    248                   },
    249                   "pageSize": {
    250                     "type": "integer",
    251                     "optional": true,
    252                     "description": "The number of candidates to display per page."
    253                   },
    254                   "auxiliaryText": {
    255                     "type": "string",
    256                     "optional": true,
    257                     "description": "Text that is shown at the bottom of the candidate window."
    258                   },
    259                   "auxiliaryTextVisible": {
    260                     "type": "boolean",
    261                     "optional": true,
    262                     "description": "True to display the auxiliary text, false to hide it."
    263                   },
    264                   "windowPosition": {
    265                     "type": "string",
    266                     "description": "Where to display the candidate window. If set to 'cursor', the window follows the cursor. If set to 'composition', the window is locked to the beginning of the composition.",
    267                     "enum": ["cursor", "composition"],
    268                     "optional": true
    269                   }
    270                 }
    271               }
    272             }
    273           },
    274           {
    275             "type": "function",
    276             "name": "callback",
    277             "optional": true,
    278             "description": "Called when the operation completes.",
    279             "parameters": [
    280               {
    281                 "name": "success",
    282                 "type": "boolean"
    283               }
    284             ]
    285           }
    286         ]
    287       },
    288       {
    289         "name": "setCandidates",
    290         "type": "function",
    291         "description": "Sets the current candidate list. This fails if this extension doesn't own the active IME",
    292         "parameters": [
    293           {
    294             "name": "parameters",
    295             "type": "object",
    296             "properties": {
    297               "contextID": {
    298                 "description": "ID of the context that owns the candidate window.",
    299                 "type": "integer"
    300               },
    301               "candidates": {
    302                 "description": "List of candidates to show in the candidate window",
    303                 "type": "array",
    304                 "items": {
    305                   "type": "object",
    306                   "properties": {
    307                     "candidate": {"type": "string", "description": "The candidate"},
    308                     "id": {"type": "integer", "description": "The candidate's id"},
    309                     "parentId": {"type": "integer", "optional": true, "description": "The id to add these candidates under"},
    310                     "label": {"type": "string", "optional": true, "description": "Short string displayed to next to the candidate, often the shortcut key or index"},
    311                     "annotation": {"type": "string", "optional": true, "description": "Additional text describing the candidate"},
    312                     "usage": {
    313                       "type": "object",
    314                       "optional": true,
    315                       "description": "The usage or detail description of word.",
    316                       "properties": {
    317                         "title": { "type": "string", "description": "The title string of details description."},
    318                         "body": { "type": "string", "description": "The body string of detail description."}
    319                       }
    320                     }
    321                   }
    322                 }
    323               }
    324             }
    325           },
    326           {
    327             "type": "function",
    328             "name": "callback",
    329             "optional": true,
    330             "description": "Called when the operation completes.",
    331             "parameters": [
    332               {
    333                 "name": "success",
    334                 "type": "boolean"
    335               }
    336             ]
    337           }
    338         ]
    339       },
    340       {
    341         "name": "setCursorPosition",
    342         "type": "function",
    343         "description": "Set the position of the cursor in the candidate window. This is a no-op if this extension does not own the active IME.",
    344         "parameters": [
    345           {
    346             "name": "parameters",
    347             "type": "object",
    348             "properties": {
    349               "contextID": {
    350                 "description": "ID of the context that owns the candidate window.",
    351                 "type": "integer"
    352               },
    353               "candidateID": {
    354                 "description": "ID of the candidate to select.",
    355                 "type": "integer"
    356               }
    357             }
    358           },
    359           {
    360             "type": "function",
    361             "name": "callback",
    362             "optional": true,
    363             "description": "Called when the operation completes",
    364             "parameters": [
    365               {
    366                 "name": "success",
    367                 "type": "boolean"
    368               }
    369             ]
    370           }
    371         ]
    372       },
    373       {
    374         "name": "setMenuItems",
    375         "type": "function",
    376         "description": "Adds the provided menu items to the language menu when this IME is active.",
    377         "parameters": [
    378           {
    379             "name": "parameters",
    380             "type": "object",
    381             "properties": {
    382               "engineID": {
    383                 "description": "ID of the engine to use",
    384                 "type": "string"
    385               },
    386               "items": {
    387                 "description": "MenuItems to add. They will be added in the order they exist in the array.",
    388                 "type": "array",
    389                 "items": {
    390                   "$ref": "MenuItem"
    391                 }
    392               }
    393             }
    394           },
    395           {
    396             "type": "function",
    397             "name": "callback",
    398             "optional": true,
    399             "description": "",
    400             "parameters": []
    401           }
    402         ]
    403       },
    404       {
    405         "name": "updateMenuItems",
    406         "type": "function",
    407         "description": "Updates the state of the MenuItems specified",
    408         "parameters": [
    409           {
    410             "name": "parameters",
    411             "type": "object",
    412             "properties": {
    413               "engineID": {
    414                 "description": "ID of the engine to use",
    415                 "type": "string"
    416               },
    417               "items": {
    418                 "description": "Array of MenuItems to update",
    419                 "type": "array",
    420                 "items": {
    421                   "$ref": "MenuItem"
    422                 }
    423               }
    424             }
    425           },
    426           {
    427             "type": "function",
    428             "name": "callback",
    429             "optional": true,
    430             "description": "Called when the operation completes",
    431             "parameters": []
    432           }
    433         ]
    434       },
    435       {
    436         "name": "deleteSurroundingText",
    437         "type": "function",
    438         "description": "Deletes the text around the caret.",
    439         "parameters": [
    440           {
    441             "name": "parameters",
    442             "type": "object",
    443             "properties": {
    444               "engineID": {
    445                 "type": "string",
    446                 "description": "ID of the engine receiving the event."
    447               },
    448               "contextID": {
    449                 "type": "integer",
    450                 "description": "ID of the context where the surrounding text will be deleted."
    451               },
    452               "offset": {
    453                 "type": "integer",
    454                 "description": "The offset from the caret position where deletion will start. This value can be negative."
    455               },
    456               "length": {
    457                 "type": "integer",
    458                 "description": "The number of characters to be deleted",
    459                 "minimum": 0
    460               }
    461             }
    462           },
    463           {
    464             "type": "function",
    465             "name": "callback",
    466             "optional": true,
    467             "description": "Called when the operation completes.",
    468             "parameters": []
    469           }
    470         ]
    471       },
    472       {
    473         "name": "keyEventHandled",
    474         "type": "function",
    475         "description": "Indicates that the key event received by onKeyEvent is handled.  This should only be called if the onKeyEvent listener is asynchronous.",
    476         "parameters": [
    477           {"type": "string", "name": "requestId", "description": "Request id of the event that was handled.  This should come from keyEvent.requestId"},
    478           {"type": "boolean", "name": "response", "description": "True if the keystroke was handled, false if not"}
    479         ]
    480       }
    481     ],
    482     "events": [
    483       {
    484         "name": "onActivate",
    485         "type": "function",
    486         "description": "This event is sent when an IME is activated. It signals that the IME will be receiving onKeyPress events.",
    487         "parameters": [
    488           {
    489             "type": "string",
    490             "name": "engineID",
    491             "description": "ID of the engine receiving the event"
    492           }
    493         ]
    494       },
    495       {
    496         "name": "onDeactivated",
    497         "type": "function",
    498         "description": "This event is sent when an IME is deactivated. It signals that the IME will no longer be receiving onKeyPress events.",
    499         "parameters": [
    500           {
    501             "type": "string",
    502             "name": "engineID",
    503             "description": "ID of the engine receiving the event"
    504           }
    505         ]
    506       },
    507       {
    508         "name": "onFocus",
    509         "type": "function",
    510         "description": "This event is sent when focus enters a text box. It is sent to all extensions that are listening to this event, and enabled by the user.",
    511         "parameters": [
    512           {
    513             "$ref": "InputContext",
    514             "name": "context",
    515             "description": "Describes the text field that has acquired focus."
    516           }
    517         ]
    518       },
    519       {
    520         "name": "onBlur",
    521         "type": "function",
    522         "description": "This event is sent when focus leaves a text box. It is sent to all extensions that are listening to this event, and enabled by the user.",
    523         "parameters": [
    524           {
    525             "type": "integer",
    526             "name": "contextID",
    527             "description": "The ID of the text field that has lost focus. The ID is invalid after this call"
    528           }
    529         ]
    530       },
    531       {
    532         "name": "onInputContextUpdate",
    533         "type": "function",
    534         "description": "This event is sent when the properties of the current InputContext change, such as the the type. It is sent to all extensions that are listening to this event, and enabled by the user.",
    535         "parameters": [
    536           {
    537             "$ref": "InputContext",
    538             "name": "context",
    539             "description": "An InputContext object describing the text field that has changed."
    540           }
    541         ]
    542       },
    543       {
    544         "name": "onKeyEvent",
    545         "type": "function",
    546         "description": "This event is sent if this extension owns the active IME.",
    547         "options": {
    548           "supportsFilters": false,
    549           "supportsListeners": true,
    550           "supportsRules": false,
    551           "maxListeners": 1
    552         },
    553         "parameters": [
    554           {
    555             "type": "string",
    556             "name": "engineID",
    557             "description": "ID of the engine receiving the event"
    558           },
    559           {
    560             "$ref": "KeyboardEvent",
    561             "name": "keyData",
    562             "description": "Data on the key event"
    563           }
    564         ],
    565         "extraParameters": [
    566           {
    567             "type": "array",
    568             "optional": true,
    569             "name": "extraInfoSpec",
    570             "description": "Array of extra information that specifies how the callback is invoked.",
    571             "items": {
    572               "type": "string",
    573               "enum": ["async"]
    574             }
    575           }
    576         ],
    577         "returns": {
    578           "type": "boolean",
    579           "description": "True if the keystroke was handled, false if not.  This function should always return a value if |async| is not specified.",
    580           "optional": true
    581         }
    582       },
    583       {
    584         "name": "onCandidateClicked",
    585         "type": "function",
    586         "description": "This event is sent if this extension owns the active IME.",
    587         "parameters": [
    588           {
    589             "type": "string",
    590             "name": "engineID",
    591             "description": "ID of the engine receiving the event"
    592           },
    593           {
    594             "type": "integer",
    595             "name": "candidateID",
    596             "description": "ID of the candidate that was clicked."
    597           },
    598           {
    599             "type": "string",
    600             "name": "button",
    601             "description": "Which mouse buttons was clicked.",
    602             "enum": ["left", "middle", "right"]
    603           }
    604         ]
    605       },
    606       {
    607         "name": "onMenuItemActivated",
    608         "type": "function",
    609         "description": "Called when the user selects a menu item",
    610         "parameters": [
    611           {
    612             "type": "string",
    613             "name": "engineID",
    614             "description": "ID of the engine receiving the event"
    615           },
    616           {
    617             "type": "string",
    618             "name": "name",
    619             "description": "Name of the MenuItem which was activated"
    620           }
    621         ]
    622       },
    623       {
    624         "name": "onSurroundingTextChanged",
    625         "type": "function",
    626         "description": "Called when the editable string around caret is changed or when the caret position is moved. The text length is limited to 100 characters for each back and forth direction.",
    627         "parameters": [
    628           {
    629             "type": "string",
    630             "name": "engineID",
    631             "description": "ID of the engine receiving the event"
    632           },
    633           {
    634             "type": "object",
    635             "name": "surroundingInfo",
    636             "description": "The surrounding information.",
    637             "properties": {
    638               "text": {
    639                 "type": "string",
    640                 "description": "The text around cursor."
    641               },
    642               "focus": {
    643                 "type": "integer",
    644                 "description": "The ending position of the selection. This value indicates caret position if there is no selection."
    645               },
    646               "anchor": {
    647                 "type": "integer",
    648                 "description": "The beginning position of the selection. This value indicates caret position if is no selection."
    649               }
    650             }
    651           }
    652         ]
    653       },
    654       {
    655         "name": "onReset",
    656         "type": "function",
    657         "description": "This event is sent when chrome terminates ongoing text input session.",
    658         "parameters": [
    659           {
    660             "type": "string",
    661             "name": "engineID",
    662             "description": "ID of the engine receiving the event"
    663           }
    664         ]
    665       }
    666     ]
    667   }
    668 ]
    669