/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** *AnnsITextInputProcessorinstanceisassociatedwithatoplevelwidgetwhich *handlesnativeIME.It'sassociatedbycallingbeginInputTransaction()or *beginInputTransactionForTests().Whileaninstancehascomposition,nobody *canstealtherightstomakecompositiononthetoplevelwidget.Inother *words,ifanotherinstanceiscomposingonatoplevelwidget,either *beginInputTransaction()orbeginInputTransactionForTests()returnsfalse *(i.e.,notthrowsanexception). * *NOTE:SeensITextInputProcessorCallback.idlforexamplesof|callback|in *followingexamples, * *Example#1JS-IMEcanstartcompositionlikethis: * *varTIP=Components.classes["@mozilla.org/text-input-processor;1"]. *createInstance(Components.interfaces.nsITextInputProcessor); *if(!TIP.beginInputTransaction(window,callback)){ *return;// You failed to get the rights to make composition *} *// Create a keyboard event if the following compositionc change is caused *// by a key event. *varkeyEvent= *newKeyboardEvent("",{key:"foo",code:"bar",keyCode:buzz}); *// Set new composition string first *TIP.setPendingCompositionString("some-words-are-inputted"); *// Set clause information. *TIP.appendClauseToPendingComposition(23,TIP.ATTR_RAW_CLAUSE); *// Set caret position, this is optional. *TIP.setCaretInPendingComposition(23); *// Flush the pending composition *if(!TIP.flushPendingComposition(keyEvent)){ *// If it returns false, it fails to start composition. *return; *} * *Example#2JS-IMEcanseparatecompositionstringtotwoormoreclauses: * *// Create a keyboard event if the following compositionc change is caused *// by a key event. *varkeyEvent= *newKeyboardEvent("",{key:"foo",code:"bar",keyCode:buzz}); *// First, set composition string again *TIP.setPendingCompositionString("some-words-are-inputted"); *// Then, if "are" is selected to convert, there are 3 clauses: *TIP.appendClauseToPendingComposition(11,TIP.ATTR_CONVERTED_CLAUSE); *TIP.appendClauseToPendingComposition(3,TIP.ATTR_SELECTED_CLAUSE); *TIP.appendClauseToPendingComposition(9,TIP.ATTR_CONVERTED_CLAUSE); *// Show caret at the beginning of the selected clause *TIP.setCaretInPendingComposition(11); *// Flush the pending composition. Note that if there is a composition, *// flushPendingComposition() won't return false. *TIP.flushPendingComposition(keyEvent); * *Example#3JS-IMEcancommitcompositionwithspecificstringwiththis: * *// Create a keyboard event if the following compositionc change is caused *// by a key event. *varkeyEvent1= *newKeyboardEvent("",{key:"foo",code:"bar",keyCode:buzz}); *// First, there is a composition. *TIP.setPendingCompositionString("some-words-directly-inputted"); *TIP.appendClauseToPendingComposition(28,TIP.ATTR_RAW_CLAUSE); *TIP.flushPendingComposition(keyEvent1); *// Create a keyboard event if the following commit composition is caused *// by a key event. *varkeyEvent2= *newKeyboardEvent("",{key:"foo",code:"bar",keyCode:buzz}); *// This is useful when user selects a commit string from candidate list UI *// which is provided by JS-IME. *TIP.commitCompositionWith("selected-words-from-candidate-list",keyEvent2); * *Example#4JS-IMEcancommitcompositionwiththelastcompositionstring *withoutspecifyingcommitstring: * *// Create a keyboard event if the following compositionc change is caused *// by a key event. *varkeyEvent1= *newKeyboardEvent("",{key:"foo",code:"bar",keyCode:buzz}); *// First, there is a composition. *TIP.setPendingCompositionString("some-words-will-be-commited"); *TIP.appendClauseToPendingComposition(27,TIP.ATTR_RAW_CLAUSE); *TIP.flushPendingComposition(keyEvent1); *// Create a keyboard event if the following commit is caused by a key *// event. *varkeyEvent2= *newKeyboardEvent("",{key:"Enter",code:"Enter", keyCode:KeyboardEvent.DOM_VK_RETURN}); *// This is useful when user just type Enter key. *TIP.commitComposition(keyEvent2); * *Example#5JS-IMEcancancelcompositionwiththis: * *// Create a keyboard event if the following composition change is caused *// by a key event. *varkeyEvent1= *newKeyboardEvent("",{key:"foo",code:"bar",keyCode:buzz}); *// First, there is a composition. *TIP.setPendingCompositionString("some-words-will-be-canceled"); *TIP.appendClauseToPendingComposition(27,TIP.ATTR_RAW_CLAUSE); *TIP.flushPendingComposition(keyEvent1); *// Create a keyboard event if the following canceling composition is *// caused by a key event. *varkeyEvent2= *newKeyboardEvent("",{key:"Escape",code:"Escape", keyCode:KeyboardEvent.DOM_VK_ESCAPE}); *// This is useful when user doesn't want to commit the composition. *// FYI: This is same as TIP.commitCompositionWith("") for now. *TIP.cancelComposition(keyEvent2); * *Example#6JS-IMEcaninserttextonlywithcommitCompositionWith(): * *// Create a keyboard event if the following inserting text is caused by a *// key event. *varkeyEvent1= *newKeyboardEvent("",{key:"foo",code:"bar",keyCode:buzz}); *if(!TIP.beginInputTransaction(window,callback)){ *return;// You failed to get the rights to make composition *} *TIP.commitCompositionWith("Somewords",keyEvent1); * *Example#7JS-IMEcanstartcompositionexplicitly: * *if(!TIP.beginInputTransaction(window,callback)){ *return;// You failed to get the rights to make composition *} *// Create a keyboard event if the following starting composition is caused *// by a key event. *varkeyEvent1= *newKeyboardEvent("",{key:"foo",code:"bar",keyCode:buzz}); *// If JS-IME don't want to show composing string in the focused editor, *// JS-IME can dispatch only compositionstart event with this. *if(!TIP.startComposition(keyEvent1)){ *// Failed to start composition. *return; *} *// And when user selects a result from UI of JS-IME, commit with it. *// Then, the key event should be null. *TIP.commitCompositionWith("selected-words"); * *Example#8JS-IMEorJS-Keyboardshoulddispatchkeyeventsevenduring *composition(non-printablekeycase): * *if(!TIP.beginInputTransaction(window,callback)){ *return;// You failed to get the rights to dispatch key events *} * *// You don't need to specify .keyCode value if it's non-printable key *// because it can be computed from .key value. *// If you specify non-zero value to .keyCode, it'll be used. *varkeyEvent=newKeyboardEvent("",{code:"Enter",key:"Enter"}); *if(TIP.keydown(keyEvent)){ *// Handle its default action *} * *// Even if keydown event was consumed, keyup event should be dispatched. *if(TIP.keyup(keyEvent)){ *// Handle its default action *} * *Example#9JS-IMEorJS-Keyboardshoulddispatchkeyeventsevenduring *composition(printablekeycase): * *if(!TIP.beginInputTransaction(window,callback)){ *return;// You failed to get the rights to dispatch key events *} * *// You need to specify .keyCode value if it's printable key. *// The rules of .keyCode value is documented in MDN: *// https://developer.mozilla.org/docs/Web/API/KeyboardEvent.keyCode *// *// #1 If the key location is DOM_KEY_LOCATION_NUMPAD and NumLock is *// active, you should specify DOM_VK_NUMPAD[0-9], DOM_VK_MULTIPLY, *// DOM_VK_ADD, DOM_VK_SEPARATOR, DOM_VK_SUBTRACT, DOM_VK_DECIMAL or *// DOM_VK_DIVIDE. *// #2 If the key is Spacebar, use DOM_VK_SPACE. *// *// Following rules are printable keys in DOM_KEY_LOCATION_STANDARD. *// .keyCode value for a key shouldn't be changed by modifier states: *// #1 If the key can input [0-9] with any modifier state (except *// NumLock state), the value should be DOM_VK_[0-9]. *// #2 Otherwise, and if the key inputs an ASCII alphabet with no *// active modifiers, use DOM_VK_[A-Z]. *// #3 Otherwise, and if the key inputs an ASCII alphabet with no *// active modifiers except Shift key state, use DOM_VK_[A-Z] for *// the shifted character. E.g., if a key causes non-alphabet *// character such as "@" or a Unicode character without Shift key *// but "a" is inputted when Shift key is pressed, the proper *// keyCode is DOM_VK_A. *// #4 Otherwise, and if the key inputs another ASCII character with *// no modifier states, use a proper value for the character. E.g., *// if the key inputs "*" without Shift key state, it should be *// DOM_VK_ASTERISK. *// #5 Otherwise, and if the key inputs another ASCII character with *// Shift key state, use a proper value for the character. E.g., *// if a key causes a Unicode character without Shift key but "&" *// is inputted when Shift key is pressed, the proper keyCode is *// DOM_VK_AMPERSAND. *// See above document for the other cases. *// *// NOTE: If the software keyboard is 10-key like simple phone, *// We don't have common rules to decide its .keyCode value. *// Above rules should be used when the JS-Keyboard emulates PC *// keyboard. *// .key value should be inputting character by the key with current *// modifier state. *// .code value should be empty string if the JS-Keyboard isn't emulating *// physical keyboard. Otherwise, use same value with physical keyboard's *// same key. *varkeyEvent=newKeyboardEvent("",{code:"KeyA",key:"a", *keyCode:KeyboardEvent.DOM_VK_A}); *if(TIP.keydown(keyEvent)){ *// Handle its default action *} * *// Even if keydown event was consumed, keyup event should be dispatched. *if(TIP.keyup(keyEvent)){ *// Handle its default action *} * *Example#10JS-Keyboarddoesn'tneedtoinitializemodifierstatesat *callingeitherkeydown()orkeyup(). * *// Neither beginInputTransaction() nor beginInputTransactionForTests() *// resets modifier state. *if(!TIP.beginInputTransaction(window,callback)){ *return;// You failed to get the rights to dispatch key events *} * *varleftShift=newKeyboardEvent("",{code:"ShiftLeft",key:"Shift"}); * *// This causes following key events will be shifted automatically. *TIP.keydown(leftShift); * *varrightShift= *newKeyboardEvent("",{code:"ShiftRight",key:"Shift"}); * *TIP.keydown(rightShift); * *// keyup of one of shift key doesn't cause inactivating "Shift" state. *TIP.keyup(rightShift); * *// This causes inactivating "Shift" state completely. *TIP.keyup(leftShift);
*/
// ATTR_RAW_CLAUSE means that the clause hasn't been selected nor converted // yet. constunsigned long ATTR_RAW_CLAUSE = 0x02; // ATTR_SELECTED_RAW_CLAUSE means that the clause hasn't been converted yet // but is selected for converting to the other string. constunsigned long ATTR_SELECTED_RAW_CLAUSE = 0x03; // ATTR_CONVERTED_CLAUSE means that the clause has already been converted but // is not selected. This does NOT mean that this clause isn't modifiable. constunsigned long ATTR_CONVERTED_CLAUSE = 0x04; // ATTR_SELECTED_CLAUSE means that the clause has already been converted and // is selected. In other words, the clause is being converted. constunsigned long ATTR_SELECTED_CLAUSE = 0x05;
// Specifying KEY_DEFAULT_PREVENTED can dispatch key events whose // defaultPrevented are true. Note that if this is specified, keypress event // won't be fired. constunsigned long KEY_DEFAULT_PREVENTED = 0x00000001; // If KEY_NON_PRINTABLE_KEY is specified and the .key value isn't valid // key name, the methods will throws an exception. In other words, this // flag prevents to dispatch key events with wrong key values and to cause // such key events input the key values as text. constunsigned long KEY_NON_PRINTABLE_KEY = 0x00000002; // If KEY_FORCE_PRINTABLE_KEY is specified and even if the .key value is a // registered key name, it's treated as inputting text value. constunsigned long KEY_FORCE_PRINTABLE_KEY = 0x00000004; // If KEY_KEEP_KEY_LOCATION_STANDARD is specified when its .location is not // initialized or initialized with 0, the value isn't computed with .code // value. Note that if .location is initialized with non-zero value, // this flag causes throwing an exception. // NOTE: This is not recommended to use except for tests. constunsigned long KEY_KEEP_KEY_LOCATION_STANDARD = 0x00000008; // If KEY_KEEP_KEYCODE_ZERO is specified when its .keyCode is not initialized // or initialized with 0, the value isn't computed with .key value when it // represents non-printable key. Note that if .keyCode is initialized with // non-zero value, this flag causes throwing an exception. constunsigned long KEY_KEEP_KEYCODE_ZERO = 0x00000010; // If KEY_DONT_DISPATCH_MODIFIER_KEY_EVENT is specified when the key event is // a modifier key's, keydown() and keyup() only modifies its modifier state // without dispatching key events. This is useful for testing odd behavior // or emulating legacy API behavior. constunsigned long KEY_DONT_DISPATCH_MODIFIER_KEY_EVENT = 0x00000020; // If KEY_DONT_MARK_KEYDOWN_AS_PROCESSED is specified, key value and keyCode // value of keydown event are not changed to "Process" and DOM_VK_PROCESSKEY. constunsigned long KEY_DONT_MARK_KEYDOWN_AS_PROCESSED = 0x00000040; // If KEY_MARK_KEYUP_AS_PROCESSED is specified, key value and keyCode value // of keyup event are changed to "Process" and DOM_VK_PROCESSKEY. constunsigned long KEY_MARK_KEYUP_AS_PROCESSED = 0x00000080;
// These values can be used to do bitwise operation with the return value of // the keydown() method. constunsigned long KEYEVENT_NOT_CONSUMED = 0x00000000; constunsigned long KEYDOWN_IS_CONSUMED = 0x00000001; constunsigned long KEYPRESS_IS_CONSUMED = 0x00000002;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.