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
Родитель 23f3493642
Коммит 8fdb11594c
2 изменённых файлов: 11 добавлений и 4 удалений

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

@ -528,9 +528,12 @@ nsChildView::nsChildView() : nsBaseWidget()
nsChildView::~nsChildView() nsChildView::~nsChildView()
{ {
// notify the children that we're gone // Notify the children that we're gone. childView->ResetParent() can change
for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) { // 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); nsChildView* childView = static_cast<nsChildView*>(kid);
kid = kid->GetPrevSibling();
childView->ResetParent(); childView->ResetParent();
} }

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

@ -161,16 +161,20 @@ nsCocoaWindow::~nsCocoaWindow()
// Notify the children that we're gone. Popup windows (e.g. tooltips) can // 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 // have nsChildView children. 'kid' is an nsChildView object if and only if
// its 'type' is 'eWindowType_child'. // its 'type' is 'eWindowType_child'. childView->ResetParent() can change
for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) { // 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; nsWindowType kidType;
kid->GetWindowType(kidType); kid->GetWindowType(kidType);
if (kidType == eWindowType_child) { if (kidType == eWindowType_child) {
nsChildView* childView = static_cast<nsChildView*>(kid); nsChildView* childView = static_cast<nsChildView*>(kid);
kid = kid->GetPrevSibling();
childView->ResetParent(); childView->ResetParent();
} else { } else {
nsCocoaWindow* childWindow = static_cast<nsCocoaWindow*>(kid); nsCocoaWindow* childWindow = static_cast<nsCocoaWindow*>(kid);
childWindow->mParent = nsnull; childWindow->mParent = nsnull;
kid = kid->GetPrevSibling();
} }
} }