Safely iterate parents' children in widget destructors on OS X. b=503196 r=josh

This commit is contained in:
Steven Michaud 2009-07-20 10:02:31 -05:00
Родитель efbee7cd1c
Коммит 040ee0abe0
2 изменённых файлов: 11 добавлений и 4 удалений

Просмотреть файл

@ -528,9 +528,12 @@ nsChildView::nsChildView() : nsBaseWidget()
nsChildView::~nsChildView()
{
// notify the children that we're gone
for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) {
// Notify the children that we're gone. childView->ResetParent() can change
// our list of children while it's being iterated, so the way we iterate the
// list must allow for this.
for (nsIWidget* kid = mLastChild; kid;) {
nsChildView* childView = static_cast<nsChildView*>(kid);
kid = kid->GetPrevSibling();
childView->ResetParent();
}

Просмотреть файл

@ -161,16 +161,20 @@ nsCocoaWindow::~nsCocoaWindow()
// Notify the children that we're gone. Popup windows (e.g. tooltips) can
// have nsChildView children. 'kid' is an nsChildView object if and only if
// its 'type' is 'eWindowType_child'.
for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) {
// its 'type' is 'eWindowType_child'. childView->ResetParent() can change
// our list of children while it's being iterated, so the way we iterate the
// list must allow for this.
for (nsIWidget* kid = mLastChild; kid;) {
nsWindowType kidType;
kid->GetWindowType(kidType);
if (kidType == eWindowType_child) {
nsChildView* childView = static_cast<nsChildView*>(kid);
kid = kid->GetPrevSibling();
childView->ResetParent();
} else {
nsCocoaWindow* childWindow = static_cast<nsCocoaWindow*>(kid);
childWindow->mParent = nsnull;
kid = kid->GetPrevSibling();
}
}