Home | History | Annotate | Download | only in basic
      1 // Copyright 2013 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 var ime_api = chrome.input.ime;
      6 
      7 var context_id = -1;
      8 
      9 console.log("Initializing IME");
     10 
     11 ime_api.onFocus.addListener(function(context) {
     12   console.log('onFocus:' + context.contextID);
     13   context_id = context.contextID;
     14 });
     15 ime_api.onBlur.addListener(function(contextID) {
     16   console.log('onBlur:' + contextID);
     17   context_id = -1;
     18 });
     19 
     20 ime_api.onActivate.addListener(function(engineID) {
     21   console.log('onActivate:' + engineID);
     22 });
     23 ime_api.onDeactivated.addListener(function(engineID) {
     24   console.log('onDeactivated:' + engineID);
     25 });
     26 
     27 ime_api.onKeyEvent.addListener(
     28 function(engineID, keyData) {
     29   console.log('onKeyEvent:' + keyData.key + " context: " + context_id);
     30   if (keyData.type == "keydown" && keyData.key.match(/^[a-z]$/)) {
     31     chrome.input.ime.commitText({"contextID": context_id,
     32                                  "text": keyData.key.toUpperCase()});
     33     return true;
     34   }
     35 
     36   return false
     37 });
     38