How to place a Xul window as “Always On Top”?

拥有回忆 提交于 2019-12-07 15:39:36

问题


I found this file at google code with the function:

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;
    }
}

The parts of it that I need are just:

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

But I'm not finding what where's the Ci defined. Any idea what can it be? Or any other idea of how to set a window always on top? (that solution "just for windows" don't fits to me).

--update

I'm reading about the nsIWindowMediator, which has some methods to handle the window Z order. But it's saying that the methods should be used from c++, not javascript. That means the code should be used from XPCOM components (I should as XPCOM component to open the window)? Does anyone that already used it could confirm?

I'm still reading anyway.

--update

I've tried the nsIWindowMediator (with a XPCOM component) but it just does nothing when I set the Z level.

Still look for a way to put the window aways on top..

--attempt with '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>

didn't worked.

--attempt with '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>

didn't worked. Nither with alwaysraised setted, or adding a higher or lower zlevel to the test.xul (with top.xul zlevel="6")


回答1:


Found: just open it using openDialog, and it will be always on top.

Ex:

<?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>



回答2:


If you always want the window to be on top, then the easiest way is to use the alwaysraised chrome flag when opening the window.

If you don't get to open the window yourself, the second easiest way is to use <window zlevel="6"> in your XUL. You can even persist the zlevel; SeaMonkey's Help window does this, using a context menu option to toggle the zLevel.

By the way, Ci is a common abbreviation for Components.interfaces since writing (e.g.) Components.interfaces.nsIXULWindow.rasiedZ is difficult to do on 80-character lines.



来源:https://stackoverflow.com/questions/4335286/how-to-place-a-xul-window-as-always-on-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!