Confirmed users
58
edits
m (→Proposed API) |
m (→Proposed API) |
||
Line 150: | Line 150: | ||
Promise<boolean> setSelectionRange(long start, long length); | Promise<boolean> setSelectionRange(long start, long length); | ||
/* User moves the cursor, or changes the selection with other means | /* User moves the cursor, or changes the selection with other means. If the text around | ||
* | * cursor has changed, but the cursor has not been moved, the IME won't get notification. | ||
* | * | ||
* [JJ] I would merge this with onsurroundingtextchange to have 1 state event. | * [JJ] I would merge this with onsurroundingtextchange to have 1 state event. | ||
* in the end, every onselectionchange event will also generate a surrounding | * in the end, every onselectionchange event will also generate a surrounding | ||
* text change event. | * text change event. | ||
*/ | */ | ||
attribute EventHandler onselectionchange; | attribute EventHandler onselectionchange; | ||
/* | |||
* Commit text to current input field and replace text around cursor position. It will clear the current composition. | |||
* | |||
* @param text The string to be replaced with. | |||
* @param offset The offset from the cursor position where replacing starts. Defaults to 0. | |||
* @param length The length of text to replace. Defaults to 0. | |||
*/ | |||
Promise<boolean> replaceSurroundingText(DOMString text, [optional] long offset, [optional] long length); | |||
/* | /* | ||
* | * | ||
Line 168: | Line 176: | ||
* [JJ] Rather do a replaceSurroundingText(long offset, long length, optional DOMString text) | * [JJ] Rather do a replaceSurroundingText(long offset, long length, optional DOMString text) | ||
* If text is null or empty, it behaves the same | * If text is null or empty, it behaves the same | ||
*/ | */ | ||
Promise<boolean> deleteSurroundingText(long offset, long length); | Promise<boolean> deleteSurroundingText(long offset, long length); | ||
/* | /* | ||
* | * Notifies when the text around the cursor is changed, due to either text | ||
* editing or cursor movement. | * editing or cursor movement. If the cursor has been moved, but the text around has not | ||
* changed, the IME won't get notification. | |||
* | * | ||
* The event handler function is specified as: | * The event handler function is specified as: | ||
* @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(DOMString beforeText, DOMString afterText) { | * function(DOMString beforeText, DOMString afterText) { | ||
* ... | * ... | ||
* } | * } | ||
*/ | */ | ||
attribute SurroundingTextChangeEventHandler onsurroundingtextchange; | attribute SurroundingTextChangeEventHandler onsurroundingtextchange; | ||
Line 194: | Line 195: | ||
/* | /* | ||
* send a character with its key events. | * send a character with its key events. | ||
* | * @param modifiers see http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/base/nsIDOMWindowUtils.idl#206 | ||
* @return true if succeeds. Otherwise false if the input context becomes void. | |||
* Alternative: sendKey(KeyboardEvent event), but we will likely waste memory for creating the KeyboardEvent object. | * Alternative: sendKey(KeyboardEvent event), but we will likely waste memory for creating the KeyboardEvent object. | ||
*/ | */ | ||
Promise<boolean> sendKey(long keyCode, long charCode, long modifiers); | Promise<boolean> sendKey(long keyCode, long charCode, long modifiers); | ||
Line 206: | Line 204: | ||
* Set current composition. It will start or update composition. | * Set current composition. It will start or update composition. | ||
* @param cursor Position in the text of the cursor. | * @param cursor Position in the text of the cursor. | ||
* | * | ||
* | * The API implementation should automatically ends the composition | ||
* session (with event and confirm the current composition) if | |||
* | * endComposition is never called. Same apply when the inputContext is lost | ||
* | * during a unfinished composition session. | ||
*/ | */ | ||
Promise<boolean> setComposition(DOMString text, long cursor); | Promise<boolean> setComposition(DOMString text, long cursor); | ||
Line 224: | Line 222: | ||
*/ | */ | ||
Promise<boolean> endComposition(DOMString text); | Promise<boolean> endComposition(DOMString text); | ||
}; | }; | ||