nsITextInputProcessorCallback 编辑

dom/interfaces/base/nsITextInputProcessor.idlScriptable A callback interface for nsITextInputProcessor user 1.0 66 Introduced Gecko 38 Inherits from: nsISupports Last changed in Gecko 38.0 (Firefox 38.0 / Thunderbird 38.0 / SeaMonkey 2.35)

nsITextInputProcessorCallback is defined for receiving requests and notifications to IME from Gecko. This interface has a "function" attribute. Therefore, JS-IME can implement this as a function.

Example of simple JS-IME:

var simpleIME = {
  _hasFocus: false,
  _hasRightsToCompose: false,
  _TIP: null,
  _callback: function simpleIME_callback(aTIP, aNotification)
  {
    try {
      switch (aNotification.type) {
        case "request-to-commit":
          aTIP.commitComposition();
          break;
        case "request-to-cancel":
          aTIP.cancelComposition();
          break;
        case "notify-focus":
          this._hasFocus = true;
          break;
        case "notify-blur":
          this._hasFocus = false;
          break;
        case "notify-detached":
          this._hasFocus = false;
          this._hasRightsToCompose = false;
          break;
      }
      return true;
    } catch (e) {
      return false;
    }
  },
  setComposition: function simpleIME_setComposition(aText, aClauses, aCaret)
  {
    if (!this._TIP) {
      this._TIP = Components.classes["@mozilla.org/text-input-processor;1"].
                    createInstance(Components.interfaces.nsITextInputProcessor);
    }
    if (!this._TIP.beginInputTransaction(window, this._callback)) {
      return false;
    }
    ...
  },
}

Method overview

boolean onNotify(in nsITextInputProcessor aTextInputProcessor, in nsITextInputProcessorNotification aNotification);

Methods

onNotify()

This is called when Gecko requests or notifies something to IME.

boolean onNotify(in nsITextInputProcessor aTextInputProcessor,
                 in nsITextInputProcessorNotification aNotification);
Parameters
aTextInputProcessor
The instance which receives the notification. If the handler needs to do something with composition, you can use this.
aNotification
A notification or request. See the document of nsITextInputProcessorNotification for the details.
Return value

If this handles the notification normally or does nothing, it should return true. Otherwise, false.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:77 次

字数:3468

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文