diff --git a/mozilla/content/xul/document/src/Makefile.in b/mozilla/content/xul/document/src/Makefile.in index b1f0f216f3e..4b585467edc 100644 --- a/mozilla/content/xul/document/src/Makefile.in +++ b/mozilla/content/xul/document/src/Makefile.in @@ -70,6 +70,7 @@ REQUIRES = xpcom \ xultmpl \ webshell \ unicharutil \ + appshell \ $(NULL) CPPSRCS = nsXULControllers.cpp diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 84173ead4e8..670c1ae36e0 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -122,6 +122,9 @@ #include "nsContentErrors.h" #include "nsIObserverService.h" #include "nsNodeUtils.h" +#include "nsIDocShellTreeItem.h" +#include "nsIDocShellTreeOwner.h" +#include "nsIXULWindow.h" //---------------------------------------------------------------------- // @@ -2940,6 +2943,25 @@ nsXULDocument::ResumeWalk() } SetTitle(title); + // Before starting layout, check whether we're a toplevel chrome + // window. If we are, set our chrome flags now, so that we don't have + // to restyle the whole frame tree after StartLayout. + nsCOMPtr container = GetContainer(); + nsCOMPtr item = do_QueryInterface(container); + if (item) { + nsCOMPtr owner; + item->GetTreeOwner(getter_AddRefs(owner)); + nsCOMPtr xulWin = do_GetInterface(owner); + if (xulWin) { + nsCOMPtr xulWinShell; + xulWin->GetDocShell(getter_AddRefs(xulWinShell)); + if (SameCOMIdentity(xulWinShell, container)) { + // We're the chrome document! Apply our chrome flags now. + xulWin->ApplyChromeFlags(); + } + } + } + StartLayout(); if (mIsWritingFastLoad && IsChromeURI(mDocumentURI)) diff --git a/mozilla/xpfe/appshell/public/nsIXULWindow.idl b/mozilla/xpfe/appshell/public/nsIXULWindow.idl index cb9fb493e35..ebec94bac85 100644 --- a/mozilla/xpfe/appshell/public/nsIXULWindow.idl +++ b/mozilla/xpfe/appshell/public/nsIXULWindow.idl @@ -138,4 +138,12 @@ interface nsIXULWindow : nsISupports in nsIAppShell aAppShell); attribute nsIXULBrowserWindow XULBrowserWindow; + + /** + * Back-door method to force application of chrome flags at a particular + * time. Do NOT call this unless you know what you're doing! In particular, + * calling this when this XUL window doesn't yet have a document in its + * docshell could cause problems. + */ + [noscript] void applyChromeFlags(); }; diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.cpp b/mozilla/xpfe/appshell/src/nsXULWindow.cpp index 9f1085a5c8d..16b993c90d6 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsXULWindow.cpp @@ -2012,20 +2012,27 @@ void nsXULWindow::PersistentAttributesDirty(PRUint32 aDirtyFlags) mPersistentAttributesDirty |= aDirtyFlags & mPersistentAttributesMask; } -nsresult nsXULWindow::ApplyChromeFlags() +NS_IMETHODIMP nsXULWindow::ApplyChromeFlags() { nsCOMPtr window; GetWindowDOMElement(getter_AddRefs(window)); NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); - // menubar has its own special treatment - mWindow->ShowMenuBar(mChromeFlags & nsIWebBrowserChrome::CHROME_MENUBAR ? - PR_TRUE : PR_FALSE); + if (mChromeLoaded) { + // The two calls in this block don't need to happen early because they + // don't cause a global restyle on the document. Not only that, but the + // scrollbar stuff needs a content area to toggle the scrollbars on anyway. + // So just don't do these until mChromeLoaded is true. + + // menubar has its own special treatment + mWindow->ShowMenuBar(mChromeFlags & nsIWebBrowserChrome::CHROME_MENUBAR ? + PR_TRUE : PR_FALSE); - // Scrollbars have their own special treatment. - SetContentScrollbarVisibility(mChromeFlags & + // Scrollbars have their own special treatment. + SetContentScrollbarVisibility(mChromeFlags & nsIWebBrowserChrome::CHROME_SCROLLBARS ? - PR_TRUE : PR_FALSE); + PR_TRUE : PR_FALSE); + } /* the other flags are handled together. we have style rules in navigator.css that trigger visibility based on @@ -2050,14 +2057,9 @@ nsresult nsXULWindow::ApplyChromeFlags() if (! (mChromeFlags & nsIWebBrowserChrome::CHROME_EXTRA)) newvalue.AppendLiteral("extrachrome "); - - // Get the old value, to avoid useless style reflows if we're just - // setting stuff to the exact same thing. - nsAutoString oldvalue; - window->GetAttribute(NS_LITERAL_STRING("chromehidden"), oldvalue); - - if (oldvalue != newvalue) - window->SetAttribute(NS_LITERAL_STRING("chromehidden"), newvalue); + // Note that if we're not actually changing the value this will be a no-op, + // so no need to compare to the old value. + window->SetAttribute(NS_LITERAL_STRING("chromehidden"), newvalue); return NS_OK; } diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.h b/mozilla/xpfe/appshell/src/nsXULWindow.h index fc9fa2e259a..04de3a08104 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.h +++ b/mozilla/xpfe/appshell/src/nsXULWindow.h @@ -148,7 +148,6 @@ protected: void SetContentScrollbarVisibility(PRBool aVisible); PRBool GetContentScrollbarVisibility(); void PersistentAttributesDirty(PRUint32 aDirtyFlags); - nsresult ApplyChromeFlags(); nsChromeTreeOwner* mChromeTreeOwner; nsContentTreeOwner* mContentTreeOwner;