From 759efb046b77a1b81c5c0991ece578ae439688de Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 2 Oct 2012 10:24:10 +0200 Subject: [PATCH] Bug 795403 - Cleanup nsXULWindow::GetWindowDOMElement; r=bz --- xpfe/appshell/src/nsChromeTreeOwner.cpp | 6 +-- xpfe/appshell/src/nsContentTreeOwner.cpp | 19 +++----- xpfe/appshell/src/nsXULWindow.cpp | 58 ++++++++++-------------- xpfe/appshell/src/nsXULWindow.h | 2 +- 4 files changed, 33 insertions(+), 52 deletions(-) diff --git a/xpfe/appshell/src/nsChromeTreeOwner.cpp b/xpfe/appshell/src/nsChromeTreeOwner.cpp index eacc9cd6a697..5ce3745fc15f 100644 --- a/xpfe/appshell/src/nsChromeTreeOwner.cpp +++ b/xpfe/appshell/src/nsChromeTreeOwner.cpp @@ -258,8 +258,7 @@ nsChromeTreeOwner::SetPersistence(bool aPersistPosition, bool aPersistSizeMode) { NS_ENSURE_STATE(mXULWindow); - nsCOMPtr docShellElement; - mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement)); + nsCOMPtr docShellElement = mXULWindow->GetWindowDOMElement(); if (!docShellElement) return NS_ERROR_FAILURE; @@ -296,8 +295,7 @@ nsChromeTreeOwner::GetPersistence(bool* aPersistPosition, bool* aPersistSizeMode) { NS_ENSURE_STATE(mXULWindow); - nsCOMPtr docShellElement; - mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement)); + nsCOMPtr docShellElement = mXULWindow->GetWindowDOMElement(); if (!docShellElement) return NS_ERROR_FAILURE; diff --git a/xpfe/appshell/src/nsContentTreeOwner.cpp b/xpfe/appshell/src/nsContentTreeOwner.cpp index 2b88d65a3a11..afa47122fd3e 100644 --- a/xpfe/appshell/src/nsContentTreeOwner.cpp +++ b/xpfe/appshell/src/nsContentTreeOwner.cpp @@ -312,9 +312,8 @@ nsContentTreeOwner::SetPersistence(bool aPersistPosition, bool aPersistSizeMode) { NS_ENSURE_STATE(mXULWindow); - nsCOMPtr docShellElement; - mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement)); - if(!docShellElement) + nsCOMPtr docShellElement = mXULWindow->GetWindowDOMElement(); + if (!docShellElement) return NS_ERROR_FAILURE; nsAutoString persistString; @@ -381,9 +380,8 @@ nsContentTreeOwner::GetPersistence(bool* aPersistPosition, bool* aPersistSizeMode) { NS_ENSURE_STATE(mXULWindow); - nsCOMPtr docShellElement; - mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement)); - if(!docShellElement) + nsCOMPtr docShellElement = mXULWindow->GetWindowDOMElement(); + if (!docShellElement) return NS_ERROR_FAILURE; nsAutoString persistString; @@ -725,8 +723,7 @@ NS_IMETHODIMP nsContentTreeOwner::SetTitle(const PRUnichar* aTitle) // if there is no location bar we modify the title to display at least // the scheme and host (if any) as an anti-spoofing measure. // - nsCOMPtr docShellElement; - mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement)); + nsCOMPtr docShellElement = mXULWindow->GetWindowDOMElement(); if (docShellElement) { nsAutoString chromeString; @@ -956,11 +953,9 @@ private: void nsContentTreeOwner::XULWindow(nsXULWindow* aXULWindow) { mXULWindow = aXULWindow; - if(mXULWindow && mPrimary) - { + if (mXULWindow && mPrimary) { // Get the window title modifiers - nsCOMPtr docShellElement; - mXULWindow->GetWindowDOMElement(getter_AddRefs(docShellElement)); + nsCOMPtr docShellElement = mXULWindow->GetWindowDOMElement(); nsAutoString contentTitleSetting; diff --git a/xpfe/appshell/src/nsXULWindow.cpp b/xpfe/appshell/src/nsXULWindow.cpp index 1542a7a563a3..567d0d33568c 100644 --- a/xpfe/appshell/src/nsXULWindow.cpp +++ b/xpfe/appshell/src/nsXULWindow.cpp @@ -54,6 +54,7 @@ #include "prenv.h" #include "mozilla/Preferences.h" +#include "mozilla/dom/Element.h" using namespace mozilla; @@ -1003,11 +1004,8 @@ bool nsXULWindow::LoadPositionFromXUL() if (mIsHiddenWindow) return false; - nsCOMPtr windowElement; - GetWindowDOMElement(getter_AddRefs(windowElement)); - NS_ASSERTION(windowElement, "no xul:window"); - if (!windowElement) - return false; + nsCOMPtr windowElement = GetWindowDOMElement(); + NS_ENSURE_TRUE(windowElement, false); int32_t currX = 0; int32_t currY = 0; @@ -1072,11 +1070,8 @@ bool nsXULWindow::LoadSizeFromXUL() if (mIsHiddenWindow) return false; - nsCOMPtr windowElement; - GetWindowDOMElement(getter_AddRefs(windowElement)); - NS_ASSERTION(windowElement, "no xul:window"); - if (!windowElement) - return false; + nsCOMPtr windowElement = GetWindowDOMElement(); + NS_ENSURE_TRUE(windowElement, false); int32_t currWidth = 0; int32_t currHeight = 0; @@ -1153,11 +1148,8 @@ bool nsXULWindow::LoadMiscPersistentAttributesFromXUL() if (mIsHiddenWindow) return false; - nsCOMPtr windowElement; - GetWindowDOMElement(getter_AddRefs(windowElement)); - NS_ASSERTION(windowElement, "no xul:window"); - if (!windowElement) - return false; + nsCOMPtr windowElement = GetWindowDOMElement(); + NS_ENSURE_TRUE(windowElement, false); nsAutoString stateString; @@ -1243,8 +1235,10 @@ void nsXULWindow::StaggerPosition(int32_t &aRequestedX, int32_t &aRequestedY, if (!wm) return; - nsCOMPtr windowElement; - GetWindowDOMElement(getter_AddRefs(windowElement)); + nsCOMPtr windowElement = GetWindowDOMElement(); + if (!windowElement) + return; + nsCOMPtr ourXULWindow(this); nsAutoString windowType; @@ -1344,8 +1338,7 @@ void nsXULWindow::StaggerPosition(int32_t &aRequestedX, int32_t &aRequestedY, void nsXULWindow::SyncAttributesToWidget() { - nsCOMPtr windowElement; - GetWindowDOMElement(getter_AddRefs(windowElement)); + nsCOMPtr windowElement = GetWindowDOMElement(); if (!windowElement) return; @@ -1410,8 +1403,7 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes() if (!mDocShell) return NS_ERROR_FAILURE; - nsCOMPtr docShellElement; - GetWindowDOMElement(getter_AddRefs(docShellElement)); + nsCOMPtr docShellElement = GetWindowDOMElement(); if (!docShellElement) return NS_ERROR_FAILURE; @@ -1537,25 +1529,22 @@ NS_IMETHODIMP nsXULWindow::GetWindowDOMWindow(nsIDOMWindow** aDOMWindow) return NS_OK; } -NS_IMETHODIMP nsXULWindow::GetWindowDOMElement(nsIDOMElement** aDOMElement) +nsIDOMElement* +nsXULWindow::GetWindowDOMElement() const { - NS_ENSURE_STATE(mDocShell); - NS_ENSURE_ARG_POINTER(aDOMElement); - - *aDOMElement = nullptr; + NS_ENSURE_TRUE(mDocShell, nullptr); nsCOMPtr cv; - mDocShell->GetContentViewer(getter_AddRefs(cv)); - NS_ENSURE_TRUE(cv, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(cv, nullptr); - nsCOMPtr domdoc(do_QueryInterface(cv->GetDocument())); - NS_ENSURE_TRUE(domdoc, NS_ERROR_FAILURE); + const nsIDocument* document = cv->GetDocument(); + NS_ENSURE_TRUE(document, nullptr); - domdoc->GetDocumentElement(aDOMElement); - NS_ENSURE_TRUE(*aDOMElement, NS_ERROR_FAILURE); + dom::Element* element = document->GetRootElement(); + NS_ENSURE_TRUE(element, nullptr); - return NS_OK; + return static_cast(element->AsDOMNode()); } nsresult nsXULWindow::ContentShellAdded(nsIDocShellTreeItem* aContentShell, @@ -1988,8 +1977,7 @@ void nsXULWindow::PersistentAttributesDirty(uint32_t aDirtyFlags) NS_IMETHODIMP nsXULWindow::ApplyChromeFlags() { - nsCOMPtr window; - GetWindowDOMElement(getter_AddRefs(window)); + nsCOMPtr window = GetWindowDOMElement(); NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); if (mChromeLoaded) { diff --git a/xpfe/appshell/src/nsXULWindow.h b/xpfe/appshell/src/nsXULWindow.h index 2be75d28bbfa..b202e45a7277 100644 --- a/xpfe/appshell/src/nsXULWindow.h +++ b/xpfe/appshell/src/nsXULWindow.h @@ -91,7 +91,7 @@ protected: NS_IMETHOD SavePersistentAttributes(); NS_IMETHOD GetWindowDOMWindow(nsIDOMWindow** aDOMWindow); - NS_IMETHOD GetWindowDOMElement(nsIDOMElement** aDOMElement); + nsIDOMElement* GetWindowDOMElement() const; // See nsIDocShellTreeOwner for docs on next two methods NS_HIDDEN_(nsresult) ContentShellAdded(nsIDocShellTreeItem* aContentShell,