2016-01-20 18:20:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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)
|
|
|
|
|
|
|
|
DetailsFrame*
|
|
|
|
NS_NewDetailsFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) DetailsFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
DetailsFrame::DetailsFrame(nsStyleContext* aContext)
|
|
|
|
: nsBlockFrame(aContext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DetailsFrame::~DetailsFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
DetailsFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::detailsFrame;
|
|
|
|
}
|
2016-02-02 12:39:49 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
DetailsFrame::SetInitialChildList(ChildListID aListID, nsFrameList& aChildList)
|
|
|
|
{
|
|
|
|
if (aListID == kPrincipalList) {
|
2016-03-24 10:05:29 +03:00
|
|
|
HTMLDetailsElement* details = HTMLDetailsElement::FromContent(GetContent());
|
2016-02-02 12:39:49 +03:00
|
|
|
bool isOpen = details->Open();
|
|
|
|
|
|
|
|
if (isOpen) {
|
|
|
|
// If details is open, the first summary needs to be rendered as if it is
|
|
|
|
// the first child.
|
|
|
|
for (nsIFrame* child : aChildList) {
|
2016-04-13 08:34:14 +03:00
|
|
|
HTMLSummaryElement* summary =
|
|
|
|
HTMLSummaryElement::FromContent(child->GetContent());
|
|
|
|
|
|
|
|
if (summary && summary->IsMainSummary()) {
|
2016-02-02 12:39:49 +03:00
|
|
|
// Take out the first summary frame and insert it to the beginning of
|
|
|
|
// the list.
|
|
|
|
aChildList.RemoveFrame(child);
|
|
|
|
aChildList.InsertFrame(nullptr, nullptr, child);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2016-03-24 10:05:29 +03:00
|
|
|
for (nsIFrame* child : aChildList) {
|
|
|
|
HTMLSummaryElement* summary =
|
|
|
|
HTMLSummaryElement::FromContent(child->GetContent());
|
|
|
|
|
|
|
|
if (child == aChildList.FirstChild()) {
|
|
|
|
if (summary && summary->IsMainSummary()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(!summary || !summary->IsMainSummary(),
|
|
|
|
"Rest of the children are neither summary elements nor"
|
|
|
|
"the main summary!");
|
|
|
|
}
|
|
|
|
}
|
2016-02-02 12:39:49 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBlockFrame::SetInitialChildList(aListID, aChildList);
|
|
|
|
}
|
2016-01-20 18:20:41 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
DetailsFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
|
|
{
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mDefaultSummary);
|
|
|
|
nsBlockFrame::DestroyFrom(aDestructRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
DetailsFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
|
|
|
{
|
|
|
|
auto* details = HTMLDetailsElement::FromContent(GetContent());
|
|
|
|
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,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
mDefaultSummary = new HTMLSummaryElement(nodeInfo);
|
|
|
|
|
2016-02-03 20:48:00 +03:00
|
|
|
nsXPIDLString defaultSummaryText;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|