mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-14 02:31:59 +00:00
Bug 113722: add moveToAlertPosition() and centerWindowOnScreen() to <dialog/>.r=hyatt, sr=hewitt. This will also fix bug 110459.
This commit is contained in:
parent
86f5be6e3c
commit
7895e64934
@ -64,6 +64,50 @@
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="moveToAlertPosition">
|
||||
<body>
|
||||
<![CDATA[
|
||||
// hack. we need this so the window has something like its final size
|
||||
if (window.outerWidth == 1) {
|
||||
dump("Trying to position a sizeless window; caller should have called sizeToContent() or sizeTo(). See bug 75649.\n");
|
||||
sizeToContent();
|
||||
}
|
||||
|
||||
var xOffset = (opener.outerWidth - window.outerWidth) / 2;
|
||||
var yOffset = opener.outerHeight / 5;
|
||||
|
||||
var newX = opener.screenX + xOffset;
|
||||
var newY = opener.screenY + yOffset;
|
||||
|
||||
// ensure the window is fully onscreen (if smaller than the screen)
|
||||
if (newX < screen.availLeft)
|
||||
newX = screen.availLeft + 20;
|
||||
if ((newX + window.outerWidth) > (screen.availLeft + screen.availWidth))
|
||||
newX = (screen.availLeft + screen.availWidth) - window.outerWidth - 20;
|
||||
|
||||
if (newY < screen.availTop)
|
||||
newY = screen.availTop + 20;
|
||||
if ((newY + window.outerHeight) > (screen.availTop + screen.availHeight))
|
||||
newY = (screen.availTop + screen.availHeight) - window.outerHeight - 60;
|
||||
|
||||
window.moveTo( newX, newY );
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="centerWindowOnScreen">
|
||||
<body>
|
||||
<![CDATA[
|
||||
var xOffset = screen.availWidth/2 - window.outerWidth/2;
|
||||
var yOffset = screen.availHeight/2 - window.outerHeight/2; //(opener.outerHeight *2)/10;
|
||||
|
||||
xOffset = xOffset > 0 ? xOffset : 0;
|
||||
yOffset = yOffset > 0 ? yOffset : 0;
|
||||
window.moveTo(xOffset, yOffset);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<constructor>
|
||||
<![CDATA[
|
||||
this._useAnonButton = {};
|
||||
@ -72,6 +116,9 @@
|
||||
window.addEventListener("close", this._closeHandler, false);
|
||||
|
||||
window.addEventListener("load", this.initialize, false);
|
||||
|
||||
window.moveToAlertPosition = this.moveToAlertPosition;
|
||||
window.centerWindowOnScreen = this.centerWindowOnScreen;
|
||||
]]>
|
||||
</constructor>
|
||||
|
||||
@ -90,6 +137,12 @@
|
||||
|
||||
// hide/show the appropriate buttons
|
||||
dialog._configureButtons(dialog.getAttribute("buttons"));
|
||||
|
||||
var position = dialog.getAttribute("position");
|
||||
if (position == "alert")
|
||||
dialog.moveToAlertPosition();
|
||||
else if (position == "center")
|
||||
dialog.centerWindowOnScreen();
|
||||
|
||||
// give focus to the first focusable element in the dialog
|
||||
if (!document.commandDispatcher.focusedElement)
|
||||
|
Loading…
Reference in New Issue
Block a user