如何将Xul窗口设置为“Always On Top”?

时间:2010-12-02 13:03:39

标签: javascript xul xpcom always-on-top

我在Google代码中找到了this file,功能为:

function SetAlwaysOnTop() {
    var chkTop = document.getElementById("itmAlwaysOnTop");
    var xulWin = window.QueryInterface(Ci.nsIInterfaceRequestor)
        .getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem)
        .treeOwner.QueryInterface(Ci.nsIInterfaceRequestor)
        .getInterface(Ci.nsIXULWindow);
    if(chkTop.getAttribute("checked") == "true") {
        xulWin.zLevel = xulWin.raisedZ;
    } else {
        xulWin.zLevel = xulWin.normalZ;
    }
}

我需要的部分只是:

var xulWin = window.QueryInterface(Ci.nsIInterfaceRequestor)
        .getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem)
        .treeOwner.QueryInterface(Ci.nsIInterfaceRequestor)
        .getInterface(Ci.nsIXULWindow);
xulWin.zLevel = xulWin.raisedZ;

但我找不到Ci所定义的内容。知道它能是什么吗?或者任何其他关于如何设置窗口总是在顶部的想法? (该解决方案“仅适用于Windows”不适合我)。

- 更新

我正在阅读nsIWindowMediator,它有一些处理窗口Z顺序的方法。但是它说这些方法应该用于c ++,而不是javascript。这意味着代码应该从XPCOM组件中使用(我应该作为XPCOM组件来打开窗口)?是否有人已经使用它可以确认?

无论如何我还在读。

- 更新

我已经尝试过nsIWindowMediator(带有XPCOM组件)但是当我设置Z级别时它什么也没做。

仍在寻找一种方法将窗户放在最顶层..

- 尝试使用'alwaysraised':

test.xul:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window width="400" height="300"
    onload="open('top.xul','GreenfoxChannelWindow','chrome, alwaysraised');"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <label value="MAIN WINDOW"/>

</window>

top.xul:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window width="400" height="300"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <label value="ON TOP"/>

</window>

没用。

- 尝试使用'zlevel':

test.xul:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window width="400" height="300"
    onload="open('top.xul','GreenfoxChannelWindow','chrome');"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <label value="MAIN WINDOW"/>

</window>

top.xul:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window width="400" height="300" zlevel="6"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <label value="ON TOP"/>

</window>

没用。没有经常设置,或者在test.xul中添加更高或更低的zlevel(top.xul zlevel =“6”)

2 个答案:

答案 0 :(得分:2)

找到:只需使用openDialog打开它,它将始终位于顶部。

例如:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window width="400" height="300"
    onload="openDialog('top.xul','TopWindow','chrome');"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <label value="MAIN WINDOW"/>

</window>

top.xul:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window width="400" height="300"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <label value="ON TOP" />

</window>

答案 1 :(得分:1)

如果您始终希望窗口位于顶部,那么最简单的方法是在打开窗口时使用alwaysraised镶边标记。

如果您不打算自己打开窗户,第二种最简单的方法是在您的XUL中使用<window zlevel="6">。你甚至可以坚持zlevel; SeaMonkey的帮助窗口执行此操作,使用上下文菜单选项切换zLevel。

顺便说一下,CiComponents.interfaces的常见缩写,因为在80个字符的行上很难写(例如)Components.interfaces.nsIXULWindow.rasiedZ