ChromeInputIme class
Use the chrome.input.ime
API to implement a custom IME for Chrome OS. This
allows your extension to handle keystrokes, set the composition, and manage
the candidate window.
class ChromeInputIme extends ChromeApi { static final JsObject _input_ime = chrome['input']['ime']; ChromeInputIme._(); bool get available => _input_ime != null; /** * Set the current composition. If this extension does not own the active IME, * this fails. */ Future<bool> setComposition(InputImeSetCompositionParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('setComposition', [jsify(parameters), completer.callback]); return completer.future; } /** * Clear the current composition. If this extension does not own the active * IME, this fails. */ Future<bool> clearComposition(InputImeClearCompositionParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('clearComposition', [jsify(parameters), completer.callback]); return completer.future; } /** * Commits the provided text to the current input. */ Future<bool> commitText(InputImeCommitTextParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('commitText', [jsify(parameters), completer.callback]); return completer.future; } /** * Sets the properties of the candidate window. This fails if the extension * doesn’t own the active IME */ Future<bool> setCandidateWindowProperties(InputImeSetCandidateWindowPropertiesParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('setCandidateWindowProperties', [jsify(parameters), completer.callback]); return completer.future; } /** * Sets the current candidate list. This fails if this extension doesn’t own * the active IME */ Future<bool> setCandidates(InputImeSetCandidatesParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('setCandidates', [jsify(parameters), completer.callback]); return completer.future; } /** * Set the position of the cursor in the candidate window. This is a no-op if * this extension does not own the active IME. */ Future<bool> setCursorPosition(InputImeSetCursorPositionParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('setCursorPosition', [jsify(parameters), completer.callback]); return completer.future; } /** * Adds the provided menu items to the language menu when this IME is active. */ Future setMenuItems(InputImeSetMenuItemsParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _input_ime.callMethod('setMenuItems', [jsify(parameters), completer.callback]); return completer.future; } /** * Updates the state of the MenuItems specified */ Future updateMenuItems(InputImeUpdateMenuItemsParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _input_ime.callMethod('updateMenuItems', [jsify(parameters), completer.callback]); return completer.future; } /** * Deletes the text around the caret. */ Future deleteSurroundingText(InputImeDeleteSurroundingTextParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _input_ime.callMethod('deleteSurroundingText', [jsify(parameters), completer.callback]); return completer.future; } /** * Indicates that the key event received by onKeyEvent is handled. This * should only be called if the onKeyEvent listener is asynchronous. * * [requestId] Request id of the event that was handled. This should come * from keyEvent.requestId * * [response] True if the keystroke was handled, false if not */ void keyEventHandled(String requestId, bool response) { if (_input_ime == null) _throwNotAvailable(); _input_ime.callMethod('keyEventHandled', [requestId, response]); } /** * This event is sent when an IME is activated. It signals that the IME will * be receiving onKeyPress events. */ Stream<String> get onActivate => _onActivate.stream; final ChromeStreamController<String> _onActivate = new ChromeStreamController<String>.oneArg(_input_ime, 'onActivate', selfConverter); /** * This event is sent when an IME is deactivated. It signals that the IME will * no longer be receiving onKeyPress events. */ Stream<String> get onDeactivated => _onDeactivated.stream; final ChromeStreamController<String> _onDeactivated = new ChromeStreamController<String>.oneArg(_input_ime, 'onDeactivated', selfConverter); /** * 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. */ Stream<InputContext> get onFocus => _onFocus.stream; final ChromeStreamController<InputContext> _onFocus = new ChromeStreamController<InputContext>.oneArg(_input_ime, 'onFocus', _createInputContext); /** * 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. */ Stream<int> get onBlur => _onBlur.stream; final ChromeStreamController<int> _onBlur = new ChromeStreamController<int>.oneArg(_input_ime, 'onBlur', selfConverter); /** * 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. */ Stream<InputContext> get onInputContextUpdate => _onInputContextUpdate.stream; final ChromeStreamController<InputContext> _onInputContextUpdate = new ChromeStreamController<InputContext>.oneArg(_input_ime, 'onInputContextUpdate', _createInputContext); /** * This event is sent if this extension owns the active IME. */ Stream<OnKeyEventEvent> get onKeyEvent => _onKeyEvent.stream; final ChromeStreamController<OnKeyEventEvent> _onKeyEvent = new ChromeStreamController<OnKeyEventEvent>.twoArgs(_input_ime, 'onKeyEvent', _createOnKeyEventEvent); /** * This event is sent if this extension owns the active IME. */ Stream<OnCandidateClickedEvent> get onCandidateClicked => _onCandidateClicked.stream; final ChromeStreamController<OnCandidateClickedEvent> _onCandidateClicked = new ChromeStreamController<OnCandidateClickedEvent>.threeArgs(_input_ime, 'onCandidateClicked', _createOnCandidateClickedEvent); /** * Called when the user selects a menu item */ Stream<OnMenuItemActivatedEvent> get onMenuItemActivated => _onMenuItemActivated.stream; final ChromeStreamController<OnMenuItemActivatedEvent> _onMenuItemActivated = new ChromeStreamController<OnMenuItemActivatedEvent>.twoArgs(_input_ime, 'onMenuItemActivated', _createOnMenuItemActivatedEvent); /** * 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. */ Stream<OnSurroundingTextChangedEvent> get onSurroundingTextChanged => _onSurroundingTextChanged.stream; final ChromeStreamController<OnSurroundingTextChangedEvent> _onSurroundingTextChanged = new ChromeStreamController<OnSurroundingTextChangedEvent>.twoArgs(_input_ime, 'onSurroundingTextChanged', _createOnSurroundingTextChangedEvent); /** * This event is sent when chrome terminates ongoing text input session. */ Stream<String> get onReset => _onReset.stream; final ChromeStreamController<String> _onReset = new ChromeStreamController<String>.oneArg(_input_ime, 'onReset', selfConverter); void _throwNotAvailable() { throw new UnsupportedError("'chrome.input.ime' is not available"); } }
Extends
ChromeApi > ChromeInputIme
Properties
final bool available #
Returns true if the API is available. The common causes of an API not being avilable are:
- a permission is missing in the application's manifest.json file
- the API is defined on a newer version of Chrome then the current runtime
bool get available => _input_ime != null;
final Stream<String> onActivate #
This event is sent when an IME is activated. It signals that the IME will be receiving onKeyPress events.
Stream<String> get onActivate => _onActivate.stream;
final Stream<int> onBlur #
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.
Stream<int> get onBlur => _onBlur.stream;
final Stream<OnCandidateClickedEvent> onCandidateClicked #
This event is sent if this extension owns the active IME.
Stream<OnCandidateClickedEvent> get onCandidateClicked => _onCandidateClicked.stream;
final Stream<String> onDeactivated #
This event is sent when an IME is deactivated. It signals that the IME will no longer be receiving onKeyPress events.
Stream<String> get onDeactivated => _onDeactivated.stream;
final Stream<InputContext> onFocus #
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.
Stream<InputContext> get onFocus => _onFocus.stream;
final Stream<InputContext> onInputContextUpdate #
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.
Stream<InputContext> get onInputContextUpdate => _onInputContextUpdate.stream;
final Stream<OnKeyEventEvent> onKeyEvent #
This event is sent if this extension owns the active IME.
Stream<OnKeyEventEvent> get onKeyEvent => _onKeyEvent.stream;
final Stream<OnMenuItemActivatedEvent> onMenuItemActivated #
Called when the user selects a menu item
Stream<OnMenuItemActivatedEvent> get onMenuItemActivated => _onMenuItemActivated.stream;
final Stream<String> onReset #
This event is sent when chrome terminates ongoing text input session.
Stream<String> get onReset => _onReset.stream;
final Stream<OnSurroundingTextChangedEvent> onSurroundingTextChanged #
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.
Stream<OnSurroundingTextChangedEvent> get onSurroundingTextChanged => _onSurroundingTextChanged.stream;
Methods
Future<bool> clearComposition(InputImeClearCompositionParams parameters) #
Clear the current composition. If this extension does not own the active IME, this fails.
Future<bool> clearComposition(InputImeClearCompositionParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('clearComposition', [jsify(parameters), completer.callback]); return completer.future; }
Future<bool> commitText(InputImeCommitTextParams parameters) #
Commits the provided text to the current input.
Future<bool> commitText(InputImeCommitTextParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('commitText', [jsify(parameters), completer.callback]); return completer.future; }
Future deleteSurroundingText(InputImeDeleteSurroundingTextParams parameters) #
Deletes the text around the caret.
Future deleteSurroundingText(InputImeDeleteSurroundingTextParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _input_ime.callMethod('deleteSurroundingText', [jsify(parameters), completer.callback]); return completer.future; }
void keyEventHandled(String requestId, bool response) #
Indicates that the key event received by onKeyEvent is handled. This should only be called if the onKeyEvent listener is asynchronous.
requestId Request id of the event that was handled. This should come from keyEvent.requestId
response True if the keystroke was handled, false if not
void keyEventHandled(String requestId, bool response) { if (_input_ime == null) _throwNotAvailable(); _input_ime.callMethod('keyEventHandled', [requestId, response]); }
Future<bool> setCandidates(InputImeSetCandidatesParams parameters) #
Sets the current candidate list. This fails if this extension doesn’t own the active IME
Future<bool> setCandidates(InputImeSetCandidatesParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('setCandidates', [jsify(parameters), completer.callback]); return completer.future; }
Future<bool> setCandidateWindowProperties(InputImeSetCandidateWindowPropertiesParams parameters) #
Sets the properties of the candidate window. This fails if the extension doesn’t own the active IME
Future<bool> setCandidateWindowProperties(InputImeSetCandidateWindowPropertiesParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('setCandidateWindowProperties', [jsify(parameters), completer.callback]); return completer.future; }
Future<bool> setComposition(InputImeSetCompositionParams parameters) #
Set the current composition. If this extension does not own the active IME, this fails.
Future<bool> setComposition(InputImeSetCompositionParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('setComposition', [jsify(parameters), completer.callback]); return completer.future; }
Future<bool> setCursorPosition(InputImeSetCursorPositionParams parameters) #
Set the position of the cursor in the candidate window. This is a no-op if this extension does not own the active IME.
Future<bool> setCursorPosition(InputImeSetCursorPositionParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _input_ime.callMethod('setCursorPosition', [jsify(parameters), completer.callback]); return completer.future; }
Future setMenuItems(InputImeSetMenuItemsParams parameters) #
Adds the provided menu items to the language menu when this IME is active.
Future setMenuItems(InputImeSetMenuItemsParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _input_ime.callMethod('setMenuItems', [jsify(parameters), completer.callback]); return completer.future; }
Future updateMenuItems(InputImeUpdateMenuItemsParams parameters) #
Updates the state of the MenuItems specified
Future updateMenuItems(InputImeUpdateMenuItemsParams parameters) { if (_input_ime == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _input_ime.callMethod('updateMenuItems', [jsify(parameters), completer.callback]); return completer.future; }