Backed out changeset ab1cbc8a9d51, bug 90268. r=josh
authorJosh Aas <joshmoz@gmail.com>
Tue, 30 Aug 2011 02:13:01 -0400
changeset 76167 a6e7760f2f3682ddd8310bc75af718dcc2b20486
parent 76016 ab1cbc8a9d51a6fe320b62819c2a5bbce95c5cee
child 76168 e6591ea9b27b4f3a652a11645aa63ccfae67603e
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersjosh
bugs90268
milestone9.0a1
backs outab1cbc8a9d51a6fe320b62819c2a5bbce95c5cee
Backed out changeset ab1cbc8a9d51, bug 90268. r=josh
widget/public/nsIWidget.h
widget/src/cocoa/nsChildView.mm
widget/src/gtk2/nsWindow.cpp
widget/src/xpwidgets/nsBaseWidget.cpp
widget/src/xpwidgets/nsBaseWidget.h
--- a/widget/public/nsIWidget.h
+++ b/widget/public/nsIWidget.h
@@ -113,18 +113,18 @@ typedef nsEventStatus (* EVENT_CALLBACK)
 #endif
 #ifdef XP_WIN
 #define NS_NATIVE_TSF_THREAD_MGR       100
 #define NS_NATIVE_TSF_CATEGORY_MGR     101
 #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
 #endif
 
 #define NS_IWIDGET_IID \
-  { 0xEAAF1019, 0x0CD8, 0x4DD8, \
-    { 0xBE, 0xB9, 0x8D, 0x8D, 0xEB, 0x52, 0xFC, 0xF6 } }
+  { 0xf43254ce, 0xd315, 0x458b, \
+    { 0xba, 0x72, 0xa8, 0xdf, 0x21, 0xcf, 0xa7, 0x2a } }
 
 /*
  * Window shadow styles
  * Also used for the -moz-window-shadow CSS property
  */
 
 #define NS_STYLE_WINDOW_SHADOW_NONE             0
 #define NS_STYLE_WINDOW_SHADOW_DEFAULT          1
@@ -359,24 +359,16 @@ class nsIWidget : public nsISupports {
                 EVENT_CALLBACK   aHandleEventFunction,
                 nsDeviceContext *aContext,
                 nsIAppShell      *aAppShell = nsnull,
                 nsIToolkit       *aToolkit = nsnull,
                 nsWidgetInitData *aInitData = nsnull,
                 PRBool           aForceUseIWidgetParent = PR_FALSE) = 0;
 
     /**
-     * Set the event callback for a widget. If a device context is not
-     * provided then the existing device context will remain, it will
-     * not be nulled out.
-     */
-    NS_IMETHOD SetEventCallback(EVENT_CALLBACK aEventFunction,
-                                nsDeviceContext *aContext) = 0;
-
-    /**
      * Attach to a top level widget. 
      *
      * In cases where a top level chrome widget is being used as a content
      * container, attach a secondary event callback and update the device
      * context. The primary event callback will continue to be called, so the
      * owning base window will continue to function.
      *
      * aViewEventFunction Event callback that will receive mirrored
@@ -408,17 +400,17 @@ class nsIWidget : public nsISupports {
      */
 
     NS_IMETHOD Destroy(void) = 0;
 
 
     /**
      * Reparent a widget
      *
-     * Change the widget's parent. Null parents are allowed.
+     * Change the widgets parent
      *
      * @param     aNewParent   new parent 
      */
     NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
 
     NS_IMETHOD RegisterTouchWindow() = 0;
     NS_IMETHOD UnregisterTouchWindow() = 0;
 
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -699,40 +699,36 @@ NS_IMETHODIMP nsChildView::Show(PRBool a
 }
 
 // Change the parent of this widget
 NS_IMETHODIMP
 nsChildView::SetParent(nsIWidget* aNewParent)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
+  NS_ENSURE_ARG(aNewParent);
+
   if (mOnDestroyCalled)
     return NS_OK;
 
+  // make sure we stay alive
   nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
   
-  if (mParentWidget) {
+  // remove us from our existing parent
+  if (mParentWidget)
     mParentWidget->RemoveChild(this);
-  }
-
-  if (aNewParent) {
-    ReparentNativeWidget(aNewParent);
-  } else {
-    [mView removeFromSuperview];
-    mParentView = nil;
-  }
-
-  mParentWidget = aNewParent;
-
-  if (mParentWidget) {
-    mParentWidget->AddChild(this);
-  }
-
+
+  nsresult rv = ReparentNativeWidget(aNewParent);
+  if (NS_SUCCEEDED(rv))
+    mParentWidget = aNewParent;
+
+  // add us to the new parent
+  mParentWidget->AddChild(this);
   return NS_OK;
-
+  
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 NS_IMETHODIMP
 nsChildView::ReparentNativeWidget(nsIWidget* aNewParent)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
@@ -742,17 +738,17 @@ nsChildView::ReparentNativeWidget(nsIWid
     return NS_OK;
 
   NSView<mozView>* newParentView =
    (NSView*)aNewParent->GetNativeData(NS_NATIVE_WIDGET); 
   NS_ENSURE_TRUE(newParentView, NS_ERROR_FAILURE);
 
   // we hold a ref to mView, so this is safe
   [mView removeFromSuperview];
-  mParentView = newParentView;
+  mParentView   = newParentView;
   [mParentView addSubview:mView];
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 void nsChildView::ResetParent()
 {
--- a/widget/src/gtk2/nsWindow.cpp
+++ b/widget/src/gtk2/nsWindow.cpp
@@ -877,27 +877,25 @@ nsWindow::GetDPI()
     }
     return float(DisplayHeight(dpy, defaultScreen)/heightInches);
 #endif
 }
 
 NS_IMETHODIMP
 nsWindow::SetParent(nsIWidget *aNewParent)
 {
-    if (mContainer || !mGdkWindow) {
-        NS_NOTREACHED("nsWindow::SetParent called illegally");
+    if (mContainer || !mGdkWindow || !mParent) {
+        NS_NOTREACHED("nsWindow::SetParent - reparenting a non-child window");
         return NS_ERROR_NOT_IMPLEMENTED;
     }
 
     NS_ASSERTION(!mTransientParent, "child widget with transient parent");
 
     nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
-    if (mParent) {
-        mParent->RemoveChild(this);
-    }
+    mParent->RemoveChild(this);
 
     mParent = aNewParent;
 
     GtkWidget* oldContainer = GetMozContainerWidget();
     if (!oldContainer) {
         // The GdkWindows have been destroyed so there is nothing else to
         // reparent.
         NS_ABORT_IF_FALSE(GDK_WINDOW_OBJECT(mGdkWindow)->destroyed,
@@ -984,20 +982,16 @@ nsWindow::ReparentNativeWidgetInternal(n
                           GDK_WINDOW_OBJECT(aNewParentWindow)->destroyed,
                           "live GdkWindow with no widget");
         Destroy();
     } else {
         if (aNewContainer != aOldContainer) {
             NS_ABORT_IF_FALSE(!GDK_WINDOW_OBJECT(aNewParentWindow)->destroyed,
                               "destroyed GdkWindow with widget");
             SetWidgetForHierarchy(mGdkWindow, aOldContainer, aNewContainer);
-
-            if (aOldContainer == gInvisibleContainer) {
-              CheckDestroyInvisibleContainer();
-            }
         }
 
         if (!mIsTopLevel) {
             gdk_window_reparent(mGdkWindow, aNewParentWindow, mBounds.x,
                                 mBounds.y);
         }
     }
 
--- a/widget/src/xpwidgets/nsBaseWidget.cpp
+++ b/widget/src/xpwidgets/nsBaseWidget.cpp
@@ -284,31 +284,16 @@ nsBaseWidget::CreateChild(const nsIntRec
                                   aContext, aAppShell, aToolkit,
                                   aInitData))) {
     return widget.forget();
   }
 
   return nsnull;
 }
 
-NS_IMETHODIMP
-nsBaseWidget::SetEventCallback(EVENT_CALLBACK aEventFunction,
-                               nsDeviceContext *aContext)
-{
-  mEventCallback = aEventFunction;
-
-  if (aContext) {
-    NS_IF_RELEASE(mContext);
-    mContext = aContext;
-    NS_ADDREF(mContext);
-  }
-
-  return NS_OK;
-}
-
 // Attach a view to our widget which we'll send events to. 
 NS_IMETHODIMP
 nsBaseWidget::AttachViewToTopLevel(EVENT_CALLBACK aViewEventFunction,
                                    nsDeviceContext *aContext)
 {
   NS_ASSERTION((mWindowType == eWindowType_toplevel ||
                 mWindowType == eWindowType_dialog ||
                 mWindowType == eWindowType_invisible ||
--- a/widget/src/xpwidgets/nsBaseWidget.h
+++ b/widget/src/xpwidgets/nsBaseWidget.h
@@ -165,17 +165,16 @@ public:
   virtual already_AddRefed<nsIWidget>
   CreateChild(const nsIntRect  &aRect,
               EVENT_CALLBACK   aHandleEventFunction,
               nsDeviceContext *aContext,
               nsIAppShell      *aAppShell = nsnull,
               nsIToolkit       *aToolkit = nsnull,
               nsWidgetInitData *aInitData = nsnull,
               PRBool           aForceUseIWidgetParent = PR_FALSE);
-  NS_IMETHOD              SetEventCallback(EVENT_CALLBACK aEventFunction, nsDeviceContext *aContext);
   NS_IMETHOD              AttachViewToTopLevel(EVENT_CALLBACK aViewEventFunction, nsDeviceContext *aContext);
   virtual ViewWrapper*    GetAttachedViewPtr();
   NS_IMETHOD              SetAttachedViewPtr(ViewWrapper* aViewWrapper);
   NS_IMETHOD              ResizeClient(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint);
   NS_IMETHOD              GetNonClientMargins(nsIntMargin &margins);
   NS_IMETHOD              SetNonClientMargins(nsIntMargin &margins);
   NS_IMETHOD              RegisterTouchWindow();
   NS_IMETHOD              UnregisterTouchWindow();