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/. */
7 #include "mozilla/dom/HTMLTemplateElement.h"
8 #include "mozilla/dom/HTMLTemplateElementBinding.h"
10 #include "mozilla/dom/Document.h"
11 #include "mozilla/MappedDeclarations.h"
12 #include "nsGkAtoms.h"
13 #include "nsStyleConsts.h"
16 NS_IMPL_NS_NEW_HTML_ELEMENT(Template
)
18 namespace mozilla::dom
{
20 HTMLTemplateElement::HTMLTemplateElement(
21 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
22 : nsGenericHTMLElement(std::move(aNodeInfo
)) {
23 SetHasWeirdParserInsertionMode();
25 Document
* contentsOwner
= OwnerDoc()->GetTemplateContentsOwner();
27 MOZ_CRASH("There should always be a template contents owner.");
30 mContent
= contentsOwner
->CreateDocumentFragment();
31 mContent
->SetHost(this);
34 HTMLTemplateElement::~HTMLTemplateElement() {
36 mContent
->SetHost(nullptr);
40 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLTemplateElement
,
43 NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTemplateElement
)
45 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLTemplateElement
,
48 tmp
->mContent
->SetHost(nullptr);
49 tmp
->mContent
= nullptr;
51 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
53 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTemplateElement
,
55 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContent
)
56 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
58 NS_IMPL_ELEMENT_CLONE(HTMLTemplateElement
)
60 JSObject
* HTMLTemplateElement::WrapNode(JSContext
* aCx
,
61 JS::Handle
<JSObject
*> aGivenProto
) {
62 return HTMLTemplateElement_Binding::Wrap(aCx
, this, aGivenProto
);
65 } // namespace mozilla::dom