зеркало из https://github.com/mozilla/gecko-dev.git
Bug 593307. Ensure centerscreen windows are initially created in a valid screen position. r=jst,jmathies a=blocking-final
This commit is contained in:
Родитель
f2e3d7e675
Коммит
ab0981bac5
|
@ -540,8 +540,7 @@ nsWindow::Create(nsIWidget *aParent,
|
|||
nsnull : aParent;
|
||||
|
||||
mIsTopWidgetWindow = (nsnull == baseParent);
|
||||
mBounds.width = aRect.width;
|
||||
mBounds.height = aRect.height;
|
||||
mBounds = aRect;
|
||||
|
||||
BaseCreate(baseParent, aRect, aHandleEventFunction, aContext,
|
||||
aAppShell, aToolkit, aInitData);
|
||||
|
|
|
@ -68,6 +68,9 @@ _CHROME_FILES = test_bug343416.xul \
|
|||
test_bug478536.xul \
|
||||
window_bug478536.xul \
|
||||
test_bug517396.xul \
|
||||
test_bug593307.xul \
|
||||
window_bug593307_offscreen.xul \
|
||||
window_bug593307_centerscreen.xul \
|
||||
test_keycodes.xul \
|
||||
test_wheeltransaction.xul \
|
||||
window_wheeltransaction.xul \
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
||||
type="text/css"?>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=593307
|
||||
-->
|
||||
<window title="Mozilla Bug 593307"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<title>Test for Bug 593307</title>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function finish() {
|
||||
offscreenWindow.close();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIWebNavigation)
|
||||
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
|
||||
.rootTreeItem
|
||||
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindow);
|
||||
|
||||
var offscreenWindow = mainWindow.openDialog("window_bug593307_offscreen.xul", "",
|
||||
"dialog=no,chrome,width=200,height=200,screenX=-3000,screenY=-3000",
|
||||
SimpleTest, finish);
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</window>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<window title="Mozilla Bug 593307"
|
||||
width="100" height="100"
|
||||
onload="onload();"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml" id="body">
|
||||
</body>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
function onload()
|
||||
{
|
||||
var SimpleTest = window.opener.SimpleTest;
|
||||
SimpleTest.ok(window.screenX >= 0, "centerscreen window should not start offscreen (X coordinate)");
|
||||
SimpleTest.ok(window.screenY >= 0, "centerscreen window should not start offscreen (Y coordinate)");
|
||||
window.opener.finished();
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</window>
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<window title="Mozilla Bug 593307"
|
||||
width="100" height="100"
|
||||
onload="onLoad();"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml" id="body">
|
||||
</body>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
var centerscreen = null;
|
||||
var SimpleTest = window.arguments[0];
|
||||
var finish = window.arguments[1];
|
||||
|
||||
function onLoad()
|
||||
{
|
||||
centerscreen = window.openDialog('window_bug593307_centerscreen.xul','', 'chrome,centerscreen,dependent,dialog=no');
|
||||
}
|
||||
|
||||
function finished() {
|
||||
centerscreen.close();
|
||||
finish();
|
||||
}
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</window>
|
|
@ -95,6 +95,9 @@
|
|||
#include "nsIObserverService.h"
|
||||
#include "prprf.h"
|
||||
|
||||
#include "nsIScreenManager.h"
|
||||
#include "nsIScreen.h"
|
||||
|
||||
#include "nsIContent.h" // for menus
|
||||
|
||||
// For calculating size
|
||||
|
@ -162,6 +165,7 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,
|
|||
|
||||
mIsHiddenWindow = aIsHiddenWindow;
|
||||
|
||||
PRInt32 initialX = 0, initialY = 0;
|
||||
nsCOMPtr<nsIBaseWindow> base(do_QueryInterface(aOpener));
|
||||
if (base) {
|
||||
rv = base->GetPositionAndSize(&mOpenerScreenRect.x,
|
||||
|
@ -170,12 +174,16 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,
|
|||
&mOpenerScreenRect.height);
|
||||
if (NS_FAILED(rv)) {
|
||||
mOpenerScreenRect.Empty();
|
||||
} else {
|
||||
initialX = mOpenerScreenRect.x;
|
||||
initialY = mOpenerScreenRect.y;
|
||||
ConstrainToOpenerScreen(&initialX, &initialY);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: need to get the default window size from prefs...
|
||||
// Doesn't come from prefs... will come from CSS/XUL/RDF
|
||||
nsIntRect r(mOpenerScreenRect.x, mOpenerScreenRect.y, aInitialWidth, aInitialHeight);
|
||||
nsIntRect r(initialX, initialY, aInitialWidth, aInitialHeight);
|
||||
|
||||
// Create top level window
|
||||
mWindow = do_CreateInstance(kWindowCID, &rv);
|
||||
|
@ -772,6 +780,33 @@ PRBool nsWebShellWindow::ExecuteCloseHandler()
|
|||
return PR_FALSE;
|
||||
} // ExecuteCloseHandler
|
||||
|
||||
void nsWebShellWindow::ConstrainToOpenerScreen(PRInt32* aX, PRInt32* aY)
|
||||
{
|
||||
if (mOpenerScreenRect.IsEmpty()) {
|
||||
*aX = *aY = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
PRInt32 left, top, width, height;
|
||||
// Constrain initial positions to the same screen as opener
|
||||
nsCOMPtr<nsIScreenManager> screenmgr = do_GetService("@mozilla.org/gfx/screenmanager;1");
|
||||
if (screenmgr) {
|
||||
nsCOMPtr<nsIScreen> screen;
|
||||
screenmgr->ScreenForRect(mOpenerScreenRect.x, mOpenerScreenRect.y,
|
||||
mOpenerScreenRect.width, mOpenerScreenRect.height,
|
||||
getter_AddRefs(screen));
|
||||
if (screen) {
|
||||
screen->GetAvailRect(&left, &top, &width, &height);
|
||||
if (*aX < left || *aY > left + width) {
|
||||
*aX = left;
|
||||
}
|
||||
if (*aY < top || *aY > top + height) {
|
||||
*aY = top;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// nsIBaseWindow
|
||||
NS_IMETHODIMP nsWebShellWindow::Destroy()
|
||||
{
|
||||
|
|
|
@ -84,6 +84,7 @@ protected:
|
|||
|
||||
void LoadContentAreas();
|
||||
PRBool ExecuteCloseHandler();
|
||||
void ConstrainToOpenerScreen(PRInt32* aX, PRInt32* aY);
|
||||
|
||||
static nsEventStatus HandleEvent(nsGUIEvent *aEvent);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче