2017-10-27 17:33:53 +00: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: */
|
2016-01-20 15:20:41 +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/. */
|
|
|
|
|
|
|
|
#include "DetailsFrame.h"
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2019-04-16 07:24:49 +00:00
|
|
|
#include "mozilla/PresShell.h"
|
2016-01-20 15:20:41 +00:00
|
|
|
#include "mozilla/dom/HTMLDetailsElement.h"
|
|
|
|
#include "mozilla/dom/HTMLSummaryElement.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsPlaceholderFrame.h"
|
|
|
|
#include "nsTextNode.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(DetailsFrame)
|
|
|
|
|
|
|
|
NS_QUERYFRAME_HEAD(DetailsFrame)
|
2018-12-07 20:00:18 +00:00
|
|
|
NS_QUERYFRAME_ENTRY(DetailsFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
2016-01-20 15:20:41 +00:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
|
|
|
|
|
2019-04-16 07:24:49 +00:00
|
|
|
nsBlockFrame* NS_NewDetailsFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
|
2019-02-05 16:45:54 +00:00
|
|
|
return new (aPresShell) DetailsFrame(aStyle, aPresShell->GetPresContext());
|
2016-01-20 15:20:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 05:18:03 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2019-02-05 16:45:54 +00:00
|
|
|
DetailsFrame::DetailsFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
|
|
|
|
: nsBlockFrame(aStyle, aPresContext, kClassID) {}
|
2016-01-20 15:20:41 +00:00
|
|
|
|
2020-03-17 09:38:32 +00:00
|
|
|
DetailsFrame::~DetailsFrame() = default;
|
2016-01-20 15:20:41 +00:00
|
|
|
|
2016-02-02 09:39:49 +00:00
|
|
|
void DetailsFrame::SetInitialChildList(ChildListID aListID,
|
|
|
|
nsFrameList& aChildList) {
|
|
|
|
#ifdef DEBUG
|
2016-10-05 06:43:32 +00:00
|
|
|
if (aListID == kPrincipalList) {
|
2016-10-05 06:43:31 +00:00
|
|
|
CheckValidMainSummary(aChildList);
|
2016-02-02 09:39:49 +00:00
|
|
|
}
|
2016-10-05 06:43:32 +00:00
|
|
|
#endif
|
2016-02-02 09:39:49 +00:00
|
|
|
|
|
|
|
nsBlockFrame::SetInitialChildList(aListID, aChildList);
|
|
|
|
}
|
2016-01-20 15:20:41 +00:00
|
|
|
|
2016-10-05 06:43:31 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool DetailsFrame::CheckValidMainSummary(const nsFrameList& aFrameList) const {
|
|
|
|
for (nsIFrame* child : aFrameList) {
|
2019-03-24 22:13:53 +00:00
|
|
|
if (child->IsGeneratedContentFrame()) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-10-05 06:43:31 +00:00
|
|
|
HTMLSummaryElement* summary =
|
2018-03-21 21:39:04 +00:00
|
|
|
HTMLSummaryElement::FromNode(child->GetContent());
|
2016-10-05 06:43:31 +00:00
|
|
|
if (child == aFrameList.FirstChild()) {
|
|
|
|
if (summary && summary->IsMainSummary()) {
|
2016-10-05 06:43:32 +00:00
|
|
|
return true;
|
|
|
|
} else if (child->GetContent() == GetContent()) {
|
|
|
|
// The child frame's content is the same as our content, which means
|
|
|
|
// it's a kind of wrapper frame. Descend into its child list to find
|
|
|
|
// main summary.
|
|
|
|
if (CheckValidMainSummary(child->PrincipalChildList())) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-10-05 06:43:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(!summary || !summary->IsMainSummary(),
|
|
|
|
"Rest of the children are either not summary element "
|
|
|
|
"or are not the main summary!");
|
|
|
|
}
|
|
|
|
}
|
2016-10-05 06:43:32 +00:00
|
|
|
return false;
|
2016-10-05 06:43:31 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-11-07 00:20:33 +00:00
|
|
|
void DetailsFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) {
|
|
|
|
aPostDestroyData.AddAnonymousContent(mDefaultSummary.forget());
|
|
|
|
nsBlockFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
2016-01-20 15:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DetailsFrame::CreateAnonymousContent(
|
|
|
|
nsTArray<ContentInfo>& aElements) {
|
2018-03-21 21:39:04 +00:00
|
|
|
auto* details = HTMLDetailsElement::FromNode(GetContent());
|
2016-01-20 15:20:41 +00:00
|
|
|
if (details->GetFirstSummary()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The <details> element lacks any direct <summary> child. Create a default
|
|
|
|
// <summary> element as an anonymous content.
|
|
|
|
nsNodeInfoManager* nodeInfoManager =
|
|
|
|
GetContent()->NodeInfo()->NodeInfoManager();
|
|
|
|
|
2018-09-21 20:45:49 +00:00
|
|
|
RefPtr<NodeInfo> nodeInfo = nodeInfoManager->GetNodeInfo(
|
2016-01-20 15:20:41 +00:00
|
|
|
nsGkAtoms::summary, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
2020-03-17 14:53:08 +00:00
|
|
|
mDefaultSummary = new (nodeInfoManager) HTMLSummaryElement(nodeInfo.forget());
|
2016-01-20 15:20:41 +00:00
|
|
|
|
2017-08-04 04:40:52 +00:00
|
|
|
nsAutoString defaultSummaryText;
|
2019-11-04 16:56:27 +00:00
|
|
|
nsContentUtils::GetMaybeLocalizedString(
|
|
|
|
nsContentUtils::eFORMS_PROPERTIES, "DefaultSummary",
|
|
|
|
GetContent()->OwnerDoc(), defaultSummaryText);
|
2020-03-17 14:53:54 +00:00
|
|
|
RefPtr<nsTextNode> description =
|
|
|
|
new (nodeInfoManager) nsTextNode(nodeInfoManager);
|
2016-02-03 17:48:00 +00:00
|
|
|
description->SetText(defaultSummaryText, false);
|
2021-06-02 13:43:39 +00:00
|
|
|
mDefaultSummary->AppendChildTo(description, false, IgnoreErrors());
|
2016-01-20 15:20:41 +00:00
|
|
|
|
|
|
|
aElements.AppendElement(mDefaultSummary);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DetailsFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
|
|
|
uint32_t aFilter) {
|
|
|
|
if (mDefaultSummary) {
|
|
|
|
aElements.AppendElement(mDefaultSummary);
|
|
|
|
}
|
|
|
|
}
|
2016-12-01 05:18:03 +00:00
|
|
|
|
2017-07-05 06:52:37 +00:00
|
|
|
bool DetailsFrame::HasMainSummaryFrame(nsIFrame* aSummaryFrame) {
|
2018-12-19 00:50:09 +00:00
|
|
|
const ChildListIDs flowLists = {kPrincipalList, kOverflowList};
|
2018-05-04 23:06:57 +00:00
|
|
|
for (nsIFrame* frag = this; frag; frag = frag->GetNextInFlow()) {
|
2020-05-19 12:37:37 +00:00
|
|
|
for (const auto& [list, listID] : frag->ChildLists()) {
|
2020-05-18 01:09:34 +00:00
|
|
|
if (!flowLists.contains(listID)) {
|
2018-05-17 15:30:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-05-18 01:09:34 +00:00
|
|
|
for (nsIFrame* child : list) {
|
2018-05-17 15:30:34 +00:00
|
|
|
child = nsPlaceholderFrame::GetRealFrameFor(child);
|
|
|
|
// We skip any non-primary frames such as a list-style-position:inside
|
|
|
|
// bullet frame for the <details> itself.
|
2019-03-24 22:13:53 +00:00
|
|
|
if (!child->IsGeneratedContentFrame()) {
|
2018-05-17 15:30:34 +00:00
|
|
|
return aSummaryFrame == child;
|
|
|
|
}
|
2018-05-04 23:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-17 15:30:34 +00:00
|
|
|
return false;
|
2017-07-05 06:52:37 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 05:18:03 +00:00
|
|
|
} // namespace mozilla
|