Bug 1299335 (part 3) - Streamline nsIWidget::SetParent. r=mstange.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 16 Dec 2016 10:54:11 +1100
changeset 326544 fe8165b5dbe97e858c7df9b044429c1dbb71bfa8
parent 326543 a75e4a674e23d927b9b3bcebe389b66958ebb82b
child 326545 19292462b6f53ac0d690a5303a97d14b3cab4c2d
push id31106
push userkwierso@gmail.com
push dateTue, 20 Dec 2016 19:42:03 +0000
treeherdermozilla-central@7083c0d30e75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1299335
milestone53.0a1
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 1299335 (part 3) - Streamline nsIWidget::SetParent. r=mstange. This patch removes its return value, because none of the call sites check it except for one non-vital assertion.
view/nsViewManager.cpp
widget/PluginWidgetProxy.cpp
widget/PluginWidgetProxy.h
widget/android/nsWindow.cpp
widget/android/nsWindow.h
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
widget/nsBaseWidget.cpp
widget/nsBaseWidget.h
widget/nsIWidget.h
widget/windows/nsWindow.cpp
widget/windows/nsWindow.h
--- a/view/nsViewManager.cpp
+++ b/view/nsViewManager.cpp
@@ -831,21 +831,17 @@ void nsViewManager::ReparentChildWidgets
     // same as the new parent. If not then reparent
     // the widget, otherwise there is nothing more
     // to do for the view and its descendants
     nsIWidget* widget = aView->GetWidget();
     nsIWidget* parentWidget = widget->GetParent();
     if (parentWidget) {
       // Child widget
       if (parentWidget != aNewWidget) {
-#ifdef DEBUG
-        nsresult rv =
-#endif
-          widget->SetParent(aNewWidget);
-        NS_ASSERTION(NS_SUCCEEDED(rv), "SetParent failed!");
+        widget->SetParent(aNewWidget);
       }
     } else {
       // Toplevel widget (popup, dialog, etc)
       widget->ReparentNativeWidget(aNewWidget);
     }
     return;
   }
 
--- a/widget/PluginWidgetProxy.cpp
+++ b/widget/PluginWidgetProxy.cpp
@@ -81,29 +81,28 @@ PluginWidgetProxy::Create(nsIWidget* aPa
   if (instance) {
     Unused << NS_WARN_IF(NS_FAILED(instance->SetScrollCaptureId(scrollCaptureId)));
   }
 #endif
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
+void
 PluginWidgetProxy::SetParent(nsIWidget* aNewParent)
 {
   nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
   nsIWidget* parent = GetParent();
   if (parent) {
     parent->RemoveChild(this);
   }
   if (aNewParent) {
     aNewParent->AddChild(this);
   }
   mParent = aNewParent;
-  return NS_OK;
 }
 
 nsIWidget*
 PluginWidgetProxy::GetParent(void)
 {
   return mParent.get();
 }
 
--- a/widget/PluginWidgetProxy.h
+++ b/widget/PluginWidgetProxy.h
@@ -37,17 +37,17 @@ public:
   using PuppetWidget::Create; // for Create signature not overridden here
   virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
                                        nsNativeWidget aNativeParent,
                                        const LayoutDeviceIntRect& aRect,
                                        nsWidgetInitData* aInitData = nullptr)
                                        override;
   virtual void Destroy() override;
   NS_IMETHOD SetFocus(bool aRaise = false) override;
-  NS_IMETHOD SetParent(nsIWidget* aNewParent) override;
+  virtual void SetParent(nsIWidget* aNewParent) override;
 
   virtual nsIWidget* GetParent(void) override;
   virtual void* GetNativeData(uint32_t aDataType) override;
 #if defined(XP_WIN)
   void SetNativeData(uint32_t aDataType, uintptr_t aVal) override;
 #endif
   virtual nsTransparencyMode GetTransparencyMode() override
   { return eTransparencyOpaque; }
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -1627,37 +1627,35 @@ nsWindow::RedrawAll()
 {
     if (mAttachedWidgetListener) {
         mAttachedWidgetListener->RequestRepaint();
     } else if (mWidgetListener) {
         mWidgetListener->RequestRepaint();
     }
 }
 
-NS_IMETHODIMP
+void
 nsWindow::SetParent(nsIWidget *aNewParent)
 {
     if ((nsIWidget*)mParent == aNewParent)
-        return NS_OK;
+        return;
 
     // If we had a parent before, remove ourselves from its list of
     // children.
     if (mParent)
         mParent->mChildren.RemoveElement(this);
 
     mParent = (nsWindow*)aNewParent;
 
     if (mParent)
         mParent->mChildren.AppendElement(this);
 
     // if we are now in the toplevel window's hierarchy, schedule a redraw
     if (FindTopLevel() == nsWindow::TopWindow())
         RedrawAll();
-
-    return NS_OK;
 }
 
 nsIWidget*
 nsWindow::GetParent()
 {
     return mParent;
 }
 
--- a/widget/android/nsWindow.h
+++ b/widget/android/nsWindow.h
@@ -153,17 +153,17 @@ public:
 
     using nsBaseWidget::Create; // for Create signature not overridden here
     virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
                                          nsNativeWidget aNativeParent,
                                          const LayoutDeviceIntRect& aRect,
                                          nsWidgetInitData* aInitData) override;
     virtual void Destroy() override;
     NS_IMETHOD ConfigureChildren(const nsTArray<nsIWidget::Configuration>&) override;
-    NS_IMETHOD SetParent(nsIWidget* aNewParent) override;
+    virtual void SetParent(nsIWidget* aNewParent) override;
     virtual nsIWidget *GetParent(void) override;
     virtual float GetDPI() override;
     virtual double GetDefaultScaleInternal() override;
     NS_IMETHOD Show(bool aState) override;
     virtual bool IsVisible() const override;
     virtual void ConstrainPosition(bool aAllowSlop,
                                    int32_t *aX,
                                    int32_t *aY) override;
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -304,17 +304,17 @@ public:
                                        nsWidgetInitData* aInitData = nullptr)
                                        override;
 
   virtual void            Destroy() override;
 
   NS_IMETHOD              Show(bool aState) override;
   virtual bool            IsVisible() const override;
 
-  NS_IMETHOD              SetParent(nsIWidget* aNewParent) override;
+  virtual void            SetParent(nsIWidget* aNewParent) override;
   virtual nsIWidget*      GetParent(void) override;
   virtual float           GetDPI() override;
 
   NS_IMETHOD              Move(double aX, double aY) override;
   NS_IMETHOD              Resize(double aWidth, double aHeight, bool aRepaint) override;
   NS_IMETHOD              Resize(double aX, double aY,
                                  double aWidth, double aHeight, bool aRepaint) override;
 
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -734,23 +734,23 @@ NS_IMETHODIMP nsChildView::Show(bool aSt
     mVisible = aState;
   }
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 // Change the parent of this widget
-NS_IMETHODIMP
+void
 nsChildView::SetParent(nsIWidget* aNewParent)
 {
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if (mOnDestroyCalled)
-    return NS_OK;
+    return;
 
   nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
 
   if (mParentWidget) {
     mParentWidget->RemoveChild(this);
   }
 
   if (aNewParent) {
@@ -761,19 +761,17 @@ nsChildView::SetParent(nsIWidget* aNewPa
   }
 
   mParentWidget = aNewParent;
 
   if (mParentWidget) {
     mParentWidget->AddChild(this);
   }
 
-  return NS_OK;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
+  NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 void
 nsChildView::ReparentNativeWidget(nsIWidget* aNewParent)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   NS_PRECONDITION(aNewParent, "");
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -826,54 +826,53 @@ nsWindow::GetDPI()
 }
 
 double
 nsWindow::GetDefaultScaleInternal()
 {
     return GdkScaleFactor() * gfxPlatformGtk::GetDPIScale();
 }
 
-NS_IMETHODIMP
+void
 nsWindow::SetParent(nsIWidget *aNewParent)
 {
     if (mContainer || !mGdkWindow) {
         NS_NOTREACHED("nsWindow::SetParent called illegally");
-        return NS_ERROR_NOT_IMPLEMENTED;
+        return;
     }
 
     nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
     if (mParent) {
         mParent->RemoveChild(this);
     }
 
     mParent = aNewParent;
 
     GtkWidget* oldContainer = GetMozContainerWidget();
     if (!oldContainer) {
         // The GdkWindows have been destroyed so there is nothing else to
         // reparent.
         MOZ_ASSERT(gdk_window_is_destroyed(mGdkWindow),
                    "live GdkWindow with no widget");
-        return NS_OK;
+        return;
     }
 
     if (aNewParent) {
         aNewParent->AddChild(this);
         ReparentNativeWidget(aNewParent);
     } else {
         // aNewParent is nullptr, but reparent to a hidden window to avoid
         // destroying the GdkWindow and its descendants.
         // An invisible container widget is needed to hold descendant
         // GtkWidgets.
         GtkWidget* newContainer = EnsureInvisibleContainer();
         GdkWindow* newParentWindow = gtk_widget_get_window(newContainer);
         ReparentNativeWidgetInternal(aNewParent, newContainer, newParentWindow,
                                      oldContainer);
     }
-    return NS_OK;
 }
 
 bool
 nsWindow::WidgetTypeSupportsAcceleration()
 {
   return !IsSmallPopup();
 }
 
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -102,17 +102,17 @@ public:
     virtual nsIWidget *GetParent() override;
     virtual float      GetDPI() override;
     virtual double     GetDefaultScaleInternal() override;
     // Under Gtk, we manage windows using device pixels so no scaling is needed:
     mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() final
     {
         return mozilla::DesktopToLayoutDeviceScale(1.0);
     }
-    virtual nsresult   SetParent(nsIWidget* aNewParent) override;
+    virtual void       SetParent(nsIWidget* aNewParent) override;
     virtual void       SetModal(bool aModal) override;
     virtual bool       IsVisible() const override;
     virtual void       ConstrainPosition(bool aAllowSlop,
                                          int32_t *aX,
                                          int32_t *aY) override;
     virtual void       SetSizeConstraints(const SizeConstraints& aConstraints) override;
     NS_IMETHOD         Move(double aX,
                             double aY) override;
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -533,28 +533,16 @@ void nsBaseWidget::Destroy()
   }
 
 #if defined(XP_WIN)
   // Allow our scroll capture container to be cleaned up, if we have one.
   mScrollCaptureContainer = nullptr;
 #endif
 }
 
-
-//-------------------------------------------------------------------------
-//
-// Set this nsBaseWidget's parent
-//
-//-------------------------------------------------------------------------
-NS_IMETHODIMP nsBaseWidget::SetParent(nsIWidget* aNewParent)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-
 //-------------------------------------------------------------------------
 //
 // Get this nsBaseWidget parent
 //
 //-------------------------------------------------------------------------
 nsIWidget* nsBaseWidget::GetParent(void)
 {
   return nullptr;
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -144,17 +144,17 @@ public:
 
   // nsIWidget interface
   virtual void            CaptureMouse(bool aCapture) override {}
   virtual void            CaptureRollupEvents(nsIRollupListener* aListener,
                                               bool aDoCapture) override {}
   virtual nsIWidgetListener*  GetWidgetListener() override;
   virtual void            SetWidgetListener(nsIWidgetListener* alistener) override;
   virtual void            Destroy() override;
-  NS_IMETHOD              SetParent(nsIWidget* aNewParent) override;
+  virtual void            SetParent(nsIWidget* aNewParent) override {};
   virtual nsIWidget*      GetParent(void) override;
   virtual nsIWidget*      GetTopLevelWidget() override;
   virtual nsIWidget*      GetSheetWindowParent(void) override;
   virtual float           GetDPI() override;
   virtual void            AddChild(nsIWidget* aChild) override;
   virtual void            RemoveChild(nsIWidget* aChild) override;
 
   void                    SetZIndex(int32_t aZIndex) override;
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -518,17 +518,17 @@ class nsIWidget : public nsISupports
 
     /**
      * Reparent a widget
      *
      * Change the widget's parent. Null parents are allowed.
      *
      * @param     aNewParent   new parent
      */
-    NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
+    virtual void SetParent(nsIWidget* aNewParent) = 0;
 
     /**
      * Return the parent Widget of this Widget or nullptr if this is a
      * top level window
      *
      * @return the parent widget or nullptr if it does not have a parent
      *
      */
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -1140,35 +1140,35 @@ void nsWindow::SubclassWindow(BOOL bStat
  * SECTION: nsIWidget::SetParent, nsIWidget::GetParent
  *
  * Set or clear the parent widgets using window properties, and
  * handles calculating native parent handles.
  *
  **************************************************************/
 
 // Get and set parent widgets
-NS_IMETHODIMP nsWindow::SetParent(nsIWidget *aNewParent)
+void
+nsWindow::SetParent(nsIWidget *aNewParent)
 {
   mParent = aNewParent;
 
   nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
   nsIWidget* parent = GetParent();
   if (parent) {
     parent->RemoveChild(this);
   }
   if (aNewParent) {
     ReparentNativeWidget(aNewParent);
     aNewParent->AddChild(this);
-    return NS_OK;
+    return;
   }
   if (mWnd) {
     // If we have no parent, SetParent should return the desktop.
     VERIFY(::SetParent(mWnd, nullptr));
   }
-  return NS_OK;
 }
 
 void
 nsWindow::ReparentNativeWidget(nsIWidget* aNewParent)
 {
   NS_PRECONDITION(aNewParent, "");
 
   mParent = aNewParent;
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -99,17 +99,17 @@ public:
   // nsIWidget interface
   using nsWindowBase::Create; // for Create signature not overridden here
   virtual MOZ_MUST_USE nsresult Create(nsIWidget* aParent,
                                        nsNativeWidget aNativeParent,
                                        const LayoutDeviceIntRect& aRect,
                                        nsWidgetInitData* aInitData = nullptr)
                                        override;
   virtual void            Destroy() override;
-  NS_IMETHOD              SetParent(nsIWidget *aNewParent) override;
+  virtual void            SetParent(nsIWidget *aNewParent) override;
   virtual nsIWidget*      GetParent(void) override;
   virtual float           GetDPI() override;
   double                  GetDefaultScaleInternal() final;
   int32_t                 LogToPhys(double aValue) final;
   mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() final
   {
     if (mozilla::widget::WinUtils::IsPerMonitorDPIAware()) {
       return mozilla::DesktopToLayoutDeviceScale(1.0);