Bug 582057, part d: Simplify nsView::LoadWidget and return early if it fails. r=roc
authorChris Jones <jones.chris.g@gmail.com>
Fri, 20 Aug 2010 14:29:01 -0500
changeset 51045 418247b1dc8a311fabb4b07ae9ae0d6b2e4741ca
parent 51044 1007fbdaad19091f39d2886bd48147bab018a11c
child 51046 17ccf212ce682029152a3b386c0368c7bccbf4cb
push id15218
push usercjones@mozilla.com
push dateFri, 20 Aug 2010 19:30:45 +0000
treeherdermozilla-central@95a39e236cc4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs582057
milestone2.0b5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 582057, part d: Simplify nsView::LoadWidget and return early if it fails. r=roc
view/src/nsView.cpp
--- a/view/src/nsView.cpp
+++ b/view/src/nsView.cpp
@@ -683,71 +683,74 @@ nsresult nsView::CreateWidget(const nsII
     NS_ERROR("We already have a window for this view? BAD");
     ViewWrapper* wrapper = GetWrapperFor(mWindow);
     NS_IF_RELEASE(wrapper);
     mWindow->SetClientData(nsnull);
     mWindow->Destroy();
     NS_RELEASE(mWindow);
   }
 
+  nsresult rv = LoadWidget(aWindowIID);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+
   PRBool initDataPassedIn = PR_TRUE;
   nsWidgetInitData initData;
   if (!aWidgetInitData) {
     // No initData, we're a child window
     initDataPassedIn = PR_FALSE;
     initData.mWindowType = eWindowType_child;
     initData.clipChildren = PR_TRUE;
     initData.clipSiblings = PR_TRUE;
     aWidgetInitData = &initData;
   }
   aWidgetInitData->mContentType = aContentType;
 
   nsIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
 
-  if (NS_OK == LoadWidget(aWindowIID))
-  {
-    nsCOMPtr<nsIDeviceContext> dx;
-    mViewManager->GetDeviceContext(*getter_AddRefs(dx));
+  nsCOMPtr<nsIDeviceContext> dx;
+  mViewManager->GetDeviceContext(*getter_AddRefs(dx));
 
-    if (aNative && aWidgetInitData->mWindowType != eWindowType_popup)
-      mWindow->Create(nsnull, aNative, trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
-    else
-    {
-      if (!initDataPassedIn && GetParent() && 
-          GetParent()->GetViewManager() != mViewManager)
-        initData.mListenForResizes = PR_TRUE;
-      if (aParentWidget) {
-        NS_ASSERTION(aWidgetInitData->mWindowType == eWindowType_popup,
-                     "popup widget type expected");
-        mWindow->Create(aParentWidget, nsnull, trect,
+  if (aNative && aWidgetInitData->mWindowType != eWindowType_popup) {
+    mWindow->Create(nsnull, aNative, trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
+  }
+  else {
+    if (!initDataPassedIn && GetParent() && 
+        GetParent()->GetViewManager() != mViewManager)
+      initData.mListenForResizes = PR_TRUE;
+    if (aParentWidget) {
+      NS_ASSERTION(aWidgetInitData->mWindowType == eWindowType_popup,
+                   "popup widget type expected");
+      mWindow->Create(aParentWidget, nsnull, trect,
+                      ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
+    }
+    else {
+      nsIWidget* parentWidget = GetParent() ? GetParent()->GetNearestWidget(nsnull)
+                                            : nsnull;
+      if (aWidgetInitData->mWindowType == eWindowType_popup) {
+        // Without a parent, we can't make a popup.  This can happen
+        // when printing
+        if (!parentWidget)
+          return NS_ERROR_FAILURE;
+        mWindow->Create(nsnull, parentWidget->GetNativeData(NS_NATIVE_WIDGET), trect,
+                        ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
+      } else {
+        mWindow->Create(parentWidget, nsnull, trect,
                         ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
       }
-      else {
-        nsIWidget* parentWidget = GetParent() ? GetParent()->GetNearestWidget(nsnull)
-                                              : nsnull;
-        if (aWidgetInitData->mWindowType == eWindowType_popup) {
-          // Without a parent, we can't make a popup.  This can happen
-          // when printing
-          if (!parentWidget)
-            return NS_ERROR_FAILURE;
-          mWindow->Create(nsnull, parentWidget->GetNativeData(NS_NATIVE_WIDGET), trect,
-                          ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
-        } else {
-          mWindow->Create(parentWidget, nsnull, trect,
-                          ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
-        }
-      }
     }
-    if (aEnableDragDrop) {
-      mWindow->EnableDragDrop(PR_TRUE);
-    }
+  }
+
+  if (aEnableDragDrop) {
+    mWindow->EnableDragDrop(PR_TRUE);
+  }
       
-    // propagate the z-index to the widget.
-    UpdateNativeWidgetZIndexes(this, FindNonAutoZIndex(this));
-  }
+  // propagate the z-index to the widget.
+  UpdateNativeWidgetZIndexes(this, FindNonAutoZIndex(this));
 
   //make sure visibility state is accurate
 
   if (aResetVisibility) {
     SetVisibility(GetVisibility());
   }
 
   return NS_OK;
@@ -820,30 +823,26 @@ void nsView::SetZIndex(PRBool aAuto, PRI
   }
 }
 
 //
 // internal window creation functions
 //
 nsresult nsView::LoadWidget(const nsCID &aClassIID)
 {
-  ViewWrapper* wrapper = new ViewWrapper(this);
-  if (!wrapper)
-    return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(wrapper); // Will be released in ~nsView
+  NS_ABORT_IF_FALSE(!mWindow, "Already have a widget?");
 
   nsresult rv = CallCreateInstance(aClassIID, &mWindow);
-
-  if (NS_SUCCEEDED(rv)) {
-    // Set the widget's client data
-    mWindow->SetClientData(wrapper);
-  } else {
-    delete wrapper;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
+  ViewWrapper* wrapper = new ViewWrapper(this);
+  NS_ADDREF(wrapper); // Will be released in ~nsView
+  mWindow->SetClientData(wrapper);
   return rv;
 }
 
 EVENT_CALLBACK nsIView::AttachWidgetEventHandler(nsIWidget* aWidget)
 {
 #ifdef DEBUG
   void* data = nsnull;
   aWidget->GetClientData(data);