获取一个Tab的nsIDOMWindow来做文本输入 [英] Get nsIDOMWindow of a Tab to do Text Input

查看:98
本文介绍了获取一个Tab的nsIDOMWindow来做文本输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Firefox窗口的特定选项卡上使用文本输入处理器?



所有选项卡共享相同的nsIDOMWindow对象吗?如果是这样,那么有没有其他解决方案?



改写我的问题:我想输入文本到一个特定的选项卡,如果有多个,那么它可能不是当前的。



以下是在任何Firefox窗口上编写文本的示例代码,但只适用于当前选项卡:

  function myTestFunc(){
// var windows = Services.wm.getEnumerator(navigation:browser);
var windows = require(sdk / windows);
for(让browserWindow的windows.browserWindows){
//console.log(window.title);
var chromeWindow = viewFor(browserWindow);
console.log(chromeWindow.document.location.href);
var idomWindow = chromeWindow.QueryInterface(Ci.nsIDOMWindow);

var TIP = Cc [@ mozilla.org/text-input-processor; 1]。
createInstance(Ci.nsITextInputProcessor);
if(!TIP.beginInputTransaction(idomWindow,onNotifyImpl)){
console.log(Error TIP can not start);
继续;

TIP.setPendingCompositionString(foo-bar-buzz);
if(!TIP.flushPendingComposition()){
console.log(无法刷新);
继续; //构图未开始



$ b code $
$ b $ div class (+ docshell等各种相关的接口)是常规的窗口的XPCOM表示 w3c规范中的对象。由于窗口对象可以嵌套(例如通过iframe),所以可以是nsIDOMWindows。当你访问浏览器窗口时,通常访问代表浏览器chrome的外部窗口,而不是内容。



原则上,您可以直接访问标签的内容窗口它的< browser> XUL元素,但是要与e10s向前兼容,您应该使用 framescript


Is it possible to use Text Input Processor on a specific Tab of a Firefox window?

Do all the tabs share the same nsIDOMWindow object? If so, then is there any other solution?

Rephrasing my problem: I want to type text to a specific tab, and if there is more than one, then it might not be the current.

Below is an example code to write text on any Firefox window, but only for current tab:

function myTestFunc() {
  // var windows = Services.wm.getEnumerator("navigation:browser");
  var windows = require("sdk/windows");
  for (let browserWindow of windows.browserWindows)  {
    //console.log(window.title);
    var chromeWindow = viewFor(browserWindow);
    console.log(chromeWindow.document.location.href);
    var idomWindow = chromeWindow.QueryInterface(Ci.nsIDOMWindow);

    var TIP = Cc["@mozilla.org/text-input-processor;1"].
              createInstance(Ci.nsITextInputProcessor);
    if(!TIP.beginInputTransaction(idomWindow, onNotifyImpl))  {
      console.log("Error TIP can't start");
      continue;
    }
    TIP.setPendingCompositionString("foo-bar-buzz");
    if (!TIP.flushPendingComposition()) {
      console.log("Failed to flush");
      continue; // Composition is not started
    }
  }

}

解决方案

nsIDOMWindow (+ various related interfaces like the docshell) is the XPCOM representation of regular window objects in the w3c specs. And since window objects can be nested (e.g. via iframes) so can be nsIDOMWindows. When you're accessing browser windows you're generally accessing the outer windows representing the browser chrome, not the content.

In principle you can access a tab's content window directly from its <browser> XUL element, but to be forward-compatible with e10s you should use framescripts instead.

这篇关于获取一个Tab的nsIDOMWindow来做文本输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆