Bug 1452889: Assert more tightly. r?bz
Let's see if listboxes are the only ones breaking invariants.
MozReview-Commit-ID: DSgfEoCOI78
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -327,16 +327,42 @@ NS_NewScrollbarButtonFrame (nsIPresShell
#ifdef NOISY_FINDFRAME
static int32_t FFWC_totalCount=0;
static int32_t FFWC_doLoop=0;
static int32_t FFWC_doSibling=0;
static int32_t FFWC_recursions=0;
static int32_t FFWC_nextInFlows=0;
#endif
+#ifdef MOZ_XUL
+
+static bool
+IsXULListBox(nsIContent* aContainer)
+{
+ return aContainer->IsXULElement(nsGkAtoms::listbox);
+}
+
+static
+nsListBoxBodyFrame*
+MaybeGetListBoxBodyFrame(nsIContent* aChild)
+{
+ if (aChild->IsXULElement(nsGkAtoms::listitem) && aChild->GetParent() &&
+ IsXULListBox(aChild->GetParent())) {
+ RefPtr<nsXULElement> xulElement =
+ nsXULElement::FromNode(aChild->GetParent());
+ nsCOMPtr<nsIBoxObject> boxObject = xulElement->GetBoxObject(IgnoreErrors());
+ nsCOMPtr<nsPIListBoxObject> listBoxObject = do_QueryInterface(boxObject);
+ if (listBoxObject) {
+ return listBoxObject->GetListBoxBody(false);
+ }
+ }
+
+ return nullptr;
+}
+#endif // MOZ_XUL
// Returns true if aFrame is an anonymous flex/grid item.
static inline bool
IsAnonymousFlexOrGridItem(const nsIFrame* aFrame)
{
const nsAtom* pseudoType = aFrame->Style()->GetPseudo();
return pseudoType == nsCSSAnonBoxes::anonymousFlexItem ||
pseudoType == nsCSSAnonBoxes::anonymousGridItem;
@@ -5527,16 +5553,19 @@ nsCSSFrameConstructor::ShouldCreateItems
nsContainerFrame* aParentFrame)
{
aContent->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME);
// XXX the GetContent() != aContent check is needed due to bug 135040.
// Remove it once that's fixed.
if (aContent->GetPrimaryFrame() &&
aContent->GetPrimaryFrame()->GetContent() == aContent &&
!aState.mCreatingExtraFrames) {
+ MOZ_ASSERT(MaybeGetListBoxBodyFrame(aContent),
+ "asked to create frame construction item for a node that "
+ "already has a frame");
NS_ERROR("asked to create frame construction item for a node that already "
"has a frame");
return false;
}
// don't create a whitespace frame if aParent doesn't want it
if (!NeedFrameFor(aState, aParentFrame, aContent)) {
return false;
@@ -6729,43 +6758,16 @@ IsSpecialFramesetChild(nsIContent* aCont
{
// IMPORTANT: This must match the conditions in nsHTMLFramesetFrame::Init.
return aContent->IsAnyOfHTMLElements(nsGkAtoms::frameset, nsGkAtoms::frame);
}
static void
InvalidateCanvasIfNeeded(nsIPresShell* presShell, nsIContent* node);
-#ifdef MOZ_XUL
-
-static bool
-IsXULListBox(nsIContent* aContainer)
-{
- return aContainer->IsXULElement(nsGkAtoms::listbox);
-}
-
-static
-nsListBoxBodyFrame*
-MaybeGetListBoxBodyFrame(nsIContent* aChild)
-{
- if (aChild->IsXULElement(nsGkAtoms::listitem) && aChild->GetParent() &&
- IsXULListBox(aChild->GetParent())) {
- RefPtr<nsXULElement> xulElement =
- nsXULElement::FromNode(aChild->GetParent());
- nsCOMPtr<nsIBoxObject> boxObject = xulElement->GetBoxObject(IgnoreErrors());
- nsCOMPtr<nsPIListBoxObject> listBoxObject = do_QueryInterface(boxObject);
- if (listBoxObject) {
- return listBoxObject->GetListBoxBody(false);
- }
- }
-
- return nullptr;
-}
-#endif // MOZ_XUL
-
void
nsCSSFrameConstructor::AddTextItemIfNeeded(nsFrameConstructorState& aState,
const InsertionPoint& aInsertion,
nsIContent* aPossibleTextContent,
FrameConstructionItemList& aItems)
{
NS_PRECONDITION(aPossibleTextContent, "Must have node");
if (!aPossibleTextContent->IsNodeOfType(nsINode::eTEXT) ||