2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-08-06 18:16:27 +00:00
|
|
|
|
|
|
|
#include "nsPopupSetFrame.h"
|
2007-10-06 13:53:05 +00:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsCOMPtr.h"
|
1999-08-06 18:16:27 +00:00
|
|
|
#include "nsIContent.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
2000-03-31 07:02:06 +00:00
|
|
|
#include "nsBoxLayoutState.h"
|
2000-05-15 04:12:31 +00:00
|
|
|
#include "nsIScrollableFrame.h"
|
2002-08-19 18:29:29 +00:00
|
|
|
#include "nsIRootBox.h"
|
2010-02-09 16:05:19 +00:00
|
|
|
#include "nsMenuPopupFrame.h"
|
1999-08-06 18:16:27 +00:00
|
|
|
|
2005-10-26 21:46:39 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewPopupSetFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1999-08-06 18:16:27 +00:00
|
|
|
{
|
2015-01-06 09:27:56 +00:00
|
|
|
return new (aPresShell) nsPopupSetFrame(aContext);
|
1999-08-06 18:16:27 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsPopupSetFrame)
|
|
|
|
|
2013-03-20 01:47:48 +00:00
|
|
|
void
|
2014-05-24 22:20:40 +00:00
|
|
|
nsPopupSetFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1999-08-06 18:16:27 +00:00
|
|
|
{
|
2013-03-20 01:47:48 +00:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2002-08-19 18:29:29 +00:00
|
|
|
|
2008-12-17 00:30:31 +00:00
|
|
|
// Normally the root box is our grandparent, but in case of wrapping
|
|
|
|
// it can be our great-grandparent.
|
|
|
|
nsIRootBox *rootBox = nsIRootBox::GetRootBox(PresContext()->GetPresShell());
|
|
|
|
if (rootBox) {
|
2002-08-19 18:29:29 +00:00
|
|
|
rootBox->SetPopupSetFrame(this);
|
|
|
|
}
|
1999-08-06 18:16:27 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:36:58 +00:00
|
|
|
void
|
2011-08-24 20:54:30 +00:00
|
|
|
nsPopupSetFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 17:23:32 +00:00
|
|
|
nsFrameList& aFrameList)
|
2006-08-29 22:20:41 +00:00
|
|
|
{
|
2011-08-24 20:54:30 +00:00
|
|
|
if (aListID == kPopupList) {
|
2010-02-09 16:05:19 +00:00
|
|
|
AddPopupFrameList(aFrameList);
|
2014-05-28 19:36:58 +00:00
|
|
|
return;
|
2006-08-29 22:20:41 +00:00
|
|
|
}
|
2014-05-28 19:36:58 +00:00
|
|
|
nsBoxFrame::AppendFrames(aListID, aFrameList);
|
2006-08-29 22:20:41 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:36:58 +00:00
|
|
|
void
|
2011-08-24 20:54:30 +00:00
|
|
|
nsPopupSetFrame::RemoveFrame(ChildListID aListID,
|
2006-08-29 22:20:41 +00:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2011-08-24 20:54:30 +00:00
|
|
|
if (aListID == kPopupList) {
|
2010-02-09 16:05:19 +00:00
|
|
|
RemovePopupFrame(aOldFrame);
|
2014-05-28 19:36:58 +00:00
|
|
|
return;
|
2006-08-29 22:20:41 +00:00
|
|
|
}
|
2014-05-28 19:36:58 +00:00
|
|
|
nsBoxFrame::RemoveFrame(aListID, aOldFrame);
|
2006-08-29 22:20:41 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:36:58 +00:00
|
|
|
void
|
2011-08-24 20:54:30 +00:00
|
|
|
nsPopupSetFrame::InsertFrames(ChildListID aListID,
|
2006-08-29 22:20:41 +00:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 17:23:32 +00:00
|
|
|
nsFrameList& aFrameList)
|
2006-08-29 22:20:41 +00:00
|
|
|
{
|
2011-08-24 20:54:30 +00:00
|
|
|
if (aListID == kPopupList) {
|
2010-02-09 16:05:19 +00:00
|
|
|
AddPopupFrameList(aFrameList);
|
2014-05-28 19:36:58 +00:00
|
|
|
return;
|
2007-03-02 12:03:02 +00:00
|
|
|
}
|
2014-05-28 19:36:58 +00:00
|
|
|
nsBoxFrame::InsertFrames(aListID, aPrevFrame, aFrameList);
|
2006-08-29 22:20:41 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:36:58 +00:00
|
|
|
void
|
2011-08-24 20:54:30 +00:00
|
|
|
nsPopupSetFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 12:53:20 +00:00
|
|
|
nsFrameList& aChildList)
|
2006-08-29 22:20:41 +00:00
|
|
|
{
|
2011-08-24 20:54:30 +00:00
|
|
|
if (aListID == kPopupList) {
|
2013-11-04 16:22:20 +00:00
|
|
|
NS_ASSERTION(mPopupList.IsEmpty(),
|
|
|
|
"SetInitialChildList on non-empty child list");
|
2010-02-09 16:05:19 +00:00
|
|
|
AddPopupFrameList(aChildList);
|
2014-05-28 19:36:58 +00:00
|
|
|
return;
|
2007-03-02 12:03:02 +00:00
|
|
|
}
|
2014-05-28 19:36:58 +00:00
|
|
|
nsBoxFrame::SetInitialChildList(aListID, aChildList);
|
2006-08-29 22:20:41 +00:00
|
|
|
}
|
|
|
|
|
2013-11-04 16:22:20 +00:00
|
|
|
const nsFrameList&
|
|
|
|
nsPopupSetFrame::GetChildList(ChildListID aListID) const
|
|
|
|
{
|
|
|
|
if (kPopupList == aListID) {
|
|
|
|
return mPopupList;
|
|
|
|
}
|
|
|
|
return nsBoxFrame::GetChildList(aListID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsPopupSetFrame::GetChildLists(nsTArray<ChildList>* aLists) const
|
|
|
|
{
|
|
|
|
nsBoxFrame::GetChildLists(aLists);
|
|
|
|
mPopupList.AppendIfNonempty(aLists, kPopupList);
|
|
|
|
}
|
|
|
|
|
2006-04-10 00:16:29 +00:00
|
|
|
void
|
2009-12-24 05:21:15 +00:00
|
|
|
nsPopupSetFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
1999-08-06 18:16:27 +00:00
|
|
|
{
|
2010-02-09 16:05:19 +00:00
|
|
|
mPopupList.DestroyFramesFrom(aDestructRoot);
|
2000-08-03 00:22:36 +00:00
|
|
|
|
2008-12-17 00:30:31 +00:00
|
|
|
// Normally the root box is our grandparent, but in case of wrapping
|
|
|
|
// it can be our great-grandparent.
|
|
|
|
nsIRootBox *rootBox = nsIRootBox::GetRootBox(PresContext()->GetPresShell());
|
|
|
|
if (rootBox) {
|
2012-07-30 14:20:58 +00:00
|
|
|
rootBox->SetPopupSetFrame(nullptr);
|
2002-08-19 18:29:29 +00:00
|
|
|
}
|
|
|
|
|
2009-12-24 05:21:15 +00:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot);
|
1999-08-06 18:16:27 +00:00
|
|
|
}
|
|
|
|
|
2000-03-31 07:02:06 +00:00
|
|
|
NS_IMETHODIMP
|
2016-04-21 04:28:35 +00:00
|
|
|
nsPopupSetFrame::DoXULLayout(nsBoxLayoutState& aState)
|
2000-03-31 07:02:06 +00:00
|
|
|
{
|
|
|
|
// lay us out
|
2016-04-21 04:28:35 +00:00
|
|
|
nsresult rv = nsBoxFrame::DoXULLayout(aState);
|
2000-03-31 07:02:06 +00:00
|
|
|
|
2001-08-18 01:04:47 +00:00
|
|
|
// lay out all of our currently open popups.
|
2010-02-09 16:05:19 +00:00
|
|
|
for (nsFrameList::Enumerator e(mPopupList); !e.AtEnd(); e.Next()) {
|
|
|
|
nsMenuPopupFrame* popupChild = static_cast<nsMenuPopupFrame*>(e.get());
|
2014-01-28 16:28:45 +00:00
|
|
|
popupChild->LayoutPopup(aState, nullptr, nullptr, false);
|
2000-03-31 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-02-09 16:05:19 +00:00
|
|
|
void
|
2001-09-22 00:32:23 +00:00
|
|
|
nsPopupSetFrame::RemovePopupFrame(nsIFrame* aPopup)
|
|
|
|
{
|
2010-02-09 16:05:19 +00:00
|
|
|
NS_PRECONDITION((aPopup->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
|
2017-04-30 15:30:08 +00:00
|
|
|
aPopup->IsMenuPopupFrame(),
|
2010-02-09 16:05:19 +00:00
|
|
|
"removing wrong type of frame in popupset's ::popupList");
|
2001-09-22 00:32:23 +00:00
|
|
|
|
2010-02-09 16:05:19 +00:00
|
|
|
mPopupList.DestroyFrame(aPopup);
|
2001-09-22 00:32:23 +00:00
|
|
|
}
|
|
|
|
|
2010-02-09 16:05:19 +00:00
|
|
|
void
|
2009-07-28 12:53:20 +00:00
|
|
|
nsPopupSetFrame::AddPopupFrameList(nsFrameList& aPopupFrameList)
|
2007-03-02 12:03:02 +00:00
|
|
|
{
|
2010-02-09 16:05:19 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
for (nsFrameList::Enumerator e(aPopupFrameList); !e.AtEnd(); e.Next()) {
|
|
|
|
NS_ASSERTION((e.get()->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
|
2017-04-30 15:30:08 +00:00
|
|
|
e.get()->IsMenuPopupFrame(),
|
2010-02-09 16:05:19 +00:00
|
|
|
"adding wrong type of frame in popupset's ::popupList");
|
2007-03-02 12:03:02 +00:00
|
|
|
}
|
2010-02-09 16:05:19 +00:00
|
|
|
#endif
|
2012-07-30 14:20:58 +00:00
|
|
|
mPopupList.InsertFrames(nullptr, nullptr, aPopupFrameList);
|
2000-08-17 09:15:51 +00:00
|
|
|
}
|