Bug 1156110 - Make nsView::mWindow an nsCOMPtr; r=roc

This commit is contained in:
Ehsan Akhgari 2015-04-19 14:59:51 -04:00
parent d871ed2e61
commit d7e0f82f13
2 changed files with 12 additions and 13 deletions

View File

@ -134,7 +134,7 @@ void nsView::DestroyWidget()
NS_DispatchToMainThread(widgetDestroyer);
}
NS_RELEASE(mWindow);
mWindow = nullptr;
}
}
@ -233,7 +233,7 @@ nsIntRect nsView::CalcWidgetBounds(nsWindowType aType)
// cocoa rounds widget coordinates to the nearest global "display pixel"
// integer value. So we avoid fractional display pixel values by rounding
// to the nearest value that won't yield a fractional display pixel.
nsIWidget* widget = parentWidget ? parentWidget : mWindow;
nsIWidget* widget = parentWidget ? parentWidget : mWindow.get();
uint32_t round;
if (aType == eWindowType_popup && widget &&
((round = widget->RoundsWidgetCoordinatesTo()) > 1)) {
@ -575,7 +575,7 @@ nsresult nsView::CreateWidget(nsWidgetInitData *aWidgetInitData,
// XXX: using aForceUseIWidgetParent=true to preserve previous
// semantics. It's not clear that it's actually needed.
mWindow = parentWidget->CreateChild(trect, aWidgetInitData, true).take();
mWindow = parentWidget->CreateChild(trect, aWidgetInitData, true);
if (!mWindow) {
return NS_ERROR_FAILURE;
}
@ -601,8 +601,7 @@ nsresult nsView::CreateWidgetForParent(nsIWidget* aParentWidget,
nsIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
mWindow =
aParentWidget->CreateChild(trect, aWidgetInitData).take();
mWindow = aParentWidget->CreateChild(trect, aWidgetInitData);
if (!mWindow) {
return NS_ERROR_FAILURE;
}
@ -631,7 +630,7 @@ nsresult nsView::CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData,
if (aParentWidget) {
// XXX: using aForceUseIWidgetParent=true to preserve previous
// semantics. It's not clear that it's actually needed.
mWindow = aParentWidget->CreateChild(trect, aWidgetInitData, true).take();
mWindow = aParentWidget->CreateChild(trect, aWidgetInitData, true);
}
else {
nsIWidget* nearestParent = GetParent() ? GetParent()->GetNearestWidget(nullptr)
@ -642,7 +641,7 @@ nsresult nsView::CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData,
return NS_ERROR_FAILURE;
}
mWindow = nearestParent->CreateChild(trect, aWidgetInitData).take();
mWindow = nearestParent->CreateChild(trect, aWidgetInitData);
}
if (!mWindow) {
return NS_ERROR_FAILURE;
@ -695,7 +694,6 @@ nsresult nsView::AttachToTopLevelWidget(nsIWidget* aWidget)
return rv;
mWindow = aWidget;
NS_ADDREF(mWindow);
mWindow->SetAttachedWidgetListener(this);
mWindow->EnableDragDrop(true);
@ -714,7 +712,7 @@ nsresult nsView::DetachFromTopLevelWidget()
NS_PRECONDITION(mWindow, "null mWindow for DetachFromTopLevelWidget!");
mWindow->SetAttachedWidgetListener(nullptr);
NS_RELEASE(mWindow);
mWindow = nullptr;
mWidgetIsTopLevel = false;
@ -739,7 +737,7 @@ void nsView::AssertNoWindow()
NS_ERROR("We already have a window for this view? BAD");
mWindow->SetWidgetListener(nullptr);
mWindow->Destroy();
NS_RELEASE(mWindow);
mWindow = nullptr;
}
}
@ -775,8 +773,8 @@ void nsView::List(FILE* out, int32_t aIndent) const
nsRect windowBounds = rect.ToAppUnits(p2a);
mWindow->GetBounds(rect);
nsRect nonclientBounds = rect.ToAppUnits(p2a);
nsrefcnt widgetRefCnt = mWindow->AddRef() - 1;
mWindow->Release();
nsrefcnt widgetRefCnt = mWindow.get()->AddRef() - 1;
mWindow.get()->Release();
int32_t Z = mWindow->GetZIndex();
fprintf(out, "(widget=%p[%" PRIuPTR "] z=%d pos={%d,%d,%d,%d}) ",
(void*)mWindow, widgetRefCnt, Z,

View File

@ -11,6 +11,7 @@
#include "nsPoint.h"
#include "nsRegion.h"
#include "nsCRT.h"
#include "nsCOMPtr.h"
#include "nsWidgetInitData.h" // for nsWindowType
#include "nsIWidgetListener.h"
#include "mozilla/EventForwards.h"
@ -446,7 +447,7 @@ private:
nsViewManager *mViewManager;
nsView *mParent;
nsIWidget *mWindow;
nsCOMPtr<nsIWidget> mWindow;
nsView *mNextSibling;
nsView *mFirstChild;
nsIFrame *mFrame;