Bug 1554951 [wpt PR 17043] - wake-lock: Fix invalid types test in wakelock-type.https...
[gecko.git] / dom / html / HTMLTemplateElement.cpp
blob40bbdb74fadbd61e0aee9acdbd225ec9ac99cbe8
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/MappedDeclarations.h"
11 #include "nsGkAtoms.h"
12 #include "nsStyleConsts.h"
13 #include "nsAtom.h"
15 NS_IMPL_NS_NEW_HTML_ELEMENT(Template)
17 namespace mozilla {
18 namespace dom {
20 HTMLTemplateElement::HTMLTemplateElement(
21 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
22 : nsGenericHTMLElement(std::move(aNodeInfo)) {
23 SetHasWeirdParserInsertionMode();
25 Document* contentsOwner = OwnerDoc()->GetTemplateContentsOwner();
26 if (!contentsOwner) {
27 MOZ_CRASH("There should always be a template contents owner.");
30 mContent = contentsOwner->CreateDocumentFragment();
31 mContent->SetHost(this);
34 HTMLTemplateElement::~HTMLTemplateElement() {
35 if (mContent) {
36 mContent->SetHost(nullptr);
40 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLTemplateElement,
41 nsGenericHTMLElement)
43 NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTemplateElement)
45 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLTemplateElement,
46 nsGenericHTMLElement)
47 if (tmp->mContent) {
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,
54 nsGenericHTMLElement)
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 dom
66 } // namespace mozilla