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: */
|
2016-01-20 18:20:41 +03: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"
|
|
|
|
#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)
|
|
|
|
NS_QUERYFRAME_ENTRY(DetailsFrame)
|
2016-01-20 18:20:41 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
2016-01-20 18:20:41 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
|
|
|
|
|
2016-09-07 09:45:42 +03:00
|
|
|
nsBlockFrame*
|
2018-03-22 21:20:41 +03:00
|
|
|
NS_NewDetailsFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle)
|
2016-01-20 18:20:41 +03:00
|
|
|
{
|
2018-03-22 21:20:41 +03:00
|
|
|
return new (aPresShell) DetailsFrame(aStyle);
|
2016-01-20 18:20:41 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 08:18:03 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
DetailsFrame::DetailsFrame(ComputedStyle* aStyle)
|
|
|
|
: nsBlockFrame(aStyle, kClassID)
|
2016-01-20 18:20:41 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DetailsFrame::~DetailsFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-02 12:39:49 +03:00
|
|
|
void
|
|
|
|
DetailsFrame::SetInitialChildList(ChildListID aListID, nsFrameList& aChildList)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-10-05 09:43:32 +03:00
|
|
|
if (aListID == kPrincipalList) {
|
2016-10-05 09:43:31 +03:00
|
|
|
CheckValidMainSummary(aChildList);
|
2016-02-02 12:39:49 +03:00
|
|
|
}
|
2016-10-05 09:43:32 +03:00
|
|
|
#endif
|
2016-02-02 12:39:49 +03:00
|
|
|
|
|
|
|
nsBlockFrame::SetInitialChildList(aListID, aChildList);
|
|
|
|
}
|
2016-01-20 18:20:41 +03:00
|
|
|
|
2016-10-05 09:43:31 +03:00
|
|
|
#ifdef DEBUG
|
2016-10-05 09:43:32 +03:00
|
|
|
bool
|
2016-10-05 09:43:31 +03:00
|
|
|
DetailsFrame::CheckValidMainSummary(const nsFrameList& aFrameList) const
|
|
|
|
{
|
|
|
|
for (nsIFrame* child : aFrameList) {
|
|
|
|
HTMLSummaryElement* summary =
|
2018-03-22 00:39:04 +03:00
|
|
|
HTMLSummaryElement::FromNode(child->GetContent());
|
2016-10-05 09:43:31 +03:00
|
|
|
|
|
|
|
if (child == aFrameList.FirstChild()) {
|
|
|
|
if (summary && summary->IsMainSummary()) {
|
2016-10-05 09:43:32 +03: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 09:43:31 +03: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 09:43:32 +03:00
|
|
|
return false;
|
2016-10-05 09:43:31 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-20 18:20:41 +03:00
|
|
|
void
|
2017-11-07 03:20:33 +03:00
|
|
|
DetailsFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData)
|
2016-01-20 18:20:41 +03:00
|
|
|
{
|
2017-11-07 03:20:33 +03:00
|
|
|
aPostDestroyData.AddAnonymousContent(mDefaultSummary.forget());
|
|
|
|
nsBlockFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
2016-01-20 18:20:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
DetailsFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
|
|
|
{
|
2018-03-22 00:39:04 +03:00
|
|
|
auto* details = HTMLDetailsElement::FromNode(GetContent());
|
2016-01-20 18:20:41 +03: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();
|
|
|
|
|
|
|
|
already_AddRefed<NodeInfo> nodeInfo =
|
|
|
|
nodeInfoManager->GetNodeInfo(nsGkAtoms::summary, nullptr, kNameSpaceID_XHTML,
|
2018-01-30 07:10:53 +03:00
|
|
|
nsINode::ELEMENT_NODE);
|
2016-01-20 18:20:41 +03:00
|
|
|
mDefaultSummary = new HTMLSummaryElement(nodeInfo);
|
|
|
|
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAutoString defaultSummaryText;
|
2016-02-03 20:48:00 +03:00
|
|
|
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
|
|
|
"DefaultSummary", defaultSummaryText);
|
2016-01-20 18:20:41 +03:00
|
|
|
RefPtr<nsTextNode> description = new nsTextNode(nodeInfoManager);
|
2016-02-03 20:48:00 +03:00
|
|
|
description->SetText(defaultSummaryText, false);
|
2016-01-20 18:20:41 +03:00
|
|
|
mDefaultSummary->AppendChildTo(description, false);
|
|
|
|
|
|
|
|
aElements.AppendElement(mDefaultSummary);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DetailsFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
|
|
|
uint32_t aFilter)
|
|
|
|
{
|
|
|
|
if (mDefaultSummary) {
|
|
|
|
aElements.AppendElement(mDefaultSummary);
|
|
|
|
}
|
|
|
|
}
|
2016-12-01 08:18:03 +03:00
|
|
|
|
2017-07-05 09:52:37 +03:00
|
|
|
bool
|
|
|
|
DetailsFrame::HasMainSummaryFrame(nsIFrame* aSummaryFrame)
|
|
|
|
{
|
2018-05-05 02:06:57 +03:00
|
|
|
nsIFrame* firstChild = nullptr;
|
|
|
|
for (nsIFrame* frag = this; frag; frag = frag->GetNextInFlow()) {
|
|
|
|
firstChild = frag->PrincipalChildList().FirstChild();
|
|
|
|
if (!firstChild) {
|
|
|
|
nsFrameList* overflowFrames = GetOverflowFrames();
|
|
|
|
if (overflowFrames) {
|
|
|
|
firstChild = overflowFrames->FirstChild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (firstChild) {
|
|
|
|
firstChild = nsPlaceholderFrame::GetRealFrameFor(firstChild);
|
|
|
|
MOZ_ASSERT(firstChild && firstChild->IsPrimaryFrame(),
|
|
|
|
"this is probably not the frame you were looking for");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-05 09:52:37 +03:00
|
|
|
return aSummaryFrame == firstChild;
|
|
|
|
}
|
|
|
|
|
2016-12-01 08:18:03 +03:00
|
|
|
} // namespace mozilla
|