Bug 508180 - Consolidate four nsXULWindow::Load*FromXUL methods. r=Neil

This commit is contained in:
Markus Stange 2009-08-06 08:52:08 +12:00
parent 369cb6add1
commit 23cf4a7d99
2 changed files with 28 additions and 112 deletions

View File

@ -968,10 +968,7 @@ void nsXULWindow::OnChromeLoaded()
if (NS_SUCCEEDED(rv)) {
mChromeLoaded = PR_TRUE;
ApplyChromeFlags();
LoadChromeHidingFromXUL();
LoadWindowClassFromXUL();
LoadIconFromXUL();
SyncAttributesToWidget();
LoadSizeFromXUL();
if (mIntrinsicallySized) {
// (if LoadSizeFromXUL set the size, mIntrinsicallySized will be false)
@ -994,9 +991,6 @@ void nsXULWindow::OnChromeLoaded()
if (positionSet)
positionSet = LoadPositionFromXUL();
LoadMiscPersistentAttributesFromXUL();
LoadToolbarButtonPresenceFromXUL();
//LoadContentAreas();
if (mCenterAfterLoad && !positionSet)
Center(parentWindow, parentWindow ? PR_FALSE : PR_TRUE, PR_FALSE);
@ -1007,25 +1001,6 @@ void nsXULWindow::OnChromeLoaded()
mPersistentAttributesMask |= PAD_POSITION | PAD_SIZE | PAD_MISC;
}
nsresult nsXULWindow::LoadChromeHidingFromXUL()
{
NS_ENSURE_STATE(mWindow);
// Get <window> element.
nsCOMPtr<nsIDOMElement> windowElement;
GetWindowDOMElement(getter_AddRefs(windowElement));
NS_ENSURE_TRUE(windowElement, NS_ERROR_FAILURE);
nsAutoString attr;
nsresult rv = windowElement->GetAttribute(NS_LITERAL_STRING("hidechrome"), attr);
if (NS_SUCCEEDED(rv) && attr.LowerCaseEqualsLiteral("true")) {
mWindow->HideWindowChrome(PR_TRUE);
}
return NS_OK;
}
PRBool nsXULWindow::LoadPositionFromXUL()
{
nsresult rv;
@ -1359,95 +1334,39 @@ void nsXULWindow::StaggerPosition(PRInt32 &aRequestedX, PRInt32 &aRequestedY,
} while (keepTrying);
}
NS_IMETHODIMP nsXULWindow::LoadWindowClassFromXUL()
{
nsCOMPtr<nsIDOMElement> docShellElement;
GetWindowDOMElement(getter_AddRefs(docShellElement));
NS_ENSURE_TRUE(docShellElement, NS_ERROR_FAILURE);
nsAutoString windowType;
docShellElement->GetAttribute(NS_LITERAL_STRING("windowtype"),
windowType);
if (!windowType.IsEmpty()) {
mWindow->SetWindowClass(windowType);
}
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::LoadIconFromXUL()
{
NS_ENSURE_STATE(mWindow);
// Get <window> element.
nsCOMPtr<nsIDOMElement> windowElement;
GetWindowDOMElement(getter_AddRefs(windowElement));
NS_ENSURE_TRUE(windowElement, NS_ERROR_FAILURE);
// XXX The following code is being #if 0'd out since it
// basically does nothing until bug 70974 is fixed.
// After bug 70974 is fixed, we will also need to implement
// computed style for that property before this will
// be of any use. And even then, it will *still*
// do nothing on platforms which don't implement
// nsWindow::SetIcon(). See bug 76211 for that.
// Also see bug 57576 and its dependency tree.
#if 0
// Get document in which this <window> is contained.
nsCOMPtr<nsIDOMDocument> document;
windowElement->GetOwnerDocument(getter_AddRefs(document));
NS_ENSURE_TRUE(document, NS_ERROR_FAILURE);
// Get document view.
nsCOMPtr<nsIDOMDocumentView> docView(do_QueryInterface(document));
NS_ENSURE_TRUE(docView, NS_ERROR_FAILURE);
// Get default/abstract view.
nsCOMPtr<nsIDOMAbstractView> abstractView;
docView->GetDefaultView(getter_AddRefs(abstractView));
NS_ENSURE_TRUE(abstractView, NS_ERROR_FAILURE);
// Get "view CSS."
nsCOMPtr<nsIDOMViewCSS> viewCSS(do_QueryInterface(abstractView));
NS_ENSURE_TRUE(viewCSS, NS_ERROR_FAILURE);
// Next, get CSS style declaration.
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
viewCSS->GetComputedStyle(windowElement, EmptyString(),
getter_AddRefs(cssDecl));
NS_ENSURE_TRUE(cssDecl, NS_ERROR_FAILURE);
// Whew. Now get "list-style-image" property value.
nsAutoString windowIcon;
windowIcon.AssignLiteral("-moz-window-icon");
nsAutoString icon;
cssDecl->GetPropertyValue(windowIcon, icon);
#endif
nsAutoString id;
windowElement->GetAttribute(NS_LITERAL_STRING("id"), id);
if (id.IsEmpty()) {
id.AssignLiteral("default");
}
mWindow->SetIcon(id);
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::LoadToolbarButtonPresenceFromXUL()
void nsXULWindow::SyncAttributesToWidget()
{
nsCOMPtr<nsIDOMElement> windowElement;
GetWindowDOMElement(getter_AddRefs(windowElement));
NS_ENSURE_TRUE(windowElement, NS_ERROR_FAILURE);
if (!windowElement)
return;
nsAutoString attr;
nsresult rv = windowElement->GetAttribute(NS_LITERAL_STRING("toggletoolbar"), attr);
// "hidechrome" attribute
nsresult rv = windowElement->GetAttribute(NS_LITERAL_STRING("hidechrome"), attr);
if (NS_SUCCEEDED(rv) && attr.EqualsLiteral("true")) {
mWindow->HideWindowChrome(PR_TRUE);
}
// "windowtype" attribute
rv = windowElement->GetAttribute(NS_LITERAL_STRING("windowtype"), attr);
if (NS_SUCCEEDED(rv) && !attr.IsEmpty()) {
mWindow->SetWindowClass(attr);
}
// "id" attribute for icon
rv = windowElement->GetAttribute(NS_LITERAL_STRING("id"), attr);
if (NS_FAILED(rv) || attr.IsEmpty()) {
attr.AssignLiteral("default");
}
mWindow->SetIcon(attr);
// "toggletoolbar" attribute
rv = windowElement->GetAttribute(NS_LITERAL_STRING("toggletoolbar"), attr);
if (NS_SUCCEEDED(rv)) {
mWindow->SetShowsToolbarButton(attr.LowerCaseEqualsLiteral("true"));
}
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()

View File

@ -119,10 +119,7 @@ protected:
PRBool LoadPositionFromXUL();
PRBool LoadSizeFromXUL();
PRBool LoadMiscPersistentAttributesFromXUL();
nsresult LoadChromeHidingFromXUL();
NS_IMETHOD LoadWindowClassFromXUL();
NS_IMETHOD LoadIconFromXUL();
NS_IMETHOD LoadToolbarButtonPresenceFromXUL();
void SyncAttributesToWidget();
NS_IMETHOD SavePersistentAttributes();
NS_IMETHOD GetWindowDOMWindow(nsIDOMWindowInternal** aDOMWindow);