1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "nsUnicharUtils.h"
9 #include "mozilla/dom/LinkStyle.h"
10 #include "mozilla/dom/ProcessingInstruction.h"
11 #include "mozilla/dom/ProcessingInstructionBinding.h"
12 #include "mozilla/dom/XMLStylesheetProcessingInstruction.h"
13 #include "mozilla/IntegerPrintfMacros.h"
14 #include "nsContentUtils.h"
16 already_AddRefed
<mozilla::dom::ProcessingInstruction
>
17 NS_NewXMLProcessingInstruction(nsNodeInfoManager
* aNodeInfoManager
,
18 const nsAString
& aTarget
,
19 const nsAString
& aData
) {
20 using mozilla::dom::ProcessingInstruction
;
21 using mozilla::dom::XMLStylesheetProcessingInstruction
;
23 MOZ_ASSERT(aNodeInfoManager
, "Missing nodeinfo manager");
25 RefPtr
<nsAtom
> target
= NS_Atomize(aTarget
);
28 if (target
== nsGkAtoms::xml_stylesheet
) {
29 RefPtr
<XMLStylesheetProcessingInstruction
> pi
= new (aNodeInfoManager
)
30 XMLStylesheetProcessingInstruction(aNodeInfoManager
, aData
);
34 RefPtr
<mozilla::dom::NodeInfo
> ni
;
35 ni
= aNodeInfoManager
->GetNodeInfo(
36 nsGkAtoms::processingInstructionTagName
, nullptr, kNameSpaceID_None
,
37 nsINode::PROCESSING_INSTRUCTION_NODE
, target
);
39 RefPtr
<ProcessingInstruction
> instance
=
40 new (aNodeInfoManager
) ProcessingInstruction(ni
.forget(), aData
);
42 return instance
.forget();
48 ProcessingInstruction::ProcessingInstruction(
49 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
50 const nsAString
& aData
)
51 : CharacterData(std::move(aNodeInfo
)) {
52 MOZ_ASSERT(mNodeInfo
->NodeType() == nsINode::PROCESSING_INSTRUCTION_NODE
,
53 "Bad NodeType in aNodeInfo");
55 SetTextInternal(0, mText
.GetLength(), aData
.BeginReading(), aData
.Length(),
56 false); // Don't notify (bug 420429).
59 ProcessingInstruction::~ProcessingInstruction() = default;
61 StyleSheet
* ProcessingInstruction::GetSheetForBindings() const {
62 if (const auto* linkStyle
= LinkStyle::FromNode(*this)) {
63 return linkStyle
->GetSheetForBindings();
68 JSObject
* ProcessingInstruction::WrapNode(JSContext
* aCx
,
69 JS::Handle
<JSObject
*> aGivenProto
) {
70 return ProcessingInstruction_Binding::Wrap(aCx
, this, aGivenProto
);
73 bool ProcessingInstruction::GetAttrValue(nsAtom
* aName
, nsAString
& aValue
) {
77 return nsContentUtils::GetPseudoAttributeValue(data
, aName
, aValue
);
80 already_AddRefed
<CharacterData
> ProcessingInstruction::CloneDataNode(
81 mozilla::dom::NodeInfo
* aNodeInfo
, bool aCloneText
) const {
84 RefPtr
<mozilla::dom::NodeInfo
> ni
= aNodeInfo
;
85 auto* nim
= ni
->NodeInfoManager();
86 return do_AddRef(new (nim
) ProcessingInstruction(ni
.forget(), data
));
90 void ProcessingInstruction::List(FILE* out
, int32_t aIndent
) const {
92 for (index
= aIndent
; --index
>= 0;) fputs(" ", out
);
94 fprintf(out
, "Processing instruction refcount=%" PRIuPTR
"<", mRefCnt
.get());
97 ToCString(tmp
, 0, mText
.GetLength());
98 tmp
.Insert(nsDependentAtomString(NodeInfo()->GetExtraName()).get(), 0);
99 fputs(NS_LossyConvertUTF16toASCII(tmp
).get(), out
);
104 void ProcessingInstruction::DumpContent(FILE* out
, int32_t aIndent
,
105 bool aDumpAll
) const {}
109 } // namespace mozilla