Bug 590294, part 0: Add an nsDOMWindowUtils::GetPresShell() helper. r=smaug
authorChris Jones <jones.chris.g@gmail.com>
Fri, 03 Sep 2010 15:10:45 -0500
changeset 54075 38d1ce121661ef142e3092d70b2cced75a6fab2c
parent 54074 b3039d94296ea086716f9ddb1442c3fcb7d86ba2
child 54076 8129639ab610a1790662ad2616ca3b11ff282439
push idunknown
push userunknown
push dateunknown
reviewerssmaug
bugs590294
milestone2.0b6pre
Bug 590294, part 0: Add an nsDOMWindowUtils::GetPresShell() helper. r=smaug
dom/base/nsDOMWindowUtils.cpp
dom/base/nsDOMWindowUtils.h
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -106,16 +106,31 @@ nsDOMWindowUtils::nsDOMWindowUtils(nsGlo
 {
   NS_ASSERTION(mWindow->IsOuterWindow(), "How did that happen?");
 }
 
 nsDOMWindowUtils::~nsDOMWindowUtils()
 {
 }
 
+nsIPresShell*
+nsDOMWindowUtils::GetPresShell()
+{
+  if (!mWindow)
+    return nsnull;
+
+  nsIDocShell *docShell = mWindow->GetDocShell();
+  if (!docShell)
+    return nsnull;
+
+  nsCOMPtr<nsIPresShell> presShell;
+  docShell->GetPresShell(getter_AddRefs(presShell));
+  return presShell;
+}
+
 nsPresContext*
 nsDOMWindowUtils::GetPresContext()
 {
   if (!mWindow)
     return nsnull;
   nsIDocShell *docShell = mWindow->GetDocShell();
   if (!docShell)
     return nsnull;
@@ -184,45 +199,37 @@ nsDOMWindowUtils::GetDocumentMetadata(co
   
   aValue.Truncate();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::Redraw(PRUint32 aCount, PRUint32 *aDurationOut)
 {
-  nsresult rv;
-
   if (aCount == 0)
     aCount = 1;
 
-  nsCOMPtr<nsIDocShell> docShell = mWindow->GetDocShell();
-  if (docShell) {
-    nsCOMPtr<nsIPresShell> presShell;
-
-    rv = docShell->GetPresShell(getter_AddRefs(presShell));
-    if (NS_SUCCEEDED(rv) && presShell) {
-      nsIFrame *rootFrame = presShell->GetRootFrame();
+  if (nsIPresShell* presShell = GetPresShell()) {
+    nsIFrame *rootFrame = presShell->GetRootFrame();
 
-      if (rootFrame) {
-        nsRect r(nsPoint(0, 0), rootFrame->GetSize());
+    if (rootFrame) {
+      nsRect r(nsPoint(0, 0), rootFrame->GetSize());
 
-        PRIntervalTime iStart = PR_IntervalNow();
+      PRIntervalTime iStart = PR_IntervalNow();
 
-        for (PRUint32 i = 0; i < aCount; i++)
-          rootFrame->InvalidateWithFlags(r, nsIFrame::INVALIDATE_IMMEDIATE);
+      for (PRUint32 i = 0; i < aCount; i++)
+        rootFrame->InvalidateWithFlags(r, nsIFrame::INVALIDATE_IMMEDIATE);
 
 #if defined(MOZ_X11) && defined(MOZ_WIDGET_GTK2)
-        XSync(GDK_DISPLAY(), False);
+      XSync(GDK_DISPLAY(), False);
 #endif
 
-        *aDurationOut = PR_IntervalToMilliseconds(PR_IntervalNow() - iStart);
+      *aDurationOut = PR_IntervalToMilliseconds(PR_IntervalNow() - iStart);
 
-        return NS_OK;
-      }
+      return NS_OK;
     }
   }
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
                                  float aX,
--- a/dom/base/nsDOMWindowUtils.h
+++ b/dom/base/nsDOMWindowUtils.h
@@ -36,16 +36,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAutoPtr.h"
 #include "nsWeakReference.h"
 
 #include "nsIDOMWindowUtils.h"
 
 class nsGlobalWindow;
+class nsIPresShell;
 
 class nsDOMWindowUtils : public nsIDOMWindowUtils,
                          public nsSupportsWeakReference
 {
 public:
   nsDOMWindowUtils(nsGlobalWindow *aWindow);
   ~nsDOMWindowUtils();
   NS_DECL_ISUPPORTS
@@ -56,16 +57,17 @@ protected:
 
   // If aOffset is non-null, it gets filled in with the offset of the root
   // frame of our window to the nearest widget in the app units of our window.
   // Add this offset to any event offset we're given to make it relative to the
   // widget returned by GetWidget.
   nsIWidget* GetWidget(nsPoint* aOffset = nsnull);
   nsIWidget* GetWidgetForElement(nsIDOMElement* aElement);
 
+  nsIPresShell* GetPresShell();
   nsPresContext* GetPresContext();
 
   NS_IMETHOD SendMouseEventCommon(const nsAString& aType,
                                   float aX,
                                   float aY,
                                   PRInt32 aButton,
                                   PRInt32 aClickCount,
                                   PRInt32 aModifiers,