From 95bcc0e95f0bbb75b9439412213c61ed1093b63a Mon Sep 17 00:00:00 2001 From: "mats.palmgren@bredband.net" Date: Sat, 6 Oct 2007 06:53:05 -0700 Subject: [PATCH] Call RemoveMappingsForFrameSubtree() before destroying an "internal" popup frame. b=372685 r+sr=bzbarsky blocking1.9=dsicore --- layout/xul/Makefile.in | 4 ++ layout/xul/base/src/nsMenuPopupFrame.cpp | 11 ----- layout/xul/base/src/nsPopupSetFrame.cpp | 41 +++++++++---------- layout/xul/base/src/nsPopupSetFrame.h | 12 ++---- layout/xul/test/Makefile.in | 51 ++++++++++++++++++++++++ layout/xul/test/test_bug372685.xul | 50 +++++++++++++++++++++++ 6 files changed, 130 insertions(+), 39 deletions(-) create mode 100644 layout/xul/test/Makefile.in create mode 100644 layout/xul/test/test_bug372685.xul diff --git a/layout/xul/Makefile.in b/layout/xul/Makefile.in index 5a6df44d759..36f7cfee7d5 100644 --- a/layout/xul/Makefile.in +++ b/layout/xul/Makefile.in @@ -44,5 +44,9 @@ include $(DEPTH)/config/autoconf.mk DIRS = base +ifdef MOZ_MOCHITEST +DIRS += test +endif + include $(topsrcdir)/config/rules.mk diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index 9f239b97d7e..78309b07e7a 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -86,16 +86,6 @@ const PRInt32 kMaxZ = 0x7fffffff; //XXX: Shouldn't there be a define somewhere for MaxInt for PRInt32 -static nsPopupSetFrame* -GetPopupSetFrame(nsPresContext* aPresContext) -{ - nsIRootBox* rootBox = nsIRootBox::GetRootBox(aPresContext->PresShell()); - if (!rootBox) - return nsnull; - - return rootBox->GetPopupSetFrame(); -} - // NS_NewMenuPopupFrame // // Wrapper for creating a new menu popup container @@ -630,7 +620,6 @@ nsMenuPopupFrame::GetRootViewForPopup(nsIFrame* aStartFrame) { nsIView* view = aStartFrame->GetClosestView(); NS_ASSERTION(view, "frame must have a closest view!"); - nsIView* rootView = nsnull; while (view) { // Walk up the view hierarchy looking for a view whose widget has a // window type of eWindowType_popup - in other words a popup window diff --git a/layout/xul/base/src/nsPopupSetFrame.cpp b/layout/xul/base/src/nsPopupSetFrame.cpp index f32bcaf3086..a9694afceee 100644 --- a/layout/xul/base/src/nsPopupSetFrame.cpp +++ b/layout/xul/base/src/nsPopupSetFrame.cpp @@ -23,6 +23,7 @@ * Original Author: David W. Hyatt (hyatt@netscape.com) * Pierre Phaneuf * Dean Tessman + * Mats Palmgren * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -38,37 +39,21 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsGkAtoms.h" #include "nsPopupSetFrame.h" -#include "nsIMenuParent.h" -#include "nsMenuFrame.h" -#include "nsBoxFrame.h" +#include "nsGkAtoms.h" +#include "nsCOMPtr.h" #include "nsIContent.h" -#include "prtypes.h" -#include "nsIAtom.h" #include "nsPresContext.h" #include "nsStyleContext.h" #include "nsCSSRendering.h" #include "nsINameSpaceManager.h" -#include "nsMenuPopupFrame.h" -#include "nsMenuBarFrame.h" -#include "nsIView.h" -#include "nsIWidget.h" #include "nsIDocument.h" -#include "nsIDOMNSDocument.h" -#include "nsIDOMDocument.h" -#include "nsIDOMXULDocument.h" -#include "nsIDOMElement.h" -#include "nsISupportsArray.h" -#include "nsIDOMText.h" #include "nsBoxLayoutState.h" #include "nsIScrollableFrame.h" #include "nsCSSFrameConstructor.h" #include "nsGUIEvent.h" #include "nsIRootBox.h" -#define NS_MENU_POPUP_LIST_INDEX 0 - nsPopupFrameList::nsPopupFrameList(nsIContent* aPopupContent, nsPopupFrameList* aNext) :mNextPopup(aNext), mPopupFrame(nsnull), @@ -104,6 +89,12 @@ nsPopupSetFrame::Init(nsIContent* aContent, return rv; } +nsIAtom* +nsPopupSetFrame::GetType() const +{ + return nsGkAtoms::popupSetFrame; +} + NS_IMETHODIMP nsPopupSetFrame::AppendFrames(nsIAtom* aListName, nsIFrame* aFrameList) @@ -148,10 +139,12 @@ nsPopupSetFrame::SetInitialChildList(nsIAtom* aListName, void nsPopupSetFrame::Destroy() { + nsCSSFrameConstructor* frameConstructor = + PresContext()->PresShell()->FrameConstructor(); // remove each popup from the list as we go. while (mPopupList) { if (mPopupList->mPopupFrame) - mPopupList->mPopupFrame->Destroy(); + DestroyPopupFrame(frameConstructor, mPopupList->mPopupFrame); nsPopupFrameList* temp = mPopupList; mPopupList = mPopupList->mNextPopup; @@ -245,7 +238,8 @@ nsPopupSetFrame::RemovePopupFrame(nsIFrame* aPopup) mPopupList = currEntry->mNextPopup; // Destroy the frame. - currEntry->mPopupFrame->Destroy(); + DestroyPopupFrame(PresContext()->PresShell()->FrameConstructor(), + currEntry->mPopupFrame); // Delete the entry. currEntry->mNextPopup = nsnull; @@ -302,3 +296,10 @@ nsPopupSetFrame::AddPopupFrame(nsIFrame* aPopup) return NS_OK; } + +void +nsPopupSetFrame::DestroyPopupFrame(nsCSSFrameConstructor* aFc, nsIFrame* aPopup) +{ + aFc->RemoveMappingsForFrameSubtree(aPopup); + aPopup->Destroy(); +} diff --git a/layout/xul/base/src/nsPopupSetFrame.h b/layout/xul/base/src/nsPopupSetFrame.h index 858833f0879..901b578ed6e 100644 --- a/layout/xul/base/src/nsPopupSetFrame.h +++ b/layout/xul/base/src/nsPopupSetFrame.h @@ -43,17 +43,12 @@ #ifndef nsPopupSetFrame_h__ #define nsPopupSetFrame_h__ -#include "prtypes.h" #include "nsIAtom.h" -#include "nsCOMPtr.h" -#include "nsGkAtoms.h" #include "nsBoxFrame.h" -#include "nsFrameList.h" #include "nsMenuPopupFrame.h" -#include "nsIMenuParent.h" -#include "nsITimer.h" -#include "nsISupportsArray.h" + +class nsCSSFrameConstructor; nsIFrame* NS_NewPopupSetFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); @@ -93,7 +88,7 @@ public: // Used to destroy our popup frames. virtual void Destroy(); - virtual nsIAtom* GetType() const { return nsGkAtoms::popupSetFrame; } + virtual nsIAtom* GetType() const; #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const @@ -107,6 +102,7 @@ protected: nsresult AddPopupFrameList(nsIFrame* aPopupFrameList); nsresult AddPopupFrame(nsIFrame* aPopup); nsresult RemovePopupFrame(nsIFrame* aPopup); + void DestroyPopupFrame(nsCSSFrameConstructor* aFc, nsIFrame* aPopup); nsPopupFrameList* mPopupList; diff --git a/layout/xul/test/Makefile.in b/layout/xul/test/Makefile.in new file mode 100644 index 00000000000..0120a8a5428 --- /dev/null +++ b/layout/xul/test/Makefile.in @@ -0,0 +1,51 @@ +# +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is +# Mozilla Foundation. +# Portions created by the Initial Developer are Copyright (C) 2007 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either of the GNU General Public License Version 2 or later (the "GPL"), +# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ +relativesrcdir = layout/xul/test + +include $(DEPTH)/config/autoconf.mk +include $(topsrcdir)/config/rules.mk + +_TEST_FILES = test_bug372685.xul \ + $(NULL) + +libs:: $(_TEST_FILES) + $(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir) diff --git a/layout/xul/test/test_bug372685.xul b/layout/xul/test/test_bug372685.xul new file mode 100644 index 00000000000..17c1aae4b18 --- /dev/null +++ b/layout/xul/test/test_bug372685.xul @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + +Mozilla Bug 372685 +

+ +
+
+ + + + +