Bug 508180 - Consolidate four nsXULWindow::Load*FromXUL methods. r=Neil
authorMarkus Stange <mstange@themasta.com>
Thu, 06 Aug 2009 08:52:08 +1200
changeset 31162 35d52ec7e8842b73c72d260e2b6c6fcbbf250d32
parent 31161 33a666c42ee3bb4a9b1594a0e7ae89be893bde7f
child 31163 8e1a59451aaafcf554141d7ed984ca2c8107e104
push id8401
push usermstange@themasta.com
push dateWed, 05 Aug 2009 21:09:49 +0000
treeherdermozilla-central@35d52ec7e884 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs508180
milestone1.9.2a1pre
Bug 508180 - Consolidate four nsXULWindow::Load*FromXUL methods. r=Neil
xpfe/appshell/src/nsXULWindow.cpp
xpfe/appshell/src/nsXULWindow.h
--- a/xpfe/appshell/src/nsXULWindow.cpp
+++ b/xpfe/appshell/src/nsXULWindow.cpp
@@ -963,20 +963,17 @@ NS_IMETHODIMP nsXULWindow::EnsureAuthPro
  
 void nsXULWindow::OnChromeLoaded()
 {
   nsresult rv = EnsureContentTreeOwner();
 
   if (NS_SUCCEEDED(rv)) {
     mChromeLoaded = PR_TRUE;
     ApplyChromeFlags();
-
-    LoadChromeHidingFromXUL();
-    LoadWindowClassFromXUL();
-    LoadIconFromXUL();
+    SyncAttributesToWidget();
     LoadSizeFromXUL();
     if (mIntrinsicallySized) {
       // (if LoadSizeFromXUL set the size, mIntrinsicallySized will be false)
       nsCOMPtr<nsIContentViewer> cv;
       mDocShell->GetContentViewer(getter_AddRefs(cv));
       nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
       if (markupViewer)
         markupViewer->SizeToContent();
@@ -989,48 +986,26 @@ void nsXULWindow::OnChromeLoaded()
     // (however, we think the benefits of intelligent dependent window placement
     // trump that override.)
     if (!parentWindow)
       positionSet = PR_FALSE;
 #endif
     if (positionSet)
       positionSet = LoadPositionFromXUL();
     LoadMiscPersistentAttributesFromXUL();
-    LoadToolbarButtonPresenceFromXUL();
-
-    //LoadContentAreas();
 
     if (mCenterAfterLoad && !positionSet)
       Center(parentWindow, parentWindow ? PR_FALSE : PR_TRUE, PR_FALSE);
 
     if (mShowAfterLoad)
       SetVisibility(PR_TRUE);
   }
   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;
   PRBool   gotPosition = PR_FALSE;
   
   // if we're the hidden window, don't try to validate our size/position. We're
   // special.
   if (mIsHiddenWindow)
@@ -1354,105 +1329,49 @@ void nsXULWindow::StaggerPosition(PRInt3
           keepTrying = bouncedX < 2 || bouncedY == 0;
           break;
         }
       }
     } while(1);
   } 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()
 {
   // can happen when the persistence timer fires at an inopportune time
   // during window shutdown
   if (!mDocShell)
     return NS_ERROR_FAILURE;
--- a/xpfe/appshell/src/nsXULWindow.h
+++ b/xpfe/appshell/src/nsXULWindow.h
@@ -114,20 +114,17 @@ protected:
    NS_IMETHOD EnsureAuthPrompter();
    
    void OnChromeLoaded();
    void StaggerPosition(PRInt32 &aRequestedX, PRInt32 &aRequestedY,
                         PRInt32 aSpecWidth, PRInt32 aSpecHeight);
    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);
    NS_IMETHOD GetWindowDOMElement(nsIDOMElement** aDOMElement);
 
    // See nsIDocShellTreeOwner for docs on next two methods
    NS_HIDDEN_(nsresult) ContentShellAdded(nsIDocShellTreeItem* aContentShell,
                                           PRBool aPrimary, PRBool aTargetable,