2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 22:16:27 +04:00
|
|
|
|
|
|
|
#include "nsPopupSetFrame.h"
|
2007-10-06 17:53:05 +04:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsCOMPtr.h"
|
1999-08-06 22:16:27 +04:00
|
|
|
#include "nsIContent.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2018-03-22 21:20:41 +03:00
|
|
|
#include "mozilla/ComputedStyle.h"
|
2019-04-03 15:40:26 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsBoxLayoutState.h"
|
2000-05-15 08:12:31 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2018-06-27 03:29:55 +03:00
|
|
|
#include "nsIPopupContainer.h"
|
2010-02-09 19:05:19 +03:00
|
|
|
#include "nsMenuPopupFrame.h"
|
1999-08-06 22:16:27 +04:00
|
|
|
|
2018-07-18 13:23:32 +03:00
|
|
|
typedef mozilla::ComputedStyle ComputedStyle;
|
|
|
|
|
2019-04-16 10:24:49 +03:00
|
|
|
nsIFrame* NS_NewPopupSetFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell) nsPopupSetFrame(aStyle, aPresShell->GetPresContext());
|
1999-08-06 22:16:27 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsPopupSetFrame)
|
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
void nsPopupSetFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2013-03-20 05:47:48 +04:00
|
|
|
nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2002-08-19 22:29:29 +04:00
|
|
|
|
2008-12-17 03:30:31 +03:00
|
|
|
// Normally the root box is our grandparent, but in case of wrapping
|
|
|
|
// it can be our great-grandparent.
|
2018-06-27 03:29:55 +03:00
|
|
|
nsIPopupContainer* popupContainer =
|
|
|
|
nsIPopupContainer::GetPopupContainer(PresContext()->GetPresShell());
|
|
|
|
if (popupContainer) {
|
|
|
|
popupContainer->SetPopupSetFrame(this);
|
2002-08-19 22:29:29 +04:00
|
|
|
}
|
1999-08-06 22:16:27 +04:00
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsPopupSetFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList) {
|
2011-08-25 00:54:30 +04:00
|
|
|
if (aListID == kPopupList) {
|
2010-02-09 19:05:19 +03:00
|
|
|
AddPopupFrameList(aFrameList);
|
2014-05-28 23:36:58 +04:00
|
|
|
return;
|
2006-08-30 02:20:41 +04:00
|
|
|
}
|
2014-05-28 23:36:58 +04:00
|
|
|
nsBoxFrame::AppendFrames(aListID, aFrameList);
|
2006-08-30 02:20:41 +04:00
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsPopupSetFrame::RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) {
|
|
|
|
if (aListID == kPopupList) {
|
2010-02-09 19:05:19 +03:00
|
|
|
RemovePopupFrame(aOldFrame);
|
2014-05-28 23:36:58 +04:00
|
|
|
return;
|
2006-08-30 02:20:41 +04:00
|
|
|
}
|
2014-05-28 23:36:58 +04:00
|
|
|
nsBoxFrame::RemoveFrame(aListID, aOldFrame);
|
2006-08-30 02:20:41 +04:00
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsPopupSetFrame::InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList) {
|
2011-08-25 00:54:30 +04:00
|
|
|
if (aListID == kPopupList) {
|
2010-02-09 19:05:19 +03:00
|
|
|
AddPopupFrameList(aFrameList);
|
2014-05-28 23:36:58 +04:00
|
|
|
return;
|
2007-03-02 15:03:02 +03:00
|
|
|
}
|
2014-05-28 23:36:58 +04:00
|
|
|
nsBoxFrame::InsertFrames(aListID, aPrevFrame, aFrameList);
|
2006-08-30 02:20:41 +04:00
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsPopupSetFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 16:53:20 +04:00
|
|
|
nsFrameList& aChildList) {
|
2011-08-25 00:54:30 +04:00
|
|
|
if (aListID == kPopupList) {
|
2013-11-04 20:22:20 +04:00
|
|
|
NS_ASSERTION(mPopupList.IsEmpty(),
|
|
|
|
"SetInitialChildList on non-empty child list");
|
2010-02-09 19:05:19 +03:00
|
|
|
AddPopupFrameList(aChildList);
|
2014-05-28 23:36:58 +04:00
|
|
|
return;
|
2007-03-02 15:03:02 +03:00
|
|
|
}
|
2014-05-28 23:36:58 +04:00
|
|
|
nsBoxFrame::SetInitialChildList(aListID, aChildList);
|
2006-08-30 02:20:41 +04:00
|
|
|
}
|
|
|
|
|
2013-11-04 20:22:20 +04: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);
|
|
|
|
}
|
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
void nsPopupSetFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) {
|
|
|
|
mPopupList.DestroyFramesFrom(aDestructRoot, aPostDestroyData);
|
2000-08-03 04:22:36 +04:00
|
|
|
|
2008-12-17 03:30:31 +03:00
|
|
|
// Normally the root box is our grandparent, but in case of wrapping
|
|
|
|
// it can be our great-grandparent.
|
2018-06-27 03:29:55 +03:00
|
|
|
nsIPopupContainer* popupContainer =
|
|
|
|
nsIPopupContainer::GetPopupContainer(PresContext()->GetPresShell());
|
|
|
|
if (popupContainer) {
|
|
|
|
popupContainer->SetPopupSetFrame(nullptr);
|
2002-08-19 22:29:29 +04:00
|
|
|
}
|
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
nsBoxFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
1999-08-06 22:16:27 +04:00
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
NS_IMETHODIMP
|
2016-04-21 07:28:35 +03:00
|
|
|
nsPopupSetFrame::DoXULLayout(nsBoxLayoutState& aState) {
|
2000-03-31 11:02:06 +04:00
|
|
|
// lay us out
|
2016-04-21 07:28:35 +03:00
|
|
|
nsresult rv = nsBoxFrame::DoXULLayout(aState);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-08-18 05:04:47 +04:00
|
|
|
// lay out all of our currently open popups.
|
2010-02-09 19:05:19 +03:00
|
|
|
for (nsFrameList::Enumerator e(mPopupList); !e.AtEnd(); e.Next()) {
|
|
|
|
nsMenuPopupFrame* popupChild = static_cast<nsMenuPopupFrame*>(e.get());
|
2014-01-28 20:28:45 +04:00
|
|
|
popupChild->LayoutPopup(aState, nullptr, nullptr, false);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-09-22 04:32:23 +04:00
|
|
|
void nsPopupSetFrame::RemovePopupFrame(nsIFrame* aPopup) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT((aPopup->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
|
|
|
|
aPopup->IsMenuPopupFrame(),
|
|
|
|
"removing wrong type of frame in popupset's ::popupList");
|
2001-09-22 04:32:23 +04:00
|
|
|
|
2010-02-09 19:05:19 +03:00
|
|
|
mPopupList.DestroyFrame(aPopup);
|
2001-09-22 04:32:23 +04:00
|
|
|
}
|
|
|
|
|
2009-07-28 16:53:20 +04:00
|
|
|
void nsPopupSetFrame::AddPopupFrameList(nsFrameList& aPopupFrameList) {
|
2010-02-09 19:05:19 +03: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 18:30:08 +03:00
|
|
|
e.get()->IsMenuPopupFrame(),
|
2010-02-09 19:05:19 +03:00
|
|
|
"adding wrong type of frame in popupset's ::popupList");
|
2007-03-02 15:03:02 +03:00
|
|
|
}
|
2010-02-09 19:05:19 +03:00
|
|
|
#endif
|
2012-07-30 18:20:58 +04:00
|
|
|
mPopupList.InsertFrames(nullptr, nullptr, aPopupFrameList);
|
2000-08-17 13:15:51 +04:00
|
|
|
}
|