moving initial content focus from OnEndDocumentLoad to Show. Reinstating SetSizeFromXUL. reduces new window flashing and allows gtk windows to size from JS. r:hyatt@netscape.com

This commit is contained in:
danm%netscape.com 1999-10-28 01:52:49 +00:00
Родитель 4e63acaf85
Коммит 4ff984d739
2 изменённых файлов: 72 добавлений и 13 удалений

Просмотреть файл

@ -251,6 +251,7 @@ nsWebShellWindow::nsWebShellWindow()
mChromeMask = NS_CHROME_ALL_CHROME;
mIntrinsicallySized = PR_FALSE;
mCreatedVisible = PR_TRUE;
mDebuting = PR_FALSE;
mLoadDefaultPage = PR_TRUE;
}
@ -1743,15 +1744,35 @@ nsWebShellWindow::FocusAvailable(nsIWebShell* aFocusedWebShell, PRBool& aFocusTa
NS_IMETHODIMP
nsWebShellWindow::Show(PRBool aShow)
{
if (mDebuting)
return NS_OK;
mDebuting = PR_TRUE; // (Show/Focus is recursive)
mWebShell->Show(); // crimminy -- it doesn't take a parameter!
mWindow->Show(aShow);
// this may cause problems, focusing the content webshell on every show.
// still, this code's previous position, in OnEndDocumentLoad, was
// forcing the window visible too early. this made the window flash,
// as it was resized, and aggravated a gtk bug in which windows cannot
// be resized after they're made visible. yes, that wants fixing.
// repercussions were myriad. focusing here, instead.
nsCOMPtr<nsIWebShell> contentShell;
GetContentWebShell(getter_AddRefs(contentShell));
if (contentShell) {
nsCOMPtr<nsIDOMWindow> domWindow;
if (NS_SUCCEEDED(ConvertWebShellToDOMWindow(contentShell,
getter_AddRefs(domWindow)))) {
domWindow->Focus();
}
}
nsresult rv;
NS_WITH_SERVICE(nsIWindowMediator, windowMediator, kWindowMediatorCID, &rv);
if ( NS_SUCCEEDED(rv) )
{
windowMediator->UpdateWindowTimeStamp( this );
}
mDebuting = PR_FALSE;
return NS_OK;
}
@ -1990,20 +2011,15 @@ nsWebShellWindow::OnEndDocumentLoad(nsIDocumentLoader* loader,
ShowAppropriateChrome();
LoadContentAreas();
if (mIntrinsicallySized)
mWebShell->SizeToContent();
else
SetSizeFromXUL();
// Here's where we service the "show" request initially given in Initialize()
if (mCreatedVisible)
Show(PR_TRUE);
nsCOMPtr<nsIWebShell> contentShell;
GetContentWebShell(getter_AddRefs(contentShell));
if (contentShell) {
nsCOMPtr<nsIDOMWindow> domWindow;
if (NS_SUCCEEDED(ConvertWebShellToDOMWindow(contentShell,
getter_AddRefs(domWindow)))) {
domWindow->Focus();
}
}
return NS_OK;
}
@ -2244,6 +2260,47 @@ void nsWebShellWindow::ExecuteStartupCode()
mCallbacks->ConstructAfterJavaScript(mWebShell);
}
/* This simply reads attributes from the window tag and blindly sets the size
to whatever it finds within.
*/
void nsWebShellWindow::SetSizeFromXUL()
{
nsCOMPtr<nsIDOMNode> webshellNode = GetDOMNodeFromWebShell(mWebShell);
nsIWidget *windowWidget = GetWidget();
nsCOMPtr<nsIDOMElement> webshellElement;
nsString sizeString;
PRInt32 errorCode,
specWidth, specHeight,
specSize;
nsRect currentSize;
if (webshellNode)
webshellElement = do_QueryInterface(webshellNode);
if (!webshellElement || !windowWidget) // it's hopeless
return;
// first guess: use current size
mWindow->GetBounds(currentSize);
specWidth = currentSize.width;
specHeight = currentSize.height;
// read "height" attribute
if (NS_SUCCEEDED(webshellElement->GetAttribute("height", sizeString))) {
specSize = sizeString.ToInteger(&errorCode);
if (NS_SUCCEEDED(errorCode) && specSize > 0)
specHeight = specSize;
}
// read "width" attribute
if (NS_SUCCEEDED(webshellElement->GetAttribute("width", sizeString))) {
specSize = sizeString.ToInteger(&errorCode);
if (NS_SUCCEEDED(errorCode) || specSize > 0)
specWidth = specSize;
}
if (specWidth != currentSize.width || specHeight != currentSize.height)
windowWidget->Resize(specWidth, specHeight, PR_TRUE);
} // SetSizeFromXUL
void nsWebShellWindow::SetTitleFromXUL()

Просмотреть файл

@ -246,8 +246,8 @@ public:
NS_IMETHOD GetWindowBounds(nsRect& aResult);
NS_IMETHOD IsIntrinsicallySized(PRBool& aResult);
NS_IMETHOD ShowAfterCreation() { mCreatedVisible = PR_TRUE; return NS_OK; }
NS_IMETHOD Show() { Show(PR_TRUE); return NS_OK; }
NS_IMETHOD Hide() { Show(PR_FALSE); return NS_OK; }
NS_IMETHOD Show() { return Show(PR_TRUE); }
NS_IMETHOD Hide() { return Show(PR_FALSE); }
NS_IMETHOD SetChrome(PRUint32 aNewChromeMask);
NS_IMETHOD GetChrome(PRUint32& aChromeMaskResult);
NS_IMETHOD SetTitle(const PRUnichar* aTitle);
@ -284,6 +284,7 @@ protected:
nsCOMPtr<nsIDOMNode> GetDOMNodeFromWebShell(nsIWebShell *aShell);
void ExecuteStartupCode();
void SetSizeFromXUL();
void SetTitleFromXUL();
void ShowAppropriateChrome();
void LoadContentAreas();
@ -304,7 +305,8 @@ protected:
PRBool mLockedUntilChromeLoad;
PRBool mChromeInitialized;
PRUint32 mChromeMask;
PRBool mCreatedVisible;
PRBool mCreatedVisible; // requested visible at creation
PRBool mDebuting; // being made visible right now
PRBool mLoadDefaultPage;
nsVoidArray mMenuDelegates;