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 * Implementation of DOM Core's DocumentType node.
11 #include "mozilla/dom/DocumentType.h"
12 #include "nsGkAtoms.h"
14 #include "nsDOMString.h"
15 #include "nsNodeInfoManager.h"
16 #include "xpcpublic.h"
17 #include "nsWrapperCacheInlines.h"
18 #include "mozilla/dom/DocumentTypeBinding.h"
20 already_AddRefed
<mozilla::dom::DocumentType
> NS_NewDOMDocumentType(
21 nsNodeInfoManager
* aNodeInfoManager
, nsAtom
* aName
,
22 const nsAString
& aPublicId
, const nsAString
& aSystemId
,
23 const nsAString
& aInternalSubset
) {
24 MOZ_ASSERT(aName
, "Must have a name");
26 RefPtr
<mozilla::dom::NodeInfo
> ni
= aNodeInfoManager
->GetNodeInfo(
27 nsGkAtoms::documentTypeNodeName
, nullptr, kNameSpaceID_None
,
28 nsINode::DOCUMENT_TYPE_NODE
, aName
);
30 RefPtr
<mozilla::dom::DocumentType
> docType
=
31 new (aNodeInfoManager
) mozilla::dom::DocumentType(
32 ni
.forget(), aPublicId
, aSystemId
, aInternalSubset
);
33 return docType
.forget();
36 namespace mozilla::dom
{
38 JSObject
* DocumentType::WrapNode(JSContext
* cx
,
39 JS::Handle
<JSObject
*> aGivenProto
) {
40 return DocumentType_Binding::Wrap(cx
, this, aGivenProto
);
43 DocumentType::DocumentType(already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
44 const nsAString
& aPublicId
,
45 const nsAString
& aSystemId
,
46 const nsAString
& aInternalSubset
)
47 : CharacterData(std::move(aNodeInfo
)),
50 mInternalSubset(aInternalSubset
) {
51 MOZ_ASSERT(mNodeInfo
->NodeType() == DOCUMENT_TYPE_NODE
,
52 "Bad NodeType in aNodeInfo");
53 MOZ_ASSERT(!IsCharacterData());
56 DocumentType::~DocumentType() = default;
58 bool DocumentType::IsNodeOfType(uint32_t aFlags
) const { return false; }
60 const nsTextFragment
* DocumentType::GetText() { return nullptr; }
62 void DocumentType::GetName(nsAString
& aName
) const { aName
= NodeName(); }
64 void DocumentType::GetPublicId(nsAString
& aPublicId
) const {
65 aPublicId
= mPublicId
;
68 void DocumentType::GetSystemId(nsAString
& aSystemId
) const {
69 aSystemId
= mSystemId
;
72 void DocumentType::GetInternalSubset(nsAString
& aInternalSubset
) const {
73 aInternalSubset
= mInternalSubset
;
76 already_AddRefed
<CharacterData
> DocumentType::CloneDataNode(
77 mozilla::dom::NodeInfo
* aNodeInfo
, bool aCloneText
) const {
78 return do_AddRef(new (aNodeInfo
->NodeInfoManager()) DocumentType(
79 do_AddRef(aNodeInfo
), mPublicId
, mSystemId
, mInternalSubset
));
82 } // namespace mozilla::dom