diff --git a/content/events/src/nsDOMUIEvent.cpp b/content/events/src/nsDOMUIEvent.cpp index f793e6d9a533..3502a86f9ec5 100644 --- a/content/events/src/nsDOMUIEvent.cpp +++ b/content/events/src/nsDOMUIEvent.cpp @@ -170,17 +170,17 @@ nsPoint nsDOMUIEvent::GetClientPoint() { // anyway... actually what we want is for all users of this and refPoint to agree // gracefully on what coordinate system to use, but that's a more involved change. - nsCOMPtr eventParent = eventWidget; + nsIWidget* eventParent = eventWidget; for (;;) { - nsCOMPtr t = dont_AddRef(eventParent->GetParent()); + nsIWidget* t = eventParent->GetParent(); if (!t) break; eventParent = t; } - nsCOMPtr docParent = docWidget; + nsIWidget* docParent = docWidget; for (;;) { - nsCOMPtr t = dont_AddRef(docParent->GetParent()); + nsIWidget* t = docParent->GetParent(); if (!t) break; docParent = t; @@ -198,7 +198,7 @@ nsPoint nsDOMUIEvent::GetClientPoint() { nsRect bounds; eventWidget->GetBounds(bounds); pt += bounds.TopLeft(); - eventWidget = dont_AddRef(eventWidget->GetParent()); + eventWidget = eventWidget->GetParent(); } if (eventWidget != docWidget) { @@ -219,7 +219,7 @@ nsPoint nsDOMUIEvent::GetClientPoint() { nsRect bounds; docWidget->GetBounds(bounds); pt -= bounds.TopLeft(); - docWidget = dont_AddRef(docWidget->GetParent()); + docWidget = docWidget->GetParent(); } } diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index b6539b39c25d..6ab480d116bd 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -479,7 +479,7 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, // "on top" window. { nsMouseEvent* mouseEvent = NS_STATIC_CAST(nsMouseEvent*, aEvent); - nsCOMPtr parentWidget = getter_AddRefs(mouseEvent->widget->GetParent()); + nsIWidget* parentWidget = mouseEvent->widget->GetParent(); nsPoint eventPoint; eventPoint = nsLayoutUtils::TranslateWidgetToView(aPresContext, mouseEvent->widget, diff --git a/toolkit/components/remote/nsGTKRemoteService.cpp b/toolkit/components/remote/nsGTKRemoteService.cpp index bdcfb0d03e26..635ddad724ba 100644 --- a/toolkit/components/remote/nsGTKRemoteService.cpp +++ b/toolkit/components/remote/nsGTKRemoteService.cpp @@ -172,10 +172,10 @@ nsGTKRemoteService::RegisterWindow(nsIDOMWindow* aWindow) // walk up the widget tree and find the toplevel window in the // hierarchy - nsCOMPtr tempWidget (dont_AddRef(mainWidget->GetParent())); + nsIWidget* tempWidget = mainWidget->GetParent(); while (tempWidget) { - tempWidget = dont_AddRef(tempWidget->GetParent()); + tempWidget = tempWidget->GetParent(); if (tempWidget) mainWidget = tempWidget; } diff --git a/view/src/nsViewManager.cpp b/view/src/nsViewManager.cpp index 289dd4882a53..55581b3f111c 100644 --- a/view/src/nsViewManager.cpp +++ b/view/src/nsViewManager.cpp @@ -1767,8 +1767,8 @@ void nsViewManager::ReparentChildWidgets(nsIView* aView, nsIWidget *aNewWidget) // the widget, otherwise there is nothing more // to do for the view and its descendants nsIWidget* widget = aView->GetWidget(); - nsCOMPtr parentWidget = getter_AddRefs(widget->GetParent()); - if (parentWidget.get() != aNewWidget) { + nsIWidget* parentWidget = widget->GetParent(); + if (parentWidget != aNewWidget) { #ifdef DEBUG nsresult rv = #endif diff --git a/widget/public/nsIMenu.h b/widget/public/nsIMenu.h index 25943ff82b4c..f30e1475f33d 100644 --- a/widget/public/nsIMenu.h +++ b/widget/public/nsIMenu.h @@ -73,7 +73,7 @@ class nsIMenu : public nsISupports { nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode ) = 0; /** - * Get the Menu's Parent + * Get the Menu's Parent. This addrefs. * */ NS_IMETHOD GetParent(nsISupports *&aParent) = 0; diff --git a/widget/public/nsIMenuBar.h b/widget/public/nsIMenuBar.h index aacc860f450b..3b39d0b332d4 100644 --- a/widget/public/nsIMenuBar.h +++ b/widget/public/nsIMenuBar.h @@ -64,7 +64,7 @@ class nsIMenuBar : public nsISupports { NS_IMETHOD Create(nsIWidget * aParent) = 0; /** - * Get the MenuBar's Parent + * Get the MenuBar's Parent. This addrefs. * */ NS_IMETHOD GetParent(nsIWidget *&aParent) = 0; diff --git a/widget/public/nsIWidget.h b/widget/public/nsIWidget.h index e76d5985c1cd..8d2c70c9e0df 100644 --- a/widget/public/nsIWidget.h +++ b/widget/public/nsIWidget.h @@ -96,10 +96,10 @@ typedef nsEventStatus (*PR_CALLBACK EVENT_CALLBACK)(nsGUIEvent *event); #define NS_NATIVE_SCREEN 9 #define NS_NATIVE_SHELLWIDGET 10 // Get the shell GtkWidget -// e7f09105-d21b-406a-89d5-e6b731b8f665 +// 6259bce0-f407-4c31-a09b-5d3c7b1c4260 #define NS_IWIDGET_IID \ -{ 0xe7f09105, 0xd21b, 0x406a, \ - { 0x89, 0xd5, 0xe6, 0xb7, 0x31, 0xb8, 0xf6, 0x65 } } +{ 0x6259bce0, 0xf407, 0x4c31, \ + { 0xa0, 0x9b, 0x5d, 0x3c, 0x7b, 0x1c, 0x42, 0x60 } } // Hide the native window systems real window type so as to avoid diff --git a/widget/src/beos/nsWindow.cpp b/widget/src/beos/nsWindow.cpp index 5614db72f811..4b9e86f033d1 100644 --- a/widget/src/beos/nsWindow.cpp +++ b/widget/src/beos/nsWindow.cpp @@ -798,7 +798,6 @@ nsIWidget* nsWindow::GetParent(void) if (mIsDestroying || mOnDestroyCalled) return nsnull; widget = (nsIWidget *)mParent; - NS_IF_ADDREF(widget); return widget; } diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index f6b4f798ff17..90d1b253d7c5 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -700,7 +700,6 @@ NS_IMETHODIMP nsChildView::Show(PRBool bState) nsIWidget* nsChildView::GetParent(void) { - NS_IF_ADDREF(mParentWidget); return mParentWidget; } diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index d7469ac998e7..d73c8cbc1c01 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -424,10 +424,7 @@ nsWidget::OnDestroySignal(GtkWidget* aGtkWidget) nsIWidget* nsWidget::GetParent(void) { - nsIWidget *ret; - ret = mParent; - NS_IF_ADDREF(ret); - return ret; + return mParent; } //------------------------------------------------------------------------- diff --git a/widget/src/gtk2/nsCommonWidget.cpp b/widget/src/gtk2/nsCommonWidget.cpp index fd625a41ee12..882735e53f52 100644 --- a/widget/src/gtk2/nsCommonWidget.cpp +++ b/widget/src/gtk2/nsCommonWidget.cpp @@ -63,10 +63,7 @@ nsCommonWidget::~nsCommonWidget() nsIWidget * nsCommonWidget::GetParent(void) { - nsIWidget *retval; - retval = mParent; - NS_IF_ADDREF(retval); - return retval; + return mParent; } void diff --git a/widget/src/mac/nsMacEventHandler.cpp b/widget/src/mac/nsMacEventHandler.cpp index d59d0352b9ff..780d35f587ee 100644 --- a/widget/src/mac/nsMacEventHandler.cpp +++ b/widget/src/mac/nsMacEventHandler.cpp @@ -257,7 +257,7 @@ void nsMacEventDispatchHandler::SetDeactivated(nsWindow *aDeactivatedWidget) if (mActiveWidget) { nsCOMPtr curWin = do_QueryInterface(NS_STATIC_CAST(nsIWidget*, mActiveWidget)); for (;;) { - nsCOMPtr parent = dont_AddRef(curWin->GetParent()); + nsIWidget* parent = curWin->GetParent(); if (!parent) break; curWin = parent; @@ -502,8 +502,8 @@ PRBool nsMacEventHandler::HandleMenuCommand( // the event is supposed to not have been handled) if (focusedWidget == gEventDispatchHandler.GetActive()) { - nsCOMPtr grandParent; - nsCOMPtr parent ( dont_AddRef(focusedWidget->GetParent()) ); + // Hold a ref across event dispatch + nsCOMPtr parent = focusedWidget->GetParent(); while (parent) { menuEvent.widget = parent; @@ -514,8 +514,7 @@ PRBool nsMacEventHandler::HandleMenuCommand( } else { - grandParent = dont_AddRef(parent->GetParent()); - parent = grandParent; + parent = parent->GetParent(); } } } diff --git a/widget/src/mac/nsNativeScrollbar.cpp b/widget/src/mac/nsNativeScrollbar.cpp index 0f7fb4c1f29f..7ce772b4b5c8 100644 --- a/widget/src/mac/nsNativeScrollbar.cpp +++ b/widget/src/mac/nsNativeScrollbar.cpp @@ -164,7 +164,7 @@ nsNativeScrollbar::DoScrollAction(ControlPartCode part) if (mOnDestroyCalled) return; - nsCOMPtr parent ( dont_AddRef(GetParent()) ); + nsCOMPtr parent ( GetParent() ); if (!parent) { // parent disappeared while scrolling was in progress. Handling Destroy diff --git a/widget/src/mac/nsWindow.cpp b/widget/src/mac/nsWindow.cpp index 1676405692dd..85edb55eac6d 100644 --- a/widget/src/mac/nsWindow.cpp +++ b/widget/src/mac/nsWindow.cpp @@ -432,7 +432,6 @@ NS_IMETHODIMP nsWindow::Destroy() nsIWidget* nsWindow::GetParent(void) { if (mIsTopWidgetWindow) return nsnull; - NS_IF_ADDREF(mParent); return mParent; } @@ -2055,7 +2054,7 @@ nsWindow::CalcOffset(PRInt32 &aX, PRInt32 &aY) { aX = aY = 0; - nsCOMPtr theParent = dont_AddRef(GetParent()); + nsIWidget* theParent = GetParent(); while (theParent) { nsRect theRect; @@ -2063,8 +2062,7 @@ nsWindow::CalcOffset(PRInt32 &aX, PRInt32 &aY) aX += theRect.x; aY += theRect.y; - nsIWidget* grandparent = theParent->GetParent(); - theParent = dont_AddRef(grandparent); + theParent = theParent->GetParent(); } } @@ -2072,7 +2070,7 @@ nsWindow::CalcOffset(PRInt32 &aX, PRInt32 &aY) PRBool nsWindow::ContainerHierarchyIsVisible() { - nsCOMPtr theParent = dont_AddRef(GetParent()); + nsIWidget* theParent = GetParent(); while (theParent) { @@ -2081,8 +2079,7 @@ nsWindow::ContainerHierarchyIsVisible() if (!visible) return PR_FALSE; - nsIWidget* grandparent = theParent->GetParent(); - theParent = dont_AddRef(grandparent); + theParent = theParent->GetParent(); } return PR_TRUE; @@ -2159,7 +2156,6 @@ NS_IMETHODIMP nsWindow::WidgetToScreen(const nsRect& aLocalRect, nsRect& aGlobal // // Convert the local rect to global, except for this level. theParent->WidgetToScreen(aLocalRect, aGlobalRect); - NS_RELEASE(theParent); // the offset from our parent is in the x/y of our bounding rect nsRect myBounds; @@ -2200,7 +2196,6 @@ NS_IMETHODIMP nsWindow::ScreenToWidget(const nsRect& aGlobalRect, nsRect& aLocal // // Convert the local rect to global, except for this level. theParent->WidgetToScreen(aGlobalRect, aLocalRect); - NS_RELEASE(theParent); // the offset from our parent is in the x/y of our bounding rect nsRect myBounds; @@ -2341,7 +2336,7 @@ NS_IMETHODIMP nsWindow::GetPluginClipRect(nsRect& outClipRect, nsPoint& outOrigi widgetClipRect.y = 0; // Gather up the absolute position of the widget, clip window, and visibilty - nsCOMPtr widget = getter_AddRefs(GetParent()); + nsIWidget* widget = GetParent(); while (widget) { if (isVisible) @@ -2358,7 +2353,7 @@ NS_IMETHODIMP nsWindow::GetPluginClipRect(nsRect& outClipRect, nsPoint& outOrigi widgetClipRect.IntersectRect(widgetClipRect, widgetRect); absX += wx; absY += wy; - widget = getter_AddRefs(widget->GetParent()); + widget = widget->GetParent(); if (!widget) { // Don't include the top-level windows offset @@ -2421,7 +2416,7 @@ NS_IMETHODIMP nsWindow::ResetInputState() { // currently, the nsMacEventHandler is owned by nsMacWindow, which is the top level window // we delegate this call to its parent - nsCOMPtr parent = getter_AddRefs(GetParent()); + nsIWidget* parent = GetParent(); NS_WARN_IF_FALSE(parent, "cannot get parent"); if (parent) { diff --git a/widget/src/os2/nsWindow.cpp b/widget/src/os2/nsWindow.cpp index e5e729de5f1a..06c3861589d0 100644 --- a/widget/src/os2/nsWindow.cpp +++ b/widget/src/os2/nsWindow.cpp @@ -1166,7 +1166,6 @@ nsIWidget* nsWindow::GetParent(void) nsWindow *widget = nsnull; if ((nsnull != mParent) && (!mParent->mIsDestroying)) { - NS_ADDREF(mParent); widget = mParent; } diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 3ed09937875b..ce17599bf04d 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -1740,6 +1740,7 @@ nsIWidget* nsWindow::GetParent(void) return GetParent(PR_TRUE); } +// XXX does anyone pass false for aStopOnFirstTopLevel? nsWindow* nsWindow::GetParent(PRBool aStopOnFirstTopLevel) { if (mIsTopWidgetWindow && aStopOnFirstTopLevel) { @@ -1764,8 +1765,6 @@ nsWindow* nsWindow::GetParent(PRBool aStopOnFirstTopLevel) // do NOT return it if (widget->mIsDestroying) { widget = nsnull; - } else { - NS_ADDREF(widget); } } } @@ -2085,8 +2084,6 @@ NS_METHOD nsWindow::Move(PRInt32 aX, PRInt32 aY) VERIFY(::SetWindowPos(mWnd, NULL, aX, aY, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE)); } - - NS_IF_RELEASE(par); } return NS_OK; } @@ -2132,8 +2129,6 @@ NS_METHOD nsWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint) else { VERIFY(::SetWindowPos(mWnd, NULL, 0, 0, aWidth, GetHeight(aHeight), flags)); } - - NS_IF_RELEASE(par); } if (aRepaint) @@ -2185,8 +2180,6 @@ NS_METHOD nsWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeig else { VERIFY(::SetWindowPos(mWnd, NULL, aX, aY, aWidth, GetHeight(aHeight), flags)); } - - NS_IF_RELEASE(par); } if (aRepaint) @@ -7521,9 +7514,7 @@ nsWindow::ResolveIMECaretPos(nsWindow* aClient, nsRect& aResult) { // RootView coordinates -> Screen coordinates - nsWindow* topWindow = GetTopLevelWindow(); - topWindow->WidgetToScreen(aEventResult, aResult); - NS_RELEASE(topWindow); + GetTopLevelWindow()->WidgetToScreen(aEventResult, aResult); // if aClient is nsnull, returns screen coordinates if (!aClient) return; @@ -8325,17 +8316,14 @@ STDMETHODIMP_(LRESULT) nsWindow::LresultFromObject(REFIID riid, WPARAM wParam, L nsWindow* nsWindow::GetTopLevelWindow() { nsWindow* curWindow = this; - NS_ADDREF(curWindow); while (PR_TRUE) { nsWindow* parentWindow = curWindow->GetParent(PR_TRUE); if (parentWindow) - { - NS_RELEASE(curWindow); curWindow = parentWindow; - } else + else return curWindow; } } @@ -8448,27 +8436,21 @@ void nsWindow::ResizeTranslucentWindow(PRInt32 aNewWidth, PRInt32 aNewHeight, PR NS_IMETHODIMP nsWindow::GetWindowTranslucency(PRBool& aTranslucent) { - nsWindow* topWindow = GetTopLevelWindow(); - aTranslucent = topWindow->GetWindowTranslucencyInner(); - NS_RELEASE(topWindow); + aTranslucent = GetTopLevelWindow()->GetWindowTranslucencyInner(); return NS_OK; } NS_IMETHODIMP nsWindow::SetWindowTranslucency(PRBool aTranslucent) { - nsWindow* topWindow = GetTopLevelWindow(); - nsresult rv = topWindow->SetWindowTranslucencyInner(aTranslucent); - NS_RELEASE(topWindow); + nsresult rv = GetTopLevelWindow()->SetWindowTranslucencyInner(aTranslucent); return rv; } NS_IMETHODIMP nsWindow::UpdateTranslucentWindowAlpha(const nsRect& aRect, PRUint8* aAlphas) { - nsWindow* topWindow = GetTopLevelWindow(); - topWindow->UpdateTranslucentWindowAlphaInner(aRect, aAlphas); - NS_RELEASE(topWindow); + GetTopLevelWindow()->UpdateTranslucentWindowAlphaInner(aRect, aAlphas); return NS_OK; } diff --git a/widget/src/xlib/nsWidget.cpp b/widget/src/xlib/nsWidget.cpp index 8e1a3586a9b4..139dc3dd1f6b 100644 --- a/widget/src/xlib/nsWidget.cpp +++ b/widget/src/xlib/nsWidget.cpp @@ -756,9 +756,6 @@ NS_IMETHODIMP nsWidget::PreCreateWidget(nsWidgetInitData *aInitData) nsIWidget *nsWidget::GetParent(void) { - if (nsnull != mParentWidget) { - NS_ADDREF(mParentWidget); - } return mParentWidget; } diff --git a/widget/src/xpwidgets/nsBaseWidget.cpp b/widget/src/xpwidgets/nsBaseWidget.cpp index d8e37b55d6ee..86551f9b3aae 100644 --- a/widget/src/xpwidgets/nsBaseWidget.cpp +++ b/widget/src/xpwidgets/nsBaseWidget.cpp @@ -244,7 +244,6 @@ NS_METHOD nsBaseWidget::Destroy() nsIWidget *parent = GetParent(); if (parent) { parent->RemoveChild(this); - NS_RELEASE(parent); } // disconnect listeners. NS_IF_RELEASE(mMouseListener); @@ -306,9 +305,7 @@ void nsBaseWidget::AddChild(nsIWidget* aChild) //------------------------------------------------------------------------- void nsBaseWidget::RemoveChild(nsIWidget* aChild) { - NS_ASSERTION(nsCOMPtr(dont_AddRef(aChild->GetParent())) == - NS_STATIC_CAST(nsIWidget*, this), - "Not one of our kids!"); + NS_ASSERTION(aChild->GetParent() == this, "Not one of our kids!"); if (mLastChild == aChild) { mLastChild = mLastChild->GetPrevSibling(); @@ -340,6 +337,10 @@ void nsBaseWidget::RemoveChild(nsIWidget* aChild) //------------------------------------------------------------------------- NS_IMETHODIMP nsBaseWidget::SetZIndex(PRInt32 aZIndex) { + // Hold a ref to ourselves just in case, since we're going to remove + // from our parent. + nsCOMPtr kungFuDeathGrip(this); + mZIndex = aZIndex; // reorder this child in its parent's list. @@ -374,8 +375,6 @@ NS_IMETHODIMP nsBaseWidget::SetZIndex(PRInt32 aZIndex) if (!sib) { parent->AddChild(this); } - - NS_RELEASE(parent); } return NS_OK; } diff --git a/xpfe/appshell/src/nsXULWindow.cpp b/xpfe/appshell/src/nsXULWindow.cpp index 098cdc51521c..c7a9fefdb761 100644 --- a/xpfe/appshell/src/nsXULWindow.cpp +++ b/xpfe/appshell/src/nsXULWindow.cpp @@ -707,7 +707,7 @@ NS_IMETHODIMP nsXULWindow::GetParentWidget(nsIWidget** aParentWidget) NS_ENSURE_ARG_POINTER(aParentWidget); NS_ENSURE_STATE(mWindow); - *aParentWidget = mWindow->GetParent(); + NS_IF_ADDREF(*aParentWidget = mWindow->GetParent()); return NS_OK; }