mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-04 04:58:00 +00:00
don't resize or move while 'opening' an extant window
This commit is contained in:
parent
17402208c3
commit
89545a8ee9
@ -1931,11 +1931,16 @@ GlobalWindowImpl::OpenInternal(JSContext *cx,
|
|||||||
if ((nsnull != mWebShell) &&
|
if ((nsnull != mWebShell) &&
|
||||||
(NS_OK == mWebShell->GetContainer(webShellContainer)) &&
|
(NS_OK == mWebShell->GetContainer(webShellContainer)) &&
|
||||||
(nsnull != webShellContainer)) {
|
(nsnull != webShellContainer)) {
|
||||||
|
|
||||||
|
PRBool windowIsNew;
|
||||||
|
|
||||||
// Check for existing window of same name.
|
// Check for existing window of same name.
|
||||||
|
windowIsNew = PR_FALSE;
|
||||||
webShellContainer->FindWebShellWithName(name.GetUnicode(), newOuterShell);
|
webShellContainer->FindWebShellWithName(name.GetUnicode(), newOuterShell);
|
||||||
if (nsnull == newOuterShell) {
|
if (nsnull == newOuterShell) {
|
||||||
// No window of that name, and we are allowed to create a new one now.
|
// No window of that name, and we are allowed to create a new one now.
|
||||||
webShellContainer->NewWebShell(chromeFlags, PR_FALSE, newOuterShell);
|
webShellContainer->NewWebShell(chromeFlags, PR_FALSE, newOuterShell);
|
||||||
|
windowIsNew = PR_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsnull != newOuterShell) {
|
if (nsnull != newOuterShell) {
|
||||||
@ -1944,7 +1949,7 @@ GlobalWindowImpl::OpenInternal(JSContext *cx,
|
|||||||
AttachArguments(*aReturn, argv+3, argc-3);
|
AttachArguments(*aReturn, argv+3, argc-3);
|
||||||
newOuterShell->SetName(name.GetUnicode());
|
newOuterShell->SetName(name.GetUnicode());
|
||||||
newOuterShell->LoadURL(mAbsURL.GetUnicode());
|
newOuterShell->LoadURL(mAbsURL.GetUnicode());
|
||||||
SizeAndShowOpenedWebShell(newOuterShell, options);
|
SizeAndShowOpenedWebShell(newOuterShell, options, windowIsNew);
|
||||||
}
|
}
|
||||||
NS_RELEASE(newOuterShell);
|
NS_RELEASE(newOuterShell);
|
||||||
}
|
}
|
||||||
@ -2046,7 +2051,8 @@ GlobalWindowImpl::CalculateChromeFlags(char *aFeatures) {
|
|||||||
|
|
||||||
// set the newly opened webshell's (window) size, and show it
|
// set the newly opened webshell's (window) size, and show it
|
||||||
nsresult
|
nsresult
|
||||||
GlobalWindowImpl::SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell, char *aFeatures)
|
GlobalWindowImpl::SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell, char *aFeatures,
|
||||||
|
PRBool aNewWindow)
|
||||||
{
|
{
|
||||||
if (nsnull == aOuterShell)
|
if (nsnull == aOuterShell)
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
@ -2057,30 +2063,44 @@ GlobalWindowImpl::SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell, char *aFea
|
|||||||
*openedWindow = nsnull;
|
*openedWindow = nsnull;
|
||||||
|
|
||||||
// use this window's size as the default
|
// use this window's size as the default
|
||||||
if (NS_SUCCEEDED(GetBrowserWindowInterface(thisWindow))) {
|
if (aNewWindow && NS_SUCCEEDED(GetBrowserWindowInterface(thisWindow))) {
|
||||||
thisWindow->GetWindowBounds(defaultBounds);
|
thisWindow->GetWindowBounds(defaultBounds);
|
||||||
NS_RELEASE(thisWindow);
|
NS_RELEASE(thisWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the nsIBrowserWindow corresponding to the given aOuterShell
|
// get the nsIBrowserWindow corresponding to the given aOuterShell
|
||||||
nsIWebShell *rootShell;
|
nsIWebShell *rootShell;
|
||||||
aOuterShell->GetRootWebShellEvenIfChrome(rootShell);
|
aOuterShell->GetRootWebShellEvenIfChrome(rootShell);
|
||||||
if (nsnull != rootShell) {
|
if (nsnull != rootShell) {
|
||||||
nsIWebShellContainer *newContainer;
|
nsIWebShellContainer *newContainer;
|
||||||
rootShell->GetContainer(newContainer);
|
rootShell->GetContainer(newContainer);
|
||||||
if (nsnull != newContainer) {
|
if (nsnull != newContainer) {
|
||||||
if (NS_FAILED(newContainer->QueryInterface(kIBrowserWindowIID, (void**)&openedWindow)))
|
if (NS_FAILED(newContainer->QueryInterface(kIBrowserWindowIID, (void**)&openedWindow)))
|
||||||
openedWindow = nsnull;
|
openedWindow = nsnull;
|
||||||
NS_RELEASE(newContainer);
|
NS_RELEASE(newContainer);
|
||||||
}
|
}
|
||||||
NS_RELEASE(rootShell);
|
NS_RELEASE(rootShell);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set size
|
// set size
|
||||||
if (nsnull != openedWindow) {
|
if (nsnull != openedWindow) {
|
||||||
|
|
||||||
|
nsRect contentOffsets; // constructor sets all values to 0
|
||||||
PRUint32 chromeFlags = CalculateChromeFlags(aFeatures);
|
PRUint32 chromeFlags = CalculateChromeFlags(aFeatures);
|
||||||
PRBool openAsContent = ((chromeFlags & NS_CHROME_OPEN_AS_CHROME) == 0);
|
PRBool openAsContent = ((chromeFlags & NS_CHROME_OPEN_AS_CHROME) == 0);
|
||||||
|
|
||||||
|
// if it's an extant window, we are already our default size
|
||||||
|
if (!aNewWindow)
|
||||||
|
if (openAsContent) {
|
||||||
|
// defaultBounds are the content rect. also, save window size diffs
|
||||||
|
openedWindow->GetWindowBounds(contentOffsets);
|
||||||
|
openedWindow->GetContentBounds(defaultBounds);
|
||||||
|
contentOffsets.x -= defaultBounds.x;
|
||||||
|
contentOffsets.y -= defaultBounds.y;
|
||||||
|
contentOffsets.width -= defaultBounds.width;
|
||||||
|
contentOffsets.height -= defaultBounds.height;
|
||||||
|
} else
|
||||||
|
openedWindow->GetWindowBounds(defaultBounds);
|
||||||
|
|
||||||
if (nsnull != aFeatures) {
|
if (nsnull != aFeatures) {
|
||||||
|
|
||||||
@ -2096,16 +2116,35 @@ GlobalWindowImpl::SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell, char *aFea
|
|||||||
|
|
||||||
left = WinHasOption(aFeatures, "left") | WinHasOption(aFeatures, "screenX");
|
left = WinHasOption(aFeatures, "left") | WinHasOption(aFeatures, "screenX");
|
||||||
top = WinHasOption(aFeatures, "top") | WinHasOption(aFeatures, "screenY");
|
top = WinHasOption(aFeatures, "top") | WinHasOption(aFeatures, "screenY");
|
||||||
|
|
||||||
|
if (left)
|
||||||
|
defaultBounds.x = left;
|
||||||
|
if (top)
|
||||||
|
defaultBounds.y = top;
|
||||||
|
if (width)
|
||||||
|
defaultBounds.width = width;
|
||||||
|
if (height)
|
||||||
|
defaultBounds.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
// beard: don't resize/reposition the window if it is the same web shell.
|
// beard: don't resize/reposition the window if it is the same web shell.
|
||||||
if (aOuterShell != mWebShell) {
|
if (aOuterShell != mWebShell) {
|
||||||
if (openAsContent)
|
if (openAsContent) {
|
||||||
openedWindow->SizeContentTo(width ? width : defaultBounds.width, height ? height : defaultBounds.height);
|
openedWindow->SizeWindowTo(defaultBounds.width + contentOffsets.width,
|
||||||
else if (width > 0 || height > 0)
|
defaultBounds.height + contentOffsets.height);
|
||||||
openedWindow->SizeWindowTo(width ? width : defaultBounds.width, height ? height : defaultBounds.height);
|
// oy. sizing the content makes sense: that's what the user asked for,
|
||||||
|
// however, it doesn't have the desired effect because all sizing
|
||||||
|
// functions eventually end up sizing the window, and the subwindows
|
||||||
|
// used to calculate the appropriate deltas are different. here we use
|
||||||
|
// the HTML content area; the window uses the main webshell. maybe
|
||||||
|
// i could calculate a triple offset, but commenting it out is easier,
|
||||||
|
// and probably effectively the same thing.
|
||||||
|
// openedWindow->SizeContentTo(defaultBounds.width, defaultBounds.height);
|
||||||
|
} else
|
||||||
|
openedWindow->SizeWindowTo(defaultBounds.width, defaultBounds.height);
|
||||||
|
|
||||||
openedWindow->MoveTo(left ? left : defaultBounds.x, top ? top : defaultBounds.y);
|
openedWindow->MoveTo(defaultBounds.x + contentOffsets.x,
|
||||||
|
defaultBounds.y + contentOffsets.y);
|
||||||
openedWindow->Show();
|
openedWindow->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +223,8 @@ protected:
|
|||||||
PRBool aAttachArguments, nsIDOMWindow** aReturn);
|
PRBool aAttachArguments, nsIDOMWindow** aReturn);
|
||||||
nsresult AttachArguments(nsIDOMWindow *aWindow, jsval *argv, PRUint32 argc);
|
nsresult AttachArguments(nsIDOMWindow *aWindow, jsval *argv, PRUint32 argc);
|
||||||
PRUint32 CalculateChromeFlags(char *aFeatures);
|
PRUint32 CalculateChromeFlags(char *aFeatures);
|
||||||
nsresult SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell, char *aFeatures);
|
nsresult SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell, char *aFeatures,
|
||||||
|
PRBool aNewWindow);
|
||||||
nsresult ReadyOpenedWebShell(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow);
|
nsresult ReadyOpenedWebShell(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow);
|
||||||
|
|
||||||
static nsresult WebShellToDOMWindow(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow);
|
static nsresult WebShellToDOMWindow(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user